首页 > 解决方案 > 使用 Python API 从另一个网络连接到盈透证券交易平台

问题描述

我正在尝试从另一个网络连接到我的 TWS 应用程序(在我的家庭网络上),但我的 TWS 应用程序没有收到任何连接。

我确保我启用了“ActiveX 和套接字客户端”,设置了主 API 客户端 ID,使用了正确的端口,甚至将我的公共 IP 地址添加为“受信任的 IP”,但我没有弹出接受连接的弹出窗口。

这是我的代码:

class IBapi(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)
    def tickPrice(self, reqId, tickType, price, attrib):
        if tickType == 2 and reqId == 1:
            print('The current ask price is: ', price)

def run_loop():
    app.run()

app = IBapi()
app.connect('PUBLIC_IPV4_ADDRESS', 7497, MASTER_API_CLIENT_ID)

我收到以下错误:


ERROR -1 502 Couldn't connect to TWS. Confirm that "Enable ActiveX and Socket EClients" 
is enabled and connection port is the same as "Socket Port" on the 
TWS "Edit->Global Configuration...->API->Settings" menu. Live Trading ports: 
TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations 
of version 954.1 or newer:  TWS: 7497; IB Gateway: 4002
ERROR 1 504 Not connected

有什么我错过的吗?

标签: pythonpython-3.xstockinteractive-brokers

解决方案


推荐阅读