Errors and Exceptions ===================== Errors and exceptions, including from user strategy, are caught by Blueshift and handled based on their category and recoverability. If an error is recoverable, Blueshift logs the error details and continues to run. If it is irrecoverable, Blueshift executes the exit processes (graceful exit, saving data etc.). Errors are usually classified based on their types and sources, as described below. - User Strategy Errors Any errors generated from user strategy code are considered fatal and no attempt is made to recover. - Recoverable Errors Errors due to a drop in connection, or from broker API (e.g. invalid or illegal orders, bad data from broker etc.) are considered recoverable. If a recoverable error is raised, the event loop stops the current iteration at that point, and starts the next iteration as usual in the next cycle. If the error continues to repeat, after a certain threshold, it is upgraded to irrecoverable error. - Irrecoverable Errors Any errors during the Blueshift event loop initialization is considered irrecoverable in a fail-fast manner (including connection errors, API errors or validation failures). Once the event loop starts normal cycles, any unexpected error (e.g. disk full, or server crash) or any error upgraded (as described above) is considered fatal. Error Handling in Strategy -------------------------- It is usually a good idea to handle possible errors in the strategy itself, rather than leaving it to Blueshift. Strategy code can use the Python try-except block to achieve the same. Below are a list of useful errors that can be handled from within the strategy. .. py:module:: blueshift.errors .. autoclass:: ValidationError .. autoclass:: SymbolNotFound .. autoclass:: ServerError .. autoclass:: IllegalRequest .. autoclass:: BrokerError .. autoclass:: AlgoOrderError .. autoclass:: APIError .. autoclass:: BrokerConnectionError .. autoclass:: InsufficientFund .. autoclass:: OrderAlreadyProcessed .. autoclass:: TradingControlError .. autoclass:: BadDataError .. autoclass:: NoDataForAsset .. autoclass:: HistoryWindowStartsBeforeData .. autoclass:: NoSuchPipeline In addition to error handling, it is highly recommended that strategy code also applies input data sanity checks.