Skip to content

Commit

Permalink
Added sub account endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Aug 21, 2024
1 parent 1eb50a7 commit de29786
Show file tree
Hide file tree
Showing 22 changed files with 1,054 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST
/api/v2/sub/user/created
true
{
"code": "200000",
"data": {
"uid": 9969082973,
"subName": "AAAAAAAAAA0007",
"remarks": "remark",
"access": "Spot"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
POST
/api/v1/sub/api-key
true
{
"code": "200000",
"data": {
"subName": "AAAAAAAAAA0007",
"remark": "remark",
"apiKey": "630325e0e750870001829864",
"apiSecret": "110f31fc-61c5-4baf-a29f-3f19a62bbf5d",
"passphrase": "passphrase",
"permission": "General",
"ipWhitelist": "",
"createdAt": 1661150688000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DELETE
/api/v1/sub/api-key
true
{
"code": "200000",
"data": {
"subName": "AAAAAAAAAA0007",
"apiKey": "630325e0e750870001829864"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST
/api/v1/sub/api-key/update
true
{
"code": "200000",
"data": {
"subName": "AAAAAAAAAA0007",
"apiKey": "630329b4e7508700018298c5",
"permission": "General",
"ipWhitelist": "127.0.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GET
/api/v1/sub/api-key
true
{
"code": "200000",
"data": [
{
"subName": "AAAAAAAAAAAAA0022",
"remark": "hytest01-01",
"apiKey": "63032453e75087000182982b",
"permission": "General",
"ipWhitelist": "",
"createdAt": 1661150291000,
"apiVersion" : 3
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
GET
/api/v1/sub-accounts/123
true
{
"code": "200000",
"data":
{
"subUserId": "5caefba7d9575a0688f83c45",
"subName": "sdfgsdfgsfd",
"mainAccounts": [
{
"currency": "BTC",
"balance": "8",
"available": "8",
"holds": "0",
"baseCurrency": "BTC",
"baseCurrencyPrice": "1",
"baseAmount": "1.1"
}
],
"tradeAccounts": [
{
"currency": "BTC",
"balance": "1000",
"available": "1000",
"holds": "0",
"baseCurrency": "BTC",
"baseCurrencyPrice": "1",
"baseAmount": "1.1"
}
],
"marginAccounts": [
{
"currency": "BTC",
"balance": "1.1",
"available": "1.1",
"holds": "0",
"baseCurrency": "BTC",
"baseCurrencyPrice": "1",
"baseAmount": "1.1"
}
]
}
}
24 changes: 24 additions & 0 deletions Kucoin.Net.UnitTests/Endpoints/Spot/SubAccount/GetSubAccounts.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GET
/api/v2/sub/user
true
{
"code": "200000",
"data": {
"currentPage": 1,
"pageSize": 100,
"totalNum": 1,
"totalPage": 1,
"items": [
{
"userId": "635002438793b80001dcc8b3",
"uid": 62356,
"subName": "margin01",
"status": 2,
"type": 4,
"access": "Margin",
"createdAt": 1666187844000,
"remarks": null
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
GET
/api/v2/sub-accounts
true
{
"code": "200000",
"data": {
"currentPage": 1,
"pageSize": 10,
"totalNum": 14,
"totalPage": 2,
"items": [
{
"subUserId": "635002438793b80001dcc8b3",
"subName": "margin03",
"mainAccounts": [
{
"currency": "00",
"balance": "0",
"available": "0",
"holds": "0",
"baseCurrency": "BTC",
"baseCurrencyPrice": "125.63",
"baseAmount": "0"
}
]
}
]
}
}
2 changes: 1 addition & 1 deletion Kucoin.Net.UnitTests/KucoinRestIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task TestErrorResponseParsing()
public async Task TestSpotAccount()
{
await RunAndCheckResult(client => client.SpotApi.Account.GetUserInfoAsync(default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetSubUserInfoAsync(default), true);
//await RunAndCheckResult(client => client.SpotApi.Account.GetSubUserInfoAsync(default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetAccountsAsync(default, default, default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetBasicUserFeeAsync(default, default), true);
await RunAndCheckResult(client => client.SpotApi.Account.GetSymbolTradingFeesAsync("ETH-USDT", default), true);
Expand Down
21 changes: 20 additions & 1 deletion Kucoin.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public async Task ValidateSpotAccountCalls()
});
var tester = new RestRequestValidator<KucoinRestClient>(client, "Endpoints/Spot/Account", "https://api.kucoin.com", IsAuthenticated, "data", stjCompare: false);
await tester.ValidateAsync(client => client.SpotApi.Account.GetUserInfoAsync(), "GetUserInfo");
await tester.ValidateAsync(client => client.SpotApi.Account.GetSubUserInfoAsync(), "GetSubUserInfo");
await tester.ValidateAsync(client => client.SpotApi.Account.GetAccountsAsync(), "GetAccounts");
await tester.ValidateAsync(client => client.SpotApi.Account.GetAccountAsync("123"), "GetAccount");
await tester.ValidateAsync(client => client.SpotApi.Account.GetBasicUserFeeAsync(), "GetBasicUserFee");
Expand All @@ -50,6 +49,26 @@ public async Task ValidateSpotAccountCalls()
await tester.ValidateAsync(client => client.SpotApi.Account.GetIsolatedMarginAccountsAsync(), "GetIsolatedMarginAccounts");
}

[Test]
public async Task ValidateSpotSubAccountCalls()
{
var client = new KucoinRestClient(opts =>
{
opts.AutoTimestamp = false;
opts.ApiCredentials = new KucoinApiCredentials("123", "456", "789");
opts.OutputOriginalData = true;
});
var tester = new RestRequestValidator<KucoinRestClient>(client, "Endpoints/Spot/SubAccount", "https://api.kucoin.com", IsAuthenticated, "data", stjCompare: false);
await tester.ValidateAsync(client => client.SpotApi.SubAccount.GetSubAccountsAsync(), "GetSubAccounts");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.CreateSubAccountAsync("123", "123", "123"), "CreateSubAccount");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.GetSubAccountBalancesAsync("123"), "GetSubAccountBalances");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.GetSubAccountsBalancesAsync(), "GetSubAccountsBalances");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.GetSubAccountApiKeyAsync("123"), "GetSubAccountApiKey");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.CreateSubAccountApiKeyAsync("123","123", "123"), "CreateSubAccountApiKey");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.EditSubAccountApiKeyAsync("123", "123", "123"), "EditSubAccountApiKey");
await tester.ValidateAsync(client => client.SpotApi.SubAccount.DeleteSubAccountApiKeyAsync("123", "123", "123"), "DeleteSubAccountApiKey");
}

[Test]
public async Task ValidateSpotExchangeDataCalls()
{
Expand Down
12 changes: 12 additions & 0 deletions Kucoin.Net/Clients/SpotApi/KucoinRestClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ internal class KucoinRestClientSpotApi : RestApiClient, IKucoinRestClientSpotApi

/// <inheritdoc />
public IKucoinRestClientSpotApiAccount Account { get; }
/// <inheritdoc />
public IKucoinRestClientSpotApiSubAccount SubAccount { get; }

/// <inheritdoc />
public IKucoinRestClientSpotApiExchangeData ExchangeData { get; }
Expand All @@ -57,6 +59,7 @@ internal KucoinRestClientSpotApi(ILogger logger, HttpClient? httpClient, KucoinR
: base(logger, httpClient, options.Environment.SpotAddress, options, options.SpotOptions)
{
Account = new KucoinRestClientSpotApiAccount(this);
SubAccount = new KucoinRestClientSpotApiSubAccount(this);
ExchangeData = new KucoinRestClientSpotApiExchangeData(this);
Trading = new KucoinRestClientSpotApiTrading(this);
HfTrading = new KucoinRestClientSpotApiHfTrading(this);
Expand Down Expand Up @@ -375,6 +378,15 @@ internal async Task<WebCallResult<T>> SendAsync<T>(RequestDefinition definition,
return result.As(result.Data.Data);
}

internal async Task<WebCallResult<T>> SendRawAsync<T>(RequestDefinition definition, ParameterCollection? parameters, CancellationToken cancellationToken, int? weight = null) where T : class
{
var result = await base.SendAsync<T>(BaseAddress, definition, parameters, cancellationToken, null, weight).ConfigureAwait(false);
if (!result)
return result.AsError<T>(result.Error!);

return result.As(result.Data);
}

/// <inheritdoc />
protected override ServerRateLimitError ParseRateLimitResponse(int httpStatusCode, IEnumerable<KeyValuePair<string, IEnumerable<string>>> responseHeaders, IMessageAccessor accessor)
{
Expand Down
Loading

0 comments on commit de29786

Please sign in to comment.