Skip to content

Commit

Permalink
Added missing properties V5 position model
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Sep 2, 2023
1 parent 8ecdc15 commit 52de31a
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Bybit.Net.Interfaces.Clients.V5
/// <summary>
/// Bybit V5 API endpoints
/// </summary>
public interface IBybitRestClientApi : IBaseApiClient
public interface IBybitRestClientApi : IBaseApiClient, IRestApiClient
{
/// <summary>
/// Endpoints related to account settings, info or actions
Expand Down
10 changes: 10 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,15 @@ private decimal? EntryPrice
[JsonProperty("updatedTime")]
[JsonConverter(typeof(DateTimeConverter))]
public DateTime UpdateTime { get; set; }
/// <summary>
/// Whether to add margin automatically
/// </summary>
[JsonProperty("autoAddMargin")]
public bool AutoAddMargin { get; set; }
/// <summary>
/// Position margin
/// </summary>
[JsonProperty("positionBalance")]
public decimal? PositionBalance { get; set; }
}
}
41 changes: 41 additions & 0 deletions Bybit.UnitTests/JsonResponses/V5/Trading/GetPositionsAsync.txt
Original file line number Diff line number Diff line change
@@ -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
}
16 changes: 16 additions & 0 deletions Bybit.UnitTests/JsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class JsonTests
x.UsdPerpetualOptions.OutputOriginalData = true;
x.DerivativesOptions.RateLimiters = new List<IRateLimiter>();
x.DerivativesOptions.OutputOriginalData = true;
x.V5Options.RateLimiters = new List<IRateLimiter>();
x.V5Options.OutputOriginalData = true;
},
System.Net.HttpStatusCode.OK));

Expand Down Expand Up @@ -347,5 +349,19 @@ await _comparer.ProcessSubject("Derivatives/Contract/Account", c => c.Derivative
useNestedJsonPropertyForAllCompare: new List<string> { "result" }
);
}

[Test]
public async Task ValidateV5TradingCalls()
{
await _comparer.ProcessSubject("V5/Trading", c => c.V5Api.Trading,
useNestedJsonPropertyForCompare: new Dictionary<string, string>
{
},
ignoreProperties: new Dictionary<string, List<string>>
{
},
useNestedJsonPropertyForAllCompare: new List<string> { "result" }
);
}
}
}
4 changes: 4 additions & 0 deletions Bybit.UnitTests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static BybitRestClient CreateClient(Action<BybitRestOptions> options = nu
client.InversePerpetualApi.RequestFactory = Mock.Of<IRequestFactory>();
client.UsdPerpetualApi.RequestFactory = Mock.Of<IRequestFactory>();
client.DerivativesApi.RequestFactory = Mock.Of<IRequestFactory>();
client.V5Api.RequestFactory = Mock.Of<IRequestFactory>();
return client;
}

Expand Down Expand Up @@ -119,6 +120,9 @@ public static Mock<IRequest> SetResponse(BybitRestClient client, string response
factory.Setup(c => c.Create(It.IsAny<HttpMethod>(), It.IsAny<Uri>(), It.IsAny<int>()))
.Returns(request.Object);
factory = Mock.Get(client.DerivativesApi.RequestFactory);
factory.Setup(c => c.Create(It.IsAny<HttpMethod>(), It.IsAny<Uri>(), It.IsAny<int>()))
.Returns(request.Object);
factory = Mock.Get(client.V5Api.RequestFactory);
factory.Setup(c => c.Create(It.IsAny<HttpMethod>(), It.IsAny<Uri>(), It.IsAny<int>()))
.Returns(request.Object);
return request;
Expand Down

0 comments on commit 52de31a

Please sign in to comment.