-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial.py
37 lines (29 loc) · 1.78 KB
/
tutorial.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
from datamodel import OrderDepth, UserId, TradingState, Order
from typing import List
import string
class Trader:
def run(self, state: TradingState):
# Only method required. It takes all buy and sell orders for all symbols as an input, and outputs a list of orders to be sent
print("traderData: " + state.traderData)
print("Observations: " + str(state.observations))
result = {}
for product in state.order_depths:
order_depth: OrderDepth = state.order_depths[product]
orders: List[Order] = []
acceptable_price = 10; # Participant should calculate this value
print("Acceptable price : " + str(acceptable_price))
print("Buy Order depth : " + str(len(order_depth.buy_orders)) + ", Sell order depth : " + str(len(order_depth.sell_orders)))
if len(order_depth.sell_orders) != 0:
best_ask, best_ask_amount = list(order_depth.sell_orders.items())[0]
if int(best_ask) < acceptable_price:
print("BUY", str(-best_ask_amount) + "x", best_ask)
orders.append(Order(product, best_ask, -best_ask_amount))
if len(order_depth.buy_orders) != 0:
best_bid, best_bid_amount = list(order_depth.buy_orders.items())[0]
if int(best_bid) > acceptable_price:
print("SELL", str(best_bid_amount) + "x", best_bid)
orders.append(Order(product, best_bid, -best_bid_amount))
result[product] = orders
traderData = "SAMPLE" # String value holding Trader state data required. It will be delivered as TradingState.traderData on next execution.
conversions = 1
return result, conversions, traderData