Closed zinhoo closed 5 years ago
Hi zihoa,
are you using the btoandav20 store?
check this example for setup:
https://github.com/ftomassetti/backtrader-oandav20/blob/master/examples/oandav20test/oandav20test.py
Hi zihoa,
are you using the btoandav20 store?
check this example for setup:
https://github.com/ftomassetti/backtrader-oandav20/blob/master/examples/oandav20test/oandav20test.py
Hi Happydasch, Thanks for your reply.
Yes I directly run the example code of btoandav20,
as the command below:
(base) eMacBook-Pro:backtrader-oandav20-master e$ python oandav20test.py --token 'e25677e.........84f63' --account '10........01' --data0 'EUR_USD'
The output is:
--------------------------------------------------
Strategy Created
--------------------------------------------------
-- Contract Details:
{'name': 'EUR_USD', 'type': 'CURRENCY', 'displayName': 'EUR/USD', 'pipLocation': -4, 'displayPrecision': 5, 'tradeUnitsPrecision': 0, 'minimumTradeSize': '1.0', 'maximumTrailingStopDistance': '1.0', 'minimumTrailingStopDistance': '0.0005', 'maximumPositionSize': '0.0', 'maximumOrderUnits': '100000000.0', 'marginRate': '0.01'}
Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA
***** DATA NOTIF: DELAYED
The example code have no respond then. I then keep the process continue to wait the exception cached, the error info seems shown that the program is waiting for response from oanda.
Traceback (most recent call last):
File "/Users/zihoa/anaconda3/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Users/zihoa/anaconda3/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Users/zihoa/PycharmProjects/Hheng/btoandav20/stores/oandav20store.py", line 465, in _t_account
print(e, response.get('errorMessage'))
File "/Users/zihoa/anaconda3/lib/python3.7/site-packages/v20/response.py", line 35, in get
raise ResponseNoField(self, field)
v20.errors.ResponseNoField: 200 response for GET https://api-fxpractice.oanda.com:443/v3/accounts/101.................001/summary does not have field 'errorMessage' (contains 'account', 'lastTransactionID')
***** STORE NOTIF: v20 REST request to https://api-fxpractice.oanda.com:443/v3/accounts/101-...............001/summary has timed out (read)
Is there any possible explanations for this issue?
Many thanks, zihoa
Hi,
I cannot see a issue here. the output is account info, which seems to be working. Is there a problem accessing data or what exactly does not work for you?
Cheers
I have tried to access oanda with a practice account just now and it seems that the service is not available at the moment. Maybe that is your issue. Check for oanda server status and try again maybe later.
***** STORE NOTIF: GET https://api-fxpractice.oanda.com:443/v3/accounts/1xxx-001/summary expected status 200, got 503 (Service Unavailable)
Hi,
I cannot see a issue here. the output is account info, which seems to be working. Is there a problem accessing data or what exactly does not work for you?
Cheers
Hi,
My problems is when I launch the program by command,
(base) eMacBook-Pro:HengSheng zihoa $ python3 oandaTest.py --token "asdasdasdasdasd" --account "100000000001" --data0 "EUR_USD" --timeframe Seconds`
The output I get is:
--------------------------------------------------
Strategy Created
--------------------------------------------------
-- Contract Details:
{'name': 'EUR_USD', 'type': 'CURRENCY', 'displayName': 'EUR/USD', 'pipLocation': -4, 'displayPrecision': 5, 'tradeUnitsPrecision': 0, 'minimumTradeSize': '1.0', 'maximumTrailingStopDistance': '1.0', 'minimumTrailingStopDistance': '0.0005', 'maximumPositionSize': '0.0', 'maximumOrderUnits': '100000000.0', 'marginRate': '0.01'}
Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA
***** DATA NOTIF: DELAYED
And the program do not response then. But as espected it should return the 5 seconds price stream...
I found the problem yesterday and I tried in another computer but also have same problem.
Yes, I also suspect the problem comes from OANDA server. I will explore then and keep update here. Thanks happydasch.
It is most likely the oanda server. I have just tried accessing the api with my live account, which is working. I did just output the data in the strategy, no order execution.
I'll close this issue, but reopen it or create a new one if your issue remains.
Hi Happydasch, I check the program this morning and the problem still exist. To verify the problem comes from OANDA Server or not I use the curl command to ask the price stream and it works:
curl \
-H "Authorization: Bearer <TOKEN>" \
"https://stream-fxpractice.oanda.com/v3/accounts/<ACCOUNTID>/pricing/stream?instruments=EUR_USD%2CUSD_CAD"
The command return:
{"type":"PRICE","time":"2019-05-28T13:06:32.682119462Z","bids":[{"price":"1.11914","liquidity":10000000}],"asks":[{"price":"1.11925","liquidity":10000000}],"closeoutBid":"1.11899","closeoutAsk":"1.11940","status":"tradeable","tradeable":true,"instrument":"EUR_USD"}
{"type":"PRICE","time":"2019-05-28T13:06:36.867978259Z","bids":[{"price":"1.34639","liquidity":10000000}],"asks":[{"price":"1.34656","liquidity":10000000}],"closeoutBid":"1.34639","closeoutAsk":"1.34656","status":"tradeable","tradeable":true,"instrument":"USD_CAD"}
{"type":"PRICE","time":"2019-05-28T13:06:38.001645632Z","bids":[{"price":"1.34641","liquidity":10000000}],"asks":[{"price":"1.34658","liquidity":10000000}],"closeoutBid":"1.34641","closeoutAsk":"1.34658","status":"tradeable","tradeable":true,"instrument":"USD_CAD"}
However, I call the example test program, there is no response. I then use a simple program to run the oandav20 package, which just request the price stream from oanda and print the price. The code shown following:
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse
import datetime
import backtrader as bt
import btoandav20
StoreCls = btoandav20.stores.OandaV20Store
DataCls = btoandav20.feeds.OandaV20Data
#BrokerCls = btoandav20.brokers.OandaV20Broker
# available timeframes for oanda
TIMEFRAMES = [bt.TimeFrame.Names[bt.TimeFrame.Seconds],
bt.TimeFrame.Names[bt.TimeFrame.Minutes],
bt.TimeFrame.Names[bt.TimeFrame.Days],
bt.TimeFrame.Names[bt.TimeFrame.Weeks],
bt.TimeFrame.Names[bt.TimeFrame.Months]]
api_key = "e2 63"
account_number = "10 001"
class TestStrategy(bt.Strategy):
def __init__(self):
# To keep track of pending orders
self.orders = []
# others
self.datastatus = 0
def logdata(self):
txt = []
txt.append('{}'.format(len(self)))
txt.append('{}'.format(
self.data.datetime.datetime(0).isoformat())
)
txt.append('{:.4f}'.format(self.data.open[0]))
txt.append('{:.4f}'.format(self.data.high[0]))
txt.append('{:.4f}'.format(self.data.low[0]))
txt.append('{:.4f}'.format(self.data.close[0]))
txt.append('{:.4f}'.format(self.data.volume[0]))
print(','.join(txt))
def notify_data(self, data, status, *args, **kwargs):
print('*' * 5, 'DATA NOTIF:', data._getstatusname(status), *args)
if status == data.LIVE:
self.datastatus = 1
def notify_trade(self, trade):
date = self.data.datetime.datetime()
if trade.isclosed:
print('-' * 32, ' NOTIFY TRADE ', '-' * 32)
print('{}, Close Price: {}, Profit, Gross {}, Net {}'.format(
date,
trade.price,
round(trade.pnl, 2),
round(trade.pnlcomm, 2)))
print('-' * 80)
def next(self):
print('-' * 32, ' NOTIFY PRICE ', '-' * 32)
print('{},'.format(self.data.close[0]))
print('-' * 80)
def start(self):
if self.data0.contractdetails is not None:
print('-- Contract Details:')
print(self.data0.contractdetails)
print('Started')
acc_cash = cerebro.broker.getcash()
acc_val = cerebro.broker.getvalue()
print('Account Cash = {}'.format(acc_cash))
print('Account Value = {}'.format(acc_val))
if __name__ == '__main__':
cerebro = bt.Cerebro()
oandastore = StoreCls(token=api_key, account=account_number, practice=True)
cerebro.broker = oandastore.getbroker()#BrokerCls()
data = oandastore.getdata(dataname="EUR_USD", timeframe=bt.TimeFrame.Seconds,
compression=5, reconnect = True,reconntimeout = 10)
cerebro.adddata(data)
cerebro.addsizer(bt.sizers.SizerFix, stake=500)
cerebro.addstrategy(TestStrategy)
cerebro.run()
After function 'start' return the account information, there are no response data return. I am not sure where the problem come from yet, maybe it's related to my network? I checked the code in store, I think the thread is waiting for the response from OANDA, but using single V20 package the server return my request data. Totally confused...
Best, zihoa
Hi zihoa,
please check out the updated store. This may fix your issues.
Hi zihoa,
please check out the updated store. This may fix your issues.
Hi Happydasch,
Thank you very much for solving the problem, and thanks for contributing the oandav20 project. Best regards, zihao
Hi, I use a following command to get a living data stream but no data returns. (Accound Id and token is omitted) python btTest.py --data0 EUR_USD --resample --timeframe Seconds --compression 1.
The output is: -- Contract Details: {'name': 'EUR_USD', 'type': 'CURRENCY', 'displayName': 'EUR/USD', 'pipLocation': -4, 'displayPrecision': 5, 'tradeUnitsPrecision': 0, 'minimumTradeSize': '1.0', 'maximumTrailingStopDistance': '1.0', 'minimumTrailingStopDistance': '0.0005', 'maximumPositionSize': '0.0', 'maximumOrderUnits': '100000000.0', 'marginRate': '0.01'} Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA Could you please tell me where is the possible error? Thanks zihoa