Skip to content

Commit 3d3d25e

Browse files
authored
Add missing REST methods from ExchangeAPI to IExchangeAPI (#622)
1 parent 39786cd commit 3d3d25e

File tree

2 files changed

+94
-64
lines changed

2 files changed

+94
-64
lines changed

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

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,34 @@ public virtual async Task<IEnumerable<ExchangeMarket>> GetMarketSymbolsMetadataA
743743
return null;
744744
}
745745

746+
/// <summary>
747+
/// Gets the address to deposit to and applicable details.
748+
/// </summary>
749+
/// <param name="currency">Currency to get address for.</param>
750+
/// <param name="forceRegenerate">Regenerate the address</param>
751+
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
752+
public virtual async Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false)
753+
{
754+
if (forceRegenerate)
755+
{
756+
// force regenetate, do not cache
757+
return await OnGetDepositAddressAsync(currency, forceRegenerate);
758+
}
759+
else
760+
{
761+
return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetDepositAddressAsync(currency, forceRegenerate), nameof(GetDepositAddressAsync), nameof(currency), currency);
762+
}
763+
}
764+
765+
/// <summary>
766+
/// Gets the deposit history for a symbol
767+
/// </summary>
768+
/// <returns>Collection of ExchangeCoinTransfers</returns>
769+
public virtual async Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency)
770+
{
771+
return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetDepositHistoryAsync(currency), nameof(GetDepositHistoryAsync), nameof(currency), currency);
772+
}
773+
746774
/// <summary>
747775
/// Get exchange ticker
748776
/// </summary>
@@ -811,34 +839,6 @@ public virtual async Task<IEnumerable<ExchangeTrade>> GetRecentTradesAsync(strin
811839
//return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetRecentTradesAsync(marketSymbol), nameof(GetRecentTradesAsync), nameof(marketSymbol), marketSymbol);
812840
}
813841

814-
/// <summary>
815-
/// Gets the address to deposit to and applicable details.
816-
/// </summary>
817-
/// <param name="currency">Currency to get address for.</param>
818-
/// <param name="forceRegenerate">Regenerate the address</param>
819-
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
820-
public virtual async Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false)
821-
{
822-
if (forceRegenerate)
823-
{
824-
// force regenetate, do not cache
825-
return await OnGetDepositAddressAsync(currency, forceRegenerate);
826-
}
827-
else
828-
{
829-
return await Cache.CacheMethod(MethodCachePolicy, async() => await OnGetDepositAddressAsync(currency, forceRegenerate), nameof(GetDepositAddressAsync), nameof(currency), currency);
830-
}
831-
}
832-
833-
/// <summary>
834-
/// Gets the deposit history for a symbol
835-
/// </summary>
836-
/// <returns>Collection of ExchangeCoinTransfers</returns>
837-
public virtual async Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency)
838-
{
839-
return await Cache.CacheMethod(MethodCachePolicy, async() => await OnGetDepositHistoryAsync(currency), nameof(GetDepositHistoryAsync), nameof(currency), currency);
840-
}
841-
842842
/// <summary>
843843
/// Get candles (open, high, low, close)
844844
/// </summary>
@@ -855,6 +855,15 @@ public virtual async Task<IEnumerable<MarketCandle>> GetCandlesAsync(string mark
855855
nameof(marketSymbol), marketSymbol, nameof(periodSeconds), periodSeconds, nameof(startDate), startDate, nameof(endDate), endDate, nameof(limit), limit);
856856
}
857857

858+
/// <summary>
859+
/// Get fees
860+
/// </summary>
861+
/// <returns>The customer trading fees</returns>
862+
public virtual async Task<Dictionary<string, decimal>> GetFeesAync()
863+
{
864+
return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetFeesAsync(), nameof(GetFeesAync));
865+
}
866+
858867
/// <summary>
859868
/// Get total amounts, symbol / amount dictionary
860869
/// </summary>
@@ -867,15 +876,6 @@ public virtual async Task<Dictionary<string, decimal>> GetAmountsAsync()
867876
return globalAmounts;
868877
}
869878

870-
/// <summary>
871-
/// Get fees
872-
/// </summary>
873-
/// <returns>The customer trading fees</returns>
874-
public virtual async Task<Dictionary<string, decimal>> GetFeesAync()
875-
{
876-
return await Cache.CacheMethod(MethodCachePolicy, async() => await OnGetFeesAsync(), nameof(GetFeesAync));
877-
}
878-
879879
/// <summary>
880880
/// Get amounts available to trade, symbol / amount dictionary
881881
/// </summary>

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

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,14 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
6868

6969
#endregion Utility Methods
7070

71-
#region REST
71+
#region REST API
7272

7373
/// <summary>
7474
/// Gets currencies and related data such as IsEnabled and TxFee (if available)
7575
/// </summary>
7676
/// <returns>Collection of Currencies</returns>
7777
Task<IReadOnlyDictionary<string, ExchangeCurrency>> GetCurrenciesAsync();
7878

79-
/// <summary>
80-
/// Gets the address to deposit to and applicable details.
81-
/// </summary>
82-
/// <param name="currency">Currency to get address for.</param>
83-
/// <param name="forceRegenerate">True to regenerate the address</param>
84-
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
85-
Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false);
86-
87-
/// <summary>
88-
/// Gets the deposit history for a currency
89-
/// </summary>
90-
/// <param name="currency">The currency to check. May be null.</param>
91-
/// <returns>Collection of ExchangeCoinTransfers</returns>
92-
Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency);
93-
9479
/// <summary>
9580
/// Get symbols for the exchange markets
9681
/// </summary>
@@ -109,6 +94,29 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
10994
/// <returns>Collection of ExchangeMarkets</returns>
11095
Task<IEnumerable<ExchangeMarket>> GetMarketSymbolsMetadataAsync();
11196

97+
/// <summary>
98+
/// Gets the exchange market from this exchange's SymbolsMetadata cache. This will make a network request if needed to retrieve fresh markets from the exchange using GetSymbolsMetadataAsync().
99+
/// Please note that sending a symbol that is not found over and over will result in many network requests. Only send symbols that you are confident exist on the exchange.
100+
/// </summary>
101+
/// <param name="marketSymbol">The market symbol. Ex. ADA/BTC. This is assumed to be normalized and already correct for the exchange.</param>
102+
/// <returns>The ExchangeMarket or null if it doesn't exist in the cache or there was an error</returns>
103+
Task<ExchangeMarket?> GetExchangeMarketFromCacheAsync(string marketSymbol);
104+
105+
/// <summary>
106+
/// Gets the address to deposit to and applicable details.
107+
/// </summary>
108+
/// <param name="currency">Currency to get address for.</param>
109+
/// <param name="forceRegenerate">True to regenerate the address</param>
110+
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
111+
Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false);
112+
113+
/// <summary>
114+
/// Gets the deposit history for a currency
115+
/// </summary>
116+
/// <param name="currency">The currency to check. May be null.</param>
117+
/// <returns>Collection of ExchangeCoinTransfers</returns>
118+
Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency);
119+
112120
/// <summary>
113121
/// Get latest ticker
114122
/// </summary>
@@ -132,6 +140,10 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
132140
Task GetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrade>, bool> callback, string marketSymbol, DateTime? startDate = null, DateTime? endDate = null, int? limit = null);
133141
//Task GetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrade>, bool> callback, string marketSymbol, DateTime? startDate = null, DateTime? endDate = null);
134142

143+
// Task<ExchangeOrderBook> GetOrderBookAsync(string marketSymbol, int maxCount = 100); is in IOrderBookProvider
144+
145+
// Task<IEnumerable<KeyValuePair<string, ExchangeOrderBook>>> GetOrderBooksAsync(int maxCount = 100); is in IOrderBookProvider
146+
135147
/// <summary>
136148
/// Get the latest trades
137149
/// </summary>
@@ -151,6 +163,12 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
151163
/// <returns>Candles</returns>
152164
Task<IEnumerable<MarketCandle>> GetCandlesAsync(string marketSymbol, int periodSeconds, DateTime? startDate = null, DateTime? endDate = null, int? limit = null);
153165

166+
/// <summary>
167+
/// Get fees
168+
/// </summary>
169+
/// <returns>The customer trading fees</returns>
170+
Task<Dictionary<string, decimal>> GetFeesAync();
171+
154172
/// <summary>
155173
/// Get total amounts, symbol / amount dictionary
156174
/// </summary>
@@ -163,6 +181,13 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
163181
/// <returns>Dictionary of symbols and amounts available to trade</returns>
164182
Task<Dictionary<string, decimal>> GetAmountsAvailableToTradeAsync();
165183

184+
/// <summary>
185+
/// Get margin amounts available to trade, symbol / amount dictionary
186+
/// </summary>
187+
/// <param name="includeZeroBalances">Include currencies with zero balance in return value</param>
188+
/// <returns>Dictionary of symbols and amounts available to trade in margin account</returns>
189+
Task<Dictionary<string, decimal>> GetMarginAmountsAvailableToTradeAsync(bool includeZeroBalances = false);
190+
166191
/// <summary>
167192
/// Place an order
168193
/// </summary>
@@ -208,11 +233,16 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
208233
Task CancelOrderAsync(string orderId, string? marketSymbol = null);
209234

210235
/// <summary>
211-
/// Get margin amounts available to trade, symbol / amount dictionary
236+
/// Asynchronous withdraws request.
212237
/// </summary>
213-
/// <param name="includeZeroBalances">Include currencies with zero balance in return value</param>
214-
/// <returns>Dictionary of symbols and amounts available to trade in margin account</returns>
215-
Task<Dictionary<string, decimal>> GetMarginAmountsAvailableToTradeAsync(bool includeZeroBalances = false);
238+
/// <param name="withdrawalRequest">The withdrawal request.</param>
239+
Task<ExchangeWithdrawalResponse> WithdrawAsync(ExchangeWithdrawalRequest withdrawalRequest);
240+
241+
/// <summary>
242+
/// Gets the withdraw history for a symbol
243+
/// </summary>
244+
/// <returns>Collection of ExchangeCoinTransfers</returns>
245+
Task<IEnumerable<ExchangeTransaction>> GetWithdrawHistoryAsync(string currency);
216246

217247
/// <summary>
218248
/// Get open margin position
@@ -228,15 +258,9 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
228258
/// <returns>Close margin position result</returns>
229259
Task<ExchangeCloseMarginPositionResult> CloseMarginPositionAsync(string marketSymbol);
230260

231-
/// <summary>
232-
/// Get fees
233-
/// </summary>
234-
/// <returns>The customer trading fees</returns>
235-
Task<Dictionary<string, decimal>> GetFeesAync();
236-
237261
#endregion REST
238262

239-
#region Web Socket
263+
#region Web Socket API
240264
/// <summary>
241265
/// Gets Candles (OHLC) websocket
242266
/// </summary>
@@ -285,6 +309,12 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
285309
/// <returns>Web socket, call Dispose to close</returns>
286310
Task<IWebSocket> GetCompletedOrderDetailsWebSocketAsync(Action<ExchangeOrderResult> callback);
287311

312+
/// <summary>
313+
/// Get user detail over web socket
314+
/// </summary>
315+
/// <param name="callback">Callback</param>
316+
/// <param name="listenKey">Listen key</param>
317+
/// <returns>Web socket, call Dispose to close</returns>
288318
Task<IWebSocket> GetUserDataWebSocketAsync(Action<object> callback, string listenKey);
289319
#endregion Web Socket
290320
}

0 commit comments

Comments
 (0)