Strategies
BaseStrategy
The base strategy class should be used for all strategies and contains the following parameters / functions for order/trade execution.
Parameters
market_filter
Streaming market filter or list of filters requiredmarket_data_filter
Streaming market data filter requiredstreaming_timeout
Streaming timeout, will call snap() on cache every x secondsconflate_ms
Streaming conflatestream_class
MarketStream or RawDataStreamname
Strategy name, if None will default to class namecontext
Dictionary object where any extra data can be stored here such as triggersmax_selection_exposure
Max exposure per selection (including new order), note this does not handle reduction in exposure due to laying another runnermax_order_exposure
Max exposure per orderclients
flumine.clientsmax_trade_count
Max total number of trades per runnermax_live_trade_count
Max live (with executable orders) trades per runnermulti_order_trades
Allow 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_book
is only executed if this returns Trueprocess_market_book()
Processes market book updates, called on every update that is receivedprocess_raw_data()
As perprocess_market_book
but 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