Ejemplo n.º 1
0
 def test_adding_exchange(self):
     exchange = Exchange()
     exchange.asks = Orderbook_half('asks', 1)
     exchange.bids = Orderbook_half('bids', 100)
     order01 = Order('T01', 'Ask', 3, 1, 1, 0, 'LIM')
     order03 = Order('T01', 'Ask', 5, 2, 1, 0, 'LIM')
     exchange.asks.book_add(order01)
     exchange.asks.book_add(order03)
     self.assertEqual(exchange.asks.n_orders, 1)
     self.assertEqual(
         exchange.asks.lob,
         collections.OrderedDict([(5, [2, [[1, 2, 'T01', 0]]])]))
     order02 = Order('T01', 'Ask', 6, 3, 1, 0, 'LIM')
     exchange.asks.book_add(order02)
     self.assertEqual(exchange.asks.n_orders, 1)
Ejemplo n.º 2
0
 def test_processOrder_exchange_bid(self):
     exchange = Exchange()
     exchange.asks = Orderbook_half('Ask', 1)
     exchange.bids = Orderbook_half('Bid', 100)
     order01 = Order('T01', 'Bid', 13, 1, 1, 0, 'LIM')
     order03 = Order('T02', 'Bid', 15, 2, 1, 0, 'LIM')
     exchange.add_order(order01, False)
     exchange.add_order(order03, False)
     order02 = Order('T03', 'Ask', 6, 10, 1, 0, 'LIM')
     transac, actual = exchange.process_order2(12, order02, False)
     self.assertEqual(exchange.asks.best_qty, 7)
     self.assertEqual(exchange.bids.n_orders, 0)
     self.assertEqual(transac[0]['party1'], 'T02')
     self.assertEqual(transac[1]['party1'], 'T01')
     self.assertEqual(actual, 3)
Ejemplo n.º 3
0
 def test_dec_bid(self):
     exchange = Exchange()
     exchange.asks = Orderbook_half('Ask', 1)
     exchange.bids = Orderbook_half('Bid', 100)
     order01 = Order('T01', 'Bid', 3, 5, 1, 0, 'LIM')
     order03 = Order('T02', 'Bid', 5, 10, 1, 0, 'LIM')
     exchange.add_order(order01, False)
     exchange.add_order(order03, False)
     exchange.bids.decrement_order(5, 'T02', 1)
     self.assertEqual(exchange.bids.n_orders, 2)
     self.assertEqual(exchange.bids.best_qty, 9)
     self.assertEqual(
         exchange.bids.lob,
         collections.OrderedDict([(5, [9, [[1, 9, 'T02', 1]]]),
                                  (3, [5, [[1, 5, 'T01', 0]]])]))
Ejemplo n.º 4
0
 def test_processOrder_bid_LIM04(self):
     exchange = Exchange()
     exchange.asks = Orderbook_half('Ask', 1)
     exchange.bids = Orderbook_half('Bid', 100)
     order01 = Order('T03', 'Ask', 3, 4, 1, 0, 'LIM')
     order02 = Order('T01', 'Ask', 4, 3, 1, 0, 'LIM')
     order03 = Order('T02', 'Ask', 5, 2, 1, 0, 'LIM')
     exchange.add_order(order01, False)
     exchange.add_order(order02, False)
     exchange.add_order(order03, False)
     order02 = Order('T01', 'Bid', 6, 10, 1, 0, 'LIM')
     transac, actual = exchange.process_order2(12, order02, False)
     self.assertEqual(exchange.bids.best_qty, 4)
     self.assertEqual(exchange.bids.best_price, 6)
     self.assertEqual(exchange.bids.n_orders, 1)
     self.assertEqual(exchange.asks.n_orders, 1)
     self.assertEqual(transac[0]['party1'], 'T03')
     self.assertEqual(transac[0]['qty'], 4)
     self.assertEqual(transac[1]['party1'], 'T02')
     self.assertEqual(transac[1]['qty'], 2)
     self.assertEqual(actual, 6)
Ejemplo n.º 5
0
    def test_processOrder_bid_wp_mkt(self):
        exchange = Exchange()
        exchange.asks = Orderbook_half('Ask', 1)
        exchange.bids = Orderbook_half('Bid', 100)
        order01 = Order('T02', 'Ask', 13, 1, 1, 0, 'LIM')
        order02 = Order('T01', 'Ask', 14, 3, 1, 0, 'LIM')
        order03 = Order('T03', 'Ask', 15, 2, 1, 0, 'LIM')
        exchange.add_order(order01, False)
        exchange.add_order(order03, False)
        exchange.add_order(order02, False)
        order02 = Order('T04', 'Bid', 5, 10, 1, 0, 'MKT')
        transac, actual = exchange.process_order2(12, order02, False)
        self.assertEqual(exchange.asks.n_orders, 0)
        self.assertEqual(exchange.bids.n_orders, 0)

        self.assertEqual(transac[0]['party1'], 'T02')
        self.assertEqual(transac[0]['qty'], 1)
        self.assertEqual(transac[1]['party1'], 'T01')
        self.assertEqual(transac[1]['qty'], 3)
        self.assertEqual(transac[2]['party1'], 'T03')
        self.assertEqual(transac[2]['qty'], 2)

        self.assertEqual(actual, 6)