我正在努力理解IBrokers软件包,在阅读其实时小插曲时,在第2.4.1节的末尾,该软件包的作者Jeffrey A.Ryan写道:
[…]要从TWS请求当前时间,需要发送"当前时间"(.twsOutgoingMSG$REQ current time)的代码:"49"和特定请求的当前版本号。在当前时间的情况下,版本只是字符"1"。
通过扫描IBrokers包的源代码,我注意到作者对不同的请求使用了不同的VERSION编号(例如,对于reqMrktData,VERSION=9)。当我查看InteractiveBrokers API文档中的reqMktData()函数时,我发现该函数不需要"版本号"作为参数。
我还试图寻找一个通用的解释,说明特定请求的版本号是什么,以及我们何时何地可能需要它,但我找不到。
如果有人能给我解释"VERSION"变量,它意味着要做/实现什么,以及我们如何/在哪里可以找到Interactive Brokers API的各种请求的版本号列表,我将不胜感激。
提前感谢
如果有人能给我解释"VERSION"变量,它意味着要做/实现什么,以及我们如何/在哪里可以找到Interactive Brokers API的各种请求的版本号列表,我将不胜感激。
API演变问题。
查看Java(或C++)API客户端库代码中的class EClientSocket
。Jeff Ryan可能从这里学会了/不得不学会版本号。
基本上,随着IB平台/服务器功能的发展,客户使用的客户端API既有旧版本,也有新版本。因此,IB服务器能够处理来自旧版本的IB API客户端以及新版本的请求。VERSION帮助服务器区分正在处理哪个版本的API调用。
例如,IB客户端API的较新版本可以在一次拍摄中为具有多个腿的整个组合reqMktData()
,而较老的客户端无法做到这一点。因此,正如您所注意到的,对于没有发展的较简单的API,如cancelHistoricalData()
、cancelScannerSubscription()
等,它是1;,但对于倾向于随时间发展的API(如reqMktData()),可以高达7或9。
在更低级的术语中,VERSION命令告诉服务器客户端在send()
和VERSION
之后将立即在套接字上传递什么参数。以下是reqScannerSubscription()
的代码摘录。注意send(REQ_SCANNER_SUBSCRIPTION);
后面的send(VERSION);
(请注意,还有两种其他类型的版本号:服务器端(IB服务器/平台)版本号和IB TWS客户端API版本号!这些是独立于你所关心的per-API版本。IB是否真的需要一个独立于IB客户端版本的每个API调用VERSION对我来说并不明显,但这就是他们现在的工作方式)。
为漫无边际的回答道歉;看一眼EClientSocket.java
就会明白!:-)
public synchronized void reqScannerSubscription( int tickerId,
ScannerSubscription subscription) {
// not connected?
if (!m_connected) {
error(EClientErrors.NO_VALID_ID, EClientErrors.NOT_CONNECTED, "");
return;
}
if (m_serverVersion < 24) {
error(EClientErrors.NO_VALID_ID, EClientErrors.UPDATE_TWS,
" It does not support API scanner subscription.");
return;
}
final int VERSION = 3;
try {
send(REQ_SCANNER_SUBSCRIPTION);
send(VERSION);
send(tickerId);
sendMax(subscription.numberOfRows());
send(subscription.instrument());
send(subscription.locationCode());
EClientSocket顶部的客户端版本历史记录。
public class EClientSocket {
// Client version history
//
// 6 = Added parentId to orderStatus
// 7 = The new execDetails event returned for an order filled status and reqExecDetails
// Also market depth is available.
// 8 = Added lastFillPrice to orderStatus() event and permId to execution details
// 9 = Added 'averageCost', 'unrealizedPNL', and 'unrealizedPNL' to updatePortfolio event
// 10 = Added 'serverId' to the 'open order' & 'order status' events.
// We send back all the API open orders upon connection.
// Added new methods reqAllOpenOrders, reqAutoOpenOrders()
// Added FA support - reqExecution has filter.
// - reqAccountUpdates takes acct code.
// 11 = Added permId to openOrder event.
// 12 = requsting open order attributes ignoreRth, hidden, and discretionary
// 13 = added goodAfterTime
// 14 = always send size on bid/ask/last tick
// 15 = send allocation description string on openOrder
// 16 = can receive account name in account and portfolio updates, and fa params in openOrder
// 17 = can receive liquidation field in exec reports, and notAutoAvailable field in mkt data
// 18 = can receive good till date field in open order messages, and request intraday backfill
// 19 = can receive rthOnly flag in ORDER_STATUS
// 20 = expects TWS time string on connection after server version >= 20.
// 21 = can receive bond contract details.
// 22 = can receive price magnifier in version 2 contract details message
// 23 = support for scanner
// 24 = can receive volatility order parameters in open order messages
// 25 = can receive HMDS query start and end times
// 26 = can receive option vols in option market data messages
// 27 = can receive delta neutral order type and delta neutral aux price in place order version 20: API 8.85
// 28 = can receive option model computation ticks: API 8.9
// 29 = can receive trail stop limit price in open order and can place them: API 8.91
// 30 = can receive extended bond contract def, new ticks, and trade count in bars
// 31 = can receive EFP extensions to scanner and market data, and combo legs on open orders
// ; can receive RT bars
// 32 = can receive TickType.LAST_TIMESTAMP
// ; can receive "whyHeld" in order status messages
// 33 = can receive ScaleNumComponents and ScaleComponentSize is open order messages
// 34 = can receive whatIf orders / order state
// 35 = can receive contId field for Contract objects
// 36 = can receive outsideRth field for Order objects
// 37 = can receive clearingAccount and clearingIntent for Order objects
private static final int CLIENT_VERSION = 37;
private static final int SERVER_VERSION = 38;
private static final byte[] EOL = {0};
private static final String BAG_SEC_TYPE = "BAG";