def update_trader_info_looped(runtime): """ 循环版本更新账户信息。 """ while True: runtime['trader_info_full'] = broker_stub.get_trader(api.TraderRequest_get_trader_full()) runtime['account_info'] = runtime['trader_info_full'].account runtime['order_info'] = tradingObjects.order_info(runtime['trader_info_full']) runtime['positions_info'] = tradingObjects.positions_info(runtime['trader_info_full']) runtime['trader_info_count'] += 1
def update_trader_info(runtime): """ 更新账户信息。 """ #//update trader info runtime['trader_info_full'] = broker_stub.get_trader(api.TraderRequest_get_trader_full()) runtime['account_info'] = runtime['trader_info_full'].account runtime['order_info'] = tradingObjects.order_info(runtime['trader_info_full']) runtime['positions_info'] = tradingObjects.positions_info(runtime['trader_info_full']) runtime['trader_info_count'] += 1
TraderRequest_cancel_order = proto_wrapper.TraderRequest_cancel_order( order_id=tuple(response_new_order.orders.orders.keys())[0]) response_cancel_order = broker_stub.cancel_order(TraderRequest_cancel_order) print(response_cancel_order) print("##########################################") """ 获取增量账户信息和完整的账户信息 """ TraderRequest_get_trader_incremental = proto_wrapper.TraderRequest_get_trader_inc( ) response_get_trader_incremental = broker_stub.get_trader( TraderRequest_get_trader_incremental) print(response_get_trader_incremental) print("##########################################") TraderRequest_get_trader_full = proto_wrapper.TraderRequest_get_trader_full() response_get_trader_full = broker_stub.get_trader( TraderRequest_get_trader_full) print(response_get_trader_full) print("##########################################") #获取data流对象 market_data_stream = md_stub.subscribe( broker_pb2.TraderRequest(trader_id=33, trader_pin='jY0RyHyK9')) if market_data_stream.is_active: while True: market_data_snapshot = market_data_stream.next() for insturment_data in market_data_snapshot.instruments: print("[%s] GET instrument %s at timestamp %s" % (ctime(), insturment_data.symbol, insturment_data.timestamp)) sleep(1)
data_stub = broker_pb2_grpc.MarketDataStub(CHANNEL_DATA) #//创建客户端 data_stream = data_stub.subscribe( broker_pb2.TraderRequest(trader_id=ID, trader_pin=PIN)) api.set_stub(broker=broker_stub, data=data_stub) api.set_stream(data_stream) print("Set up stub used %.9f" % (time_ns() - time_now)) time_now = time_ns() #//测试行情订阅 for i in range(1000): snapshot_new = data_stream.next() print('Subscribe one snapshot used %.9f' % ((time_ns() - time_now) / 1000)) time_now = time_ns() #//下单 for i in range(1000): broker_stub.new_order(api.TraderRequest_new_order('A002', 0, 0, 1, 100)) print('Place one new order used %.9f' % ((time_ns() - time_now) / 1000)) time_now = time_ns() #//获取用户信息 for i in range(1000): info = broker_stub.get_trader(api.TraderRequest_get_trader_full()) print('Get my info used %.9f' % ((time_ns() - time_now) / 1000))