happydasch / btoandav20

Support for Oanda-V20 API in backtrader
Apache License 2.0
131 stars 52 forks source link

backfill_from does not backfill DELAYED or switch to LIVE data #36

Closed faroutxxx closed 5 years ago

faroutxxx commented 5 years ago

As per output below you get a status notification that the data is DELAYED but no backfill or live data comes in.

Ive included below the output using ibstore(). You can see it notifies DELAYED, backfills and then switches to LIVE.

Ive included all outputs, code and the test file:

--------- Print btoandav20 of next(),notify_store(), notify_data()

EUR_USD 2019-09-20 09:44:00 1.10533
EUR_USD 2019-09-20 09:45:00 1.10521
EUR_USD 2019-09-20 09:46:00 1.10521
EUR_USD 2019-09-20 09:47:00 1.10525
EUR_USD 2019-09-20 09:48:00 1.10521
EUR_USD 2019-09-20 09:49:35.331337 1.10506
 STATUS ************ DATA NOTIF: EUR_USD DELAYED

--------- CODE for btoandav20

class TestX(bt.Strategy):

    def __init__(self):
        pass

    def notify_data(self, data, status, *args, **kwargs):
        print(" STATUS ************ DATA NOTIF: "+data._name+" "+data._getstatusname(status))

    def notify_store(self, msg, *args, **kwargs):
        print(" STORE NOTIF ------------- : "+str(msg))

    def next(self):
        print(self.data._name,self.data.datetime.datetime(),self.data.close[0])

def runstrat(args=None):
    pair = "EUR_USD"
    cerebro = bt.Cerebro()
    btoandav20.stores.OandaV20Store(token=apikey, account=acc, practice=True)
    filein = os.path.join(dir_path,"Data","Backtrader",pair+"_Test.h5")
    dataframe = pd.read_hdf(filein,"x")
    dataBackfill = bt.feeds.PandasData(dataname=dataframe) 
    data = btoandav20.feeds.OandaV20Data(dataname=pair,backfill_from=dataBackfill,backfill=True,timeframe=bt.TimeFrame.Minutes, compression=1)
    cerebro.adddata(data)
    cerebro.addstrategy(TestX)
    cerebro.run()

--------- Print ibstore of next(),notify_store(), notify_data()

EUR.USD-CASH-IDEALPRO 2019-09-20 05:46:00 1.10521
EUR.USD-CASH-IDEALPRO 2019-09-20 05:47:00 1.10525
EUR.USD-CASH-IDEALPRO 2019-09-20 05:48:00 1.10521
EUR.USD-CASH-IDEALPRO 2019-09-20 05:49:35.331337 1.10506
 STATUS ************ DATA NOTIF: EUR.USD-CASH-IDEALPRO DELAYED
 STORE NOTIF ------------- : <error id=-1, errorCode=2119, errorMsg=Market data farm is connecting:cashfarm>
EUR.USD-CASH-IDEALPRO 2019-09-20 05:50:00 1.10515
 STORE NOTIF ------------- : <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
 STORE NOTIF ------------- : <error id=-1, errorCode=2106, errorMsg=HMDS data farm connection is OK:cashhmds>
EUR.USD-CASH-IDEALPRO 2019-09-20 05:51:00 1.10507
EUR.USD-CASH-IDEALPRO 2019-09-20 05:52:00 1.10502
EUR.USD-CASH-IDEALPRO 2019-09-20 05:53:00 1.10491
EUR.USD-CASH-IDEALPRO 2019-09-20 05:54:00 1.10492
EUR.USD-CASH-IDEALPRO 2019-09-20 05:54:53.250373 1.10492
EUR.USD-CASH-IDEALPRO 2019-09-20 05:54:54.349542 1.1049
EUR.USD-CASH-IDEALPRO 2019-09-20 05:54:54.350538 1.10489
 STATUS ************ DATA NOTIF: EUR.USD-CASH-IDEALPRO LIVE
EUR.USD-CASH-IDEALPRO 2019-09-20 05:54:54.350538 1.1049
EUR.USD-CASH-IDEALPRO 2019-09-20 05:54:54.794882 1.10491

--------- CODE for ibstore


class TestX(bt.Strategy):

    def __init__(self):
        pass

    def notify_data(self, data, status, *args, **kwargs):
        print(" STATUS ************ DATA NOTIF: "+data._name+" "+data._getstatusname(status))

    def notify_store(self, msg, *args, **kwargs):
        print(" STORE NOTIF ------------- : "+str(msg))

    def next(self):
        print(self.data._name,self.data.datetime.datetime(),self.data.close[0])

def runstrat(args=None):
    pair = "EUR_USD"
    cerebro = bt.Cerebro()
    ibstore = bt.stores.IBStore(host='127.0.0.1', port=4002, clientId=1,reconnect=-1,timeout = 600) 
    filein = os.path.join(dir_path,"Data","Backtrader",pair+"_Test.h5")
    dataframe = pd.read_hdf(filein,"x")
    dataBackfill = bt.feeds.PandasData(dataname=dataframe) 
    data = ibstore.getdata(dataname='EUR.USD-CASH-IDEALPRO',backfill_from=dataBackfill, backfill=True,timeframe=bt.TimeFrame.Minutes, compression=1)
    cerebro.adddata(data)
    cerebro.addstrategy(TestX)
    cerebro.run()

-------- Test file EUR_USD_Test.h5.zip

EUR_USD_Test.h5.zip

happydasch commented 5 years ago

Check out the last commit :) hopefully this fixed your issue.

happydasch commented 5 years ago

Closing this issue. Assuming the commit fixed the issue, since no feedback given.