[英]Interactive Brokers API - How to disconnect an existing connection of IB Gateway and establish a new connection using Python?
I am testing Interactive Brokers Python API in a Hobby project.我正在一个爱好项目中测试盈透证券 Python API。 I am using Interactive Brokers Gateway (rather TWS).我正在使用盈透证券网关(而不是 TWS)。 My project is a simple Django-based application.我的项目是一个简单的基于 Django 的应用程序。 I can connect successfully and receive real-time data using the method reqMktData()
.我可以使用reqMktData()
方法成功连接并接收实时数据。 Everything is OK so far.到目前为止一切都很好。
But when I refresh the page it shows 504 Not Connected , although in IB Gateway it shows there is a running connection.但是当我刷新页面时它显示504 Not Connected ,尽管在 IB Gateway 中它显示有一个正在运行的连接。 To stop this, During a page reload I am trying to disconnect the previous connection using the Eclient disconnect()
method available in the API, but it can not disconnect the running connection.为了阻止这种情况,在页面重新加载期间,我尝试使用 API 中可用的Eclient disconnect()
方法断开先前的连接,但它无法断开正在运行的连接。
Can anyone have any idea how can I disconnect a running connection in IB Gateway and start a new connection?谁能知道如何断开 IB 网关中正在运行的连接并开始新的连接?
Changing my client Id seems to fix it for me.更改我的客户 ID 似乎可以为我解决问题。 Maybe toggle back and forth between 2 of them?也许在其中两个之间来回切换?
To disconnect from TWS IBAPI
(python)断开TWS IBAPI
(python)
ib.conn = None
设置属性ib.conn = None
ib.disconnect()
function,然后调用ib.disconnect()
function,stop()
of EWrapper
class然后回调 function 将stop()
的EWrapper
class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.