Which datetime to take in notify_order()?
NewestTrader last edited by
I am building an environment where I do live trading and backtesting within the same python module. I want to store the values that I get from backtrader in my SQL database for both kinds of trading.
I am presently thinking how I can store the
positionsthat are created / deleted during trading and that I get informed about in the method
I would like to take the
datetimethat I possibly could get from backtrader for an order that is in state
order.getstatusname() = 'Completed'and use this as part of a compound key that I will store in my database.
I presently see the following candidates for this, but I am unsure which one to take.
These are my possible candidates:
datetime.datetime.utcnow()(at least during livetrading), as maybe the moment when
notify_order()gets triggered is independant from any candles I get).
At least during backtesting, 1.-3. contain the
datetimethat I will receive with the upcoming
next(), but I am not sure whether to take 1.-3. is valid anyhow.
What would you take in my situation / what makes sense from the internal logics point of view of backtrader?
Thanks in advance!
run-out last edited by
You may with to look into using trade instead of orders. notify_trade will be notified when trades open and close. Backtrader uses numbers for dates. In notify_trade you could use the following:
trade.dtopen trade.dtclose # Giving values like: 735906.0