Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

""" Package implementing the Python API for the TWS/IB Gateway """

VERSION = {"major": 10, "minor": 46, "micro": 1}
VERSION = {"major": 10, "minor": 47, "micro": 1}


def get_version_string():
Expand Down
196 changes: 5 additions & 191 deletions ibapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
FAIL_SEND_CORDER, FAIL_SEND_OORDER, FAIL_SEND_REQCONTRACT, FAIL_SEND_REQMKTDEPTH, FAIL_SEND_CANMKTDEPTH,
FAIL_SEND_SERVER_LOG_LEVEL, FAIL_SEND_FA_REQUEST, FAIL_SEND_FA_REPLACE, FAIL_SEND_REQSCANNER, FAIL_SEND_CANSCANNER,
FAIL_SEND_REQSCANNERPARAMETERS, FAIL_SEND_REQHISTDATA, FAIL_SEND_CANHISTDATA, FAIL_SEND_REQRTBARS,
FAIL_SEND_CANRTBARS, FAIL_SEND_REQCURRTIME, FAIL_SEND_REQFUNDDATA, FAIL_SEND_CANFUNDDATA,
FAIL_SEND_CANRTBARS, FAIL_SEND_REQCURRTIME,
FAIL_SEND_REQCALCIMPLIEDVOLAT, FAIL_SEND_REQCALCOPTIONPRICE, FAIL_SEND_CANCALCIMPLIEDVOLAT,
FAIL_SEND_CANCALCOPTIONPRICE, FAIL_SEND_REQGLOBALCANCEL, FAIL_SEND_REQMARKETDATATYPE, FAIL_SEND_REQPOSITIONS,
FAIL_SEND_CANPOSITIONS, FAIL_SEND_REQACCOUNTDATA, FAIL_SEND_CANACCOUNTDATA, FAIL_SEND_VERIFYREQUEST,
Expand Down Expand Up @@ -126,7 +126,6 @@
MIN_SERVER_VER_REQ_HISTOGRAM,
MIN_SERVER_VER_HISTORICAL_TICKS,
MIN_SERVER_VER_SCANNER_GENERIC_OPTS,
MIN_SERVER_VER_FUNDAMENTAL_DATA,
MIN_SERVER_VER_REQ_NEWS_PROVIDERS,
MIN_SERVER_VER_REQ_NEWS_ARTICLE,
MIN_SERVER_VER_NEWS_QUERY_ORIGINS,
Expand Down Expand Up @@ -183,7 +182,7 @@
from ibapi.client_utils import createNewsBulletinsRequestProto, createCancelNewsBulletinsProto, createNewsArticleRequestProto, createNewsProvidersRequestProto
from ibapi.client_utils import createHistoricalNewsRequestProto, createWshMetaDataRequestProto, createCancelWshMetaDataProto, createWshEventDataRequestProto, createCancelWshEventDataProto
from ibapi.client_utils import createScannerParametersRequestProto, createScannerSubscriptionRequestProto, createCancelScannerSubscriptionProto
from ibapi.client_utils import createFundamentalsDataRequestProto, createCancelFundamentalsDataProto, createPnLRequestProto, createCancelPnLProto, createPnLSingleRequestProto, createCancelPnLSingleProto
from ibapi.client_utils import createPnLRequestProto, createCancelPnLProto, createPnLSingleRequestProto, createCancelPnLSingleProto
from ibapi.client_utils import createFARequestProto, createFAReplaceProto, createExerciseOptionsRequestProto
from ibapi.client_utils import createCalculateImpliedVolatilityRequestProto, createCancelCalculateImpliedVolatilityProto, createCalculateOptionPriceRequestProto, createCancelCalculateOptionPriceProto
from ibapi.client_utils import createSecDefOptParamsRequestProto, createSoftDollarTiersRequestProto, createFamilyCodesRequestProto, createMatchingSymbolsRequestProto
Expand Down Expand Up @@ -242,11 +241,9 @@
from ibapi.protobuf.ScannerParametersRequest_pb2 import ScannerParametersRequest as ScannerParametersRequestProto
from ibapi.protobuf.ScannerSubscriptionRequest_pb2 import ScannerSubscriptionRequest as ScannerSubscriptionRequestProto
from ibapi.protobuf.ScannerSubscription_pb2 import ScannerSubscription as ScannerSubscriptionProto
from ibapi.protobuf.FundamentalsDataRequest_pb2 import FundamentalsDataRequest as FundamentalsDataRequestProto
from ibapi.protobuf.PnLRequest_pb2 import PnLRequest as PnLRequestProto
from ibapi.protobuf.PnLSingleRequest_pb2 import PnLSingleRequest as PnLSingleRequestProto
from ibapi.protobuf.CancelScannerSubscription_pb2 import CancelScannerSubscription as CancelScannerSubscriptionProto
from ibapi.protobuf.CancelFundamentalsData_pb2 import CancelFundamentalsData as CancelFundamentalsDataProto
from ibapi.protobuf.CancelPnL_pb2 import CancelPnL as CancelPnLProto
from ibapi.protobuf.CancelPnLSingle_pb2 import CancelPnLSingle as CancelPnLSingleProto
from ibapi.protobuf.FARequest_pb2 import FARequest as FARequestProto
Expand Down Expand Up @@ -465,6 +462,9 @@ def connect(self, host, port, clientId):

try:
self.host = host

if not self.host: self.host = "127.0.0.1"

self.port = port
self.clientId = clientId
logger.debug(
Expand Down Expand Up @@ -5878,192 +5878,6 @@ def cancelRealTimeBarsProtoBuf(self, cancelRealTimeBarsProto: CancelRealTimeBars
self.wrapper.error(reqId, currentTimeMillis(), FAIL_SEND_CANRTBARS.code(), FAIL_SEND_CANRTBARS.msg() + str(ex))
return

#########################################################################
# Fundamental Data
#########################################################################

def reqFundamentalData(
self,
reqId: TickerId,
contract: Contract,
reportType: str,
fundamentalDataOptions: TagValueList,
):
"""Call this function to receive fundamental data for
stocks. The appropriate market data subscription must be set up in
Account Management before you can receive this data.
Fundamental data will be returned at EWrapper.fundamentalData().

reqFundamentalData() can handle conid specified in the Contract object,
but not tradingClass or multiplier. This is because reqFundamentalData()
is used only for stocks and stocks do not have a multiplier and
trading class.

reqId:tickerId - The ID of the data request. Ensures that responses are
matched to requests if several requests are in process.
contract:Contract - This structure contains a description of the
contract for which fundamental data is being requested.
reportType:str - One of the following XML reports:
ReportSnapshot (company overview)
ReportsFinSummary (financial summary)
ReportRatios (financial ratios)
ReportsFinStatements (financial statements)
RESC (analyst estimates)"""

if self.useProtoBuf(OUT.REQ_FUNDAMENTAL_DATA):
self.reqFundamentalsDataProtoBuf(createFundamentalsDataRequestProto(reqId, contract, reportType, fundamentalDataOptions))
return

self.logRequest(current_fn_name(), vars())

if not self.isConnected():
self.wrapper.error(NO_VALID_ID, currentTimeMillis(), NOT_CONNECTED.code(), NOT_CONNECTED.msg())
return

try:
VERSION = 2

if self.serverVersion() < MIN_SERVER_VER_FUNDAMENTAL_DATA:
self.wrapper.error(
NO_VALID_ID,
currentTimeMillis(),
UPDATE_TWS.code(),
UPDATE_TWS.msg()
+ " It does not support fundamental data request.",
)
return

if self.serverVersion() < MIN_SERVER_VER_TRADING_CLASS:
self.wrapper.error(
NO_VALID_ID,
currentTimeMillis(),
UPDATE_TWS.code(),
UPDATE_TWS.msg()
+ " It does not support conId parameter in reqFundamentalData.",
)
return

flds = []
flds += [
make_field(VERSION),
make_field(reqId),
]

# send contract fields
if self.serverVersion() >= MIN_SERVER_VER_TRADING_CLASS:
flds += [
make_field(contract.conId),
]
flds += [
make_field(contract.symbol),
make_field(contract.secType),
make_field(contract.exchange),
make_field(contract.primaryExchange),
make_field(contract.currency),
make_field(contract.localSymbol),
make_field(reportType),
]

if self.serverVersion() >= MIN_SERVER_VER_LINKING:
fundDataOptStr = ""
tagValuesCount = (
len(fundamentalDataOptions) if fundamentalDataOptions else 0
)
if fundamentalDataOptions:
for fundDataOption in fundamentalDataOptions:
fundDataOptStr += str(fundDataOption)
flds += [make_field(tagValuesCount), make_field(fundDataOptStr)]

msg = "".join(flds)
self.sendMsg(OUT.REQ_FUNDAMENTAL_DATA, msg)

except ClientException as ex:
self.wrapper.error(reqId, currentTimeMillis(), ex.code, ex.msg + ex.text)
return
except Exception as ex:
self.wrapper.error(reqId, currentTimeMillis(), FAIL_SEND_REQFUNDDATA.code(), FAIL_SEND_REQFUNDDATA.msg() + str(ex))
return

def reqFundamentalsDataProtoBuf(self, fundamentalsDataRequestProto: FundamentalsDataRequestProto):
if fundamentalsDataRequestProto is None:
return

self.logRequest(current_fn_name(), vars())

reqId = fundamentalsDataRequestProto.reqId if fundamentalsDataRequestProto.HasField('reqId') else NO_VALID_ID

if not self.isConnected():
self.wrapper.error(reqId, currentTimeMillis(), NOT_CONNECTED.code(), NOT_CONNECTED.msg())
return

try:
serializedString = fundamentalsDataRequestProto.SerializeToString()
self.sendMsgProtoBuf(OUT.REQ_FUNDAMENTAL_DATA + PROTOBUF_MSG_ID, serializedString)

except ClientException as ex:
self.wrapper.error(reqId, currentTimeMillis(), ex.code, ex.msg + ex.text)
return
except Exception as ex:
self.wrapper.error(reqId, currentTimeMillis(), FAIL_SEND_REQFUNDDATA.code(), FAIL_SEND_REQFUNDDATA.msg() + str(ex))
return

def cancelFundamentalData(self, reqId: TickerId):
"""Call this function to stop receiving fundamental data.

reqId:TickerId - The ID of the data request."""

if self.useProtoBuf(OUT.CANCEL_FUNDAMENTAL_DATA):
self.cancelFundamentalsDataProtoBuf(createCancelFundamentalsDataProto(reqId))
return

self.logRequest(current_fn_name(), vars())

if not self.isConnected():
self.wrapper.error(NO_VALID_ID, currentTimeMillis(), NOT_CONNECTED.code(), NOT_CONNECTED.msg())
return

if self.serverVersion() < MIN_SERVER_VER_FUNDAMENTAL_DATA:
self.wrapper.error(
NO_VALID_ID,
currentTimeMillis(),
UPDATE_TWS.code(),
UPDATE_TWS.msg() + " It does not support fundamental data request.",
)
return

try:
VERSION = 1

msg = (
make_field(VERSION)
+ make_field(reqId)
)

self.sendMsg(OUT.CANCEL_FUNDAMENTAL_DATA, msg)
except Exception as ex:
self.wrapper.error(reqId, currentTimeMillis(), FAIL_SEND_CANFUNDDATA.code(), FAIL_SEND_CANFUNDDATA.msg() + str(ex))
return

def cancelFundamentalsDataProtoBuf(self, cancelFundamentalsDataProto: CancelFundamentalsDataProto):
if cancelFundamentalsDataProto is None:
return

self.logRequest(current_fn_name(), vars())

reqId = cancelFundamentalsDataProto.reqId if cancelFundamentalsDataProto.HasField('reqId') else NO_VALID_ID

if not self.isConnected():
self.wrapper.error(reqId, currentTimeMillis(), NOT_CONNECTED.code(), NOT_CONNECTED.msg())
return

try:
serializedString = cancelFundamentalsDataProto.SerializeToString()
self.sendMsgProtoBuf(OUT.CANCEL_FUNDAMENTAL_DATA + PROTOBUF_MSG_ID, serializedString)

except Exception as ex:
self.wrapper.error(reqId, currentTimeMillis(), FAIL_SEND_CANFUNDDATA.code(), FAIL_SEND_CANFUNDDATA.msg() + str(ex))
return

########################################################################
# News
#########################################################################
Expand Down
18 changes: 0 additions & 18 deletions ibapi/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@
from ibapi.protobuf.ScannerParametersRequest_pb2 import ScannerParametersRequest as ScannerParametersRequestProto
from ibapi.protobuf.ScannerSubscriptionRequest_pb2 import ScannerSubscriptionRequest as ScannerSubscriptionRequestProto
from ibapi.protobuf.ScannerSubscription_pb2 import ScannerSubscription as ScannerSubscriptionProto
from ibapi.protobuf.FundamentalsDataRequest_pb2 import FundamentalsDataRequest as FundamentalsDataRequestProto
from ibapi.protobuf.PnLRequest_pb2 import PnLRequest as PnLRequestProto
from ibapi.protobuf.PnLSingleRequest_pb2 import PnLSingleRequest as PnLSingleRequestProto
from ibapi.protobuf.CancelScannerSubscription_pb2 import CancelScannerSubscription as CancelScannerSubscriptionProto
from ibapi.protobuf.CancelFundamentalsData_pb2 import CancelFundamentalsData as CancelFundamentalsDataProto
from ibapi.protobuf.CancelPnL_pb2 import CancelPnL as CancelPnLProto
from ibapi.protobuf.CancelPnLSingle_pb2 import CancelPnLSingle as CancelPnLSingleProto
from ibapi.protobuf.FARequest_pb2 import FARequest as FARequestProto
Expand Down Expand Up @@ -884,16 +882,6 @@ def createScannerSubscriptionProto(subscription: ScannerSubscription,
fillTagValueList(scannerSubscriptionFilterOptionsList, scannerSubscriptionProto.scannerSubscriptionFilterOptions)
return scannerSubscriptionProto

@staticmethod
def createFundamentalsDataRequestProto(reqId: int, contract: Contract, reportType: str, fundamentalsDataOptionsList: TagValueList) -> FundamentalsDataRequestProto:
fundamentalsDataRequestProto = FundamentalsDataRequestProto()
if isValidIntValue(reqId): fundamentalsDataRequestProto.reqId = reqId
contractProto = createContractProto(contract, None)
if contractProto is not None: fundamentalsDataRequestProto.contract.CopyFrom(contractProto)
if reportType: fundamentalsDataRequestProto.reportType = reportType
fillTagValueList(fundamentalsDataOptionsList, fundamentalsDataRequestProto.fundamentalsDataOptions)
return fundamentalsDataRequestProto

@staticmethod
def createPnLRequestProto(reqId: int, account: str, modelCode: str) -> PnLRequestProto:
pnlRequestProto = PnLRequestProto()
Expand All @@ -917,12 +905,6 @@ def createCancelScannerSubscriptionProto(reqId: int) -> CancelScannerSubscriptio
if isValidIntValue(reqId): cancelScannerSubscriptionProto.reqId = reqId
return cancelScannerSubscriptionProto

@staticmethod
def createCancelFundamentalsDataProto(reqId: int) -> CancelFundamentalsDataProto:
cancelFundamentalsDataProto = CancelFundamentalsDataProto()
if isValidIntValue(reqId): cancelFundamentalsDataProto.reqId = reqId
return cancelFundamentalsDataProto

@staticmethod
def createCancelPnLProto(reqId: int) -> CancelPnLProto:
cancelPnLProto = CancelPnLProto()
Expand Down
2 changes: 0 additions & 2 deletions ibapi/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@
OUT.REQ_SCANNER_PARAMETERS: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.REQ_SCANNER_SUBSCRIPTION: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.CANCEL_SCANNER_SUBSCRIPTION: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.REQ_FUNDAMENTAL_DATA: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.CANCEL_FUNDAMENTAL_DATA: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.REQ_PNL: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.CANCEL_PNL: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
OUT.REQ_PNL_SINGLE: MIN_SERVER_VER_PROTOBUF_SCAN_DATA,
Expand Down
14 changes: 0 additions & 14 deletions ibapi/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
from ibapi.protobuf.TickNews_pb2 import TickNews as TickNewsProto
from ibapi.protobuf.ScannerParameters_pb2 import ScannerParameters as ScannerParametersProto
from ibapi.protobuf.ScannerData_pb2 import ScannerData as ScannerDataProto
from ibapi.protobuf.FundamentalsData_pb2 import FundamentalsData as FundamentalsDataProto
from ibapi.protobuf.PnL_pb2 import PnL as PnLProto
from ibapi.protobuf.PnLSingle_pb2 import PnLSingle as PnLSingleProto
from ibapi.protobuf.ReceiveFA_pb2 import ReceiveFA as ReceiveFAProto
Expand Down Expand Up @@ -2565,17 +2564,6 @@ def processScannerParametersMsgProtoBuf(self, protobuf):

self.wrapper.scannerParameters(xml)

def processFundamentalsDataMsgProtoBuf(self, protobuf):
fundamentalsDataProto = FundamentalsDataProto()
fundamentalsDataProto.ParseFromString(protobuf)

self.wrapper.fundamentalsDataProtoBuf(fundamentalsDataProto)

reqId = fundamentalsDataProto.reqId if fundamentalsDataProto.HasField('reqId') else NO_VALID_ID
data = fundamentalsDataProto.data if fundamentalsDataProto.HasField('data') else ""

self.wrapper.fundamentalData(reqId, data)

def processReceiveFAMsgProtoBuf(self, protobuf):
receiveFAProto = ReceiveFAProto()
receiveFAProto.ParseFromString(protobuf)
Expand Down Expand Up @@ -2820,7 +2808,6 @@ def processProtoBuf(self, protoBuf, msgId):
IN.TICK_EFP: HandleInfo(wrap=EWrapper.tickEFP),
IN.CURRENT_TIME: HandleInfo(wrap=EWrapper.currentTime),
IN.REAL_TIME_BARS: HandleInfo(proc=processRealTimeBarMsg),
IN.FUNDAMENTAL_DATA: HandleInfo(wrap=EWrapper.fundamentalData),
IN.CONTRACT_DATA_END: HandleInfo(wrap=EWrapper.contractDetailsEnd),
IN.OPEN_ORDER_END: HandleInfo(wrap=EWrapper.openOrderEnd),
IN.ACCT_DOWNLOAD_END: HandleInfo(wrap=EWrapper.accountDownloadEnd),
Expand Down Expand Up @@ -2941,7 +2928,6 @@ def processProtoBuf(self, protoBuf, msgId):
IN.TICK_NEWS: HandleInfo(proc=processTickNewsMsgProtoBuf),
IN.SCANNER_PARAMETERS: HandleInfo(proc=processScannerParametersMsgProtoBuf),
IN.SCANNER_DATA: HandleInfo(proc=processScannerDataMsgProtoBuf),
IN.FUNDAMENTAL_DATA: HandleInfo(proc=processFundamentalsDataMsgProtoBuf),
IN.PNL: HandleInfo(proc=processPnLMsgProtoBuf),
IN.PNL_SINGLE: HandleInfo(proc=processPnLSingleMsgProtoBuf),
IN.RECEIVE_FA: HandleInfo(proc=processReceiveFAMsgProtoBuf),
Expand Down
2 changes: 0 additions & 2 deletions ibapi/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def msg(self):
FAIL_SEND_REQRTBARS = CodeMsgPair(529, "Request Real-time Bar Data Sending Error - ")
FAIL_SEND_CANRTBARS = CodeMsgPair(530, "Cancel Real-time Bar Data Sending Error - ")
FAIL_SEND_REQCURRTIME = CodeMsgPair(531, "Request Current Time Sending Error - ")
FAIL_SEND_REQFUNDDATA = CodeMsgPair(532, "Request Fundamental Data Sending Error - ")
FAIL_SEND_CANFUNDDATA = CodeMsgPair(533, "Cancel Fundamental Data Sending Error - ")
FAIL_SEND_REQCALCIMPLIEDVOLAT = CodeMsgPair(534, "Request Calculate Implied Volatility Sending Error - ")
FAIL_SEND_REQCALCOPTIONPRICE = CodeMsgPair(535, "Request Calculate Option Price Sending Error - ")
FAIL_SEND_CANCALCIMPLIEDVOLAT = CodeMsgPair(536, "Cancel Calculate Implied Volatility Sending Error - ")
Expand Down
3 changes: 0 additions & 3 deletions ibapi/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class IN:
TICK_EFP = 47
CURRENT_TIME = 49
REAL_TIME_BARS = 50
FUNDAMENTAL_DATA = 51
CONTRACT_DATA_END = 52
OPEN_ORDER_END = 53
ACCT_DOWNLOAD_END = 54
Expand Down Expand Up @@ -133,8 +132,6 @@ class OUT:
REQ_CURRENT_TIME = 49
REQ_REAL_TIME_BARS = 50
CANCEL_REAL_TIME_BARS = 51
REQ_FUNDAMENTAL_DATA = 52
CANCEL_FUNDAMENTAL_DATA = 53
REQ_CALC_IMPLIED_VOLAT = 54
REQ_CALC_OPTION_PRICE = 55
CANCEL_CALC_IMPLIED_VOLAT = 56
Expand Down
1 change: 0 additions & 1 deletion ibapi/server_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# MIN_SERVER_VER_WHAT_IF_ORDERS = 36
# MIN_SERVER_VER_CONTRACT_CONID = 37
MIN_SERVER_VER_PTA_ORDERS = 39
MIN_SERVER_VER_FUNDAMENTAL_DATA = 40
MIN_SERVER_VER_DELTA_NEUTRAL = 40
MIN_SERVER_VER_CONTRACT_DATA_CHAIN = 40
MIN_SERVER_VER_SCALE_ORDERS2 = 40
Expand Down
2 changes: 1 addition & 1 deletion ibapi/ticktype.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"CLOSE_EFP_COMPUTATION",
"LAST_TIMESTAMP",
"SHORTABLE",
"FUNDAMENTAL_RATIOS",
"NOT_USED",
"RT_VOLUME",
"HALTED",
"BID_YIELD",
Expand Down
Loading