def main(): json_file = open("config.json") config = json.load(json_file) json_file.close() print(config) investor_id = config["investor_id"] broker_id = config["broker_id"] password = config["password"] server = config["trader_server"] app_id = config["app_id"] auth_code = config["auth_code"] if check_address_port(server): user_trader = Trader(broker_id=broker_id, app_id=app_id, auth_code=auth_code, investor_id=investor_id, password=password) user_trader.Create() user_trader.RegisterFront(server) user_trader.SubscribePrivateTopic(2) # 只传送登录后的流内容 user_trader.SubscribePrivateTopic(2) # 只传送登录后的流内容 user_trader.Init() print("trader api started") print("trading day:", user_trader.GetTradingDay()) if user_trader.login: investor = ApiStructure.QryInvestorField(broker_id, investor_id) user_trader.ReqQryInvestor(investor, user_trader.request_id) # position = ApiStructure.QryInvestorPositionField.from_dict({"BrokerID": broker_id, # "InvestorID": investor_id}) # user_trader.ReqQryInvestorPosition(position, user_trader.request_id) settlement_info = ApiStructure.SettlementInfoConfirmField.from_dict( { "BrokerID": broker_id, "InvestorID": investor_id }) user_trader.ReqSettlementInfoConfirm(settlement_info, user_trader.request_id) trader_account = ApiStructure.QryTradingAccountField( BrokerID=broker_id, InvestorID=investor_id) user_trader.ReqQryTradingAccount(trader_account, user_trader.request_id) user_trader.Join() else: print("trader server down")
def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast): if pRspInfo.ErrorID != 0: print("Trader OnRspUserLogin failed error_id=%s msg:%s", pRspInfo.ErrorID, pRspInfo.ErrorMsg.decode('gbk')) else: print("Trader user login successfully") inv = ApiStructure.QryInvestorField(BrokerID=self.broker_id, InvestorID=self.investor_id) self.ReqQryInvestor(inv, self.inc_request_id()) req = ApiStructure.SettlementInfoConfirmField( BrokerID=self.broker_id, InvestorID=self.investor_id) self.ReqSettlementInfoConfirm(req, self.inc_request_id()) self.Join()
def OnRspUserLogin(self, pRspUserLogin, pRspInfo, nRequestID, bIsLast): """用户登录响应""" if pRspInfo.ErrorID != 0: print("交易端 OnRspUserLogin failed error_id=%s msg:%s", pRspInfo.ErrorID, pRspInfo.ErrorMsg.decode('gbk')) else: print("交易端 user login successfully", nRequestID) inv = ApiStructure.QryInvestorField(BrokerID=self.broker_id, InvestorID=self.investor_id) self.ReqQryInvestor(inv, self.inc_request_id()) print("查询投资者信息.", "请求编号:", self.request_id) req = ApiStructure.SettlementInfoConfirmField.from_dict({ "BrokerID": self.broker_id, "InvestorID": self.investor_id }) self.ReqSettlementInfoConfirm(req, self.inc_request_id())