Model representing an individual order
class Order(BaseModel):
"""
Model representing an individual order.
params:
price (Decimal): The price of the order.
volume (Decimal): The volume of the order.
"""
price: Decimal
volume: Decimal
from CryptoMathTrade.types import Order
order = Order(price='4', volume='431')
print(order) # -> price=Decimal('4') volume=Decimal('431')
for example Binance orderbook data
{
"lastUpdateId": 1027024,
"bids": [
[
"4.00000000", // PRICE
"431.00000000" // QTY
]
],
"asks": [
[
"4.00000200",
"12.00000000"
]
]
}
from CryptoMathTrade.types import Order
binance_orderbook = {"lastUpdateId": 1027024, "bids": [["4.00000000", "431.00000000"]], "asks": [["4.00000200", "12.00000000"]]}
bids = [Order(price=bid[0], volume=bid[1]) for bid in binance_orderbook['bids']]
asks = [Order(price=ask[0], volume=ask[1]) for ask in binance_orderbook['asks']]
print(bids) # -> [Order(price=Decimal('4.00000000'), volume=Decimal('431.00000000'))]
print(asks) # -> [Order(price=Decimal('4.00000200'), volume=Decimal('12.00000000'))]
Model representing an order book with both buy and sell orders
class OrderBook(BaseModel):
"""
Model representing an order book with both buy and sell orders.
params:
asks (list[Order]): List of sell orders (asks).
bids (list[Order]): List of buy orders (bids).
"""
asks: list[Order]
bids: list[Order]
from CryptoMathTrade.types import Order, OrderBook
ask = Order(price='4.00000200', volume='12')
bid = Order(price='4', volume='431')
orderbook = OrderBook(asks=[ask], bids=[bid])
print(orderbook) # -> asks=[Order(price=Decimal('4.00000200'), volume=Decimal('12'))] bids=[Order(price=Decimal('4'), volume=Decimal('431'))]
for example Binance orderbook data
{
"lastUpdateId": 1027024,
"bids": [
[
"4.00000000", // PRICE
"431.00000000" // QTY
]
],
"asks": [
[
"4.00000200",
"12.00000000"
]
]
}
from CryptoMathTrade.types import Order, OrderBook
binance_orderbook = {"lastUpdateId": 1027024, "bids": [["4.00000000", "431.00000000"]], "asks": [["4.00000200", "12.00000000"]]}
orderbook = OrderBook(asks=[Order(price=ask[0], volume=ask[1]) for ask in binance_orderbook['asks']],
bids=[Order(price=bid[0], volume=bid[1]) for bid in binance_orderbook['bids']], )
print(orderbook) # -> asks=[Order(price=Decimal('4.00000200'), volume=Decimal('12.00000000'))] bids=[Order(price=Decimal('4.00000000'), volume=Decimal('431.00000000'))]