Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Bug websocket session refresh" #20

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .github/workflows/gh-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@ jobs:
QC_JOB_USER_ID: ${{ secrets.JOB_USER_ID }}
QC_API_ACCESS_TOKEN: ${{ secrets.API_ACCESS_TOKEN }}
QC_JOB_ORGANIZATION_ID: ${{ secrets.JOB_ORGANIZATION_ID }}
container:
image: quantconnect/lean:foundation
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Free space
run: df -h && rm -rf /opt/hostedtoolcache* && df -h

- uses: addnab/docker-run-action@v3
with:
image: quantconnect/lean:foundation
options: --workdir /__w/Lean.Brokerages.Tradier/Lean.Brokerages.Tradier -v /home/runner/work:/__w -e QC_TRADIER_ENVIRONMENT=${{ secrets.QC_TRADIER_ENVIRONMENT }} -e QC_TRADIER_ACCESS_TOKEN=${{ secrets.QC_TRADIER_ACCESS_TOKEN }} -e QC_TRADIER_ACCOUNT_ID=${{ secrets.QC_TRADIER_ACCOUNT_ID }} -e QC_JOB_USER_ID=${{ secrets.JOB_USER_ID }} -e QC_API_ACCESS_TOKEN=${{ secrets.API_ACCESS_TOKEN }} -e QC_JOB_ORGANIZATION_ID=${{ secrets.JOB_ORGANIZATION_ID }}
- uses: actions/checkout@v2

- name: Checkout Lean Same Branch
id: lean-same-branch
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

namespace QuantConnect.Tests.Brokerages.Tradier
{
public partial class TradierBrokerageTests : BrokerageTests
public class TradierBrokerageTests : BrokerageTests
{
/// <summary>
/// Provides the data required to test each order type in various cases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace QuantConnect.Brokerages.Tradier
{
Expand All @@ -38,9 +37,6 @@ public partial class TradierBrokerage
{
#region IDataQueueHandler implementation

private readonly static TimeSpan SessionTimeout = TimeSpan.FromMinutes(4.8);
private bool _sessionExpired;

private const string WebSocketUrl = "wss://ws.tradier.com/v1/markets/events";

private object _streamSessionLock = new ();
Expand Down Expand Up @@ -270,23 +266,10 @@ private TradierStreamSession GetStreamSession()
{
lock (_streamSessionLock)
{
if (_streamSession == null || _sessionExpired)
if (_streamSession == null || !_streamSession.IsValid)
{
var request = new RestRequest("markets/events/session", Method.POST);
_streamSession = Execute<TradierStreamSession>(request, TradierApiRequestType.Data, "stream");

// clear expired state, we just refreshed it
_sessionExpired = false;

// after timeout, expire the session and refresh subscriptions, which will refresh token
Task.Delay(SessionTimeout).ContinueWith(_ =>
{
lock (_streamSessionLock)
{
_sessionExpired = true;
_subscribeProcedure.Set();
}
});
}

return _streamSession;
Expand Down
10 changes: 10 additions & 0 deletions QuantConnect.TradierBrokerage/TradierStreamSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
*
*/

using System;

namespace QuantConnect.Brokerages.Tradier
{
/// <summary>
/// Create a new stream session
/// </summary>
public class TradierStreamSession
{
private readonly static TimeSpan LifeSpan = TimeSpan.FromMinutes(4.9);
private readonly DateTime _createdTime = DateTime.UtcNow;

/// <summary>
/// Trading Stream: Session Id
/// </summary>
Expand All @@ -30,5 +35,10 @@ public class TradierStreamSession
/// Trading Stream: Stream URL
/// </summary>
public string Url;

/// <summary>
/// Determines if this session Id is valid
/// </summary>
public bool IsValid => DateTime.UtcNow - _createdTime < LifeSpan;
}
}
Loading