def OnReceivedBizMsg(self, hSend, sBuff, iLenght) -> None: """""" biz_msg = py_t2sdk.pyIBizMessage() biz_msg.SetBuff(sBuff, iLenght) ret = biz_msg.GetReturnCode() if not ret: function = biz_msg.GetFunction() buf, len = biz_msg.GetContent() unpacker = py_t2sdk.pyIF2UnPacker() unpacker.Open(buf, len) data = unpack_data(unpacker) self.td_api.on_callback(function, data) unpacker.Release() else: buf, len = biz_msg.GetContent() unpacker = py_t2sdk.pyIF2UnPacker() unpacker.Open(buf, len) if unpacker: data = unpack_data(unpacker) self.td_api.on_error(data) unpacker.Release() else: error_msg = str(biz_msg.GetErrorInfo(), encoding="gbk") msg = f"请求失败,信息:{error_msg}" self.td_api.gateway.write_log(msg) biz_msg.Release()
def OnReceived(self, topic, sBuff, iLen) -> None: """""" biz_msg = py_t2sdk.pyIBizMessage() biz_msg.SetBuff(sBuff, iLen) buf, len = biz_msg.GetContent() unpacker = py_t2sdk.pyIF2UnPacker() unpacker.Open(buf, len) data = unpack_data(unpacker) self.td_api.on_callback(topic, data) unpacker.Release() biz_msg.Release()
def subcribe_topic(self, biz_name: str, topic_name: str) -> int: """""" # Create subscrbe callback sub_callback = py_t2sdk.pySubCallBack( "vnpy-xx.gateway.hsoption.hsoption_gateway", "TdSubCallback" ) sub_callback.initInstance() # Create subscriber ret, subscriber = self.connection.NewSubscriber( sub_callback, biz_name, 5000 ) if ret != 0: error_msg = str(self.connection.GetMCLastError(), encoding="gbk") msg = f"订阅推送失败:{error_msg}" self.gateway.write_log(msg) return # Set subscribe parameters sub_param = py_t2sdk.pySubscribeParamInterface() sub_param.SetTopicName(topic_name) sub_param.SetFilter("branch_no", str(self.branch_no)) sub_param.SetFilter("fund_account", str(self.userid)) # Pack data packer = py_t2sdk.pyIF2Packer() packer.BeginPack() packer.AddField("fund_account") packer.AddField("password") packer.AddStr(self.userid) packer.AddStr(self.password) packer.EndPack() # Start subcribe unpacker = py_t2sdk.pyIF2UnPacker() result = subscriber.SubscribeTopic(sub_param, 5000, unpacker, packer) packer.FreeMem() packer.Release() unpacker.Release() sub_param.Release() return result