From 70631388d08d54a281d72422215533f880d7831f Mon Sep 17 00:00:00 2001 From: Victor Lee Date: Tue, 1 Jun 2021 14:36:39 -0700 Subject: [PATCH 1/2] Add Candles (OHLC) websocket support in ExchangeAPI - part of #595 --- .../API/Exchanges/_Base/ExchangeAPI.cs | 13 +++++++++++++ .../API/Exchanges/_Base/IExchangeAPI.cs | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs index 2a323d8f..d0974981 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs @@ -178,6 +178,8 @@ protected virtual Task OnGetOpenPositionAsync(stri throw new NotImplementedException(); protected virtual Task OnCloseMarginPositionAsync(string marketSymbol) => throw new NotImplementedException(); + protected virtual Task OnGetCandlesWebSocketAsync(Action> callback, params string[] marketSymbols) => + throw new NotImplementedException(); protected virtual Task OnGetTickersWebSocketAsync(Action>> tickers, params string[] marketSymbols) => throw new NotImplementedException(); protected virtual Task OnGetTradesWebSocketAsync(Func, Task> callback, params string[] marketSymbols) => @@ -997,6 +999,17 @@ public virtual async Task CloseMarginPosition #endregion REST API #region Web Socket API + /// + /// Gets Candles (OHLC) websocket + /// + /// Callback + /// Market Symbols + /// Web socket, call Dispose to close + protected virtual Task GetCandlesWebSocketAsync(Action> callback, params string[] marketSymbols) + { + callback.ThrowIfNull(nameof(callback), "Callback must not be null"); + return OnGetCandlesWebSocketAsync(callback, marketSymbols); + } /// /// Get all tickers via web socket diff --git a/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs b/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs index 24eda096..47e330d9 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs @@ -237,6 +237,13 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider #endregion REST #region Web Socket + /// + /// Gets Candles (OHLC) websocket + /// + /// Callback + /// Market Symbols + /// Web socket, call Dispose to close + Task GetCandlesWebSocketAsync(Action> callback, params string[] marketSymbols); /// /// Get all tickers via web socket @@ -254,6 +261,8 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider /// Web socket, call Dispose to close Task GetTradesWebSocketAsync(Func, Task> callback, params string[] marketSymbols); + // Task GetDeltaOrderBookWebSocketAsync is in IOrderBookProvider + /// /// Get the details of all changed orders via web socket /// @@ -268,6 +277,7 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider /// Web socket, call Dispose to close Task GetCompletedOrderDetailsWebSocketAsync(Action callback); + Task GetUserDataWebSocketAsync(Action callback, string listenKey); #endregion Web Socket } } From e380e8e7859141d3a306b9f85882286a602fd451 Mon Sep 17 00:00:00 2001 From: Victor Lee Date: Thu, 3 Jun 2021 14:29:20 -0700 Subject: [PATCH 2/2] changed GetCandlesWebSocketAsync() to allow for async callback --- src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs | 10 +++++----- src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs index d0974981..dcc2158e 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs @@ -178,7 +178,7 @@ protected virtual Task OnGetOpenPositionAsync(stri throw new NotImplementedException(); protected virtual Task OnCloseMarginPositionAsync(string marketSymbol) => throw new NotImplementedException(); - protected virtual Task OnGetCandlesWebSocketAsync(Action> callback, params string[] marketSymbols) => + protected virtual Task OnGetCandlesWebSocketAsync(Func, Task> callbackAsync, params string[] marketSymbols) => throw new NotImplementedException(); protected virtual Task OnGetTickersWebSocketAsync(Action>> tickers, params string[] marketSymbols) => throw new NotImplementedException(); @@ -1002,13 +1002,13 @@ public virtual async Task CloseMarginPosition /// /// Gets Candles (OHLC) websocket /// - /// Callback + /// Callback /// Market Symbols /// Web socket, call Dispose to close - protected virtual Task GetCandlesWebSocketAsync(Action> callback, params string[] marketSymbols) + public virtual Task GetCandlesWebSocketAsync(Func, Task> callbackAsync, params string[] marketSymbols) { - callback.ThrowIfNull(nameof(callback), "Callback must not be null"); - return OnGetCandlesWebSocketAsync(callback, marketSymbols); + callbackAsync.ThrowIfNull(nameof(callbackAsync), "Callback must not be null"); + return OnGetCandlesWebSocketAsync(callbackAsync, marketSymbols); } /// diff --git a/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs b/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs index 47e330d9..e264ad5c 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs @@ -240,10 +240,10 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider /// /// Gets Candles (OHLC) websocket /// - /// Callback + /// Callback /// Market Symbols /// Web socket, call Dispose to close - Task GetCandlesWebSocketAsync(Action> callback, params string[] marketSymbols); + Task GetCandlesWebSocketAsync(Func, Task> callbackAsync, params string[] marketSymbols); /// /// Get all tickers via web socket