def test_find_profitable_arbitrage_orders(self):
     self.market_2_data.order_book.apply_diffs(
         [OrderBookRow(1.1, 30, 2)], [], 2)
     """
     market_1 Ask
     price  amount  update_id
     0  1.005    10.0        1.0
     1  1.015    20.0        1.0
     2  1.025    30.0        1.0
     3  1.035    40.0        1.0
     4  1.045    50.0        1.0
     market_2 Bid
         price  amount  update_id
     0  1.1000    30.0        2.0
     1  0.9975     5.0        1.0
     2  0.9925    10.0        1.0
     3  0.9875    15.0        1.0
     4  0.9825    20.0        1.0
     """
     profitable_orders = ArbitrageStrategy.find_profitable_arbitrage_orders(Decimal("0"),
                                                                            self.market_trading_pair_tuple_1,
                                                                            self.market_trading_pair_tuple_2,
                                                                            Decimal("1"),
                                                                            Decimal("0.95"))
     self.assertEqual(profitable_orders, [
         (Decimal("1.045"), Decimal("1.005"), Decimal("1.1"), Decimal("1.005"), Decimal("10.0")),
         (Decimal("1.045"), Decimal("1.015"), Decimal("1.1"), Decimal("1.015"), Decimal("20.0"))
     ])
     """
     price  amount  update_id
     0  0.900     5.0        2.0
     1  0.950    15.0        2.0
     2  1.005    10.0        1.0
     3  1.015    20.0        1.0
     4  1.025    30.0        1.0
     market_2 Bid
         price  amount  update_id
     0  1.1000    30.0        2.0
     1  0.9975     5.0        1.0
     2  0.9925    10.0        1.0
     3  0.9875    15.0        1.0
     4  0.9825    20.0        1.0
     """
     self.market_1_data.order_book.apply_diffs(
         [],
         [OrderBookRow(0.9, 5, 2), OrderBookRow(0.95, 15, 2)],
         2
     )
     profitable_orders = ArbitrageStrategy.find_profitable_arbitrage_orders(Decimal("0"),
                                                                            self.market_trading_pair_tuple_1,
                                                                            self.market_trading_pair_tuple_2,
                                                                            Decimal("1"),
                                                                            Decimal("0.95"))
     self.assertEqual(profitable_orders, [
         (Decimal("1.045"), Decimal("0.9"), Decimal("1.1"), Decimal("0.9"), Decimal("5.0")),
         (Decimal("1.045"), Decimal("0.95"), Decimal("1.1"), Decimal("0.95"), Decimal("15.0")),
         (Decimal("1.045"), Decimal("1.005"), Decimal("1.1"), Decimal("1.005"), Decimal("10.0"))
     ])
Exemple #2
0
 def test_find_profitable_arbitrage_orders(self):
     self.market_2_data.order_book.apply_diffs([OrderBookRow(1.1, 30, 2)],
                                               [], 2)
     """
     market_1 Ask
     price  amount  update_id
     0  1.005    10.0        1.0
     1  1.015    20.0        1.0
     2  1.025    30.0        1.0
     3  1.035    40.0        1.0
     4  1.045    50.0        1.0
     
     market_2 Bid
         price  amount  update_id
     0  1.1000    30.0        2.0
     1  0.9975     5.0        1.0
     2  0.9925    10.0        1.0
     3  0.9875    15.0        1.0
     4  0.9825    20.0        1.0
     """
     profitable_orders = ArbitrageStrategy.find_profitable_arbitrage_orders(
         0.0, self.market_1_data.order_book, self.market_2_data.order_book,
         self.market_1_symbols[2], self.market_2_symbols[2])
     self.assertEqual(profitable_orders, [(1.045, 1.005, 1.1, 1.005, 10.0),
                                          (1.045, 1.015, 1.1, 1.015, 20.0)])
     """
     price  amount  update_id
     0  0.900     5.0        2.0
     1  0.950    15.0        2.0
     2  1.005    10.0        1.0
     3  1.015    20.0        1.0
     4  1.025    30.0        1.0
     
     market_2 Bid
         price  amount  update_id
     0  1.1000    30.0        2.0
     1  0.9975     5.0        1.0
     2  0.9925    10.0        1.0
     3  0.9875    15.0        1.0
     4  0.9825    20.0        1.0
     """
     self.market_1_data.order_book.apply_diffs(
         [], [OrderBookRow(0.9, 5, 2),
              OrderBookRow(0.95, 15, 2)], 2)
     profitable_orders = ArbitrageStrategy.find_profitable_arbitrage_orders(
         0.0, self.market_1_data.order_book, self.market_2_data.order_book,
         self.market_1_symbols[2], self.market_2_symbols[2])
     self.assertEqual(profitable_orders, [(1.045, 0.9, 1.1, 0.9, 5.0),
                                          (1.045, 0.95, 1.1, 0.95, 15.0),
                                          (1.045, 1.005, 1.1, 1.005, 10.0)])