-
Notifications
You must be signed in to change notification settings - Fork 0
/
Book.py
60 lines (49 loc) · 2.19 KB
/
Book.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from Events import *
from typing import Callable
class Book:
def __init__(self):
pass
# Adds a new order to the book. Returns the refnum of the order.
def on_add(self, order : Order) -> int:
# TODO implement
return order.refnum
# Updates an existing order on the book.
# `order` contains the refnum of the order it is updating. An update may
# only change the price and/or size. It cannot change the symbol or side of the order.
# Updates must maintain PIQ (place-in-queue).
def on_update(self, order : Order) -> None:
# TODO implement
pass
# Cancels an order.
# `order` only contains the symbol and the refnum and size.
# A size of 0 indicates that the order is to be removed entirely.
# A size greater than 0 indicates only `size` number of shares should be cancelled.
# Cancels with non-0 size must maintain PIQ (place-in-queue).
# NOTE: Assume size 0 cancels until the MatchingEngine followup.
def on_cancel(self, order :Order) -> None:
# TODO implement
pass
# Executes an order.
# NOTE: Can be left unimplemented until the MatchingEngine followup.
def on_exec(self, order : Order) -> None:
# TODO implement
pass
# Returns a list of orders at the best Bid price. The best Bid price is the
# highest price of all Bid orders for a symbol. The output must be sorted by
# price-time priority.
def get_best_bids(self, symbol : str) -> list[Order]:
# TODO implement
return []
# Returns a list of orders at the best Ask price. The best Ask price is the
# lowest price of all Ask orders for a symbol. The ouput must be sorted by
# price-time priority.
def get_best_asks(self, symbol : str) -> list[Order]:
# TODO implement
return []
# Subscribes a callback `cb` that is invoked when the inside changes.
# The inside refers to the best bid or ask. The inside changes if the
# price or size of best bid/ask for the symbol changes.
# The callback is to be invoked with the symbol and Side that changed.
def sub_on_inside(self, cb : Callable[[ str, Side],None]) -> None:
# TODO implement
pass