softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

Defining Futures Contracts #16

Open bginvestor opened 6 years ago

bginvestor commented 6 years ago

Hi Abel,

Say, I need a little help with downloading historical FUTURES contract data. Can you please help? Here's the equivalent commands in IB Trader Workstation format. Thank you!

PS Is there a disconnection command necessary to disconnect a TWS session using your code ? How does that work? Thank you!!! Brian

symbol = 'ES';
ib = ibtws('',7496);

ibContract = ib.Handle.createContract; ibContract.symbol=symbol; ibContract.secType='FUT'; ibContract.expiry='201712'; ibContract.exchange='GLOBEX'; ibContract.currency='USD';

startdate = floor(now)-.5; enddate = now; barsize = '15 mins';

d = timeseries(ib,ibContract,startdate,enddate,barsize);
close(ib)

softwarespartan commented 6 years ago

Thanks for reaching out.

You should just be able to configure a contract any way you like and request data or place orders etc.

Create a contract object with

contract = com.ib.client.Contract()

and then have a look at the fields of the object

fields(contract)

ans =

18×1 cell array

'm_conId'
'm_symbol'
'm_secType'
'm_expiry'
'm_strike'
'm_right'
'm_multiplier'
'm_exchange'
'm_currency'
'm_localSymbol'
'm_tradingClass'
'm_primaryExch'
'm_includeExpired'
'm_secIdType'
'm_secId'
'm_comboLegsDescrip'
'm_comboLegs'
'm_underComp'

See link below for how to configure various contracts:

https://interactivebrokers.github.io/tws-api/basic_contracts.html#gsc.tab=1 <https://interactivebrokers.github.io/tws-api/basic_contracts.html#gsc.tab=1>

Don’t hesitate to reply if you need anything additional or have more questions.

On Nov 27, 2017, at 6:39 PM, bginvestor notifications@github.com wrote:

Hi Abel,

Say, I need a little help with downloading historical FUTURES contract data. Can you please help? Here's the equivalent commands in IB Trader Workstation format. Thank you!

PS Is there a disconnection command necessary to disconnect a TWS session using your code ? How does that work? Thank you!!! Brian

symbol = 'ES'; ib = ibtws('',7496);

ibContract = ib.Handle.createContract; ibContract.symbol=symbol; ibContract.secType='FUT'; ibContract.expiry='201712'; ibContract.exchange='GLOBEX'; ibContract.currency='USD';

startdate = floor(now)-.5; enddate = now; barsize = '15 mins';

d = timeseries(ib,ibContract,startdate,enddate,barsize); close(ib)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/16, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1CaWOPejQVofgSxHRfe68kOWj_ibks5s63JOgaJpZM4Qsmft.

bginvestor commented 6 years ago

Thank you!

Sent from Mail for Windows 10

From: Abel Brown Sent: Tuesday, November 28, 2017 5:42 PM To: softwarespartan/IB4m Cc: bginvestor; Author Subject: Re: [softwarespartan/IB4m] Defining Futures Contracts (#16)

Thanks for reaching out.

You should just be able to configure a contract any way you like and request data or place orders etc.

Create a contract object with

contract = com.ib.client.Contract()

and then have a look at the fields of the object

fields(contract)

ans =

18×1 cell array

'm_conId' 'm_symbol' 'm_secType' 'm_expiry' 'm_strike' 'm_right' 'm_multiplier' 'm_exchange' 'm_currency' 'm_localSymbol' 'm_tradingClass' 'm_primaryExch' 'm_includeExpired' 'm_secIdType' 'm_secId' 'm_comboLegsDescrip' 'm_comboLegs' 'm_underComp'

See link below for how to configure various contracts:

https://interactivebrokers.github.io/tws-api/basic_contracts.html#gsc.tab=1 https://interactivebrokers.github.io/tws-api/basic_contracts.html#gsc.tab=1

Don’t hesitate to reply if you need anything additional or have more questions.

On Nov 27, 2017, at 6:39 PM, bginvestor notifications@github.com wrote:

Hi Abel,

Say, I need a little help with downloading historical FUTURES contract data. Can you please help? Here's the equivalent commands in IB Trader Workstation format. Thank you!

PS Is there a disconnection command necessary to disconnect a TWS session using your code ? How does that work? Thank you!!! Brian

symbol = 'ES'; ib = ibtws('',7496);

ibContract = ib.Handle.createContract; ibContract.symbol=symbol; ibContract.secType='FUT'; ibContract.expiry='201712'; ibContract.exchange='GLOBEX'; ibContract.currency='USD';

startdate = floor(now)-.5; enddate = now; barsize = '15 mins';

d = timeseries(ib,ibContract,startdate,enddate,barsize); close(ib)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/16, or mute the thread https://github.com/notifications/unsubscribe-auth/AEWq1CaWOPejQVofgSxHRfe68kOWj_ibks5s63JOgaJpZM4Qsmft.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

deano1949 commented 6 years ago

Just a quick comment on this subject...

In order to download expired futures contracts, you have to include m_includeExpired when setting up contracts. To set 'm_includeExpired=1'