} pending_orders.append(new_order) except: print('Unable to parse headline: Unknown error') DEBUG = True algo_bot = None if len(sys.argv) >= 4: algo_bot = TradersBot(host=sys.argv[1], id=sys.argv[2], password=sys.argv[3]) # DEBUG = False CANCEL_TRADES = False else: algo_bot = TradersBot('127.0.0.1', 'trader0', 'trader0') algo_bot.onAckRegister = onAckRegister algo_bot.onMarketUpdate = onMarketUpdate algo_bot.onTraderUpdate = onTraderUpdate algo_bot.onTrade = onTrade algo_bot.onAckModifyOrders = onAckModifyOrders algo_bot.onNews = onNews if not DEBUG: def f(*args): return None print = f algo_bot.run()
print 'Data ', news if len(news) >= 2: x = [] d1 = np.array(news[-2]) d0 = np.delete(np.array(news[-1]),[2]) x = np.append(x, d0) x = np.append(x,d1) print 'Prediction: ', ridge.predict([x])[0] t.onNews = updatePredict def hi(msg,order): print "hey" t.onAckRegister = hi # ###################################################### # # each time AAPL trade happens for $x, make bid # # and ask at $x-0.02, $x+0.02, respectively # def marketMake(msg, order): # for trade in msg["trades"]: # if trade["ticker"] == 'AAPL': # px = trade["price"] # order.addBuy('AAPL', 10, px - 0.02) # order.addSell('AAPL', 10, px + 0.02) #t.onTrade = marketMake
def load_case(msg, TradersOrder): global model, res, case_meta, outcry_data print('Connected!') case_meta = msg['case_meta'] outcry_data = pd.read_csv('./outcry_data.csv') for name in outcry_data.columns: outcry_data[name] = proportional_change(outcry_data[name]) model = smf.ols( formula='TAMIT ~ GDP + CPI + RS + HS + PPI + MTIS + U + MS + PI', data=outcry_data) res = model.fit() t.onAckRegister = load_case ## onAckModifyOrders ## onNews def get_data(msg, TradersOrder): global res, model, outcry_data, pred_counter news = msg['news']['body'] news_items = news.split(';') news_items = [item.split() for item in news_items] names = [item[0] for item in news_items] numbers = [[float(item[4])] for item in news_items] reading = zip(names, numbers) reading = pd.DataFrame.from_items(reading)
def trade_method(msg, order): global MARKET print(MARKET['T85C']['price']) trade_dict = msg['trades'] for trade in trade_dict: security = MARKET[trade["ticker"]] security['price'] = trade["price"] # security['vol'] = calc_vol(security['type'] == 'C', trade['price'], 100, security['strike'], exp_time(), INTEREST_RATE) # 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 MARKET positions = msg['trader_state']['positions'] for security in positions.keys(): if random.random() < 0.5: quant = 10*random.randint(1, 10) order.addBuy(security, quantity=quant,price=MARKET[security]['price']) else: quant = 10*random.randint(1, 10) order.addSell(security, quantity=quant,price=MARKET[security]['price']) t.onAckRegister = ack_register_method t.onMarketUpdate = market_update_method t.onTraderUpdate = trader_update_method t.onTrade = trade_method #t.onAckModifyOrders = ack_modify_orders_method #t.onNews = news_method t.run()