: | : | :期货量化学习 | :期货量化 |
返回列表 发帖

TWS API v9.72 在线文档 —— 初始准备【翻译】

TWS API v9.72 在线文档 —— 初始准备【翻译】

Initial Setup

【译】 前期准备

The TWS API is an interface to IB's standalone trading applications, TWS and IB Gateway. These are both standalone, Java-based trading applications which were designed to require the use of a graphical user interface for the security of user authentication. For that reason, "headless" operation is not supported.

【译】 TWS API则是TWS客户端及IB网关的API。TWS客户端以及IB网关都是独立的,基于Java的交易系统,以图形化的用户界面形式确保用户的身份安全,因此,“无头”操作是不支持的。

The Trader Workstation

【译】 交易者工作站

Our market maker-designed IB Trader Workstation (TWS) lets traders, investors, and institutions trade stocks, options, futures, forex, bonds and funds on over 100 markets worldwide from a single account. The TWS API is a programming interface to TWS and as such, it forcefully requires a TWS to connect to. To use version 9.72+ of the API, it is necessary to have TWS version 952 or higher.

【译】 我们设计的IB交易工作站(TWS)可以让投资者以及机构使用一个账户在全球100多个市场交易股票、期权、外汇、债券以及基金。TWS API 是TWS及IB网关的编程接口,因此要求用户必须先连接至TWS。使用9.72+版本的API,需要TWS 952或更高的版本。

The IB Gateway

【译】 IB网关

As an alternative to TWS for API users, IB also offers IB Gateway (IBG). From the perspective of an API application, IB Gateway and TWS are essentially identical; both represent a server to which an API client application can open a socket connection once the user has first authenticated a session.

【译】 作为连接TWS的替代方案,API开发者还可以使用赢透证券提供的IB网关。从API应用看,IB网关于TWS的功能基本相同,都需要通过验证后,建立客户端与服务器的会话。

In either case (TWS or IBG), the user must authenticate a session by manually entering credentials into the login window- for security reasons, a headless session of TWS or IBG without a GUI is not supported. From the user's perspective, IB Gateway is a lighter application which consumes about 40% fewer resources and has some advantages over using an API connection to TWS- most noticeably, it does not have the designed limitation that an autologoff time is programmed when it must shutdown to be restarted. IB Gateway does not update automatically and it is recommended to upgrade to a current version from the website every few months or less.

【译】 在任何情况下(TWS或网关),用户都必须手段输入账户信息并登陆系统。出于安全原因,不允许绕过TWS或网关的GUI登陆界面的无头操作。从开发者角度考虑,IB网关是一个轻量级应用程序,与TWS相比,IB 网关只消耗60%左右的计算资源。而且还有其他相较于TWS显而易见的优点,当必须关闭以重启时,它不存在自动注销时间的编程限制。

IB网关不会自动更新,因此建议用户每隔几个月或更短的时间从赢透的官网升级到最新版本。

There are however some times in which it will also be necessary to restart IB Gateway, for instance if there is a change to IB's contract database because of a ticker symbol changed or the introduction of a new contract, it will be necessary to restart IBG to access the updated contract information.

【译】 然而,有些时候还需要重新启动IB网关,例如,由于更改了代码标志或引入了新合同,IB的合同数据库发生变化,因此有必要重新启动网关,以此获取最新的信息。

The advantages of TWS over IBG is that it provides the end user with many tools (Risk Navigator, OptionTrader, BookTrader, etc) and a graphical user interface which can be used to monitor an account or place orders. For beginning API users, it is recommended to first become acquainted with TWS before using IBG.

【译】 较于网关,TWS为用户提供了更多的工具(Risk Navigator,OptionTrader,BookTrader等)以及可用于监控账户或者下订单的图形界面。对于初学者而言,建议使用网关之前先熟悉TWS。

For simplicity, this guide will mostly refer to the TWS although the reader should understand that for the TWS API's purposes, TWS and IB Gateway are synonymous.

【译】 为简洁起见,本手册将更多的介绍TWS,但用户应该明白对于TWS API:TWS与IB网关是一回事。

Enable API connections

【译】 启动API连接

Before any client application can connect to the Trader Workstation, the TWS needs to be configured to listen for incoming API connections on a very specific port. By default when TWS is first installed it will not allow API connections. IBG by contrast accepts socket-based API connections by default. To enable API access in TWS, navigate to the TWS' API settings at Edit -> Global Configuration -> API -> Settings and make sure the "Enable ActiveX and Socket Clients" option is activated as shown below:

【译】 在客户端建立起与TWS平台的连接前,需要配置TWS对API消息的监听端口。默认情况下,TWS在安装之后是没有启动这一功能的。而IB网关则是默认接收基于socket的API连接。为了让TWS启动对API消息的监听,需要在 Edit(编辑)-> Global Configuration(全局配置)-> API -> Settings(设置), 通过点选“Enable ActiveX and Socket Clients”激活该功能。




Also important to mention is the "Socket port". By default a production account TWS session will be set for socket port 7496, and a paper account session will listen on socket port 7497.

【译】 需要提到的是,“Socket Port”,通常,7496为默认的端口号,而模拟交易账户会使用7497端口。

However these are just default values chosen because they are almost always available on any computer. They can be changed to any open socket port, as long as the socket ports specified in the API client and TWS settings match.

【译】 作为默认端口号,它在任意电脑上都是可用的。当然,它也可以被修改为其他端口号,只要保证客户端端口号与TWS的设置一致。

If there are multiple TWS sessions on one computer, the socket port is used to distinguish the TWS session. Since only one application can listen on one port at a time you will need to assign different ports to each running TWS.

【译】 如果在同一电脑上有多个会话,TWS会使用端口号以区分不同的会话信息。由于一个应用程序只能在一个端口上监听消息,因此,你需要为每个正在运行的TWS分配不同的端口号。

Important: when running paper and live TWS on the same computer, make sure your client application is connecting to the right TWS!

【译】 重要信息:无论您使用模拟账户还是真实账户,请确保正确地连接到TWS!

Read Only API

【译】 只读API

The API Settings dialogue allows you to configure TWS to note accept API orders with the "Read Only" setting. By default, "Read Only" is enabled as an additional precautionary measure. Information about orders is not available to the API when read-only mode is enabled.

【译】 API Setting会话框允许你配置TWS接受API指令为“只读模式”。默认情况下,“只读模式”是一种预防措施。关于订单的信息不适用于被配置为“只读模式”下的API。

Master Client ID

【译】 主客户端ID

By default the "Master Client ID" field is unset. To specify that a certain client should automatically receive updates about all open orders, as well as commission reports from orders placed from all clients, the client's ID should be set as the Master Client ID in TWS or IBG Global Configuration. The clientID is specified from an API client application in the initial function call to IBApi::EClientSocket::eConnect.

【译】 默认情况下,“主客户端ID”字段是没有设置的。如果需要指定特定的客户端自动接收关于所有未结订单的最新信息,以及来自订单的佣金报告。则应该在TWS或网关的全局配置中,设置该客户端的ID为“主客户端ID”。在IBApi :: EClientSocket :: eConnect的初始函数调用中,客户端ID由API客户端应用程序指定。

Installing the API source

【译】 安装API

The API itself can be downloaded and installed from:

【译】 API可以从以下链接下载并安装

http://interactivebrokers.github.io/

Many third party applications already have their own version of the API which is installed in the process of installing the third party application. If using a third party product, it should first be verified if the API must be separately installed and what version of the API is needed- many third party products are only compatible with a specific API version.

【译】 许多第三方应用,在安装时已经拥有自己的API版本。如果使用第三方产品,则应首先验证API是否必须单独安装,并且需要哪个版本的API。许多第三方产品仅于特定版本的API兼容。

The Windows version of the API installer will create a directory "C:\TWS API\" for the API source code in addition to automatically copying two files into the Windows directory for the ActiveX/DDE and C++ APIs.
It is important that the API installs to the C: drive, as otherwise API applications may not be able to find the associated files. The Windows installer also copies compiled dynamic linked libraries (DLL) of the 32 versions of the ActiveX control TWSLib.dll, C# API CSharpAPI.dll, and C++ API TwsSocketClient.dll.

【译】 Windows版本的API安装程序会在“C:\TWS API\”创建目录,以存放API的源代码以及 ActiveX/DDE 和 C++ APIs。
将API安装到C盘是非常重要的,否则其他的API应用程序可能会无法找到对应的API文件。Windows安装程序同时也会拷贝32位的ActiveX动态链接库(DLL)——TWSLiberal.dll以及C++API——TwsSocketClient.dll。

Starting in version 973.03, the Windows installer also installs a 32 bit version of the RTDServer control. To use a 64 bit application which loads the API as a dynamic library, it is necessary to compile and install a 64 bit version of the desired control.

【译】 从973.03版开始,Windows安装程序同时也会安装RTDServer控件。 如果要使用将API加载为动态库的64位应用程序,需要编译和安装所需控件的64位版本。

Changing the installed API version

【译】 修改安装的API版本(Windows Only)

(On Windows Only)

If a different version of the ActiveX (v9.71 or lower) or C++ API is required than the one currently installed on the system, there are additional steps required to uninstall the previous API version to manually remove a file called "TwsSocketClient.dll":

【译】 如果系统中存在不同版本的ActiveX(9.71或更低的版本)或C++ API要求的其他控件,那么就需要一些额外的操作,卸载过往版本的API以及手动删除“TwsSocketClient.dll”

  • Uninstall the API from the "Add/Remove Tool" in the Windows Control Panel as usual
  • Delete the C:\TWS API\ folder if any files are still remaining to prevent a version mismatch.
  • Locate the file "C:\Windows\SysWOW64\TwsSocketClient.dll". Delete this file.
  • Restart the computer before installing a different API version.

【译】

  • 从Windows控制面板“添加/删除”卸载API
  • 手动删除“C:\TWS API\”文件夹及可能残留的文件
  • 找到"C:\Windows\SysWOW64\TwsSocketClient.dll",并删除它
  • 重启电脑,再次尝试安装

论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
 
期货论坛 - 版权/免责声明   1.本站发布源码(包括函数、指标、策略等)均属开放源码,用意在于让使用者学习程序化语法撰写,使用者可以任意修改语法內容并调整参数。仅限用于个人学习使用,请勿转载、滥用,严禁私自连接实盘账户交易
  2.本站发布资讯(包括文章、视频、历史记录、教材、评论、资讯、交易方案等)均系转载自网络主流媒体,内容仅为作者当日个人观点,本网转载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。本网不对该类信息或数据做任何保证。不对您构成任何投资建议,不能依靠信息而取代自身独立判断,不对因使用本篇文章所诉信息或观点等导致的损失承担任何责任。
  3.本站发布资源(包括书籍、杂志、文档、软件等)均从互联网搜索而来,仅供个人免费交流学习,不可用作商业用途,本站不对显示的内容承担任何责任。请在下载后24小时内删除。如果喜欢,请购买正版,谢谢合作!
  4.龙听期货论坛原创文章属本网版权作品,转载须注明来源“龙听期货论坛”,违者本网将保留追究其相关法律责任的权力。本论坛除发布原创文章外,亦致力于优秀财经文章的交流分享,部分文章推送时若未能及时与原作者取得联系并涉及版权问题时,请及时联系删除。联系方式:http://www.qhlt.cn/thread-262-1-1.html
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

返回列表