You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RFC: Change of the system of stopping strategy, so positions and orders are both always closable in the live trading
Context
Consider situation, when you want to close all orders and all positions in on_stop of the strategy. Now, you can't know at the time of closing position, how large reduce order is needed to be sent. You could close the positions on on_cancel_order hook, when all the orders are closed, but it won't be called in current design. (if I understand the design right - it certainly won't be called, if it is disposed in meantime)
There might be some orders filled in between, before cancel_order(s) and reduce_only orders from close_all_positions and cancel_all_orders are delivered to the venues.
This means, that after this block of code, it is still possible, the position is opened.
Considerations
I propose to implement this, until NT is beta, as this will be probably required by some users in the future and it presents breaking API change.
I would propose to make a solution, when the strategy itself must make a signal, it is stopped, so all positions are always possible to be closed on_cancel_order hook.
There is also a situation, when you trade such large quantity, that you need more time for a graceful shutdown, and only the strategy knows, when it stopped (in general case).
I would also propose to make the backtest fail, when a strategy on the end of a simulation doesn't send the signal, so the developer always knows about the mistake. I also propose a parameter for the graceful shutdown timeout in the backtest, so the strategy has always some time to shutdown. (the on_stop hook would be called at stop_time - shutdown_timeout).
The text was updated successfully, but these errors were encountered:
stastnypremysl
changed the title
Change of the system of stopping strategy, so positions and orders are both always closable in live trading
Change of the system of stopping strategy, so positions and orders are both always closable in the live trading
Apr 28, 2025
cjdsellers
changed the title
Change of the system of stopping strategy, so positions and orders are both always closable in the live trading
Add additional event hook and system process for strategy stop/graceful shutdown
May 9, 2025
Uh oh!
There was an error while loading. Please reload this page.
RFC: Change of the system of stopping strategy, so positions and orders are both always closable in the live trading
Context
Consider situation, when you want to close all orders and all positions in on_stop of the strategy. Now, you can't know at the time of closing position, how large reduce order is needed to be sent. You could close the positions on on_cancel_order hook, when all the orders are closed, but it won't be called in current design. (if I understand the design right - it certainly won't be called, if it is disposed in meantime)
For example, if you use following code:
There might be some orders filled in between, before cancel_order(s) and reduce_only orders from close_all_positions and cancel_all_orders are delivered to the venues.
This means, that after this block of code, it is still possible, the position is opened.
Considerations
I propose to implement this, until NT is beta, as this will be probably required by some users in the future and it presents breaking API change.
I would propose to make a solution, when the strategy itself must make a signal, it is stopped, so all positions are always possible to be closed on_cancel_order hook.
There is also a situation, when you trade such large quantity, that you need more time for a graceful shutdown, and only the strategy knows, when it stopped (in general case).
I would also propose to make the backtest fail, when a strategy on the end of a simulation doesn't send the signal, so the developer always knows about the mistake. I also propose a parameter for the graceful shutdown timeout in the backtest, so the strategy has always some time to shutdown. (the on_stop hook would be called at stop_time - shutdown_timeout).
The text was updated successfully, but these errors were encountered: