-
Notifications
You must be signed in to change notification settings - Fork 0
/
datamodel.py
70 lines (56 loc) · 2.11 KB
/
datamodel.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
60
61
62
63
64
65
66
67
68
69
70
import json
from typing import Dict, List
from json import JSONEncoder
Time = int
Symbol = str
Product = str
Position = int
UserId = str
Observation = int
class Listing:
def __init__(self, symbol: Symbol, product: Product, denomination: Product):
self.symbol = symbol
self.product = product
self.denomination = denomination
class Order:
def __init__(self, symbol: Symbol, price: int, quantity: int) -> None:
self.symbol = symbol
self.price = price
self.quantity = quantity
def __str__(self) -> str:
return "(" + self.symbol + ", " + str(self.price) + ", " + str(self.quantity) + ")"
def __repr__(self) -> str:
return "(" + self.symbol + ", " + str(self.price) + ", " + str(self.quantity) + ")"
class OrderDepth:
def __init__(self):
self.buy_orders: Dict[int, int] = {}
self.sell_orders: Dict[int, int] = {}
class Trade:
def __init__(self, symbol: Symbol, price: int, quantity: int, buyer: UserId = None, seller: UserId = None, timestamp: int = 0) -> None:
self.symbol = symbol
self.price: int = price
self.quantity: int = quantity
self.buyer = buyer
self.seller = seller
self.timestamp = timestamp
class TradingState(object):
def __init__(self,
timestamp: Time,
listings: Dict[Symbol, Listing],
order_depths: Dict[Symbol, OrderDepth],
own_trades: Dict[Symbol, List[Trade]],
market_trades: Dict[Symbol, List[Trade]],
position: Dict[Product, Position],
observations: Dict[Product, Observation]):
self.timestamp = timestamp
self.listings = listings
self.order_depths = order_depths
self.own_trades = own_trades
self.market_trades = market_trades
self.position = position
self.observations = observations
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True)
class ProsperityEncoder(JSONEncoder):
def default(self, o):
return o.__dict__