diff --git a/bot split/bot split.py b/bot split/bot split.py index 0c80876..5964877 100644 --- a/bot split/bot split.py +++ b/bot split/bot split.py @@ -6,9 +6,7 @@ import argparse import time from ETC import ExchangeConnection, Dir, team_name -from order_new import OrderManager -from position import PositionManager -from value import ValueManager +from manager import Manager # ~~~~~============== CONFIGURATION ==============~~~~~ # 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 # before it will start making good trades! +last_print_time = 0 def main(): - global args, exchange, positionMan, orderMan, valueMan - global vale_last_print_time + global last_print_time args = parse_arguments() exchange = ExchangeConnection(args=args) - positionMan = PositionManager() - orderMan = OrderManager(exchange, positionMan) - valueMan = ValueManager() + man = Manager(exchange) hello_message = exchange.read_message() print("First message from exchange:", hello_message) # - exchange.send_add_message(order_id=1, symbol="BOND", dir=Dir.BUY, price=990, size=1) - - vale_last_print_time = time.time() + last_print_time = time.time() while True: message = exchange.read_message() @@ -54,18 +48,20 @@ def main(): elif message["type"] == "reject": print(message) elif message["type"] == "fill": - on_fill(message) + on_fill(message, exchange, man) 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): - positionMan.update_position(message["symbol"], message["size"]) + man.positionMan.update_position(message["symbol"], message["size"]) elif (message["dir"] == Dir.SELL): - positionMan.update_position(message["symbol"], -message["size"]) + man.positionMan.update_position(message["symbol"], -message["size"]) -def on_book(message): - valueMan.set_value(message["symbol"], message["buy"][0][0], message["sell"][0][0]) +def on_book(message, man: Manager): + 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": def best_price(side): @@ -76,22 +72,22 @@ def on_book(message): now = time.time() - if now > vale_last_print_time: - vale_last_print_time = now + if now > last_print_time: + last_print_time = now - valePos = positionMan.get_position("VALE") - valeBid = valueMan.get_bid("VALE") - valeAsk = valueMan.get_ask("VALE") - valbzPos = positionMan.get_position("VALBZ") - valbzBid = valueMan.get_bid("VALBZ") - valbzAsk = valueMan.get_ask("VALBZ") + valePos = man.positionMan.get_position("VALE") + valeBid = man.valueMan.get_bid("VALE") + valeAsk = man.valueMan.get_ask("VALE") + valbzPos = man.positionMan.get_position("VALBZ") + valbzBid = man.valueMan.get_bid("VALBZ") + valbzAsk = man.valueMan.get_ask("VALBZ") FEE = 10 - if (valePos * positionMan.get_position["VALE"] + FEE < - valbzPos * positionMan.get_position["VALBZ"]): - orderMan.convert("VALE", Dir.SELL, valePos) - if (valePos * positionMan.get_position["VALE"] > - valbzPos * positionMan.get_position["VALBZ"] + FEE): - orderMan.convert("VALBZ", Dir.SELL, valbzPos) + if (valePos * man.positionMan.get_position["VALE"] + FEE < + valbzPos * man.positionMan.get_position["VALBZ"]): + man.orderMan.convert("VALE", Dir.SELL, valePos) + if (valePos * man.positionMan.get_position["VALE"] > + valbzPos * man.positionMan.get_position["VALBZ"] + FEE): + man.orderMan.convert("VALBZ", Dir.SELL, valbzPos) diff --git a/bot split/manager.py b/bot split/manager.py new file mode 100644 index 0000000..ecb4e9b --- /dev/null +++ b/bot split/manager.py @@ -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() \ No newline at end of file