""".#protocol.py handling protocol."""
|
import book
|
|
|
def handleMessage(bs: {str, book.Book}, message: {str, str}):
|
"""Handle message from exchange."""
|
if (message["type"] in {"FUTURE", "SPREAD", "CALL", "PUT"}):
|
announce(bs, message)
|
elif (message["type"] == "SETTLEMENT"):
|
settle(bs, message)
|
elif (message["type"] == "ADDED"):
|
addOrder(bs, message)
|
elif (message["type"] == "DELETED"):
|
pass
|
|
|
def announce(bs: {str, book.Book}, message: {str, str}):
|
"""Announce message."""
|
# print(message)
|
bs[message["product"]] = book.Book(message["type"], message["product"],
|
message["stationId"], message["unit"],
|
message["expiry"],
|
message["aggressiveFee"],
|
message["passiveFee"],
|
message["brokerFee"])
|
|
|
def settle(bs: {str, book.Book}, message: {str, str}):
|
"""Settle order."""
|
bs.pop(message["product"])#.printBook()
|
|
def addOrder(bs: {str, book.Book}, message: {str, str}):
|
"""Order added to exchange."""
|
price = message["price"]
|
volume = message["resting"] + message["filled"]
|
if (message["side"] == "BUY"):
|
side = book.OrderSide.Buy
|
else:
|
side = book.OrderSide.Sell
|
bs[message["product"]].addOrder(book.Order(price, side, volume))
|