If CashBuyingPowerModel finds an invalid security, throw an exception.
Actual Behavior
If CashBuyingPowerModel finds an invalid security, throw an exception, the order is invalid and we don't know why:
Order Error: id: 1, Error executing margin models: Object reference not set to an instance of an object.
In the syslog, we can read:
2024-06-14T20:53:43.6886306Z ERROR:: BrokerageTransactionHandler.HandleSubmitOrderRequest(): System.NullReferenceException: Object reference not set to an instance of an object.
at QuantConnect.Securities.CashBuyingPowerModel.GetOpenOrdersReservedQuantity(SecurityPortfolioManager portfolio, Security security, Order order) in /Common/Securities/CashBuyingPowerModel.cs:line 416
It happens because the BaseCurrency of one of the securities is null. For example if the algorithm adds BTGUSDT crypto future:
self.add_crypto_future("BTGUSDT")
it's not in our database, so the base currency is null.
Potential Solution
When we create a CryptoFuture object, we should throw an exception if the baseCurrency parameter is null (CryptoFuture.cs#L76)
Checklist
[x] I have completely filled out this template
[x] I have confirmed that this issue exists on the current master branch
[x] I have confirmed that this is not a duplicate issue by searching issues
[x] I have provided detailed steps to reproduce the issue
Expected Behavior
If
CashBuyingPowerModel
finds an invalid security, throw an exception.Actual Behavior
If
CashBuyingPowerModel
finds an invalid security, throw an exception, the order is invalid and we don't know why:Order Error: id: 1, Error executing margin models: Object reference not set to an instance of an object.
In the syslog, we can read:
It happens because the
BaseCurrency
of one of the securities isnull
. For example if the algorithm adds BTGUSDT crypto future:it's not in our database, so the base currency is
null
.Potential Solution
When we create a
CryptoFuture
object, we should throw an exception if thebaseCurrency
parameter isnull
(CryptoFuture.cs#L76)Checklist
master
branch