盈透证券 (IB) 允许通过其 TWS API 连接其交易软件 Trader Workstation (TWS)。
您首先需要在计算机上启动 TWS,并在设置菜单中为端口 7496 上的“localhost”网络接口 (127.0.0.1) 启用 TWS API 访问。对于模拟交易(演示/测试账户),这是端口 7497默认情况下。这允许在运行 TWS 的同一台计算机上运行脚本。
您还可以使用 IB 网关来代替 IB TWS。默认使用端口 4002 进行模拟交易(模拟/测试账户),使用 4001 端口进行活跃/真实/真实账户。
检查这个:https://interactivebrokers.github.io/tws-api/initial_setup.html。
一旦您启动连接到您的交易平台的脚本,您还可以在您的交易平台上看到一个新选项卡“API”。
盈透证券的官方 TWS API 软件可在 https://www.interactivebrokers.com/en/trading/ib-api.php 上找到。
关于 TWS API 的讨论最好在 https://groups.io/g/twsapi 上进行。
另请查看常见问题解答:https://dimon.ca/dmitrys-tws-api-faq/。
ib_async 是另一个 Python API,用于通过 https://ib-api-reloaded.github.io/ib_async/api.html 上的文档连接到您的 TWS,并在 https://groups.io/g/insync 上进行讨论。 (原始项目位于 https://github.com/erdewit/ib_insync。)
要安装 ib_async,首先安装 python3,然后运行:
pip3 安装 ib_async
要稍后更新 ib_async,请运行:
pip3 install --升级 ib_async
pandas 是一个有用的附加 Python 库,用于数据分析和操作。
在 Debian 或 Ubuntu Linux 上安装:
sudo apt-get install python3-pandas
或者你可以通过 pip3 安装:
pip3安装pandas
对于更新运行:
pip3 install --升级 pandas
下载 DOW、SP500 和 Nasdaq100 指数所有公司的历史股票数据的示例脚本。
数据默认存储在子目录“data”中,因此请在调用此脚本之前创建该目录。
请参阅 stock-hist-data-download.py。
如何更新SP500和Nasdaq100指数列表:
python3 stock-hist-data-download.py --list-index > TMPFILE diff -u stock-hist-data-download.py TMPFILE
另请查看 https://github.com/deltaray-io/ib_dl。
自动运行 IB TWS:https://github.com/IbcAlpha/IBC
https://groups.io/g/ibcalpha
值得一看的 Github 主题:
https://github.com/topics/interactive-brokers
https://github.com/topics/tws
https://github.com/topics/tws-api
https://github.com/topics/ib-api
https://github.com/topics/ibapi
IB 红宝石:https://github.com/ib-ruby
https://github.com/andrey-zotov/ib_console
https://github.com/pavanmullapudy/InteractiveBrokers_TWS_API
https://github.com/pavanmullapudy/InteractiveBrokers_TWS_API/blob/master/futures%20and%20options/NIFTY%20ORB%20Trading%20System/tech_indicators.py
与 TWS API 有点不同的是灵活查询和下载/解析它们。
这里有一些围绕这个的项目:
https://github.com/MikePia/structjour