Skip to content

Commit

Permalink
Added restClient.PerpetualFuturesApi.Account.GetIsolatedMarginChangeH…
Browse files Browse the repository at this point in the history
…istoryAsync endpoint
  • Loading branch information
JKorf committed Nov 1, 2024
1 parent 497cd34 commit 70e66ae
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 4 deletions.
8 changes: 4 additions & 4 deletions BingX.Net.UnitTests/BingXRestIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public async Task TestPerpetualFuturesTrading()
{
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetPositionsAsync(default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetOpenOrdersAsync(default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetClosedOrdersAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetLiquidationOrdersAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetUserTradesAsync(default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetClosedOrdersAsync(default, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetLiquidationOrdersAsync(default, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetUserTradesAsync(default, default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetPositionAndMarginInfoAsync("ETH-USDT", default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetPositionHistoryAsync("ADA-USDT", default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.PerpetualFuturesApi.Trading.GetPositionHistoryAsync("ADA-USDT", default, default, default, default, default, default, default), true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
GET
/openApi/swap/v1/positionMargin/history
true
{
"code": 0,
"msg": "",
"timestamp": 1702731661854,
"data": {
"records": [
{
"symbol": "BTC-USDT",
"positionId": "1847596444958068736",
"changeReason": "OpenPosition",
"marginChange": "7586.46841066",
"marginAfterChange": "7586.46841066",
"time": 1729336294000
}
],
"total": 4
}
}
1 change: 1 addition & 0 deletions BingX.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public async Task ValidatePerpetualFuturesAccountCalls()
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.AdjustIsolatedMarginAsync("ETHUDST", 1, Enums.AdjustDirection.Decrease, Enums.PositionSide.Long), "AdjustIsolatedMargin");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetPositionModeAsync("ETHUDST"), "GetPositionMode");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.SetPositionModeAsync("ETHUDST", Enums.PositionMode.SinglePositionMode), "SetPositionMode");
await tester.ValidateAsync(client => client.PerpetualFuturesApi.Account.GetIsolatedMarginChangeHistoryAsync(), "GetIsolatedMarginChangeHistory", nestedJsonProperty: "data");
}

[Test]
Expand Down
66 changes: 66 additions & 0 deletions BingX.Net/BingX.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,24 @@ public async Task<WebCallResult<BingXPositionMode>> SetPositionModeAsync(string

#endregion

#region Get Isolated Margin Change History

/// <inheritdoc />
public async Task<WebCallResult<BingXMarginHistory>> GetIsolatedMarginChangeHistoryAsync(string? symbol = null, string? positionId = null, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, CancellationToken ct = default)
{
var parameters = new ParameterCollection();
parameters.AddOptional("symbol", symbol);
parameters.AddOptional("positionId", positionId);
parameters.AddOptionalMilliseconds("startTime", startTime);
parameters.AddOptionalMilliseconds("endTime", endTime);
parameters.AddOptional("pageIndex", page);
parameters.AddOptional("pageSize", pageSize);
var request = _definitions.GetOrCreate(HttpMethod.Get, "/openApi/swap/v1/positionMargin/history", BingXExchange.RateLimiter.RestAccount1, 1, true,
limitGuard: new SingleLimitGuard(5, TimeSpan.FromSeconds(1), RateLimitWindowType.Sliding, keySelector: SingleLimitGuard.PerApiKey));
var result = await _baseClient.SendAsync<BingXMarginHistory>(request, parameters, ct).ConfigureAwait(false);
return result;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,19 @@ public interface IBingXRestClientPerpetualFuturesApiAccount
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<BingXPositionMode>> SetPositionModeAsync(string symbol, PositionMode positionMode, CancellationToken ct = default);

/// <summary>
/// Get history of margin changes
/// <para><a href="https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Isolated%20Margin%20Change%20History" /></para>
/// </summary>
/// <param name="symbol">Filter by symbol, for example `ETH-USDT`</param>
/// <param name="positionId">Filter by positionId</param>
/// <param name="startTime">Filter by start time</param>
/// <param name="endTime">Filter by end time</param>
/// <param name="page">Page</param>
/// <param name="pageSize">Page size</param>
/// <param name="ct">Cancellation token</param>
Task<WebCallResult<BingXMarginHistory>> GetIsolatedMarginChangeHistoryAsync(string? symbol = null, string? positionId = null, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, CancellationToken ct = default);

}
}
63 changes: 63 additions & 0 deletions BingX.Net/Objects/Models/BingXMarginHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

namespace BingX.Net.Objects.Models
{
/// <summary>
/// Margin change info
/// </summary>
public record BingXMarginHistory
{
/// <summary>
/// Records
/// </summary>
[JsonPropertyName("records")]
public IEnumerable<BingXMarginHistoryEntry> Records { get; set; } = Array.Empty<BingXMarginHistoryEntry>();
/// <summary>
/// Total amount of records
/// </summary>
[JsonPropertyName("total")]
public decimal Total { get; set; }
}

/// <summary>
/// Margin change info
/// </summary>
public record BingXMarginHistoryEntry
{
/// <summary>
/// Symbol
/// </summary>
[JsonPropertyName("symbol")]
public string Symbol { get; set; } = string.Empty;
/// <summary>
/// Position id
/// </summary>
[JsonPropertyName("positionId")]
public string PositionId { get; set; } = string.Empty;
/// <summary>
/// Change reason
/// </summary>
[JsonPropertyName("changeReason")]
public string ChangeReason { get; set; } = string.Empty;
/// <summary>
/// Margin change
/// </summary>
[JsonPropertyName("marginChange")]
public decimal MarginChange { get; set; }
/// <summary>
/// Margin after change
/// </summary>
[JsonPropertyName("marginAfterChange")]
public decimal MarginAfterChange { get; set; }
/// <summary>
/// Time of change
/// </summary>
[JsonPropertyName("time")]
public DateTime Timestamp { get; set; }
}


}

0 comments on commit 70e66ae

Please sign in to comment.