add many change

This commit is contained in:
2026-05-09 14:04:07 +09:00
parent d17815f727
commit f015d73e87
5 changed files with 156 additions and 209 deletions

99
bot.py
View File

@@ -12,7 +12,7 @@ import socket
import json
from state import StateManager
from order import OrderManager
# ~~~~~============== CONFIGURATION ==============~~~~~
# Replace "REPLACEME" with your team name!
team_name = "HanyangFloorFunction"
@@ -32,48 +32,18 @@ team_name = "HanyangFloorFunction"
def main():
args = parse_arguments()
state = StateManager()
exchange = ExchangeConnection(args=args)
orderman = OrderManager(exchange)
# Store and print the "hello" message received from the exchange. This
# contains useful information about your positions. Normally you start with
# all positions at zero, but if you reconnect during a round, you might
# have already bought/sold symbols and have non-zero positions.
hello_message = exchange.read_message()
print("First message from exchange:", hello_message)
# Send an order for BOND at a good price, but it is low enough that it is
# unlikely it will be traded against. Maybe there is a better price to
# pick? Also, you will need to send more orders over time.
exchange.send_add_message(order_id=1, symbol="BOND", dir=Dir.BUY, price=990, size=1)
orderman.sell("BOND", 1001, 99)
orderman.buy("BOND", 999, 99)
# Set up some variables to track the bid and ask price of a symbol. Right
# now this doesn't track much information, but it's enough to get a sense
# of the VALE market.
vale_bid_price, vale_ask_price = None, None
vale_last_print_time = time.time()
# Here is the main loop of the program. It will continue to read and
# process messages in a loop until a "close" message is received. You
# should write to code handle more types of messages (and not just print
# the message). Feel free to modify any of the starter code below.
#
# Note: a common mistake people make is to call write_message() at least
# once for every read_message() response.
#
# Every message sent to the exchange generates at least one response
# message. Sending a message in response to every exchange message will
# cause a feedback loop where your bot's messages will quickly be
# rate-limited and ignored. Please, don't do that!
while True:
message = exchange.read_message()
# Some of the message types below happen infrequently and contain
# important information to help you understand what your bot is doing,
# so they are printed in full. We recommend not always printing every
# message because it can be a lot of information to read. Instead, let
# your code handle the messages and just print the information
# important for you!
if message["type"] == "close":
print("The round has ended")
break
@@ -81,28 +51,55 @@ def main():
print(message)
elif message["type"] == "reject":
print(message)
elif message["type"] == "fill":
print(message)
elif message["type"] == "book":
if message["symbol"] == "VALE":
on_book(message, state)
elif message["type"] == "trade":
on_trade(message, state)
elif message["type"] == "fill":
on_fill(message, orderman, state)
def best_price(side):
if message[side]:
return message[side][0][0]
vale_bid_price = best_price("buy")
vale_ask_price = best_price("sell")
def on_book(message: dict, state: StateManager):
symbol = message["symbol"]
now = time.time()
def best_price(side) -> int:
if message[side]:
return message[side][0][0]
if now > vale_last_print_time + 1:
vale_last_print_time = now
print(
{
"vale_bid_price": vale_bid_price,
"vale_ask_price": vale_ask_price,
}
)
bid_price = int(best_price("buy"))
ask_price = int(best_price("sell"))
state.update_bid_ask_price(symbol, bid_price, ask_price)
def on_fill(message: dict, orderman: OrderManager, state: StateManager):
symbol = message["symbol"]
dir = message["dir"]
size = message["size"]
quantity = size if dir == Dir.BUY else -size
orderman.update_position(symbol, message["order_id"], quantity)
def on_trade(message: dict, orderman: OrderManager, state: StateManager):
symbol = message["symbol"]
price = message["price"]
state.set_last_price(symbol, price)
# 거래도
p_valbz = state.get_fair_value("VALBZ")
p_vale = state.get_fair_value("VALE")
if state.get_last_price("VALBZ") is None or state.get_last_price("VALE") is None:
return
FEE = 10
SZ = 10
if p_vale < p_valbz:
if p_vale * SZ + FEE < p_valbz * SZ:
orderman.buy("VALE", p_vale, SZ)
orderman.sell("VALBZ", p_valbz, SZ)
# ~~~~~============== PROVIDED CODE ==============~~~~~