|
I am currently working on integrating a Current backtesting exchange implementation executes market orders at the next bar's open, updating balances accordingly. The reasons for this are clear. However, this delays ability to place corresponding stop orders since balances aren't updated until after execution. This make it impossible to use Could you recommend a method within Basana to place stop orders immediately or at least as soon as possible after market orders? I am currently thinking about preserving a need for a stop order in the internal state of a PositionManager and placing it inside Appreciate any insights or best practices you can share for integrating this with your library's order management system. Thanks. |
Replies: 2 comments
|
The limitation here is related to the event based nature of the backtester. For any order to get filled a BarEvent needs to take place. When you submit an order, Market, Limit, whatever, those are validated and accepted by the exchange, and they remain in that state until the next BarEvent. It is for that reason that the create_market_order + create_stop_order, or any other combination, won't work with the backtesting exchange. Because you need a BarEvent for an order to get filled. I'd suggest a couple of things to mitigate this limitation:
This is assuming you're using hourly bars, so 1 minute after the next bar the check_order coroutine will be called and you can check and submit the stop order. The nice thing about this approach is that will also work with a real exchange. You just don't need to schedule after the next bar, you can schedule a check in 5 minutes. Hope this helps. |
|
I've addressed this issue at 5d55772 and it will be available in the next version. |
I've addressed this issue at 5d55772 and it will be available in the next version.
It is currently disabled by default, for backwards compatibility reasons, but the examples have been updated to enable immediate order processing.