Skip to content

Commit

Permalink
Added SpotApi.Margin.GetCrossMarginSymbolsAsync endpoint, Added SpotA…
Browse files Browse the repository at this point in the history
…pi.Margin.SetLeverageMultiplierAsync endpoint, Added SpotApi.HfTrading.GetMarginSymbolsWithOpenOrdersAsync endpoint
  • Loading branch information
JKorf committed Jun 25, 2024
1 parent 2bf3537 commit d457503
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GET
/api/v3/hf/margin/order/active/symbols
true
{
"code": "200000",
"data": {
"symbolSize": 1,
"symbols": ["ADA-USDT"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
GET
/api/v3/margin/symbols
true
{
"code": "200000",
"data": {
"timestamp": 1718779915377,
"items": [{
"symbol": "ATOM-USDT",
"name": "ATOM-USDT",
"enableTrading": true,
"market": "USDS",
"baseCurrency": "ATOM",
"quoteCurrency": "USDT",
"baseIncrement": 0.0001,
"baseMinSize": 0.1,
"quoteIncrement": 0.0001,
"quoteMinSize": 0.1,
"baseMaxSize": 10000000000,
"quoteMaxSize": 99999999,
"priceIncrement": 0.0001,
"feeCurrency": "USDT",
"priceLimitRate": 0.1,
"minFunds": 0.1
}]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POST
/api/v3/position/update-user-leverage
true
{
"code": "200000",
"data": null
}
3 changes: 3 additions & 0 deletions Kucoin.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public async Task ValidateSpotMarginCalls()
await tester.ValidateAsync(client => client.SpotApi.Margin.EditSubscriptionOrderAsync("ETH", 1, "123"), "EditSubscriptionOrder");
await tester.ValidateAsync(client => client.SpotApi.Margin.GetRedemptionOrdersAsync("ETH", "123"), "GetRedemptionOrders", ignoreProperties: new List<string> { "redeemAmount", "receiptAmount" });
await tester.ValidateAsync(client => client.SpotApi.Margin.GetSubscriptionOrdersAsync("ETH", "123"), "GetSubscriptionOrders", ignoreProperties: new List<string> { "purchaseAmount", "lendAmount", "redeemAmount", "incomeAmount" });
await tester.ValidateAsync(client => client.SpotApi.Margin.SetLeverageMultiplierAsync(1), "SetLeverageMultiplier");
await tester.ValidateAsync(client => client.SpotApi.Margin.GetCrossMarginSymbolsAsync(), "GetCrossMarginSymbols", "data.items");
}

[Test]
Expand Down Expand Up @@ -257,6 +259,7 @@ public async Task ValidateSpotHfTradingCalls()
await tester.ValidateAsync(client => client.SpotApi.HfTrading.GetMarginOrderAsync("ETHUSDT", "123"), "GetMarginOrder");
await tester.ValidateAsync(client => client.SpotApi.HfTrading.GetMarginOrderByClientOrderIdAsync("ETHUSDT", "123"), "GetMarginOrderByClientOrderId");
await tester.ValidateAsync(client => client.SpotApi.HfTrading.GetMarginUserTradesAsync("ETHUSDT", Enums.TradeType.IsolatedMarginTrade), "GetMarginUserTrades", ignoreProperties: new List<string> { "id" });
await tester.ValidateAsync(client => client.SpotApi.HfTrading.GetMarginSymbolsWithOpenOrdersAsync(true), "GetMarginSymbolsWithOpenOrders");
}

private bool IsAuthenticated(WebCallResult result)
Expand Down
10 changes: 10 additions & 0 deletions Kucoin.Net/Clients/SpotApi/KucoinRestClientSpotApiHfTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,5 +670,15 @@ public async Task<WebCallResult<KucoinHfPaginated<KucoinUserTrade>>> GetMarginUs
var request = _definitions.GetOrCreate(HttpMethod.Get, $"api/v3/hf/margin/fills", KucoinExchange.RateLimiter.SpotRest, 5, true);
return await _baseClient.SendAsync<KucoinHfPaginated<KucoinUserTrade>>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<KucoinMarginOpenOrderSymbols>> GetMarginSymbolsWithOpenOrdersAsync(bool isolated, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.Add("tradeType", isolated ? "MARGIN_ISOLATED_TRADE" : "MARGIN_TRADE");
var request = _definitions.GetOrCreate(HttpMethod.Get, $"api/v3/hf/margin/order/active/symbols", KucoinExchange.RateLimiter.SpotRest, 2, true);
return await _baseClient.SendAsync<KucoinMarginOpenOrderSymbols>(request, parameters, ct).ConfigureAwait(false);
}

}
}
24 changes: 24 additions & 0 deletions Kucoin.Net/Clients/SpotApi/KucoinRestClientSpotApiMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,29 @@ public async Task<WebCallResult<KucoinPaginated<KucoinLendSubscription>>> GetSub
var request = _definitions.GetOrCreate(HttpMethod.Get, $"api/v3/purchase/orders", KucoinExchange.RateLimiter.SpotRest, 10, true);
return await _baseClient.SendAsync<KucoinPaginated<KucoinLendSubscription>>(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult> SetLeverageMultiplierAsync(decimal leverage, string? symbol = null, bool? isolatedMargin = null, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddString("leverage", leverage);
parameters.AddOptional("symbol", symbol);
parameters.AddOptional("isIsolated", isolatedMargin);

var request = _definitions.GetOrCreate(HttpMethod.Post, $"api/v3/position/update-user-leverage", KucoinExchange.RateLimiter.SpotRest, 5, true);
return await _baseClient.SendAsync(request, parameters, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<KucoinCrossMarginSymbol>>> GetCrossMarginSymbolsAsync(string? symbol = null, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddOptional("symbol", symbol);

var request = _definitions.GetOrCreate(HttpMethod.Get, $"api/v3/margin/symbols", KucoinExchange.RateLimiter.SpotRest, 5, true);
var result = await _baseClient.SendAsync<KucoinCrossMarginSymbols>(request, parameters, ct).ConfigureAwait(false);
return result.As<IEnumerable<KucoinCrossMarginSymbol>>(result.Data?.Items);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,14 @@ Task<WebCallResult<KucoinNewMarginOrder>> PlaceTestMarginOrderAsync(
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<KucoinHfPaginated<KucoinUserTrade>>> GetMarginUserTradesAsync(string symbol, TradeType tradeType, Enums.OrderSide? side = null, Enums.OrderType? type = null, DateTime? startTime = null, DateTime? endTime = null, string? orderId = null, long? lastId = null, int? limit = null, CancellationToken ct = default);

/// <summary>
/// Get symbols with active margin orders
/// <para><a href="https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-active-hf-order-symbols" /></para>
/// </summary>
/// <param name="isolated">true for isolated margin, false for cross margin</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<KucoinMarginOpenOrderSymbols>> GetMarginSymbolsWithOpenOrdersAsync(bool isolated, CancellationToken ct = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,25 @@ Task<WebCallResult<KucoinNewBorrowOrder>> RepayAsync(
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<KucoinPaginated<KucoinLendSubscription>>> GetSubscriptionOrdersAsync(string asset, string status, string? purchaseOrderId = null, int? page = null, int? pageSize = null, CancellationToken ct = default);

/// <summary>
/// Modify the leverage multiplier for cross margin or isolated margin.
/// <para><a href="https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/modify-leverage-multiplier" /></para>
/// </summary>
/// <param name="leverage">New leverage multiplier. Must be greater than 1 and up to two decimal places, and cannot be less than the user's current debt leverage or greater than the system's maximum leverage</param>
/// <param name="symbol">Symbol. Leave empty for cross margin, or specify for isolated margin</param>
/// <param name="isolatedMargin">Is isolated margin</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult> SetLeverageMultiplierAsync(decimal leverage, string? symbol = null, bool? isolatedMargin = null, CancellationToken ct = default);

/// <summary>
/// Get cross margin symbols
/// <para><a href="https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-cross-margin-trading-pairs-configuration" /></para>
/// </summary>
/// <param name="symbol">Filter by symbol</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<KucoinCrossMarginSymbol>>> GetCrossMarginSymbolsAsync(string? symbol = null, CancellationToken ct = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Task<CallResult<UpdateSubscription>> SubscribeToOrderUpdatesAsync(
Task<CallResult<UpdateSubscription>> SubscribeToStopOrderUpdatesAsync(Action<DataEvent<KucoinStreamStopOrderUpdateBase>> onData, CancellationToken ct = default);

/// <summary>
/// Subscribe to funding book updates
/// DEPRECATED
/// <para><a href="https://www.kucoin.com/docs/websocket/margin-trading/public-channels/margin-funding-order-book-change" /></para>
/// </summary>
/// <param name="currency">Currencies to subscribe</param>
Expand All @@ -208,7 +208,7 @@ Task<CallResult<UpdateSubscription>> SubscribeToOrderUpdatesAsync(
Task<CallResult<UpdateSubscription>> SubscribeToFundingBookUpdatesAsync(string currency, Action<DataEvent<KucoinStreamFundingBookUpdate>> onData, CancellationToken ct = default);

/// <summary>
/// Subscribe to funding book updates
/// DEPRECATED
/// <para><a href="https://www.kucoin.com/docs/websocket/margin-trading/public-channels/margin-funding-order-book-change" /></para>
/// </summary>
/// <param name="currencies">Currencies to subscribe</param>
Expand Down
142 changes: 140 additions & 2 deletions Kucoin.Net/Kucoin.Net.xml
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@
<member name="M:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiHfTrading.GetMarginUserTradesAsync(System.String,Kucoin.Net.Enums.TradeType,System.Nullable{Kucoin.Net.Enums.OrderSide},System.Nullable{Kucoin.Net.Enums.OrderType},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.String,System.Nullable{System.Int64},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiHfTrading.GetMarginSymbolsWithOpenOrdersAsync(System.Boolean,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="T:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiMargin">
<inheritdoc />
</member>
Expand Down Expand Up @@ -691,6 +694,12 @@
<member name="M:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiMargin.GetSubscriptionOrdersAsync(System.String,System.String,System.String,System.Nullable{System.Int32},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiMargin.SetLeverageMultiplierAsync(System.Decimal,System.String,System.Nullable{System.Boolean},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiMargin.GetCrossMarginSymbolsAsync(System.String,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="T:Kucoin.Net.Clients.SpotApi.KucoinRestClientSpotApiTrading">
<inheritdoc />
</member>
Expand Down Expand Up @@ -3892,6 +3901,15 @@
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinRestClientSpotApiHfTrading.GetMarginSymbolsWithOpenOrdersAsync(System.Boolean,System.Threading.CancellationToken)">
<summary>
Get symbols with active margin orders
<para><a href="https://www.kucoin.com/docs/rest/margin-trading/margin-hf-trade/get-active-hf-order-symbols" /></para>
</summary>
<param name="isolated">true for isolated margin, false for cross margin</param>
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="T:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinRestClientSpotApiMargin">
<summary>
Margin borrow and repay endpoints
Expand Down Expand Up @@ -4090,6 +4108,26 @@
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinRestClientSpotApiMargin.SetLeverageMultiplierAsync(System.Decimal,System.String,System.Nullable{System.Boolean},System.Threading.CancellationToken)">
<summary>
Modify the leverage multiplier for cross margin or isolated margin.
<para><a href="https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/modify-leverage-multiplier" /></para>
</summary>
<param name="leverage">New leverage multiplier. Must be greater than 1 and up to two decimal places, and cannot be less than the user's current debt leverage or greater than the system's maximum leverage</param>
<param name="symbol">Symbol. Leave empty for cross margin, or specify for isolated margin</param>
<param name="isolatedMargin">Is isolated margin</param>
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinRestClientSpotApiMargin.GetCrossMarginSymbolsAsync(System.String,System.Threading.CancellationToken)">
<summary>
Get cross margin symbols
<para><a href="https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-cross-margin-trading-pairs-configuration" /></para>
</summary>
<param name="symbol">Filter by symbol</param>
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="T:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinRestClientSpotApiTrading">
<summary>
Kucoin Spot trading endpoints, placing and mananging orders.
Expand Down Expand Up @@ -4655,7 +4693,7 @@
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinSocketClientSpotApi.SubscribeToFundingBookUpdatesAsync(System.String,System.Action{CryptoExchange.Net.Objects.Sockets.DataEvent{Kucoin.Net.Objects.Models.Spot.Socket.KucoinStreamFundingBookUpdate}},System.Threading.CancellationToken)">
<summary>
Subscribe to funding book updates
DEPRECATED
<para><a href="https://www.kucoin.com/docs/websocket/margin-trading/public-channels/margin-funding-order-book-change" /></para>
</summary>
<param name="currency">Currencies to subscribe</param>
Expand All @@ -4665,7 +4703,7 @@
</member>
<member name="M:Kucoin.Net.Interfaces.Clients.SpotApi.IKucoinSocketClientSpotApi.SubscribeToFundingBookUpdatesAsync(System.Collections.Generic.IEnumerable{System.String},System.Action{CryptoExchange.Net.Objects.Sockets.DataEvent{Kucoin.Net.Objects.Models.Spot.Socket.KucoinStreamFundingBookUpdate}},System.Threading.CancellationToken)">
<summary>
Subscribe to funding book updates
DEPRECATED
<para><a href="https://www.kucoin.com/docs/websocket/margin-trading/public-channels/margin-funding-order-book-change" /></para>
</summary>
<param name="currencies">Currencies to subscribe</param>
Expand Down Expand Up @@ -8216,6 +8254,91 @@
The user's remaining maximum loan amount
</summary>
</member>
<member name="T:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol">
<summary>
Cross margin symbol
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.Symbol">
<summary>
Symbol
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.Name">
<summary>
Name
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.TradingEnabled">
<summary>
Trading enabled
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.Market">
<summary>
Market
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.BaseAsset">
<summary>
Base asset
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.QuoteAsset">
<summary>
Quote asset
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.BaseAssetStep">
<summary>
Base asset step
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.MinOrderQuantity">
<summary>
Minimal order quantity (base asset)
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.QuoteAssetStep">
<summary>
Quote asset step
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.MinQuoteOrderQuantity">
<summary>
Minimal order value (quote asset)
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.MaxOrderQuantity">
<summary>
Max order quantity
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.MaxOrderValue">
<summary>
Max order value (quote asset)
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.PriceStep">
<summary>
Price step
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.FeeAsset">
<summary>
Fee asset
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.PriceLimitRate">
<summary>
Price protection threshold
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinCrossMarginSymbol.MinOrderValue">
<summary>
Minimum trading amount
</summary>
</member>
<member name="T:Kucoin.Net.Objects.Models.Spot.KucoinCrossRiskLimitConfig">
<summary>
Cross margin risk limit and asset configuration
Expand Down Expand Up @@ -9211,6 +9334,21 @@
Timesatmp
</summary>
</member>
<member name="T:Kucoin.Net.Objects.Models.Spot.KucoinMarginOpenOrderSymbols">
<summary>
Symbols with open orders
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinMarginOpenOrderSymbols.ActiveOrderSymbols">
<summary>
Number or symbols with active orders
</summary>
</member>
<member name="P:Kucoin.Net.Objects.Models.Spot.KucoinMarginOpenOrderSymbols.Symbols">
<summary>
Symbols with open orders
</summary>
</member>
<member name="T:Kucoin.Net.Objects.Models.Spot.KucoinModifiedOrder">
<summary>
New order id
Expand Down
Loading

0 comments on commit d457503

Please sign in to comment.