Skip to content

Commit 1356191

Browse files
authored
Add Candles (OHLC) websocket support in ExchangeAPI (#596)
* Add Candles (OHLC) websocket support in ExchangeAPI - part of #595 * changed GetCandlesWebSocketAsync() to allow for async callback
1 parent d1c5137 commit 1356191

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ protected virtual Task<ExchangeMarginPositionResult> OnGetOpenPositionAsync(stri
178178
throw new NotImplementedException();
179179
protected virtual Task<ExchangeCloseMarginPositionResult> OnCloseMarginPositionAsync(string marketSymbol) =>
180180
throw new NotImplementedException();
181+
protected virtual Task<IWebSocket> OnGetCandlesWebSocketAsync(Func<IReadOnlyCollection<MarketCandle>, Task> callbackAsync, params string[] marketSymbols) =>
182+
throw new NotImplementedException();
181183
protected virtual Task<IWebSocket> OnGetTickersWebSocketAsync(Action<IReadOnlyCollection<KeyValuePair<string, ExchangeTicker>>> tickers, params string[] marketSymbols) =>
182184
throw new NotImplementedException();
183185
protected virtual Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValuePair<string, ExchangeTrade>, Task> callback, params string[] marketSymbols) =>
@@ -997,6 +999,17 @@ public virtual async Task<ExchangeCloseMarginPositionResult> CloseMarginPosition
997999
#endregion REST API
9981000

9991001
#region Web Socket API
1002+
/// <summary>
1003+
/// Gets Candles (OHLC) websocket
1004+
/// </summary>
1005+
/// <param name="callbackAsync">Callback</param>
1006+
/// <param name="marketSymbols">Market Symbols</param>
1007+
/// <returns>Web socket, call Dispose to close</returns>
1008+
public virtual Task<IWebSocket> GetCandlesWebSocketAsync(Func<IReadOnlyCollection<MarketCandle>, Task> callbackAsync, params string[] marketSymbols)
1009+
{
1010+
callbackAsync.ThrowIfNull(nameof(callbackAsync), "Callback must not be null");
1011+
return OnGetCandlesWebSocketAsync(callbackAsync, marketSymbols);
1012+
}
10001013

10011014
/// <summary>
10021015
/// Get all tickers via web socket

src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
237237
#endregion REST
238238

239239
#region Web Socket
240+
/// <summary>
241+
/// Gets Candles (OHLC) websocket
242+
/// </summary>
243+
/// <param name="callbackAsync">Callback</param>
244+
/// <param name="marketSymbols">Market Symbols</param>
245+
/// <returns>Web socket, call Dispose to close</returns>
246+
Task<IWebSocket> GetCandlesWebSocketAsync(Func<IReadOnlyCollection<MarketCandle>, Task> callbackAsync, params string[] marketSymbols);
240247

241248
/// <summary>
242249
/// Get all tickers via web socket
@@ -254,6 +261,8 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
254261
/// <returns>Web socket, call Dispose to close</returns>
255262
Task<IWebSocket> GetTradesWebSocketAsync(Func<KeyValuePair<string, ExchangeTrade>, Task> callback, params string[] marketSymbols);
256263

264+
// Task<IWebSocket> GetDeltaOrderBookWebSocketAsync is in IOrderBookProvider
265+
257266
/// <summary>
258267
/// Get the details of all changed orders via web socket
259268
/// </summary>
@@ -268,6 +277,7 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
268277
/// <returns>Web socket, call Dispose to close</returns>
269278
Task<IWebSocket> GetCompletedOrderDetailsWebSocketAsync(Action<ExchangeOrderResult> callback);
270279

280+
Task<IWebSocket> GetUserDataWebSocketAsync(Action<object> callback, string listenKey);
271281
#endregion Web Socket
272282
}
273283
}

0 commit comments

Comments
 (0)