forked from cpartridge18/prosperity-24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datamodel.py
109 lines (78 loc) · 3.54 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import json
from typing import Dict, List
from json import JSONEncoder
import jsonpickle
Time = int
Symbol = str
Product = str
Position = int
UserId = str
ObservationValue = int
class Listing:
def __init__(self, symbol: Symbol, product: Product, denomination: Product):
self.symbol = symbol
self.product = product
self.denomination = denomination
class ConversionObservation:
def __init__(self, bidPrice: float, askPrice: float, transportFees: float, exportTariff: float, importTariff: float, sunlight: float, humidity: float):
self.bidPrice = bidPrice
self.askPrice = askPrice
self.transportFees = transportFees
self.exportTariff = exportTariff
self.importTariff = importTariff
self.sunlight = sunlight
self.humidity = humidity
class Observation:
def __init__(self, plainValueObservations: Dict[Product, ObservationValue], conversionObservations: Dict[Product, ConversionObservation]) -> None:
self.plainValueObservations = plainValueObservations
self.conversionObservations = conversionObservations
def __str__(self) -> str:
return "(plainValueObservations: " + jsonpickle.encode(self.plainValueObservations) + ", conversionObservations: " + jsonpickle.encode(self.conversionObservations) + ")"
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
def __str__(self) -> str:
return "(" + self.symbol + ", " + self.buyer + " << " + self.seller + ", " + str(self.price) + ", " + str(self.quantity) + ", " + str(self.timestamp) + ")"
def __repr__(self) -> str:
return "(" + self.symbol + ", " + self.buyer + " << " + self.seller + ", " + str(self.price) + ", " + str(self.quantity) + ", " + str(self.timestamp) + ")"
class TradingState(object):
def __init__(self,
traderData: str,
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: Observation):
self.traderData = traderData
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__