def setUp(self): self.clock: Clock = Clock(ClockMode.BACKTEST, 60.0, self.start_timestamp, self.end_timestamp) self.clock_tick_size = 60 self.maker_market: BacktestMarket = BacktestMarket() self.maker_data: MockOrderBookLoader = MockOrderBookLoader(*self.maker_symbols) self.mid_price = 100 self.bid_threshold = 0.01 self.ask_threshold = 0.01 self.cancel_order_wait_time = 45 self.maker_data.set_balanced_order_book(mid_price=self.mid_price, min_price=1, max_price=200, price_step_size=1, volume_step_size=10) self.maker_market.add_data(self.maker_data) self.maker_market.set_balance("COINALPHA", 500) self.maker_market.set_balance("WETH", 500) self.maker_market.set_balance("QETH", 500) self.maker_market.set_quantization_param( QuantizationParams( self.maker_symbols[0], 5, 5, 5, 5 ) ) self.market_info: MarketInfo = MarketInfo( *( [self.maker_market] + self.maker_symbols ) ) logging_options: int = (PureMarketMakingStrategyV2.OPTION_LOG_ALL & (~PureMarketMakingStrategyV2.OPTION_LOG_NULL_ORDER_SIZE)) self.strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], legacy_order_size=1.0, legacy_bid_spread=self.bid_threshold, legacy_ask_spread=self.ask_threshold, cancel_order_wait_time=45, logging_options=logging_options ) self.logging_options = logging_options self.clock.add_iterator(self.maker_market) self.clock.add_iterator(self.strategy) self.maker_order_fill_logger: EventLogger = EventLogger() self.cancel_order_logger: EventLogger = EventLogger() self.maker_market.add_listener(MarketEvent.OrderFilled, self.maker_order_fill_logger) self.maker_market.add_listener(MarketEvent.OrderCancelled, self.cancel_order_logger)
def setUp(self): self.clock: Clock = Clock(ClockMode.BACKTEST, 60.0, self.start_timestamp, self.end_timestamp) self.clock_tick_size = 60 self.maker_market: BacktestMarket = BacktestMarket() self.maker_data: MockOrderBookLoader = MockOrderBookLoader(*self.maker_symbols) self.mid_price = 100 self.bid_threshold = 0.01 self.ask_threshold = 0.01 self.cancel_order_wait_time = 45 self.maker_data.set_balanced_order_book(mid_price=self.mid_price, min_price=1, max_price=200, price_step_size=1, volume_step_size=10) self.filter_delegate = PassThroughFilterDelegate() self.constant_pricing_delegate = ConstantSpreadPricingDelegate(self.bid_threshold, self.ask_threshold) self.constant_sizing_delegate = ConstantSizeSizingDelegate(1.0) self.equal_strategy_sizing_delegate = StaggeredMultipleSizeSizingDelegate( order_start_size=1.0, order_step_size=0, number_of_orders=5 ) self.staggered_strategy_sizing_delegate = StaggeredMultipleSizeSizingDelegate( order_start_size=1.0, order_step_size=0.5, number_of_orders=5 ) self.multiple_order_strategy_pricing_delegate = ConstantMultipleSpreadPricingDelegate( bid_spread=self.bid_threshold, ask_spread=self.ask_threshold, order_interval_size=0.01, number_of_orders=5 ) self.maker_market.add_data(self.maker_data) self.maker_market.set_balance("COINALPHA", 500) self.maker_market.set_balance("WETH", 5000) self.maker_market.set_balance("QETH", 500) self.maker_market.set_quantization_param( QuantizationParams( self.maker_symbols[0], 6, 6, 6, 6 ) ) self.market_info: MarketSymbolPair = MarketSymbolPair( *( [self.maker_market] + self.maker_symbols ) ) logging_options: int = (PureMarketMakingStrategyV2.OPTION_LOG_ALL & (~PureMarketMakingStrategyV2.OPTION_LOG_NULL_ORDER_SIZE)) self.strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], filter_delegate=self.filter_delegate, sizing_delegate=self.constant_sizing_delegate, pricing_delegate=self.constant_pricing_delegate, cancel_order_wait_time=45, logging_options=logging_options ) self.multi_order_equal_strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], filter_delegate=self.filter_delegate, pricing_delegate=self.multiple_order_strategy_pricing_delegate, sizing_delegate=self.equal_strategy_sizing_delegate, cancel_order_wait_time=45, logging_options=logging_options ) self.multi_order_staggered_strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], filter_delegate=self.filter_delegate, pricing_delegate=self.multiple_order_strategy_pricing_delegate, sizing_delegate=self.staggered_strategy_sizing_delegate, cancel_order_wait_time=45, logging_options=logging_options ) self.logging_options = logging_options self.clock.add_iterator(self.maker_market) self.clock.add_iterator(self.strategy) self.maker_order_fill_logger: EventLogger = EventLogger() self.cancel_order_logger: EventLogger = EventLogger() self.maker_market.add_listener(MarketEvent.OrderFilled, self.maker_order_fill_logger) self.maker_market.add_listener(MarketEvent.OrderCancelled, self.cancel_order_logger)
def setUp(self): self.clock_tick_size = 1 self.clock: Clock = Clock(ClockMode.BACKTEST, self.clock_tick_size, self.start_timestamp, self.end_timestamp) self.maker_market: BacktestMarket = BacktestMarket() self.maker_data: MockOrderBookLoader = MockOrderBookLoader( *self.maker_trading_pairs) self.mid_price = 100 self.bid_spread = 0.01 self.ask_spread = 0.01 self.order_refresh_time = 30 self.maker_data.set_balanced_order_book(mid_price=self.mid_price, min_price=1, max_price=200, price_step_size=1, volume_step_size=10) self.constant_pricing_delegate = ConstantSpreadPricingDelegate( Decimal(self.bid_spread), Decimal(self.ask_spread)) self.constant_sizing_delegate = ConstantSizeSizingDelegate( Decimal("1.0")) self.filter_delegate = PassThroughFilterDelegate() self.maker_market.add_data(self.maker_data) self.maker_market.set_balance("COINALPHA", 500) self.maker_market.set_balance("WETH", 5000) self.maker_market.set_balance("QETH", 500) self.maker_market.set_quantization_param( QuantizationParams(self.maker_trading_pairs[0], 6, 6, 6, 6)) self.market_info: MarketTradingPairTuple = MarketTradingPairTuple( *([self.maker_market] + self.maker_trading_pairs)) logging_options: int = ( PureMarketMakingStrategyV2.OPTION_LOG_ALL & (~PureMarketMakingStrategyV2.OPTION_LOG_NULL_ORDER_SIZE)) self.one_level_strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], filter_delegate=self.filter_delegate, pricing_delegate=self.constant_pricing_delegate, sizing_delegate=self.constant_sizing_delegate, order_refresh_time=4, filled_order_delay=8, hanging_orders_enabled=True, logging_options=logging_options, hanging_orders_cancel_pct=0.05, order_refresh_tolerance_pct=0) self.multiple_order_pricing_delegate = ConstantMultipleSpreadPricingDelegate( bid_spread=Decimal(self.bid_spread), ask_spread=Decimal(self.ask_spread), order_level_spread=Decimal("0.01"), order_levels=Decimal("5")) self.equal_sizing_delegate = StaggeredMultipleSizeSizingDelegate( order_start_size=Decimal("1.0"), order_step_size=Decimal("0"), order_levels=Decimal("5")) self.multi_levels_strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], filter_delegate=self.filter_delegate, pricing_delegate=self.multiple_order_pricing_delegate, sizing_delegate=self.equal_sizing_delegate, order_refresh_time=4, filled_order_delay=8, hanging_orders_enabled=True, logging_options=logging_options, hanging_orders_cancel_pct=0.1, order_refresh_tolerance_pct=0) self.hanging_order_multiple_strategy: PureMarketMakingStrategyV2 = PureMarketMakingStrategyV2( [self.market_info], filter_delegate=self.filter_delegate, pricing_delegate=self.multiple_order_pricing_delegate, sizing_delegate=self.equal_sizing_delegate, order_refresh_time=4, filled_order_delay=8, hanging_orders_enabled=True, logging_options=logging_options, order_refresh_tolerance_pct=0) self.logging_options = logging_options self.clock.add_iterator(self.maker_market) self.maker_order_fill_logger: EventLogger = EventLogger() self.cancel_order_logger: EventLogger = EventLogger() self.maker_market.add_listener(MarketEvent.OrderFilled, self.maker_order_fill_logger) self.maker_market.add_listener(MarketEvent.OrderCancelled, self.cancel_order_logger)