Skip to content

Commit

Permalink
Units tests, fixes for issues found in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed May 6, 2024
1 parent 6ccce89 commit 1ddba02
Show file tree
Hide file tree
Showing 116 changed files with 2,855 additions and 300 deletions.
4 changes: 2 additions & 2 deletions ByBit.Net/Bybit.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -48,7 +48,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.5.0" />
<PackageReference Include="CryptoExchange.Net" Version="7.5.1" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
10 changes: 5 additions & 5 deletions ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public async Task<WebCallResult> SetTradingStopAsync(
#region Purchase Leverage Token

/// <inheritdoc />
public async Task<WebCallResult<BybitLeverageTokenRecord>> PurchaseLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default)
public async Task<WebCallResult<BybitLeverageTokenPurchase>> PurchaseLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default)
{
var parameters = new Dictionary<string, object>()
{
Expand All @@ -742,15 +742,15 @@ public async Task<WebCallResult<BybitLeverageTokenRecord>> PurchaseLeverageToken

parameters.AddOptionalParameter("serialNo", clientOrderId);

return await _baseClient.SendRequestAsync<BybitLeverageTokenRecord>(_baseClient.GetUrl("v5/position/spot-lever-token/purchase"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
return await _baseClient.SendRequestAsync<BybitLeverageTokenPurchase>(_baseClient.GetUrl("v5/spot-lever-token/purchase"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

#endregion

#region Redeem Leverage Token

/// <inheritdoc />
public async Task<WebCallResult<BybitLeverageTokenRecord>> RedeemLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default)
public async Task<WebCallResult<BybitLeverageTokenRedemption>> RedeemLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default)
{
var parameters = new Dictionary<string, object>()
{
Expand All @@ -760,7 +760,7 @@ public async Task<WebCallResult<BybitLeverageTokenRecord>> RedeemLeverageTokenAs

parameters.AddOptionalParameter("serialNo", clientOrderId);

return await _baseClient.SendRequestAsync<BybitLeverageTokenRecord>(_baseClient.GetUrl("v5/position/spot-lever-token/redeem"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
return await _baseClient.SendRequestAsync<BybitLeverageTokenRedemption>(_baseClient.GetUrl("v5/spot-lever-token/redeem"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

#endregion
Expand All @@ -779,7 +779,7 @@ public async Task<WebCallResult<IEnumerable<BybitLeverageTokenHistory>>> GetLeve
parameters.AddOptionalParameter("orderId", orderId);
parameters.AddOptionalParameter("ltCoin", token);

var result = await _baseClient.SendRequestAsync<BybitResponse<BybitLeverageTokenHistory>>(_baseClient.GetUrl("v5/position/spot-lever-token/order-record"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);
var result = await _baseClient.SendRequestAsync<BybitResponse<BybitLeverageTokenHistory>>(_baseClient.GetUrl("v5/spot-lever-token/order-record"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);
if (!result)
return result.As<IEnumerable<BybitLeverageTokenHistory>>(default);

Expand Down
4 changes: 2 additions & 2 deletions ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ Task<WebCallResult<IEnumerable<BybitBatchResult<BybitBatchOrderId>>>> EditMultip
/// <param name="clientOrderId">Custom order id</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<BybitLeverageTokenRecord>> PurchaseLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default);
Task<WebCallResult<BybitLeverageTokenPurchase>> PurchaseLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default);

/// <summary>
/// Redeem a leverage token
Expand All @@ -403,7 +403,7 @@ Task<WebCallResult<IEnumerable<BybitBatchResult<BybitBatchOrderId>>>> EditMultip
/// <param name="clientOrderId">Custom order id</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<BybitLeverageTokenRecord>> RedeemLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default);
Task<WebCallResult<BybitLeverageTokenRedemption>> RedeemLeverageTokenAsync(string token, decimal quantity, string? clientOrderId = null, CancellationToken ct = default);

/// <summary>
/// Get leverage token order history
Expand Down
10 changes: 10 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitApiKeyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public class BybitApiKeyInfo
/// </summary>
[JsonProperty("kycRegion")]
public string? KycRegion { get; set; }

/// <summary>
/// The type of api key. 1:personal, 2:connected to the third-party app
/// </summary>
[JsonProperty("type")]
public int ApiKeyType { get; set; }
/// <summary>
/// Permissions
/// </summary>
Expand Down Expand Up @@ -157,5 +163,9 @@ public class BybitPermissions
/// NFT permissions
/// </summary>
public IEnumerable<string> NFT { get; set; } = Array.Empty<string>();
/// <summary>
/// Affiliate permissions
/// </summary>
public IEnumerable<string> Affiliate { get; set; } = Array.Empty<string>();
}
}
2 changes: 1 addition & 1 deletion ByBit.Net/Objects/Models/V5/BybitBorrowHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class BybitBorrowHistory
/// <summary>
/// Cost exemption
/// </summary>
public decimal CostExcemption { get; set; }
public decimal CostExemption { get; set; }
/// <summary>
/// Total borrow quantity
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitCollateralInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class BybitCollateralInfo
[JsonProperty("freeBorrowingAmount")]
public decimal? FreeBorrowAmount { get; set; }
/// <summary>
/// The maximum limit for interest-free borrowing
/// </summary>
[JsonProperty("freeBorrowingLimit")]
public decimal? FreeBorrowingLimit { get; set; }
/// <summary>
/// Borrow amount
/// </summary>
[JsonProperty("borrowAmount")]
Expand All @@ -48,9 +53,19 @@ public class BybitCollateralInfo
[JsonProperty("marginCollateral")]
public bool MarginCollateral { get; set; }
/// <summary>
/// Whether the collateral is turned on by user
/// </summary>
[JsonProperty("collateralSwitch")]
public bool CollateralSwitch { get; set; }
/// <summary>
/// Collateral ratio
/// </summary>
[JsonProperty("collateralRatio")]
public decimal CollateralRatio { get; set; }
/// <summary>
/// Borrow usage rate
/// </summary>
[JsonProperty("borrowUsageRate")]
public decimal BorrowUsageRate { get; set; }
}
}
1 change: 1 addition & 0 deletions ByBit.Net/Objects/Models/V5/BybitDeliveryRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class BybitDeliveryRecord
/// <summary>
/// Realized profit and loss
/// </summary>
[JsonProperty("deliveryRpl")]
public decimal RealizedPnl { get; set; }
}
}
5 changes: 4 additions & 1 deletion ByBit.Net/Objects/Models/V5/BybitGreeks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Bybit.Net.Objects.Models.V5
using Newtonsoft.Json;

namespace Bybit.Net.Objects.Models.V5
{
/// <summary>
/// Greeks
Expand All @@ -8,6 +10,7 @@ public class BybitGreeks
/// <summary>
/// Asset
/// </summary>
[JsonProperty("baseCoin")]
public string BaseAsset { get; set; } = string.Empty;
/// <summary>
/// Delta
Expand Down
31 changes: 25 additions & 6 deletions ByBit.Net/Objects/Models/V5/BybitLeverageTokenRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public class BybitLeverageTokenRecord
/// Purchase amount
/// </summary>
[JsonProperty("amount")]
public decimal Quantity { get; set; }
/// <summary>
/// Purchase id
/// </summary>
[JsonProperty("purchaseId")]
public string PurchaseId { get; set; } = string.Empty;
public decimal? Quantity { get; set; }
/// <summary>
/// Serial number
/// </summary>
Expand All @@ -50,4 +45,28 @@ public class BybitLeverageTokenRecord
[JsonProperty("valueCoin")]
public string QuoteAsset { get; set; } = string.Empty;
}

/// <summary>
/// Purchase record
/// </summary>
public class BybitLeverageTokenPurchase : BybitLeverageTokenRecord
{
/// <summary>
/// Purchase id
/// </summary>
[JsonProperty("purchaseId")]
public string PurchaseId { get; set; } = string.Empty;
}

/// <summary>
/// Purchase record
/// </summary>
public class BybitLeverageTokenRedemption : BybitLeverageTokenRecord
{
/// <summary>
/// Redeem id
/// </summary>
[JsonProperty("redeemId")]
public string RedeemId { get; set; } = string.Empty;
}
}
3 changes: 2 additions & 1 deletion ByBit.Net/Objects/Models/V5/BybitLeveragedTokenNav.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class BybitLeveragedTokenNav
/// <summary>
/// Timestamp
/// </summary>
[JsonConverter(typeof(EnumConverter))]
[JsonConverter(typeof(DateTimeConverter))]
[JsonProperty("time")]
public DateTime Timestamp { get; set; }
/// <summary>
/// Symbol
Expand Down
4 changes: 2 additions & 2 deletions ByBit.Net/Objects/Models/V5/BybitOptionTicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class BybitOptionTicker
/// <summary>
/// Best bid IV
/// </summary>
[JsonProperty("bid1lv")]
[JsonProperty("bid1Iv")]
public decimal BestBidIv { get; set; }
/// <summary>
/// Best ask price
Expand All @@ -39,7 +39,7 @@ public class BybitOptionTicker
/// <summary>
/// Best ask IV
/// </summary>
[JsonProperty("ask1lv")]
[JsonProperty("ask1Iv")]
public decimal BestAskIv { get; set; }
/// <summary>
/// Last trade price
Expand Down
11 changes: 11 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,16 @@ public class BybitOrder
/// </summary>
[JsonProperty("smpOrderId")]
public string? SelfMatchPreventionOrderId { get; set; }
/// <summary>
/// Take profit/stop loss mode
/// </summary>
[JsonConverter(typeof(EnumConverter))]
[JsonProperty("tpslMode")]
public StopLossTakeProfitMode? TpSlMode { get; set; }
/// <summary>
/// Place type (option only)
/// </summary>
[JsonProperty("placeType")]
public string? PlaceType { get; set; }
}
}
5 changes: 5 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitOrderbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public class BybitOrderbook
/// </summary>
[JsonProperty("u")]
public int UpdateId { get; set; }
/// <summary>
/// Cross sequence
/// </summary>
[JsonProperty("seq")]
public long? Sequence { get; set; }
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace Bybit.Net.Objects.Models.V5
/// </summary>
public class BybitPosition
{
/// <summary>
/// Category
/// </summary>
[JsonProperty("category")]
[JsonConverter(typeof(EnumConverter))]
public Category Category { get; set; }
/// <summary>
/// Position mode
/// </summary>
Expand Down
5 changes: 0 additions & 5 deletions ByBit.Net/Objects/Models/V5/BybitPositionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@ namespace Bybit.Net.Objects.Models.V5
/// </summary>
public class BybitPositionUpdate : BybitPosition
{
/// <summary>
/// Category
/// </summary>
[JsonConverter(typeof(EnumConverter))]
public Category Category { get; set; }
}
}
4 changes: 4 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitUserTrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public class BybitUserTrade
/// </summary>
public bool IsMaker { get; set; }
/// <summary>
/// Whether to borrow. Unified spot only
/// </summary>
public bool? IsLeverage { get; set; }
/// <summary>
/// Spot trading fee asset
/// </summary>
[JsonProperty("feeCurrency")]
Expand Down
34 changes: 34 additions & 0 deletions Bybit.UnitTests/Endpoints/V5Api/Account/AddOrReduceMargin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
POST
/v5/position/add-margin
true
{
"retCode": 0,
"retMsg": "OK",
"result": {
"category": "inverse",
"symbol": "ETHUSD",
"positionIdx": 0,
"riskId": 11,
"riskLimitValue": "500",
"size": "200",
"positionValue": "0.11033265",
"avgPrice": "1812.70004844",
"liqPrice": "1550.80",
"bustPrice": "1544.20",
"markPrice": "1812.90",
"leverage": "12",
"autoAddMargin": 0,
"positionStatus": "Normal",
"positionIM": "0.01926611",
"positionMM": "0",
"unrealisedPnl": "0.00001217",
"cumRealisedPnl": "-0.04618929",
"stopLoss": "0.00",
"takeProfit": "0.00",
"trailingStop": "0.00",
"createdTime": "1672737740039",
"updatedTime": "1684234363788"
},
"retExtInfo": {},
"time": 1684234363789
}
12 changes: 12 additions & 0 deletions Bybit.UnitTests/Endpoints/V5Api/Account/CancelWithdrawal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
POST
/v5/asset/withdraw/cancel
true
{
"retCode": 0,
"retMsg": "success",
"result": {
"status": 1
},
"retExtInfo": {},
"time": 1672197228408
}
10 changes: 10 additions & 0 deletions Bybit.UnitTests/Endpoints/V5Api/Account/DeleteApiKey.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POST
/v5/user/delete-api
true
{
"retCode": 0,
"retMsg": "",
"result": {},
"retExtInfo": {},
"time": 1676431577675
}
Loading

0 comments on commit 1ddba02

Please sign in to comment.