28 lines
885 B
Python
28 lines
885 B
Python
from arbitrade.exchange.models import BookLevel
|
|
from arbitrade.market_data.order_book import OrderBook
|
|
|
|
|
|
def test_order_book_apply_and_best_levels() -> None:
|
|
book = OrderBook()
|
|
book.apply_bids([BookLevel(price=100.0, volume=1.0), BookLevel(price=99.5, volume=2.0)])
|
|
book.apply_asks([BookLevel(price=100.5, volume=1.1), BookLevel(price=101.0, volume=0.9)])
|
|
|
|
best_bid = book.best_bid()
|
|
best_ask = book.best_ask()
|
|
|
|
assert best_bid is not None
|
|
assert best_ask is not None
|
|
assert best_bid.price == 100.0
|
|
assert best_ask.price == 100.5
|
|
|
|
|
|
def test_order_book_checksum_matches_self() -> None:
|
|
book = OrderBook()
|
|
book.apply_bids([BookLevel(price=100.0, volume=1.0)])
|
|
book.apply_asks([BookLevel(price=100.5, volume=1.0)])
|
|
|
|
checksum = book.compute_checksum()
|
|
|
|
assert isinstance(checksum, int)
|
|
assert checksum == book.compute_checksum()
|