开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

How do I find out the margin requirements for a US stock through the TWS API?


 

Hi,

I'd like to find out the margin requirements for US stocks via the TWS API in python. On the Trader Workstation, of I look the Description of a Stock, it has a tab about margins, and lists the initial and maintenance margin requirements for long and short positions - see screenshot attached. I'd like to get the same information via the TWS API in python.

When requesting the contract details via the API, this information is not contained in the returned ContractDetails object. Here's a sample code using the ib_async wrapper:

qqq = Stock(symbol='META', exchange='SMART', currency='USD')
qqq_details = ib.reqContractDetails(qqq)
pprint(qqq_details)

here's the result of the printout:

[ContractDetails(contract=Contract(secType='STK', conId=107113386, symbol='META', exchange='SMART', primaryExchange='NASDAQ', currency='USD', localSymbol='META', tradingClass='NMS'),
marketName='NMS',
minTick=0.01,
orderTypes='ACTIVETIM,AD,ADJUST,ALERT,ALGO ,ALLOC,AON,AVGCOST,BASKET,BENC HPX,CASHQTY,COND,CONDORDER,DAR KONLY,DARKPOLL,DAY,DEACT,DEACT DIS,DEACTEOD,DIS,DUR,GAT,GTC,G TD,GTT,HID,IBKRATS,ICE,IMB,IOC ,LIT,LMT,LOC,MIDPX,MIT,MKT,MOC ,MTL,NGCOMB,NODARK,NONALGO,OCA ,OPG,OPGREROUT,PEGBENCH,PEGMID ,POSTATS,POSTONLY,PREOPGRTH,PR ICECHK,REL,REL2MID,RELPCTOFS,R PI,RTH,SCALE,SCALEODD,SCALERST ,SIZECHK,SMARTSTG,SNAPMID,SNAP MKT,SNAPREL,STP,STPLMT,SWEEP,T RAIL,TRAILLIT,TRAILLMT,TRAILMI T,WHATIF',
validExchanges='SMART,AMEX,NYSE,CBOE,PHLX,ISE, CHX,ARCA,NASDAQ,DRCTEDGE,BEX,B ATS,EDGEA,BYX,IEX,EDGX,FOXRIVE R,PEARL,NYSENAT,LTSE,MEMX,IBEO S,OVERNIGHT,TPLUS0,PSX',
priceMagnifier=1,
underConId=0,
longName='META PLATFORMS INC-CLASS A',
contractMonth='',
industry='Communications',
category='Internet',
subcategory='Internet Content-Entmnt',
timeZoneId='US/Eastern',
tradingHours='20241016:0400-20241016:2000;20241017:0400-20241017:2000;20241018:0400-20241018:2000;20241019:CLOSED;20241020:CLOSED;20241021:0400-20241021:2000',
liquidHours='20241016:0930-20241016:1600;20241017:0930-20241017:1600;20241018:0930-20241018:1600;20241019:CLOSED;20241020:CLOSED;20241021:0930-20241021:1600',
evRule='',
evMultiplier=0,
mdSizeMultiplier=1,
aggGroup=1,
underSymbol='',
underSecType='',
marketRuleIds='26,26,26,26,26,26,26,26,26,26, 26,26,26,26,26,26,26,26,26,26, 26,26,26,26,26',
secIdList=[TagValue(tag='ISIN', value='US30303M1027')],
realExpirationDate='',
lastTradeTime='',
stockType='COMMON',
minSize=0.0001,
sizeIncrement=0.0001,
suggestedSizeIncrement=100.0,
cusip='',
ratings='',
descAppend='',
bondType='',
couponType='',
callable=False,
putable=False,
coupon=0,
convertible=False,
maturity='',
issueDate='',
nextOptionDate='',
nextOptionType='',
nextOptionPartial=False,
notes='')]

Join [email protected] to automatically receive all group messages.