Example #1
0
def test_closer_to_quote():
    assert Side.closer_to_quote(Side.BID, 10, 11) == 11
    assert Side.closer_to_quote(Side.ASK, 10, 11) == 10
    assert Side.closer_to_quote(Side.ASK, 10, 10) == 10
    assert Side.closer_to_quote(Side.BID, 11, 11) == 11

    assert Side.closer_to_quote(Side.BID, 10.01, 11.01) == 11.01
    assert Side.closer_to_quote(Side.ASK, 10.01, 11.01) == 10.01
    assert Side.closer_to_quote(Side.ASK, 10.01, 10.01) == 10.01
    assert Side.closer_to_quote(Side.BID, 11.01, 11.01) == 11.01

    assert Side.closer_to_quote(Side.BID, Decimal(10.01),
                                Decimal(11.01)) == 11.01
    assert Side.closer_to_quote(Side.ASK, Decimal(10.01),
                                Decimal(11.01)) == 10.01
    assert Side.closer_to_quote(Side.ASK, Decimal(10.01),
                                Decimal(10.01)) == 10.01
    assert Side.closer_to_quote(Side.BID, Decimal(11.01),
                                Decimal(11.01)) == 11.01
Example #2
0
def should_update_price(side, current_price: Decimal, new_price: Decimal,
                        barrier: Decimal):
    return current_price - new_price > barrier or Side.closer_to_quote(
        side, current_price, new_price) == new_price