Back

Error attempting to get 'bid' data from a local gdax file

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}");
}

}
}

 

Update Backtest







0

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.


I've found and fixed the problem.

Cause: The following line that I hadn't noticed was remaining (not commented out) in Initialize() from earlier testing:

SetWarmUp(14);

 

Fix: Added the following line to OnData(Slice data):

if (IsWarmingUp) return;

 

0

Update Backtest





0

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.


Loading...

This discussion is closed