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

Add Candles (OHLC) websocket support in ExchangeAPI #596

Merged
merged 2 commits into from
Jun 5, 2021
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
13 changes: 13 additions & 0 deletions src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ protected virtual Task<ExchangeMarginPositionResult> OnGetOpenPositionAsync(stri
throw new NotImplementedException();
protected virtual Task<ExchangeCloseMarginPositionResult> OnCloseMarginPositionAsync(string marketSymbol) =>
throw new NotImplementedException();
protected virtual Task<IWebSocket> OnGetCandlesWebSocketAsync(Func<IReadOnlyCollection<MarketCandle>, Task> callbackAsync, params string[] marketSymbols) =>
throw new NotImplementedException();
protected virtual Task<IWebSocket> OnGetTickersWebSocketAsync(Action<IReadOnlyCollection<KeyValuePair<string, ExchangeTicker>>> tickers, params string[] marketSymbols) =>
throw new NotImplementedException();
protected virtual Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValuePair<string, ExchangeTrade>, Task> callback, params string[] marketSymbols) =>
Expand Down Expand Up @@ -997,6 +999,17 @@ public virtual async Task<ExchangeCloseMarginPositionResult> CloseMarginPosition
#endregion REST API

#region Web Socket API
/// <summary>
/// Gets Candles (OHLC) websocket
/// </summary>
/// <param name="callbackAsync">Callback</param>
/// <param name="marketSymbols">Market Symbols</param>
/// <returns>Web socket, call Dispose to close</returns>
public virtual Task<IWebSocket> GetCandlesWebSocketAsync(Func<IReadOnlyCollection<MarketCandle>, Task> callbackAsync, params string[] marketSymbols)
{
callbackAsync.ThrowIfNull(nameof(callbackAsync), "Callback must not be null");
return OnGetCandlesWebSocketAsync(callbackAsync, marketSymbols);
}

/// <summary>
/// Get all tickers via web socket
Expand Down
10 changes: 10 additions & 0 deletions src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
#endregion REST

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

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

// Task<IWebSocket> GetDeltaOrderBookWebSocketAsync is in IOrderBookProvider

/// <summary>
/// Get the details of all changed orders via web socket
/// </summary>
Expand All @@ -268,6 +277,7 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
/// <returns>Web socket, call Dispose to close</returns>
Task<IWebSocket> GetCompletedOrderDetailsWebSocketAsync(Action<ExchangeOrderResult> callback);

Task<IWebSocket> GetUserDataWebSocketAsync(Action<object> callback, string listenKey);
#endregion Web Socket
}
}