简体   繁体   中英

IBrokers - reqMktData

Has anyone tried different exchanges on IBrokers? I am trying to get either market data or historical data for stocks listed on ASX(Australian Exchange). I am subscribed to Chi-X Australia.

library("IBrokers")
tws <- twsConnect()
security = twsSTK("TLS",primary = "ASX")
is.twsConnection(security) #says false 
security_copy = twsEquity(symbol = "TLS",primary = "ASX")
reqMktData(tws,security)
data_stock = reqHistoricalData(tws, security)

I get this error messages.

TWS Message: 2 1 200 No security definition has been found for the request TWS Message: 2 1 300 Can't find EId with tickerId:1 waiting for TWS reply on TLS ....failed.

I don't use Chi-X, but as an example the code below works for the ASX and Globex exchanges. I hope this helps.

    library(IBrokers)

    tws = twsConnect()

    #ASX
    contract <-  twsSTK(symbol="BHP",exch="ASX",primary="ASX",currency="AUD")
    BHPHistorical <-  reqHistoricalData(tws, contract)
    BHPRealTime <- reqMktData(tws,contract,snapshot = TRUE)

    #SNFE futures data
    contract <-  twsFuture(symbol="SPI",exch="SNFE",primary="SNFE",currency="AUD",expiry="201712")          
    SPIHistorical <-  reqHistoricalData(tws, contract,barSize="30 mins",duration="1 M")
    SPIPRealTime <- reqMktData(tws,contract)

    #ASX Options data
    #using twsOption hasn't always worked
    contract <-  twsOption(local="XJOHU9",expiry = "20171116",strike="5750",right="C",exch="ASX",primary="",currency="AUD",symbol="",multiplier = 10,include_expired = FALSE,conId = 0)
    OptRealTime <- reqMktData(tws,contract)
    OptHistorical <-  reqHistoricalData(tws, contract)

    contract <-  twsContract(0,symbol="AP",sectype="OPT",exch="ASX",primary="ASX",expiry= "20171116",strike="5750",currency="AUD",right="C",local="",multiplier = "10",combo_legs_desc = "",comboleg = "",include_expired = "",secIdType = "",secId = "")
    OptRealTime <- reqMktData(tws,contract,snapshot = TRUE)
    OptHistorical <-  reqHistoricalData(tws, contract)


    #USA
    contract = twsFuture(symbol="ES",exch="GLOBEX",primary="GLOBEX",currency="USD",expiry="20171215")
    ESHistorical = reqHistoricalData(tws, contract)
    ESRealTime = reqMktData(tws, contract)

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