Skip to content

Commit

Permalink
Updated PerpetualFuturesApi.Account.GetBalancesAsync to V3, returning…
Browse files Browse the repository at this point in the history
… both USDT and USDC balances
  • Loading branch information
JKorf committed Aug 19, 2024
1 parent fa18cf4 commit bbbe6c4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
GET
/openApi/swap/v2/user/balance
/openApi/swap/v3/user/balance
true
{
"code": 0,
"msg": "",
"data": {
"balance": {
"userId": "116295",
"asset": "USDT",
"balance": "194.8212",
"equity": "196.7431",
"unrealizedProfit": "1.9219",
"realisedProfit": "-109.2504",
"availableMargin": "193.7609",
"usedMargin": "1.0602",
"freezedMargin": "0.0000"
}
}
}
{"code":0,"msg":"","data":[{"userId":"1341158271307522053","asset":"USDT","balance":"19.9003","equity":"19.9003","unrealizedProfit":"0.0000","realisedProfit":"0","availableMargin":"19.9003","usedMargin":"0.0000","freezedMargin":"0.0000","shortUid":"25307298"},{"userId":"1341158271307522053","asset":"USDC","balance":"0.0000","equity":"0.0000","unrealizedProfit":"0.0000","realisedProfit":"0","availableMargin":"0.0000","usedMargin":"0.0000","freezedMargin":"0.0000","shortUid":"25307298"}]}
4 changes: 2 additions & 2 deletions BingX.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task ValidatePerpetualFuturesAccountCalls()
opts.ApiCredentials = new ApiCredentials("123", "456");
});
var tester = new RestRequestValidator<BingXRestClient>(client, "Endpoints/PerpetualFutures/Account", "https://open-api.bingx.com", IsAuthenticated, "data");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetBalancesAsync(), "GetBalances", nestedJsonProperty: "data.balance");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetBalancesAsync(), "GetBalances", nestedJsonProperty: "data");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetIncomesAsync(), "GetIncomes");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetTradingFeesAsync(), "GetTradingFees", "data.commission");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.StartUserStreamAsync(), "StartUserStream", "listenKey");
Expand Down Expand Up @@ -152,7 +152,7 @@ public async Task ValidatePerpetualFuturesTradingCalls()
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.CancelAllOrdersAfterAsync(true, 1), "CancelAllOrdersAfter");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.ClosePositionAsync("123"), "ClosePosition");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.GetPositionAndMarginInfoAsync("123"), "GetPositionAndMarginInfo");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.GetPositionHistoryAsync(), "GetPositionHistory", nestedJsonProperty: "data");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Trading.GetPositionHistoryAsync("ETH-USDT"), "GetPositionHistory", nestedJsonProperty: "data.positionHistory");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ internal BingXRestClientPerpetualFuturesApiAccount(BingXRestClientPerpetualFutur
#region Get Balances

/// <inheritdoc />
public async Task<WebCallResult<BingXFuturesBalance>> GetBalancesAsync(CancellationToken ct = default)
public async Task<WebCallResult<IEnumerable<BingXFuturesBalance>>> GetBalancesAsync(CancellationToken ct = default)
{
var request = _definitions.GetOrCreate(HttpMethod.Get, "/openApi/swap/v2/user/balance", BingXExchange.RateLimiter.RestAccount2, 1, true,
var request = _definitions.GetOrCreate(HttpMethod.Get, "/openApi/swap/v3/user/balance", BingXExchange.RateLimiter.RestAccount2, 1, true,
limitGuard: new SingleLimitGuard(5, TimeSpan.FromSeconds(1), RateLimitWindowType.Sliding, keySelector: SingleLimitGuard.PerApiKey));
var result = await _baseClient.SendAsync<BingXFuturesBalanceWrapper>(request, null, ct).ConfigureAwait(false);
return result.As<BingXFuturesBalance>(result.Data?.Balance);
return await _baseClient.SendAsync<IEnumerable<BingXFuturesBalance>>(request, null, ct).ConfigureAwait(false);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IBingXRestClientPerpetualFuturesApiAccount
/// </summary>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<BingXFuturesBalance>> GetBalancesAsync(CancellationToken ct = default);
Task<WebCallResult<IEnumerable<BingXFuturesBalance>>> GetBalancesAsync(CancellationToken ct = default);

/// <summary>
/// Get income history
Expand Down

0 comments on commit bbbe6c4

Please sign in to comment.