Closed BrettForr closed 2 weeks ago
There are several options here:
let symbol = "ES";
let exchange = "CME";
let expiry = "202309";
let mut contract = Contract::futures(symbol);
contract.expiry = expiry
contract.exchange = exchange
let symbol = "ES";
let exchange = "CME";
let expiry = "202309";
let contract1 = Contract::futures(symbol);
let contract2 = Contract::futures_with_exchange(symbol, exchange);
let symbol = "ES";
let exchange = "CME";
let expiry = "202309";
let contract = ContractBuilder::futures(symbol)
.with_exchange(exchange)
.with_expiry(expiry)
.build()
Summary
To retrieve historical data for futures contracts, the
Contract
fields forexchange
andlast_trade_date_or_contract_month
need to be filled in, butContract::futures(symbol)
only accepts one argument for the symbol, so theexchange
andlast_trade_date_or_contract_month
fields use the defaults empty strings.A futures contract without an exchange and a contract month is a valid contract for a
contract_details
request. Based on my limited testing, running acontract_details
request without an exchange or contract month returns a Iterator of all active contracts, whereas running the same request with a futures contract with the exchange and contract month specified returns and Iterator with just the details for that single contract. Each version has it's use case, so would be good to support both.I didn't do thorough testing of what other requests work for a futures Contract without an exchange or contract month. At a glance, it looks like requesting the
head_timestamp
returns a value but it appears to be nonsense. I'm seeing 1970-01-01 for a contract that first existed just a couple years ago.Steps to reproduce
Running the following program
Returns the following (i.e. the ticks returned is an empty Iterator):
The log from IB Gateway says:
Environment
I'm using IB Gateway 10.19. These are my dependencies:
Working version
Switching the
futures
function to this results in a valid contract for historical data requests:Running this program
results in the expected output:
Proposal
Since there's a valid use for both a futures product (retrieving contract details for all active contracts) as well as an individual futures contract (retrieving historical data or contract details for a single contract), I think it makes sense to keep the current contstructor and add another
Contract
constructor function for an individual futures contract with an exchange and contract month. Also, I thinkinclude_expired
be set to true for the individual contract constructor and perhaps be an argument for the current constructor.I can put together a pull request for this.