Open ghost opened 7 years ago
If you just created your oanda account then it will be tied to the new oanda API, and bowhead is currently written only for the old V1 api at the moment. Hopefully that'll change soonish!
my account is at least a year old and its a practice account so could that be a issue. Im using the oanda account of the V20 account ID number, could that be the issue?
It could be, I was reading the comments to issue #4 and realised the api differences. Are you using the docker file? If so it seems known that in streaming.py the hard coded endpoint seems to point to v1. If you go to oandas api site you can see the new api that refers to v3.
yes I am using the docker file, also using the docker update steps to install instead of composer.
I tried all the docker update steps but keep getting this error even after changing v1 to v3 in streaming.py and using the regular account id which is not v20
The account ID is not actually linked to a specific account, it's an ID you're given in one of the emails when you sign up so hunt back and try and find that. I've done the same as you with regards to using docker. I've been playing around with the new api in postman and I can get the account returning a response with the new api of the accounts I hold, but not the price stream. http://developer.oanda.com/rest-live-v20/pricing-ep/
I looked at the json response when requesting the account id and to me it seems its the same digit number as the account number in your primary account
{ "accountId" : 8954947, "accountName" : "Primary", "balance" : 100000, "unrealizedPl" : 0, "realizedPl" : 0, "marginUsed" : 0, "marginAvail" : 100000, "openTrades" : 0, "openOrders" : 0, "marginRate" : 0.05, "accountCurrency" : "USD" }
after doing this request
$curl -X GET "https://api-fxtrade.oanda.com/v1/accounts/8954947"
can you list the specific steps that you did using docker?
did you do docker run -d -p 9000:9000 -v "/var/run/docker.sock:/var/run/docker.sock" portainer/portainer
and then localhost or through the command line?
also which OS are you using to install and run this?
I'm planning on spending some time on this tonight I'll send a proper reply later, but I've got some data flowing through to streaming.py if I add the argument '-b', it doesn't seem to stream though, it gives me one lump of data then closes. And if I use 'screen' it just terminates immediately.
My live OANDA account was just approved today. Tried using that with my the Account ID I was emailed but am still getting an error:
{
"code" : 1,
"message" : "Invalid or malformed argument: accountId",
"moreInfo" : "http:\/\/developer.oanda.com\/docs\/v1\/troubleshooting\/#errors"
}
I'm assuming that my account is linked only to the V20 api? Should we be working on changing the script to use that instead?
I still dont have my OANDA account approved so it would be interesting to see what you get with an approved account.. I've changed the connect_to_stream() and demo(displayHeartBeat) methods in the streaming.py file. It now points to the new API, as well as adding some error catching into the demo method. Try pasting this into these methods in your streaming.py:
def connect_to_stream():
"""
Environment Description
fxTrade (Live) The live (real money) environment
fxTrade Practice (Demo) The demo (simulated money) environment
"""
dotenv.load()
domainDict = { 'live' : 'api-fxtrade.oanda.com',
'demo' : 'api-fxpractice.oanda.com' }
# Replace the following variables with your personal values
environment = "demo" # Replace this 'live' if you wish to connect to the live environment
domain = domainDict[environment]
access_token = os.environ.get('OANDA_TOKEN')
account_id = os.environ.get('OANDA_ACCOUNT')
instruments = 'USD_JPY,EUR_USD,AUD_USD,EUR_GBP,USD_CAD,USD_CHF,USD_MXN,USD_TRY,USD_CNH,NZD_USD'
try:
s = requests.Session()
url = "https://" + domain + "/v3/accounts/" + account_id + "/pricing"
headers = {'Authorization' : 'Bearer ' + access_token,
# 'X-Accept-Datetime-Format' : 'unix'
}
params = {'instruments' : instruments, 'accountId' : account_id}
req = requests.Request('GET', url, headers = headers, params = params)
pre = req.prepare()
resp = s.send(pre, stream = True, verify = True)
return resp
except Exception as e:
s.close()
print("Caught exception when connecting to stream\n" + str(e))
def demo(displayHeartbeat):
response = connect_to_stream()
try:
if response.status_code != 200:
print(response.text)
return
except IOError:
# stdout is closed, no point in continuing
# Attempt to close them explicitly to prevent cleanup problems:
try:
sys.stdout.close()
except IOError:
pass
try:
sys.stderr.close()
except IOError:
pass
for line in response.iter_lines(1):
if line:
try:
line = line.decode('utf-8')
msg = json.loads(line)
except Exception as e:
print("Caught exception when converting message into json\n" + str(e))
return
if "instrument" in msg or "tick" in msg or displayHeartbeat:
fifo=open('quotes','a')
fifo.write(line + "\n")
print(line)
The accountID in the .env file should be an exact trading account by the way I think, not the one in the email. It seems to actually return data when you add the '-b' argument - 'python streaming.py -b'. It just doesnt seem to "stream" it. Also, my streaming.py is pointing to the demo env so be sure to change that if you're using live.
Used your code. With the -b argument, I also see the quotes fifo populated but it doesn't seem to be streaming either...
I need to set up a secondary Oanda account myself and verify this and get it into the docker setup. Sorry this has caused confusion.
thanks Joel, I been waiting to get this setup, hopefully we can resolve these issues soon and great to see part 3 is up.
I added a new command to bowhead as a complete workaround. php artisan bowhead:fx_stream
Which uses the XML from here http://rates.fxcm.com/RatesXML and queries it every 15 seconds.
@rxmg-joeldg could you include this in the article as well and update the steps, I think that would help people who are doing this from the start
edited the .env file to add OANDA_TOKEN=XXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXX and OANDA_ACCOUNT=XXX-XXX-XXXXXXX-XXX
but still get this error INFO gave up: oanda entered FATAL state, too many start retries too quickly docker run --name=bowhead -p 127.0.0.1:8080:8080 bowhead
also this is for fx-trade practice account that I am using