Skip to content

Add missing REST methods from ExchangeAPI to IExchangeAPI #622

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

Merged
merged 1 commit into from
Aug 9, 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
74 changes: 37 additions & 37 deletions src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,34 @@ public virtual async Task<IEnumerable<ExchangeMarket>> GetMarketSymbolsMetadataA
return null;
}

/// <summary>
/// Gets the address to deposit to and applicable details.
/// </summary>
/// <param name="currency">Currency to get address for.</param>
/// <param name="forceRegenerate">Regenerate the address</param>
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
public virtual async Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false)
{
if (forceRegenerate)
{
// force regenetate, do not cache
return await OnGetDepositAddressAsync(currency, forceRegenerate);
}
else
{
return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetDepositAddressAsync(currency, forceRegenerate), nameof(GetDepositAddressAsync), nameof(currency), currency);
}
}

/// <summary>
/// Gets the deposit history for a symbol
/// </summary>
/// <returns>Collection of ExchangeCoinTransfers</returns>
public virtual async Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency)
{
return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetDepositHistoryAsync(currency), nameof(GetDepositHistoryAsync), nameof(currency), currency);
}

/// <summary>
/// Get exchange ticker
/// </summary>
Expand Down Expand Up @@ -811,34 +839,6 @@ public virtual async Task<IEnumerable<ExchangeTrade>> GetRecentTradesAsync(strin
//return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetRecentTradesAsync(marketSymbol), nameof(GetRecentTradesAsync), nameof(marketSymbol), marketSymbol);
}

/// <summary>
/// Gets the address to deposit to and applicable details.
/// </summary>
/// <param name="currency">Currency to get address for.</param>
/// <param name="forceRegenerate">Regenerate the address</param>
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
public virtual async Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false)
{
if (forceRegenerate)
{
// force regenetate, do not cache
return await OnGetDepositAddressAsync(currency, forceRegenerate);
}
else
{
return await Cache.CacheMethod(MethodCachePolicy, async() => await OnGetDepositAddressAsync(currency, forceRegenerate), nameof(GetDepositAddressAsync), nameof(currency), currency);
}
}

/// <summary>
/// Gets the deposit history for a symbol
/// </summary>
/// <returns>Collection of ExchangeCoinTransfers</returns>
public virtual async Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency)
{
return await Cache.CacheMethod(MethodCachePolicy, async() => await OnGetDepositHistoryAsync(currency), nameof(GetDepositHistoryAsync), nameof(currency), currency);
}

/// <summary>
/// Get candles (open, high, low, close)
/// </summary>
Expand All @@ -855,6 +855,15 @@ public virtual async Task<IEnumerable<MarketCandle>> GetCandlesAsync(string mark
nameof(marketSymbol), marketSymbol, nameof(periodSeconds), periodSeconds, nameof(startDate), startDate, nameof(endDate), endDate, nameof(limit), limit);
}

/// <summary>
/// Get fees
/// </summary>
/// <returns>The customer trading fees</returns>
public virtual async Task<Dictionary<string, decimal>> GetFeesAync()
{
return await Cache.CacheMethod(MethodCachePolicy, async () => await OnGetFeesAsync(), nameof(GetFeesAync));
}

/// <summary>
/// Get total amounts, symbol / amount dictionary
/// </summary>
Expand All @@ -867,15 +876,6 @@ public virtual async Task<Dictionary<string, decimal>> GetAmountsAsync()
return globalAmounts;
}

/// <summary>
/// Get fees
/// </summary>
/// <returns>The customer trading fees</returns>
public virtual async Task<Dictionary<string, decimal>> GetFeesAync()
{
return await Cache.CacheMethod(MethodCachePolicy, async() => await OnGetFeesAsync(), nameof(GetFeesAync));
}

/// <summary>
/// Get amounts available to trade, symbol / amount dictionary
/// </summary>
Expand Down
84 changes: 57 additions & 27 deletions src/ExchangeSharp/API/Exchanges/_Base/IExchangeAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,14 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider

#endregion Utility Methods

#region REST
#region REST API

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

/// <summary>
/// Gets the address to deposit to and applicable details.
/// </summary>
/// <param name="currency">Currency to get address for.</param>
/// <param name="forceRegenerate">True to regenerate the address</param>
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false);

/// <summary>
/// Gets the deposit history for a currency
/// </summary>
/// <param name="currency">The currency to check. May be null.</param>
/// <returns>Collection of ExchangeCoinTransfers</returns>
Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency);

/// <summary>
/// Get symbols for the exchange markets
/// </summary>
Expand All @@ -109,6 +94,29 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
/// <returns>Collection of ExchangeMarkets</returns>
Task<IEnumerable<ExchangeMarket>> GetMarketSymbolsMetadataAsync();

/// <summary>
/// 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().
/// 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.
/// </summary>
/// <param name="marketSymbol">The market symbol. Ex. ADA/BTC. This is assumed to be normalized and already correct for the exchange.</param>
/// <returns>The ExchangeMarket or null if it doesn't exist in the cache or there was an error</returns>
Task<ExchangeMarket?> GetExchangeMarketFromCacheAsync(string marketSymbol);

/// <summary>
/// Gets the address to deposit to and applicable details.
/// </summary>
/// <param name="currency">Currency to get address for.</param>
/// <param name="forceRegenerate">True to regenerate the address</param>
/// <returns>Deposit address details (including tag if applicable, such as XRP)</returns>
Task<ExchangeDepositDetails> GetDepositAddressAsync(string currency, bool forceRegenerate = false);

/// <summary>
/// Gets the deposit history for a currency
/// </summary>
/// <param name="currency">The currency to check. May be null.</param>
/// <returns>Collection of ExchangeCoinTransfers</returns>
Task<IEnumerable<ExchangeTransaction>> GetDepositHistoryAsync(string currency);

/// <summary>
/// Get latest ticker
/// </summary>
Expand All @@ -132,6 +140,10 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
Task GetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrade>, bool> callback, string marketSymbol, DateTime? startDate = null, DateTime? endDate = null, int? limit = null);
//Task GetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrade>, bool> callback, string marketSymbol, DateTime? startDate = null, DateTime? endDate = null);

// Task<ExchangeOrderBook> GetOrderBookAsync(string marketSymbol, int maxCount = 100); is in IOrderBookProvider

// Task<IEnumerable<KeyValuePair<string, ExchangeOrderBook>>> GetOrderBooksAsync(int maxCount = 100); is in IOrderBookProvider

/// <summary>
/// Get the latest trades
/// </summary>
Expand All @@ -151,6 +163,12 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
/// <returns>Candles</returns>
Task<IEnumerable<MarketCandle>> GetCandlesAsync(string marketSymbol, int periodSeconds, DateTime? startDate = null, DateTime? endDate = null, int? limit = null);

/// <summary>
/// Get fees
/// </summary>
/// <returns>The customer trading fees</returns>
Task<Dictionary<string, decimal>> GetFeesAync();

/// <summary>
/// Get total amounts, symbol / amount dictionary
/// </summary>
Expand All @@ -163,6 +181,13 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
/// <returns>Dictionary of symbols and amounts available to trade</returns>
Task<Dictionary<string, decimal>> GetAmountsAvailableToTradeAsync();

/// <summary>
/// Get margin amounts available to trade, symbol / amount dictionary
/// </summary>
/// <param name="includeZeroBalances">Include currencies with zero balance in return value</param>
/// <returns>Dictionary of symbols and amounts available to trade in margin account</returns>
Task<Dictionary<string, decimal>> GetMarginAmountsAvailableToTradeAsync(bool includeZeroBalances = false);

/// <summary>
/// Place an order
/// </summary>
Expand Down Expand Up @@ -208,11 +233,16 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
Task CancelOrderAsync(string orderId, string? marketSymbol = null);

/// <summary>
/// Get margin amounts available to trade, symbol / amount dictionary
/// Asynchronous withdraws request.
/// </summary>
/// <param name="includeZeroBalances">Include currencies with zero balance in return value</param>
/// <returns>Dictionary of symbols and amounts available to trade in margin account</returns>
Task<Dictionary<string, decimal>> GetMarginAmountsAvailableToTradeAsync(bool includeZeroBalances = false);
/// <param name="withdrawalRequest">The withdrawal request.</param>
Task<ExchangeWithdrawalResponse> WithdrawAsync(ExchangeWithdrawalRequest withdrawalRequest);

/// <summary>
/// Gets the withdraw history for a symbol
/// </summary>
/// <returns>Collection of ExchangeCoinTransfers</returns>
Task<IEnumerable<ExchangeTransaction>> GetWithdrawHistoryAsync(string currency);

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

/// <summary>
/// Get fees
/// </summary>
/// <returns>The customer trading fees</returns>
Task<Dictionary<string, decimal>> GetFeesAync();

#endregion REST

#region Web Socket
#region Web Socket API
/// <summary>
/// Gets Candles (OHLC) websocket
/// </summary>
Expand Down Expand Up @@ -285,6 +309,12 @@ public interface IExchangeAPI : IDisposable, IBaseAPI, IOrderBookProvider
/// <returns>Web socket, call Dispose to close</returns>
Task<IWebSocket> GetCompletedOrderDetailsWebSocketAsync(Action<ExchangeOrderResult> callback);

/// <summary>
/// Get user detail over web socket
/// </summary>
/// <param name="callback">Callback</param>
/// <param name="listenKey">Listen key</param>
/// <returns>Web socket, call Dispose to close</returns>
Task<IWebSocket> GetUserDataWebSocketAsync(Action<object> callback, string listenKey);
#endregion Web Socket
}
Expand Down