which data is LIVE?
-
Hello,
I have multiple data fed to my strategy and want to keep track of which data among self.datas has the status
LIVE
.def notify_data(self, data, status, *args, **kwargs): if status == data.LIVE: # the data has switched to live data # do something pass
this would help for a single data feed. How can I check the status in case
len(self.datas)
> 1 ?
-
The
data
which has gone live is given as a parameter tonotify_data
. What else do you need?
-
hey bb2,
For my first post I'll give you a more detailed answer as I had the same issue. I ended up doing the below. Others can now critique it. I used the timeframe to determine the data feeds. BTW, backtrader rules! I've spent just a few days with it now, but it will be my platform going forward. Thanks Daniel!
if status == data.LIVE: if data._timeframe==bt.TimeFrame.Minutes: self.data2_live = True print("DATA2 LIVE") else: self.data1_live = True print("DATA1 LIVE") if self.data1_live and self.data2_live: self.data_live = True print("ALL DATA LIVE")
-
@twabscs if you need to known when all data feeds have gone live the first time (apparently
2
in your case) you can then do this:def __init__(self): self.not_yet_live = [d._id for d in self.datas] def notify_data(self, data, status, *args, **kwargs): if data._id in self.not_yet_live: self.not_yet_live.remove(data._id) def next(self): if self.not_yet_live: # NOT ALL DATAS HAVE GONE LIVE print('do nothing') else: # ALL DATAS HAVE GONE LIVE print('do something')
-
@backtrader Thanks bt, I knew you'd have a more elegant solution.
Edit:
Just one tweak for those that might be needing this, at least when compared to my post. I was catching the delayed notifications without the extra check.def notify_data(self, data, status, *args, **kwargs): if status == data.LIVE: if data._id in self.not_yet_live: self.not_yet_live.remove(data._id)
-
Indeed. That's what happens with hand crafting ...