Skip to content

Commit d246b46

Browse files
authored
Feature/orderbook (#285)
Updated CryptoExchange.Net to version 10.2.0 Added SequenceNumber to order book websocket updates Added small balances convert endpoints Added restClient.V5Api.Account.Get/SetSpotMarginAutoRepayModeAsync endpoints Added ParentOrderId to BybitOrder model Removed MaxBalance property from BybitAdlAlert model as its deprecated
1 parent a8cb01c commit d246b46

23 files changed

+891
-11
lines changed

ByBit.Net/Bybit.Net.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
<None Include="..\README.md" Pack="true" PackagePath="\" />
4949
</ItemGroup>
5050
<ItemGroup>
51-
<PackageReference Include="CryptoExchange.Net" Version="10.1.0" />
5251
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="5.0.0.1">
5352
<PrivateAssets>all</PrivateAssets>
5453
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
5554
</PackageReference>
55+
<PackageReference Include="CryptoExchange.Net" Version="10.2.0" />
5656
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.101">
5757
<PrivateAssets>all</PrivateAssets>
5858
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

ByBit.Net/Clients/V5/BybitRestClientApiAccount.cs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,37 @@ public async Task<WebCallResult<BybitSpotMarginBorrowRate[]>> GetSpotMarginInter
10661066

10671067
#endregion
10681068

1069+
#region Set Spot Margin Auto Repay Mode
1070+
1071+
/// <inheritdoc />
1072+
public async Task<WebCallResult<BybitSpotMarginAutoRepayMode[]>> SetSpotMarginAutoRepayModeAsync(bool enabled, string? asset = null, CancellationToken ct = default)
1073+
{
1074+
var parameters = new ParameterCollection();
1075+
parameters.AddOptional("currency", asset);
1076+
parameters.Add("autoRepayMode", enabled ? "1" : "0");
1077+
1078+
var request = _definitions.GetOrCreate(HttpMethod.Post, "v5/spot-margin-trade/set-auto-repay-mode", BybitExchange.RateLimiter.BybitRest, 1, true);
1079+
var result = await _baseClient.SendAsync<BybitSpotMarginAutoRepayModeWrapper>(request, parameters, ct).ConfigureAwait(false);
1080+
return result.As<BybitSpotMarginAutoRepayMode[]>(result.Data?.Data);
1081+
}
1082+
1083+
#endregion
1084+
1085+
#region Get Spot Margin Auto Repay Mode
1086+
1087+
/// <inheritdoc />
1088+
public async Task<WebCallResult<BybitSpotMarginAutoRepayMode[]>> GetSpotMarginAutoRepayModeAsync(string? asset = null, CancellationToken ct = default)
1089+
{
1090+
var parameters = new ParameterCollection();
1091+
parameters.AddOptional("currency", asset);
1092+
1093+
var request = _definitions.GetOrCreate(HttpMethod.Get, "v5/spot-margin-trade/get-auto-repay-mode", BybitExchange.RateLimiter.BybitRest, 1, true);
1094+
var result = await _baseClient.SendAsync<BybitSpotMarginAutoRepayModeWrapper>(request, parameters, ct).ConfigureAwait(false);
1095+
return result.As<BybitSpotMarginAutoRepayMode[]>(result.Data?.Data);
1096+
}
1097+
1098+
#endregion
1099+
10691100
#region Get Broker Account Info
10701101

10711102
/// <inheritdoc />
@@ -1336,5 +1367,89 @@ public async Task<WebCallResult<BybitResponse<BybitWithdrawAddress>>> GetWithdra
13361367
}
13371368

13381369
#endregion
1370+
1371+
#region Get Small Balance Assets
1372+
1373+
/// <inheritdoc />
1374+
public async Task<WebCallResult<BybitSmallBalanceAssets>> GetSmallBalanceAssetsAsync(
1375+
ConvertAccountType accountType,
1376+
string? fromAsset = null,
1377+
CancellationToken ct = default)
1378+
{
1379+
var parameters = new ParameterCollection();
1380+
parameters.AddEnum("accountType", accountType);
1381+
parameters.AddOptional("fromCoin", fromAsset);
1382+
1383+
var request = _definitions.GetOrCreate(HttpMethod.Get, "/v5/asset/covert/small-balance-list", BybitExchange.RateLimiter.BybitRest, 1, true,
1384+
limitGuard: new SingleLimitGuard(10, TimeSpan.FromSeconds(1), RateLimitWindowType.Sliding, null, SingleLimitGuard.PerApiKey));
1385+
return await _baseClient.SendAsync<BybitSmallBalanceAssets>(request, parameters, ct).ConfigureAwait(false);
1386+
}
1387+
1388+
#endregion
1389+
1390+
#region Get Small Balances Quote
1391+
1392+
/// <inheritdoc />
1393+
public async Task<WebCallResult<BybitSmallBalancesQuote>> GetSmallBalancesQuoteAsync(
1394+
ConvertAccountType accountType,
1395+
IEnumerable<string> fromAssets,
1396+
string toAsset,
1397+
CancellationToken ct = default)
1398+
{
1399+
var parameters = new ParameterCollection();
1400+
parameters.AddEnum("accountType", accountType);
1401+
parameters.Add("fromCoinList", fromAssets.ToArray());
1402+
parameters.Add("toCoin", toAsset);
1403+
1404+
var request = _definitions.GetOrCreate(HttpMethod.Post, "/v5/asset/covert/get-quote", BybitExchange.RateLimiter.BybitRest, 1, true,
1405+
limitGuard: new SingleLimitGuard(5, TimeSpan.FromSeconds(1), RateLimitWindowType.Sliding, null, SingleLimitGuard.PerApiKey));
1406+
return await _baseClient.SendAsync<BybitSmallBalancesQuote>(request, parameters, ct).ConfigureAwait(false);
1407+
}
1408+
1409+
#endregion
1410+
1411+
#region Confirm Small Balances Quote
1412+
1413+
/// <inheritdoc />
1414+
public async Task<WebCallResult<BybitSmallBalancesQuoteResult>> ConfirmSmallBalancesQuoteAsync(
1415+
string quoteId,
1416+
CancellationToken ct = default)
1417+
{
1418+
var parameters = new ParameterCollection();
1419+
parameters.Add("quoteId", quoteId);
1420+
1421+
var request = _definitions.GetOrCreate(HttpMethod.Post, "/v5/asset/covert/small-balance-execute", BybitExchange.RateLimiter.BybitRest, 1, true,
1422+
limitGuard: new SingleLimitGuard(5, TimeSpan.FromSeconds(1), RateLimitWindowType.Sliding, null, SingleLimitGuard.PerApiKey));
1423+
return await _baseClient.SendAsync<BybitSmallBalancesQuoteResult>(request, parameters, ct).ConfigureAwait(false);
1424+
}
1425+
1426+
#endregion
1427+
1428+
#region Get Small Balance Exchange History
1429+
1430+
/// <inheritdoc />
1431+
public async Task<WebCallResult<BybitPage<BybitSmallBalancesExchangeItem>>> GetSmallBalancesExchangeHistoryAsync(
1432+
ConvertAccountType? accountType = null,
1433+
string? quoteId = null,
1434+
DateTime? startTime = null,
1435+
DateTime? endTime = null,
1436+
int? page = null,
1437+
int? pageSize = null,
1438+
CancellationToken ct = default)
1439+
{
1440+
var parameters = new ParameterCollection();
1441+
parameters.AddOptionalEnum("accountType", accountType);
1442+
parameters.AddOptional("quoteId", quoteId);
1443+
parameters.AddOptionalMilliseconds("startTime", startTime);
1444+
parameters.AddOptionalMilliseconds("endTime", endTime);
1445+
parameters.AddOptional("cursor", page);
1446+
parameters.AddOptional("size", pageSize);
1447+
1448+
var request = _definitions.GetOrCreate(HttpMethod.Get, "/v5/asset/covert/small-balance-history", BybitExchange.RateLimiter.BybitRest, 1, true,
1449+
limitGuard: new SingleLimitGuard(10, TimeSpan.FromSeconds(1), RateLimitWindowType.Sliding, null, SingleLimitGuard.PerApiKey));
1450+
return await _baseClient.SendAsync<BybitPage<BybitSmallBalancesExchangeItem>>(request, parameters, ct).ConfigureAwait(false);
1451+
}
1452+
1453+
#endregion
13391454
}
13401455
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Bybit.Net.Converters
2+
{
3+
internal class Bool12Converter : IntBoolConverter
4+
{
5+
public Bool12Converter(int trueValue) : base(1)
6+
{
7+
}
8+
}
9+
}

ByBit.Net/Converters/BybitSourceGenerationContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
namespace Bybit.Net.Converters
99
{
10+
[JsonSerializable(typeof(BybitResult<BybitSmallBalanceAssets>))]
11+
[JsonSerializable(typeof(BybitResult<BybitSmallBalancesQuote>))]
12+
[JsonSerializable(typeof(BybitResult<BybitSmallBalancesQuoteResult>))]
13+
[JsonSerializable(typeof(BybitResult<BybitPage<BybitSmallBalancesExchangeItem>>))]
14+
[JsonSerializable(typeof(BybitResult<BybitSpotMarginAutoRepayModeWrapper>))]
15+
1016
[JsonSerializable(typeof(BybitExtResult<BybitList<BybitBatchOrderId>, BybitList<BybitBatchResult>>))]
1117
[JsonSerializable(typeof(BybitRequestQueryResponse<BybitList<BybitBatchOrderId>, BybitList<BybitBatchResult>>))]
1218
[JsonSerializable(typeof(BybitRequestQueryResponse<object>))]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Text.Json.Serialization;
2+
using CryptoExchange.Net.Attributes;
3+
4+
namespace Bybit.Net.Enums
5+
{
6+
/// <summary>
7+
/// Small balance exchange status
8+
/// </summary>
9+
[JsonConverter(typeof(EnumConverter<SmallBalanceConvertStatus>))]
10+
public enum SmallBalanceConvertStatus
11+
{
12+
/// <summary>
13+
/// Initial
14+
/// </summary>
15+
[Map("init")]
16+
Init,
17+
/// <summary>
18+
/// Processing
19+
/// </summary>
20+
[Map("processing")]
21+
Processing,
22+
/// <summary>
23+
/// Success
24+
/// </summary>
25+
[Map("success")]
26+
Success,
27+
/// <summary>
28+
/// Failure
29+
/// </summary>
30+
[Map("failure")]
31+
Failure,
32+
/// <summary>
33+
/// Partially filled
34+
/// </summary>
35+
[Map("partial_fulfillment")]
36+
PartiallyFilled
37+
}
38+
}

ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiAccount.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,5 +747,78 @@ Task<WebCallResult<BybitResponse<BybitWithdrawAddress>>> GetWithdrawAddressListA
747747
int? limit = null,
748748
string? cursor = null,
749749
CancellationToken ct = default);
750+
751+
/// <summary>
752+
/// Get small balance assets
753+
/// <para><a href="https://bybit-exchange.github.io/docs/v5/asset/convert-small-balance/small-balanc-coins" /></para>
754+
/// </summary>
755+
/// <param name="accountType">Account type</param>
756+
/// <param name="fromAsset">From asset filter</param>
757+
/// <param name="ct">Cancellation token</param>
758+
Task<WebCallResult<BybitSmallBalanceAssets>> GetSmallBalanceAssetsAsync(
759+
ConvertAccountType accountType,
760+
string? fromAsset = null,
761+
CancellationToken ct = default);
762+
763+
/// <summary>
764+
/// Get small balance exchange quote
765+
/// <para><a href="https://bybit-exchange.github.io/docs/v5/asset/convert-small-balance/request-quote" /></para>
766+
/// </summary>
767+
/// <param name="accountType">Account type</param>
768+
/// <param name="fromAssets">Assets to convert</param>
769+
/// <param name="toAsset">Output asset</param>
770+
/// <param name="ct">Cancellation token</param>
771+
Task<WebCallResult<BybitSmallBalancesQuote>> GetSmallBalancesQuoteAsync(
772+
ConvertAccountType accountType,
773+
IEnumerable<string> fromAssets,
774+
string toAsset,
775+
CancellationToken ct = default);
776+
777+
/// <summary>
778+
/// Confirm small balances exchange quote
779+
/// <para><a href="https://bybit-exchange.github.io/docs/v5/asset/convert-small-balance/confirm-quote" /></para>
780+
/// </summary>
781+
/// <param name="quoteId">Quote id</param>
782+
/// <param name="ct">Cancellation token</param>
783+
Task<WebCallResult<BybitSmallBalancesQuoteResult>> ConfirmSmallBalancesQuoteAsync(
784+
string quoteId,
785+
CancellationToken ct = default);
786+
787+
/// <summary>
788+
/// Get small balances exchange history
789+
/// <para><a href="https://bybit-exchange.github.io/docs/v5/asset/convert-small-balance/exchange-history" /></para>
790+
/// </summary>
791+
/// <param name="accountType">Filter by account</param>
792+
/// <param name="quoteId">Filter by quote id</param>
793+
/// <param name="startTime">Filter by start time</param>
794+
/// <param name="endTime">Filter by end time</param>
795+
/// <param name="page">Page number</param>
796+
/// <param name="pageSize">Page size</param>
797+
/// <param name="ct">Cancellation token</param>
798+
Task<WebCallResult<BybitPage<BybitSmallBalancesExchangeItem>>> GetSmallBalancesExchangeHistoryAsync(
799+
ConvertAccountType? accountType = null,
800+
string? quoteId = null,
801+
DateTime? startTime = null,
802+
DateTime? endTime = null,
803+
int? page = null,
804+
int? pageSize = null,
805+
CancellationToken ct = default);
806+
807+
/// <summary>
808+
/// Set Spot Margin auto repay mode
809+
/// <para><a href="https://bybit-exchange.github.io/docs/v5/spot-margin-uta/set-auto-repay-mode" /></para>
810+
/// </summary>
811+
/// <param name="asset">Asset. If not provided set for all assets</param>
812+
/// <param name="enabled">Enable or not</param>
813+
/// <param name="ct">Cancellation token</param>
814+
Task<WebCallResult<BybitSpotMarginAutoRepayMode[]>> SetSpotMarginAutoRepayModeAsync(bool enabled, string? asset = null, CancellationToken ct = default);
815+
816+
/// <summary>
817+
/// Get Spot Margin auto repay mode
818+
/// <para><a href="https://bybit-exchange.github.io/docs/v5/spot-margin-uta/get-auto-repay-mode" /></para>
819+
/// </summary>
820+
/// <param name="asset">Asset. If not provided get mode for all assets</param>
821+
/// <param name="ct">Cancellation token</param>
822+
Task<WebCallResult<BybitSpotMarginAutoRepayMode[]>> GetSpotMarginAutoRepayModeAsync(string? asset = null, CancellationToken ct = default);
750823
}
751824
}

ByBit.Net/Objects/Models/V5/BybitAdlAlert.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ public record BybitAdlAlert
3131
[JsonInclude, JsonPropertyName("b")]
3232
internal decimal WSBalance { set => Balance = value; }
3333

34-
/// <summary>
35-
/// Maximum balance of the insurance pool in the last 8 hours
36-
/// </summary>
37-
[JsonPropertyName("maxBalance")]
38-
public decimal MaxBalance { get; set; }
39-
[JsonInclude, JsonPropertyName("mb")]
40-
internal decimal WSMaxBalance { set => MaxBalance = value; }
41-
4234
/// <summary>
4335
/// PnL ratio threshold for triggering contract PnL drawdown ADL
4436
/// </summary>

ByBit.Net/Objects/Models/V5/BybitOrder.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public record BybitOrder
2222
[JsonPropertyName("orderLinkId")]
2323
public string? ClientOrderId { get; set; }
2424
/// <summary>
25+
/// Linked parent order for stop loss / take profit orders for futures/options orders
26+
/// </summary>
27+
[JsonPropertyName("parentOrderLinkId")]
28+
public string? ParentOrderId { get; set; }
29+
/// <summary>
2530
/// Block trade id
2631
/// </summary>
2732
[JsonPropertyName("blockTradeId")]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Bybit.Net.Objects.Models.V5
9+
{
10+
/// <summary>
11+
/// Bybit page
12+
/// </summary>
13+
public record BybitPage<T>
14+
{
15+
/// <summary>
16+
/// Current page
17+
/// </summary>
18+
[JsonPropertyName("cursor")]
19+
public int Page { get; set; }
20+
/// <summary>
21+
/// Page size
22+
/// </summary>
23+
[JsonPropertyName("size")]
24+
public int PageSize { get; set; }
25+
/// <summary>
26+
/// Last page
27+
/// </summary>
28+
[JsonPropertyName("lastPage")]
29+
public int LastPage { get; set; }
30+
/// <summary>
31+
/// Total count
32+
/// </summary>
33+
[JsonPropertyName("totalCount")]
34+
public int Total { get; set; }
35+
/// <summary>
36+
/// Page records
37+
/// </summary>
38+
[JsonPropertyName("records")]
39+
public T[] Records { get; set; } = [];
40+
}
41+
}

0 commit comments

Comments
 (0)