简体   繁体   中英

How do I get the ISIN of a security from Interactive Brokers?

I am trying to get the International Securities Identification Numbers (ISIN) for securities in my Interactive Brokers portfolio.

In the documentation I found two places, that mention ISIN :

  1. secId and secIdType fields inside Contract : Source
  2. secIdList field inside ContractDetails : Source

But I can't get the API to fill any of these fields. Example code:

from ib_insync import *
ib = IB()
ib.connect("127.0.0.1", 4002, 0)
for pfi in ib.portfolio():
    for detail in ib.reqContractDetails(pfi.contract):
        print(detail)

This outputs:

ContractDetails(summary=Contract(conId=13181, symbol='AEE', secType='STK', exchange='SMART', primaryExchange='NYSE', currency='USD', localSymbol='AEE', tradingClass='AEE'), marketName='AEE', minTick=0.01, orderTypes='ACTIVETIM,ADJUST,ALERT,ALGO,ALLOC,AON,AVGCOST,BASKET,COND,CONDORDER,DARKONLY,DARKPOLL,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,GAT,GTC,GTD,GTT,HID,IBKRATS,ICE,IMB,IOC,LIT,LMT,LOC,MIT,MKT,MOC,MTL,NGCOMB,NODARK,NONALGO,OCA,OPG,OPGREROUT,PEGBENCH,POSTONLY,PREOPGRTH,REL,RPI,RTH,RTHIGNOPG,SCALE,SCALEODD,SCALERST,SMARTSTG,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,SWEEP,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,WHATIF', validExchanges='SMART,AMEX,NYSE,CBOE,ISE,CHX,ARCA,ISLAND,VWAP,DRCTEDGE,NSX,BEX,BATS,EDGEA,CSFBALGO,JEFFALGO,BYX,IEX,CVGXALGO,PSX', priceMagnifier=1, longName='AMEREN CORP', industry='Utilities', category='Electric', subcategory='Electric-Integrated', timeZoneId='EST5EDT', tradingHours='20170816:0400-2000;20170817:0400-2000', liquidHours='20170816:0930-1600;20170817:0930-1600', mdSizeMultiplier=100)

As you can see, none of the above mentioned fields are filled. Do you have any idea how to get the ISIN for a security?

I'm working with the IB API every day. Therefore I would prefer to get the ISIN with the function

reqFundamentalData

You have to use 4 arguments and the third is called reportType . Here you can choose the easiest type named ReportSnapshot . You will receive a xml -file and in the second part ( Common Stock ) you find the line with the ISIN. For example in the request for AAPL :

<IssueID Type="ISIN">US0378331005</IssueID>

It's not so complicated. If you need sample code just ask me.

More informations: IB about reqFundamentalData and documentation of the function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM