mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 07:56:12 +00:00
Shared exchange functionality (#214)
This commit is contained in:
parent
5d3de52da6
commit
b8686d60b9
@ -8,6 +8,7 @@ using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Clients;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.Objects.Options;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using CryptoExchange.Net.UnitTests.TestImplementations;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@ -55,7 +56,7 @@ namespace CryptoExchange.Net.UnitTests
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
public override TimeSpan? GetTimeOffset() => null;
|
||||
public override TimeSyncInfo GetTimeSyncInfo() => null;
|
||||
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
|
||||
|
@ -15,6 +15,7 @@ using System.Collections.Generic;
|
||||
using CryptoExchange.Net.Objects.Options;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CryptoExchange.Net.Clients;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
|
||||
namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
@ -138,7 +139,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
|
||||
public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class
|
||||
{
|
||||
@ -182,7 +183,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
|
||||
public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class
|
||||
{
|
||||
|
@ -14,6 +14,7 @@ using CryptoExchange.Net.UnitTests.TestImplementations.Sockets;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using CryptoExchange.Net.Testing.Implementations;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
|
||||
namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
@ -86,7 +87,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
||||
|
||||
internal IWebsocket CreateSocketInternal(string address)
|
||||
{
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.Objects.Options;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CryptoExchange.Net.Clients
|
||||
@ -76,7 +78,7 @@ namespace CryptoExchange.Net.Clients
|
||||
protected abstract AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials);
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract string FormatSymbol(string baseAsset, string quoteAsset);
|
||||
public abstract string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverDate = null);
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SetApiCredentials<T>(T credentials) where T : ApiCredentials
|
||||
|
@ -18,7 +18,6 @@ using CryptoExchange.Net.RateLimiting;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using CryptoExchange.Net.Requests;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace CryptoExchange.Net.Clients
|
||||
{
|
||||
|
@ -8,7 +8,6 @@ using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using CryptoExchange.Net.Sockets;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
@ -1,11 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Globalization;
|
||||
|
||||
namespace CryptoExchange.Net.Converters.SystemTextJson
|
||||
{
|
||||
|
@ -35,7 +35,7 @@
|
||||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Label="Deterministic Build" Condition="'$(Configuration)' == 'Release'">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
@ -1,7 +1,11 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net
|
||||
{
|
||||
@ -12,6 +16,22 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
private const string _allowedRandomChars = "ABCDEFGHIJKLMONOPQRSTUVWXYZabcdefghijklmonopqrstuvwxyz0123456789";
|
||||
|
||||
private static readonly Dictionary<int, string> _monthSymbols = new Dictionary<int, string>()
|
||||
{
|
||||
{ 1, "F" },
|
||||
{ 2, "G" },
|
||||
{ 3, "H" },
|
||||
{ 4, "J" },
|
||||
{ 5, "K" },
|
||||
{ 6, "M" },
|
||||
{ 7, "N" },
|
||||
{ 8, "Q" },
|
||||
{ 9, "U" },
|
||||
{ 10, "V" },
|
||||
{ 11, "X" },
|
||||
{ 12, "Z" },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The last used id, use NextId() to get the next id and up this
|
||||
/// </summary>
|
||||
@ -55,6 +75,11 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
value -= offset;
|
||||
}
|
||||
else if(roundingType == RoundingType.Up)
|
||||
{
|
||||
if (offset != 0)
|
||||
value += (step.Value - offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (offset < step / 2)
|
||||
@ -107,17 +132,23 @@ namespace CryptoExchange.Net
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a value down to
|
||||
/// Rounds a value down
|
||||
/// </summary>
|
||||
/// <param name="i"></param>
|
||||
/// <param name="decimalPlaces"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal RoundDown(decimal i, double decimalPlaces)
|
||||
{
|
||||
var power = Convert.ToDecimal(Math.Pow(10, decimalPlaces));
|
||||
return Math.Floor(i * power) / power;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a value up
|
||||
/// </summary>
|
||||
public static decimal RoundUp(decimal i, double decimalPlaces)
|
||||
{
|
||||
var power = Convert.ToDecimal(Math.Pow(10, decimalPlaces));
|
||||
return Math.Ceiling(i * power) / power;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Strips any trailing zero's of a decimal value, useful when converting the value to string.
|
||||
/// </summary>
|
||||
@ -177,5 +208,70 @@ namespace CryptoExchange.Net
|
||||
|
||||
return source + RandomString(totalLength - source.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the month representation for futures symbol based on the delivery month
|
||||
/// </summary>
|
||||
/// <param name="time">Delivery time</param>
|
||||
/// <returns></returns>
|
||||
public static string GetDeliveryMonthSymbol(DateTime time) => _monthSymbols[time.Month];
|
||||
|
||||
/// <summary>
|
||||
/// Execute multiple requests to retrieve multiple pages of the result set
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the client</typeparam>
|
||||
/// <typeparam name="U">Type of the request</typeparam>
|
||||
/// <param name="paginatedFunc">The func to execute with each request</param>
|
||||
/// <param name="request">The request parameters</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
public static async IAsyncEnumerable<ExchangeWebResult<IEnumerable<T>>> ExecutePages<T, U>(Func<U, INextPageToken?, CancellationToken, Task<ExchangeWebResult<IEnumerable<T>>>> paginatedFunc, U request, [EnumeratorCancellation]CancellationToken ct = default)
|
||||
{
|
||||
var result = new List<T>();
|
||||
ExchangeWebResult<IEnumerable<T>> batch;
|
||||
INextPageToken? nextPageToken = null;
|
||||
while (true)
|
||||
{
|
||||
batch = await paginatedFunc(request, nextPageToken, ct).ConfigureAwait(false);
|
||||
yield return batch;
|
||||
if (!batch || ct.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
result.AddRange(batch.Data);
|
||||
nextPageToken = batch.NextPageToken;
|
||||
if (nextPageToken == null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply the rules (price and quantity step size and decimals precision, min/max quantity) from the symbol to the quantity and price
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol as retrieved from the exchange</param>
|
||||
/// <param name="quantity">Quantity to trade</param>
|
||||
/// <param name="price">Price to trade at</param>
|
||||
/// <param name="adjustedQuantity">Quantity adjusted to match all trading rules</param>
|
||||
/// <param name="adjustedPrice">Price adjusted to match all trading rules</param>
|
||||
public static void ApplySymbolRules(SharedSpotSymbol symbol, decimal quantity, decimal? price, out decimal adjustedQuantity, out decimal? adjustedPrice)
|
||||
{
|
||||
adjustedPrice = price;
|
||||
adjustedQuantity = quantity;
|
||||
var minNotionalAdjust = false;
|
||||
|
||||
if (price != null)
|
||||
{
|
||||
adjustedPrice = AdjustValueStep(0, decimal.MaxValue, symbol.PriceStep, RoundingType.Down, price.Value);
|
||||
adjustedPrice = symbol.PriceDecimals.HasValue ? RoundDown(price.Value, symbol.PriceDecimals.Value) : adjustedPrice;
|
||||
if (adjustedPrice != 0 && adjustedPrice * quantity < symbol.MinNotionalValue)
|
||||
{
|
||||
adjustedQuantity = symbol.MinNotionalValue.Value / adjustedPrice.Value;
|
||||
minNotionalAdjust = true;
|
||||
}
|
||||
}
|
||||
|
||||
adjustedQuantity = AdjustValueStep(symbol.MinTradeQuantity ?? 0, symbol.MaxTradeQuantity ?? decimal.MaxValue, symbol.QuantityStep, minNotionalAdjust ? RoundingType.Up : RoundingType.Down, adjustedQuantity);
|
||||
adjustedQuantity = symbol.QuantityDecimals.HasValue ? (minNotionalAdjust ? RoundUp(adjustedQuantity, symbol.QuantityDecimals.Value) : RoundDown(adjustedQuantity, symbol.QuantityDecimals.Value)) : adjustedQuantity;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,12 @@ using System.IO.Compression;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System.Globalization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
|
||||
namespace CryptoExchange.Net
|
||||
{
|
||||
@ -378,6 +379,116 @@ namespace CryptoExchange.Net
|
||||
output.Position = 0;
|
||||
return new ReadOnlyMemory<byte>(output.GetBuffer(), 0, (int)output.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the trading mode is linear
|
||||
/// </summary>
|
||||
public static bool IsLinear(this TradingMode type) => type == TradingMode.PerpetualLinear || type == TradingMode.DeliveryLinear;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the trading mode is inverse
|
||||
/// </summary>
|
||||
public static bool IsInverse(this TradingMode type) => type == TradingMode.PerpetualInverse || type == TradingMode.DeliveryInverse;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the trading mode is perpetual
|
||||
/// </summary>
|
||||
public static bool IsPerpetual(this TradingMode type) => type == TradingMode.PerpetualInverse || type == TradingMode.PerpetualLinear;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the trading mode is delivery
|
||||
/// </summary>
|
||||
public static bool IsDelivery(this TradingMode type) => type == TradingMode.DeliveryInverse || type == TradingMode.DeliveryLinear;
|
||||
|
||||
/// <summary>
|
||||
/// Register rest client interfaces
|
||||
/// </summary>
|
||||
public static IServiceCollection RegisterSharedRestInterfaces<T>(this IServiceCollection services, Func<IServiceProvider, T> client)
|
||||
{
|
||||
if (typeof(IAssetsRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IAssetsRestClient)client(x)!);
|
||||
if (typeof(IBalanceRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IBalanceRestClient)client(x)!);
|
||||
if (typeof(IDepositRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IDepositRestClient)client(x)!);
|
||||
if (typeof(IKlineRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IKlineRestClient)client(x)!);
|
||||
if (typeof(IListenKeyRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IListenKeyRestClient)client(x)!);
|
||||
if (typeof(IOrderBookRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IOrderBookRestClient)client(x)!);
|
||||
if (typeof(IRecentTradeRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IRecentTradeRestClient)client(x)!);
|
||||
if (typeof(ITradeHistoryRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ITradeHistoryRestClient)client(x)!);
|
||||
if (typeof(IWithdrawalRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IWithdrawalRestClient)client(x)!);
|
||||
if (typeof(IWithdrawRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IWithdrawRestClient)client(x)!);
|
||||
|
||||
if (typeof(ISpotOrderRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ISpotOrderRestClient)client(x)!);
|
||||
if (typeof(ISpotSymbolRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ISpotSymbolRestClient)client(x)!);
|
||||
if (typeof(ISpotTickerRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ISpotTickerRestClient)client(x)!);
|
||||
|
||||
if (typeof(IFundingRateRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IFundingRateRestClient)client(x)!);
|
||||
if (typeof(IFuturesOrderRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IFuturesOrderRestClient)client(x)!);
|
||||
if (typeof(IFuturesSymbolRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IFuturesSymbolRestClient)client(x)!);
|
||||
if (typeof(IFuturesTickerRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IFuturesTickerRestClient)client(x)!);
|
||||
if (typeof(IIndexPriceKlineRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IIndexPriceKlineRestClient)client(x)!);
|
||||
if (typeof(ILeverageRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ILeverageRestClient)client(x)!);
|
||||
if (typeof(IMarkPriceKlineRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IMarkPriceKlineRestClient)client(x)!);
|
||||
if (typeof(IOpenInterestRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IOpenInterestRestClient)client(x)!);
|
||||
if (typeof(IPositionHistoryRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IPositionHistoryRestClient)client(x)!);
|
||||
if (typeof(IPositionModeRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IPositionModeRestClient)client(x)!);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register socket client interfaces
|
||||
/// </summary>
|
||||
public static IServiceCollection RegisterSharedSocketInterfaces<T>(this IServiceCollection services, Func<IServiceProvider, T> client)
|
||||
{
|
||||
if (typeof(IBalanceSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IBalanceSocketClient)client(x)!);
|
||||
if (typeof(IBookTickerSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IBookTickerSocketClient)client(x)!);
|
||||
if (typeof(IKlineSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IKlineSocketClient)client(x)!);
|
||||
if (typeof(IOrderBookRestClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IOrderBookRestClient)client(x)!);
|
||||
if (typeof(ITickerSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ITickerSocketClient)client(x)!);
|
||||
if (typeof(ITickersSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ITickersSocketClient)client(x)!);
|
||||
if (typeof(ITradeSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ITradeSocketClient)client(x)!);
|
||||
if (typeof(IUserTradeSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IUserTradeSocketClient)client(x)!);
|
||||
|
||||
if (typeof(ISpotOrderSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (ISpotOrderSocketClient)client(x)!);
|
||||
|
||||
if (typeof(IFuturesOrderSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IFuturesOrderSocketClient)client(x)!);
|
||||
if (typeof(IPositionSocketClient).IsAssignableFrom(typeof(T)))
|
||||
services.AddTransient(x => (IPositionSocketClient)client(x)!);
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,131 +8,87 @@ using System.Threading.Tasks;
|
||||
namespace CryptoExchange.Net.Interfaces.CommonClients
|
||||
{
|
||||
/// <summary>
|
||||
/// Common rest client endpoints
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
public interface IBaseRestClient
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the exchange
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
string ExchangeName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Should be triggered on order placing
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
event Action<OrderId> OnOrderPlaced;
|
||||
/// <summary>
|
||||
/// Should be triggered on order cancelling
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
event Action<OrderId> OnOrderCanceled;
|
||||
|
||||
/// <summary>
|
||||
/// Get the symbol name based on a base and quote asset
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="baseAsset">The base asset</param>
|
||||
/// <param name="quoteAsset">The quote asset</param>
|
||||
/// <returns></returns>
|
||||
string GetSymbolName(string baseAsset, string quoteAsset);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of symbols for the exchange
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Symbol>>> GetSymbolsAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get a ticker for the exchange
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol to get klines for</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<Ticker>> GetTickerAsync(string symbol, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of tickers for the exchange
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Ticker>>> GetTickersAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of candles for a given symbol on the exchange
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol to retrieve the candles for</param>
|
||||
/// <param name="timespan">The timespan to retrieve the candles for. The supported value are dependent on the exchange</param>
|
||||
/// <param name="startTime">[Optional] Start time to retrieve klines for</param>
|
||||
/// <param name="endTime">[Optional] End time to retrieve klines for</param>
|
||||
/// <param name="limit">[Optional] Max number of results</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Kline>>> GetKlinesAsync(string symbol, TimeSpan timespan, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get the order book for a symbol
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol to get the book for</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<CommonObjects.OrderBook>> GetOrderBookAsync(string symbol, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// The recent trades for a symbol
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol to get the trades for</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Trade>>> GetRecentTradesAsync(string symbol, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get balances
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="accountId">[Optional] The account id to retrieve balances for, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Balance>>> GetBalancesAsync(string? accountId = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get an order by id
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="orderId">The id</param>
|
||||
/// <param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<Order>> GetOrderAsync(string orderId, string? symbol = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get trades for an order by id
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="orderId">The id</param>
|
||||
/// <param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<UserTrade>>> GetOrderTradesAsync(string orderId, string? symbol = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of open orders
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">[Optional] The symbol to get open orders for, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Order>>> GetOpenOrdersAsync(string? symbol = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of closed orders
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">[Optional] The symbol to get closed orders for, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Order>>> GetClosedOrdersAsync(string? symbol = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an order by id
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="orderId">The id</param>
|
||||
/// <param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<OrderId>> CancelOrderAsync(string orderId, string? symbol = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
||||
|
@ -7,30 +7,18 @@ using CryptoExchange.Net.Objects;
|
||||
namespace CryptoExchange.Net.Interfaces.CommonClients
|
||||
{
|
||||
/// <summary>
|
||||
/// Common futures endpoints
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
public interface IFuturesClient : IBaseRestClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Place an order
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol the order is for</param>
|
||||
/// <param name="side">The side of the order</param>
|
||||
/// <param name="type">The type of the order</param>
|
||||
/// <param name="quantity">The quantity of the order</param>
|
||||
/// <param name="price">The price of the order, only for limit orders</param>
|
||||
/// <param name="accountId">[Optional] The account id to place the order on, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="leverage">[Optional] Leverage for this order. This is needed for some exchanges. For exchanges where this is not needed this parameter is ignored (and should be set before hand)</param>
|
||||
/// <param name="clientOrderId">[Optional] Client specified id for this order</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns>The id of the resulting order</returns>
|
||||
Task<WebCallResult<OrderId>> PlaceOrderAsync(string symbol, CommonOrderSide side, CommonOrderType type, decimal quantity, decimal? price = null, int? leverage = null, string? accountId = null, string? clientOrderId = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get position
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns></returns>
|
||||
Task<WebCallResult<IEnumerable<Position>>> GetPositionsAsync(CancellationToken ct = default);
|
||||
}
|
||||
}
|
||||
|
@ -6,22 +6,13 @@ using System.Threading.Tasks;
|
||||
namespace CryptoExchange.Net.Interfaces.CommonClients
|
||||
{
|
||||
/// <summary>
|
||||
/// Common spot endpoints
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="" /> for more info.
|
||||
/// </summary>
|
||||
public interface ISpotClient: IBaseRestClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Place an order
|
||||
/// DEPRECATED; use <see cref="SharedApis.ISharedClient" /> instead for common/shared functionality. See <see href="https://jkorf.github.io/CryptoExchange.Net/docs/index.html#shared" /> for more info.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol the order is for</param>
|
||||
/// <param name="side">The side of the order</param>
|
||||
/// <param name="type">The type of the order</param>
|
||||
/// <param name="quantity">The quantity of the order</param>
|
||||
/// <param name="price">The price of the order, only for limit orders</param>
|
||||
/// <param name="accountId">[Optional] The account id to place the order on, required for some exchanges, ignored otherwise</param>
|
||||
/// <param name="clientOrderId">[Optional] Client specified id for this order</param>
|
||||
/// <param name="ct">[Optional] Cancellation token for cancelling the request</param>
|
||||
/// <returns>The id of the resulting order</returns>
|
||||
Task<WebCallResult<OrderId>> PlaceOrderAsync(string symbol, CommonOrderSide side, CommonOrderType type, decimal quantity, decimal? price = null, string? accountId = null, string? clientOrderId = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using System;
|
||||
|
||||
namespace CryptoExchange.Net.Interfaces
|
||||
{
|
||||
@ -17,8 +20,10 @@ namespace CryptoExchange.Net.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="baseAsset">The base asset</param>
|
||||
/// <param name="quoteAsset">The quote asset</param>
|
||||
/// <param name="tradingMode">The trading mode</param>
|
||||
/// <param name="deliverDate">The deliver date for a delivery futures symbol</param>
|
||||
/// <returns></returns>
|
||||
string FormatSymbol(string baseAsset, string quoteAsset);
|
||||
string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverDate = null);
|
||||
|
||||
/// <summary>
|
||||
/// Set the API credentials for this API client
|
||||
|
@ -1,7 +1,6 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Net.Http;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.Objects
|
||||
namespace CryptoExchange.Net.Objects
|
||||
{
|
||||
/// <summary>
|
||||
/// Proxy info
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
@ -284,6 +285,32 @@ namespace CryptoExchange.Net.Objects
|
||||
return new WebCallResult<K>(ResponseStatusCode, ResponseHeaders, ResponseTime, 0, null, RequestId, RequestUrl, RequestBody, RequestMethod, RequestHeaders, ResultDataSource.Server, data, Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult of a new data type
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="tradeMode">Trade mode the result applies to</param>
|
||||
/// <param name="data">The data</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<K> AsExchangeResult<K>(string exchange, TradingMode tradeMode, [AllowNull] K data)
|
||||
{
|
||||
return new ExchangeWebResult<K>(exchange, tradeMode, this.As<K>(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult of a new data type
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="tradeModes">Trade modes the result applies to</param>
|
||||
/// <param name="data">The data</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<K> AsExchangeResult<K>(string exchange, TradingMode[]? tradeModes, [AllowNull] K data)
|
||||
{
|
||||
return new ExchangeWebResult<K>(exchange, tradeModes, this.As<K>(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to a new data type
|
||||
/// </summary>
|
||||
@ -447,6 +474,68 @@ namespace CryptoExchange.Net.Objects
|
||||
return new WebCallResult<K>(ResponseStatusCode, ResponseHeaders, ResponseTime, ResponseLength, OriginalData, RequestId, RequestUrl, RequestBody, RequestMethod, RequestHeaders, DataSource, default, error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult of a new data type
|
||||
/// </summary>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="tradeMode">Trade mode the result applies to</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<T> AsExchangeResult(string exchange, TradingMode tradeMode)
|
||||
{
|
||||
return new ExchangeWebResult<T>(exchange, tradeMode, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult of a new data type
|
||||
/// </summary>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="tradeModes">Trade modes the result applies to</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<T> AsExchangeResult(string exchange, TradingMode[] tradeModes)
|
||||
{
|
||||
return new ExchangeWebResult<T>(exchange, tradeModes, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult of a new data type
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="tradeMode">Trade mode the result applies to</param>
|
||||
/// <param name="data">Data</param>
|
||||
/// <param name="nextPageToken">Next page token</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<K> AsExchangeResult<K>(string exchange, TradingMode tradeMode, [AllowNull] K data, INextPageToken? nextPageToken = null)
|
||||
{
|
||||
return new ExchangeWebResult<K>(exchange, tradeMode, As<K>(data), nextPageToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult of a new data type
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="tradeModes">Trade modes the result applies to</param>
|
||||
/// <param name="data">Data</param>
|
||||
/// <param name="nextPageToken">Next page token</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<K> AsExchangeResult<K>(string exchange, TradingMode[]? tradeModes, [AllowNull] K data, INextPageToken? nextPageToken = null)
|
||||
{
|
||||
return new ExchangeWebResult<K>(exchange, tradeModes, As<K>(data), nextPageToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to an ExchangeWebResult with a specific error
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="exchange">The exchange</param>
|
||||
/// <param name="error">The error returned</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeWebResult<K> AsExchangeError<K>(string exchange, Error error)
|
||||
{
|
||||
return new ExchangeWebResult<K>(exchange, null, AsError<K>(error));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a copy of this result with data source set to cache
|
||||
/// </summary>
|
||||
|
@ -152,7 +152,11 @@
|
||||
/// <summary>
|
||||
/// Round to closest value
|
||||
/// </summary>
|
||||
Closest
|
||||
Closest,
|
||||
/// <summary>
|
||||
/// Round up (ceil)
|
||||
/// </summary>
|
||||
Up
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -203,4 +207,5 @@
|
||||
/// </summary>
|
||||
Cache
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using CryptoExchange.Net.Authentication;
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
|
||||
namespace CryptoExchange.Net.Objects.Options
|
||||
|
@ -1,5 +1,4 @@
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace CryptoExchange.Net.Objects
|
||||
|
@ -1,7 +1,5 @@
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace CryptoExchange.Net.Objects
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using System;
|
||||
|
||||
namespace CryptoExchange.Net.Objects.Sockets
|
||||
{
|
||||
@ -38,7 +39,10 @@ namespace CryptoExchange.Net.Objects.Sockets
|
||||
/// </summary>
|
||||
public T Data { get; set; }
|
||||
|
||||
internal DataEvent(T data, string? streamId, string? symbol, string? originalData, DateTime timestamp, SocketUpdateType? updateType)
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public DataEvent(T data, string? streamId, string? symbol, string? originalData, DateTime timestamp, SocketUpdateType? updateType)
|
||||
{
|
||||
Data = data;
|
||||
StreamId = streamId;
|
||||
@ -85,6 +89,19 @@ namespace CryptoExchange.Net.Objects.Sockets
|
||||
return new DataEvent<K>(data, streamId, symbol, OriginalData, Timestamp, updateType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the WebCallResult to a new data type
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="exchange">The exchange the result is for</param>
|
||||
/// <param name="data">The data</param>
|
||||
/// <returns></returns>
|
||||
public ExchangeEvent<K> AsExchangeEvent<K>(string exchange, K data)
|
||||
{
|
||||
return new ExchangeEvent<K>(exchange, this.As<K>(data));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Specify the symbol
|
||||
/// </summary>
|
||||
|
@ -30,6 +30,15 @@ namespace CryptoExchange.Net.Objects.Sockets
|
||||
remove => _connection.ConnectionClosed -= value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event when a lost connection is restored, but the resubscribing of update subscriptions failed
|
||||
/// </summary>
|
||||
public event Action<Error> ResubscribingFailed
|
||||
{
|
||||
add => _connection.ResubscribingFailed += value;
|
||||
remove => _connection.ResubscribingFailed -= value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event when the connection is restored. Timespan parameter indicates the time the socket has been offline for before reconnecting.
|
||||
/// Note that when the executing code is suspended and resumed at a later period (for example, a laptop going to sleep) the disconnect time will be incorrect as the diconnect
|
||||
|
@ -1,6 +1,5 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Filters
|
||||
{
|
||||
|
@ -1,9 +1,6 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Filters
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Filters
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Filters
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Filters
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Filters
|
||||
{
|
||||
|
@ -3,8 +3,6 @@ using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using CryptoExchange.Net.RateLimiting.Trackers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Guards
|
||||
{
|
||||
|
@ -1,9 +1,6 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Guards
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using CryptoExchange.Net.RateLimiting.Interfaces;
|
||||
using CryptoExchange.Net.RateLimiting.Trackers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Guards
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Interfaces
|
||||
{
|
||||
|
@ -1,8 +1,6 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.RateLimiting.Guards;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System.Net.Http;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.RateLimiting.Interfaces
|
||||
{
|
||||
|
@ -7,7 +7,6 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
29
CryptoExchange.Net/SharedApis/Enums/SharedFeeAssetType.cs
Normal file
29
CryptoExchange.Net/SharedApis/Enums/SharedFeeAssetType.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Fee asset selection type
|
||||
/// </summary>
|
||||
public enum SharedFeeAssetType
|
||||
{
|
||||
/// <summary>
|
||||
/// Fee is always in the base asset
|
||||
/// </summary>
|
||||
BaseAsset,
|
||||
/// <summary>
|
||||
/// Fee is always in the quote asset
|
||||
/// </summary>
|
||||
QuoteAsset,
|
||||
/// <summary>
|
||||
/// Fee is always in the input asset
|
||||
/// </summary>
|
||||
InputAsset,
|
||||
/// <summary>
|
||||
/// Fee is always in the output asset
|
||||
/// </summary>
|
||||
OutputAsset,
|
||||
/// <summary>
|
||||
/// Fee is variable
|
||||
/// </summary>
|
||||
Variable
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Fee deduction type
|
||||
/// </summary>
|
||||
public enum SharedFeeDeductionType
|
||||
{
|
||||
/// <summary>
|
||||
/// The fee is deducted from the output amount. For example buying 1 ETH at 1000 USDT with a 1% fee would cost 1000 USDT and output 0.99 ETH
|
||||
/// </summary>
|
||||
DeductFromOutput,
|
||||
/// <summary>
|
||||
/// The fee is added to the order cost. For example buying 1 ETH at 1000 USDT with a 1% fee would cost 1010 USDT and output 1 ETH
|
||||
/// </summary>
|
||||
AddToCost
|
||||
}
|
||||
}
|
33
CryptoExchange.Net/SharedApis/Enums/SharedKlineInterval.cs
Normal file
33
CryptoExchange.Net/SharedApis/Enums/SharedKlineInterval.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Kline interval
|
||||
/// </summary>
|
||||
public enum SharedKlineInterval
|
||||
{
|
||||
/// <summary>
|
||||
/// 5 min
|
||||
/// </summary>
|
||||
FiveMinutes = 60 * 5,
|
||||
/// <summary>
|
||||
/// 15 min
|
||||
/// </summary>
|
||||
FifteenMinutes = 60 * 15,
|
||||
/// <summary>
|
||||
/// 1 hour
|
||||
/// </summary>
|
||||
OneHour = 60 * 60,
|
||||
/// <summary>
|
||||
/// 1 day
|
||||
/// </summary>
|
||||
OneDay = 60 * 60 * 24,
|
||||
/// <summary>
|
||||
/// 1 week
|
||||
/// </summary>
|
||||
OneWeek = 60 * 60 * 24 * 7,
|
||||
/// <summary>
|
||||
/// 1 month
|
||||
/// </summary>
|
||||
OneMonth = 60 * 60 * 24 * 30
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Leverage setting mode
|
||||
/// </summary>
|
||||
public enum SharedLeverageSettingMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Leverage is configured per side (in hedge mode)
|
||||
/// </summary>
|
||||
PerSide,
|
||||
/// <summary>
|
||||
/// Leverage is configured for the symbol
|
||||
/// </summary>
|
||||
PerSymbol
|
||||
}
|
||||
}
|
17
CryptoExchange.Net/SharedApis/Enums/SharedMarginMode.cs
Normal file
17
CryptoExchange.Net/SharedApis/Enums/SharedMarginMode.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Margin mode
|
||||
/// </summary>
|
||||
public enum SharedMarginMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Cross margin, margin is shared across symbols
|
||||
/// </summary>
|
||||
Cross,
|
||||
/// <summary>
|
||||
/// Isolated margin, margin is isolated on a symbol
|
||||
/// </summary>
|
||||
Isolated
|
||||
}
|
||||
}
|
17
CryptoExchange.Net/SharedApis/Enums/SharedOrderSide.cs
Normal file
17
CryptoExchange.Net/SharedApis/Enums/SharedOrderSide.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Side of an order
|
||||
/// </summary>
|
||||
public enum SharedOrderSide
|
||||
{
|
||||
/// <summary>
|
||||
/// Buy order
|
||||
/// </summary>
|
||||
Buy,
|
||||
/// <summary>
|
||||
/// Sell order
|
||||
/// </summary>
|
||||
Sell
|
||||
}
|
||||
}
|
21
CryptoExchange.Net/SharedApis/Enums/SharedOrderStatus.cs
Normal file
21
CryptoExchange.Net/SharedApis/Enums/SharedOrderStatus.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Status of an order
|
||||
/// </summary>
|
||||
public enum SharedOrderStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Order is open waiting to be filled
|
||||
/// </summary>
|
||||
Open,
|
||||
/// <summary>
|
||||
/// Order has been fully filled
|
||||
/// </summary>
|
||||
Filled,
|
||||
/// <summary>
|
||||
/// Order has been canceled
|
||||
/// </summary>
|
||||
Canceled
|
||||
}
|
||||
}
|
25
CryptoExchange.Net/SharedApis/Enums/SharedOrderType.cs
Normal file
25
CryptoExchange.Net/SharedApis/Enums/SharedOrderType.cs
Normal file
@ -0,0 +1,25 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Type of an order
|
||||
/// </summary>
|
||||
public enum SharedOrderType
|
||||
{
|
||||
/// <summary>
|
||||
/// Limit order, execute at a specific price
|
||||
/// </summary>
|
||||
Limit,
|
||||
/// <summary>
|
||||
/// Limit maker order, a limit order with the condition that is will never be executed as a maker
|
||||
/// </summary>
|
||||
LimitMaker,
|
||||
/// <summary>
|
||||
/// Market order, execute at the best price currently available
|
||||
/// </summary>
|
||||
Market,
|
||||
/// <summary>
|
||||
/// Other order type, used for parsing unsupported order types
|
||||
/// </summary>
|
||||
Other
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Supported pagination type
|
||||
/// </summary>
|
||||
public enum SharedPaginationSupport
|
||||
{
|
||||
/// <summary>
|
||||
/// Pagination is not supported for this exchange request
|
||||
/// </summary>
|
||||
NotSupported,
|
||||
/// <summary>
|
||||
/// Pagination is in ascending order
|
||||
/// </summary>
|
||||
Ascending,
|
||||
/// <summary>
|
||||
/// Pagination is in descending order
|
||||
/// </summary>
|
||||
Descending
|
||||
}
|
||||
}
|
17
CryptoExchange.Net/SharedApis/Enums/SharedPositionMode.cs
Normal file
17
CryptoExchange.Net/SharedApis/Enums/SharedPositionMode.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Position mode
|
||||
/// </summary>
|
||||
public enum SharedPositionMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Hedge mode, a symbol can have both a long and a short position at the same time
|
||||
/// </summary>
|
||||
HedgeMode,
|
||||
/// <summary>
|
||||
/// One way mode, a symbol can only have one open position side at a time
|
||||
/// </summary>
|
||||
OneWay
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Position mode selection type
|
||||
/// </summary>
|
||||
public enum SharedPositionModeSelection
|
||||
{
|
||||
/// <summary>
|
||||
/// Position mode is configured per symbol
|
||||
/// </summary>
|
||||
PerSymbol,
|
||||
/// <summary>
|
||||
/// Position mode is configured for the entire account
|
||||
/// </summary>
|
||||
PerAccount
|
||||
}
|
||||
}
|
17
CryptoExchange.Net/SharedApis/Enums/SharedPositionSide.cs
Normal file
17
CryptoExchange.Net/SharedApis/Enums/SharedPositionSide.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// The side of a position
|
||||
/// </summary>
|
||||
public enum SharedPositionSide
|
||||
{
|
||||
/// <summary>
|
||||
/// Long position
|
||||
/// </summary>
|
||||
Long,
|
||||
/// <summary>
|
||||
/// Short position
|
||||
/// </summary>
|
||||
Short
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Quote asset order quantity support
|
||||
/// </summary>
|
||||
public enum SharedQuantityType
|
||||
{
|
||||
/// <summary>
|
||||
/// Quantity should be in the base asset
|
||||
/// </summary>
|
||||
BaseAsset,
|
||||
/// <summary>
|
||||
/// Quantity should be in the quote asset
|
||||
/// </summary>
|
||||
QuoteAsset,
|
||||
/// <summary>
|
||||
/// Quantity is in the number of contracts
|
||||
/// </summary>
|
||||
Contracts,
|
||||
/// <summary>
|
||||
/// Quantity can be either base or quote quantity
|
||||
/// </summary>
|
||||
BaseAndQuoteAsset
|
||||
}
|
||||
}
|
17
CryptoExchange.Net/SharedApis/Enums/SharedRole.cs
Normal file
17
CryptoExchange.Net/SharedApis/Enums/SharedRole.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// The role of a trade
|
||||
/// </summary>
|
||||
public enum SharedRole
|
||||
{
|
||||
/// <summary>
|
||||
/// Maker role, put an order on the order book which has been filled
|
||||
/// </summary>
|
||||
Maker,
|
||||
/// <summary>
|
||||
/// Taker role, took an order of the order book to fill
|
||||
/// </summary>
|
||||
Taker
|
||||
}
|
||||
}
|
25
CryptoExchange.Net/SharedApis/Enums/SharedSymbolType.cs
Normal file
25
CryptoExchange.Net/SharedApis/Enums/SharedSymbolType.cs
Normal file
@ -0,0 +1,25 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Type of a symbol
|
||||
/// </summary>
|
||||
public enum SharedSymbolType
|
||||
{
|
||||
/// <summary>
|
||||
/// Perpetual linear, contract has no delivery date and is settled in stablecoin
|
||||
/// </summary>
|
||||
PerpetualLinear,
|
||||
/// <summary>
|
||||
/// Perpetual inverse, contract has no delivery date and is settled in crypto
|
||||
/// </summary>
|
||||
PerpetualInverse,
|
||||
/// <summary>
|
||||
/// Delivery linear, contract has a specific delivery date and is settled in stablecoin
|
||||
/// </summary>
|
||||
DeliveryLinear,
|
||||
/// <summary>
|
||||
/// Delivery inverse, contract has a specific delivery date and is settled in crypto
|
||||
/// </summary>
|
||||
DeliveryInverse
|
||||
}
|
||||
}
|
21
CryptoExchange.Net/SharedApis/Enums/SharedTimeInForce.cs
Normal file
21
CryptoExchange.Net/SharedApis/Enums/SharedTimeInForce.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Time in force for an order
|
||||
/// </summary>
|
||||
public enum SharedTimeInForce
|
||||
{
|
||||
/// <summary>
|
||||
/// Order is good until canceled
|
||||
/// </summary>
|
||||
GoodTillCanceled,
|
||||
/// <summary>
|
||||
/// Order should execute immediately, not executed part is canceled
|
||||
/// </summary>
|
||||
ImmediateOrCancel,
|
||||
/// <summary>
|
||||
/// Order should execute fully immediately or is fully canceled
|
||||
/// </summary>
|
||||
FillOrKill
|
||||
}
|
||||
}
|
29
CryptoExchange.Net/SharedApis/Enums/TradingMode.cs
Normal file
29
CryptoExchange.Net/SharedApis/Enums/TradingMode.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Trading mode
|
||||
/// </summary>
|
||||
public enum TradingMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Spot trading
|
||||
/// </summary>
|
||||
Spot,
|
||||
/// <summary>
|
||||
/// Perpetual linear futures
|
||||
/// </summary>
|
||||
PerpetualLinear,
|
||||
/// <summary>
|
||||
/// Delivery linear futures
|
||||
/// </summary>
|
||||
DeliveryLinear,
|
||||
/// <summary>
|
||||
/// Perpetual inverse futures
|
||||
/// </summary>
|
||||
PerpetualInverse,
|
||||
/// <summary>
|
||||
/// Delivery inverse futures
|
||||
/// </summary>
|
||||
DeliveryInverse
|
||||
}
|
||||
}
|
111
CryptoExchange.Net/SharedApis/Interfaces/INextPageToken.cs
Normal file
111
CryptoExchange.Net/SharedApis/Interfaces/INextPageToken.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using System;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// A token which a request can use to retrieve the next page if there are more pages in the result set
|
||||
/// </summary>
|
||||
public interface INextPageToken
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A datetime offset token
|
||||
/// </summary>
|
||||
public record DateTimeToken: INextPageToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Last result time
|
||||
/// </summary>
|
||||
public DateTime LastTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public DateTimeToken(DateTime timestamp)
|
||||
{
|
||||
LastTime = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A current page index token
|
||||
/// </summary>
|
||||
public record PageToken: INextPageToken
|
||||
{
|
||||
/// <summary>
|
||||
/// The next page index
|
||||
/// </summary>
|
||||
public int Page { get; set; }
|
||||
/// <summary>
|
||||
/// Page size
|
||||
/// </summary>
|
||||
public int PageSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public PageToken(int page, int pageSize)
|
||||
{
|
||||
Page = page;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A id offset token
|
||||
/// </summary>
|
||||
public record FromIdToken : INextPageToken
|
||||
{
|
||||
/// <summary>
|
||||
/// The last id from previous result
|
||||
/// </summary>
|
||||
public string FromToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public FromIdToken(string fromToken)
|
||||
{
|
||||
FromToken = fromToken;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A cursor token
|
||||
/// </summary>
|
||||
public record CursorToken : INextPageToken
|
||||
{
|
||||
/// <summary>
|
||||
/// The next page cursor
|
||||
/// </summary>
|
||||
public string Cursor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public CursorToken(string cursor)
|
||||
{
|
||||
Cursor = cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A result offset token
|
||||
/// </summary>
|
||||
public record OffsetToken : INextPageToken
|
||||
{
|
||||
/// <summary>
|
||||
/// Offset in the result set
|
||||
/// </summary>
|
||||
public int Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public OffsetToken(int offset)
|
||||
{
|
||||
Offset = offset;
|
||||
}
|
||||
}
|
||||
}
|
43
CryptoExchange.Net/SharedApis/Interfaces/ISharedClient.cs
Normal file
43
CryptoExchange.Net/SharedApis/Interfaces/ISharedClient.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// A shared/common client interface
|
||||
/// </summary>
|
||||
public interface ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the exchange
|
||||
/// </summary>
|
||||
string Exchange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Which trading modes this client supports
|
||||
/// </summary>
|
||||
TradingMode[] SupportedTradingModes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Format a base and quote asset to an exchange accepted symbol
|
||||
/// </summary>
|
||||
/// <param name="baseAsset">The base asset</param>
|
||||
/// <param name="quoteAsset">The quote asset</param>
|
||||
/// <param name="tradingMode">The trading mode</param>
|
||||
/// <param name="deliverDate">The deliver date for a delivery futures symbol</param>
|
||||
/// <returns></returns>
|
||||
string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverDate = null);
|
||||
|
||||
/// <summary>
|
||||
/// Set a default exchange parameter. This can be used instead of passing in an ExchangeParameters object which each request.
|
||||
/// </summary>
|
||||
/// <param name="name">Parameter name</param>
|
||||
/// <param name="value">Parameter value</param>
|
||||
void SetDefaultExchangeParameter(string name, object value);
|
||||
|
||||
/// <summary>
|
||||
/// Reset the default exchange parameters, resets parameters for all exchanges
|
||||
/// </summary>
|
||||
void ResetDefaultExchangeParameters();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for request funding rate records
|
||||
/// </summary>
|
||||
public interface IFundingRateRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Funding rate request options
|
||||
/// </summary>
|
||||
GetFundingRateHistoryOptions GetFundingRateHistoryOptions { get; }
|
||||
/// <summary>
|
||||
/// Get funding rate records
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFundingRate>>> GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for placing and managing futures orders
|
||||
/// </summary>
|
||||
public interface IFuturesOrderRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// How the trading fee is deducted
|
||||
/// </summary>
|
||||
SharedFeeDeductionType FuturesFeeDeductionType { get; }
|
||||
/// <summary>
|
||||
/// How the asset is determined in which the trading fee is paid
|
||||
/// </summary>
|
||||
SharedFeeAssetType FuturesFeeAssetType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Supported order types
|
||||
/// </summary>
|
||||
IEnumerable<SharedOrderType> FuturesSupportedOrderTypes { get; }
|
||||
/// <summary>
|
||||
/// Supported time in force
|
||||
/// </summary>
|
||||
IEnumerable<SharedTimeInForce> FuturesSupportedTimeInForce { get; }
|
||||
/// <summary>
|
||||
/// Quantity types support
|
||||
/// </summary>
|
||||
SharedQuantitySupport FuturesSupportedOrderQuantity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Futures place order request options
|
||||
/// </summary>
|
||||
PlaceFuturesOrderOptions PlaceFuturesOrderOptions { get; }
|
||||
/// <summary>
|
||||
/// Place a new futures order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedId>> PlaceFuturesOrderAsync(PlaceFuturesOrderRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Futures get order request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOrderRequest> GetFuturesOrderOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on a specific futures order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedFuturesOrder>> GetFuturesOrderAsync(GetOrderRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Futures get open orders request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOpenOrdersRequest> GetOpenFuturesOrdersOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on a open futures orders
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFuturesOrder>>> GetOpenFuturesOrdersAsync(GetOpenOrdersRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot get closed orders request options
|
||||
/// </summary>
|
||||
PaginatedEndpointOptions<GetClosedOrdersRequest> GetClosedFuturesOrdersOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on closed futures orders
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFuturesOrder>>> GetClosedFuturesOrdersAsync(GetClosedOrdersRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Futures get order trades request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOrderTradesRequest> GetFuturesOrderTradesOptions { get; }
|
||||
/// <summary>
|
||||
/// Get trades for a specific futures order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> GetFuturesOrderTradesAsync(GetOrderTradesRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Futures user trades request options
|
||||
/// </summary>
|
||||
PaginatedEndpointOptions<GetUserTradesRequest> GetFuturesUserTradesOptions { get; }
|
||||
/// <summary>
|
||||
/// Get futures user trade records
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> GetFuturesUserTradesAsync(GetUserTradesRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Futures cancel order request options
|
||||
/// </summary>
|
||||
EndpointOptions<CancelOrderRequest> CancelFuturesOrderOptions { get; }
|
||||
/// <summary>
|
||||
/// Cancel a futures order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedId>> CancelFuturesOrderAsync(CancelOrderRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Positions request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetPositionsRequest> GetPositionsOptions { get; }
|
||||
/// <summary>
|
||||
/// Get open position info
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedPosition>>> GetPositionsAsync(GetPositionsRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Close position order request options
|
||||
/// </summary>
|
||||
EndpointOptions<ClosePositionRequest> ClosePositionOptions { get; }
|
||||
/// <summary>
|
||||
/// Close a currently open position
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<SharedId>> ClosePositionAsync(ClosePositionRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for request futures symbol info
|
||||
/// </summary>
|
||||
public interface IFuturesSymbolRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Futures symbol request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetSymbolsRequest> GetFuturesSymbolsOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on all futures symbols supported on the exchagne
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFuturesSymbol>>> GetFuturesSymbolsAsync(GetSymbolsRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting ticker info for futures symbols
|
||||
/// </summary>
|
||||
public interface IFuturesTickerRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Futures get ticker request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetTickerRequest> GetFuturesTickerOptions { get; }
|
||||
/// <summary>
|
||||
/// Get ticker info for a specific futures symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedFuturesTicker>> GetFuturesTickerAsync(GetTickerRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Futures get tickers request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetTickersRequest> GetFuturesTickersOptions { get; }
|
||||
/// <summary>
|
||||
/// Get ticker info for aall futures symbols
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFuturesTicker>>> GetFuturesTickersAsync(GetTickersRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for getting the index price klines for a symbol
|
||||
/// </summary>
|
||||
public interface IIndexPriceKlineRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Index price klines request options
|
||||
/// </summary>
|
||||
GetKlinesOptions GetIndexPriceKlinesOptions { get; }
|
||||
/// <summary>
|
||||
/// Get index price kline/candlestick data
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFuturesKline>>> GetIndexPriceKlinesAsync(GetKlinesRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for managing the leverage of a symbol
|
||||
/// </summary>
|
||||
public interface ILeverageRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// How the leverage setting is configured on the exchange
|
||||
/// </summary>
|
||||
SharedLeverageSettingMode LeverageSettingType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Leverage request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetLeverageRequest> GetLeverageOptions { get; }
|
||||
/// <summary>
|
||||
/// Get the current leverage setting for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedLeverage>> GetLeverageAsync(GetLeverageRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Leverage set request options
|
||||
/// </summary>
|
||||
SetLeverageOptions SetLeverageOptions { get; }
|
||||
/// <summary>
|
||||
/// Set the leverage for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedLeverage>> SetLeverageAsync(SetLeverageRequest request, CancellationToken ct = default);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for getting the mark price klines for a symbol
|
||||
/// </summary>
|
||||
public interface IMarkPriceKlineRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Mark price klines request options
|
||||
/// </summary>
|
||||
GetKlinesOptions GetMarkPriceKlinesOptions { get; }
|
||||
/// <summary>
|
||||
/// Get mark price kline/candlestick data
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedFuturesKline>>> GetMarkPriceKlinesAsync(GetKlinesRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for getting the open interest for a symbol
|
||||
/// </summary>
|
||||
public interface IOpenInterestRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Open interest request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOpenInterestRequest> GetOpenInterestOptions { get; }
|
||||
/// <summary>
|
||||
/// Get the open interest for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedOpenInterest>> GetOpenInterestAsync(GetOpenInterestRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for getting position history
|
||||
/// </summary>
|
||||
public interface IPositionHistoryRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Position history request options
|
||||
/// </summary>
|
||||
GetPositionHistoryOptions GetPositionHistoryOptions { get; }
|
||||
/// <summary>
|
||||
/// Get position history
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedPositionHistory>>> GetPositionHistoryAsync(GetPositionHistoryRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for managing the position mode setting
|
||||
/// </summary>
|
||||
public interface IPositionModeRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// How the exchange handles setting the position mode
|
||||
/// </summary>
|
||||
SharedPositionModeSelection PositionModeSettingType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Position mode request options
|
||||
/// </summary>
|
||||
GetPositionModeOptions GetPositionModeOptions { get; }
|
||||
/// <summary>
|
||||
/// Get the current position mode setting
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedPositionModeResult>> GetPositionModeAsync(GetPositionModeRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Position mode set request options
|
||||
/// </summary>
|
||||
SetPositionModeOptions SetPositionModeOptions { get; }
|
||||
/// <summary>
|
||||
/// Set the position mode to a new value
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedPositionModeResult>> SetPositionModeAsync(SetPositionModeRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting asset info
|
||||
/// </summary>
|
||||
public interface IAssetsRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Asset request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetAssetRequest> GetAssetOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get info on a specific asset
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedAsset>> GetAssetAsync(GetAssetRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Assets request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetAssetsRequest> GetAssetsOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get info on all assets the exchange supports
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedAsset>>> GetAssetsAsync(GetAssetsRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting user balance info
|
||||
/// </summary>
|
||||
public interface IBalanceRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Balances request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetBalancesRequest> GetBalancesOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get balances for the user
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedBalance>>> GetBalancesAsync(GetBalancesRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting deposit addresses and deposit records
|
||||
/// </summary>
|
||||
public interface IDepositRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Deposit addresses request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetDepositAddressesRequest> GetDepositAddressesOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get deposit addresses for an asset
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedDepositAddress>>> GetDepositAddressesAsync(GetDepositAddressesRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Deposits request options
|
||||
/// </summary>
|
||||
GetDepositsOptions GetDepositsOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get deposit records
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedDeposit>>> GetDepositsAsync(GetDepositsRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting kline/candlestick data
|
||||
/// </summary>
|
||||
public interface IKlineRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Kline request options
|
||||
/// </summary>
|
||||
GetKlinesOptions GetKlinesOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get kline/candlestick data
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedKline>>> GetKlinesAsync(GetKlinesRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for managing the listen key for user stream updates
|
||||
/// </summary>
|
||||
public interface IListenKeyRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Start listen key request options
|
||||
/// </summary>
|
||||
EndpointOptions<StartListenKeyRequest> StartOptions { get; }
|
||||
/// <summary>
|
||||
/// Get the listen key which can be used for user data updates on the socket client
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<string>> StartListenKeyAsync(StartListenKeyRequest request, CancellationToken ct = default);
|
||||
/// <summary>
|
||||
/// Keep-alive listen key request options
|
||||
/// </summary>
|
||||
EndpointOptions<KeepAliveListenKeyRequest> KeepAliveOptions { get; }
|
||||
/// <summary>
|
||||
/// Keep-alive the listen key, needs to be called at a regular interval (typically every 30 minutes)
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<string>> KeepAliveListenKeyAsync(KeepAliveListenKeyRequest request, CancellationToken ct = default);
|
||||
/// <summary>
|
||||
/// Stop listen key request options
|
||||
/// </summary>
|
||||
EndpointOptions<StopListenKeyRequest> StopOptions { get; }
|
||||
/// <summary>
|
||||
/// Stop the listen key, updates will no longer be send to the user data stream for this listen key
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<string>> StopListenKeyAsync(StopListenKeyRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for retrieving the order book for a symbol
|
||||
/// </summary>
|
||||
public interface IOrderBookRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Order book request options
|
||||
/// </summary>
|
||||
GetOrderBookOptions GetOrderBookOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the order book for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<SharedOrderBook>> GetOrderBookAsync(GetOrderBookRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for retrieving the most recent public trades
|
||||
/// </summary>
|
||||
public interface IRecentTradeRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Recent trades request options
|
||||
/// </summary>
|
||||
GetRecentTradesOptions GetRecentTradesOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the most recent public trades
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedTrade>>> GetRecentTradesAsync(GetRecentTradesRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for retrieving trading history
|
||||
/// </summary>
|
||||
public interface ITradeHistoryRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Trade history request options
|
||||
/// </summary>
|
||||
GetTradeHistoryOptions GetTradeHistoryOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get public trade history
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedTrade>>> GetTradeHistoryAsync(GetTradeHistoryRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting to withdraw funds from the exchange
|
||||
/// </summary>
|
||||
public interface IWithdrawRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Withdraw request options
|
||||
/// </summary>
|
||||
WithdrawOptions WithdrawOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Request a withdrawal
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<SharedId>> WithdrawAsync(WithdrawRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for retrieving withdrawal records
|
||||
/// </summary>
|
||||
public interface IWithdrawalRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Withdrawal record request options
|
||||
/// </summary>
|
||||
GetWithdrawalsOptions GetWithdrawalsOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get withdrawal records
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedWithdrawal>>> GetWithdrawalsAsync(GetWithdrawalsRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for placing and managing spot orders
|
||||
/// </summary>
|
||||
public interface ISpotOrderRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// How the trading fee is deducted
|
||||
/// </summary>
|
||||
SharedFeeDeductionType SpotFeeDeductionType { get; }
|
||||
/// <summary>
|
||||
/// How the asset is determined in which the trading fee is paid
|
||||
/// </summary>
|
||||
SharedFeeAssetType SpotFeeAssetType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Supported order types
|
||||
/// </summary>
|
||||
IEnumerable<SharedOrderType> SpotSupportedOrderTypes { get; }
|
||||
/// <summary>
|
||||
/// Supported time in force
|
||||
/// </summary>
|
||||
IEnumerable<SharedTimeInForce> SpotSupportedTimeInForce { get; }
|
||||
/// <summary>
|
||||
/// Quantity types support
|
||||
/// </summary>
|
||||
SharedQuantitySupport SpotSupportedOrderQuantity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Spot place order request options
|
||||
/// </summary>
|
||||
PlaceSpotOrderOptions PlaceSpotOrderOptions { get; }
|
||||
/// <summary>
|
||||
/// Place a new spot order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedId>> PlaceSpotOrderAsync(PlaceSpotOrderRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot get order request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOrderRequest> GetSpotOrderOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on a specific spot order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedSpotOrder>> GetSpotOrderAsync(GetOrderRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot get open orders request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOpenOrdersRequest> GetOpenSpotOrdersOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on a open spot orders
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedSpotOrder>>> GetOpenSpotOrdersAsync(GetOpenOrdersRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot get closed orders request options
|
||||
/// </summary>
|
||||
PaginatedEndpointOptions<GetClosedOrdersRequest> GetClosedSpotOrdersOptions { get; }
|
||||
/// <summary>
|
||||
/// Get info on closed spot orders
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedSpotOrder>>> GetClosedSpotOrdersAsync(GetClosedOrdersRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot get order trades request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetOrderTradesRequest> GetSpotOrderTradesOptions { get; }
|
||||
/// <summary>
|
||||
/// Get trades for a specific spot order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> GetSpotOrderTradesAsync(GetOrderTradesRequest request, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot user trades request options
|
||||
/// </summary>
|
||||
PaginatedEndpointOptions<GetUserTradesRequest> GetSpotUserTradesOptions { get; }
|
||||
/// <summary>
|
||||
/// Get spot user trade records
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="nextPageToken">The pagination token from the previous request to continue pagination</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedUserTrade>>> GetSpotUserTradesAsync(GetUserTradesRequest request, INextPageToken? nextPageToken = null, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Spot cancel order request options
|
||||
/// </summary>
|
||||
EndpointOptions<CancelOrderRequest> CancelSpotOrderOptions { get; }
|
||||
/// <summary>
|
||||
/// Cancel a spot order
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedId>> CancelSpotOrderAsync(CancelOrderRequest request, CancellationToken ct = default);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting spot symbols
|
||||
/// </summary>
|
||||
public interface ISpotSymbolRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Spot symbols request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetSymbolsRequest> GetSpotSymbolsOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get info on all available spot symbols on the exchange
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedSpotSymbol>>> GetSpotSymbolsAsync(GetSymbolsRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for requesting spot tickers
|
||||
/// </summary>
|
||||
public interface ISpotTickerRestClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Spot ticker request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetTickerRequest> GetSpotTickerOptions { get; }
|
||||
/// <summary>
|
||||
/// Get ticker for a specific spot symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<SharedSpotTicker>> GetSpotTickerAsync(GetTickerRequest request, CancellationToken ct = default);
|
||||
/// <summary>
|
||||
/// Spot tickers request options
|
||||
/// </summary>
|
||||
EndpointOptions<GetTickersRequest> GetSpotTickersOptions { get; }
|
||||
/// <summary>
|
||||
/// Get tickers for all spot symbols
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="ct">Cancellation token</param>
|
||||
Task<ExchangeWebResult<IEnumerable<SharedSpotTicker>>> GetSpotTickersAsync(GetTickersRequest request, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to user futures order updates
|
||||
/// </summary>
|
||||
public interface IFuturesOrderSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Futures orders subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeFuturesOrderRequest> SubscribeFuturesOrderOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to user futures order updates
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToFuturesOrderUpdatesAsync(SubscribeFuturesOrderRequest request, Action<ExchangeEvent<IEnumerable<SharedFuturesOrder>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to position updates
|
||||
/// </summary>
|
||||
public interface IPositionSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Position subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribePositionRequest> SubscribePositionOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to user position updates
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToPositionUpdatesAsync(SubscribePositionRequest request, Action<ExchangeEvent<IEnumerable<SharedPosition>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to user balance updates
|
||||
/// </summary>
|
||||
public interface IBalanceSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Balance subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeBalancesRequest> SubscribeBalanceOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to user balance updates
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToBalanceUpdatesAsync(SubscribeBalancesRequest request, Action<ExchangeEvent<IEnumerable<SharedBalance>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to book ticker updates for a symbol
|
||||
/// </summary>
|
||||
public interface IBookTickerSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Book ticker subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeBookTickerRequest> SubscribeBookTickerOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to book ticker (best ask/bid) updates for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToBookTickerUpdatesAsync(SubscribeBookTickerRequest request, Action<ExchangeEvent<SharedBookTicker>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to kline/candlestick updates for a symbol
|
||||
/// </summary>
|
||||
public interface IKlineSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Kline subscription options
|
||||
/// </summary>
|
||||
SubscribeKlineOptions SubscribeKlineOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to kline/candlestick updates for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToKlineUpdatesAsync(SubscribeKlineRequest request, Action<ExchangeEvent<SharedKline>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to order book snapshot updates for a symbol
|
||||
/// </summary>
|
||||
public interface IOrderBookSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Order book subscription options
|
||||
/// </summary>
|
||||
SubscribeOrderBookOptions SubscribeOrderBookOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to order book snapshot updates for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsync(SubscribeOrderBookRequest request, Action<ExchangeEvent<SharedOrderBook>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to ticker updates for a symbol
|
||||
/// </summary>
|
||||
public interface ITickerSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Ticker subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeTickerRequest> SubscribeTickerOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to ticker updates for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToTickerUpdatesAsync(SubscribeTickerRequest request, Action<ExchangeEvent<SharedSpotTicker>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to ticker updates for all symbols
|
||||
/// </summary>
|
||||
public interface ITickersSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Tickers subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeAllTickersRequest> SubscribeAllTickersOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to tickers updates for all symbols
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToAllTickersUpdatesAsync(SubscribeAllTickersRequest request, Action<ExchangeEvent<IEnumerable<SharedSpotTicker>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to public trade updates for a symbol
|
||||
/// </summary>
|
||||
public interface ITradeSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Trade subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeTradeRequest> SubscribeTradeOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to public trade updates for a symbol
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToTradeUpdatesAsync(SubscribeTradeRequest request, Action<ExchangeEvent<IEnumerable<SharedTrade>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to user trade updates
|
||||
/// </summary>
|
||||
public interface IUserTradeSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// User trade subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeUserTradeRequest> SubscribeUserTradeOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to user trade updates
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToUserTradeUpdatesAsync(SubscribeUserTradeRequest request, Action<ExchangeEvent<IEnumerable<SharedUserTrade>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Client for subscribing to user spot order updates
|
||||
/// </summary>
|
||||
public interface ISpotOrderSocketClient : ISharedClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Spot orders subscription options
|
||||
/// </summary>
|
||||
EndpointOptions<SubscribeSpotOrderRequest> SubscribeSpotOrderOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe to user spot order updates
|
||||
/// </summary>
|
||||
/// <param name="request">Request info</param>
|
||||
/// <param name="handler">Update handler</param>
|
||||
/// <param name="ct">Cancellation token, can be used to stop the updates</param>
|
||||
/// <returns></returns>
|
||||
Task<ExchangeResult<UpdateSubscription>> SubscribeToSpotOrderUpdatesAsync(SubscribeSpotOrderRequest request, Action<ExchangeEvent<IEnumerable<SharedSpotOrder>>> handler, CancellationToken ct = default);
|
||||
}
|
||||
}
|
33
CryptoExchange.Net/SharedApis/Models/ExchangeEvent.cs
Normal file
33
CryptoExchange.Net/SharedApis/Models/ExchangeEvent.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// An update event for a specific exchange
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the data</typeparam>
|
||||
public class ExchangeEvent<T> : DataEvent<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The exchange
|
||||
/// </summary>
|
||||
public string Exchange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public ExchangeEvent(string exchange, DataEvent<T> evnt) :
|
||||
base(evnt.Data,
|
||||
evnt.StreamId,
|
||||
evnt.Symbol,
|
||||
evnt.OriginalData,
|
||||
evnt.Timestamp,
|
||||
evnt.UpdateType)
|
||||
{
|
||||
Exchange = exchange;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"{Exchange} - " + base.ToString();
|
||||
}
|
||||
}
|
34
CryptoExchange.Net/SharedApis/Models/ExchangeParameter.cs
Normal file
34
CryptoExchange.Net/SharedApis/Models/ExchangeParameter.cs
Normal file
@ -0,0 +1,34 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Exchange parameter
|
||||
/// </summary>
|
||||
public class ExchangeParameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Exchange name
|
||||
/// </summary>
|
||||
public string Exchange { get; set; }
|
||||
/// <summary>
|
||||
/// Parameter name
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Parameter value
|
||||
/// </summary>
|
||||
public object Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new exchange parameter
|
||||
/// </summary>
|
||||
/// <param name="exchange">Exchange name</param>
|
||||
/// <param name="name">Parameter name</param>
|
||||
/// <param name="value">Parameter value</param>
|
||||
public ExchangeParameter(string exchange, string name, object value)
|
||||
{
|
||||
Exchange = exchange;
|
||||
Name = name;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
176
CryptoExchange.Net/SharedApis/Models/ExchangeParameters.cs
Normal file
176
CryptoExchange.Net/SharedApis/Models/ExchangeParameters.cs
Normal file
@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Exchange parameters
|
||||
/// </summary>
|
||||
public class ExchangeParameters
|
||||
{
|
||||
private readonly List<ExchangeParameter> _parameters;
|
||||
private static List<ExchangeParameter> _staticParameters = new List<ExchangeParameter>();
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="parameters">The parameters to add</param>
|
||||
public ExchangeParameters(params ExchangeParameter[] parameters)
|
||||
{
|
||||
_parameters = parameters.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a new parameter value
|
||||
/// </summary>
|
||||
/// <param name="exchangeParameter"></param>
|
||||
public void AddValue(ExchangeParameter exchangeParameter)
|
||||
{
|
||||
_parameters.Add(exchangeParameter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a specific parameter is provided in this specific instance
|
||||
/// </summary>
|
||||
/// <param name="exchange">The exchange name</param>
|
||||
/// <param name="name">Parameter name</param>
|
||||
/// <param name="type">Type of the parameter value</param>
|
||||
/// <returns></returns>
|
||||
public bool HasValue(string exchange, string name, Type type)
|
||||
{
|
||||
var val = _parameters.SingleOrDefault(x => x.Exchange == exchange && x.Name == name);
|
||||
val ??= _staticParameters.SingleOrDefault(x => x.Exchange == exchange && x.Name == name);
|
||||
|
||||
if (val == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Type t = Nullable.GetUnderlyingType(type) ?? type;
|
||||
Convert.ChangeType(val.Value, t);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a specific parameter is provided in the default parameters or the provided instance
|
||||
/// </summary>
|
||||
/// <param name="exchangeParameters">The provided exchange parameter in the request</param>
|
||||
/// <param name="exchange">The exchange name</param>
|
||||
/// <param name="name">Parameter name</param>
|
||||
/// <param name="type">Type of the parameter value</param>
|
||||
/// <returns></returns>
|
||||
public static bool HasValue(ExchangeParameters? exchangeParameters, string exchange, string name, Type type)
|
||||
{
|
||||
var provided = exchangeParameters?.HasValue(exchange, name, type);
|
||||
if (provided == true)
|
||||
return true;
|
||||
|
||||
var val = _staticParameters.SingleOrDefault(x => x.Exchange == exchange && x.Name == name);
|
||||
if (val == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
Type t = Nullable.GetUnderlyingType(type) ?? type;
|
||||
Convert.ChangeType(val.Value, t);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the value of a parameter from this instance
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the parameter value</typeparam>
|
||||
/// <param name="exchange">Exchange name</param>
|
||||
/// <param name="name">Parameter name</param>
|
||||
public T? GetValue<T>(string exchange, string name)
|
||||
{
|
||||
var val = _parameters.SingleOrDefault(x => x.Exchange == exchange && x.Name == name);
|
||||
if (val == null)
|
||||
return default;
|
||||
|
||||
try
|
||||
{
|
||||
Type t = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
|
||||
return (T)Convert.ChangeType(val.Value, t);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ArgumentException("Incorrect type for parameter, expected " + typeof(T).Name, name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the value of a parameter from this instance or the default values
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the parameter value</typeparam>
|
||||
/// <param name="exchangeParameters">The request parameters</param>
|
||||
/// <param name="exchange">Exchange name</param>
|
||||
/// <param name="name">Parameter name</param>
|
||||
public static T? GetValue<T>(ExchangeParameters? exchangeParameters, string exchange, string name)
|
||||
{
|
||||
T? value;
|
||||
if (exchangeParameters == null)
|
||||
{
|
||||
var parameter = _staticParameters.SingleOrDefault(x => x.Exchange == exchange && x.Name == name);
|
||||
if (parameter == null)
|
||||
return default;
|
||||
|
||||
if (parameter.Value is T val)
|
||||
return val;
|
||||
|
||||
try
|
||||
{
|
||||
Type t = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
|
||||
return (T)Convert.ChangeType(parameter.Value, t);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ArgumentException("Incorrect type for parameter, expected " + typeof(T).Name, name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value = exchangeParameters.GetValue<T>(exchange, name);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set static parameters
|
||||
/// </summary>
|
||||
/// <param name="exchange">Exchange name</param>
|
||||
/// <param name="key">Parameter name</param>
|
||||
/// <param name="value">Parameter value</param>
|
||||
public static void SetStaticParameter(string exchange, string key, object value)
|
||||
{
|
||||
var existing = _staticParameters.SingleOrDefault(x => x.Exchange == exchange && x.Name == key);
|
||||
if (existing != null)
|
||||
{
|
||||
existing.Value = value;
|
||||
return;
|
||||
}
|
||||
|
||||
_staticParameters.Add(new ExchangeParameter(exchange, key, value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the static parameters, clears all parameters for all exchanges
|
||||
/// </summary>
|
||||
public static void ResetStaticParameters()
|
||||
{
|
||||
_staticParameters.Clear();
|
||||
}
|
||||
}
|
||||
}
|
44
CryptoExchange.Net/SharedApis/Models/ExchangeResult.cs
Normal file
44
CryptoExchange.Net/SharedApis/Models/ExchangeResult.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// A CallResult from an exchange
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ExchangeResult<T> : CallResult<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The exchange
|
||||
/// </summary>
|
||||
public string Exchange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public ExchangeResult(
|
||||
string exchange,
|
||||
Error error) :
|
||||
base(error)
|
||||
{
|
||||
Exchange = exchange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public ExchangeResult(
|
||||
string exchange,
|
||||
CallResult<T> result) :
|
||||
base(
|
||||
result.Data,
|
||||
result.OriginalData,
|
||||
result.Error)
|
||||
{
|
||||
Exchange = exchange;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"{Exchange} - " + base.ToString();
|
||||
}
|
||||
}
|
150
CryptoExchange.Net/SharedApis/Models/ExchangeWebResult.cs
Normal file
150
CryptoExchange.Net/SharedApis/Models/ExchangeWebResult.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// A WebCallResult from an exchange
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The result type</typeparam>
|
||||
public class ExchangeWebResult<T> : WebCallResult<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The exchange
|
||||
/// </summary>
|
||||
public string Exchange { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The trade modes for which the result data is
|
||||
/// </summary>
|
||||
public TradingMode[]? DataTradeMode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Token to retrieve the next page with
|
||||
/// </summary>
|
||||
public INextPageToken? NextPageToken { get; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public ExchangeWebResult(
|
||||
string exchange,
|
||||
Error error) :
|
||||
base(error)
|
||||
{
|
||||
Exchange = exchange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public ExchangeWebResult(
|
||||
string exchange,
|
||||
TradingMode dataTradeMode,
|
||||
WebCallResult<T> result,
|
||||
INextPageToken? nextPageToken = null) :
|
||||
base(result.ResponseStatusCode,
|
||||
result.ResponseHeaders,
|
||||
result.ResponseTime,
|
||||
result.ResponseLength,
|
||||
result.OriginalData,
|
||||
result.RequestId,
|
||||
result.RequestUrl,
|
||||
result.RequestBody,
|
||||
result.RequestMethod,
|
||||
result.RequestHeaders,
|
||||
result.DataSource,
|
||||
result.Data,
|
||||
result.Error)
|
||||
{
|
||||
DataTradeMode = new[] { dataTradeMode };
|
||||
Exchange = exchange;
|
||||
NextPageToken = nextPageToken;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public ExchangeWebResult(
|
||||
string exchange,
|
||||
TradingMode[]? dataTradeModes,
|
||||
WebCallResult<T> result,
|
||||
INextPageToken? nextPageToken = null) :
|
||||
base(result.ResponseStatusCode,
|
||||
result.ResponseHeaders,
|
||||
result.ResponseTime,
|
||||
result.ResponseLength,
|
||||
result.OriginalData,
|
||||
result.RequestId,
|
||||
result.RequestUrl,
|
||||
result.RequestBody,
|
||||
result.RequestMethod,
|
||||
result.RequestHeaders,
|
||||
result.DataSource,
|
||||
result.Data,
|
||||
result.Error)
|
||||
{
|
||||
DataTradeMode = dataTradeModes;
|
||||
Exchange = exchange;
|
||||
NextPageToken = nextPageToken;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new result
|
||||
/// </summary>
|
||||
public ExchangeWebResult(
|
||||
string exchange,
|
||||
TradingMode[]? dataTradeModes,
|
||||
HttpStatusCode? code,
|
||||
IEnumerable<KeyValuePair<string, IEnumerable<string>>>? responseHeaders,
|
||||
TimeSpan? responseTime,
|
||||
long? responseLength,
|
||||
string? originalData,
|
||||
int? requestId,
|
||||
string? requestUrl,
|
||||
string? requestBody,
|
||||
HttpMethod? requestMethod,
|
||||
IEnumerable<KeyValuePair<string, IEnumerable<string>>>? requestHeaders,
|
||||
ResultDataSource dataSource,
|
||||
[AllowNull] T data,
|
||||
Error? error,
|
||||
INextPageToken? nextPageToken = null) : base(
|
||||
code,
|
||||
responseHeaders,
|
||||
responseTime,
|
||||
responseLength,
|
||||
originalData,
|
||||
requestId,
|
||||
requestUrl,
|
||||
requestBody,
|
||||
requestMethod,
|
||||
requestHeaders,
|
||||
dataSource,
|
||||
data,
|
||||
error)
|
||||
{
|
||||
DataTradeMode = dataTradeModes;
|
||||
Exchange = exchange;
|
||||
NextPageToken = nextPageToken;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Copy the ExchangeWebResult to a new data type
|
||||
/// </summary>
|
||||
/// <typeparam name="K">The new type</typeparam>
|
||||
/// <param name="data">The data of the new type</param>
|
||||
/// <returns></returns>
|
||||
public new ExchangeWebResult<K> As<K>([AllowNull] K data)
|
||||
{
|
||||
return new ExchangeWebResult<K>(Exchange, DataTradeMode, ResponseStatusCode, ResponseHeaders, ResponseTime, ResponseLength, OriginalData, RequestId, RequestUrl, RequestBody, RequestMethod, RequestHeaders, DataSource, data, Error, NextPageToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => $"{Exchange} - " + base.ToString();
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for an exchange endpoint
|
||||
/// </summary>
|
||||
public class EndpointOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Required exchange-specific parameters
|
||||
/// </summary>
|
||||
public List<ParameterDescription> RequiredExchangeParameters { get; set; } = new List<ParameterDescription>();
|
||||
/// <summary>
|
||||
/// Endpoint name
|
||||
/// </summary>
|
||||
public string EndpointName { get; set; }
|
||||
/// <summary>
|
||||
/// Information on the specific exchange request
|
||||
/// </summary>
|
||||
public string? RequestNotes { get; set; }
|
||||
/// <summary>
|
||||
/// Whether the call requires authentication
|
||||
/// </summary>
|
||||
public bool NeedsAuthentication { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public EndpointOptions(string endpointName, bool needAuthentication)
|
||||
{
|
||||
EndpointName = endpointName;
|
||||
NeedsAuthentication = needAuthentication;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a request
|
||||
/// </summary>
|
||||
/// <param name="exchange">Exchange name</param>
|
||||
/// <param name="exchangeParameters">Provided exchange parameters</param>
|
||||
/// <param name="tradingMode">Request trading mode</param>
|
||||
/// <param name="supportedTradingModes">Supported trading modes</param>
|
||||
/// <returns></returns>
|
||||
public virtual Error? ValidateRequest(string exchange, ExchangeParameters? exchangeParameters, TradingMode? tradingMode, TradingMode[] supportedTradingModes)
|
||||
{
|
||||
if (tradingMode != null && !supportedTradingModes.Contains(tradingMode.Value))
|
||||
return new ArgumentError($"ApiType.{tradingMode} is not supported, supported types: {string.Join(", ", supportedTradingModes)}");
|
||||
|
||||
foreach (var param in RequiredExchangeParameters)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(param.Name))
|
||||
{
|
||||
if (ExchangeParameters.HasValue(exchangeParameters, exchange, param.Name!, param.ValueType) != true)
|
||||
return new ArgumentError($"Required exchange parameter `{param.Name}` for exchange `{exchange}` is missing or has incorrect type. Expected type is {param.ValueType.Name}. Example: {param.ExampleValue}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (param.Names.All(x => ExchangeParameters.HasValue(exchangeParameters, exchange, x, param.ValueType) != true))
|
||||
return new ArgumentError($"One of exchange parameters `{string.Join(", ", param.Names)}` for exchange `{exchange}` should be provided. Example: {param.ExampleValue}");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual string ToString(string exchange)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"{exchange} {EndpointName}");
|
||||
if (!string.IsNullOrEmpty(RequestNotes))
|
||||
sb.AppendLine(RequestNotes);
|
||||
sb.AppendLine($"Needs authentication: {NeedsAuthentication}");
|
||||
sb.AppendLine($"Required exchange specific parameters: {string.Join(", ", RequiredExchangeParameters.Select(x => x.ToString()))}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Options for an exchange endpoint
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of data</typeparam>
|
||||
public class EndpointOptions<T> : EndpointOptions where T : SharedRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Required optional parameters in the request
|
||||
/// </summary>
|
||||
public List<ParameterDescription> RequiredOptionalParameters { get; set; } = new List<ParameterDescription>();
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public EndpointOptions(bool needsAuthentication) : base(typeof(T).Name, needsAuthentication)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a request
|
||||
/// </summary>
|
||||
/// <param name="exchange">Exchange name</param>
|
||||
/// <param name="request">The request</param>
|
||||
/// <param name="tradingMode">Request trading mode</param>
|
||||
/// <param name="supportedTradingModes">Supported trading modes</param>
|
||||
/// <returns></returns>
|
||||
public virtual Error? ValidateRequest(string exchange, T request, TradingMode? tradingMode, TradingMode[] supportedTradingModes)
|
||||
{
|
||||
foreach (var param in RequiredOptionalParameters)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(param.Name))
|
||||
{
|
||||
if (typeof(T).GetProperty(param.Name).GetValue(request, null) == null)
|
||||
return new ArgumentError($"Required optional parameter `{param.Name}` for exchange `{exchange}` is missing. Example: {param.ExampleValue}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (param.Names.All(x => typeof(T).GetProperty(param.Name).GetValue(request, null) == null))
|
||||
return new ArgumentError($"One of optional parameters `{string.Join(", ", param.Names)}` for exchange `{exchange}` should be provided. Example: {param.ExampleValue}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ValidateRequest(exchange, request.ExchangeParameters, tradingMode, supportedTradingModes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString(string exchange)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"{exchange} {typeof(T).Name}");
|
||||
sb.AppendLine($"Needs authentication: {NeedsAuthentication}");
|
||||
if (!string.IsNullOrEmpty(RequestNotes))
|
||||
sb.AppendLine(RequestNotes);
|
||||
if (RequiredOptionalParameters.Any())
|
||||
sb.AppendLine($"Required optional parameters: {string.Join(", ", RequiredOptionalParameters.Select(x => x.ToString()))}");
|
||||
if (RequiredExchangeParameters.Any())
|
||||
sb.AppendLine($"Required exchange specific parameters: {string.Join(", ", RequiredExchangeParameters.Select(x => x.ToString()))}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for requesting closed orders
|
||||
/// </summary>
|
||||
public class GetClosedOrdersOptions : PaginatedEndpointOptions<GetClosedOrdersRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the start/end time filter is supported
|
||||
/// </summary>
|
||||
public bool TimeFilterSupported { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public GetClosedOrdersOptions(SharedPaginationSupport paginationType, bool timeFilterSupported) : base(paginationType, true)
|
||||
{
|
||||
TimeFilterSupported = timeFilterSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Error? ValidateRequest(string exchange, GetClosedOrdersRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
|
||||
{
|
||||
if (TimeFilterSupported && request.StartTime != null)
|
||||
return new ArgumentError($"Time filter is not supported");
|
||||
|
||||
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString(string exchange)
|
||||
{
|
||||
var sb = new StringBuilder(base.ToString(exchange));
|
||||
sb.AppendLine($"Time filter supported: {TimeFilterSupported}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using System.Text;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Options for requesting deposits
|
||||
/// </summary>
|
||||
public class GetDepositsOptions : PaginatedEndpointOptions<GetDepositsRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the start/end time filter is supported
|
||||
/// </summary>
|
||||
public bool TimeFilterSupported { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public GetDepositsOptions(SharedPaginationSupport paginationType, bool timeFilterSupported) : base(paginationType, true)
|
||||
{
|
||||
TimeFilterSupported = timeFilterSupported;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Error? ValidateRequest(string exchange, GetDepositsRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
|
||||
{
|
||||
if (TimeFilterSupported && request.StartTime != null)
|
||||
return new ArgumentError($"Time filter is not supported");
|
||||
|
||||
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString(string exchange)
|
||||
{
|
||||
var sb = new StringBuilder(base.ToString(exchange));
|
||||
sb.AppendLine($"Time filter supported: {TimeFilterSupported}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user