Hi!
I'm trying to run a basic Crypto example with custom data on LEAN platform. By default it works ok, but I noticed fees are not calculated, therefor I added:
SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
But, when I do that, I start getting errors:
20190330 22:22:38.345 ERROR:: Order Error: id: 2734, Insufficient buying power to complete order (Value:97897.68), Reason: The 'BTC' security is not supported by this cash model. Currently only SecurityType.Crypto and SecurityType.Forex are supported.
Another thing, when I set quantity to < 1 (e.g. 0.1), I get different error:
20190330 22:38:50.193 ERROR:: Unable to submit order with id -10 which quantity (0.1) is less than lot size (1).
By doing some code inspection, my first guess is that Data is not recognized ar Crypto, because AddData() doesn't specify this (<Crypto>), while AddCrypto() does:
public Security AddData<T>(string symbol, Resolution resolution = Resolution.Minute)
where T : IBaseData, new()
{
return AddData<T>(symbol, resolution, fillDataForward: false, leverage: 1m);
}
public Crypto AddCrypto(string ticker, Resolution resolution = Resolution.Minute, string market = null, bool fillDataForward = true, decimal leverage = 0m)
{
return AddSecurity<Crypto>(SecurityType.Crypto, ticker, resolution, market, fillDataForward, leverage, false);
}
Is there a way to sidestep this issue? Is there another working example?
Any help would be greatly appreciated. Thanks!
Jack Simonson
Hi Deandree,
Custom data is a Security of type base, and so it won't be recognized as Crypto even though it's Bitcoin data, and this is what is preventing you from using specific Brokerage Models. Instead, you can get around the fee issue by specifying the Fee Model you want to use when initializing the algorithm, which you can read more about here. I've attached an example below, but you can find the implementations of our different brokerage Fee Models here and this can provide you with a place to start if you want to design your own.
// Set BTC to be charged $1.25 per trade Securities["BTC"].FeeModel = new ConstantFeeModel(1.25);
Deandree
Unfortunately that didn't solve the issue. I tried both:
SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash); Securities["BTCUSD"].FeeModel = new ConstantFeeModel(1.25);
and
Securities["BTCUSD"].FeeModel = new ConstantFeeModel(1.25);
Result was the same:
ERROR:: Unable to submit order with id -10 which quantity (0.1) is less than lot size (1).
Order code is:
Order("BTCUSD", 0.1);
Jared Broad
Custom imported data does not have any of the modeling built into LEAN, so for example, in this case, it is assuming a lot size of 1 for the security. The only way to get all the elegant code we've written to properly model crypto is to use a cryptosecurity type. Jack's answer solved your root question which was to add fees to your backtest since imported data is not a real "crypto" asset.
If you're attached to using that custom imported data you can use lot size 1; or switch to use the crypto data provided by QuantConnect.
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.
Deandree
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!