oanda / v20-python

OANDA v20 bindings for Python
MIT License
225 stars 91 forks source link

HTTP 502 error when trying to access order book on practice account #36

Closed Mammago closed 4 years ago

Mammago commented 4 years ago

When I try to send a GET request to the following link I get a 502 (Bad Gateway) error:

https://api-fxpractice.oanda.com/v3/instruments/USD_JPY/orderBook

I've checked issue #29 and I don't think this is the same thing, as the original poster was able to circumvent their problem by sending a GET request to the following URL directly from command line using curl:

https://api-fxtrade.oanda.com/v3/instruments/USD_JPY/orderBook

The only difference between their link and mine is that theirs is fxtrade and mine is fxpractice, so that's why I'm wondering if that's the issue. I don't have an fxtrade account yet so I can't check. If this is true, is this an intentional policy on Oanda's part not to provide order book data to practice accounts?

There was also some mention of using OrderBook instead of orderBook, but I've found that all other combinations of case generate a 404 instead of a 502 error. The code I'm using is provided below - it was mostly just stripped straight out of the request() and __request() methods of the API class in the oandaV20.py file. If you uncomment the first line and comment out the second you should get a perfectly healthy HTTP 200 response, showing that the URL for candles is available for API interaction:

#endpoint = instruments.InstrumentsCandles(instrument="USD_JPY", params = {"alignmentTimezone": "UTC"}) 
endpoint = instruments.InstrumentsOrderBook(instrument="USD_JPY", params = {"alignmentTimezone": "UTC"})
access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

method = endpoint.method.lower()

c = requests.Session()
c.stream = False
c.headers['Authorization'] = 'Bearer ' + access_token
c.headers.update({"Accept-Encoding": "gzip, deflate"})

func = getattr(c, method)

request_args = {}
request_args['params'] = {"alignmentTimezone": "UTC"}
url = "{}/{}".format('https://api-fxpractice.oanda.com', endpoint)
print(url)
response = func(url, stream=False, headers={}, **request_args)
print(response)
content = response.content.decode('utf-8')
content = json.loads(content)
hatttakumi commented 4 years ago

I am also receiving the same error. I'm contacting OANDA right now so I'll share it when I get the information. Please let us know if you have any new information.

hatttakumi commented 4 years ago

I received an answer from OANDA. It seems that only the live account can use the endpoint of orderBook. Not available for demo account.

Mammago commented 4 years ago

Yes, I spoke to Oanda myself over the phone and can confirm that they don't provide orderBook information to demo accounts. I wish this had been written down somewhere in their official documentation but never mind. Closing this issue.