Пример #1
0
    def test_get_order_book(self):
        order_bid = self.create_order(1, 100, -1)
        order_ask = self.create_order(1, 105, 1)

        self.engine.place_order(order_bid)
        self.engine.place_order(order_ask)

        order_book = self.administrator_export.get_order_book()
        self.assertTrue(
            FakeComponent.check(
                {
                    'BUY': {
                        1: {
                            'errors': "",
                            'id': 1,
                            'price': 100,
                            'quantity': 1,
                            'quantity_left': 1,
                            'username': None
                        }
                    },
                    'SELL': {
                        2: {
                            'errors': "",
                            'id': 2,
                            'price': 105,
                            'quantity': 1,
                            'quantity_left': 1,
                            'username': None
                        }
                    }
                }, order_book))
Пример #2
0
 def test_ask(self):
     order = self.create_order(1, 100, 1)
     # make a copy of the order to compare against
     order2 = self.create_order(1, 100, 1)
     self.engine.place_order(order)
     self.assertTrue(FakeComponent.check(self.engine.orderbook, {-1: [], 1: [order2]}))
     self.assertTrue(self.fake_listener.component.check_for_calls([('on_queue_success',
                                                                    (order2,),
                                                                    {})]))
Пример #3
0
    def test_no_trade(self):
        order_bid = self.create_order(1, 100, -1)
        order_ask = self.create_order(1, 105, 1)

        self.engine.place_order(order_bid)
        self.engine.place_order(order_ask)
        self.assertTrue(FakeComponent.check(self.engine.orderbook, {-1: [order_bid], 1: [order_ask]}))
        self.assertTrue(self.fake_listener.component.check_for_calls([('on_queue_success',
                                                                       (order_bid,),
                                                                       {}),
                                                                      ('on_queue_success',
                                                                       (order_ask,),
                                                                       {})]))
Пример #4
0
 def test_ask(self):
     order = self.create_order(1, 100, 1)
     # make a copy of the order to compare against
     order2 = self.create_order(1, 100, 1)
     self.engine.place_order(order)
     self.assertTrue(
         FakeComponent.check(self.engine.orderbook, {
             -1: [],
             1: [order2]
         }))
     self.assertTrue(
         self.fake_listener.component.check_for_calls([('on_queue_success',
                                                        (order2, ), {})]))
Пример #5
0
    def test_no_trade(self):
        order_bid = self.create_order(1, 100, -1)
        order_ask = self.create_order(1, 105, 1)

        self.engine.place_order(order_bid)
        self.engine.place_order(order_ask)
        self.assertTrue(
            FakeComponent.check(self.engine.orderbook, {
                -1: [order_bid],
                1: [order_ask]
            }))
        self.assertTrue(
            self.fake_listener.component.check_for_calls([
                ('on_queue_success', (order_bid, ), {}),
                ('on_queue_success', (order_ask, ), {})
            ]))
Пример #6
0
    def test_get_order_book(self):
        order_bid = self.create_order(1, 100, -1)
        order_ask = self.create_order(1, 105, 1)

        self.engine.place_order(order_bid)
        self.engine.place_order(order_ask)

        order_book = self.administrator_export.get_order_book()
        self.assertTrue(FakeComponent.check(
            {'BUY': {1: {'errors': "",
                         'id': 1,
                         'price': 100,
                         'quantity': 1,
                         'quantity_left': 1,
                         'username': None}},
             'SELL': {2: {'errors': "",
                          'id': 2,
                          'price': 105,
                          'quantity': 1,
                          'quantity_left': 1,
                          'username': None}}}, order_book))
Пример #7
0
    def test_trade_crossed(self):
        order_bid = self.create_order(1, 100, -1)
        order_bid2 = self.create_order(1, 100, -1)
        order_bid3 = self.create_order(1, 100, -1)
        order_bid3.quantity_left = 0
        order_ask = self.create_order(1, 95, 1)
        order_ask2 = self.create_order(1, 95, 1)
        order_ask2.quantity_left = 0

        self.engine.place_order(order_bid)
        self.engine.place_order(order_ask)
        self.assertTrue(
            FakeComponent.check(self.engine.orderbook, {
                -1: [],
                1: []
            }))
        self.assertTrue(
            self.fake_listener.component.check_for_calls([
                ('on_queue_success', (order_bid2, ), {}),
                ('on_trade_success', (order_ask2, order_bid3, 100, 1), {})
            ]))
Пример #8
0
    def test_trade_crossed(self):
        order_bid = self.create_order(1, 100, -1)
        order_bid2 = self.create_order(1, 100, -1)
        order_bid3 = self.create_order(1, 100, -1)
        order_bid3.quantity_left = 0
        order_ask = self.create_order(1, 95, 1)
        order_ask2 = self.create_order(1, 95, 1)
        order_ask2.quantity_left = 0

        self.engine.place_order(order_bid)
        self.engine.place_order(order_ask)
        self.assertTrue(FakeComponent.check(self.engine.orderbook, {-1: [], 1: []}))
        self.assertTrue(self.fake_listener.component.check_for_calls([('on_queue_success',
                                                                       (order_bid2,),
                                                                       {}),
                                                                      ('on_trade_success',
                                                                       (
                                                                           order_ask2,
                                                                           order_bid3,
                                                                           100,
                                                                           1),
                                                                       {})]))