Backfilling - Live Trading
-
When using the back-filling option for live trading, Backtrader will still request historical data for the instrument you are trading. This is great for filling up your indicators
minperiod
https://www.backtrader.com/docu/live/oanda/oanda.html?highlight=backfill#oandadata
However, Backtrader will also open and close orders as it loops through the historical data.
Just wondering how others are working around this? I have created a
self.start_date
attribute during__init__()
(datetime.datetime.now()
) and then I simplyreturn
fromnext()
if the data date is not>
than thestart_date
Just curious if anyone is using a different, more elegant solution?
Also my solution can run into problems it you are not in the same timezone as your data feed provider. To workaround this, I have had to add some further hacky time zone conversion. i.e:
self.start_date = datetime.now().astimezone(self._timezone).replace(tzinfo=None)
-
@ThatBlokeDave said in Backfilling - Live Trading:
However, Backtrader will also open and close orders as it loops through the historical data.
It seems you are blaming the devil instead of your code, which is the executor (unless the platform has achieved self-consciousness)
Live feeds deliver a
data.LIVE
status notification when backfilling is over and real-time data is delivered. You can find it at least here:The sources for the ibtest sample show how to tackle that.
-
Not blaming anything. Just reporting what I am seeing.
Thanks for the pointer - I will take a look.
-
Not intended to criticize, it just seemed funny that the platform would be opening and closing orders without any external intervention.
-
No worries. I probably was not clear. I was not sure how to stop
next()
being called before the live data. Naturally the code to open a position is in mynext()
method. :)Anyway, I will take a look at your suggestion. I do appreciate it.