softwarespartan / IB4m

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

How to access .strike in reqContractDetails returns #63

Closed ecpgieicg closed 4 years ago

ecpgieicg commented 4 years ago

Hi Abel,

As always, thank you very much for creating, sharing and maintaining the IB4m package.

Is there a way to enable access to the .strike field of com.ib.client.ContractDetails -- the return of reqContractDetails? .strike would be helpful for auto-discovering available option contracts of a specified underlying and expiration date.

For example, the following returns the contract details of all front month VIX Call options.

contract = com.ib.client.Contract();
contract.symbol("VIX");
contract.secType("OPT");
contract.exchange("SMART");
contract.currency("USD");
contract.lastTradeDateOrContractMonth("20190917");
contract.right("Call");

[bufc,lhc] = TWS.initBufferForEvent(TWS.Events.CONTRACTDETAILS,500);
session.eClientSocket.reqContractDetails(contract.strike*2,contract);

One of the hashsets in the buffer will look like the following.

bufc.get.data.iterator.next.contractDetails

ans =

conid   358347517
symbol  VIX
secType OPT
lastTradeDateOrContractMonth    20190917
strike  30.0
right   C
multiplier  100
exchange    SMART
currency    USD
localSymbol VIX   190918C00030000
tradingClass    VIX
marketName  VIX
minTick 0.05
priceMagnifier  1
orderTypes  ACTIVETIM,ADJUST,ALERT,ALGO,ALLOC,AVGCOST,BASKET,COND,CONDORDER,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,FOK,GAT,GTC,GTD,GTT,HID,ICE,IOC,LIT,LMT,MIT,MKT,MTL,NGCOMB,NONALGO,OCA,OPENCLOSE,PEGMIDVOL,PEGMKTVOL,PEGPRMVOL,PEGSRFVOL,POSTONLY,REL,RELSTK,RTH,SCALE,SCALERST,SMARTSTG,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,VOLAT,WHATIF
validExchanges  SMART,CBOE
underConId  13455763
longName    CBOE Volatility Index
contractMonth   201909
industry    Indices
category    Volatility Index
subcategory *
timeZoneId  CST
tradingHours    20190902:CLOSED;20190903:0200-20190903:0815;20190903:0830-20190903:1515;20190904:0200-20190904:0815;20190904:0830-20190904:1515;20190905:0200-20190905:0815;20190905:0830-20190905:1515;20190906:0200-20190906:0815;20190906:0830-20190906:1515;20190907:CLOSED;20190908:CLOSED;20190909:0200-20190909:0815;20190909:0830-20190909:1515;20190910:0200-20190910:0815;20190910:0830-20190910:1515;20190911:0200-20190911:0815;20190911:0830-20190911:1515;20190912:0200-20190912:0815;20190912:0830-20190912:1515;20190913:0200-20190913:0815;20190913:0830-20190913:1515;20190914:CLOSED;20190915:CLOSED;20190916:0200-20190916:0815;20190916:0830-20190916:1515;20190917:0200-20190917:0815;20190917:0830-20190917:1515
liquidHours 20190902:CLOSED;20190903:0830-20190903:1515;20190904:0830-20190904:1515;20190905:0830-20190905:1515;20190906:0830-20190906:1515;20190907:CLOSED;20190908:CLOSED;20190909:0830-20190909:1515;20190910:0830-20190910:1515;20190911:0830-20190911:1515;20190912:0830-20190912:1515;20190913:0830-20190913:1515;20190914:CLOSED;20190915:CLOSED;20190916:0830-20190916:1515;20190917:0830-20190917:1515
evMultiplier    0.0
mdSizeMultiplier    1
aggGroup    2
underSymbol VIX
underSecType    IND
marketRuleIds   110,110
realExpirationDate  20190918
lastTradeTime   15:15
callable    false
putable false
coupon  0.0
convertible false
nextOptionPartial   false

But with most fields, including .strike, attempting to access will give the following error.

>> bufc.get.data.iterator.next.contractDetails.strike
Undefined function 'strike' for input arguments of type 'com.ib.client.ContractDetails'.

What do I need to do in order to access the .strike field?

Thank you for your attention!

Despair2000 commented 4 years ago

Try converting the hashset to a cell-array with something like:

details = collection2cell(buf.get().data); details = details{1}.contractDetails; details.strike

Does this work?

softwarespartan commented 4 years ago

Not sure I understand. Hash is key-value pairs so does not flatten/convert to list or cell array.

I’ll try have a look today

On Sep 5, 2019, at 2:27 AM, Despair2000 notifications@github.com wrote:

Try converting the hashes to a cell-array with something like:

details = collection2cell(buf.get().data); details = details{1}.contractDetails; details.strike

Does this work?

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

Despair2000 commented 4 years ago

Did you try the lines I sent? I'm pretty sure it will do the trick. I can't try it myself right now because an application of mine is connected to the TWS right now and I don't want to stop the program.

At least I access several fields from the contract details in this way. Didn't try the strike field though.

softwarespartan commented 4 years ago

If I recall, the “strike” is property of contract so you need to ask for contractDetails.contract().strike

On Sep 5, 2019, at 5:54 AM, Despair2000 notifications@github.com wrote:

Did you try the lines I sent? I'm pretty sure it will do the trick. I can't try it myself right now because an application of mine is connected to the TWS right now and I don't want to stop the program.

At least I access several fields from the contract details in this way. Didn't try the strike field though.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/softwarespartan/IB4m/issues/63?email_source=notifications&email_token=ABC2VVCBVIITCEIJXZTK7NDQID6O5A5CNFSM4ITBFQZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD567RNY#issuecomment-528349367, or mute the thread https://github.com/notifications/unsubscribe-auth/ABC2VVF5KTITLAXU2GUTCDDQID6O5ANCNFSM4ITBFQZA.

Despair2000 commented 4 years ago

You are right. details.contract.strike (in my example) gives the strike price. I now had the possibility to try it.

ecpgieicg commented 4 years ago

hi guys,

Sorry for my late reply. I missed all the messages earlier.

Yes,

.contractDetails.contract.strike

does the trick.

Thanks a lot to both of you!