-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.py
More file actions
32 lines (26 loc) · 882 Bytes
/
order.py
File metadata and controls
32 lines (26 loc) · 882 Bytes
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
# order.py
from enum import Enum, auto
class OrderState(Enum):
NEW = auto()
ACKED = auto()
FILLED = auto()
CANCELED = auto()
REJECTED = auto()
class Order:
def __init__(self, symbol, qty, side):
self.symbol = symbol
self.qty = qty
self.side = side
self.state = OrderState.NEW
def transition(self, new_state):
allowed = {
OrderState.NEW: {OrderState.ACKED, OrderState.REJECTED},
OrderState.ACKED: {OrderState.FILLED, OrderState.CANCELED},
}
current = self.state
# If state not allowed, ignore
if current in allowed and new_state in allowed[current]:
self.state = new_state
print(f"Order {self.symbol} is now {new_state.name}")
else:
print(f"[WARN] Transition {current.name} → {new_state.name} not allowed")