def test_aggressive_buy_order_first_limit_2(): services = setup_orderbook() #insert aggressive buy order o = Order() o.price = services.bus.get_market_data()['a']["ask-0"]["price"] o.size = services.bus.get_market_data()['a']["ask-0"]["size"] * 2 o.side = +1 o.id = "order_test" o.symbol = "a" services.bus.get_orderbook()[o.id] = o services.rulebook.match_one(o.id) assert services.bus.get_executions().has_key(o.id), "Rulebook generated no executions for id = %s, expected executions" % (o.id) assert len(services.bus.get_executions()[o.id]) == 1, "Number of executions need to be equal to one. Got: %d" % (len(services.bus.get_executions()[o.id])) assert services.bus.get_executions()[o.id][0].size == services.bus.get_market_data()['a']["ask-0"]["size"], "Size of the execution must be equal to the size of the limit : %d. Got %d instead" % (services.bus.get_market_data()['a']["ask-0"]["size"], services.bus.get_executions()[o.id][0].size) assert services.bus.get_executions()[o.id][0].price == o.price, "Price of the execution must be equal to the size of the order : %f. Got %f instead" % (o.price, services.bus.get_executions()[o.id][0].price)
def test_aggressive_buy_order_second_limit_4(): services = setup_orderbook() #insert aggressive buy order o = Order() o.price = services.bus.get_market_data()['a']["ask-1"]["price"] o.size = services.bus.get_market_data()['a']["ask-0"]["size"] / 2 o.side = +1 o.id = "order_test" o.symbol = "a" services.bus.get_orderbook()[o.id] = o services.rulebook.match_one(o.id) assert services.bus.get_executions().has_key(o.id), "Rulebook generated no executions for id = %s, expected executions" % (o.id) assert_equal(len(services.bus.get_executions()[o.id]), 1, "Incorrect number of executions") assert_equal(services.bus.get_executions()[o.id][0].size, services.bus.get_market_data()['a']["ask-0"]["size"] / 2 , "Size of the first execution incorrect") assert_equal(services.bus.get_executions()[o.id][0].price, services.bus.get_market_data()['a']["ask-0"]["price"], "Price of first execution incorrect")
def generate_snapshot(lit_venue_count = 3, dark_venue_count = 3): orderbook = {} #lit venues first for lv in range(lit_venue_count): orderbook[lit_venues[lv]] = {} # buy first side = 1 limit = 0 price = 100 while (limit < 5): nb_orders = int(round(10*powerlaw.rvs(0.6))) if nb_orders > 0: orderbook[lit_venues[lv]][price] = [] for i in range(nb_orders): size = int(round(normal(100, 30))) # total qty iceberg = powerlaw.rvs(0.8) # ratio of visible qty decay = random() o = Order() o.side = side o.price = price o.size = size o.shown = int(iceberg * size) o.decay = decay o.id = "Order_%f_%d" %(price, i) o.symbol = lit_venues[lv] orderbook[lit_venues[lv]][price].append(o) limit += 1 price -= 1 side = -1 limit = 0 price = 101 while (limit < 5): nb_orders = int(round(10*powerlaw.rvs(0.6))) if nb_orders > 0: orderbook[lit_venues[lv]][price] = [] for i in range(nb_orders): size = int(round(normal(100, 30))) # total qty iceberg = powerlaw.rvs(0.8) # ratio of visible qty decay = random() o = Order() o.side = side o.price = price o.size = size o.shown = int(iceberg * size) o.decay = decay o.id = "Order_%f_%d" %(price, i) o.symbol = lit_venues[lv] orderbook[lit_venues[lv]][price].append(o) limit += 1 price += 1 return orderbook