IBrokers - reqMktData

时间:2017-06-29 13:15:21

标签: r interactive-brokers ibrokers asx

有没有人尝试过IBrokers的不同交流?我试图获得ASX(澳大利亚交易所)上市股票的市场数据或历史数据。我订阅了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)

我收到此错误消息。

TWS消息:2 1 200未找到该请求的安全定义 TWS消息:2 1 300找不到带有tickerId的EId:1 在TLS等待TWS回复....失败。

1 个答案:

答案 0 :(得分:0)

我不使用Chi-X,但作为示例,下面的代码适用于ASX和Globex交换。我希望这会有所帮助。

    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)