The code below runs fine when run as a Terminal project, however if I run it from desktop-Lean using the local data installed as part of the Lean download, then I get the following error:
Error:: AlgorithmManager.Run(): RuntimeError: Slice: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'QuantConnect.Data.Market.TradeBar' does not contain a definition for 'Bid'
I checked that it was attemtping to acutally use the local data by temporarily renaming the local files, causing the following *expected* errors:
Error:: DefaultDataProvider.Fetch(): The specified file was not found: ../../../Data/crypto\gdax\minute\btcusd\20180404_quote.zip
Error:: DefaultDataProvider.Fetch(): The specified file was not found: ../../../Data/crypto\gdax\minute\btcusd\20180404_trade.zip
So it seems that the TickType is being forced to TradeBars instead of QuoteBars.
I can work around the issue for now by hacking BaseSetupHandler.cs and changing:
var configToUse = configs.OrderBy(x => x.TickType).First();
to:
var configToUse = configs.OrderBy(x => x.TickType).Last();
forcing it to choose QuoteBars from the two items in the list, however I expect there is a way to configure my Algo to use QuoteBars via a method-call.
Anyone know the correct way to achieve this?
Here is the same code (except for the date-range) that works from Terminal:
namespace QuantConnect.Algorithm.CSharp
{
public class TestCryptoQuoteBar : QCAlgorithm
{
// ----------------------------------------------
// Option Constants:
// ----------------------------------------------
private string _strMainSymbol;
private const decimal kStartCash = 100000;
private const decimal kSpendPerBuy = 2000;
Resolution kResolution = Resolution.Hour;
//const string kMarketCrypto = Market.GDAX;
const string kMarketCrypto = Market.Bitfinex;
//const BrokerageName kBrokerageName = BrokerageName.GDAX;
const BrokerageName kBrokerageName = BrokerageName.Bitfinex;
public override void Initialize()
{
SetStartDate(2019, 1, 1);
SetEndDate(2019, 1, 2);
SetCash(kStartCash);
_strMainSymbol = "BTCUSD";
AddCrypto(_strMainSymbol, kResolution, kMarketCrypto);
SetBrokerageModel(kBrokerageName, AccountType.Cash);
}
public override void OnData(Slice data)
{
var temp = data.QuoteBars[_strMainSymbol].Bid.Close;
Debug($"temp: {temp}");
var dataValue = data[_strMainSymbol];
var bidClose = dataValue.Bid.Close;
var askClose = dataValue.Ask.Close;
var spread = askClose - bidClose;
Debug($"Spread: {spread}");
}
}
}