Hello, I have several questions about creating a custom brokerage. I have already completed my custom brokerage (dYdX), but I am encountering errors during initialization.
Here is my algorithm's initialization:
+ Expand
public override void Initialize()
{
const string market = "dydx";
Transactions.MarketOrderFillTimeout = TimeSpan.FromMinutes(15);
SetBrokerageModel(new DydxBrokerageModel());
var marketHoursDatabase = QuantConnect.Securities.MarketHoursDatabase.FromDataFolder();
var alwaysOpen = QuantConnect.Securities.SecurityExchangeHours.AlwaysOpen(DateTimeZone.Utc);
marketHoursDatabase.SetEntry(market, "[*]", SecurityType.CryptoFuture, alwaysOpen);
_symbol = AddCryptoFuture("BTCUSD", Resolution.Tick, market).Symbol;
Portfolio.CashBook.Add("BTC", 0, 0);
//Portfolio.CashBook["BTC"].SetAmount(30000);
SetBenchmark(_symbol);
}
Here is my live mode config:
"live-dydx": {
"live-mode": true,
"live-mode-brokerage": "DydxBrokerage",
"setup-handler": "QuantConnect.Lean.Engine.Setup.BrokerageSetupHandler",
"result-handler": "QuantConnect.Lean.Engine.Results.LiveTradingResultHandler",
"data-feed-handler": "QuantConnect.Lean.Engine.DataFeeds.LiveTradingDataFeed",
//"data-queue-handler": [ "DydxBrokerageDataQueue" ],
"data-queue-handler": [ "DydxBrokerage" ],
"real-time-handler": "QuantConnect.Lean.Engine.RealTime.LiveTradingRealTimeHandler",
//"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler",
"transaction-handler": "QuantConnect.Lean.Engine.TransactionHandlers.DydxBrokerageTransactionHandler"
}
No tradable pair was found for currency BTC. The conversion rate to the account currency (USD) will be set to zero. Markets: [Forex:OANDA, CFD:OANDA, Crypto:Coinbase]
Even if this issue is resolved, it seems my custom broker is not as flexible as the supported brokers. Maybe I'm missing some implementation details, or perhaps it's not possible to fully integrate a custom brokerage without modifying the Lean engine source code.
Why is Lean trying to use Coinbase or OANDA when I've specified my custom broker?
Mia Alissi
Based on the information gathered, here is a step-by-step guide to help you troubleshoot and debug your custom dYdX brokerage implementation:
Custom Brokerage Debugging Checklist
Brokerage Model Implementation:
connect
,disconnect
,is_connected
, etc.).Market Hours Configuration:
Cashbook Setup:
Initializing and Configuring the Brokerage:
Testing Within Lean Engine:
BrokerageFactory
and the relevant configuration reference your custom brokerage class.Foreign Exchange Errors with Cryptocurrencies:
Logging and Diagnostics:
Final Steps:
By following these steps, you should be able to address any issues with your custom brokerage implementation and ensure it works seamlessly within the QuantConnect ecosystem. If the problem persists, you may need to check for updates or modifications required in the Lean engine source code to fully support your custom brokerage features.
Sources: Brokerages - QuantConnect.com, Key Concepts - QuantConnect.com, Brokerage Model Algorithm, Custom Brokerage Model Regression Algorithm, Brokerage Activity Event Handling Algorithm
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!