From ae1aabedf605d771db4a1b9eb57b03cd9ae3a89d Mon Sep 17 00:00:00 2001 From: Jhonathan Abreu Date: Tue, 27 Feb 2024 16:39:23 -0400 Subject: [PATCH] Fix using default value for orderbook depth in SetJob --- .../KrakenBrokerageDataQueueHandlerTests.cs | 20 +++++++++++++++++++ .../KrakenBrokerage.DataQueueHandler.cs | 8 +++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/QuantConnect.KrakenBrokerage.Tests/KrakenBrokerageDataQueueHandlerTests.cs b/QuantConnect.KrakenBrokerage.Tests/KrakenBrokerageDataQueueHandlerTests.cs index 35fa04e..d65beef 100644 --- a/QuantConnect.KrakenBrokerage.Tests/KrakenBrokerageDataQueueHandlerTests.cs +++ b/QuantConnect.KrakenBrokerage.Tests/KrakenBrokerageDataQueueHandlerTests.cs @@ -19,6 +19,7 @@ using QuantConnect.Data; using QuantConnect.Logging; using QuantConnect.Data.Market; +using QuantConnect.Configuration; namespace QuantConnect.Tests.Brokerages.Kraken { @@ -78,5 +79,24 @@ public void StreamsData(Symbol symbol, Resolution resolution, int waitMillisecon cancelationToken.Cancel(); } + + [Test] + public void SetJobUsesOrderBookDepthDefaultValue() + { + using var brokerage = new KrakenBrokerage(); + + var packet = new Packets.LiveNodePacket() + { + BrokerageData = + { + { "kraken-api-key", Config.Get("kraken-api-key") }, + { "kraken-api-secret", Config.Get("kraken-api-secret") }, + { "kraken-verification-tier", Config.Get("kraken-verification-tier") } + } + }; + + Assert.DoesNotThrow(() => brokerage.SetJob(packet)); + Assert.IsTrue(brokerage.IsConnected); + } } } \ No newline at end of file diff --git a/QuantConnect.KrakenBrokerage/KrakenBrokerage.DataQueueHandler.cs b/QuantConnect.KrakenBrokerage/KrakenBrokerage.DataQueueHandler.cs index 9ec4d82..1fbc373 100644 --- a/QuantConnect.KrakenBrokerage/KrakenBrokerage.DataQueueHandler.cs +++ b/QuantConnect.KrakenBrokerage/KrakenBrokerage.DataQueueHandler.cs @@ -427,10 +427,12 @@ private void SetWebsocketToken() /// Job we're subscribing for public void SetJob(LiveNodePacket job) { - if (!job.BrokerageData.TryGetValue("kraken-orderbook-depth", out var orderDepth)) + var orderDepth = 10; + if (job.BrokerageData.TryGetValue("kraken-orderbook-depth", out var orderDepthStr)) { - throw new ArgumentException($"KrakenBrokerage.SetJob(): missing value -- kraken-orderbook-depth"); + orderDepth = orderDepthStr.ToInt32(); } + var aggregator = Composer.Instance.GetExportedValueByTypeName( Config.Get("data-aggregator", "QuantConnect.Lean.Engine.DataFeeds.AggregationManager"), forceTypeNameOnExisting: false); @@ -438,7 +440,7 @@ public void SetJob(LiveNodePacket job) job.BrokerageData["kraken-api-key"], job.BrokerageData["kraken-api-secret"], job.BrokerageData["kraken-verification-tier"], - orderDepth.ToInt32(), + orderDepth, null, aggregator, job);