Open jeremytanjianle opened 7 years ago
Can't tell from the code you posted whether you have an v1 or v20 API account. The code also referred to a ForexSystem class which seemed to be a custom class created by the author. It's a bit challenging to tell what the problem is.
You might like to refer to some sample codes that I posted on my github to get up and running quickly. It's open sourced.
Oanda quotes v1 API:
I ran this a moment ago.
import oandapy
access_token=".."
oanda = oandapy.API(environment="practice", access_token=access_token)
account = "XXXXXXX"
class MyStreamer(oandapy.Streamer):
def __init__(self, count=10, *args, **kwargs):
super(MyStreamer, self).__init__(*args, **kwargs)
self.count = count
self.reccnt = 0
def on_success(self, data):
print(data)
self.reccnt += 1
if self.reccnt == self.count:
self.disconnect()
def on_error(self, data):
self.disconnect()
stream = MyStreamer(environment="practice", access_token=access_token)
stream.rates(account, instruments="EUR_USD")
Gives JSON decoded output:
{u'tick': {u'ask': 1.09708, u'instrument': u'EUR_USD', u'bid': 1.09697, u'time': u'2017-05-15T11:04:11.936976Z'}}
{u'tick': {u'ask': 1.09708, u'instrument': u'EUR_USD', u'bid': 1.09697, u'time': u'2017-05-15T11:04:11.936976Z'}}
{u'heartbeat': {u'time': u'2017-05-15T11:04:14.275570Z'}}
{u'heartbeat': {u'time': u'2017-05-15T11:04:16.603674Z'}}
{u'heartbeat': {u'time': u'2017-05-15T11:04:19.275622Z'}}
So these are Python dicts. The streamer does JSON decoding of the incoming data. I guess you have to look in the ForexSystem class where it handles the tick responses.
The error you report comes for instance from trying to decode a stringyfied dict:
>>> d = {"a": 10} # dict
>>> s = str(d)
>>> print(s)
"{'a': 10}"
>>> json.loads(s)
you get the error you reported
These's are the exact codes from which I copy from a popular oanda sample code in some "Mastering Python for Finance" book. But no matter what I do, I keep getting JSON errors!
The Errors responses are the following. Can someone tell me how to fix this? I hear its OANDA's problem