コード例 #1
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()
コード例 #2
0
def load_case(msg, TradersOrder):
    global case_meta, orderbook
    print('Connected!')
    case_meta = msg['case_meta']
    securities = case_meta['securities'].keys()
    orderbook = {ticker: {'bids': {}, 'asks': {}, 'last_price': case_meta['securities'][ticker]['starting_price'], 'time': 0} for ticker in securities}

t.onAckRegister = load_case

## onAckModifyOrders

def order_confirmation(msg, TradersOrder):
    # print('Order accepted!')
    return

t.onAckModifyOrders = order_confirmation

## onNews

## onMarketUpdate

def market_update(msg, TradersOrder):
    global orderbook, time_last_order
    market_state = msg['market_state']
    ticker = market_state['ticker']
    orderbook[ticker]['bids'] = market_state['bids']
    orderbook[ticker]['asks'] = market_state['asks']
    orderbook[ticker]['last_price'] = market_state['last_price']
    orderbook[ticker]['time'] = market_state['time']
    if (time.time() - time_last_order < 1):
        return