def test_failed_set_sell_quote_locked_market(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) ask_quote2 = Quote(MARKET, BID_SIDE, "25.23", 3) tsq = TwoSidedQuote(bid_quote, ask_quote) with pytest.raises(Exception): tsq.set_sell_quote(ask_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_failed_set_sell_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) ask_quote2 = Quote(market2, ASK_SIDE, "25.98", 3) tsq = TwoSidedQuote(bid_quote, ask_quote) with pytest.raises(Exception): tsq.set_sell_quote(ask_quote2)
def test_successful_instantiation_no_cross(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) 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 TwoSidedQuote(bid_quote, ask_quote, False) TwoSidedQuote(bid_quote, None) TwoSidedQuote(None, ask_quote) TwoSidedQuote(None, None)
def test_successful_set_sell_quote(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) ask_quote2 = Quote(MARKET, ASK_SIDE, "25.98", 3) tsq = TwoSidedQuote(bid_quote, ask_quote) assert tsq.buy_quote() == bid_quote assert tsq.sell_quote() == ask_quote tsq.set_sell_quote(ask_quote2) assert tsq.buy_quote() == bid_quote assert tsq.sell_quote() == ask_quote2
def test_failed_instantiation_products_not_the_same(): market1 = Market(Product("MSFT", "Microsoft"), Endpoint("Nasdaq", "NSDQ"), PriceFactory(".01")) market2 = Market(Product("APPL", "Apple"), Endpoint("Nasdaq", "NSDQ"), PriceFactory(".01")) bid_quote = Quote(market1, BID_SIDE, "25.23", 18) ask_quote = Quote(market2, ASK_SIDE, "26.20", 233) with pytest.raises(Exception): TwoSidedQuote(bid_quote, ask_quote)
def test_failed_instantiation_crossed_market(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "25.20", 233) with pytest.raises(Exception): TwoSidedQuote(bid_quote, ask_quote)
def test_failed_instantiation_sell_quote_not_an_ask(): with pytest.raises(AssertionError): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, BID_SIDE, "26.20", 233) TwoSidedQuote(bid_quote, ask_quote)
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_sell_quote_locked_market(): bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18) ask_quote = Quote(MARKET, ASK_SIDE, "26.20", 233) ask_quote2 = Quote(MARKET, ASK_SIDE, "25.23", 3) tsq = TwoSidedQuote(bid_quote, ask_quote, True) tsq.set_sell_quote(ask_quote2)