I'm following the sample code here:
https://www.quantconnect.com/docs/v2/writing-algorithms/datasets/coinapi/binance-crypto-future-price-data
I set the date to something more recent. In the sample code the brokerage model is set twice. I tried with both.
class CoinAPIDataAlgorithm(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2020, 6, 1)
self.set_end_date(2021, 6, 1)
# Set Account Currency to Binance Stable Coin for USD
self.set_account_currency("BUSD")
self.set_cash(100000)
self.set_brokerage_model(BrokerageName.BINANCE_FUTURES, AccountType.MARGIN)
self.set_brokerage_model(BrokerageName.BINANCE_COIN_FUTURES, AccountType.MARGIN)
crypto_future = self.add_crypto_future("BTCBUSD", Resolution.MINUTE)
# perpetual futures does not have a filter function
self.btcbusd = crypto_future.symbol
I then call historical data which is also from the sample. However I get no data. length == 0
What am I doing wrong?
# TradeBar objects
history_trade_bars = self.history[TradeBar](self.btcbusd, 100, Resolution.MINUTE)
The Futures Trader
Hi there,
I see a few potential issues that could explain why you're getting no historical data:
You're setting the brokerage model twice, which means the second call overwrites the first:
BTCBUSD is a USDT-margined future, so you should only use:
Use BINANCE_COIN_FUTURES only for coin-margined futures (like BTCUSD_PERP).
When are you calling the history() method? If you're calling it immediately in Initialize(), the data might not be ready yet. Try calling it in OnData() or after the algorithm has warmed up.
Example:
Let me know what you find!
Greetings,
Jordy
Ectrist
When updating the date range, to 2024 - 2025 it worked for me. You can try below code, when setting to the original date range 2020 - 2021 it returns also no data for me.
The duplicate brokerage model setting is from the original code in the QC docs, I guess one can be left out indeed (but I am not an expert ! also starting to learn how this works :-)).
C
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!