Beispiel #1
0
		count = 0

def status(msg, order):
	global TMX
	global endTime
	totalDelta = 0.0
	totalVega = 0.0
	for key in msg['trader_state']['positions']:
		quant = msg['trader_state']['positions'][key]
		print key, quant
		try:
			K = int(key[1:-1])
		except:
			continue
		v = vols[K]
		if vols[K] == 0.0 or vols[K] == None:
			v = 20
		c = mibian.BS([TMX, K, 0.0, (endTime-time.time())/15.0], volatility = v)
		type = key[-1]
		if type == 'P':
			totalDelta += (c.putDelta)*quant
		else:
			totalDelta += (c.callDelta)*quant
		totalVega += c.vega*quant
	print 'Total delta: ' + str(totalDelta*100)
	print 'Total vega: ' + str(totalVega*100)

t.onMarketUpdate = upd
t.onTraderUpdate = status

t.run()
Beispiel #2
0
                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()
Beispiel #3
0
        }
        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()
Beispiel #4
0
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()
Beispiel #5
0
    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()
        resp = check_cycle(cycle)
        if resp[0] == 'BUY':
            order_size = resp[4]
            TradersOrder.addBuy(cycle[0], order_size)#, price=resp[1])
            TradersOrder.addBuy(cycle[1], order_size)#, price=resp[2])
            TradersOrder.addSell(cycle[2], order_size)#, price=resp[3])
            time_last_order = time.time()
        elif resp[0] == 'SELL':
            order_size = resp[4]
            TradersOrder.addSell(cycle[0], order_size)#, price=resp[1])
            TradersOrder.addSell(cycle[1], order_size)#, price=resp[2])
            TradersOrder.addBuy(cycle[2], order_size)#, price=resp[3])
            time_last_order = time.time()
    return

t.onMarketUpdate = market_update

## onTraderUpdate

def adjust_params(msg, TradersOrder):
    global orderbook, time_last_clear, time_last_threshold_update, current_pnl, pnl_deltas, arb_threshold, DELTASHIFT
    counter = 0
    # clear 10 old orders every 3 seconds
    if (time.time() - time_last_clear > 3):
       if 'open_orders' in msg:
            for order in msg['open_orders']:
                if counter > 10:
                    break
                order_id = order.split(':')
                ticker = order_id[0]
                id_num = order_id[1]