Hello all, I am looking to build a strategy that trades MES futures with an indicator. I have used an algorithm similar to this a few months ago and the logic worked but since then it seems like the API has changed and the way I was able to trade futures then no longer works. I really just cannot even get QC to place the order. All the documentation I can find seem to use outdated API and the responses Mia is giving me do the same. The latest error I am getting, using this code below basically made entirely by Mia, is:
"Runtime Error: 'MethodBinding' object is not iterable
at on_data
valid_mes = [c for c in mes_contracts if c.open_interest > 200]"
What can I do to fix this? Is there another standard way I can just place a futures order?
def on_data(self, slice: Slice) -> None:
if self.is_warming_up: return
#Track MES contract to trade
mes_chains = slice.future_chains.get(self.mes.symbol)
if mes_chains is not None:
# Filter out contracts with open interest <= 200
mes_contracts = mes_chains.contracts.values
valid_mes = [c for c in mes_contracts if c.open_interest > 200]
if valid_mes:
# Sort descending by open interest, pick top
sorted_mes = sorted(valid_es, key=lambda c: c.open_interest, reverse=True)
top_mes_contract = sorted_es[0]
top_mes_symbol = top_mes_contract.symbol
Louis Szeto
HI Ethan
In python, .Keys and .Values in C# should be transformed into .keys() and .values(), so you can just modify line 9 into:
Best
Louis
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.
Ethan Wertlieb
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!