HI,
I installed LEAN CLI locally and tried to test Binance or Bitfinex paper trading, both of them cannot work. I already followed '
https://www.quantconnect.com/docs/v2/lean-cli/tutorials/live-trading/local-live-trading' to setup lean.json correctly.
The script is simple like below:
class Test7(QCAlgorithm): def Initialize(self): self.AddCrypto("BTCUSD", Resolution.Minute, Market.Binance) def OnData(self, data): self.Debug(data.Time)1. When I set live-paper data-queue-handler as 'BinanceBrokerage', the 'lean live test7 live-paper' output stop at as below, then just pause there
20210415 02:01:14.041 TRACE:: DataManager.AddSubscription(): Added BTCUSD,BTCUSD,Minute,TradeBar,Trade,Adjusted. Start: 4/15/2021 2:01:14 AM. End: 12/31/2050 5:00:00 AM
20210415 02:01:14.045 TRACE:: DataManager.AddSubscription(): Added BTCUSD,BTCUSD,Minute,QuoteBar,Quote,Adjusted. Start: 4/15/2021 2:01:14 AM. End: 12/31/2050 5:00:00 AM
20210415 02:01:14.049 TRACE:: DataManager.AddSubscription(): Added SPY,SPY,Minute,TradeBar,Trade,Adjusted,Internal. Start: 4/14/2021 7:59:00 PM. End: 12/31/2050 5:00:00 AM
20210415 02:01:14.049 TRACE:: UniverseSelection.AddPendingInternalDataFeeds(): Adding internal benchmark data feed SPY,SPY,Minute,TradeBar,Trade,Adjusted,Internal
20210415 02:01:14.051 TRACE:: DataManager.RemoveSubscription(): Removed SPY,SPY,Minute,TradeBar,Trade,Adjusted,Internal
20210415 02:01:14.167 TRACE:: Debug: Paper Brokerage account base currency: USD
2. When I set live-paper data-queue-handler as 'BitfinexBrokerage' (I also update the scirpt to use Market.Bitfinex)
, the 'lean live test7 live-paper' output has error as below:
20210415 02:07:24.690 TRACE:: LiveTradingDataFeed.GetDataQueueHandler(): will use BitfinexBrokerage
20210415 02:07:24.694 ERROR:: Engine.Run(): System.MissingMethodException: Default constructor not found for type QuantConnect.Brokerages.Bitfinex.BitfinexBrokerage
at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in
<b0e1ad7573a24fd5a9f2af9595e677e7>:0
at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark)
[0x00027] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <b0e1ad7573a24fd5a9f2af9595e677e7>:0
at QuantConnect.Util.Composer.GetExportedValueByTypeName[T] (System.String typeName) [0x000b1] in <efd746b365db4bf0ab2b88f1f55b9dce>:0
at QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed.GetDataQueueHandler () [0x00022] in <721fec37ec5f4038996cdd30e5719a40>:0
at QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed.Initialize (QuantConnect.Interfaces.IAlgorithm algorithm, QuantConnect.Packets.AlgorithmNodePacket job,
QuantConnect.Lean.Engine.Results.IResultHandler resultHandler, QuantConnect.Interfaces.IMapFileProvider mapFileProvider, QuantConnect.Interfaces.IFactorFileProvider
factorFileProvider, QuantConnect.Interfaces.IDataProvider dataProvider, QuantConnect.Lean.Engine.DataFeeds.IDataFeedSubscriptionManager subscriptionManager,
QuantConnect.Lean.Engine.DataFeeds.IDataFeedTimeProvider dataFeedTimeProvider, QuantConnect.Interfaces.IDataChannelProvider dataChannelProvider) [0x00099] in
<721fec37ec5f4038996cdd30e5719a40>:0
at QuantConnect.Lean.Engine.Engine.Run (QuantConnect.Packets.AlgorithmNodePacket job, QuantConnect.Lean.Engine.AlgorithmManager manager, System.String assemblyPath,
QuantConnect.Util.WorkerThread workerThread) [0x003e3] in <721fec37ec5f4038996cdd30e5719a40>:0
20210415 02:07:24.695 TRACE:: JOB HANDLERS:
20210415 02:07:24.695 TRACE:: DataFeed: QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed
20210415 02:07:24.695 TRACE:: Setup: QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler
20210415 02:07:24.695 TRACE:: RealTime: QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler
20210415 02:07:24.695 TRACE:: Results: QuantConnect.Lean.Engine.Results.LiveTradingResultHandler
20210415 02:07:24.695 TRACE:: Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20210415 02:07:24.695 TRACE:: Alpha: QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20210415 02:07:24.695 TRACE:: ObjectStore: QuantConnect.Lean.Engine.Storage.LocalObjectStore
20210415 02:07:24.695 TRACE:: Brokerage: QuantConnect.Brokerages.Paper.PaperBrokerage
20210415 02:07:24.696 TRACE:: DefaultAlphaHandler.Exit(): Exiting...
20210415 02:07:24.701 TRACE:: DefaultAlphaHandler.Exit(): Ended
20210415 02:07:24.704 ERROR:: Algorithm.Initialize() Error: Default constructor not found for type QuantConnect.Brokerages.Bitfinex.BitfinexBrokerage Stack Trace: Default constructor
not found for type QuantConnect.Brokerages.Bitfinex.BitfinexBrokerage
Default constructor not found for type QuantConnect.Brokerages.Bitfinex.BitfinexBrokerage
20210415 02:07:24.704 TRACE:: StopSafely(): waiting for 'Result Thread' thread to stop...
20210415 02:07:24.709 ERROR:: LiveTradingResultHandler.Update(): Algorithm not yet initialized.
20210415 02:07:24.709 TRACE:: LiveTradingResultHandler.Run(): Ending Thread...
20210415 02:07:24.710 TRACE:: LiveTradingResultHandler.SendFinalResult(): Starting...
20210415 02:07:24.761 TRACE:: LiveTradingResultHandler.SendFinalResult(): Finished storing results. Start sending...
20210415 02:07:24.761 TRACE:: LiveTradingResultHandler.SendFinalResult(): Ended
20210415 02:07:24.761 TRACE:: Engine.Run(): Disconnecting from brokerage...
20210415 02:07:24.761 TRACE:: Engine.Run(): Disposing of setup handler...
20210415 02:07:24.762 TRACE:: BrokerageSetupHandler.Setup(): did not find any data queue handler to dispose
20210415 02:07:24.762 TRACE:: Engine.Main(): Analysis Completed and Results Posted.
Engine.Main(): Analysis Complete.
20210415 02:07:24.762 TRACE:: Engine.Main(): Packet removed from queue: main
20210415 02:07:24.763 TRACE:: LeanEngineSystemHandlers.Dispose(): start...
20210415 02:07:24.763 TRACE:: LeanEngineSystemHandlers.Dispose(): Disposed of system handlers.
20210415 02:07:24.763 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): start...
20210415 02:07:24.763 TRACE:: BrokerageSetupHandler.Setup(): did not find any data queue handler to dispose
20210415 02:07:24.764 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): Disposed of algorithm handlers.
20210415 02:07:24.765 TRACE:: Program.Main(): Exiting Lean...
Error: Something went wrong while running 'test7' in the 'live-paper' environment,
Do we know why the local paper trading cannot work?
Thanks,
henry
Jasper van Merle
Hi Henry,
Regarding the Binance issue:
You are subscribing to BTCUSD data, which is a pair Binance doesn't offer, so there is no data for it. In a previous comment, you said you updated your symbol properties database to replace all occurrences of USDT with USD, you'll have to undo these changes to subscribe to BTCUSDT data from Binance. You can find the original symbol properties database on GitHub.
After making these changes you'll probably encounter an error about a required data feed for USDTUSD or USDUSDT. You can fix this error by changing your account currency to USDT and by updating the benchmark to a pair that is available on Binance, like in the example below:
from QuantConnect import Market, Resolution, SecurityType, Symbol from QuantConnect.Algorithm import QCAlgorithm class MyAlgorithm(QCAlgorithm): def Initialize(self): # The default currency is USD, which Binance doesn't offer self.SetAccountCurrency("USDT") # Use BTCUSDT from Binance as benchmark self.SetBenchmark(Symbol.Create("BTCUSDT", SecurityType.Crypto, Market.Binance)) # Subscribe to BTCUSDT data self.AddCrypto("BTCUSDT", Resolution.Second, Market.Binance) def OnData(self, data): self.Debug(data.Time)
The Bitfinex issue appears to be a bug in LEAN, I have created a pull request to fix it.
Henry111
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!