: | : | :期货程序化 | :期货程序化研究 | :期货量化学习 | :期货量化 |
返回列表 发帖

WS API v9.72 在线文档 ——合约【翻译】

WS API v9.72 在线文档 ——合约【翻译】

Contracts(合约)Overview

An IBApi.Contract object represents trading instruments such as a stocks, futures or options.

【译】 IBApi.Contract 对象表示金融交易工具,如股票,期货或者期权。

Every time a new request that requires a contract (i.e. market data, order placing, etc.) is sent to TWS, the platform will try to match the provided contract object with a single candidate.

【译】 每次当客户端生成一个合约请求(如市场数据,订单等),TWS平台都会尝试对请求的合同对象匹配一个申请号。

If there is more than one contract matching the same description, TWS will return an error notifying you there is an ambiguity.

【译】 如果有一个以上的合约具备相同的属性(如请求的市场数据,合约代码,类型相同),TWS会返回error信息,告知你的合约存在歧义。

In these cases the TWS needs further information to narrow down the list of contracts matching the provided description to a single element.

【译】 这种情况发生时,用户需要向TWS提交更详细的信息,以便TWS从合约中准确地找出请求的合约对象。

The best way of finding a contract’s description is within the TWS itself. Within the TWS, you can easily check a contract’s description either by double clicking it or through the Contract Info -> Description menu, which you access by right-clicking a contract in TWS:

【译】 准确地找出合约信息的最好方法是直接使用TWS。在TWS界面中,您能轻易的通过点击鼠标,通常可以在 Contract Info -> Description 菜单查找到所要合约的描述信息。


The description will then appear:

【译】 合约的描述信息如下:


Note: you can see the extended contract details by choosing Contract Info -> Details. This option will open a web page showing all available information on the contract.

【译】 备注:你能通过 Contract Info -> Details 查看合约的扩展信息。该操作将打开一个网页,展示合约的所有可用信息。

Whenever a contract description is provided via the TWS API, the TWS will try to match the given description to a single contract. This mechanism allows for great flexibility since it gives the possibility to define the same contract in multiple ways.

【译】 无论何时,TWS都会尝试通过用户提交的合约描述信息,匹配完整的信息。这样的机制提供了一个巨大的灵活性。也就是说,TWS会根据用户的请求尽最大可能的匹配合约信息。

The simplest way to define a contract is by providing its symbol, security type, currency and exchange. The vast majority of stocks, CFDs, Indexes or FX pairs can be uniquely defined through these four attributes. More complex contracts such as options and futures require some extra information due to their nature. Below are several examples for different types of instruments.

【译】 定义一份合约的最简单的方法时通过提交合约的代码(译者注,比如股票交易代码,如浦发银行600000,英特尔intl,谷歌googl)资产类型,货币符号,交易所。绝大多数的股票,差价合约,指数,或外汇可以通过这四个属性进行唯一性定义。而更复杂的合约(如期权和期货),由于其特殊性质需要额外的信息。

【译】 以下是几种不同的例子:

See also:

  • Requesting Contract Details (获取合约详细信息)
  • Stock Contract Search (股票合约的查询)
  • Basic Contracts (基础合约)
  • Spreads (投资组合合约)
Requesting Contract Details

Complete details about a contract in IB's database can be retrieved using the function IBApi.EClient.reqContractDetails.

【译】 关于合约的完整信息,可以通过IBApi.EClient.reqContractDetails,从IB的数据库中获取。

This includes information about a contracts conID, symbol, local symbol, currency, etc. which is returned in a IBApi.ContractDetails object IBApi.EWrapper.contractDetail. reqContractDetails takes as an argument a Contract object which may uniquely match an argument, and unlike other API functions it can also take a Contract object which matches multiple contracts in IB's database.

【译】 它包含关于一个合约的conID(合约ID),symbol(合约符号), local symbol(本地符号), currency(货币符号)等信息,这通过IBApi.ContractDetails 返回的对象 IBApi.EWrapper.contractDetail。 reqContractDetails方法以合约的对象为参数,(合约描述信息)可以是唯一的,也可以不是,并且与其他的API函数不同,它可以从IB的数据库中匹配出多个合约信息。

(译者注:contractDetail对象,即可以匹配一个对象,也可以匹配多个对象,区别只在于您提交给TWS的数据是否足够完整和精确,例如提交期货合约时,您还需要附加其他的限制条件进行精确查询。)

When there are multiple matches, they will each be returned individually to the function IBApi::EWrapper::contractDetails.

【译】 当出现1对多匹配时,每一个合约都将被独立返回给函数IBApi::EWrapper::contractDetails。

Note: Invoking reqContractDetails with a Contract object which has currency = USD will only return US contracts, even if there are non-US instruments which have the USD currency.

【译】 备注:通过合约 Contract 对象激活 reqContractDetails 方法,当合约信息中货币符号为美元 USD 时,将只返回美国的合约内容,无论该合约对象是否还包含了其他货币符号的合约对象。

(注:即便同一个合约标记,在不同的国家都存在,但通过货币符号进行锁定时,只会返回该货币符号对应的合约内容。)

Request for Bond details will be returned to IBApi::EWrapper::bondContractDetails instead. Because of bond market data license restrictions, there are only a few available fields to be returned in a bond contract description, namely the minTick, exchange, currency, and short name.

【译】 如果您试图请求一个债券的合约信息,那么它将只被返回给 IBApi::EWrapper::bondContractDetails。因为债券市场受许可条件限制,因此只有少量信息被返回,通常这些信息是:minTick, exchange(交易所), currency(货币), and short name(简称).

One particular use of the IBApi::EClient::reqContractDetails function is to request an option chain. See Option Chains for more details.

【译】 关于 IBApi::EClient::reqContractDetails 方法,有一个特殊的用法,就是用它获取期权链信息,关于期权链的更多信息请参考相关章节内容。

BroadTape News List

【译】 BroadTape 新闻列表

The example below shows an "incomplete" news IBApi.Contract with no symbol or currency defined. In most cases using such a contract would result in an invalid contract details error since a symbol or localSymbol is required. IBApi.EClient.reqContractDetails will instead use it to obtain the whole BroadTape news chain from the TWS.

【译】 以下样例展示了如何定义 IBApi.Contract 获取一个“非完整”的合约新闻的方式。在多数情况下,需要合约符号(symbol),或者本地符号(localSymbol),这样的合约请求都会导致无效合约内容的错误。 因此,通过IBApi.EClient.reqContractDetails函数,可以从BroadTape新闻链获取到最新消息。

  1. Contract contract = new Contract();
  2. contract.secType("NEWS");
  3. contract.exchange("BT"); //Briefing Trader
  4. ...
  5. client.reqContractDetails(211, ContractSamples.NewsFeedForQuery());
复制代码

All returned objects will be delivered via IBApi.EWrapper.contractDetails. Once all contracts have been delivered the IBApi.EWrapper.contractDetailsEnd marker will be triggered to notify it.

【译】 所有返回的对象,都会通过IBApi.EWrapper.contractDetails传递(给调用者)。当所有的合约返回给用户后,IBApi.EWrapper.contractDetailsEnd 标记将被激活,告知用户合约信息获取完毕。

  1. public class EWrapperImpl implements EWrapper {
  2. ...
  3.     @Override
  4.     public void contractDetails(int reqId, ContractDetails contractDetails) {
  5.         System.out.println(EWrapperMsgGenerator.contractDetails(reqId, contractDetails));
  6.     }
  7. ...
  8.     @Override
  9.     public void contractDetailsEnd(int reqId) {
  10.         System.out.println("ContractDetailsEnd. "+reqId+"\n");
  11.     }
复制代码

Important: due to the potentially high amount of data resulting from such queries this request is subject to pacing. Although a request such as the above one will be answered immediately, a similar subsequent one will be kept on hold for one minute. This amount of time will increase if more such requests are performed. To prevent this narrow down the amount of eligible contracts by providing an expiration date specifying at least the year (i.e. 2016) or the year and the month (i.e. 201603 for March 2016).


【译】 重要信息:由于此类请求方式会产生大量的数据通信,因此可能导致函数返回需要花费较长时间。尽管如上样例一样的查询会即刻响应,而类似的后续请求则要停滞约1分钟。如果执行更多的类似请求,暂停的时间将会持续增加。为了避免此类情况,建议提交的请求中包含查询的时间段,如2016年,或者某个月如2016年3月,从而获取这些数据。


Stock Contract Search

【译】 股票合约的查询


Starting in API v973.02 and TWS v964, a function IBApi::EClient::reqMatchingSymbols is available to search for stock contracts. The input can be either the first few letters of the ticker symbol, or for longer strings, a character sequence matching a word in the security name. For instance to search for the stock symbol 'IBKR', the input 'I' or 'IB' can be used, as well as the word 'Interactive'. Up to 16 matching results are returned.


【译】 从TWS v964及API v973开始,赢透API提供了一个全新的函数用于查询股票合约,IBApi::EClient::reqMatchingSymbols。 它可以通过股票名称的简写形式(如浦发银行,PFYH;谷歌,Goog),或者股票代码(600000,GOOGL)进行查询,如果以简写形式查询,每一个字母代表每个单词的首字母。例如,“IBKR”是赢透在纳斯达克的股票代码,“I”或者“IB”也可以查询到赢透证券。通过模糊条件进行查询时,最多有16条记录会被返回。

  1. client.reqMatchingSymbols(211, "IB");
复制代码

Matching stock contracts are returned to IBApi::EWrapper::symbolSamples with information about types of derivative contracts which exist (warrants, options, dutch warrants, futures).


【译】 匹配到的结果,会返回给 IBApi::EWrapper::symbolSamples,如果合约还有衍生品的话,这些信息也会同时被返回给用户(例如,权证,期权,荷兰权证,期货)。


  1. @Override
  2. public void symbolSamples(int reqId, ContractDescription[] contractDescriptions) {
  3.     System.out.println("Contract Descriptions. Request: " + reqId + "\n");
  4.     for (ContractDescription  cd : contractDescriptions) {
  5.         Contract c = cd.contract();
  6.         StringBuilder derivativeSecTypesSB = new StringBuilder();
  7.         for (String str : cd.derivativeSecTypes()) {
  8.             derivativeSecTypesSB.append(str);
  9.             derivativeSecTypesSB.append(",");
  10.         }
  11.         System.out.print("Contract. ConId: " + c.conid() + ", Symbol: " + c.symbol() + ", SecType: " + c.secType() +
  12.                 ", PrimaryExch: " + c.primaryExch() + ", Currency: " + c.currency() +
  13.                 ", DerivativeSecTypes:[" + derivativeSecTypesSB.toString() + "]");
  14.     }
  15.     System.out.println();
  16. }
复制代码

Basic Contracts(基础合约类型)

FX Pairs (外汇)

  1.    Contract contract = new Contract();
  2.     contract.symbol("EUR");
  3.     contract.secType("CASH");
  4.     contract.currency("GBP");
  5.     contract.exchange("IDEALPRO");
复制代码

Stocks (股票)

  1.    Contract contract = new Contract();
  2.     contract.conid(46636665);
  3.     contract.secType("STK");
  4.     //contract.currency("USD");
  5.     //In the API side, NASDAQ is always defined as ISLAND
  6.     contract.exchange("SEHK");
复制代码

For certain smart-routed stock contracts that have the same symbol, currency and exchange, you would also need to specify the primary exchange attribute to uniquely define the contract. This should be defined as the native exchange of a contract, and is good practice for all stocks:


【译】 对于可能存在相同符号,为了更快的获取到对应股票合约信息,除了股票代码,货币符号,交易所,你还需要指定主要的交易所标记,以便唯一地确定对应的合约,具体实现如下:

  1.   Contract contract = new Contract();
  2.     contract.symbol("MSFT");
  3.     contract.secType("STK");
  4.     contract.currency("USD");
  5.     contract.exchange("SMART");
  6.     // Specify the Primary Exchange attribute to avoid contract ambiguity
  7.     // (there is an ambiguity because there is also a MSFT contract with primary exchange = "AEB")
  8.     contract.primaryExch("ISLAND");
复制代码

(注:primaryExch 字段指定主要交易所,避免由于交易所符号不清晰,导致歧义。)


As an alternative to defining the exchange and primary exchange fields, it is possible to specify the exchange field as "Exchange:Primary Exchange", e.g. "SMART:NASDAQ". The colon ":" or slash "/" separating this fields is known as the "Component Exchange Separator" and defined in the API Settings in Global Configuration.


【译】 作为主要交易所和交易所字段的替代方法,可以通过指定字段“Exchange:Primary Exchange”的方法,例如:"SMART:NASDAQ",使用“:”或“/”符号区分字段。


Indexes(指数)


ISINs for indices which are available in IB's database are available in the API as of TWS 965+.


【译】 ISINs用于指示在在TWS965+版的IB的数据库中有哪些可用的API。

  1.   Contract contract = new Contract();
  2.     contract.symbol("DAX");
  3.     contract.secType("IND");
  4.     contract.currency("EUR");
  5.     contract.exchange("DTB");
复制代码

CFDs (差价合约)

  1.   Contract contract = new Contract();
  2.     contract.symbol("IBDE30");
  3.     contract.secType("CFD");
  4.     contract.currency("EUR");
  5.     contract.exchange("SMART");
复制代码

Futures(期货)


A regular futures contract is commonly defined using an expiry and the symbol field defined as the symbol of the underlying.


【译】 标准期货合约通常使用到期日和使用symbol字段作为基础标记进行定义。

  1. Contract contract = new Contract();
  2.     contract.symbol("ES");
  3.     contract.secType("FUT");
  4.     contract.currency("USD");
  5.     contract.exchange("GLOBEX");
  6.     contract.lastTradeDateOrContractMonth("201803");
复制代码

By contract the 'local symbol' field is IB's symbol for the future itself (the Symbol within the TWS' Contract Description dialog). Since a local symbol uniquely defines a future, an expiry is not necessary.


【译】 作为对比,“local symbol” 标记,在IB的标记为期货专用(在TWS合约详细信息对话框里)。当使用“local symbol”定义期货时,“合约到期日”字段不再需要。


  1. Contract contract = new Contract();
  2.     contract.localSymbol("ESU6");
  3.     contract.secType("FUT");
  4.     contract.currency("USD");
  5.     contract.exchange("GLOBEX");
复制代码

  1. Occasionally, you can expect to have more than a single future contract for the same underlying with the same expiry. To rule out the ambiguity, the contract's multiplier can be given as shown below:

  2. 【译】 某些时候,您可能期望获得多于单一期货合约的多个拥有共同基础标记及合约到期日(注:例如某一天到期的多个棉花期货合约)。为了处理歧义性,可以设置合约乘数:
复制代码

  1.   Contract contract = new Contract();
  2.     contract.symbol("DAX");
  3.     contract.secType("FUT");
  4.     contract.currency("EUR");
  5.     contract.exchange("DTB");
  6.     contract.lastTradeDateOrContractMonth("201609");
  7.     contract.multiplier("5");
复制代码


It is possible to use continuous futures contracts to receive historical data, real time bars, or contract details (requires TWS v966+). Continuous futures cannot be used with real time data or to place orders.


【译】 可以通过设置连续合约获取某合约的历史数据,时间轴,或者合约详细信息(需要TWS v966+以上版本支持)。连续期货合约不能用于实时数据,或着提交订单。


  1.    Contract contract = new Contract();
  2.     contract.symbol("ES");
  3.     contract.secType("CONTFUT");
  4.     contract.exchange("GLOBEX");
复制代码


The security type "FUT+CONTFUT" can be used to request contract details about the futures and continuous futures on an underlying. This security type cannot be used with other functionality.


【译】 资产类型“FUT+CONTFUT”可以被用于查询合约详细信息及合约历史信息,除此之外不能被其他合约类型使用。

  1.    Contract contract = new Contract();
  2.     contract.symbol("ES");
  3.     contract.secType("FUT+CONTFUT");
  4.     contract.exchange("GLOBEX");
复制代码

Options(股票期权合约)


Options, like futures, also require an expiration date plus a strike and a multiplier:


【译】 如同期货,期权合约也需要到期日,以及一个期权合约乘数(注:也就是获取在某一天到期的某期权不同价位的情况)

  1.    Contract contract = new Contract();
  2.     contract.symbol("GOOG");
  3.     contract.secType("OPT");
  4.     contract.currency("USD");
  5.     contract.exchange("BOX");
  6.     contract.lastTradeDateOrContractMonth("20170120");
  7.     contract.right("C");
  8.     contract.strike(615);
  9.     contract.multiplier("100");
复制代码

It is not unusual to find many option contracts with an almost identical description (i.e. underlying symbol, strike, last trading date, multiplier, etc.). Adding more details such as the trading class will help:


【译】 查找几乎拥有相同属性的期权合约(如基础标识,竞价,最近交易时间,乘数等),通过增加更多的信息,可以帮助用户更容易的找到对应的期权合约。

  1.    Contract contract = new Contract();
  2.     contract.symbol("SANT");
  3.     contract.secType("OPT");
  4.     contract.currency("EUR");
  5.     contract.exchange("MEFFRV");
  6.     contract.lastTradeDateOrContractMonth("20190621");
  7.     contract.right("C");
  8.     contract.strike(7.5);
  9.     contract.multiplier("100");
  10.     contract.tradingClass("SANEU");
复制代码

The OCC options symbol can be used to define an option contract in the API through the option's 'local symbol' field.


【译】 使用OCC属性标记,可以在API中用来定义一个期权合约。

  1.    Contract contract = new Contract();
  2.     //Watch out for the spaces within the local symbol!
  3.     contract.localSymbol("C DBK  DEC 20  1600");
  4.     contract.secType("OPT");
  5.     contract.exchange("DTB");
  6.     contract.currency("EUR");
复制代码


论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
 
期货论坛 - 版权/免责声明   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

Futures Options(期货期权)

Futures options follow the same rules as conventional option contracts:

【译】 期货期权,遵循和期权一样定义方式。
  1.   Contract contract = new Contract();
  2.     contract.symbol("ES");
  3.     contract.secType("FOP");
  4.     contract.currency("USD");
  5.     contract.exchange("GLOBEX");
  6.     contract.lastTradeDateOrContractMonth("20180316");
  7.     contract.right("C");
  8.     contract.strike(2800);
  9.     contract.multiplier("50");
复制代码



Bonds(债券)

Bonds can be specified by defining the symbol as the CUSIP or ISIN.

【译】 债券可以在“symbol”定义为“CUSIP”或“ISIN”使用


  1.   Contract contract = new Contract();
  2.     // enter CUSIP as symbol
  3.     contract.symbol("912828C57");
  4.     contract.secType("BOND");
  5.     contract.exchange("SMART");
  6.     contract.currency("USD");
复制代码



Bonds can also be defined with the conId and exchange as with any security type.

【译】 债券也可以像其他资产类型一样,通过conId和exchange进行定义。


  1. Contract contract = new Contract();
  2.     contract.conid(285191782);
  3.     contract.exchange("SMART");
复制代码



(注:SMART相当于一个默认标记,相当于告知系统自动帮助用户查找合约对应的交易所,因此可能带来歧义性,所以赢透并不推荐这样操作。因此确定具体的合约交易所代码后,赢透建议用户每次提交合约都指明具体的交易所。)

Mutual Funds(共同基金)

Mutual Funds are supported in the API. Note: Mutual Funds cannot be traded in paper accounts.

【译】 API也提供了对共同基金的支持,注意,模拟交易账户不能交易共同基金。


  1. Contract contract = new Contract();
  2.     contract.symbol("VINIX");
  3.     contract.secType("FUND");
  4.     contract.exchange("FUNDSERV");
  5.     contract.currency("USD");
复制代码



Commodities(商品期货)

  1.     Contract contract = new Contract();
  2.     contract.symbol("XAUUSD");
  3.     contract.secType("CMDTY");
  4.     contract.exchange("SMART");
  5.     contract.currency("USD");
复制代码



Dutch Warrants(荷兰认股权证)

Dutch Warrants (IOPTs) can be defined with the local symbol or contract ID (conid), but not the ISIN.

【译】 荷兰权证,可以通过“local symbol”和“conid”进行定义,但不能使用ISIN进行定义。


  1.   Contract contract = new Contract();
  2.     contract.localSymbol("B881G");
  3.     contract.secType("IOPT");
  4.     contract.exchange("SBF");
  5.     contract.currency("EUR");
复制代码



Spreads(投资组合合约)
Spread contracts, also known as combos or combinations, combine two or more instruments. To define a combination contract it is required to know the conId of the IBApi.Contract in question. The conId of an instrument can easily be obtained via the IBApi.EClientSocket.reqContractDetails request.

【译】 投资组合合约(也称为组合)结合了两个或更多的金融工具。定义一个组合合约,需要知道IBApi.Contract的“conId”。用户可以从IBApi.EClientSocket.reqContractDetails获得交易工具的“conId”

The spread contract's symbol can be either the symbol of one of the contract legs or, for two-legged combinations the symbols of both legs separated by a comma as shown in the examples below.

【译】 组合合约的符号,可以是组合其一的合约代码,也可以是多个用逗号隔开的不同合约代码的组合。

Stock Spread(股票组合)


  1.    Contract contract = new Contract();
  2.     contract.symbol("MCD");
  3.     contract.secType("BAG");
  4.     contract.currency("USD");
  5.     contract.exchange("SMART");

  6.     ComboLeg leg1 = new ComboLeg();
  7.     ComboLeg leg2 = new ComboLeg();
  8.     List<ComboLeg> addAllLegs = new ArrayList<>();
  9.     leg1.conid(43645865);//IBKR STK
  10.     leg1.ratio(1);
  11.     leg1.action("BUY");
  12.     leg1.exchange("SMART");
  13.     leg2.conid(9408);//MCD STK
  14.     leg2.ratio(1);
  15.     leg2.action("SELL");
  16.     leg2.exchange("SMART");
  17.     addAllLegs.add(leg1);
  18.     addAllLegs.add(leg2);

  19.     contract.comboLegs(addAllLegs);
复制代码



Note: EFPs are simply defined as a bag contract of stock and corresponding SSF with a ratio of 100:1. 【译】 EFPs用来简要的定义一组股票投资组合,按100:1的比例对应于SSF。

Options Spread(期权组合)


  1.   Contract contract = new Contract();
  2.         contract.symbol("DBK");
  3.         contract.secType("BAG");
  4.         contract.currency("EUR");
  5.         contract.exchange("DTB");

  6.         ComboLeg leg1 = new ComboLeg();
  7.         ComboLeg leg2 = new ComboLeg();
  8.         List<ComboLeg> addAllLegs = new ArrayList<>();
  9.         leg1.conid(197397509);//DBK JUN 15 '18 C
  10.         leg1.ratio(1);
  11.         leg1.action("BUY");
  12.         leg1.exchange("DTB");
  13.         leg2.conid(197397584);//DBK JUN 15 '18 P
  14.         leg2.ratio(1);
  15.         leg2.action("SELL");
  16.         leg2.exchange("DTB");
  17.         addAllLegs.add(leg1);
  18.         addAllLegs.add(leg2);

  19.         contract.comboLegs(addAllLegs);
复制代码



Guaranteed Futures Spread(保证期货组合)

  1.    Contract contract = new Contract();
  2.         contract.symbol("VIX");
  3.         contract.secType("BAG");
  4.         contract.currency("USD");
  5.         contract.exchange("CFE");

  6.         ComboLeg leg1 = new ComboLeg();
  7.         ComboLeg leg2 = new ComboLeg();
  8.         List<ComboLeg> addAllLegs = new ArrayList<>();
  9.         leg1.conid(195538625);//VIX FUT 20160217
  10.         leg1.ratio(1);
  11.         leg1.action("BUY");
  12.         leg1.exchange("CFE");
  13.         leg2.conid(197436571);//VIX FUT 20160316
  14.         leg2.ratio(1);
  15.         leg2.action("SELL");
  16.         leg2.exchange("CFE");
  17.         addAllLegs.add(leg1);
  18.         addAllLegs.add(leg2);

  19.         contract.comboLegs(addAllLegs);
复制代码



Smart-Routed Futures Spread(自动路由期货组合)

Futures spreads can also be defined as Smart-routed (non-guaranteed) combos. When placing an order for a non-guaranteed combo from the API, the non-guaranteed flag must be set to 1. Historical data for smart-routed futures spreads is generally available from the API with the requisite market data subscriptions.

【译】 期货组合也以定义为智能路由组合(无保证)。当从API下无保证订单,非保证标识需要被设置为1.此外,智能路由期货组合的历史数据可以通过API,从市场中订阅。


  1.    Contract contract = new Contract();
  2.     contract.symbol("WTI");  // WTI,COIL spread. Symbol can be defined as first leg symbol ("WTI") or currency ("USD").
  3.     contract.secType("BAG");
  4.     contract.currency("USD");
  5.     contract.exchange("SMART"); // smart-routed rather than direct routed
  6.     ComboLeg leg1 = new ComboLeg();
  7.     ComboLeg leg2 = new ComboLeg();
  8.     List<ComboLeg> addAllLegs = new ArrayList<>();
  9.     leg1.conid(55928698);// WTI future June 2017
  10.     leg1.ratio(1);
  11.     leg1.action("BUY");
  12.     leg1.exchange("IPE");
  13.     leg2.conid(55850663);// COIL future June 2017
  14.     leg2.ratio(1);
  15.     leg2.action("SELL");
  16.     leg2.exchange("IPE");
  17.     addAllLegs.add(leg1);
  18.     addAllLegs.add(leg2);
  19.     contract.comboLegs(addAllLegs);
复制代码



Inter-Commodity Futures

For Inter-Commodity futures, the 'Local Symbol' field in TWS is used for the 'Symbol' field in the API contract definition, e.g. "CL.BZ". They are always guaranteed combos, which is the default in the API.

【译】 商品间期货,在TWS中的“Local Symbol”标记,被用于合约“Symbol”的定义。例如“CL.BZ”。在API中,这些都是保证的组合。


  1. Contract contract = new Contract();
  2.     contract.symbol("CL.BZ");
  3.     contract.secType("BAG");
  4.     contract.currency("USD");
  5.     contract.exchange("NYMEX");

  6.     ComboLeg leg1 = new ComboLeg();
  7.     ComboLeg leg2 = new ComboLeg();
  8.     List<ComboLeg> addAllLegs = new ArrayList<>();
  9.     leg1.conid(47207310); //CL Dec'16 @NYMEX
  10.     leg1.ratio(1);
  11.     leg1.action("BUY");
  12.     leg1.exchange("NYMEX");
  13.     leg2.conid(47195961); //BZ Dec'16 @NYMEX
  14.     leg2.ratio(1);
  15.     leg2.action("SELL");
  16.     leg2.exchange("NYMEX");
  17.     addAllLegs.add(leg1);
  18.     addAllLegs.add(leg2);

  19.     contract.comboLegs(addAllLegs);
复制代码



Please be mindful of the fact that inter-commodity spreads are offered by the exchange directly, and so they are direct-routed though the legs have different underlyings. Only real time, and not historical, data is offered for inter-commodity spread contracts through the API.

【译】 请特别注意一点,Inter-Commodity Futures由交易所直接提供。因此即便组合中各工具不同,也会被直接路由到交易所。而且API只提供了实时数据,而没有历史数据。

It is also possible in many cases to create a spread of the same future contracts in a inter-commodity spread which is smart-routed and non-guaranteed. Historical data for this spread would generally be available from the API. Also, historical data for expired spread contracts is not available in TWS or the API.

【译】 用户有可能用各种方式创建同一个期货合约组成的商品间期货合约,它是智能路由,并且,非保证的。这类组合的历史数据可由API提供。尽管,组合的历史数据无论对于API还是TWS来说,都是不再可用的。
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

TOP

返回列表