def setup_rand_trader(self): name = ''.join( random.choices(string.ascii_uppercase + string.digits, k=10)) bid_or_ask = rd.rand_trader_type() funds = rd.trader_funds(self.clearing_price, bid_or_ask) trader = Trader(name, funds) p_low, p_high = rd.rand_prices(self.clearing_price, bid_or_ask) trader.enter_order( bid_or_ask, # 'bid', 'ask' p_high, # p_high p_low, # p_low rd.rand_u_max(10), # u_max rd.rand_q_max(100)) # q_max self.traders[name] = trader return trader
def setup_book(num_bids, num_asks): bids = {} asks = {} p_high = 110 p_low = 90 u_max = 250 for x in range(0, num_asks): asker = Trader(f'asker{x}', 100000) asker.enter_order('ask', p_high, p_low, u_max, 10000) asks[asker.account] = asker.current_order for x in range(0, num_bids): p_low -= 10 bidder = Trader(f'bidder{x}', 100000) bidder.enter_order('bid', p_high, p_low, u_max, 10000) bids[bidder.account] = bidder.current_order return bids, asks
def scenario_2(): ex = Exchange('name', 'addr') bids = {} asks = {} min_p = 80 max_p = 120 tick_size = .1 bidder1 = Trader('bidder1', 10000000) bidder1.enter_order('bid', 110, 90, 250, 10000) bids[bidder1.account] = bidder1.current_order asker1 = Trader('asker1', 100000) asker1.enter_order('ask', 110, 90, 250, 10000000) asks[asker1.account] = asker1.current_order mover_bid = Trader('mover_bid', 100000) mover_bid.enter_order('bid', 110, 90, 250, 10000) mover_bid.enter_order('bid', 110, 105, 500, 10000) bids[mover_bid.account] = mover_bid.current_order mover_ask = Trader('mover_ask', 100000) mover_ask.enter_order('ask', 110, 90, 250, 10000) asks[mover_ask.account] = mover_ask.current_order results = ex.calc_crossing(min_p, max_p, tick_size, bids, asks, debug=False) c_p, c_r, bb, ba = results print(c_p, c_r, bb, ba) b1_shares = Payer.calc_demand(bidder1.current_order['p_low'], bidder1.current_order['p_high'], bidder1.current_order['u_max'], c_p) a1_shares = Payer.calc_supply(asker1.current_order['p_low'], asker1.current_order['p_high'], asker1.current_order['u_max'], c_p) move_bid_shares = Payer.calc_demand(mover_bid.current_order['p_low'], mover_bid.current_order['p_high'], mover_bid.current_order['u_max'], c_p) move_ask_shares = Payer.calc_supply(mover_ask.current_order['p_low'], mover_ask.current_order['p_high'], mover_ask.current_order['u_max'], c_p) print(f'bid1 shares: {b1_shares}') print(f'ask1 shares: {a1_shares}') print(f'mover_bid shares: {move_bid_shares}') print(f'mover_ask shares: {move_ask_shares}') Graph.test_graph(min_p, max_p, tick_size, bids, asks, c_p, c_r)