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.

class blueshift.errors.ValidationError(*args, **kwargs)

Validation failed. Raise this exception to flag invalid inputs or parameters.

class blueshift.errors.SymbolNotFound(*args, **kwargs)

Symbol requested does not exist. Usually raised when symbol function fails.

class blueshift.errors.ServerError(*args, **kwargs)

Received an error response from broker data or trade API.

class blueshift.errors.IllegalRequest(*args, **kwargs)

Illegal parameters for API request.

class blueshift.errors.BrokerError(*args, **kwargs)

Something went wrong while connecting to the broker or fetching data over broker API.

class blueshift.errors.AlgoOrderError(*args, **kwargs)

Error in Blueshift algo order.

class blueshift.errors.APIError(*args, **kwargs)

Broker server sent an error response, either because of invalid or illegal input parameters, or the server failed to respond temporarily.

class blueshift.errors.BrokerConnectionError(*args, **kwargs)

Error in connecting to broker servers.

class blueshift.errors.InsufficientFund(*args, **kwargs)

Insufficient fund in account. Could not complete the transaction.

class blueshift.errors.OrderError(*args, **kwargs)

Error while placing an order.

class blueshift.errors.OrderAlreadyProcessed(*args, **kwargs)

Order cannot be modified or cancel, as it is already processed.

class blueshift.errors.TradingControlError(*args, **kwargs)

A trading risk control check failed. See Risk Management APIs.

class blueshift.errors.BadDataError(*args, **kwargs)

Received malformed data from broker server.

class blueshift.errors.NoDataForAsset(*args, **kwargs)

Data query extended beyond available start date. See data.history.

class blueshift.errors.HistoryWindowStartsBeforeData(*args, **kwargs)

Data query in pipelines extended beyond available start date. See Pipeline APIs.

class blueshift.errors.NoSuchPipeline(*args, **kwargs)

Pipeline requested is not registered. See Pipeline APIs.

In addition to error handling, it is highly recommended that strategy code also applies input data sanity checks.