def test_failed_set_buy_quote_locked_market(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) buy_quote2 = Quote(MARKET, BID_SIDE, "26.20", 3) tsq = TwoSidedQuote(bid_quote, ask_quote) with pytest.raises(Exception): tsq.set_buy_quote(buy_quote2)
def test_failed_set_buy_quote_wrong_side(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) buy_quote2 = Quote(MARKET, ASK_SIDE, "25.98", 3) tsq = TwoSidedQuote(bid_quote, ask_quote) with pytest.raises(AssertionError): tsq.set_buy_quote(buy_quote2)
def test_successful_set_buy_quote(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) bid_quote2 = Quote(MARKET, BID_SIDE, "25.25", 43) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) tsq = TwoSidedQuote(bid_quote, ask_quote) assert tsq.buy_quote() == bid_quote assert tsq.sell_quote() == ask_quote tsq.set_buy_quote(bid_quote2) assert tsq.buy_quote() == bid_quote2 assert tsq.sell_quote() == ask_quote
def test_failed_set_buy_quote_wrong_product(): market1 = Market(Product("MSFT", "Microsoft"), Endpoint("Nasdaq", "NSDQ"), PriceFactory("0.01")) market2 = Market(Product( "APPL", "Apple", ), Endpoint("Nasdaq", "NSDQ"), PriceFactory("0.01")) bid_quote = Quote(market1, BID_SIDE, "25.23", 18) ask_quote = Quote(market1, ASK_SIDE, "26.20", 233) buy_quote2 = Quote(market2, BID_SIDE, "25.98", 3) tsq = TwoSidedQuote(bid_quote, ask_quote) with pytest.raises(Exception): tsq.set_buy_quote(buy_quote2)
def test_spread(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) tsq = TwoSidedQuote(bid_quote, ask_quote, True) assert tsq.spread() == 97 # now lock the market ask_quote2 = Quote(MARKET, ASK_SIDE, "25.23", 2334) tsq.set_sell_quote(ask_quote2) assert tsq.spread() == 0 # now cross the market ask_quote3 = Quote(MARKET, ASK_SIDE, "24.23", 2334) tsq.set_sell_quote(ask_quote3) assert tsq.spread() == -100 # now test ask None tsq.set_sell_quote(None) assert tsq.spread() is None # now test both None tsq.set_buy_quote(None) assert tsq.spread() is None
def test_successful_set_buy_quote_crossed_market(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) buy_quote2 = Quote(MARKET, BID_SIDE, "28.20", 3) tsq = TwoSidedQuote(bid_quote, ask_quote, True) tsq.set_buy_quote(buy_quote2)