def send_req(self, function: int, req: dict) -> int: """""" packer = py_t2sdk.pyIF2Packer() packer.BeginPack() for Field in req.keys(): packer.AddField(Field) for value in req.values(): packer.AddStr(str(value)) packer.EndPack() msg = py_t2sdk.pyIBizMessage() msg.SetFunction(function) msg.SetPacketType(0) msg.SetContent(packer.GetPackBuf(), packer.GetPackLen()) n = self.connection.SendBizMsg(msg, 1) packer.FreeMem() packer.Release() msg.Release() return n
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