Skip to main content

Wrapper

ib_interface.api.wrapper

Wrapper to handle incoming messages.

RequestError

Exception to raise when the API reports an error that can be tied to a single request.

Wrapper

Wrapper implementation for use with the IB class.

reset

def reset()

setEventsDone

def setEventsDone()

Set all subscription-type events as done.

connectionClosed

def connectionClosed()

startReq

def startReq(key, contract = None, container = None)

Start a new request and return the future that is associated with the key and container. The container is a list by default.

startTicker

def startTicker(reqId: int, contract: Contract, tickType: Union[int, str])

Start a tick request that has the reqId associated with the contract. Return the ticker.

endTicker

def endTicker(ticker: Ticker, tickType: Union[int, str])

startSubscription

def startSubscription(reqId, subscriber, contract = None)

Register a live subscription.

endSubscription

def endSubscription(subscriber)

Unregister a live subscription.

orderKey

def orderKey(clientId: int, orderId: int, permId: int) -> OrderKeyType

setTimeout

def setTimeout(timeout: float)

connectAck

def connectAck()

nextValidId

def nextValidId(reqId: int)

managedAccounts

def managedAccounts(accountsList: str)

updateAccountTime

def updateAccountTime(timestamp: str)

updateAccountValue

def updateAccountValue(tag: str, val: str, currency: str, account: str)

accountDownloadEnd

def accountDownloadEnd(_account: str)

accountUpdateMulti

def accountUpdateMulti(reqId: int, account: str, modelCode: str, tag: str, val: str, currency: str)

accountUpdateMultiEnd

def accountUpdateMultiEnd(reqId: int)

accountSummary

def accountSummary(_reqId: int, account: str, tag: str, value: str, currency: str)

accountSummaryEnd

def accountSummaryEnd(reqId: int)

updatePortfolio

def updatePortfolio(contract: Contract, posSize: float, marketPrice: float, marketValue: float, averageCost: float, unrealizedPNL: float, realizedPNL: float, account: str)

position

def position(account: str, contract: Contract, posSize: float, avgCost: float)

positionEnd

def positionEnd()

positionMulti

def positionMulti(reqId: int, account: str, modelCode: str, contract: Contract, pos: float, avgCost: float)

positionMultiEnd

def positionMultiEnd(reqId: int)

pnl

def pnl(reqId: int, dailyPnL: float, unrealizedPnL: float, realizedPnL: float)

pnlSingle

def pnlSingle(reqId: int, pos: int, dailyPnL: float, unrealizedPnL: float, realizedPnL: float, value: float)

openOrder

def openOrder(orderId: int, contract: Contract, order: Order, orderState: OrderState)

This wrapper is called to:

  • feed in open orders at startup;
  • feed in open orders or order updates from other clients and TWS if clientId=master id;
  • feed in manual orders and order updates from TWS if clientId=0;
  • handle openOrders and allOpenOrders responses.

openOrderEnd

def openOrderEnd()

completedOrder

def completedOrder(contract: Contract, order: Order, orderState: OrderState)

completedOrdersEnd

def completedOrdersEnd()

orderStatus

def orderStatus(orderId: int, status: str, filled: float, remaining: float, avgFillPrice: float, permId: int, parentId: int, lastFillPrice: float, clientId: int, whyHeld: str, mktCapPrice: float = 0.0)

execDetails

def execDetails(reqId: int, contract: Contract, execution: Execution)

This wrapper handles both live fills and responses to reqExecutions.

execDetailsEnd

def execDetailsEnd(reqId: int)

commissionReport

def commissionReport(commissionReport: CommissionReport)

orderBound

def orderBound(reqId: int, apiClientId: int, apiOrderId: int)

contractDetails

def contractDetails(reqId: int, contractDetails: ContractDetails)

contractDetailsEnd

def contractDetailsEnd(reqId: int)

symbolSamples

def symbolSamples(reqId: int, contractDescriptions: List[ContractDescription])

marketRule

def marketRule(marketRuleId: int, priceIncrements: List[PriceIncrement])

marketDataType

def marketDataType(reqId: int, marketDataId: int)

realtimeBar

def realtimeBar(reqId: int, time: int, open_: float, high: float, low: float, close: float, volume: float, wap: float, count: int)

historicalData

def historicalData(reqId: int, bar: BarData)

historicalDataEnd

def historicalDataEnd(reqId, _start: str, _end: str)

historicalDataUpdate

def historicalDataUpdate(reqId: int, bar: BarData)

headTimestamp

def headTimestamp(reqId: int, headTimestamp: str)

historicalTicks

def historicalTicks(reqId: int, ticks: List[HistoricalTick], done: bool)

historicalTicksBidAsk

def historicalTicksBidAsk(reqId: int, ticks: List[HistoricalTickBidAsk], done: bool)

historicalTicksLast

def historicalTicksLast(reqId: int, ticks: List[HistoricalTickLast], done: bool)

priceSizeTick

def priceSizeTick(reqId: int, tickType: int, price: float, size: float)

tickSize

def tickSize(reqId: int, tickType: int, size: float)

tickSnapshotEnd

def tickSnapshotEnd(reqId: int)

tickByTickAllLast

def tickByTickAllLast(reqId: int, tickType: int, time: int, price: float, size: float, tickAttribLast: TickAttribLast, exchange, specialConditions)

tickByTickBidAsk

def tickByTickBidAsk(reqId: int, time: int, bidPrice: float, askPrice: float, bidSize: float, askSize: float, tickAttribBidAsk: TickAttribBidAsk)

tickByTickMidPoint

def tickByTickMidPoint(reqId: int, time: int, midPoint: float)

tickString

def tickString(reqId: int, tickType: int, value: str)

tickGeneric

def tickGeneric(reqId: int, tickType: int, value: float)

tickReqParams

def tickReqParams(reqId: int, minTick: float, bboExchange: str, snapshotPermissions: int)

smartComponents

def smartComponents(reqId, components)

mktDepthExchanges

def mktDepthExchanges(depthMktDataDescriptions: List[DepthMktDataDescription])

updateMktDepth

def updateMktDepth(reqId: int, position: int, operation: int, side: int, price: float, size: float)

updateMktDepthL2

def updateMktDepthL2(reqId: int, position: int, marketMaker: str, operation: int, side: int, price: float, size: float, isSmartDepth: bool = False)

tickOptionComputation

def tickOptionComputation(reqId: int, tickType: int, tickAttrib: int, impliedVol: float, delta: float, optPrice: float, pvDividend: float, gamma: float, vega: float, theta: float, undPrice: float)

deltaNeutralValidation

def deltaNeutralValidation(reqId: int, dnc: DeltaNeutralContract)

fundamentalData

def fundamentalData(reqId: int, data: str)

scannerParameters

def scannerParameters(xml: str)

scannerData

def scannerData(reqId: int, rank: int, contractDetails: ContractDetails, distance: str, benchmark: str, projection: str, legsStr: str)

scannerDataEnd

def scannerDataEnd(reqId: int)

histogramData

def histogramData(reqId: int, items: List[HistogramData])

securityDefinitionOptionParameter

def securityDefinitionOptionParameter(reqId: int, exchange: str, underlyingConId: int, tradingClass: str, multiplier: str, expirations: List[str], strikes: List[float])

securityDefinitionOptionParameterEnd

def securityDefinitionOptionParameterEnd(reqId: int)

newsProviders

def newsProviders(newsProviders: List[NewsProvider])

tickNews

def tickNews(_reqId: int, timeStamp: int, providerCode: str, articleId: str, headline: str, extraData: str)

newsArticle

def newsArticle(reqId: int, articleType: int, articleText: str)

historicalNews

def historicalNews(reqId: int, time: str, providerCode: str, articleId: str, headline: str)

historicalNewsEnd

def historicalNewsEnd(reqId, _hasMore: bool)

updateNewsBulletin

def updateNewsBulletin(msgId: int, msgType: int, message: str, origExchange: str)

receiveFA

def receiveFA(_faDataType: int, faXmlData: str)

currentTime

def currentTime(time: int)

tickEFP

def tickEFP(reqId: int, tickType: int, basisPoints: float, formattedBasisPoints: str, totalDividends: float, holdDays: int, futureLastTradeDate: str, dividendImpact: float, dividendsToLastTradeDate: float)

historicalSchedule

def historicalSchedule(reqId: int, startDateTime: str, endDateTime: str, timeZone: str, sessions: List[HistoricalSession])

wshMetaData

def wshMetaData(reqId: int, dataJson: str)

wshEventData

def wshEventData(reqId: int, dataJson: str)

userInfo

def userInfo(reqId: int, whiteBrandingId: str)

softDollarTiers

def softDollarTiers(reqId: int, tiers: List[SoftDollarTier])

familyCodes

def familyCodes(familyCodes: List[FamilyCode])

configResponse

def configResponse(reqId: int, config: dict)

Receive API configuration response from TWS/Gateway.

Called in response to Client.reqConfig() request. Configuration is provided as key-value dictionary.

Args: reqId: Request identifier from reqConfig() call config: Dictionary of configuration parameters

Event: configResponseEvent(reqId: int, config: dict)

updateConfigResponse

def updateConfigResponse(reqId: int, success: bool, message: str)

Receive response to configuration update request.

Called in response to Client.updateConfig() request. Indicates whether the configuration update was successful.

Args: reqId: Request identifier from updateConfig() call success: True if update succeeded, False otherwise message: Status message or error description

Event: updateConfigResponseEvent(reqId: int, success: bool, message: str)

error

def error(reqId: int, errorCode: int, errorString: str, advancedOrderRejectJson: str = '', errorTime: str = '')

Receive error or warning message from TWS/Gateway.

Args: reqId: Request identifier (-1 for general errors) errorCode: Error code from TWS errorString: Error message description advancedOrderRejectJson: JSON string with order rejection details (v222+) errorTime: Timestamp when error occurred (v222+)

tcpDataArrived

def tcpDataArrived()

tcpDataProcessed

def tcpDataProcessed()