Board logo

标题: TWS API v9.72 在线文档 —— 软件架构【翻译】 [打印本页]

作者: 龙听    时间: 2018-3-27 10:07     标题: TWS API v9.72 在线文档 —— 软件架构【翻译】

【译者注】 IB API 在线文档包含有 C#/Java/CPP/Python 等版本,程序的调用方法基本一致。但因为时间有限,不能翻译全部的版本,而且考虑到适用性和性能,因此在这个版本里,主要围绕着 Java API 进行翻译。您可以从 IB API 在线文档中找到自己熟悉的语言部分,差异不会很大。

http://interactivebrokers.github.io/tws-api/introduction.html
API Software Architecture
【译】 API 软件架构

EClientSocket and EWrapper Classes
Once the TWS is up and running and actively listening for incoming connections we are ready to write our code. This brings us to the TWS API's two major classes: the IBApi.EWrapper interface and the IBApi.EClientSocket

【译】 当TWS运行后,并开始监听来自我们程序的消息请求。这里,将介绍两个重要的类,IBApi.EWrapper 接口和 IBApi.EClientSocket。

Implementing the EWrapper Interface
【译】 对EWrapper接口的实现

The IBApi.EWrapper interface is the mechanism through which the TWS delivers information to the API client application. By implementing this interface the client application will be able to receive and handle the information coming from the TWS. For further information on how to implement interfaces, refer to your programming language's documentation.

【译】 IBApi.EWrapper 接口是客户端接收来自TWS消息的机制。通过对它的实现,客户端能够获取以及处理来自TWS的消息。更多关于如何实现IBApi.EWrapper的方法,请参考您自己的编程语言的相关说明。

public class EWrapperImpl implements EWrapper
The EClientSocket Class
The class used to send messages to TWS is IBApi.EClientSocket. Unlike EWrapper, this class is not overriden as the provided functions in EClientSocket are invoked to send messages to TWS. To use EClientSocket, first it may be necessary to implement the IBApi.EWrapper interface as part of its constructor parameters so that the application can handle all returned messages. Messages sent from TWS as a response to function calls in IBApi.EClientSocket require a EWrapper implementation so they can processed to meet the needs of the API client.

【译】 EClientSocket 类用于向TWS发送消息,与 EWrapper 不同,它不需要被重写,因为它提供的函数将被用于向TWS发送消息。为了使用EclientSocket,首先需要实现 IBApi.EWrapper 的接口,并作为参数传递至构造函数中,从而使得程序能够处理全部的返回消息。此外对于程序来说,从TWS发送的消息,需要依靠实现 EWrapper 的接口,并作为 IBApi.EClientSocket 的回掉函数进行处理。

Another crucial element is the IBApi.EReaderSignal object passed to theEClientSocket's constructor. With the exception of Python, this object is used in APIs to signal a message is ready for processing in the queue. (In Python the Queue class handles this task directly). We will discuss this object in more detail in the The EReader Thread section.

【译】 另一个关键元素是传递给 EClientSocket 构造函数的 IBApi.EReaderSignal。除了Python之外,这个对象在 API 中被用于表示消息队列的状态。(在Python中,队列直接处理这些任务)。我们将在 EReader Thread 章节中详细的讨论这个对象。

  1. private EReaderSignal readerSignal;
  2. private EClientSocket clientSocket;
  3. protected int currentOrderId = -1;
复制代码


  1. public EWrapperImpl()
  2. {
  3.     Signal = new EReaderMonitorSignal();
  4.     clientSocket = new EClientSocket(this, readerSignal);
  5. }
复制代码





欢迎光临 龙听期货论坛 (http://www.qhlt.cn/) Powered by Discuz! 7.2