1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-14 23:21:48 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Jkorf 911e09be61 wip 2026-09-10 15:03:29 +02:00
Jkorf 876c2d27f7 wip 2026-09-10 13:26:33 +02:00
Jkorf dc4a6af695 wip 2026-09-10 12:53:11 +02:00
Jkorf c56e31abab wip 2026-09-10 12:02:57 +02:00
129 changed files with 1844 additions and 226 deletions
@@ -0,0 +1,170 @@
using CryptoExchange.Net.SharedApis;
using NUnit.Framework;
namespace CryptoExchange.Net.UnitTests
{
[TestFixture]
internal class SharedApiClientTests
{
[Test]
public void GetCapability_ShouldUseCapabilityTradingModes()
{
var sharedApi = new TestSharedApi(
[TradingMode.Spot, TradingMode.PerpetualLinear],
[TradingMode.Spot]);
var client = new TestSharedApiClient(sharedApi);
Assert.Multiple(() =>
{
Assert.That(client.GetCapability<ITestCapability>(TradingMode.Spot), Is.SameAs(sharedApi));
Assert.That(client.GetCapability<ITestCapability>(TradingMode.PerpetualLinear), Is.Null);
Assert.That(client.GetCapabilities<ITestCapability>(TradingMode.Spot), Has.Count.EqualTo(1));
Assert.That(client.GetCapabilities<ITestCapability>(TradingMode.PerpetualLinear), Is.Empty);
});
}
[Test]
public void CapabilityTradingModes_ShouldDefaultToSharedApiTradingModes()
{
var sharedApi = new TestSharedApi(
[TradingMode.Spot, TradingMode.PerpetualLinear],
null);
var client = new TestSharedApiClient(sharedApi);
Assert.Multiple(() =>
{
Assert.That(client.GetCapability<ITestCapability>(TradingMode.Spot), Is.SameAs(sharedApi));
Assert.That(client.GetCapability<ITestCapability>(TradingMode.PerpetualLinear), Is.SameAs(sharedApi));
});
}
[Test]
public void CapabilityTradingModes_ShouldIntersectApiApplicableAndOverrideModes()
{
var sharedApi = new TestSharedApi(
[TradingMode.Spot, TradingMode.PerpetualLinear, TradingMode.DeliveryLinear],
[TradingMode.Spot, TradingMode.PerpetualLinear],
[TradingMode.PerpetualLinear, TradingMode.DeliveryLinear]);
Assert.That(
sharedApi.CapabilityOptions.SupportedTradingModes,
Is.EqualTo(new[] { TradingMode.PerpetualLinear }));
}
[Test]
public void CapabilityOptions_ShouldApplyIntrinsicTradingModes()
{
var apiModes = new[]
{
TradingMode.Spot,
TradingMode.PerpetualLinear,
TradingMode.DeliveryLinear,
TradingMode.PerpetualInverse,
TradingMode.DeliveryInverse
};
var spotOptions = new PlaceSpotOrderOptions("TestExchange");
var futuresOptions = new GetPositionsOptions("TestExchange", false);
var perpetualOptions = new GetFundingRateHistoryOptions(
"TestExchange",
true,
true,
true,
100,
false);
var unrestrictedOptions = new GetTickerOptions("TestExchange");
_ = new TestOptionsHost(apiModes, spotOptions);
_ = new TestOptionsHost(apiModes, futuresOptions);
_ = new TestOptionsHost(apiModes, perpetualOptions);
_ = new TestOptionsHost(apiModes, unrestrictedOptions);
Assert.Multiple(() =>
{
Assert.That(spotOptions.SupportedTradingModes, Is.EqualTo(new[] { TradingMode.Spot }));
Assert.That(futuresOptions.SupportedTradingModes, Is.EqualTo(new[]
{
TradingMode.PerpetualLinear,
TradingMode.DeliveryLinear,
TradingMode.PerpetualInverse,
TradingMode.DeliveryInverse
}));
Assert.That(perpetualOptions.SupportedTradingModes, Is.EqualTo(new[]
{
TradingMode.PerpetualLinear,
TradingMode.PerpetualInverse
}));
Assert.That(unrestrictedOptions.SupportedTradingModes, Is.EqualTo(apiModes));
});
}
private interface ITestCapability : ISharedApiCapability
{
}
private sealed class TestCapabilityOptions : CapabilityOptions<SharedRequest, ITestCapability>
{
public override string Description => "Test capability";
public TestCapabilityOptions(TradingMode[]? applicableTradingModes)
: base("TestExchange", false, "TestOperation", [], applicableTradingModes)
{
}
}
private sealed class TestSharedApi : SharedApiBase, ITestCapability
{
public TestCapabilityOptions CapabilityOptions { get; }
public TestSharedApi(TradingMode[] apiTradingModes, TradingMode[]? capabilityTradingModes)
: this(apiTradingModes, capabilityTradingModes, null)
{
}
public TestSharedApi(
TradingMode[] apiTradingModes,
TradingMode[]? capabilityTradingModes,
TradingMode[]? applicableTradingModes)
: base(
SharedTransport.Rest,
"TestExchange",
apiTradingModes,
() => false,
(baseAsset, quoteAsset, tradingMode, deliverDate) => $"{baseAsset}{quoteAsset}")
{
var options = new TestCapabilityOptions(applicableTradingModes)
{
SupportedTradingModeOverrides = capabilityTradingModes
};
SetCapabilities(options);
CapabilityOptions = options;
}
public override SharedClientInfo Discover() => new();
}
private sealed class TestOptionsHost : SharedApiBase
{
public TestOptionsHost(TradingMode[] apiTradingModes, CapabilityOptions capabilityOptions)
: base(
SharedTransport.Rest,
"TestExchange",
apiTradingModes,
() => false,
(baseAsset, quoteAsset, tradingMode, deliverDate) => $"{baseAsset}{quoteAsset}")
{
SetCapabilities(capabilityOptions);
}
public override SharedClientInfo Discover() => new();
}
private sealed class TestSharedApiClient : SharedApiClientBase
{
public TestSharedApiClient(params ISharedApiCapability[] sharedApis)
: base([SharedTransport.Rest, SharedTransport.Socket], sharedApis)
{
}
}
}
}
@@ -0,0 +1,89 @@
using CryptoExchange.Net.SharedApis;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace CryptoExchange.Net.UnitTests
{
[TestFixture]
internal class SharedCapabilitiesTests
{
[Test]
public void AllSharedApiCapabilities_ShouldBeListedInSharedCapabilities()
{
var markerTypes = new[]
{
typeof(ISharedApiCapability),
typeof(ISharedRest),
typeof(ISharedSocket),
typeof(ISharedSubscription)
};
var expectedCapabilities = typeof(ISharedApiCapability).Assembly
.GetTypes()
.Where(x => x.IsInterface
&& typeof(ISharedApiCapability).IsAssignableFrom(x)
&& !markerTypes.Contains(x))
.OrderBy(x => x.FullName)
.ToArray();
var listedCapabilities = GetTypeAndNestedTypes(typeof(SharedCapabilities))
.SelectMany(x => x.GetProperties(
BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
.SelectMany(x => x.PropertyType.GetGenericArguments())
.Where(x => x.IsInterface
&& typeof(ISharedApiCapability).IsAssignableFrom(x))
.ToArray();
var missingCapabilities = expectedCapabilities
.Except(listedCapabilities)
.Select(x => x.Name)
.ToArray();
var unknownCapabilities = listedCapabilities
.Except(expectedCapabilities)
.Select(x => x.Name)
.ToArray();
var duplicateCapabilities = listedCapabilities
.GroupBy(x => x)
.Where(x => x.Count() > 1)
.Select(x => x.Key.Name)
.ToArray();
Assert.Multiple(() =>
{
Assert.That(
missingCapabilities,
Is.Empty,
$"Capabilities missing from SharedCapabilities: " +
string.Join(", ", missingCapabilities));
Assert.That(
unknownCapabilities,
Is.Empty,
$"Unknown capabilities listed in SharedCapabilities: " +
string.Join(", ", unknownCapabilities));
Assert.That(
duplicateCapabilities,
Is.Empty,
$"Capabilities listed multiple times in SharedCapabilities: " +
string.Join(", ", duplicateCapabilities));
});
}
private static IEnumerable<Type> GetTypeAndNestedTypes(Type type)
{
yield return type;
foreach (var nestedType in type.GetNestedTypes(BindingFlags.Public))
{
foreach (var result in GetTypeAndNestedTypes(nestedType))
yield return result;
}
}
}
}
@@ -91,6 +91,66 @@ namespace CryptoExchange.Net.UnitTests
string.Join(Environment.NewLine, failures));
}
[Test]
public void RequiredExchangeParameter_ShouldAcceptNameOrAnyAlias()
{
const string exchange = "TestExchange";
var options = new GetTickerOptions(exchange)
{
ExchangeParameterRules =
[
ExchangeParameterRule.Required(
"Parameter",
"Test parameter",
1,
"Alias1",
"Alias2")
]
};
var missingResult = options.ValidateRequest(null, null, [TradingMode.Spot]);
var nameResult = options.ValidateRequest(
new ExchangeParameters(new ExchangeParameter(exchange, "Parameter", 1)),
null,
[TradingMode.Spot]);
var firstAliasResult = options.ValidateRequest(
new ExchangeParameters(new ExchangeParameter(exchange, "Alias1", 1)),
null,
[TradingMode.Spot]);
var secondAliasResult = options.ValidateRequest(
new ExchangeParameters(new ExchangeParameter(exchange, "Alias2", 1)),
null,
[TradingMode.Spot]);
Assert.Multiple(() =>
{
Assert.That(missingResult, Is.Not.Null);
Assert.That(nameResult, Is.Null);
Assert.That(firstAliasResult, Is.Null);
Assert.That(secondAliasResult, Is.Null);
});
}
[Test]
public void RequiredExchangeParameterWithoutAliases_ShouldBeRequired()
{
const string exchange = "TestExchange";
var options = new GetTickerOptions(exchange)
{
ExchangeParameterRules =
[
ExchangeParameterRule.Required(
"Parameter",
"Test parameter",
1)
]
};
var result = options.ValidateRequest(null, null, [TradingMode.Spot]);
Assert.That(result, Is.Not.Null);
}
private static Type? GetGenericOptionsType(Type optionsType)
{
for (var type = optionsType; type != null; type = type.BaseType)
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Catalog of Shared API capability references.
/// </summary>
public static partial class SharedCapabilities
{
/// <summary>
/// Asset capabilities.
/// </summary>
public static class Assets
{
/// <summary>
/// Get asset capability.
/// </summary>
public static SharedRestCapability<IGetAsset, IGetAssetRest> GetAsset { get; } = new();
/// <summary>
/// Get all assets capability.
/// </summary>
public static SharedRestCapability<IGetAllAssets, IGetAllAssetsRest> GetAllAssets { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Balance capabilities.
/// </summary>
public static class Balances
{
/// <summary>
/// Get balances capability.
/// </summary>
public static SharedRestCapability<IGetBalances, IGetBalancesRest> GetBalances { get; } = new();
/// <summary>
/// Subscribe to balance updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeBalancesSocket> SubscribeBalances { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Deposit capabilities.
/// </summary>
public static class Deposits
{
/// <summary>
/// Get deposit addresses capability.
/// </summary>
public static SharedRestCapability<IGetDepositAddresses, IGetDepositAddressesRest> GetDepositAddresses { get; } = new();
/// <summary>
/// Get deposit history capability.
/// </summary>
public static SharedRestCapability<IGetDepositHistory, IGetDepositHistoryRest> GetDepositHistory { get; } = new();
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Fee capabilities.
/// </summary>
public static class Fees
{
/// <summary>
/// Get fees capability.
/// </summary>
public static SharedRestCapability<IGetFees, IGetFeesRest> GetFees { get; } = new();
}
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Funding capabilities.
/// </summary>
public static class Funding
{
/// <summary>
/// Get current funding information capability.
/// </summary>
public static SharedRestCapability<IGetFundingInfo, IGetFundingInfoRest> GetFundingInfo { get; } = new();
/// <summary>
/// Get funding rate history capability.
/// </summary>
public static SharedRestCapability<IGetFundingRateHistory, IGetFundingRateHistoryRest> GetFundingRateHistory { get; } = new();
/// <summary>
/// Get user funding history capability.
/// </summary>
public static SharedRestCapability<IGetUserFundingHistory, IGetUserFundingHistoryRest> GetUserFundingHistory { get; } = new();
}
}
}
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Index price capabilities.
/// </summary>
public static class IndexPrices
{
/// <summary>
/// Get an index price capability.
/// </summary>
public static SharedRestCapability<IGetIndexPrice, IGetIndexPriceRest> GetIndexPrice { get; } = new();
/// <summary>
/// Get all index prices capability.
/// </summary>
public static SharedRestCapability<IGetAllIndexPrices, IGetAllIndexPricesRest> GetAllIndexPrices { get; } = new();
/// <summary>
/// Subscribe to index price updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeIndexPriceSocket> SubscribeIndexPrice { get; } = new();
}
}
}
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Kline capabilities.
/// </summary>
public static class Klines
{
/// <summary>
/// Get klines capability.
/// </summary>
public static SharedRestCapability<IGetKlines, IGetKlinesRest> GetKlines { get; } = new();
/// <summary>
/// Get mark price klines capability.
/// </summary>
public static SharedRestCapability<IGetMarkPriceKlines, IGetMarkPriceKlinesRest> GetMarkPriceKlines { get; } = new();
/// <summary>
/// Get index price klines capability.
/// </summary>
public static SharedRestCapability<IGetIndexPriceKlines, IGetIndexPriceKlinesRest> GetIndexPriceKlines { get; } = new();
/// <summary>
/// Subscribe to kline updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeKlinesSocket> SubscribeKlines { get; } = new();
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Ledger capabilities.
/// </summary>
public static class Ledger
{
/// <summary>
/// Get ledger entries capability.
/// </summary>
public static SharedRestCapability<IGetLedger, IGetLedgerRest> GetLedger { get; } = new();
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Leverage capabilities.
/// </summary>
public static class Leverage
{
/// <summary>
/// Get leverage capability.
/// </summary>
public static SharedRestCapability<IGetLeverage, IGetLeverageRest> GetLeverage { get; } = new();
/// <summary>
/// Set leverage capability.
/// </summary>
public static SharedRestCapability<ISetLeverage, ISetLeverageRest> SetLeverage { get; } = new();
/// <summary>
/// Get leverage tiers capability.
/// </summary>
public static SharedRestCapability<IGetLeverageTiers, IGetLeverageTiersRest> GetLeverageTiers { get; } = new();
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Mark price capabilities.
/// </summary>
public static class MarkPrices
{
/// <summary>
/// Get a mark price capability.
/// </summary>
public static SharedRestCapability<IGetMarkPrice, IGetMarkPriceRest> GetMarkPrice { get; } = new();
/// <summary>
/// Get all mark prices capability.
/// </summary>
public static SharedRestCapability<IGetAllMarkPrices, IGetAllMarkPricesRest> GetAllMarkPrices { get; } = new();
/// <summary>
/// Subscribe to mark price updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeMarkPriceSocket> SubscribeMarkPrice { get; } = new();
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Open interest capabilities.
/// </summary>
public static class OpenInterest
{
/// <summary>
/// Get open interest capability.
/// </summary>
public static SharedRestCapability<IGetOpenInterest, IGetOpenInterestRest> GetOpenInterest { get; } = new();
}
}
}
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Order book capabilities.
/// </summary>
public static class OrderBooks
{
/// <summary>
/// Get an order book capability.
/// </summary>
public static SharedRestCapability<IGetOrderBook, IGetOrderBookRest> GetOrderBook { get; } = new();
/// <summary>
/// Get a book ticker capability.
/// </summary>
public static SharedRestCapability<IGetBookTicker, IGetBookTickerRest> GetBookTicker { get; } = new();
/// <summary>
/// Subscribe to order book updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeOrderBookSocket> SubscribeOrderBook { get; } = new();
/// <summary>
/// Subscribe to incremental order book updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeIncrementalOrderBookSocket> SubscribeIncrementalOrderBook { get; } = new();
}
}
}
@@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Order capabilities.
/// </summary>
public static class Orders
{
/// <summary>
/// Spot order capabilities.
/// </summary>
public static class Spot
{
/// <summary>
/// Place a spot order capability.
/// </summary>
public static SharedRestSocketCapability<IPlaceSpotOrder, IPlaceSpotOrderRest, IPlaceSpotOrderSocket> PlaceOrder { get; } = new();
/// <summary>
/// Place multiple spot orders capability.
/// </summary>
public static SharedRestSocketCapability<IPlaceMultipleSpotOrders, IPlaceMultipleSpotOrdersRest, IPlaceMultipleSpotOrdersSocket> PlaceMultipleOrders { get; } = new();
/// <summary>
/// Edit a spot order capability.
/// </summary>
public static SharedRestSocketCapability<IEditSpotOrder, IEditSpotOrderRest, IEditSpotOrderSocket> EditOrder { get; } = new();
/// <summary>
/// Edit a spot order by client order id capability.
/// </summary>
public static SharedRestSocketCapability<IEditSpotOrderByClientOrderId, IEditSpotOrderByClientOrderIdRest, IEditSpotOrderByClientOrderIdSocket> EditOrderByClientOrderId { get; } = new();
/// <summary>
/// Cancel a spot order capability.
/// </summary>
public static SharedRestSocketCapability<ICancelSpotOrder, ICancelSpotOrderRest, ICancelSpotOrderSocket> CancelOrder { get; } = new();
/// <summary>
/// Cancel a spot order by client order id capability.
/// </summary>
public static SharedRestSocketCapability<ICancelSpotOrderByClientOrderId, ICancelSpotOrderByClientOrderIdRest, ICancelSpotOrderByClientOrderIdSocket> CancelOrderByClientOrderId { get; } = new();
/// <summary>
/// Cancel all spot orders capability.
/// </summary>
public static SharedRestSocketCapability<ICancelAllSpotOrders, ICancelAllSpotOrdersRest, ICancelAllSpotOrdersSocket> CancelAllOrders { get; } = new();
/// <summary>
/// Cancel all spot orders for a symbol capability.
/// </summary>
public static SharedRestSocketCapability<ICancelAllSpotSymbolOrders, ICancelAllSpotSymbolOrdersRest, ICancelAllSpotSymbolOrdersSocket> CancelAllSymbolOrders { get; } = new();
/// <summary>
/// Get a spot order capability.
/// </summary>
public static SharedRestCapability<IGetSpotOrder, IGetSpotOrderRest> GetOrder { get; } = new();
/// <summary>
/// Get a spot order by client order id capability.
/// </summary>
public static SharedRestCapability<IGetSpotOrderByClientOrderId, IGetSpotOrderByClientOrderIdRest> GetOrderByClientOrderId { get; } = new();
/// <summary>
/// Get open spot orders capability.
/// </summary>
public static SharedRestCapability<IGetOpenSpotOrders, IGetOpenSpotOrdersRest> GetOpenOrders { get; } = new();
/// <summary>
/// Get closed spot orders capability.
/// </summary>
public static SharedRestCapability<IGetClosedSpotOrders, IGetClosedSpotOrdersRest> GetClosedOrders { get; } = new();
/// <summary>
/// Subscribe to spot order updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeSpotOrdersSocket> SubscribeOrders { get; } = new();
}
/// <summary>
/// Futures order capabilities.
/// </summary>
public static class Futures
{
/// <summary>
/// Place a futures order capability.
/// </summary>
public static SharedRestSocketCapability<IPlaceFuturesOrder, IPlaceFuturesOrderRest, IPlaceFuturesOrderSocket> PlaceOrder { get; } = new();
/// <summary>
/// Place multiple futures orders capability.
/// </summary>
public static SharedRestSocketCapability<IPlaceMultipleFuturesOrders, IPlaceMultipleFuturesOrdersRest, IPlaceMultipleFuturesOrdersSocket> PlaceMultipleOrders { get; } = new();
/// <summary>
/// Edit a futures order capability.
/// </summary>
public static SharedRestSocketCapability<IEditFuturesOrder, IEditFuturesOrderRest, IEditFuturesOrderSocket> EditOrder { get; } = new();
/// <summary>
/// Edit a futures order by client order id capability.
/// </summary>
public static SharedRestSocketCapability<IEditFuturesOrderByClientOrderId, IEditFuturesOrderByClientOrderIdRest, IEditFuturesOrderByClientOrderIdSocket> EditOrderByClientOrderId { get; } = new();
/// <summary>
/// Cancel a futures order capability.
/// </summary>
public static SharedRestSocketCapability<ICancelFuturesOrder, ICancelFuturesOrderRest, ICancelFuturesOrderSocket> CancelOrder { get; } = new();
/// <summary>
/// Cancel a futures order by client order id capability.
/// </summary>
public static SharedRestSocketCapability<ICancelFuturesOrderByClientOrderId, ICancelFuturesOrderByClientOrderIdRest, ICancelFuturesOrderByClientOrderIdSocket> CancelOrderByClientOrderId { get; } = new();
/// <summary>
/// Cancel all futures orders capability.
/// </summary>
public static SharedRestSocketCapability<ICancelAllFuturesOrders, ICancelAllFuturesOrdersRest, ICancelAllFuturesOrdersSocket> CancelAllOrders { get; } = new();
/// <summary>
/// Cancel all futures orders for a symbol capability.
/// </summary>
public static SharedRestSocketCapability<ICancelAllFuturesSymbolOrders, ICancelAllFuturesSymbolOrdersRest, ICancelAllFuturesSymbolOrdersSocket> CancelAllSymbolOrders { get; } = new();
/// <summary>
/// Get a futures order capability.
/// </summary>
public static SharedRestCapability<IGetFuturesOrder, IGetFuturesOrderRest> GetOrder { get; } = new();
/// <summary>
/// Get a futures order by client order id capability.
/// </summary>
public static SharedRestCapability<IGetFuturesOrderByClientOrderId, IGetFuturesOrderByClientOrderIdRest> GetOrderByClientOrderId { get; } = new();
/// <summary>
/// Get open futures orders capability.
/// </summary>
public static SharedRestCapability<IGetOpenFuturesOrders, IGetOpenFuturesOrdersRest> GetOpenOrders { get; } = new();
/// <summary>
/// Get closed futures orders capability.
/// </summary>
public static SharedRestCapability<IGetClosedFuturesOrders, IGetClosedFuturesOrdersRest> GetClosedOrders { get; } = new();
/// <summary>
/// Subscribe to futures order updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeFuturesOrdersSocket> SubscribeOrders { get; } = new();
}
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Position mode capabilities.
/// </summary>
public static class PositionMode
{
/// <summary>
/// Get position mode capability.
/// </summary>
public static SharedRestCapability<IGetPositionMode, IGetPositionModeRest> GetPositionMode { get; } = new();
/// <summary>
/// Set position mode capability.
/// </summary>
public static SharedRestCapability<ISetPositionMode, ISetPositionModeRest> SetPositionMode { get; } = new();
}
}
}
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Position capabilities.
/// </summary>
public static class Positions
{
/// <summary>
/// Get positions capability.
/// </summary>
public static SharedRestCapability<IGetPositions, IGetPositionsRest> GetPositions { get; } = new();
/// <summary>
/// Get position history capability.
/// </summary>
public static SharedRestCapability<IGetPositionHistory, IGetPositionHistoryRest> GetPositionHistory { get; } = new();
/// <summary>
/// Close a full position capability.
/// </summary>
public static SharedRestCapability<ICloseFullPosition, ICloseFullPositionRest> CloseFullPosition { get; } = new();
/// <summary>
/// Subscribe to position updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribePositionsSocket> SubscribePositions { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Symbol capabilities.
/// </summary>
public static class Symbols
{
/// <summary>
/// Get spot symbols capability.
/// </summary>
public static SharedRestCapability<IGetSpotSymbols, IGetSpotSymbolsRest> GetSpotSymbols { get; } = new();
/// <summary>
/// Get futures symbols capability.
/// </summary>
public static SharedRestCapability<IGetFuturesSymbols, IGetFuturesSymbolsRest> GetFuturesSymbols { get; } = new();
}
}
}
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Ticker capabilities.
/// </summary>
public static class Tickers
{
/// <summary>
/// Get a ticker capability.
/// </summary>
public static SharedRestCapability<IGetTicker, IGetTickerRest> GetTicker { get; } = new();
/// <summary>
/// Get all tickers capability.
/// </summary>
public static SharedRestCapability<IGetAllTickers, IGetAllTickersRest> GetAllTickers { get; } = new();
/// <summary>
/// Subscribe to ticker updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeTickerSocket> SubscribeTicker { get; } = new();
/// <summary>
/// Subscribe to all ticker updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeAllTickersSocket> SubscribeAllTickers { get; } = new();
/// <summary>
/// Subscribe to book ticker updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeBookTickerSocket> SubscribeBookTicker { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Take profit and stop loss capabilities.
/// </summary>
public static class TpSl
{
/// <summary>
/// Set futures take profit or stop loss capability.
/// </summary>
public static SharedRestCapability<ISetFuturesTpSl, ISetFuturesTpSlRest> SetFuturesTpSl { get; } = new();
/// <summary>
/// Cancel futures take profit or stop loss capability.
/// </summary>
public static SharedRestCapability<ICancelFuturesTpSl, ICancelFuturesTpSlRest> CancelFuturesTpSl { get; } = new();
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Public trade capabilities.
/// </summary>
public static class Trades
{
/// <summary>
/// Get recent trades capability.
/// </summary>
public static SharedRestCapability<IGetRecentTrades, IGetRecentTradesRest> GetRecentTrades { get; } = new();
/// <summary>
/// Get trade history capability.
/// </summary>
public static SharedRestCapability<IGetTradeHistory, IGetTradeHistoryRest> GetTradeHistory { get; } = new();
/// <summary>
/// Subscribe to trade updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeTradesSocket> SubscribeTrades { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Transfer capabilities.
/// </summary>
public static class Transfers
{
/// <summary>
/// Transfer assets capability.
/// </summary>
public static SharedRestCapability<ITransfer, ITransferRest> Transfer { get; } = new();
/// <summary>
/// Get transfer history capability.
/// </summary>
public static SharedRestCapability<IGetTransferHistory, IGetTransferHistoryRest> GetTransferHistory { get; } = new();
}
}
}
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Trigger order capabilities.
/// </summary>
public static class TriggerOrders
{
/// <summary>
/// Spot trigger order capabilities.
/// </summary>
public static class Spot
{
/// <summary>
/// Place a spot trigger order capability.
/// </summary>
public static SharedRestCapability<IPlaceSpotTriggerOrder, IPlaceSpotTriggerOrderRest> PlaceOrder { get; } = new();
/// <summary>
/// Get a spot trigger order capability.
/// </summary>
public static SharedRestCapability<IGetSpotTriggerOrder, IGetSpotTriggerOrderRest> GetOrder { get; } = new();
/// <summary>
/// Cancel a spot trigger order capability.
/// </summary>
public static SharedRestCapability<ICancelSpotTriggerOrder, ICancelSpotTriggerOrderRest> CancelOrder { get; } = new();
}
/// <summary>
/// Futures trigger order capabilities.
/// </summary>
public static class Futures
{
/// <summary>
/// Place a futures trigger order capability.
/// </summary>
public static SharedRestCapability<IPlaceFuturesTriggerOrder, IPlaceFuturesTriggerOrderRest> PlaceOrder { get; } = new();
/// <summary>
/// Get a futures trigger order capability.
/// </summary>
public static SharedRestCapability<IGetFuturesTriggerOrder, IGetFuturesTriggerOrderRest> GetOrder { get; } = new();
/// <summary>
/// Cancel a futures trigger order capability.
/// </summary>
public static SharedRestCapability<ICancelFuturesTriggerOrder, ICancelFuturesTriggerOrderRest> CancelOrder { get; } = new();
}
}
}
}
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// User trade capabilities.
/// </summary>
public static class UserTrades
{
/// <summary>
/// Get trades for a spot order capability.
/// </summary>
public static SharedRestCapability<IGetSpotOrderTrades, IGetSpotOrderTradesRest> GetSpotOrderTrades { get; } = new();
/// <summary>
/// Get spot user trade history capability.
/// </summary>
public static SharedRestCapability<IGetSpotUserTradeHistory, IGetSpotUserTradeHistoryRest> GetSpotTradeHistory { get; } = new();
/// <summary>
/// Get trades for a futures order capability.
/// </summary>
public static SharedRestCapability<IGetFuturesOrderTrades, IGetFuturesOrderTradesRest> GetFuturesOrderTrades { get; } = new();
/// <summary>
/// Get futures user trade history capability.
/// </summary>
public static SharedRestCapability<IGetFuturesUserTradeHistory, IGetFuturesUserTradeHistoryRest> GetFuturesTradeHistory { get; } = new();
/// <summary>
/// Subscribe to user trade updates capability.
/// </summary>
public static SharedCapabilityReference<ISubscribeUserTradesSocket> SubscribeUserTrades { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
public static partial class SharedCapabilities
{
/// <summary>
/// Withdrawal capabilities.
/// </summary>
public static class Withdrawals
{
/// <summary>
/// Withdraw assets capability.
/// </summary>
public static SharedRestCapability<IWithdraw, IWithdrawRest> Withdraw { get; } = new();
/// <summary>
/// Get withdrawal history capability.
/// </summary>
public static SharedRestCapability<IGetWithdrawalHistory, IGetWithdrawalHistoryRest> GetWithdrawalHistory { get; } = new();
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Strongly typed reference to a Shared API capability.
/// </summary>
public class SharedCapabilityReference<T>
where T : ISharedApiCapability
{
/// <summary>
/// Capability interface type.
/// </summary>
public Type CapabilityType => typeof(T);
internal SharedCapabilityReference()
{
}
/// <inheritdoc />
public override string ToString() => typeof(T).Name;
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Capability lookup result
/// </summary>
/// <typeparam name="T">Capability type</typeparam>
public class SharedCapabilityResolution<T>
where T : ISharedApiCapability
{
/// <summary>
/// The capability
/// </summary>
public T Capability { get; }
/// <summary>
/// The capability options
/// </summary>
public CapabilityOptions Options { get; }
internal SharedCapabilityResolution(
T capability,
CapabilityOptions options)
{
Capability = capability;
Options = options;
}
}
}
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// References for a capability available through REST.
/// </summary>
public sealed class SharedRestCapability<TCapability, TRest>
: SharedCapabilityReference<TCapability>
where TCapability : ISharedApiCapability
where TRest : TCapability, ISharedRest
{
/// <summary>
/// Transport-agnostic capability.
/// </summary>
public SharedCapabilityReference<TCapability> Any { get; } = new();
/// <summary>
/// REST capability.
/// </summary>
public SharedCapabilityReference<TRest> Rest { get; } = new();
internal SharedRestCapability()
{
}
}
}
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// References for a capability available through REST and WebSocket.
/// </summary>
public sealed class SharedRestSocketCapability<TCapability, TRest, TSocket>
: SharedCapabilityReference<TCapability>
where TCapability : ISharedApiCapability
where TRest : TCapability, ISharedRest
where TSocket : TCapability, ISharedSocket
{
/// <summary>
/// REST capability.
/// </summary>
public SharedCapabilityReference<TRest> Rest { get; } = new();
/// <summary>
/// WebSocket capability.
/// </summary>
public SharedCapabilityReference<TSocket> Socket { get; } = new();
internal SharedRestSocketCapability()
{
}
}
}
@@ -23,12 +23,6 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc />
public override Type CapabilityType => typeof(IFuturesOrderRestClient);
/// <inheritdoc />
public virtual RequestParameterRuleOverride[] ParameterRuleOverwrites
{
set => SetRequestParameters(value);
}
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<ClosePositionRequest>.Required(x => x.Symbol, "The symbol of the position to close", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
@@ -41,7 +35,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public ClosePositionOptions(string exchange, bool authenticated) : base(exchange, nameof(IFuturesOrderRestClient.ClosePositionAsync), true, _defaultParameterRules)
public ClosePositionOptions(string exchange, bool authenticated) : base(exchange, nameof(IFuturesOrderRestClient.ClosePositionAsync), true, _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
@@ -37,7 +37,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Use Capabilities instead
/// </summary>
[Obsolete("Use Capabilities instead")]
#pragma warning disable CS0618 // Type or member is obsolete
public EndpointOptions[] Features
{
get => _capabilities
@@ -46,6 +46,7 @@ namespace CryptoExchange.Net.SharedApis
init => _capabilities = value;
}
#pragma warning restore CS0618 // Type or member is obsolete
/// <summary>
/// Client capabilities
@@ -27,6 +27,7 @@ namespace CryptoExchange.Net.SharedApis
public ExchangeParameterDescription[] ExchangeParameterRules { get; set; } = [];
private readonly RequestParameterDescription[] _defaultParameterRules;
private readonly TradingMode[]? _applicableTradingModes;
/// <summary>
@@ -84,6 +85,26 @@ namespace CryptoExchange.Net.SharedApis
/// </summary>
public bool Supported { get; set; } = true;
/// <summary>
/// Trading modes supported by this capability on the containing Shared API.
/// </summary>
public TradingMode[] SupportedTradingModes { get; private set; } = [];
/// <summary>
/// Implementation-specific overrides for the default request parameter rules.
/// </summary>
public RequestParameterRuleOverride[] ParameterRuleOverrides
{
init
{
RequestParameterRules = CombineParameters(_defaultParameterRules, value);
}
}
/// <summary>
/// Optional implementation-specific restriction of the trading modes supported by this capability.
/// The final supported modes are the intersection of this value, the modes applicable to the capability,
/// and the modes supported by the containing Shared API.
/// </summary>
public TradingMode[]? SupportedTradingModeOverrides { private get; init; }
/// <summary>
/// Description of the endpoint
/// </summary>
public abstract string Description { get; }
@@ -99,7 +120,8 @@ namespace CryptoExchange.Net.SharedApis
string exchange,
string operationName,
bool needAuthentication,
IEnumerable<RequestParameterDescription> defaultParameterRules)
IEnumerable<RequestParameterDescription> defaultParameterRules,
IEnumerable<TradingMode>? applicableTradingModes = null)
{
Exchange = exchange;
OperationName = operationName;
@@ -112,15 +134,19 @@ namespace CryptoExchange.Net.SharedApis
RequestParameterRules = CombineParameters(
_defaultParameterRules,
Array.Empty<RequestParameterRuleOverride>());
_applicableTradingModes = applicableTradingModes?.Distinct().ToArray();
}
/// <summary>
/// Set request parameter overrides for this instance
/// </summary>
/// <param name="overrides">The parameter overrides</param>
protected void SetRequestParameters(IEnumerable<RequestParameterRuleOverride> overrides)
internal void InitializeSupportedTradingModes(TradingMode[] apiSupportedTradingModes)
{
RequestParameterRules = CombineParameters(_defaultParameterRules, overrides);
IEnumerable<TradingMode> supportedModes = apiSupportedTradingModes;
if (_applicableTradingModes != null)
supportedModes = supportedModes.Intersect(_applicableTradingModes);
if (SupportedTradingModeOverrides != null)
supportedModes = supportedModes.Intersect(SupportedTradingModeOverrides);
SupportedTradingModes = supportedModes.Distinct().ToArray();
}
private RequestParameterDescription[] CombineParameters(
@@ -167,8 +193,9 @@ namespace CryptoExchange.Net.SharedApis
foreach (var param in RequiredExchangeParameters)
{
if (ExchangeParameters.HasValue(exchangeParameters, Exchange, param.Name, param.ValueType) != true
&& param.Aliases.Any(x => ExchangeParameters.HasValue(exchangeParameters, Exchange, x, param.ValueType) != true))
var hasValue = ExchangeParameters.HasValue(exchangeParameters, Exchange, param.Name, param.ValueType)
|| param.Aliases.Any(x => ExchangeParameters.HasValue(exchangeParameters, Exchange, x, param.ValueType));
if (!hasValue)
{
if (param.Aliases.Length == 0)
return ArgumentError.Invalid(param.Name, $"Exchange parameter `{param.Name}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}");
@@ -234,17 +261,16 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc />
public override Type CapabilityType => typeof(TCapability);
/// <inheritdoc />
public virtual RequestParameterRuleOverride[] ParameterRuleOverwrites
{
set => SetRequestParameters(value);
}
/// <summary>
/// ctor
/// </summary>
public CapabilityOptions(string exchange, bool needsAuthentication, string requestName, IEnumerable<RequestParameterDescription> defaultParameterRules)
: base(exchange, requestName, needsAuthentication, defaultParameterRules)
public CapabilityOptions(
string exchange,
bool needsAuthentication,
string requestName,
IEnumerable<RequestParameterDescription> defaultParameterRules,
IEnumerable<TradingMode>? applicableTradingModes = null)
: base(exchange, requestName, needsAuthentication, defaultParameterRules, applicableTradingModes)
{
}
@@ -307,7 +333,10 @@ namespace CryptoExchange.Net.SharedApis
}
return ValidateRequest(request.ExchangeParameters, request.TradingMode, client.SupportedTradingModes);
return ValidateRequest(
request.ExchangeParameters,
request.TradingMode,
SupportedTradingModes);
}
}
}
@@ -31,8 +31,9 @@ namespace CryptoExchange.Net.SharedApis
string exchange,
string operationName,
bool needsAuthentication,
IEnumerable<RequestParameterDescription> defaultParameterRules)
: base(exchange, operationName, needsAuthentication, defaultParameterRules)
IEnumerable<RequestParameterDescription> defaultParameterRules,
IEnumerable<TradingMode>? applicableTradingModes = null)
: base(exchange, operationName, needsAuthentication, defaultParameterRules, applicableTradingModes)
{
}
}
@@ -52,7 +52,8 @@ namespace CryptoExchange.Net.SharedApis
int maxLimit,
bool needsAuthentication,
string requestName,
IEnumerable<RequestParameterDescription> defaultParameterRules) : base(exchange, needsAuthentication, requestName, defaultParameterRules)
IEnumerable<RequestParameterDescription> defaultParameterRules,
IEnumerable<TradingMode>? applicableTradingModes = null) : base(exchange, needsAuthentication, requestName, defaultParameterRules, applicableTradingModes)
{
SupportsAscending = supportsAscending;
SupportsDescending = supportsDescending;
@@ -0,0 +1,24 @@
namespace CryptoExchange.Net.SharedApis
{
internal static class SharedTradingModeSets
{
internal static TradingMode[] Spot { get; } =
[
TradingMode.Spot
];
internal static TradingMode[] Futures { get; } =
[
TradingMode.PerpetualLinear,
TradingMode.DeliveryLinear,
TradingMode.PerpetualInverse,
TradingMode.DeliveryInverse
];
internal static TradingMode[] Perpetual { get; } =
[
TradingMode.PerpetualLinear,
TradingMode.PerpetualInverse
];
}
}
@@ -48,6 +48,9 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc />
protected void SetCapabilities(params CapabilityOptions[] capabilities)
{
foreach (var capability in capabilities)
capability.InitializeSupportedTradingModes(SupportedTradingModes);
_capabilities = Array.AsReadOnly(capabilities);
}
@@ -0,0 +1,205 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Base interface for Shared API clients
/// </summary>
public interface ISharedApiClientBase
{
/// <summary>
/// Shared API's available on this client
/// </summary>
IReadOnlyList<ISharedApi> SharedApis { get; }
/// <summary>
/// Get all capabilities matching the provided capability type.
/// Example:
/// <code>client.GetCapability&lt;IPlaceSpotOrder&gt;()</code>
/// </summary>
/// <typeparam name="T">The capability type</typeparam>
/// <param name="tradingMode">Filter by supported trading mode</param>
/// <param name="transport">Filter by transport method</param>
IReadOnlyList<SharedCapabilityResolution<T>> GetCapabilities<T>(TradingMode? tradingMode = null, SharedTransport? transport = null)
where T : ISharedApiCapability;
/// <summary>
/// Get the requested capability type. If more than one implementation is available the first one is returned.
/// In this case prefer using <see cref="GetCapability{T}(TradingMode, SharedTransport?)"/> to select a specific trading mode.
/// Example:
/// <code>client.GetCapability&lt;IPlaceSpotOrder&gt;(SharedTransport.Socket)</code>
/// </summary>
/// <typeparam name="T">The capability type</typeparam>
/// <param name="transport">The transport method</param>
/// <returns>The requested capability type or null if not found</returns>
SharedCapabilityResolution<T>? GetCapability<T>(SharedTransport? transport = null)
where T : ISharedApiCapability;
/// <summary>
/// Get the requested capability type for a specific trading mode.
/// Example:
/// <code>client.GetCapability&lt;IPlaceFuturesOrder&gt;(TradingMode.PerpetualLinear, SharedTransport.Rest)</code>
/// </summary>
/// <typeparam name="T">The capability type</typeparam>
/// <param name="tradingMode">The trading mode</param>
/// <param name="transport">The transport method</param>
/// <returns>The requested capability type or null if not found</returns>
SharedCapabilityResolution<T>? GetCapability<T>(TradingMode tradingMode, SharedTransport? transport = null)
where T : ISharedApiCapability;
/// <summary>
/// Get the capability matching the provided capability reference. Get a capability reference using <see cref="SharedCapabilities"/>.
/// If more than one implementation is available the first one is returned.<br />
/// Example:
/// <code>client.GetCapability(SharedCapabilities.Orders.Spot.PlaceOrder.Rest)</code>
/// </summary>
/// <typeparam name="T">The capability type</typeparam>
/// <param name="capability">The capability reference</param>
/// <returns>The requested capability type or null if not found</returns>
SharedCapabilityResolution<T>? GetCapability<T>(SharedCapabilityReference<T> capability)
where T : ISharedApiCapability;
/// <summary>
/// Get the capability matching the provided capability reference for a specific trading mode. Get a capability reference using <see cref="SharedCapabilities"/>.
/// If more than one implementation is available the first one is returned.<br />
/// Example:
/// <code>client.GetCapability(SharedCapabilities.Orders.Futures.PlaceOrder.Rest, TradingMode.PerpetualLinear)</code>
/// </summary>
/// <typeparam name="T">The capability type</typeparam>
/// <param name="capability">The capability reference</param>
/// <param name="tradingMode">The trading mode</param>
/// <returns>The requested capability type or null if not found</returns>
SharedCapabilityResolution<T>? GetCapability<T>(SharedCapabilityReference<T> capability, TradingMode tradingMode)
where T : ISharedApiCapability;
}
/// <summary>
/// Base client for Shared API clients
/// </summary>
public abstract class SharedApiClientBase : ISharedApiClientBase
{
private readonly ISharedApi[] _sharedApis;
private readonly SharedTransport[] _preferredTransports;
/// <inheritdoc />
public IReadOnlyList<ISharedApi> SharedApis => _sharedApis;
/// <summary>
/// ctor
/// </summary>
public SharedApiClientBase(
IEnumerable<SharedTransport> transportPreference,
params ISharedApi[] sharedApis)
{
_preferredTransports = transportPreference.Distinct().ToArray();
_sharedApis = sharedApis.Distinct().ToArray();
}
/// <inheritdoc />
public SharedCapabilityResolution<T>? GetCapability<T>(SharedTransport? transport = null)
where T : ISharedApiCapability
{
return GetCapabilityCore<T>(null, transport);
}
/// <inheritdoc />
public SharedCapabilityResolution<T>? GetCapability<T>(TradingMode tradingMode, SharedTransport? transport = null)
where T : ISharedApiCapability
{
return GetCapabilityCore<T>(tradingMode, transport);
}
/// <inheritdoc />
public SharedCapabilityResolution<T>? GetCapability<T>(SharedCapabilityReference<T> capability)
where T : ISharedApiCapability
{
return GetCapabilityCore<T>(null, null);
}
/// <inheritdoc />
public SharedCapabilityResolution<T>? GetCapability<T>(SharedCapabilityReference<T> capability, TradingMode tradingMode)
where T : ISharedApiCapability
{
return GetCapabilityCore<T>(tradingMode, null);
}
/// <inheritdoc />
public IReadOnlyList<SharedCapabilityResolution<T>> GetCapabilities<T>(
TradingMode? tradingMode = null,
SharedTransport? transport = null)
where T : ISharedApiCapability
{
var result = new List<SharedCapabilityResolution<T>>();
foreach (var sharedApi in _sharedApis)
{
if (sharedApi is not T capability)
continue;
if (transport != null && sharedApi.Transport != transport)
continue;
var options = GetMatchingOptions<T>(sharedApi, tradingMode);
if (options == null)
continue;
result.Add(new SharedCapabilityResolution<T>(
capability,
options));
}
// Preserve Shared API registration order within each transport.
return result
.OrderBy(x => GetTransportPriority(x.Capability.Transport))
.ToArray();
}
private SharedCapabilityResolution<T>? GetCapabilityCore<T>(
TradingMode? tradingMode,
SharedTransport? selectedTransport = null)
where T : ISharedApiCapability
{
return GetCapabilities<T>(tradingMode, selectedTransport)
.FirstOrDefault();
}
private static CapabilityOptions? GetMatchingOptions<T>(
ISharedApi sharedApi,
TradingMode? tradingMode)
where T : ISharedApiCapability
{
var requestedType = typeof(T);
return sharedApi.Capabilities
.Where(options =>
options.Supported
&& IsCapabilityTypeMatch(
requestedType,
options.CapabilityType)
&& (tradingMode == null
|| options.SupportedTradingModes.Contains(
tradingMode.Value)))
// Prefer options declared for the exact requested interface.
.OrderByDescending(options =>
options.CapabilityType == requestedType)
.FirstOrDefault();
}
private static bool IsCapabilityTypeMatch(
Type requestedType,
Type optionsCapabilityType)
{
return optionsCapabilityType.IsAssignableFrom(requestedType)
|| requestedType.IsAssignableFrom(optionsCapabilityType);
}
private int GetTransportPriority(SharedTransport transport)
{
var index = Array.IndexOf(_preferredTransports, transport);
return index == -1 ? int.MaxValue : index;
}
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting assets info
/// </summary>
public class GetAllAssetsOptions : CapabilityOptions<GetAssetsRequest, IGetAllAssetsRest>
public class GetAllAssetsOptions : CapabilityOptions<GetAssetsRequest, IGetAllAssets>
{
/// <inheritdoc />
public override string Description => "Retrieve basic info for all assets and the networks they support for withdrawals/deposits";
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting asset info
/// </summary>
public class GetAssetOptions : CapabilityOptions<GetAssetRequest, IGetAssetRest>
public class GetAssetOptions : CapabilityOptions<GetAssetRequest, IGetAsset>
{
/// <inheritdoc />
public override string Description => "Retrieve basic info for a single asset and networks it supports for withdrawals/deposits";
@@ -6,7 +6,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting a transfer
/// </summary>
public class GetBalancesOptions : CapabilityOptions<GetBalancesRequest, IGetBalancesRest>
public class GetBalancesOptions : CapabilityOptions<GetBalancesRequest, IGetBalances>
{
/// <inheritdoc />
public override string Description => "Retrieve account balances";
@@ -35,7 +35,7 @@ namespace CryptoExchange.Net.SharedApis
/// </summary>
public override Error? ValidateRequest(
GetBalancesRequest request,
IGetBalancesRest client)
IGetBalances client)
{
var error = base.ValidateRequest(request, client);
if (error != null)
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting deposit address
/// </summary>
public class GetDepositAddressesOptions : CapabilityOptions<GetDepositAddressesRequest, IGetDepositAddressesRest>
public class GetDepositAddressesOptions : CapabilityOptions<GetDepositAddressesRequest, IGetDepositAddresses>
{
/// <inheritdoc />
public override string Description => "Retrieve deposit addresses for an asset";
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting trading fee info
/// </summary>
public class GetFeeOptions : CapabilityOptions<GetFeeRequest, IGetFeesRest>
public class GetFeeOptions : CapabilityOptions<GetFeeRequest, IGetFees>
{
/// <inheritdoc />
public override string Description => "Retrieve trading fee information";
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetFundingInfoOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetFundingInfoRest.GetFundingInfoAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetFundingInfoRest.GetFundingInfoAsync), _defaultParameterRules, SharedTradingModeSets.Perpetual)
{
}
}
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetFundingRateHistoryOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetFundingRateHistoryRest.GetFundingRateHistoryAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetFundingRateHistoryRest.GetFundingRateHistoryAsync), _defaultParameterRules, SharedTradingModeSets.Perpetual)
{
}
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetUserFundingHistoryOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetUserFundingHistoryRest.GetUserFundingHistoryAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetUserFundingHistoryRest.GetUserFundingHistoryAsync), _defaultParameterRules, SharedTradingModeSets.Perpetual)
{
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting the index price
/// </summary>
public class GetAllIndexPricesOptions : CapabilityOptions<GetAllIndexPricesRequest, IGetAllIndexPricesRest>
public class GetAllIndexPricesOptions : CapabilityOptions<GetAllIndexPricesRequest, IGetAllIndexPrices>
{
/// <inheritdoc />
public override string Description => "Retrieve the index prices for all futures symbols";
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetAllIndexPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllIndexPricesRest.GetAllIndexPricesAsync), _defaultParameterRules)
public GetAllIndexPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllIndexPricesRest.GetAllIndexPricesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting the index price
/// </summary>
public class GetIndexPriceOptions : CapabilityOptions<GetIndexPriceRequest, IGetIndexPriceRest>
public class GetIndexPriceOptions : CapabilityOptions<GetIndexPriceRequest, IGetIndexPrice>
{
/// <inheritdoc />
public override string Description => "Retrieve the index price for a futures symbol";
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetIndexPriceOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetIndexPriceRest.GetIndexPriceAsync), _defaultParameterRules)
public GetIndexPriceOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetIndexPriceRest.GetIndexPriceAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -14,15 +14,15 @@ namespace CryptoExchange.Net.SharedApis
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<SubscribeIndexPriceRequest>.Optional(x => x.Symbol, "The symbol to subscribe to", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<SubscribeIndexPriceRequest>.Optional(x => x.Symbols, "The symbols to subscribe to", new[] { new SharedSymbol(TradingMode.Spot, "ETH", "USDT") }),
RequestParameterRule<SubscribeIndexPriceRequest>.Optional(x => x.Symbol, "The symbol to subscribe to", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<SubscribeIndexPriceRequest>.Optional(x => x.Symbols, "The symbols to subscribe to", new[] { new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT") }),
};
/// <summary>
/// ctor
/// </summary>
public SubscribeIndexPriceOptions(string exchange, bool needsAuthentication)
: base(exchange, needsAuthentication, nameof(ISubscribeIndexPriceSocket.SubscribeToIndexPriceUpdatesAsync), _defaultParameterRules)
: base(exchange, needsAuthentication, nameof(ISubscribeIndexPriceSocket.SubscribeToIndexPriceUpdatesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace CryptoExchange.Net.SharedApis
{
@@ -31,6 +32,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
/// <param name="symbols">The symbols to subscribe to</param>
[Obsolete("Use SubscribeIndexPriceRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) instead")]
public SubscribeIndexPriceRequest(params SharedSymbol[] symbols) : base(symbols, null)
{
}
@@ -36,7 +36,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetIndexPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetIndexPriceKlinesRest.GetIndexPriceKlinesAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetIndexPriceKlinesRest.GetIndexPriceKlinesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
SupportIntervals = new[]
{
@@ -61,7 +61,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetIndexPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
SupportIntervals = intervals;
}
@@ -36,7 +36,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetMarkPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
SupportIntervals = new[]
{
@@ -61,7 +61,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetMarkPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
SupportIntervals = intervals;
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace CryptoExchange.Net.SharedApis
{
@@ -41,6 +42,7 @@ namespace CryptoExchange.Net.SharedApis
/// </summary>
/// <param name="interval">Kline interval</param>
/// <param name="symbols">The symbols to subscribe to</param>
[Obsolete("Use SubscribeKlineRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) instead")]
public SubscribeKlineRequest(SharedKlineInterval interval, params SharedSymbol[] symbols) : base(symbols, null)
{
Interval = interval;
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting leverage info
/// </summary>
public class GetLeverageOptions : CapabilityOptions<GetLeverageRequest, IGetLeverageRest>
public class GetLeverageOptions : CapabilityOptions<GetLeverageRequest, IGetLeverage>
{
/// <inheritdoc />
public override string Description => "Retrieve the current leverage for a futures symbol";
@@ -22,7 +22,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetLeverageOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetLeverageRest.GetLeverageAsync), _defaultParameterRules)
public GetLeverageOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetLeverageRest.GetLeverageAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting leverage tier info
/// </summary>
public class GetLeverageTiersOptions : CapabilityOptions<GetLeverageTiersRequest, IGetLeverageTiersRest>
public class GetLeverageTiersOptions : CapabilityOptions<GetLeverageTiersRequest, IGetLeverageTiers>
{
/// <inheritdoc />
public override string Description => "Retrieve the current leverage tier information for a futures symbol";
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetLeverageTiersOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetLeverageTiersRest.GetLeverageTiersAsync), _defaultParameterRules)
public GetLeverageTiersOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetLeverageTiersRest.GetLeverageTiersAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -3,7 +3,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for setting leverage
/// </summary>
public class SetLeverageOptions : CapabilityOptions<SetLeverageRequest, ISetLeverageRest>
public class SetLeverageOptions : CapabilityOptions<SetLeverageRequest, ISetLeverage>
{
/// <inheritdoc />
public override string Description => "Set the leverage for a futures symbol";
@@ -19,7 +19,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public SetLeverageOptions(string exchange) : base(exchange, true, nameof(ISetLeverageRest.SetLeverageAsync), _defaultParameterRules)
public SetLeverageOptions(string exchange) : base(exchange, true, nameof(ISetLeverageRest.SetLeverageAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting the mark price
/// </summary>
public class GetAllMarkPricesOptions : CapabilityOptions<GetAllMarkPricesRequest, IGetAllMarkPricesRest>
public class GetAllMarkPricesOptions : CapabilityOptions<GetAllMarkPricesRequest, IGetAllMarkPrices>
{
/// <inheritdoc />
public override string Description => "Retrieve the mark prices for all futures symbols";
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetAllMarkPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllMarkPricesRest.GetAllMarkPricesAsync), _defaultParameterRules)
public GetAllMarkPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllMarkPricesRest.GetAllMarkPricesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting the mark price
/// </summary>
public class GetMarkPriceOptions : CapabilityOptions<GetMarkPriceRequest, IGetMarkPriceRest>
public class GetMarkPriceOptions : CapabilityOptions<GetMarkPriceRequest, IGetMarkPrice>
{
/// <inheritdoc />
public override string Description => "Retrieve the mark price for a futures symbol";
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetMarkPriceOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetMarkPriceRest.GetMarkPriceAsync), _defaultParameterRules)
public GetMarkPriceOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetMarkPriceRest.GetMarkPriceAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -14,15 +14,15 @@ namespace CryptoExchange.Net.SharedApis
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<SubscribeMarkPriceRequest>.Optional(x => x.Symbol, "The symbol to subscribe to", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<SubscribeMarkPriceRequest>.Optional(x => x.Symbols, "The symbols to subscribe to", new[] { new SharedSymbol(TradingMode.Spot, "ETH", "USDT") }),
RequestParameterRule<SubscribeMarkPriceRequest>.Optional(x => x.Symbol, "The symbol to subscribe to", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<SubscribeMarkPriceRequest>.Optional(x => x.Symbols, "The symbols to subscribe to", new[] { new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT") }),
};
/// <summary>
/// ctor
/// </summary>
public SubscribeMarkPriceOptions(string exchange, bool needsAuthentication)
: base(exchange, needsAuthentication, nameof(ISubscribeMarkPriceSocket.SubscribeToMarkPriceUpdatesAsync), _defaultParameterRules)
: base(exchange, needsAuthentication, nameof(ISubscribeMarkPriceSocket.SubscribeToMarkPriceUpdatesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace CryptoExchange.Net.SharedApis
{
@@ -31,6 +32,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
/// <param name="symbols">The symbols to subscribe to</param>
[Obsolete("Use SubscribeMarkPriceRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) instead")]
public SubscribeMarkPriceRequest(params SharedSymbol[] symbols) : base(symbols, null)
{
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting open interest
/// </summary>
public class GetOpenInterestOptions : CapabilityOptions<GetOpenInterestRequest, IGetOpenInterestRest>
public class GetOpenInterestOptions : CapabilityOptions<GetOpenInterestRequest, IGetOpenInterest>
{
/// <inheritdoc />
public override string Description => "Retrieve open interest for a futures symbol";
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetOpenInterestOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetOpenInterestRest.GetOpenInterestAsync), _defaultParameterRules)
public GetOpenInterestOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetOpenInterestRest.GetOpenInterestAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting book ticker
/// </summary>
public class GetBookTickerOptions : CapabilityOptions<GetBookTickerRequest, IGetBookTickerRest>
public class GetBookTickerOptions : CapabilityOptions<GetBookTickerRequest, IGetBookTicker>
{
/// <inheritdoc />
public override string Description => "Retrieve the best bid and ask price for a symbol";
@@ -8,7 +8,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting order book
/// </summary>
public class GetOrderBookOptions : CapabilityOptions<GetOrderBookRequest, IGetOrderBookRest>
public class GetOrderBookOptions : CapabilityOptions<GetOrderBookRequest, IGetOrderBook>
{
/// <inheritdoc />
public override string Description => "Retrieve the current order book for a symbol";
@@ -53,7 +53,7 @@ namespace CryptoExchange.Net.SharedApis
}
/// <inheritdoc />
public override Error? ValidateRequest(GetOrderBookRequest request, IGetOrderBookRest client)
public override Error? ValidateRequest(GetOrderBookRequest request, IGetOrderBook client)
{
var error = base.ValidateRequest(request, client);
if (error != null)
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace CryptoExchange.Net.SharedApis
{
@@ -38,6 +39,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
/// <param name="symbols">The symbols to subscribe to</param>
[Obsolete("Use SubscribeOrderBookRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) instead")]
public SubscribeOrderBookRequest(params SharedSymbol[] symbols) : base(symbols, null)
{
}
@@ -1,9 +1,9 @@
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Request to place a new spot order
/// Request to edit an order
/// </summary>
public record EditSpotOrderRequest : SharedSymbolRequest
public record EditOrderRequest : SharedSymbolRequest
{
/// <summary>
/// Order id
@@ -26,7 +26,7 @@
/// <param name="quantity">New quantity of the order</param>
/// <param name="price">New price of the order</param>
/// <param name="exchangeParameters">Exchange specific parameters</param>
public EditSpotOrderRequest(
public EditOrderRequest(
SharedSymbol symbol,
string orderId,
SharedQuantity? quantity = null,
@@ -18,7 +18,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public CancelAllFuturesOrdersOptions(string exchange) : base(exchange, true, nameof(ICancelAllFuturesOrders.CancelAllFuturesOrdersAsync), _defaultParameterRules)
public CancelAllFuturesOrdersOptions(string exchange) : base(exchange, true, nameof(ICancelAllFuturesOrders.CancelAllFuturesOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public CancelAllFuturesSymbolOrdersOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ICancelAllFuturesSymbolOrders.CancelAllFuturesSymbolOrdersAsync), _defaultParameterRules)
public CancelAllFuturesSymbolOrdersOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ICancelAllFuturesSymbolOrders.CancelAllFuturesSymbolOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public CancelFuturesOrderOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ICancelFuturesOrder.CancelFuturesOrderAsync), _defaultParameterRules)
public CancelFuturesOrderOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ICancelFuturesOrder.CancelFuturesOrderAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -3,7 +3,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for canceling a futures order by client order id
/// </summary>
public class CancelFuturesOrderByClientOrderIdOptions : CapabilityOptions<CancelOrderRequest, ICancelFuturesOrderByClientOrderIdRest>
public class CancelFuturesOrderByClientOrderIdOptions : CapabilityOptions<CancelOrderRequest, ICancelFuturesOrderByClientOrderId>
{
/// <inheritdoc />
public override string Description => "Cancel a futures order by its client order id";
@@ -17,7 +17,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public CancelFuturesOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ICancelFuturesOrderByClientOrderIdRest.CancelFuturesOrderByClientOrderIdAsync), _defaultParameterRules)
public CancelFuturesOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ICancelFuturesOrderByClientOrderId.CancelFuturesOrderByClientOrderIdAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,24 +7,24 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for editing an open Futures order
/// </summary>
public class EditFuturesOrderOptions : CapabilityOptions<EditFuturesOrderRequest, IEditFuturesOrder>
public class EditFuturesOrderOptions : CapabilityOptions<EditOrderRequest, IEditFuturesOrder>
{
/// <inheritdoc />
public override string Description => "Edit an existing Futures order";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<EditFuturesOrderRequest>.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<EditFuturesOrderRequest>.Required(x => x.OrderId, "The id of the order to edit", "123"),
RequestParameterRule<EditFuturesOrderRequest>.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)),
RequestParameterRule<EditFuturesOrderRequest>.Optional(x => x.Price, "The new order price", 0.1m),
RequestParameterRule<EditOrderRequest>.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<EditOrderRequest>.Required(x => x.OrderId, "The id of the order to edit", "123"),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Price, "The new order price", 0.1m),
};
/// <summary>
/// ctor
/// </summary>
public EditFuturesOrderOptions(string exchange) : base(exchange, true, nameof(IEditFuturesOrder.EditFuturesOrderAsync), _defaultParameterRules)
public EditFuturesOrderOptions(string exchange) : base(exchange, true, nameof(IEditFuturesOrder.EditFuturesOrderAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -1,41 +0,0 @@
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Request to place a new Futures order
/// </summary>
public record EditFuturesOrderRequest : SharedSymbolRequest
{
/// <summary>
/// Order id
/// </summary>
public string OrderId { get; set; }
/// <summary>
/// Quantity of the order
/// </summary>
public SharedQuantity? Quantity { get; set; }
/// <summary>
/// Price of the order
/// </summary>
public decimal? Price { get; set; }
/// <summary>
/// ctor
/// </summary>
/// <param name="symbol">Symbol to place the order on</param>
/// <param name="orderId">The id of the order to edit</param>
/// <param name="quantity">New quantity of the order</param>
/// <param name="price">New price of the order</param>
/// <param name="exchangeParameters">Exchange specific parameters</param>
public EditFuturesOrderRequest(
SharedSymbol symbol,
string orderId,
SharedQuantity? quantity = null,
decimal? price = null,
ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters)
{
OrderId = orderId;
Quantity = quantity;
Price = price;
}
}
}
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// <param name="request">Request info</param>
/// <param name="ct">Cancellation token</param>
Task<ICallResult<SharedId>> EditFuturesOrderAsync(
EditFuturesOrderRequest request,
EditOrderRequest request,
CancellationToken ct = default);
}
@@ -35,7 +35,7 @@ namespace CryptoExchange.Net.SharedApis
public interface IEditFuturesOrderRest : IEditFuturesOrder, ISharedRest
{
/// <inheritdoc />
new Task<HttpResult<SharedId>> EditFuturesOrderAsync(EditFuturesOrderRequest request, CancellationToken ct = default);
new Task<HttpResult<SharedId>> EditFuturesOrderAsync(EditOrderRequest request, CancellationToken ct = default);
}
/// <summary>
@@ -44,6 +44,6 @@ namespace CryptoExchange.Net.SharedApis
public interface IEditFuturesOrderSocket : IEditFuturesOrder, ISharedSocket
{
/// <inheritdoc />
new Task<QueryResult<SharedId>> EditFuturesOrderAsync(EditFuturesOrderRequest request, CancellationToken ct = default);
new Task<QueryResult<SharedId>> EditFuturesOrderAsync(EditOrderRequest request, CancellationToken ct = default);
}
}
@@ -0,0 +1,26 @@
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Options for editing a futures order by client order id
/// </summary>
public class EditFuturesOrderByClientOrderIdOptions : CapabilityOptions<EditOrderRequest, IEditFuturesOrderByClientOrderId>
{
/// <inheritdoc />
public override string Description => "Edit a futures order by its client order id";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<EditOrderRequest>.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<EditOrderRequest>.Required(x => x.OrderId, "The client order id of the order to edit", "123"),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Price, "The new order price", 0.1m),
};
/// <summary>
/// ctor
/// </summary>
public EditFuturesOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IEditFuturesOrderByClientOrderId.EditFuturesOrderByClientOrderIdAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
}
@@ -0,0 +1,46 @@
using CryptoExchange.Net.Objects;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Operation for editing an open futures order by its client order id on an exchange.
/// </summary>
public interface IEditFuturesOrderByClientOrderId : ISharedApiCapability
{
/// <summary>
/// Futures edit order by client order id request options.<br />
/// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary>
EditFuturesOrderByClientOrderIdOptions EditFuturesOrderByClientOrderIdOptions { get; }
/// <summary>
/// Edit a futures order using client order id, see <see cref="EditFuturesOrderByClientOrderIdOptions"/> for request options and exchange specific required/optional parameters. <br />
/// </summary>
/// <param name="request">Request info</param>
/// <param name="ct">Cancellation token</param>
Task<ICallResult<SharedId>> EditFuturesOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default);
}
/// <summary>
/// Operation for editing an open futures order by its client order id on an exchange via the REST API.
/// </summary>
public interface IEditFuturesOrderByClientOrderIdRest : IEditFuturesOrderByClientOrderId, ISharedRest
{
/// <inheritdoc />
new Task<HttpResult<SharedId>> EditFuturesOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default);
}
/// <summary>
/// Operation for editing an open futures order by its client order id on an exchange via the WebSocket API.
/// </summary>
public interface IEditFuturesOrderByClientOrderIdSocket : IEditFuturesOrderByClientOrderId, ISharedSocket
{
/// <inheritdoc />
new Task<QueryResult<SharedId>> EditFuturesOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default);
}
}
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetFuturesClosedOrdersOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, true, nameof(IGetClosedFuturesOrdersRest.GetClosedFuturesOrdersAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, true, nameof(IGetClosedFuturesOrdersRest.GetClosedFuturesOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for getting a futures order by id endpoint
/// </summary>
public class GetFuturesOrderOptions : CapabilityOptions<GetOrderRequest, IGetFuturesOrderRest>
public class GetFuturesOrderOptions : CapabilityOptions<GetOrderRequest, IGetFuturesOrder>
{
/// <inheritdoc />
public override string Description => "Retrieve a futures order";
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetFuturesOrderOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetFuturesOrderRest.GetFuturesOrderAsync), _defaultParameterRules)
public GetFuturesOrderOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetFuturesOrder.GetFuturesOrderAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for getting a spot order by client order id
/// </summary>
public class GetFuturesOrderByClientOrderIdOptions : CapabilityOptions<GetOrderRequest, IGetFuturesOrderByClientOrderIdRest>
public class GetFuturesOrderByClientOrderIdOptions : CapabilityOptions<GetOrderRequest, IGetFuturesOrderByClientOrderId>
{
/// <inheritdoc />
public override string Description => "Retrieve a futures order by its client order id";
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetFuturesOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetFuturesOrderByClientOrderIdRest.GetFuturesOrderByClientOrderIdAsync), _defaultParameterRules)
public GetFuturesOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetFuturesOrderByClientOrderId.GetFuturesOrderByClientOrderIdAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for getting a futures order by id endpoint
/// </summary>
public class GetOpenFuturesOrdersOptions : CapabilityOptions<GetOpenOrdersRequest, IGetOpenFuturesOrdersRest>
public class GetOpenFuturesOrdersOptions : CapabilityOptions<GetOpenOrdersRequest, IGetOpenFuturesOrders>
{
/// <inheritdoc />
public override string Description => "Retrieve open futures orders";
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetOpenFuturesOrdersOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetOpenFuturesOrdersRest.GetOpenFuturesOrdersAsync), _defaultParameterRules)
public GetOpenFuturesOrdersOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetOpenFuturesOrders.GetOpenFuturesOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -37,7 +37,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public PlaceFuturesOrderOptions(string exchange, bool supportsTpSl) : base(exchange, true, nameof(IPlaceFuturesOrder.PlaceFuturesOrderAsync), _defaultParameterRules)
public PlaceFuturesOrderOptions(string exchange, bool supportsTpSl) : base(exchange, true, nameof(IPlaceFuturesOrder.PlaceFuturesOrderAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
SupportsTpSl = supportsTpSl;
}
@@ -23,7 +23,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public PlaceMultipleFuturesOrdersOptions(string exchange)
: base(exchange, true, nameof(IPlaceMultipleFuturesOrders.PlaceMultipleFuturesOrdersAsync), _defaultParameterRules)
: base(exchange, true, nameof(IPlaceMultipleFuturesOrders.PlaceMultipleFuturesOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
@@ -20,7 +20,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public SubscribeFuturesOrderOptions(string exchange, bool needsAuthentication) : base(exchange, needsAuthentication, nameof(ISubscribeFuturesOrdersSocket.SubscribeToFuturesOrderUpdatesAsync), _defaultParameterRules)
public SubscribeFuturesOrderOptions(string exchange, bool needsAuthentication) : base(exchange, needsAuthentication, nameof(ISubscribeFuturesOrdersSocket.SubscribeToFuturesOrderUpdatesAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}
@@ -18,7 +18,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public CancelAllSpotOrdersOptions(string exchange) : base(exchange, true, nameof(ICancelAllSpotOrders.CancelAllSpotOrdersAsync), _defaultParameterRules)
public CancelAllSpotOrdersOptions(string exchange) : base(exchange, true, nameof(ICancelAllSpotOrders.CancelAllSpotOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
}
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public CancelAllSpotSymbolOrdersOptions(string exchange, bool authenticated)
: base(exchange, authenticated, nameof(ICancelAllSpotSymbolOrders.CancelAllSpotSymbolOrdersAsync), _defaultParameterRules)
: base(exchange, authenticated, nameof(ICancelAllSpotSymbolOrders.CancelAllSpotSymbolOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
}
@@ -23,7 +23,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public CancelSpotOrderOptions(string exchange, bool authenticated)
: base(exchange, authenticated, nameof(ICancelSpotOrder.CancelSpotOrderAsync), _defaultParameterRules)
: base(exchange, authenticated, nameof(ICancelSpotOrder.CancelSpotOrderAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
@@ -8,7 +8,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for canceling a spot order
/// </summary>
public class CancelSpotOrderByClientOrderIdOptions : CapabilityOptions<CancelOrderRequest, ICancelSpotOrderByClientOrderIdRest>
public class CancelSpotOrderByClientOrderIdOptions : CapabilityOptions<CancelOrderRequest, ICancelSpotOrderByClientOrderId>
{
/// <inheritdoc />
public override string Description => "Cancel a spot order by its client order id";
@@ -23,12 +23,12 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public CancelSpotOrderByClientOrderIdOptions(string exchange, bool authenticated)
: base(exchange, authenticated, nameof(ICancelSpotOrderByClientOrderIdRest.CancelSpotOrderByClientOrderIdAsync), _defaultParameterRules)
: base(exchange, authenticated, nameof(ICancelSpotOrderByClientOrderIdRest.CancelSpotOrderByClientOrderIdAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
/// <inheritdoc />
public override Error? ValidateRequest(CancelOrderRequest request, ICancelSpotOrderByClientOrderIdRest client)
public override Error? ValidateRequest(CancelOrderRequest request, ICancelSpotOrderByClientOrderId client)
{
var error = base.ValidateRequest(request, client);
if (error != null)
@@ -7,24 +7,24 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for editing an open spot order
/// </summary>
public class EditSpotOrderOptions : CapabilityOptions<EditSpotOrderRequest, IEditSpotOrder>
public class EditSpotOrderOptions : CapabilityOptions<EditOrderRequest, IEditSpotOrder>
{
/// <inheritdoc />
public override string Description => "Edit an existing spot order";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<EditSpotOrderRequest>.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<EditSpotOrderRequest>.Required(x => x.OrderId, "The order id of the order to edit", "123"),
RequestParameterRule<EditSpotOrderRequest>.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)),
RequestParameterRule<EditSpotOrderRequest>.Optional(x => x.Price, "The new order price", 0.1m),
RequestParameterRule<EditOrderRequest>.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<EditOrderRequest>.Required(x => x.OrderId, "The order id of the order to edit", "123"),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Price, "The new order price", 0.1m),
};
/// <summary>
/// ctor
/// </summary>
public EditSpotOrderOptions(string exchange)
: base(exchange, true, nameof(IEditSpotOrder.EditSpotOrderAsync), _defaultParameterRules)
: base(exchange, true, nameof(IEditSpotOrder.EditSpotOrderAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
@@ -32,7 +32,7 @@ namespace CryptoExchange.Net.SharedApis
/// Validate a request
/// </summary>
public override Error? ValidateRequest(
EditSpotOrderRequest request,
EditOrderRequest request,
IEditSpotOrder client)
{
var error = base.ValidateRequest(request, client);
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// <param name="request">Request info</param>
/// <param name="ct">Cancellation token</param>
Task<ICallResult<SharedId>> EditSpotOrderAsync(
EditSpotOrderRequest request,
EditOrderRequest request,
CancellationToken ct = default);
}
@@ -35,7 +35,7 @@ namespace CryptoExchange.Net.SharedApis
public interface IEditSpotOrderRest : IEditSpotOrder, ISharedRest
{
/// <inheritdoc />
new Task<HttpResult<SharedId>> EditSpotOrderAsync(EditSpotOrderRequest request, CancellationToken ct = default);
new Task<HttpResult<SharedId>> EditSpotOrderAsync(EditOrderRequest request, CancellationToken ct = default);
}
/// <summary>
@@ -44,6 +44,6 @@ namespace CryptoExchange.Net.SharedApis
public interface IEditSpotOrderSocket : IEditSpotOrder, ISharedSocket
{
/// <inheritdoc />
new Task<QueryResult<SharedId>> EditSpotOrderAsync(EditSpotOrderRequest request, CancellationToken ct = default);
new Task<QueryResult<SharedId>> EditSpotOrderAsync(EditOrderRequest request, CancellationToken ct = default);
}
}
@@ -0,0 +1,26 @@
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Options for editing a spot order by client order id
/// </summary>
public class EditSpotOrderByClientOrderIdOptions : CapabilityOptions<EditOrderRequest, IEditSpotOrderByClientOrderId>
{
/// <inheritdoc />
public override string Description => "Edit a spot order by its client order id";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<EditOrderRequest>.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<EditOrderRequest>.Required(x => x.OrderId, "The client order id of the order to edit", "123"),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)),
RequestParameterRule<EditOrderRequest>.Optional(x => x.Price, "The new order price", 0.1m),
};
/// <summary>
/// ctor
/// </summary>
public EditSpotOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IEditSpotOrderByClientOrderId.EditSpotOrderByClientOrderIdAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
}
}
@@ -0,0 +1,46 @@
using CryptoExchange.Net.Objects;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Operation for editing an open spot order by its client order id on an exchange.
/// </summary>
public interface IEditSpotOrderByClientOrderId : ISharedApiCapability
{
/// <summary>
/// Spot edit order by client order id request options.<br />
/// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary>
EditSpotOrderByClientOrderIdOptions EditSpotOrderByClientOrderIdOptions { get; }
/// <summary>
/// Edit a spot order using client order id, see <see cref="EditSpotOrderByClientOrderIdOptions"/> for request options and exchange specific required/optional parameters. <br />
/// </summary>
/// <param name="request">Request info</param>
/// <param name="ct">Cancellation token</param>
Task<ICallResult<SharedId>> EditSpotOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default);
}
/// <summary>
/// Operation for editing an open spot order by its client order id on an exchange via the REST API.
/// </summary>
public interface IEditSpotOrderByClientOrderIdRest : IEditSpotOrderByClientOrderId, ISharedRest
{
/// <inheritdoc />
new Task<HttpResult<SharedId>> EditSpotOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default);
}
/// <summary>
/// Operation for editing an open Spot order by its client order id on an exchange via the WebSocket API.
/// </summary>
public interface IEditSpotOrderByClientOrderIdSocket : IEditSpotOrderByClientOrderId, ISharedSocket
{
/// <inheritdoc />
new Task<QueryResult<SharedId>> EditSpotOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default);
}
}
@@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetSpotClosedOrdersOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, true, nameof(IGetClosedSpotOrdersRest.GetClosedSpotOrdersAsync), _defaultParameterRules)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, true, nameof(IGetClosedSpotOrdersRest.GetClosedSpotOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
@@ -7,7 +7,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for getting a spot order by id endpoint
/// </summary>
public class GetOpenSpotOrdersOptions : CapabilityOptions<GetOpenOrdersRequest, IGetOpenSpotOrdersRest>
public class GetOpenSpotOrdersOptions : CapabilityOptions<GetOpenOrdersRequest, IGetOpenSpotOrders>
{
/// <inheritdoc />
public override string Description => "Retrieve open spot orders";
@@ -21,7 +21,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetOpenSpotOrdersOptions(string exchange, bool authenticated)
: base(exchange, authenticated, nameof(IGetOpenSpotOrdersRest.GetOpenSpotOrdersAsync), _defaultParameterRules)
: base(exchange, authenticated, nameof(IGetOpenSpotOrders.GetOpenSpotOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
}
@@ -8,7 +8,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for getting a spot order by id endpoint
/// </summary>
public class GetSpotOrderOptions : CapabilityOptions<GetOrderRequest, IGetSpotOrderRest>
public class GetSpotOrderOptions : CapabilityOptions<GetOrderRequest, IGetSpotOrder>
{
/// <inheritdoc />
public override string Description => "Retrieve a spot order";
@@ -23,12 +23,12 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetSpotOrderOptions(string exchange, bool authenticated)
: base(exchange, authenticated, nameof(IGetSpotOrderRest.GetSpotOrderAsync), _defaultParameterRules)
: base(exchange, authenticated, nameof(IGetSpotOrder.GetSpotOrderAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
/// <inheritdoc />
public override Error? ValidateRequest(GetOrderRequest request, IGetSpotOrderRest client)
public override Error? ValidateRequest(GetOrderRequest request, IGetSpotOrder client)
{
var error = base.ValidateRequest(request, client);
if (error != null)
@@ -23,7 +23,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public GetSpotOrderByClientOrderIdOptions(string exchange, bool authenticated)
: base(exchange, authenticated, nameof(IGetSpotOrderByClientOrderIdRest.GetSpotOrderByClientOrderIdAsync), _defaultParameterRules)
: base(exchange, authenticated, nameof(IGetSpotOrderByClientOrderIdRest.GetSpotOrderByClientOrderIdAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
@@ -23,7 +23,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public PlaceMultipleSpotOrdersOptions(string exchange)
: base(exchange, true, nameof(IPlaceMultipleSpotOrders.PlaceMultipleSpotOrdersAsync), _defaultParameterRules)
: base(exchange, true, nameof(IPlaceMultipleSpotOrders.PlaceMultipleSpotOrdersAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
@@ -29,7 +29,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public PlaceSpotOrderOptions(string exchange)
: base(exchange, true, nameof(IPlaceSpotOrder.PlaceSpotOrderAsync), _defaultParameterRules)
: base(exchange, true, nameof(IPlaceSpotOrder.PlaceSpotOrderAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
@@ -18,7 +18,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor
/// </summary>
public SubscribeSpotOrderOptions(string exchange, bool needsAuthentication)
: base(exchange, needsAuthentication, nameof(ISubscribeSpotOrdersSocket.SubscribeToSpotOrderUpdatesAsync), _defaultParameterRules)
: base(exchange, needsAuthentication, nameof(ISubscribeSpotOrdersSocket.SubscribeToSpotOrderUpdatesAsync), _defaultParameterRules, SharedTradingModeSets.Spot)
{
}
}
@@ -3,7 +3,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// Options for requesting current position mode
/// </summary>
public class GetPositionModeOptions : CapabilityOptions<GetPositionModeRequest, IGetPositionModeRest>
public class GetPositionModeOptions : CapabilityOptions<GetPositionModeRequest, IGetPositionMode>
{
/// <inheritdoc />
public override string Description => "Retrieve the current futures position mode";
@@ -17,7 +17,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary>
/// ctor
/// </summary>
public GetPositionModeOptions(string exchange) : base(exchange, true, nameof(IGetPositionModeRest.GetPositionModeAsync), _defaultParameterRules)
public GetPositionModeOptions(string exchange) : base(exchange, true, nameof(IGetPositionMode.GetPositionModeAsync), _defaultParameterRules, SharedTradingModeSets.Futures)
{
}
}

Some files were not shown because too many files have changed in this diff Show More