diff --git a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApi.cs b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApi.cs index f317dadc..5c124074 100644 --- a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApi.cs +++ b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApi.cs @@ -6,7 +6,7 @@ namespace Bybit.Net.Interfaces.Clients.V5 /// /// Bybit V5 API endpoints /// - public interface IBybitRestClientApi : IBaseApiClient + public interface IBybitRestClientApi : IBaseApiClient, IRestApiClient { /// /// Endpoints related to account settings, info or actions diff --git a/ByBit.Net/Objects/Models/V5/BybitPosition.cs b/ByBit.Net/Objects/Models/V5/BybitPosition.cs index 4c78ff1e..80baac70 100644 --- a/ByBit.Net/Objects/Models/V5/BybitPosition.cs +++ b/ByBit.Net/Objects/Models/V5/BybitPosition.cs @@ -139,5 +139,15 @@ private decimal? EntryPrice [JsonProperty("updatedTime")] [JsonConverter(typeof(DateTimeConverter))] public DateTime UpdateTime { get; set; } + /// + /// Whether to add margin automatically + /// + [JsonProperty("autoAddMargin")] + public bool AutoAddMargin { get; set; } + /// + /// Position margin + /// + [JsonProperty("positionBalance")] + public decimal? PositionBalance { get; set; } } } diff --git a/Bybit.UnitTests/JsonResponses/V5/Trading/GetPositionsAsync.txt b/Bybit.UnitTests/JsonResponses/V5/Trading/GetPositionsAsync.txt new file mode 100644 index 00000000..9b66b0ab --- /dev/null +++ b/Bybit.UnitTests/JsonResponses/V5/Trading/GetPositionsAsync.txt @@ -0,0 +1,41 @@ +{ + "retCode": 0, + "retMsg": "OK", + "result": { + "list": [ + { + "positionIdx": 0, + "riskId": 1, + "riskLimitValue": "150", + "symbol": "BTCUSD", + "side": "Sell", + "size": "299", + "avgPrice": "30004.5006751", + "positionValue": "0.00996518", + "tradeMode": 0, + "positionStatus": "Normal", + "autoAddMargin": 1, + "adlRankIndicator": 2, + "leverage": "10", + "positionBalance": "0.00100189", + "markPrice": "26926.00", + "liqPrice": "999999.00", + "bustPrice": "999999.00", + "positionMM": "0.0000015", + "positionIM": "0.00009965", + "tpslMode": "Full", + "takeProfit": "0.00", + "stopLoss": "0.00", + "trailingStop": "0.00", + "unrealisedPnl": "0.00113932", + "cumRealisedPnl": "-0.00121275", + "createdTime": "1676538056258", + "updatedTime": "1684742400015" + } + ], + "nextPageCursor": "", + "category": "inverse" + }, + "retExtInfo": {}, + "time": 1684767531904 +} \ No newline at end of file diff --git a/Bybit.UnitTests/JsonTests.cs b/Bybit.UnitTests/JsonTests.cs index da8f0fa6..4bcd03d9 100644 --- a/Bybit.UnitTests/JsonTests.cs +++ b/Bybit.UnitTests/JsonTests.cs @@ -25,6 +25,8 @@ public class JsonTests x.UsdPerpetualOptions.OutputOriginalData = true; x.DerivativesOptions.RateLimiters = new List(); x.DerivativesOptions.OutputOriginalData = true; + x.V5Options.RateLimiters = new List(); + x.V5Options.OutputOriginalData = true; }, System.Net.HttpStatusCode.OK)); @@ -347,5 +349,19 @@ await _comparer.ProcessSubject("Derivatives/Contract/Account", c => c.Derivative useNestedJsonPropertyForAllCompare: new List { "result" } ); } + + [Test] + public async Task ValidateV5TradingCalls() + { + await _comparer.ProcessSubject("V5/Trading", c => c.V5Api.Trading, + useNestedJsonPropertyForCompare: new Dictionary + { + }, + ignoreProperties: new Dictionary> + { + }, + useNestedJsonPropertyForAllCompare: new List { "result" } + ); + } } } diff --git a/Bybit.UnitTests/TestHelpers.cs b/Bybit.UnitTests/TestHelpers.cs index 7c2cae4d..cc6a80d9 100644 --- a/Bybit.UnitTests/TestHelpers.cs +++ b/Bybit.UnitTests/TestHelpers.cs @@ -70,6 +70,7 @@ public static BybitRestClient CreateClient(Action options = nu client.InversePerpetualApi.RequestFactory = Mock.Of(); client.UsdPerpetualApi.RequestFactory = Mock.Of(); client.DerivativesApi.RequestFactory = Mock.Of(); + client.V5Api.RequestFactory = Mock.Of(); return client; } @@ -119,6 +120,9 @@ public static Mock SetResponse(BybitRestClient client, string response factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(request.Object); factory = Mock.Get(client.DerivativesApi.RequestFactory); + factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(request.Object); + factory = Mock.Get(client.V5Api.RequestFactory); factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(request.Object); return request;