Skip to content

Commit

Permalink
Revert "Bug websocket session refresh (#19)" (#20)
Browse files Browse the repository at this point in the history
This reverts commit 77dc3e9.
  • Loading branch information
Martin-Molinero authored Nov 1, 2023
1 parent 77dc3e9 commit 50d9ea2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 109 deletions.
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;
}
}

0 comments on commit 50d9ea2

Please sign in to comment.