Fix timestamps in custom data algorithms (#5426)

* Correct custom data timestamp and match performance across languages

* Add EndTime property

* Add comment for crypto SetHoldings
This commit is contained in:
Derek Melchin
2021-03-30 15:48:59 -06:00
committed by GitHub
parent 4a1485a291
commit 5ed61db2bb
8 changed files with 51 additions and 37 deletions
@@ -52,7 +52,9 @@ class CustomDataBitcoinAlgorithm(QCAlgorithm):
# If we don't have any weather "SHARES" -- invest"
if not self.Portfolio.Invested:
# Weather used as a tradable asset, like stocks, futures etc.
self.SetHoldings("BTC", 1)
# It's only OK to use SetHoldings with crypto when using custom data. When trading with built-in crypto data,
# use the cashbook. Reference https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/BasicTemplateCryptoAlgorithm.py
self.SetHoldings("BTC", 1)
self.Debug("Buying BTC 'Shares': BTC: {0}".format(close))
self.Debug("Time: {0} {1}".format(datetime.now(), close))
@@ -67,7 +69,7 @@ class Bitcoin(PythonData):
#return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip";
# OR simply return a fixed small data file. Large files will slow down your backtest
return SubscriptionDataSource("https://www.quandl.com/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc", SubscriptionTransportMedium.RemoteFile);
return SubscriptionDataSource("https://www.quantconnect.com/api/v2/proxy/quandl/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc&api_key=WyAazVXnq7ATy_fefTqm", SubscriptionTransportMedium.RemoteFile);
def Reader(self, config, line, date, isLiveMode):
@@ -112,6 +114,7 @@ class Bitcoin(PythonData):
if value == 0: return None
coin.Time = datetime.strptime(data[0], "%Y-%m-%d")
coin.EndTime = coin.Time + timedelta(days=1)
coin.Value = value
coin["Open"] = float(data[1])
coin["High"] = float(data[2])