hadrianl / ibapi

Interactive Brokers API - GoLang Implement
MIT License
137 stars 59 forks source link

ReqHistoricalData() example? #13

Closed fiber closed 4 years ago

fiber commented 4 years ago

I can't get ReqHistoricalData() to work. Do you have an example?

c := ibapi.Contract{ContractID: 309359839, Symbol: "HSI", SecurityType: "FUT", Exchange: "HKFE"}
ic.ReqMarketDataType(3)
ic.ReqHistoricalData(ic.GetReqID(), &c, "", "1 W", "1 D", "MIDPOINT", false, 1, true, nil)
hadrianl commented 4 years ago

u could get the official doc right here

hadrianl commented 4 years ago

data would deliver via wrapper.HistoricalData()

hadrianl commented 4 years ago

it seems that u got an invalid bar sizes "1 D". it should be "1 day"

fiber commented 4 years ago

I got this to work. It's essential to have a subscription for market data. I had meant to access delayed data without a subscription, which does not work.

hadrianl commented 4 years ago

1.ReqHistoricalData always require a subscription, set the market data type won't work for historical data 2.ReqMktData will work with this 3.if you already subscribed the market data, it will always return live data even though you requested delayed data 4.if you did ReqMktData right after ReqMarketDataType, that may not work properly.TWS or gateway might have not set the market data type to delayed before it got ReqMarketDataType. So, ReqMarketDataType after wrapper.MarketDataType callback is better.