Jump to content
  • 0

Error message : Exception: unauthorised.access.to.equity.exception


Majoka

Question

Hi, I have an API key and it seems to be working. For example, I can run the following command on my Python console and get a result. 

results = ig_service.search_markets("bhp")
results

But when I try to run this, it gives me an exception error: unauthorised.access.to.equity.exception

from trading_ig import IGService
from trading_ig.config import config
 
class config(object😞
    username = "xx"
    password = "xx"
    api_key = "xx"
    acc_type = "xx"
    acc_number = "xx"
 
ig_service = IGService(config.username, config.password, config.api_key, config.acc_type)
ig_service.create_session()
 
# Fetch close prices for BHP from IG Markets
epic_id = "AA.D.BHP.CASH.IP"
resolution = "D"
num_points = 10
 
response = ig_service.fetch_historical_prices_by_epic_and_num_points(epic_id, resolution, num_points)
close_prices = [float(price["closePrice"]["bid"]) for price in response["prices"]]
 
print(close_prices)
 
open_positions = ig_service.fetch_open_positions()
print("open_positions:\n%s" % open_positions)
 
Can you please help?
Link to comment

6 answers to this question

Recommended Posts

  • 0
On 14/06/2023 at 14:02, bug-or-feature said:

Your Epic is wrong, it should be "AA.D.BHP.DAILY.IP".

If you are new to the Python library, or to the IG REST API, it would be a good idea to use the IG API companion at first. It is much harder to make mistakes with the companion

Have you tried "AA.D.BHP.DAILY.IP" on the companion? I've got the same error message.

 

I remember there was very old thread saying IG does not support equity history price over APIs. Looks still the case now.

Edited by calabashsis
Link to comment
  • 0
On 15/07/2023 at 23:49, calabashsis said:

Have you tried "AA.D.BHP.DAILY.IP" on the companion? I've got the same error message.

 

I remember there was very old thread saying IG does not support equity history price over APIs. Looks still the case now.

Yes, and it works fine for both the market info and historic price endpoints:

https://demo-api.ig.com/gateway/deal/markets/AA.D.BHP.DAILY.IP

https://demo-api.ig.com/gateway/deal/prices/AA.D.BHP.DAILY.IP?resolution=DAY&max=10

 

Link to comment
  • 0
11 hours ago, bug-or-feature said:

Hi, 

  Thanks for the reply. But this is really weird:

  • market info DOES work, on the IG API companion page (the endpoints string displayed at the top of the page, under 'URL' section).
  • However, if I try "Historic Price Search" from the left pane of the page, I've got the same error code as below:
    • "errorCode": "unauthorised.access.to.equity.exception"
  •   Again, I've got identical endpoints as yours, showing at the top 'URL' field :

  

   I've tried Python version of IG REST API too (trading-ig). Exactly same behaviour.

 

  I really don't think IG offer access to Equities via the APIs  (including historic data) - however, anywhere we can confirm this???

 

 

Edited by calabashsis
Link to comment
  • 0
Quote

I really don't think IG offer access to Equities via the APIs  (including historic data) - however, anywhere we can confirm this???

You cannot use the APIs with share dealing, ISA or SIPP accounts. The APIs only work with spread betting and CFD accounts.

You can use the APIs to trade equities (and view historic prices) with spread betting or CFD accounts.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...
us