diff --git a/CryptoExchange.Net.UnitTests/SharedCapabilitiesTests.cs b/CryptoExchange.Net.UnitTests/SharedCapabilitiesTests.cs new file mode 100644 index 00000000..c7205419 --- /dev/null +++ b/CryptoExchange.Net.UnitTests/SharedCapabilitiesTests.cs @@ -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 GetTypeAndNestedTypes(Type type) + { + yield return type; + + foreach (var nestedType in type.GetNestedTypes(BindingFlags.Public)) + { + foreach (var result in GetTypeAndNestedTypes(nestedType)) + yield return result; + } + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Assets.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Assets.cs new file mode 100644 index 00000000..eac9201e --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Assets.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Catalog of Shared API capability references. + /// + public partial class SharedCapabilities + { + /// + /// Asset capabilities. + /// + public static class Assets + { + /// + /// Get asset capability. + /// + public static SharedRestCapability GetAsset { get; } = new(); + /// + /// Get all assets capability. + /// + public static SharedRestCapability GetAllAssets { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Balances.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Balances.cs new file mode 100644 index 00000000..956849c9 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Balances.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Balance capabilities. + /// + public static class Balances + { + /// + /// Get balances capability. + /// + public static SharedRestCapability GetBalances { get; } = new(); + /// + /// Subscribe to balance updates capability. + /// + public static SharedCapabilityReference SubscribeBalances { get; } = new(); + } + + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Deposits.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Deposits.cs new file mode 100644 index 00000000..306f2699 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Deposits.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Deposit capabilities. + /// + public static class Deposits + { + /// + /// Get deposit addresses capability. + /// + public static SharedRestCapability GetDepositAddresses { get; } = new(); + /// + /// Get deposit history capability. + /// + public static SharedRestCapability GetDepositHistory { get; } = new(); + } + + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Fees.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Fees.cs new file mode 100644 index 00000000..f637e325 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Fees.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Fee capabilities. + /// + public static class Fees + { + /// + /// Get fees capability. + /// + public static SharedRestCapability GetFees { get; } = new(); + } + + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Funding.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Funding.cs new file mode 100644 index 00000000..562e1f01 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Funding.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Funding capabilities. + /// + public static class Funding + { + /// + /// Get current funding information capability. + /// + public static SharedRestCapability GetFundingInfo { get; } = new(); + /// + /// Get funding rate history capability. + /// + public static SharedRestCapability GetFundingRateHistory { get; } = new(); + /// + /// Get user funding history capability. + /// + public static SharedRestCapability GetUserFundingHistory { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.IndexPrices.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.IndexPrices.cs new file mode 100644 index 00000000..b580621d --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.IndexPrices.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Index price capabilities. + /// + public static class IndexPrices + { + /// + /// Get an index price capability. + /// + public static SharedRestCapability GetIndexPrice { get; } = new(); + /// + /// Get all index prices capability. + /// + public static SharedRestCapability GetAllIndexPrices { get; } = new(); + /// + /// Subscribe to index price updates capability. + /// + public static SharedCapabilityReference SubscribeIndexPrice { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Klines.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Klines.cs new file mode 100644 index 00000000..2d09e30f --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Klines.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Kline capabilities. + /// + public static class Klines + { + /// + /// Get klines capability. + /// + public static SharedRestCapability GetKlines { get; } = new(); + + /// + /// Get mark price klines capability. + /// + public static SharedRestCapability GetMarkPriceKlines { get; } = new(); + + /// + /// Get index price klines capability. + /// + public static SharedRestCapability GetIndexPriceKlines { get; } = new(); + + /// + /// Subscribe to kline updates capability. + /// + public static SharedCapabilityReference SubscribeKlines { get; } = new(); + } + + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Ledger.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Ledger.cs new file mode 100644 index 00000000..593fa429 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Ledger.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Ledger capabilities. + /// + public static class Ledger + { + /// + /// Get ledger entries capability. + /// + public static SharedRestCapability GetLedger { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Leverage.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Leverage.cs new file mode 100644 index 00000000..eb22c096 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Leverage.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Leverage capabilities. + /// + public static class Leverage + { + /// + /// Get leverage capability. + /// + public static SharedRestCapability GetLeverage { get; } = new(); + + /// + /// Set leverage capability. + /// + public static SharedRestCapability SetLeverage { get; } = new(); + + /// + /// Get leverage tiers capability. + /// + public static SharedRestCapability GetLeverageTiers { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.MarkPrices.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.MarkPrices.cs new file mode 100644 index 00000000..710280a9 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.MarkPrices.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Mark price capabilities. + /// + public static class MarkPrices + { + /// + /// Get a mark price capability. + /// + public static SharedRestCapability GetMarkPrice { get; } = new(); + + /// + /// Get all mark prices capability. + /// + public static SharedRestCapability GetAllMarkPrices { get; } = new(); + + /// + /// Subscribe to mark price updates capability. + /// + public static SharedCapabilityReference SubscribeMarkPrice { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.OpenInterest.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.OpenInterest.cs new file mode 100644 index 00000000..40a7979d --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.OpenInterest.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Open interest capabilities. + /// + public static class OpenInterest + { + /// + /// Get open interest capability. + /// + public static SharedRestCapability GetOpenInterest { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.OrderBooks.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.OrderBooks.cs new file mode 100644 index 00000000..017ebb4c --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.OrderBooks.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Order book capabilities. + /// + public static class OrderBooks + { + /// + /// Get an order book capability. + /// + public static SharedRestCapability GetOrderBook { get; } = new(); + + /// + /// Get a book ticker capability. + /// + public static SharedRestCapability GetBookTicker { get; } = new(); + + /// + /// Subscribe to order book updates capability. + /// + public static SharedCapabilityReference SubscribeOrderBook { get; } = new(); + + /// + /// Subscribe to incremental order book updates capability. + /// + public static SharedCapabilityReference SubscribeIncrementalOrderBook { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Orders.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Orders.cs new file mode 100644 index 00000000..1c800867 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Orders.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Order capabilities. + /// + public static class Orders + { + /// + /// Spot order capabilities. + /// + public static class Spot + { + /// + /// Place a spot order capability. + /// + public static SharedRestSocketCapability PlaceOrder { get; } = new(); + + /// + /// Place multiple spot orders capability. + /// + public static SharedRestSocketCapability PlaceMultipleOrders { get; } = new(); + + /// + /// Edit a spot order capability. + /// + public static SharedRestSocketCapability EditOrder { get; } = new(); + + /// + /// Edit a spot order by client order id capability. + /// + public static SharedRestSocketCapability EditOrderByClientOrderId { get; } = new(); + + /// + /// Cancel a spot order capability. + /// + public static SharedRestSocketCapability CancelOrder { get; } = new(); + + /// + /// Cancel a spot order by client order id capability. + /// + public static SharedRestSocketCapability CancelOrderByClientOrderId { get; } = new(); + + /// + /// Cancel all spot orders capability. + /// + public static SharedRestSocketCapability CancelAllOrders { get; } = new(); + + /// + /// Cancel all spot orders for a symbol capability. + /// + public static SharedRestSocketCapability CancelAllSymbolOrders { get; } = new(); + + /// + /// Get a spot order capability. + /// + public static SharedRestCapability GetOrder { get; } = new(); + + /// + /// Get a spot order by client order id capability. + /// + public static SharedRestCapability GetOrderByClientOrderId { get; } = new(); + + /// + /// Get open spot orders capability. + /// + public static SharedRestCapability GetOpenOrders { get; } = new(); + + /// + /// Get closed spot orders capability. + /// + public static SharedRestCapability GetClosedOrders { get; } = new(); + + /// + /// Subscribe to spot order updates capability. + /// + public static SharedCapabilityReference SubscribeOrders { get; } = new(); + } + + /// + /// Futures order capabilities. + /// + public static class Futures + { + /// + /// Place a futures order capability. + /// + public static SharedRestSocketCapability PlaceOrder { get; } = new(); + + /// + /// Place multiple futures orders capability. + /// + public static SharedRestSocketCapability PlaceMultipleOrders { get; } = new(); + + /// + /// Edit a futures order capability. + /// + public static SharedRestSocketCapability EditOrder { get; } = new(); + + /// + /// Edit a futures order by client order id capability. + /// + public static SharedRestSocketCapability EditOrderByClientOrderId { get; } = new(); + + /// + /// Cancel a futures order capability. + /// + public static SharedRestSocketCapability CancelOrder { get; } = new(); + + /// + /// Cancel a futures order by client order id capability. + /// + public static SharedRestSocketCapability CancelOrderByClientOrderId { get; } = new(); + + /// + /// Cancel all futures orders capability. + /// + public static SharedRestSocketCapability CancelAllOrders { get; } = new(); + + /// + /// Cancel all futures orders for a symbol capability. + /// + public static SharedRestSocketCapability CancelAllSymbolOrders { get; } = new(); + + /// + /// Get a futures order capability. + /// + public static SharedRestCapability GetOrder { get; } = new(); + + /// + /// Get a futures order by client order id capability. + /// + public static SharedRestCapability GetOrderByClientOrderId { get; } = new(); + + /// + /// Get open futures orders capability. + /// + public static SharedRestCapability GetOpenOrders { get; } = new(); + + /// + /// Get closed futures orders capability. + /// + public static SharedRestCapability GetClosedOrders { get; } = new(); + + /// + /// Subscribe to futures order updates capability. + /// + public static SharedCapabilityReference SubscribeOrders { get; } = new(); + } + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.PositionMode.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.PositionMode.cs new file mode 100644 index 00000000..b2d82700 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.PositionMode.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Position mode capabilities. + /// + public static class PositionMode + { + /// + /// Get position mode capability. + /// + public static SharedRestCapability GetPositionMode { get; } = new(); + + /// + /// Set position mode capability. + /// + public static SharedRestCapability SetPositionMode { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Positions.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Positions.cs new file mode 100644 index 00000000..d8e270d3 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Positions.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Position capabilities. + /// + public static class Positions + { + /// + /// Get positions capability. + /// + public static SharedRestCapability GetPositions { get; } = new(); + + /// + /// Get position history capability. + /// + public static SharedRestCapability GetPositionHistory { get; } = new(); + + /// + /// Close a full position capability. + /// + public static SharedRestCapability CloseFullPosition { get; } = new(); + + /// + /// Subscribe to position updates capability. + /// + public static SharedCapabilityReference SubscribePositions { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Symbols.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Symbols.cs new file mode 100644 index 00000000..150a2709 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Symbols.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Symbol capabilities. + /// + public static class Symbols + { + /// + /// Get spot symbols capability. + /// + public static SharedRestCapability GetSpotSymbols { get; } = new(); + + /// + /// Get futures symbols capability. + /// + public static SharedRestCapability GetFuturesSymbols { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Tickers.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Tickers.cs new file mode 100644 index 00000000..8901c388 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Tickers.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Ticker capabilities. + /// + public static class Tickers + { + /// + /// Get a ticker capability. + /// + public static SharedRestCapability GetTicker { get; } = new(); + + /// + /// Get all tickers capability. + /// + public static SharedRestCapability GetAllTickers { get; } = new(); + + /// + /// Subscribe to ticker updates capability. + /// + public static SharedCapabilityReference SubscribeTicker { get; } = new(); + + /// + /// Subscribe to all ticker updates capability. + /// + public static SharedCapabilityReference SubscribeAllTickers { get; } = new(); + + /// + /// Subscribe to book ticker updates capability. + /// + public static SharedCapabilityReference SubscribeBookTicker { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.TpSl.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.TpSl.cs new file mode 100644 index 00000000..d5073c4b --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.TpSl.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Take profit and stop loss capabilities. + /// + public static class TpSl + { + /// + /// Set futures take profit or stop loss capability. + /// + public static SharedRestCapability SetFuturesTpSl { get; } = new(); + + /// + /// Cancel futures take profit or stop loss capability. + /// + public static SharedRestCapability CancelFuturesTpSl { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Trades.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Trades.cs new file mode 100644 index 00000000..e8dfcc8f --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Trades.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Public trade capabilities. + /// + public static class Trades + { + /// + /// Get recent trades capability. + /// + public static SharedRestCapability GetRecentTrades { get; } = new(); + + /// + /// Get trade history capability. + /// + public static SharedRestCapability GetTradeHistory { get; } = new(); + + /// + /// Subscribe to trade updates capability. + /// + public static SharedCapabilityReference SubscribeTrades { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Transfers.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Transfers.cs new file mode 100644 index 00000000..6832b576 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Transfers.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Transfer capabilities. + /// + public static class Transfers + { + /// + /// Transfer assets capability. + /// + public static SharedRestCapability Transfer { get; } = new(); + + /// + /// Get transfer history capability. + /// + public static SharedRestCapability GetTransferHistory { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.TriggerOrders.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.TriggerOrders.cs new file mode 100644 index 00000000..a131791a --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.TriggerOrders.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Trigger order capabilities. + /// + public static class TriggerOrders + { + /// + /// Spot trigger order capabilities. + /// + public static class Spot + { + /// + /// Place a spot trigger order capability. + /// + public static SharedRestCapability PlaceOrder { get; } = new(); + + /// + /// Get a spot trigger order capability. + /// + public static SharedRestCapability GetOrder { get; } = new(); + + /// + /// Cancel a spot trigger order capability. + /// + public static SharedRestCapability CancelOrder { get; } = new(); + } + + /// + /// Futures trigger order capabilities. + /// + public static class Futures + { + /// + /// Place a futures trigger order capability. + /// + public static SharedRestCapability PlaceOrder { get; } = new(); + + /// + /// Get a futures trigger order capability. + /// + public static SharedRestCapability GetOrder { get; } = new(); + + /// + /// Cancel a futures trigger order capability. + /// + public static SharedRestCapability CancelOrder { get; } = new(); + } + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.UserTrades.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.UserTrades.cs new file mode 100644 index 00000000..74b36e2c --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.UserTrades.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// User trade capabilities. + /// + public static class UserTrades + { + /// + /// Get trades for a spot order capability. + /// + public static SharedRestCapability GetSpotOrderTrades { get; } = new(); + + /// + /// Get spot user trade history capability. + /// + public static SharedRestCapability GetSpotTradeHistory { get; } = new(); + + /// + /// Get trades for a futures order capability. + /// + public static SharedRestCapability GetFuturesOrderTrades { get; } = new(); + + /// + /// Get futures user trade history capability. + /// + public static SharedRestCapability GetFuturesTradeHistory { get; } = new(); + + /// + /// Subscribe to user trade updates capability. + /// + public static SharedCapabilityReference SubscribeUserTrades { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Withdrawals.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Withdrawals.cs new file mode 100644 index 00000000..bf890322 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilities.Withdrawals.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + public partial class SharedCapabilities + { + /// + /// Withdrawal capabilities. + /// + public static class Withdrawals + { + /// + /// Withdraw assets capability. + /// + public static SharedRestCapability Withdraw { get; } = new(); + + /// + /// Get withdrawal history capability. + /// + public static SharedRestCapability GetWithdrawalHistory { get; } = new(); + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilityReference.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilityReference.cs new file mode 100644 index 00000000..e8724dc6 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedCapabilityReference.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Strongly typed reference to a Shared API capability. + /// + public class SharedCapabilityReference + where T : ISharedApiCapability + { + /// + /// Capability interface type. + /// + public Type CapabilityType => typeof(T); + + internal SharedCapabilityReference() + { + } + + /// + public override string ToString() => typeof(T).Name; + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedRestCapability.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedRestCapability.cs new file mode 100644 index 00000000..542f41cb --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedRestCapability.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// References for a capability available through REST. + /// + public sealed class SharedRestCapability + where TCapability : ISharedApiCapability + where TRest : TCapability, ISharedRest + { + /// + /// Transport-agnostic capability. + /// + public SharedCapabilityReference Any { get; } = new(); + + /// + /// REST capability. + /// + public SharedCapabilityReference Rest { get; } = new(); + + internal SharedRestCapability() + { + } + } +} diff --git a/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedRestSocketCapability.cs b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedRestSocketCapability.cs new file mode 100644 index 00000000..7375771c --- /dev/null +++ b/CryptoExchange.Net/SharedApis/CapabilityReferences/SharedRestSocketCapability.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// References for a capability available through REST and WebSocket. + /// + public sealed class SharedRestSocketCapability + : SharedCapabilityReference + where TCapability : ISharedApiCapability + where TRest : TCapability, ISharedRest + where TSocket : TCapability, ISharedSocket + { + /// + /// REST capability. + /// + public SharedCapabilityReference Rest { get; } = new(); + + /// + /// WebSocket capability. + /// + public SharedCapabilityReference Socket { get; } = new(); + + internal SharedRestSocketCapability() + { + } + } +} diff --git a/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs b/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs new file mode 100644 index 00000000..0c327d50 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/SharedApiClientBase.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Base interface for Shared API clients + /// + public interface ISharedApiClientBase + { + /// + /// Get all capabilities matching the provided capability type. + /// Example: + /// client.GetCapability<IPlaceSpotOrder>() + /// + /// The capability type + /// Filter by supported trading mode + /// Filter by transport method + IReadOnlyList GetCapabilities(TradingMode? tradingMode = null, SharedTransport? transport = null) + where T : ISharedApiCapability; + + /// + /// Get the requested capability type. If more than one implementation is available the first one is returned. + /// In this case prefer using to select a specific trading mode. + /// Example: + /// client.GetCapability<IPlaceSpotOrder>(SharedTransport.Socket) + /// + /// The capability type + /// The transport method + /// The requested capability type or null if not found + T? GetCapability(SharedTransport? transport = null) + where T : ISharedApiCapability; + + /// + /// Get the requested capability type for a specific trading mode. + /// Example: + /// client.GetCapability<IPlaceFuturesOrder>(TradingMode.PerpetualLinear, SharedTransport.Rest) + /// + /// The capability type + /// The trading mode + /// The transport method + /// The requested capability type or null if not found + T? GetCapability(TradingMode tradingMode, SharedTransport? transport = null) + where T : ISharedApiCapability; + + /// + /// Get the capability matching the provided capability reference. Get a capability reference using . + /// If more than one implementation is available the first one is returned.
+ /// Example: + /// client.GetCapability(SharedCapabilities.Orders.Spot.PlaceOrder.Rest) + ///
+ /// The capability type + /// The capability reference + /// The requested capability type or null if not found + T? GetCapability(SharedCapabilityReference capability) + where T : ISharedApiCapability; + + /// + /// Get the capability matching the provided capability reference for a specific trading mode. Get a capability reference using . + /// If more than one implementation is available the first one is returned.
+ /// Example: + /// client.GetCapability(SharedCapabilities.Orders.Futures.PlaceOrder.Rest, TradingMode.PerpetualLinear) + ///
+ /// The capability type + /// The capability reference + /// The trading mode + /// The requested capability type or null if not found + T? GetCapability(SharedCapabilityReference capability, TradingMode tradingMode) + where T : ISharedApiCapability; + } + + /// + /// Base client for Shared API clients + /// + public abstract class SharedApiClientBase : ISharedApiClientBase + { + private readonly ISharedApiCapability[] _sharedApis; + private readonly SharedTransport[] _preferredTransports; + + /// + /// ctor + /// + public SharedApiClientBase(SharedTransport[] transportPref, params ISharedApiCapability[] allCapabilities) + { + _preferredTransports = transportPref; + _sharedApis = allCapabilities.ToArray(); + } + + /// + public IReadOnlyList GetCapabilities(TradingMode? tradingMode = null, SharedTransport? transport = null) + where T : ISharedApiCapability + { + return _sharedApis + .OfType() + .Where(x => + (tradingMode == null || x.SupportedTradingModes.Contains(tradingMode.Value)) + && (transport == null || x.Transport == transport) + ) + .ToArray(); + } + + /// + public T? GetCapability(SharedTransport? transport = null) + where T : ISharedApiCapability + { + return GetCapabilityCore(null, transport); + } + + /// + public T? GetCapability(TradingMode tradingMode, SharedTransport? transport = null) + where T : ISharedApiCapability + { + return GetCapabilityCore(tradingMode, transport); + } + + /// + public T? GetCapability(SharedCapabilityReference capability) + where T : ISharedApiCapability + { + return GetCapabilityCore(null, null); + } + + /// + public T? GetCapability(SharedCapabilityReference capability, TradingMode tradingMode) + where T : ISharedApiCapability + { + return GetCapabilityCore(tradingMode, null); + } + + private T? GetCapabilityCore(TradingMode? tradingMode, SharedTransport? selectedTransport = null) + where T : ISharedApiCapability + { + var implementations = _sharedApis + .OfType() + .Where(x => tradingMode == null + || x.SupportedTradingModes.Contains(tradingMode.Value)) + .ToArray(); + + foreach (var transport in selectedTransport != null ? new[] { selectedTransport! } : _preferredTransports) + { + var matching = implementations + .Where(x => x.Transport == transport) + .ToArray(); + + if (matching.Length > 0) + return matching[0]; + } + + return default; + } + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/IndexPrice/SubscribeIndexPrice/SubscribeMarkPriceRequest.cs b/CryptoExchange.Net/SharedApis/V2/IndexPrice/SubscribeIndexPrice/SubscribeMarkPriceRequest.cs index 97feca8e..c1698622 100644 --- a/CryptoExchange.Net/SharedApis/V2/IndexPrice/SubscribeIndexPrice/SubscribeMarkPriceRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/IndexPrice/SubscribeIndexPrice/SubscribeMarkPriceRequest.cs @@ -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 /// /// The symbols to subscribe to + [Obsolete("Use SubscribeIndexPriceRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeIndexPriceRequest(params SharedSymbol[] symbols) : base(symbols, null) { } diff --git a/CryptoExchange.Net/SharedApis/V2/Klines/GetKlines/GetKlinesRequest.cs b/CryptoExchange.Net/SharedApis/V2/Klines/GetKlinesRequest.cs similarity index 100% rename from CryptoExchange.Net/SharedApis/V2/Klines/GetKlines/GetKlinesRequest.cs rename to CryptoExchange.Net/SharedApis/V2/Klines/GetKlinesRequest.cs diff --git a/CryptoExchange.Net/SharedApis/V2/Klines/SubscribeKlines/SubscribeKlineRequest.cs b/CryptoExchange.Net/SharedApis/V2/Klines/SubscribeKlines/SubscribeKlineRequest.cs index ed207e7e..ff086d8f 100644 --- a/CryptoExchange.Net/SharedApis/V2/Klines/SubscribeKlines/SubscribeKlineRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/Klines/SubscribeKlines/SubscribeKlineRequest.cs @@ -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 /// /// Kline interval /// The symbols to subscribe to + [Obsolete("Use SubscribeKlineRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeKlineRequest(SharedKlineInterval interval, params SharedSymbol[] symbols) : base(symbols, null) { Interval = interval; diff --git a/CryptoExchange.Net/SharedApis/V2/Klines/Futures/GetMarkPriceKlines/GetMarkPriceRequest.cs b/CryptoExchange.Net/SharedApis/V2/MarkPrice/GetMarkPrice/GetMarkPriceRequest.cs similarity index 100% rename from CryptoExchange.Net/SharedApis/V2/Klines/Futures/GetMarkPriceKlines/GetMarkPriceRequest.cs rename to CryptoExchange.Net/SharedApis/V2/MarkPrice/GetMarkPrice/GetMarkPriceRequest.cs diff --git a/CryptoExchange.Net/SharedApis/V2/MarkPrice/SubscribeMarkPrice/SubscribeMarkPriceRequest.cs b/CryptoExchange.Net/SharedApis/V2/MarkPrice/SubscribeMarkPrice/SubscribeMarkPriceRequest.cs index 0d03fef2..80f5b5b1 100644 --- a/CryptoExchange.Net/SharedApis/V2/MarkPrice/SubscribeMarkPrice/SubscribeMarkPriceRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/MarkPrice/SubscribeMarkPrice/SubscribeMarkPriceRequest.cs @@ -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 /// /// The symbols to subscribe to + [Obsolete("Use SubscribeMarkPriceRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeMarkPriceRequest(params SharedSymbol[] symbols) : base(symbols, null) { } diff --git a/CryptoExchange.Net/SharedApis/V2/OrderBooks/SubscribeOrderBook/SubscribeOrderBookRequest.cs b/CryptoExchange.Net/SharedApis/V2/OrderBooks/SubscribeOrderBook/SubscribeOrderBookRequest.cs index fd5eee92..e3dbb6c8 100644 --- a/CryptoExchange.Net/SharedApis/V2/OrderBooks/SubscribeOrderBook/SubscribeOrderBookRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/OrderBooks/SubscribeOrderBook/SubscribeOrderBookRequest.cs @@ -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 /// /// The symbols to subscribe to + [Obsolete("Use SubscribeOrderBookRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeOrderBookRequest(params SharedSymbol[] symbols) : base(symbols, null) { } diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderRequest.cs b/CryptoExchange.Net/SharedApis/V2/Orders/EditOrderRequest.cs similarity index 89% rename from CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderRequest.cs rename to CryptoExchange.Net/SharedApis/V2/Orders/EditOrderRequest.cs index d21e7f4d..11187936 100644 --- a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/Orders/EditOrderRequest.cs @@ -1,9 +1,9 @@ namespace CryptoExchange.Net.SharedApis { /// - /// Request to place a new spot order + /// Request to edit an order /// - public record EditSpotOrderRequest : SharedSymbolRequest + public record EditOrderRequest : SharedSymbolRequest { /// /// Order id @@ -26,7 +26,7 @@ /// New quantity of the order /// New price of the order /// Exchange specific parameters - public EditSpotOrderRequest( + public EditOrderRequest( SharedSymbol symbol, string orderId, SharedQuantity? quantity = null, diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderOptions.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderOptions.cs index 1b84ec19..82dad820 100644 --- a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderOptions.cs +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderOptions.cs @@ -7,17 +7,17 @@ namespace CryptoExchange.Net.SharedApis /// /// Options for editing an open Futures order /// - public class EditFuturesOrderOptions : CapabilityOptions + public class EditFuturesOrderOptions : CapabilityOptions { /// public override string Description => "Edit an existing Futures order"; private static readonly RequestParameterDescription[] _defaultParameterRules = new[] { - RequestParameterRule.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")), - RequestParameterRule.Required(x => x.OrderId, "The id of the order to edit", "123"), - RequestParameterRule.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)), - RequestParameterRule.Optional(x => x.Price, "The new order price", 0.1m), + RequestParameterRule.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")), + RequestParameterRule.Required(x => x.OrderId, "The id of the order to edit", "123"), + RequestParameterRule.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)), + RequestParameterRule.Optional(x => x.Price, "The new order price", 0.1m), }; diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderRequest.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderRequest.cs deleted file mode 100644 index 493fc908..00000000 --- a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/EditFuturesOrderRequest.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace CryptoExchange.Net.SharedApis -{ - /// - /// Request to place a new Futures order - /// - public record EditFuturesOrderRequest : SharedSymbolRequest - { - /// - /// Order id - /// - public string OrderId { get; set; } - /// - /// Quantity of the order - /// - public SharedQuantity? Quantity { get; set; } - /// - /// Price of the order - /// - public decimal? Price { get; set; } - - /// - /// ctor - /// - /// Symbol to place the order on - /// The id of the order to edit - /// New quantity of the order - /// New price of the order - /// Exchange specific parameters - public EditFuturesOrderRequest( - SharedSymbol symbol, - string orderId, - SharedQuantity? quantity = null, - decimal? price = null, - ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters) - { - OrderId = orderId; - Quantity = quantity; - Price = price; - } - } -} diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/IEditFuturesOrder.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/IEditFuturesOrder.cs index a19bf4f2..82ccd6e2 100644 --- a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/IEditFuturesOrder.cs +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrder/IEditFuturesOrder.cs @@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis /// Request info /// Cancellation token Task> EditFuturesOrderAsync( - EditFuturesOrderRequest request, + EditOrderRequest request, CancellationToken ct = default); } @@ -35,7 +35,7 @@ namespace CryptoExchange.Net.SharedApis public interface IEditFuturesOrderRest : IEditFuturesOrder, ISharedRest { /// - new Task> EditFuturesOrderAsync(EditFuturesOrderRequest request, CancellationToken ct = default); + new Task> EditFuturesOrderAsync(EditOrderRequest request, CancellationToken ct = default); } /// @@ -44,6 +44,6 @@ namespace CryptoExchange.Net.SharedApis public interface IEditFuturesOrderSocket : IEditFuturesOrder, ISharedSocket { /// - new Task> EditFuturesOrderAsync(EditFuturesOrderRequest request, CancellationToken ct = default); + new Task> EditFuturesOrderAsync(EditOrderRequest request, CancellationToken ct = default); } } diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrderByClientOrderId/EditFuturesOrderByClientOrderIdOptions.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrderByClientOrderId/EditFuturesOrderByClientOrderIdOptions.cs new file mode 100644 index 00000000..b9d3769e --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrderByClientOrderId/EditFuturesOrderByClientOrderIdOptions.cs @@ -0,0 +1,26 @@ +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Options for editing a futures order by client order id + /// + public class EditFuturesOrderByClientOrderIdOptions : CapabilityOptions + { + /// + public override string Description => "Edit a futures order by its client order id"; + + private static readonly RequestParameterDescription[] _defaultParameterRules = new[] + { + RequestParameterRule.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")), + RequestParameterRule.Required(x => x.OrderId, "The client order id of the order to edit", "123"), + RequestParameterRule.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)), + RequestParameterRule.Optional(x => x.Price, "The new order price", 0.1m), + }; + + /// + /// ctor + /// + public EditFuturesOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IEditFuturesOrderByClientOrderIdRest.EditFuturesOrderByClientOrderIdAsync), _defaultParameterRules) + { + } + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrderByClientOrderId/IEditFuturesOrderByClientOrderId.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrderByClientOrderId/IEditFuturesOrderByClientOrderId.cs new file mode 100644 index 00000000..b660804e --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Futures/EditFuturesOrderByClientOrderId/IEditFuturesOrderByClientOrderId.cs @@ -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 +{ + /// + /// Operation for editing an open futures order by its client order id on an exchange. + /// + public interface IEditFuturesOrderByClientOrderId : ISharedApiCapability + { + /// + /// Futures edit order by client order id request options.
+ /// Use and to check for required and optional parameters for the request.
+ /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. + ///
+ EditFuturesOrderByClientOrderIdOptions EditFuturesOrderByClientOrderIdOptions { get; } + /// + /// Edit a futures order using client order id, see for request options and exchange specific required/optional parameters.
+ ///
+ /// Request info + /// Cancellation token + Task> EditFuturesOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default); + } + + /// + /// Operation for editing an open futures order by its client order id on an exchange via the REST API. + /// + public interface IEditFuturesOrderByClientOrderIdRest : IEditFuturesOrderByClientOrderId, ISharedRest + { + /// + new Task> EditFuturesOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default); + } + + /// + /// Operation for editing an open futures order by its client order id on an exchange via the WebSocket API. + /// + public interface IEditFuturesOrderByClientOrderIdSocket : IEditFuturesOrderByClientOrderId, ISharedSocket + { + /// + new Task> EditFuturesOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default); + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderOptions.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderOptions.cs index 0cd1f417..42c5943c 100644 --- a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderOptions.cs +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/EditSpotOrderOptions.cs @@ -7,17 +7,17 @@ namespace CryptoExchange.Net.SharedApis /// /// Options for editing an open spot order /// - public class EditSpotOrderOptions : CapabilityOptions + public class EditSpotOrderOptions : CapabilityOptions { /// public override string Description => "Edit an existing spot order"; private static readonly RequestParameterDescription[] _defaultParameterRules = new[] { - RequestParameterRule.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")), - RequestParameterRule.Required(x => x.OrderId, "The order id of the order to edit", "123"), - RequestParameterRule.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)), - RequestParameterRule.Optional(x => x.Price, "The new order price", 0.1m), + RequestParameterRule.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")), + RequestParameterRule.Required(x => x.OrderId, "The order id of the order to edit", "123"), + RequestParameterRule.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)), + RequestParameterRule.Optional(x => x.Price, "The new order price", 0.1m), }; /// @@ -32,7 +32,7 @@ namespace CryptoExchange.Net.SharedApis /// Validate a request /// public override Error? ValidateRequest( - EditSpotOrderRequest request, + EditOrderRequest request, IEditSpotOrder client) { var error = base.ValidateRequest(request, client); diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/IEditSpotOrder.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/IEditSpotOrder.cs index fbd10d06..f73b18ce 100644 --- a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/IEditSpotOrder.cs +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrder/IEditSpotOrder.cs @@ -25,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis /// Request info /// Cancellation token Task> EditSpotOrderAsync( - EditSpotOrderRequest request, + EditOrderRequest request, CancellationToken ct = default); } @@ -35,7 +35,7 @@ namespace CryptoExchange.Net.SharedApis public interface IEditSpotOrderRest : IEditSpotOrder, ISharedRest { /// - new Task> EditSpotOrderAsync(EditSpotOrderRequest request, CancellationToken ct = default); + new Task> EditSpotOrderAsync(EditOrderRequest request, CancellationToken ct = default); } /// @@ -44,6 +44,6 @@ namespace CryptoExchange.Net.SharedApis public interface IEditSpotOrderSocket : IEditSpotOrder, ISharedSocket { /// - new Task> EditSpotOrderAsync(EditSpotOrderRequest request, CancellationToken ct = default); + new Task> EditSpotOrderAsync(EditOrderRequest request, CancellationToken ct = default); } } diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrderByClientOrderId/EditSpotOrderByClientOrderIdOptions.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrderByClientOrderId/EditSpotOrderByClientOrderIdOptions.cs new file mode 100644 index 00000000..492ab4a4 --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrderByClientOrderId/EditSpotOrderByClientOrderIdOptions.cs @@ -0,0 +1,26 @@ +namespace CryptoExchange.Net.SharedApis +{ + /// + /// Options for editing a spot order by client order id + /// + public class EditSpotOrderByClientOrderIdOptions : CapabilityOptions + { + /// + public override string Description => "Edit a spot order by its client order id"; + + private static readonly RequestParameterDescription[] _defaultParameterRules = new[] + { + RequestParameterRule.Required(x => x.Symbol, "The symbol of the order to edit", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")), + RequestParameterRule.Required(x => x.OrderId, "The client order id of the order to edit", "123"), + RequestParameterRule.Optional(x => x.Quantity, "The new order quantity", SharedQuantity.Base(1)), + RequestParameterRule.Optional(x => x.Price, "The new order price", 0.1m), + }; + + /// + /// ctor + /// + public EditSpotOrderByClientOrderIdOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IEditSpotOrderByClientOrderIdRest.EditSpotOrderByClientOrderIdAsync), _defaultParameterRules) + { + } + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrderByClientOrderId/IEditSpotOrderByClientOrderId.cs b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrderByClientOrderId/IEditSpotOrderByClientOrderId.cs new file mode 100644 index 00000000..4d91ceaf --- /dev/null +++ b/CryptoExchange.Net/SharedApis/V2/Orders/Spot/EditSpotOrderByClientOrderId/IEditSpotOrderByClientOrderId.cs @@ -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 +{ + /// + /// Operation for editing an open spot order by its client order id on an exchange. + /// + public interface IEditSpotOrderByClientOrderId : ISharedApiCapability + { + /// + /// Spot edit order by client order id request options.
+ /// Use and to check for required and optional parameters for the request.
+ /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. + ///
+ EditSpotOrderByClientOrderIdOptions EditSpotOrderByClientOrderIdOptions { get; } + /// + /// Edit a spot order using client order id, see for request options and exchange specific required/optional parameters.
+ ///
+ /// Request info + /// Cancellation token + Task> EditSpotOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default); + } + + /// + /// Operation for editing an open spot order by its client order id on an exchange via the REST API. + /// + public interface IEditSpotOrderByClientOrderIdRest : IEditSpotOrderByClientOrderId, ISharedRest + { + /// + new Task> EditSpotOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default); + } + + /// + /// Operation for editing an open Spot order by its client order id on an exchange via the WebSocket API. + /// + public interface IEditSpotOrderByClientOrderIdSocket : IEditSpotOrderByClientOrderId, ISharedSocket + { + /// + new Task> EditSpotOrderByClientOrderIdAsync(EditOrderRequest request, CancellationToken ct = default); + } +} diff --git a/CryptoExchange.Net/SharedApis/V2/PositionMode/SetPositionMode/SetPositionModeOptions.cs b/CryptoExchange.Net/SharedApis/V2/PositionMode/SetPositionMode/SetPositionModeOptions.cs index 66941196..a1d71ead 100644 --- a/CryptoExchange.Net/SharedApis/V2/PositionMode/SetPositionMode/SetPositionModeOptions.cs +++ b/CryptoExchange.Net/SharedApis/V2/PositionMode/SetPositionMode/SetPositionModeOptions.cs @@ -18,7 +18,7 @@ namespace CryptoExchange.Net.SharedApis /// /// ctor /// - public SetPositionModeOptions(string exchange) : base(exchange, true, nameof(ISetPositionModeRest.SetPositionModeOptions), _defaultParameterRules) + public SetPositionModeOptions(string exchange) : base(exchange, true, nameof(ISetPositionModeRest.SetPositionModeAsync), _defaultParameterRules) { } } diff --git a/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeBookTicker/SubscribeBookTickerRequest.cs b/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeBookTicker/SubscribeBookTickerRequest.cs index 6cabc03a..c3cc4dc1 100644 --- a/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeBookTicker/SubscribeBookTickerRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeBookTicker/SubscribeBookTickerRequest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace CryptoExchange.Net.SharedApis { @@ -29,6 +30,7 @@ namespace CryptoExchange.Net.SharedApis /// ctor ///
/// The symbols to subscribe to + [Obsolete("Use SubscribeBookTickerRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeBookTickerRequest(params SharedSymbol[] symbols) : base(symbols, null) { } diff --git a/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeTicker/SubscribeTickerRequest.cs b/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeTicker/SubscribeTickerRequest.cs index fb15db08..a0771ac6 100644 --- a/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeTicker/SubscribeTickerRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/Tickers/SubscribeTicker/SubscribeTickerRequest.cs @@ -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 ///
/// The symbols to subscribe to + [Obsolete("Use SubscribeTickerRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeTickerRequest(params SharedSymbol[] symbols) : base(symbols, null) { } diff --git a/CryptoExchange.Net/SharedApis/V2/TpSl/SetFuturesTpSl/SetFuturesTpSlOptions.cs b/CryptoExchange.Net/SharedApis/V2/TpSl/SetFuturesTpSl/SetFuturesTpSlOptions.cs index 81e10d8a..37af2864 100644 --- a/CryptoExchange.Net/SharedApis/V2/TpSl/SetFuturesTpSl/SetFuturesTpSlOptions.cs +++ b/CryptoExchange.Net/SharedApis/V2/TpSl/SetFuturesTpSl/SetFuturesTpSlOptions.cs @@ -15,12 +15,12 @@ namespace CryptoExchange.Net.SharedApis private static readonly RequestParameterDescription[] _defaultParameterRules = new[] { RequestParameterRule.Required(x => x.Symbol, "The symbol to set take profit or stop loss for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")), - RequestParameterRule.Optional(x => x.PositionMode, "The position mode of the account", SharedPositionMode.OneWay), RequestParameterRule.Required(x => x.PositionSide, "The side of the position", SharedPositionSide.Long), - RequestParameterRule.Optional(x => x.MarginMode, "The margin mode of the position", SharedMarginMode.Cross), RequestParameterRule.Required(x => x.TpSlSide, "Whether to set take profit or stop loss", SharedTpSlSide.TakeProfit), - RequestParameterRule.Optional(x => x.Quantity, "The quantity to close", 1m), RequestParameterRule.Required(x => x.TriggerPrice, "The trigger price", 1m), + RequestParameterRule.Optional(x => x.PositionMode, "The position mode of the account", SharedPositionMode.OneWay), + RequestParameterRule.Optional(x => x.MarginMode, "The margin mode of the position", SharedMarginMode.Cross), + RequestParameterRule.Optional(x => x.Quantity, "The quantity to close", 1m), }; /// diff --git a/CryptoExchange.Net/SharedApis/V2/Trades/SubscribeTrades/SubscribeTradeRequest.cs b/CryptoExchange.Net/SharedApis/V2/Trades/SubscribeTrades/SubscribeTradeRequest.cs index d533cd6a..6410b09d 100644 --- a/CryptoExchange.Net/SharedApis/V2/Trades/SubscribeTrades/SubscribeTradeRequest.cs +++ b/CryptoExchange.Net/SharedApis/V2/Trades/SubscribeTrades/SubscribeTradeRequest.cs @@ -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 /// /// The symbols to subscribe to + [Obsolete("Use SubscribeTradeRequest(IEnumerable symbols, ExchangeParameters? exchangeParameters = null) instead")] public SubscribeTradeRequest(params SharedSymbol[] symbols) : base(symbols, null) { } diff --git a/CryptoExchange.Net/SharedApis/V2/Orders/GetOrderTradesRequest.cs b/CryptoExchange.Net/SharedApis/V2/UserTrades/GetOrderTradesRequest.cs similarity index 100% rename from CryptoExchange.Net/SharedApis/V2/Orders/GetOrderTradesRequest.cs rename to CryptoExchange.Net/SharedApis/V2/UserTrades/GetOrderTradesRequest.cs diff --git a/CryptoExchange.Net/SharedApis/V2/Withdrawals/WithdrawRequest.cs b/CryptoExchange.Net/SharedApis/V2/Withdrawals/Withdraw/WithdrawRequest.cs similarity index 100% rename from CryptoExchange.Net/SharedApis/V2/Withdrawals/WithdrawRequest.cs rename to CryptoExchange.Net/SharedApis/V2/Withdrawals/Withdraw/WithdrawRequest.cs