if i != j and i != k and j != k: if LP[i][j] * LP[j][k] > LP[i][k]: order.addBuy(conv(i, j), int(LP[i][j] * LP[j][k] * 100), LP[i][j]) order.addBuy(conv(j, k), int(LP[j][k] * 100), LP[j][k]) order.addSell(conv(i, k), 100, LP[i][k]) print 'trade' ''' if LP['EURUSD']*LP["USDJPY"] < LP["EURUSD"]: order.addBuy('EURUSD', 100) order.addBuy('USDJPY', 100) order.addSell('EURUSD', 100) cur = msg['market_state']['ticker'] order.addBuy(cur, 10, lastprice-0.1) order.addSell(cur, 10, lastprice) ''' def upd(msg, order): cur = msg['trades'][0]['ticker'] price = msg['trades'][0]['price'] a = cur[0:3] b = cur[3:6] LP[a][b] = price LP[b][a] = price t.onMarketUpdate = f t.onTrade = upd t.run()
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()
} 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()
elif ticker == 'USDJPY': if len(price_list['EURJPY'])>0: val = 1/price_list['EURUSD'][-1]*price_list['EURJPY'][-1] if val<(1-5*dx)*price: return {'trade':'yes','USDJPY':('sell',amount(val,price)),'EURUSD':('sell',amount(val,price)),'EURJPY':('buy',amount(val,price))} elif val>(1+5*dx)*price: return {'trade':'yes','USDJPY':('buy',amount(val,price)),'EURUSD':('buy',amount(val,price)),'EURJPY':('sell',amount(val,price))} if len(price_list['CHFJPY'])>0: val = price_list['USDCHF'][-1]*price_list['CHFJPY'][-1] if val<(1-5*dx)*price: return {'trade':'yes','USDJPY':('sell',amount(val,price)),'USDCHF':('buy',amount(val,price)),'CHFJPY':('buy',amount(val,price))} elif val>(1+5*dx)*price: return {'trade':'yes','USDJPY':('buy',amount(val,price)),'USDCHF':('sell',amount(val,price)),'CHFJPY':('sell',amount(val,price))} return {'trade':'no'} def amount(val, price): amt = abs(val-price)/price amt *= (20/(5*dx)) return floor(amt) t.onMarketUpdate = on_update t.onTrade = trade t.onTraderUpdate = get_info t.run()