QuantEngineClient (Class)

This page explains the QuantEngineClient Class

QuantEngineClient class is the main class, which you derive your Algo strategy class from. QuantEngineClient class provides all the functionality required by your strategy class to receive real-time/historic tick data, place orders, receive order status, log messages, publish stats of your strategy, get and set strategy state, create and use indicators, etc.,

PlaceOrder Method

PlaceOrder method allows you to place an order to Algorum, which in turn will direct the order through appropriate API of the Brokerage Platform selected while starting the strategy.

public async Task<string> PlaceOrderAsync( PlaceOrderRequest placeOrderRequest )
def place_order(self, place_order_request: PlaceOrderRequest):

Method Parameters

ParameterParameter TypeDescription
placeOrderRequestPlaceOrderRequestPlace order request object.

Backtest Method

Backtest method initiates the backtesting of your strategy in the Algorum Cloud.

public virtual async Task<string> BacktestAsync( BacktestRequest backtestRequest )
def backtest(self, backtest_request: BacktestRequest):

Method Parameters

ParameterParameter TypeDescription
backtestRequestBacktestRequestBacktest request object with properties required for backtesting.

Log Method

Log method logs a message to Algorum Cloud, which you can download using Algorum CLI

public async Task LogAsync( LogLevel logLevel, string message )

In Python programs, log_level is a string. You should pass one of the LogLevel enum values to this parameter.

def log(self, log_level: str, message: str):

Method Parameters

ParameterParameter TypeDescription
logLevelLogLevelLog level of the message
messageStringMessage to log

CreateIndicatorEvaluator Method

CreateIndicatorEvaluator method will create a remote instance of an indicator evaluator in Algorum Cloud in your Algorum Quant Engine. This object keeps track of incoming data during live/paper or backtesting of the strategy, and will provide methods to get various indicator values.

public async Task<RemoteIndicatorEvaluator> CreateIndicatorEvaluatorAsync( 
  CreateIndicatorRequest createIndicatorRequest )
def create_indicator_evaluator(self, create_indicator_request: CreateIndicatorRequest) \
            -> RemoteIndicatorEvaluator:

Method Parameters

ParameterParameter TypeDescription
createIndicatorRequestCreateIndicatorRequestCreateIndicatorRequest object.

Method Return Value

Return TypeDescription
RemoteIndicatorEvaluatorRemoteIndicatorEvaluator object.

SetData Method

SetData method allows your strategy to store data in Algorum Cloud, which can be retrieved any time, even across strategy restarts, using GetData method. This should be used as the primary mechanism by your strategy to save strategy state, which can be accessed across strategy restarts.

public async Task SetDataAsync<T>( string key, T value )

Method Parameters

ParameterParameter TypeDescription
keyStringUnique key for the data within the strategy
valueTypeObject of the Type that you want to store in Algorum Cloud.

GetData Method

GetData method allows you to get the data from Algorum Cloud, which your strategy stored using SetData method.

public async Task<T> GetDataAsync<T>( string key )

Method Parameters

ParameterParameter TypeDescription
keyStringUnique key within the strategy that is used to store the data in Algorum Cloud.

Method Return Value

Return TypeDescription
Type object.You can specify the type of the data originally stored in Algorum Cloud using SetData method. The same type object will be returned.

SubscribeSymbols Method

SubscribeSymbols method allows your strategy to subscribe to a list of stock symbols. The tick data from these symbols will be streamed into your strategy, calling your strategy on_tick method. The streaming happens both in live/paper trading mode and backtesting mode.

public async Task SubscribeSymbolsAsync( List<Symbol> symbols )
def subscribe_symbols(self, symbols):

Method Parameters

ParameterParameter TypeDescription
symbolsList of Symbol objectsList of Symbol objects to subscribe.

UnsubscribeSymbols Method

UnsubscribeSymbols method allows your strategy to unsubscribe from a lost of stock symbols. After unsubscribe, your strategy will not receive the ticks related to the symbols, until they are subscribed to again.

public async Task UnsubscribeSymbolsAsync( List<Symbol> symbols )

Method Parameters

ParameterParameter TypeDescription
symbolsList of Symbol objectsList of Symbol objects to unsubscribe.

StartTrading Method

StartTrading method allows your strategy to start trading either in live or paper mode. Based on how you started your strategy using Algorum CLI, your strategy main program will receive the launch mode configuration parameter, using which you can determine if you are running in backtesting mode or live/paper mode. If the launch mode is live or paper, you should call StartTrading method to start the trading and start receiving the real-time tick data into your strategy (which calls the on_tick method of your strategy).

public virtual async Task StartTradingAsync( TradingRequest tradingRequest )
def start_trading(self, trading_request: TradingRequest):

Method Parameters

ParameterParameter TypeDescription
tradingRequestTradingRequestTradingRequest object.

StopTrading Method

StopTrading method allows you to stop your strategy at any point of time. This will stop sending real-time tick data into your strategy. You can start the trading in your strategy after this method call using StartTrading method call.

public virtual async Task StopTradingAsync()

Wait Method

Wait method allows your strategy to wait until it is stopped by the user using Algorum CLI or automatically closed when the connection with your Algorum Quant Engine is terminated or lost due to network disconnect. The Wait method is key to keep your strategy program running and processing until the termination condition occurs as mentioned above.

public void Wait()
def wait(self):

OnTick Override Method

OnTick method is a mandatory override method, which you should implement in your strategy class. This method is called for the real-time and historic tick data coming into your strategy. This is where you will write your primary trading logic (entry and exit conditions) of your strategy.

public override async Task OnTickAsync( TickData tickData )
def on_tick(self, tick_data: TickData):

Method Parameters

ParameterParameter TypeDescription
tickDataTickDataTickData object with tick details.

OnOrderUpdate Override Method

OnOrderUpdate method is a mandatory override method, which you should implement in your strategy class. This method is called when there is an update in the order flow for the order placed by your strategy.

public override async Task OnOrderUpdateAsync( Order order )
def on_order_update(self, order: Order):

Method Parameters

ParameterParameter TypeDescription
orderOrderOrder object with order details.

What’s Next