Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Feb 23, 2024
1 parent dc142a1 commit 951526c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace QuantConnect.CoinbaseBrokerage.Tests
public class CoinbaseBrokerageHistoryProviderTests
{
[Test, TestCaseSource(nameof(TestParameters))]
public void GetsHistory(Symbol symbol, Resolution resolution, TickType tickType, TimeSpan period, bool shouldBeEmpty, bool unsupported)
public void GetsHistory(Symbol symbol, Resolution resolution, TickType tickType, TimeSpan period, bool unsupported)
{
var brokerage = new CoinbaseBrokerage(
Config.Get("coinbase-url", "wss://advanced-trade-ws.coinbase.com"),
Expand Down Expand Up @@ -65,12 +65,7 @@ public void GetsHistory(Symbol symbol, Resolution resolution, TickType tickType,
return;
}

if (shouldBeEmpty)
{
Assert.IsEmpty(history);
return;
}

Assert.IsNotNull(history);
Assert.IsNotEmpty(history);

foreach (var bar in history.Cast<TradeBar>())
Expand All @@ -90,33 +85,33 @@ private static IEnumerable<TestCaseData> TestParameters
var BTCUSDC = Symbol.Create("BTCUSDC", SecurityType.Crypto, Market.Coinbase);

// valid parameters
yield return new TestCaseData(BTCUSD, Resolution.Minute, TickType.Trade, TimeSpan.FromDays(5), false, false);
yield return new TestCaseData(BTCUSD, Resolution.Minute, TickType.Trade, Time.OneHour, false, false);
yield return new TestCaseData(BTCUSD, Resolution.Hour, TickType.Trade, Time.OneDay, false, false);
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), false, false);
yield return new TestCaseData(BTCUSD, Resolution.Minute, TickType.Trade, TimeSpan.FromDays(5), false);
yield return new TestCaseData(BTCUSD, Resolution.Minute, TickType.Trade, Time.OneHour, false);
yield return new TestCaseData(BTCUSD, Resolution.Hour, TickType.Trade, Time.OneDay, false);
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), false);

yield return new TestCaseData(BTCUSDC, Resolution.Minute, TickType.Trade, Time.OneHour, false, false);
yield return new TestCaseData(BTCUSDC, Resolution.Hour, TickType.Trade, Time.OneDay, false, false);
yield return new TestCaseData(BTCUSDC, Resolution.Minute, TickType.Trade, Time.OneHour, false);
yield return new TestCaseData(BTCUSDC, Resolution.Hour, TickType.Trade, Time.OneDay, false);

// invalid period, no error, empty result
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(-15), true, false);
// invalid period
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(-15), true);

// quote tick type, null result
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.Quote, TimeSpan.FromDays(15), false, true);
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.OpenInterest, TimeSpan.FromDays(15), false, true);
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.Quote, TimeSpan.FromDays(15), true);
yield return new TestCaseData(BTCUSD, Resolution.Daily, TickType.OpenInterest, TimeSpan.FromDays(15), true);

// invalid resolution, null result
yield return new TestCaseData(BTCUSD, Resolution.Tick, TickType.Trade, TimeSpan.FromSeconds(15), false, true);
yield return new TestCaseData(BTCUSD, Resolution.Second, TickType.Trade, Time.OneMinute, false, true);
yield return new TestCaseData(BTCUSD, Resolution.Tick, TickType.Trade, TimeSpan.FromSeconds(15), true);
yield return new TestCaseData(BTCUSD, Resolution.Second, TickType.Trade, Time.OneMinute, true);

// invalid symbol, null result
yield return new TestCaseData(Symbol.Create("ABCXYZ", SecurityType.Crypto, Market.Coinbase), Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), false, true);
yield return new TestCaseData(Symbol.Create("ABCXYZ", SecurityType.Crypto, Market.Coinbase), Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), true);

// invalid security type, null result
yield return new TestCaseData(Symbols.EURGBP, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), false, true);
yield return new TestCaseData(Symbols.EURGBP, Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), true);

// invalid market, null result
yield return new TestCaseData(Symbol.Create("BTCUSD", SecurityType.Crypto, Market.Binance), Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), false, true);
yield return new TestCaseData(Symbol.Create("BTCUSD", SecurityType.Crypto, Market.Binance), Resolution.Daily, TickType.Trade, TimeSpan.FromDays(15), true);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions QuantConnect.CoinbaseBrokerage.ToolBox/CoinbaseDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public IEnumerable<BaseData> Get(DataDownloaderGetParameters dataDownloaderGetPa
tickType);

var brokerage = CreateBrokerage();
var data = brokerage.GetHistory(historyRequest);
return data;
return brokerage.GetHistory(historyRequest);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
using QuantConnect.Data.Market;
using System.Collections.Generic;
using QuantConnect.CoinbaseBrokerage.Models.Enums;
using System.Linq;

namespace QuantConnect.CoinbaseBrokerage
{
Expand All @@ -35,6 +34,7 @@ public partial class CoinbaseBrokerage
private bool _loggedCoinbaseSupportsOnlyTradeBars;
private bool _loggedUnsupportedAssetForHistory;
private bool _loggedUnsupportedResolutionForHistory;
private bool _loggedInvalidTimeRangeForHistory;

/// <summary>
/// Gets the history for the requested security
Expand Down Expand Up @@ -78,9 +78,13 @@ public override IEnumerable<BaseData> GetHistory(HistoryRequest request)

if (request.StartTimeUtc >= request.EndTimeUtc)
{
OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Warning, "InvalidDateRange",
"The history request start date must precede the end date, no history returned"));
return Enumerable.Empty<BaseData>();
if (!_loggedInvalidTimeRangeForHistory)
{
_loggedInvalidTimeRangeForHistory = true;
OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Warning, "InvalidDateRange",
"The history request start date must precede the end date, no history returned"));
}
return null;
}

Log.Debug($"{nameof(CoinbaseBrokerage)}.{nameof(GetHistory)}: Submitting request: {request.Symbol.Value}: {request.Resolution} {request.StartTimeUtc} UTC -> {request.EndTimeUtc} UTC");
Expand Down

0 comments on commit 951526c

Please sign in to comment.