Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def test_equality():
    q1 = Quote(MARKET, BID_SIDE, Price("95.42"), 94)
    q2 = Quote(MARKET, BID_SIDE, Price("95.42"), 94)
    assert q1 == q2

    q2 = Quote(
        Market(Product("APPL", "Apple"), Endpoint("Nasdaq", "NSDQ"),
               PriceFactory("0.01")), BID_SIDE, Price("95.42"), 94)
    assert q1 != q2

    q2 = Quote(MARKET, BID_SIDE, Price("95.43"), 94)
    assert q1 != q2

    q2 = Quote(MARKET, BID_SIDE, Price("95.42"), 91)
    assert q1 != q2

    q2 = Quote(MARKET, BID_SIDE, Price("95.42"), 94, 2)
    assert q1 != q2

    q2 = Quote(MARKET, BID_SIDE, Price("95.42"), 94, 0)
    assert q1 == q2

    q1 = Quote(MARKET, BID_SIDE, Price("95.42"), 94, 3)
    q2 = Quote(MARKET, BID_SIDE, Price("95.42"), 94, 3)
    assert q1 == q2
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def test_quote_creation():
    q = Quote(MARKET, BID_SIDE, Price("95.42"), 94)
    assert q.price() == Price("95.42")
    assert q.visible_qty() == 94
    assert q.hidden_qty() == 0
    assert q._price_level.number_of_orders() == 1
    assert q.market().product().name() == "Microsoft"
    assert q.market().product().symbol() == "MSFT"
Exemplo n.º 9
0
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
Exemplo n.º 10
0
def test_hidden_qty_not_negative():
    with pytest.raises(AssertionError):
        Quote(MARKET, BID_SIDE, Price("94.34"), 23, -23)
Exemplo n.º 11
0
def test_visible_qty_not_zero():
    with pytest.raises(AssertionError):
        Quote(MARKET, BID_SIDE, Price("94.34"), 0)
Exemplo n.º 12
0
def test_price_does_not_work_for_product():
    # price has to pass the test of being divisible evenly by the product's minimum price increment
    with pytest.raises(AssertionError):
        Quote(MARKET, BID_SIDE, Price("94.342"), 94)
Exemplo n.º 13
0
def test_successful_instantiation_locked_market_allowed():
    bid_quote = Quote(MARKET, BID_SIDE, "25.23", 18)
    ask_quote = Quote(MARKET, ASK_SIDE, "25.23", 233)
    TwoSidedQuote(bid_quote, ask_quote, True)
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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)