bot split sex
This commit is contained in:
@@ -5,9 +5,10 @@
|
||||
# 3) Run in loop: while true; do ./bot.py --test prod-like; sleep 1; done
|
||||
import argparse
|
||||
import time
|
||||
from ETC import ExchangeConnection
|
||||
from ETC import Dir
|
||||
from ETC import team_name
|
||||
from ETC import ExchangeConnection, Dir, team_name
|
||||
from order_new import OrderManager
|
||||
from position import PositionManager
|
||||
from value import ValueManager
|
||||
|
||||
# ~~~~~============== CONFIGURATION ==============~~~~~
|
||||
# Replace "REPLACEME" with your team name!
|
||||
@@ -25,49 +26,26 @@ from ETC import team_name
|
||||
|
||||
|
||||
def main():
|
||||
global args, exchange, positionMan, orderMan, valueMan
|
||||
|
||||
args = parse_arguments()
|
||||
|
||||
exchange = ExchangeConnection(args=args)
|
||||
|
||||
# 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.
|
||||
positionMan = PositionManager()
|
||||
orderMan = OrderManager(exchange, positionMan)
|
||||
valueMan = ValueManager()
|
||||
|
||||
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)
|
||||
|
||||
# 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
|
||||
@@ -76,27 +54,45 @@ def main():
|
||||
elif message["type"] == "reject":
|
||||
print(message)
|
||||
elif message["type"] == "fill":
|
||||
print(message)
|
||||
on_fill(message)
|
||||
elif message["type"] == "book":
|
||||
if message["symbol"] == "VALE":
|
||||
on_book(message)
|
||||
|
||||
def on_fill(message):
|
||||
if (message["dir"] == Dir.BUY):
|
||||
positionMan.update_position(message["symbol"], message["size"])
|
||||
elif (message["dir"] == Dir.SELL):
|
||||
positionMan.update_position(message["symbol"], -message["size"])
|
||||
|
||||
def on_book(message):
|
||||
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):
|
||||
if message[side]:
|
||||
return message[side][0][0]
|
||||
# best_price("buy")
|
||||
# best_price("sell")
|
||||
|
||||
def best_price(side):
|
||||
if message[side]:
|
||||
return message[side][0][0]
|
||||
now = time.time()
|
||||
|
||||
vale_bid_price = best_price("buy")
|
||||
vale_ask_price = best_price("sell")
|
||||
|
||||
now = time.time()
|
||||
|
||||
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,
|
||||
}
|
||||
)
|
||||
if now > vale_last_print_time:
|
||||
vale_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")
|
||||
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)
|
||||
|
||||
|
||||
|
||||
# ~~~~~============== PROVIDED CODE ==============~~~~~
|
||||
|
||||
Reference in New Issue
Block a user