Beispiel #1
0
    def setUp(self):
        self.maxDiff = None
        self.clock: Clock = Clock(ClockMode.BACKTEST, 1.0, self.start_timestamp, self.end_timestamp)
        self.market_1: BacktestMarket = BacktestMarket()
        self.market_2: BacktestMarket = BacktestMarket()

        self.market_1_data: MockOrderBookLoader = MockOrderBookLoader(*self.market_1_trading_pairs)
        self.market_2_data: MockOrderBookLoader = MockOrderBookLoader(*self.market_2_trading_pairs)
        self.market_1_data.set_balanced_order_book(1.0, 0.5, 1.5, 0.01, 10)
        self.market_2_data.set_balanced_order_book(1.0, 0.5, 1.5, 0.005, 5)

        self.market_1.add_data(self.market_1_data)
        self.market_2.add_data(self.market_2_data)

        self.market_1.set_balance("COINALPHA", 500)
        self.market_1.set_balance("WETH", 500)
        self.market_2.set_balance("COINALPHA", 500)
        self.market_2.set_balance("ETH", 500)
        self.market_1.set_quantization_param(
            QuantizationParams(
                self.market_1_trading_pairs[0], 5, 5, 5, 5
            )
        )
        self.market_2.set_quantization_param(
            QuantizationParams(
                self.market_2_trading_pairs[0], 5, 5, 5, 5
            )
        )
        self.market_trading_pair_tuple_1 = MarketTradingPairTuple(*([self.market_1] + self.market_1_trading_pairs))
        self.market_trading_pair_tuple_2 = MarketTradingPairTuple(*([self.market_2] + self.market_2_trading_pairs))
        self.market_pair: ArbitrageMarketPair = ArbitrageMarketPair(
            self.market_trading_pair_tuple_1, self.market_trading_pair_tuple_2
        )

        self.logging_options: int = ArbitrageStrategy.OPTION_LOG_ALL

        self.strategy: ArbitrageStrategy = ArbitrageStrategy(
            [self.market_pair],
            min_profitability=Decimal("0.03"),
            logging_options=self.logging_options,
            secondary_to_primary_quote_conversion_rate=Decimal("0.95")
        )

        self.clock.add_iterator(self.market_1)
        self.clock.add_iterator(self.market_2)
        self.clock.add_iterator(self.strategy)

        self.market_1_order_fill_logger: EventLogger = EventLogger()
        self.market_2_order_fill_logger: EventLogger = EventLogger()

        self.market_1.add_listener(MarketEvent.OrderFilled, self.market_1_order_fill_logger)
        self.market_2.add_listener(MarketEvent.OrderFilled, self.market_2_order_fill_logger)
Beispiel #2
0
    def setUp(self):
        self.clock: Clock = Clock(ClockMode.BACKTEST, 1.0,
                                  self.start_timestamp, self.end_timestamp)
        self.market_1: BacktestMarket = BacktestMarket()
        self.market_2: BacktestMarket = BacktestMarket()

        self.market_1_data: MockOrderBookLoader = MockOrderBookLoader(
            *self.market_1_symbols)
        self.market_2_data: MockOrderBookLoader = MockOrderBookLoader(
            *self.market_2_symbols)
        self.market_1_data.set_balanced_order_book(1.0, 0.5, 1.5, 0.01, 10)
        self.market_2_data.set_balanced_order_book(1.0, 0.5, 1.5, 0.005, 5)

        self.market_1.add_data(self.market_1_data)
        self.market_2.add_data(self.market_2_data)

        self.market_1.set_balance("COINALPHA", 500)
        self.market_1.set_balance("WETH", 500)

        self.market_2.set_balance("COINALPHA", 500)
        self.market_2.set_balance("ETH", 500)

        self.market_1.set_quantization_param(
            QuantizationParams(self.market_1_symbols[0], 5, 5, 5, 5))
        self.market_2.set_quantization_param(
            QuantizationParams(self.market_2_symbols[0], 5, 5, 5, 5))
        self.market_symbol_pair_1 = MarketSymbolPair(*([self.market_1] +
                                                       self.market_1_symbols))
        self.market_symbol_pair_2 = MarketSymbolPair(*([self.market_2] +
                                                       self.market_2_symbols))
        self.market_pair: ArbitrageMarketPair = ArbitrageMarketPair(
            *(self.market_symbol_pair_1 + self.market_symbol_pair_2))

        self.logging_options: int = ArbitrageStrategy.OPTION_LOG_ALL

        self.strategy: ArbitrageStrategy = ArbitrageStrategy(
            [self.market_pair],
            min_profitability=0.03,
            logging_options=self.logging_options)

        self.clock.add_iterator(self.market_1)
        self.clock.add_iterator(self.market_2)
        self.clock.add_iterator(self.strategy)

        self.market_1_order_fill_logger: EventLogger = EventLogger()
        self.market_2_order_fill_logger: EventLogger = EventLogger()

        self.market_1.add_listener(MarketEvent.OrderFilled,
                                   self.market_1_order_fill_logger)
        self.market_2.add_listener(MarketEvent.OrderFilled,
                                   self.market_2_order_fill_logger)