import tradersbot as tt import time, threading # news trading t = tt.TradersBot('52.90.204.149', 'UTexas2', '45396823') prices = {} history = {} # ticker : [isBuy, quantity, price] order_id = [] info = [] last_trade = 0.0 last = time.time() # Initialize variables: positions, expectations, future customer orders, etc position_limit = 5000 case_length = 450 cash = 0 position_lit = 0 position_dark = 0 topBid = 0 topAsk = 0 # Keeps track of prices SECURITIES = {} UNDERLYINGS = {} MARKET_STATES = {} TRADER_STATE = {} end_time = None
import tradersbot as tt import random t = tt.TradersBot(host='127.0.0.1', id='trader0', password='******') # Keeps track of prices SECURITIES = {} # Initializes the prices def ack_register_method(msg, order): global SECURITIES security_dict = msg['case_meta']['securities'] for security in security_dict.keys(): if not (security_dict[security]['tradeable']): continue SECURITIES[security] = security_dict[security]['starting_price'] # Updates latest price def market_update_method(msg, order): global SECURITIES SECURITIES[msg['market_state'] ['ticker']] = msg['market_state']['last_price'] # Buys or sells in a random quantity every time it gets an update # You do not need to buy/sell here def trader_update_method(msg, order): global SECURITIES
import numpy as np import pandas as pd from scipy.stats import norm from scipy.optimize import brentq import re import tradersbot as tt import sys import datetime t = tt.TradersBot(host=sys.argv[1], id=sys.argv[2], password=sys.argv[3]) # Keeps track of prices SECURITIES = {} HIST_VOL_CURVE = {} TIME = 0 UNDERLYING_TICKER = 'TMXFUT' TRADING_THRESHOLD = 0.05 LAST_ORDER_TIME = datetime.datetime.now() ONE_SECOND = datetime.timedelta(seconds=1) # Supporting Black Scholes def d1(S, K, t, r, sigma): # see Hull, page 292 """Calculate the d1 component of the Black-Scholes PDE. """ N = norm.cdf sigma_squared = sigma * sigma numerator = np.log(S / float(K)) + (r + sigma_squared / 2.) * t denominator = sigma * np.sqrt(t) if not denominator:
import tradersbot as tt import random import numpy as np import sklearn as sk import pandas as pd import pickle import sys from copy import deepcopy ########################################################### # Make sure you run pip install tradersbot before running # ########################################################### # Make a tradersbot t = tt.TradersBot(host='3.90.186.196', id='Harvard4', password='******') # Constants POS_LIMIT = 500 ORDER_LIMIT = 100 # Hyperparameters START_RELIABILITY = 30 MIN_RELIABILITY = 5 MEDIUM_RELIABILITY = 10 DEFAULT_CONFIDENCE = 5 MAX_TRADE_SZ = 1000 EDGE_DEMANDED = 0.5 MIN_EDGE_REQUIRED = 0.5
heapq.heappush(PREDICTIONS, (prediction_time, ticker, source, prediction_price)) ### HELPER FUNCTIONS def deviation_to_probability(deviation): return math.exp(-EPSILON * deviation**2) def clean_up_positions(current_time, order): while TO_CLEAR and TO_CLEAR[0][0] <= current_time: _, ticker, volume = heapq.heappop(TO_CLEAR) order.addBuy(ticker=ticker, quantity=volume, price=None) def update_deviations(current_time): while PREDICTIONS and PREDICTIONS[0][0] <= current_time: _, ticker, source, prediction_price = heapq.heappop(PREDICTIONS) difference = prediction_price - PRICES[ticker] difference /= PRICES[ticker] NEWS_DEVIATIONS[source] = NEWS_DEVIATIONS.get(source, 0) + difference ### OVERRIDE & RUN bot = tt.TradersBot(**LOGIN) bot.onAckRegister = ack_register_method bot.onMarketUpdate = market_update_method bot.onTraderUpdate = trader_update_method bot.onNews = news_method bot.run()
import tradersbot as tt import time import numpy import pickle as pkl import random import string import sys i = int(sys.argv[1]) time.sleep(5) t = tt.TradersBot(host='127.0.0.1', id='darkbot0', password='******') tradelist = pkl.load(open('./utils/pkls/trade{0}.pkl'.format(i), 'r')) tick = 0 ticks = {} tokens = {} ids = {} def f(order): global tick global tokens global ticks global ids if tick - 1 in ids: xx = ids[tick - 1] for cancel in xx: order.addCancel(cancel[1], cancel[0]) token = ''.join( random.choice(string.ascii_uppercase + string.digits)