Hi there
I have install LEAN on my local computer and I can backtest trading strategy on lean using Binance data.
The local data dir is like this: “data/crypto/binance/hour” in which each coin's zip file(such as ‘btcusdt_trade.zip’) is saved and would be updated per hour.
My backtest code is as below:
from AlgorithmImports import *
class ConsolidatedIndicators(QCAlgorithm):
def Initialize(self):
self.SetTimeZone("UTC") #
self.SetStartDate(2021, 3, 1)
self.SetBrokerageModel(BrokerageName.Binance, AccountType.Margin)
self.SetAccountCurrency("USDT")
self.SetCash(100000)
self.SetBenchmark(Symbol.Create("BTCUSDT", SecurityType.Crypto, Market.Binance))
self.symbols = ['ADAUSDT', 'ALGOUSDT', 'APEUSDT', 'ATOMUSDT', 'AVAXUSDT', 'BNBUSDT', 'BTCUSDT', 'COSUSDT',
'DASHUSDT', 'DOGEUSDT', 'DOTUSDT', 'EGLDUSDT', 'EOSUSDT', 'ETCUSDT', 'ETHUSDT', 'FTMUSDT',
'GALAUSDT', 'GMTUSDT', 'GRTUSDT', 'HIGHUSDT', 'IMXUSDT', 'JASMYUSDT', 'LINKUSDT', 'LOKAUSDT',
'LRCUSDT', 'LTCUSDT', 'LUNAUSDT', 'MANAUSDT', 'MATICUSDT', 'MBLUSDT', 'NEARUSDT', 'OCEANUSDT',
'OGNUSDT', 'RAREUSDT', 'RUNEUSDT', 'SANDUSDT', 'SHIBUSDT', 'SOLUSDT', 'SPELLUSDT', 'TLMUSDT',
'TRXUSDT', 'USTUSDT', 'VETUSDT', 'VITEUSDT', 'WAVESUSDT', 'XRPUSDT', 'ZECUSDT']
for si in [*self.symbols]:
try:
self.AddCrypto(si, Resolution.Hour, Market.Binance) # .SetLeverage(3.3)
except:
self.symbols.remove(si)
self.Debug(f"can't load {si}")
def OnData(self, data):
self.Debug(f"data.Bars['BTCUSDT']:{data.Bars['BTCUSDT'].EndTime}")
# self.SetHoldings('ETHUSDT', 0.1)
self.MarketOrder('ETHUSDT', 0.1)
# self.Debug(f"run once")
I have two question:
- the latest time of each coin's data is ‘2022-03-22 04:00:00’, but it shows the latest time is ‘2022-03-21 04:00:00’ when backtest. why?
- since each coin's data is updated per hour, so I want to use above code to paper trading directly; but when I run this code, it shows ‘Error’. so shall I use these data to paper trade? if ok, how shall I do that?
Fred Painchaud
Hi Frank,
Without the data it is difficult to be affirmative. But:
1- It is most probably because in your data, the time used is the beginning of the bar, not the end. LEAN wants the end time.
2- What is the error you get? You paper trade with what? Binance? Because, for paper trading, you need to get some live data feed. I am not sure paper trading with Binance is supported by LEAN…
Fred
Frank cao
Hi Fred
Thanks for your reply.
I have change bar time from start_time to end_time; and when I run the project as below:
2. select 1 for paper trading; and then select 11 for custom data only.
I get the error:
after this error, the running is corrupt.
Fred Painchaud
Hi Frank,
I would try to contact support@quantconnect.com for this one. Not sure they will be able to help as this is about using your own data on your local env. But you are using LEAN CLI so it will certainly help!
It looks like the connection between your data and your LEAN instance is not properly done. OR maybe paper trading with Binance is not supported. It kinda rings a bell…
Fred
Frank cao
Hi Fred
Thanks a lot.
Frank cao
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!