add: manager

This commit is contained in:
2026-05-09 15:42:58 +09:00
parent 2ef37ffa3c
commit c0e437eb34
2 changed files with 38 additions and 32 deletions

View File

@@ -6,9 +6,7 @@
import argparse import argparse
import time import time
from ETC import ExchangeConnection, Dir, team_name from ETC import ExchangeConnection, Dir, team_name
from order_new import OrderManager from manager import Manager
from position import PositionManager
from value import ValueManager
# ~~~~~============== CONFIGURATION ==============~~~~~ # ~~~~~============== CONFIGURATION ==============~~~~~
# Replace "REPLACEME" with your team name! # Replace "REPLACEME" with your team name!
@@ -24,24 +22,20 @@ from value import ValueManager
# code is intended to be a working example, but it needs some improvement # code is intended to be a working example, but it needs some improvement
# before it will start making good trades! # before it will start making good trades!
last_print_time = 0
def main(): def main():
global args, exchange, positionMan, orderMan, valueMan global last_print_time
global vale_last_print_time
args = parse_arguments() args = parse_arguments()
exchange = ExchangeConnection(args=args) exchange = ExchangeConnection(args=args)
positionMan = PositionManager() man = Manager(exchange)
orderMan = OrderManager(exchange, positionMan)
valueMan = ValueManager()
hello_message = exchange.read_message() hello_message = exchange.read_message()
print("First message from exchange:", hello_message) print("First message from exchange:", hello_message)
# #
exchange.send_add_message(order_id=1, symbol="BOND", dir=Dir.BUY, price=990, size=1) last_print_time = time.time()
vale_last_print_time = time.time()
while True: while True:
message = exchange.read_message() message = exchange.read_message()
@@ -54,18 +48,20 @@ def main():
elif message["type"] == "reject": elif message["type"] == "reject":
print(message) print(message)
elif message["type"] == "fill": elif message["type"] == "fill":
on_fill(message) on_fill(message, exchange, man)
elif message["type"] == "book": elif message["type"] == "book":
on_book(message) on_book(message, exchange, man)
def on_fill(message): def on_fill(message, man: Manager):
if (message["dir"] == Dir.BUY): if (message["dir"] == Dir.BUY):
positionMan.update_position(message["symbol"], message["size"]) man.positionMan.update_position(message["symbol"], message["size"])
elif (message["dir"] == Dir.SELL): elif (message["dir"] == Dir.SELL):
positionMan.update_position(message["symbol"], -message["size"]) man.positionMan.update_position(message["symbol"], -message["size"])
def on_book(message): def on_book(message, man: Manager):
valueMan.set_value(message["symbol"], message["buy"][0][0], message["sell"][0][0]) global last_print_time
man.valueMan.set_value(message["symbol"], message["buy"][0][0], message["sell"][0][0])
if message["symbol"] == "VALE" or message["symbol"] == "VALBZ": if message["symbol"] == "VALE" or message["symbol"] == "VALBZ":
def best_price(side): def best_price(side):
@@ -76,22 +72,22 @@ def on_book(message):
now = time.time() now = time.time()
if now > vale_last_print_time: if now > last_print_time:
vale_last_print_time = now last_print_time = now
valePos = positionMan.get_position("VALE") valePos = man.positionMan.get_position("VALE")
valeBid = valueMan.get_bid("VALE") valeBid = man.valueMan.get_bid("VALE")
valeAsk = valueMan.get_ask("VALE") valeAsk = man.valueMan.get_ask("VALE")
valbzPos = positionMan.get_position("VALBZ") valbzPos = man.positionMan.get_position("VALBZ")
valbzBid = valueMan.get_bid("VALBZ") valbzBid = man.valueMan.get_bid("VALBZ")
valbzAsk = valueMan.get_ask("VALBZ") valbzAsk = man.valueMan.get_ask("VALBZ")
FEE = 10 FEE = 10
if (valePos * positionMan.get_position["VALE"] + FEE < if (valePos * man.positionMan.get_position["VALE"] + FEE <
valbzPos * positionMan.get_position["VALBZ"]): valbzPos * man.positionMan.get_position["VALBZ"]):
orderMan.convert("VALE", Dir.SELL, valePos) man.orderMan.convert("VALE", Dir.SELL, valePos)
if (valePos * positionMan.get_position["VALE"] > if (valePos * man.positionMan.get_position["VALE"] >
valbzPos * positionMan.get_position["VALBZ"] + FEE): valbzPos * man.positionMan.get_position["VALBZ"] + FEE):
orderMan.convert("VALBZ", Dir.SELL, valbzPos) man.orderMan.convert("VALBZ", Dir.SELL, valbzPos)

10
bot split/manager.py Normal file
View File

@@ -0,0 +1,10 @@
from ETC import ExchangeConnection
from order_new import OrderManager
from position import PositionManager
from value import ValueManager
class Manager:
def __init__(self, exchange: ExchangeConnection):
self.positionMan = PositionManager()
self.orderMan = OrderManager(exchange, self.positionMan)
self.valueMan = ValueManager()