Skip to content

Commit

Permalink
Fixed restClient.V5Api.SubAccount.EditSubAccountApiKeyAsync parameter…
Browse files Browse the repository at this point in the history
…s not getting send
  • Loading branch information
JKorf committed Dec 23, 2024
1 parent 650eb65 commit 20b506b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions ByBit.Net/Clients/V5/BybitRestClientApiSubAccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,28 @@ public async Task<WebCallResult<BybitApiKeyInfo>> EditSubAccountApiKeyAsync(
parameters.AddOptionalParameter("ips", ipRestrictions);

var permissions = new Dictionary<string, List<string>>();
AddPermission(permissions, permissionContractTradeOrder, "ContractTrade", "Order");
AddPermission(permissions, permissionContractTradePosition, "ContractTrade", "Position");
AddPermission(permissions, permissionSpotTrade, "Spot", "SpotTrade");
AddPermission(permissions, permissionWalletTransfer, "Wallet", "AccountTransfer");
AddPermission(permissions, permissionWalletSubAccountTransfer, "Wallet", "SubMemberTransferList");
AddPermission(permissions, permissionOptionsTrade, "Options", "OptionsTrade");
AddPermission(permissions, permissionCopyTrading, "CopyTrading", "CopyTrading");
AddPermission(permissions, permissionExchangeHistory, "Exchange", "ExchangeHistory");
EditPermission(permissions, permissionContractTradeOrder, "ContractTrade", "Order");
EditPermission(permissions, permissionContractTradePosition, "ContractTrade", "Position");
EditPermission(permissions, permissionSpotTrade, "Spot", "SpotTrade");
EditPermission(permissions, permissionWalletTransfer, "Wallet", "AccountTransfer");
EditPermission(permissions, permissionWalletSubAccountTransfer, "Wallet", "SubMemberTransferList");
EditPermission(permissions, permissionOptionsTrade, "Options", "OptionsTrade");
EditPermission(permissions, permissionCopyTrading, "CopyTrading", "CopyTrading");
EditPermission(permissions, permissionExchangeHistory, "Exchange", "ExchangeHistory");
parameters.Add("permissions", permissions);
return await _baseClient.SendRequestAsync<BybitApiKeyInfo>(_baseClient.GetUrl("v5/user/update-sub-api"), HttpMethod.Post, ct, null, true).ConfigureAwait(false);
return await _baseClient.SendRequestAsync<BybitApiKeyInfo>(_baseClient.GetUrl("v5/user/update-sub-api"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

private void EditPermission(Dictionary<string, List<string>> dict, bool? hasPermission, string key, string value)
{
if (hasPermission == null)
return;

if (!dict.ContainsKey(key))
dict[key] = new List<string>();

if (hasPermission == true)
dict[key].Add(value);
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Task<WebCallResult<BybitApiKeyInfo>> CreateSubAccountApiKeyAsync(
Task<WebCallResult<List<BybitSubAccount>>> GetSubAccountsAsync(CancellationToken ct = default);

/// <summary>
/// Edit API key
/// Edit API key. Note that permissions starting with the same topic (for example `permissionContractTradeOrder` and `permissionContractTradePosition` or `permissionWalletTransfer` and `permissionWalletSubAccountTransfer`) can not be adjusted separately and should both be set when changing one of the values.
/// <para><a href="https://bybit-exchange.github.io/docs/v5/user/modify-sub-apikey" /></para>
/// </summary>
/// <param name="apiKey">Api key, should be passed if editing from Master account, should be null if editing own API key from sub account</param>
Expand Down

0 comments on commit 20b506b

Please sign in to comment.