I cloned existing template to test future history, I commented some of unimportan part of the code and add a log in OnSecuritiesChanged. As I understand history for selected future should be loged but it looks like there is no history. I tried some other things and I didn't get any history.
Jing Wu
Hi Borut,
The available resolution for futures are tick, second and minute. Daily is not available.
Borut
Thank you for the answer. If I change now to Resolution.Minute it works but when I try to do it in onData event, I still don't get any history data.
First I tried like this:
dfh = self.History(self.futureSymbol, 24, Resolution.Minute)
and then I tried like this:
chain = slice.FuturesChains[self.futureSymbol]
underlying = chain.Underlying
contracts = chain.Contracts.Value
for contract in contracts:
dfh = self.History(contract.Symbol, 24, Resolution.Minute)
self.Log(str(len(dfh)))
In the second case I got error: TypeError : unindexable object in believe in first line.
The code was copied for your documentaiton, there is still some C# code in python examples.
Jing Wu
slice.FutureChains is a FuturesChains class instead of a python dictionary. You can not use symbol index here.
# get a list of contracts for chain in slice.FutureChains: Â Â Â contracts = [i for i in chain.Value]
Borut
I finally figured out how history for future works. The proper code is here (you have to use Values instead of Value and 3th value in index (not 2nd or 1st) represents datetime of history element)
for chain in slice.FuturesChains.Values:
contracts = chain.Contracts.Values
#contract = sorted(contracts, key = lambda x: x.Expiry, reverse=True)[0] #current contract
for contract in contracts:
history = self.History(contract.Symbol, 100, Resolution.Minute)
self.Log(contract.Symbol)
for i in range(len(history)):
self.Log("History: " + str(history.iloc[i].name[1])
+ ": " + str(history.iloc[i].name[2].strftime("%m/%d/%Y %I:%M:%S %p"))
+ " > " + str(history.iloc[i]['close']))
I have still one question. Contract is somehow a qutoebar so I can get bid, ask last price, Can I get in onData event also a tradebar for futures (high, low, close price) in minute resolution?
Jing Wu
The difference between QuoteBar and TradeBar is the bid/ask. You could get the Open, High, Low and Close for both bid and ask price.
Borut
I still don't understand how to get high and low price for minute candle in onData event for Futures. Do you have an example?
Borut
So, this is not possible then?
Michael Manus
these example shows some properties of a tradebar.
Line 180
also check some other examples in the above library
Borut
I know properties of tradebar, I don't know how to get tradebar for futures. I already cheked all this examples before and no one uses tradebar for futures. I wouldn't ask you this question. So again how can I get tradebar (high, low prices) for futures (example please) in onData event for minute bar? I would appreciate if you answer my question.
Jing Wu
Hi Borut,
You could use
# open price
self.Securites[symbol].Open
# low price
self.Securites[symbol].Low
Same thing for the closing price and high price. The symbol here is a futures contract symbol object.
Borut
Thank you, This I was looking for. Just additional comment for symbol you have to use contract.Symbol from the code above.
Borut
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!