元大期货API连接程序调试问题及修复方案
元大期货Yuanta Futures API登录GUI无响应及AttributeError问题解决
问题背景
团队调试元大期货API连接代码数周,已进入收尾阶段。在Anaconda Spyder中运行程序时,会弹出GUI登录窗口,但几秒后无响应,需强制关闭;输入账号密码后还会触发AttributeError: SetMktLogon错误,初步怀疑是缺失函数/包或未继承相关对象导致。
相关代码
class MyApp(wx.App): def __init__(self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True): super().__init__(redirect, filename, useBestVisual, clearSigInt) self.keepGoing = True def MainLoop(self, run_func): # Create an event loop and make it active. If you are # only going to temporarily have a nested event loop then # you should get a reference to the old one and set it as # the active event loop when you are done with this one... evtloop = wx.GUIEventLoop() old = wx.EventLoop.GetActive() wx.EventLoop.SetActive(evtloop) # This outer loop determines when to exit the application, # for this example we let the main frame reset this flag # when it closes. while self.keepGoing: # At this point in the outer loop you could do # whatever you implemented your own MainLoop for. It # should be quick and non-blocking, otherwise your GUI # will freeze. # call_your_code_here() run_func () while not q.empty(): next_job = q.get() DoJob (Bot, next_job) # This inner loop will process any GUI events # until there are no more waiting. while evtloop.Pending(): evtloop.Dispatch() # Send idle events to idle handlers. You may want to # throttle this back a bit somehow so there is not too # much CPU time spent in the idle handlers. For this # example, I'll just snooze a little... time.sleep(0.10) evtloop.ProcessIdle() wx.EventLoop.SetActive(old) def Oninit(self): self.keepGoing = True return True def run_job(): while not q.empty(): next_job = q.get() DoJob(Bot, next_job) if __name__ == "__main__": app=MyApp() frame = AppFrame(None, title='YuantaQuoteAPI Sample',size = (670,370)) frame.Show(True) Bot = StockBot(frame.Handle) app.MainLoop(run_job)
解决方法
通过创建32位Python环境,并安装适配的32位wxPython后,问题完全解决,GUI可正常响应并完成登录操作。
内容的提问来源于stack exchange,提问作者NCUMA Brian
相关产品推荐
相关产品推荐

