generated from QuantConnect/Lean.Brokerages.Template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix data queue handler session refresh
- Fix data queue handler session refresh handling. Adding unit test
- Loading branch information
1 parent
ae1be52
commit 52b52fc
Showing
4 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
QuantConnect.TradierBrokerage.Tests/TradierBrokerageDataQueueHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. | ||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
using NUnit.Framework; | ||
using System.Threading; | ||
using QuantConnect.Data; | ||
using QuantConnect.Logging; | ||
using QuantConnect.Data.Market; | ||
using QuantConnect.Brokerages.Tradier; | ||
|
||
namespace QuantConnect.Tests.Brokerages.Tradier | ||
{ | ||
[TestFixture] | ||
public partial class TradierBrokerageTests : BrokerageTests | ||
{ | ||
private static TestCaseData[] TestParameters | ||
{ | ||
get | ||
{ | ||
return new[] | ||
{ | ||
// valid parameters, for example | ||
new TestCaseData(Symbols.AAPL, Resolution.Tick, false), | ||
}; | ||
} | ||
} | ||
|
||
[Test, TestCaseSource(nameof(TestParameters)), Explicit("Long execution time")] | ||
public void StreamsData(Symbol symbol, Resolution resolution, bool throwsException) | ||
{ | ||
var cancelationToken = new CancellationTokenSource(); | ||
|
||
var tradier = (TradierBrokerage)Brokerage; | ||
SubscriptionDataConfig[] configs; | ||
if (resolution == Resolution.Tick) | ||
{ | ||
var tradeConfig = new SubscriptionDataConfig(GetSubscriptionDataConfig<Tick>(symbol, resolution), tickType: TickType.Trade); | ||
var quoteConfig = new SubscriptionDataConfig(GetSubscriptionDataConfig<Tick>(symbol, resolution), tickType: TickType.Quote); | ||
configs = new[] { tradeConfig, quoteConfig }; | ||
} | ||
else | ||
{ | ||
configs = new[] { GetSubscriptionDataConfig<QuoteBar>(symbol, resolution), | ||
GetSubscriptionDataConfig<TradeBar>(symbol, resolution) }; | ||
} | ||
|
||
foreach (var config in configs) | ||
{ | ||
ProcessFeed(tradier.Subscribe(config, (s, e) => { }), | ||
cancelationToken, | ||
(baseData) => { | ||
if (baseData != null) { Log.Trace($"{baseData}"); } | ||
}); | ||
} | ||
|
||
// long runtime so we assert the session refresh and data stream is not interrupted | ||
Thread.Sleep(1000 * 15 * 60); | ||
|
||
foreach (var config in configs) | ||
{ | ||
tradier.Unsubscribe(config); | ||
} | ||
|
||
Thread.Sleep(1000); | ||
|
||
cancelationToken.Cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters