Ibpy: how to capture data returned from reqAccountSummary

柔情痞子 提交于 2019-12-04 14:03:19

You cannot do this in the main function, since app.run listens to responses from the TWS. Once you have set up all the callbacks as you correctly did, the main function will be looping forever in app.run.

You have to put your code directly into the accountSummary function. This is how these kind of programs work, you put your logic directly into the callback functions. You can always assign self.myTotalCashValue = value to make it available to other parts of your class, or even to another thread.

-- OR --

You run app.run in a thread and wait for the value to return, e.g.

add self._myTotalCashValue = value to accountSummary, import threading and time and then add something like this in main:

t = threading.Thread(target=app.run)
t.daemon = True
t.start()
while not hasattr(app,"_myTotalCashValue"):
    time.sleep(1)
print(app._myTotalCashValue)

As usual with threads, you have to be a bit careful with shared memory between app and main.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!