Strategies
BaseStrategy
The base strategy class should be used for all strategies and contains the following parameters / functions for order/trade execution.
Parameters
market_filterStreaming market filter or list of filters requiredmarket_data_filterStreaming market data filter requiredstreaming_timeoutStreaming timeout, will call snap() on cache every x secondsconflate_msStreaming conflatestream_classMarketStream or RawDataStreamnameStrategy name, if None will default to class namecontextDictionary object where any extra data can be stored here such as triggersmax_selection_exposureMax exposure per selection (including new order), note this does not handle reduction in exposure due to laying another runnermax_order_exposureMax exposure per orderclientsflumine.clientsmax_trade_countMax total number of trades per runnermax_live_trade_countMax live (with executable orders) trades per runnermulti_order_tradesAllow multiple live orders per trade
Functions
The following functions can be overridden dependent on the strategy:
add()Function called when strategy is added to frameworkstart()Function called when framework startsprocess_new_market()Process Market when it gets added to the framework for the first timeprocess_market_catalogue()Process updates to the market catalogue.check_market_book()Function called with marketBook,process_market_bookis only executed if this returns Trueprocess_market_book()Processes market book updates, called on every update that is receivedprocess_raw_data()As perprocess_market_bookbut handles raw dataprocess_orders()Process list of Order objects for strategy and Marketprocess_closed_market()Process Market after closurefinish()Function called when framework ends
Runner Context
Each strategy stores a RunnerContext object which contains the state of a runner based on all and current active trades. This is used by controls to calculate exposure and control the number of live or total trades.
runner_context = self.get_runner_context(
market.market_id, runner.selection_id, runner.handicap
)
runner_context.invested
runner_context.trade_count
runner_context.live_trade_count
runner_context.executable_orders
runner_context.placed_elapsed_seconds
runner_context.trades
runner_context.live_trades