Ejemplo n.º 1
0
 def testBuyMatchMarketOrdersTimePrecedence(self):
     new_order = Order(OrderType.Sell, -1, 1, OrderConditions.Market, 1)
     existing_order_1 = Order(OrderType.Buy, -1, 1, OrderConditions.Market,
                              2)
     existing_order_2 = Order(OrderType.Buy, -1, 1, OrderConditions.Market,
                              3)
     order_matcher = OrderMatcher(Queue())
     order_matcher.buy_orders.append(existing_order_1)
     order_matcher.buy_orders.append(existing_order_2)
     expected_match = existing_order_1
     actual_match = order_matcher.match(new_order)
     self.assertEqual(actual_match, expected_match)
Ejemplo n.º 2
0
 def testLimitBuyAtMarket(self):
     new_order = Order(OrderType.Buy, 1.5, 1, OrderConditions.Limit, 1)
     existing_order_1 = Order(OrderType.Sell, 1.5, 1, OrderConditions.Limit,
                              2)
     existing_order_2 = Order(OrderType.Sell, 1.6, 1, OrderConditions.Limit,
                              3)
     order_matcher = OrderMatcher(Queue())
     order_matcher.sell_orders.append(existing_order_1)
     order_matcher.sell_orders.append(existing_order_2)
     actual_match = order_matcher.match(new_order)
     expected_match = existing_order_1
     self.assertEqual(expected_match, actual_match)
Ejemplo n.º 3
0
 def testLimitSellAboveMarket(self):
     new_order = Order(OrderType.Sell, 1.7, 1, OrderConditions.Limit, 1)
     existing_order_1 = Order(OrderType.Buy, 1.5, 1, OrderConditions.Limit,
                              2)
     existing_order_2 = Order(OrderType.Buy, 1.6, 1, OrderConditions.Limit,
                              3)
     order_matcher = OrderMatcher(Queue())
     order_matcher.buy_orders.append(existing_order_1)
     order_matcher.buy_orders.append(existing_order_2)
     expected_match = None
     actual_match = order_matcher.match(new_order)
     self.assertEqual(actual_match, expected_match)
Ejemplo n.º 4
0
 def testLimitBuyAboveMarketWithPricePrecedence(
         self):  # marketable limit order
     new_order = Order(OrderType.Buy, 1.5, 1, OrderConditions.Limit, 1)
     existing_order_1 = Order(OrderType.Sell, 1.6, 1, OrderConditions.Limit,
                              2)
     existing_order_2 = Order(OrderType.Sell, 1.5, 1, OrderConditions.Limit,
                              3)
     order_matcher = OrderMatcher(Queue())
     order_matcher.sell_orders.append(existing_order_1)
     order_matcher.sell_orders.append(existing_order_2)
     actual_match = order_matcher.match(new_order)
     self.assertEqual(existing_order_2, actual_match)
Ejemplo n.º 5
0
 def testMatchBuyLimitSellMarketOverLimitEvenWithTimePrecedence(self):
     new_order = Order(OrderType.Buy, 1.5454, 1, OrderConditions.Limit, 1)
     existing_order_1 = Order(OrderType.Sell, 1.5353, 1,
                              OrderConditions.Limit, 2)
     existing_order_2 = Order(OrderType.Sell, -1, 1, OrderConditions.Market,
                              3)
     order_matcher = OrderMatcher(Queue())
     order_matcher.sell_orders.append(existing_order_1)
     order_matcher.sell_orders.append(existing_order_2)
     expected_match = existing_order_2
     actual_match = order_matcher.match(new_order)
     self.assertEqual(actual_match, expected_match)
Ejemplo n.º 6
0
 def testMatchBuyMarketSellLimitPricePrecedence(self):
     new_order = Order(OrderType.Buy, -1, 1, OrderConditions.Market, 1)
     existing_order_1 = Order(OrderType.Sell, 1.6, 1, OrderConditions.Limit,
                              2)
     existing_order_2 = Order(OrderType.Sell, 1.5, 1, OrderConditions.Limit,
                              3)
     order_matcher = OrderMatcher(Queue())
     order_matcher.sell_orders.append(existing_order_1)
     order_matcher.sell_orders.append(existing_order_2)
     expected_match = existing_order_2
     actual_match = order_matcher.match(new_order)
     self.assertEqual(actual_match, expected_match)
Ejemplo n.º 7
0
 def generateOrder(self, orderid):
     order_size = self.size_gen.generateOrderSize()
     order_type = self.type_gen.generateOrderType()
     order_conditions = self.cond_gen.generateOrderConditions()
     if order_conditions == OrderConditions.Market:
         order_price = -1
     else: #TODO AHHHH
         if order_type is OrderType.Buy:
             order_price = self.price_gen.generateBidPrice()
         else:
             order_price = self.price_gen.generateAskPrice()
     order = Order(order_type, order_price, order_size, order_conditions, orderid)
     return order