Inifinite Loop in the Global space

If i want a method to run all the time while the rebalance function is running whats the best option to do so? For example if i want to use a half life and I want to check every second or faster, how long the trade has been opened. How can i do this?

Blueshift is event-driven. That means you can run your strategy code only in response to certain events. Usually these events are based on time - e.g. handle_data is triggered every 1 minute. You can also use schedule_function to trigger a function at a specified date-time rules. In backtests, only time-based events are supported. In live-trading, in addition to time-based events, you can also use the realtime callback API functions to trigger a function. This can be done either on arrival of a new datapoint from the data source or updates to order fills. See here for more details. The frequency of the events are determined entirely by the streaming source (i.e. the broker) - how fast they push these events. Note: if you get these realtime events at a rate much higher than the speed at which you process them in your callback functions, your strategy may slow down and lag behind the market.



Apart from responding to events (time based and real-time data or order updates), there is no way to run any user code or function. This excludes parallel runs of more than two functions as you suggest above. Based on your requirements, you can possibly put a check on on_trade function to see if the position is still open in live trading. For backtesting, the maximum possible frequency to check this is 1 minute - via the handle_data callback function.