Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/JKorf/Bybit.Net
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Jun 19, 2024
2 parents 680a478 + 74a396c commit f4d11ae
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 2 deletions.
15 changes: 14 additions & 1 deletion ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,31 @@ public async Task<WebCallResult<BybitBorrowQuota>> GetBorrowQuotaAsync(
/// <inheritdoc />
public async Task<WebCallResult> SetDisconnectCancelAllAsync(
int windowSeconds,
ProductType? productType = null,
CancellationToken ct = default)
{
var parameters = new Dictionary<string, object>()
var parameters = new ParameterCollection
{
{ "timeWindow", windowSeconds },
};
parameters.AddOptionalEnum("product", productType);

return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v5/order/disconnected-cancel-all"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}

#endregion

#region Get Disconnect Cancel All

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<BybitDcpStatus>>> GetDisconnectCancelAllConfigAsync(CancellationToken ct = default)
{
var result = await _baseClient.SendRequestAsync<BybitDcpStatusWrapper>(_baseClient.GetUrl("v5/account/query-dcp-info"), HttpMethod.Get, ct, null, true).ConfigureAwait(false);
return result.As<IEnumerable<BybitDcpStatus>>(result.Data?.Infos);
}

#endregion

#region Get User Trades

/// <inheritdoc />
Expand Down
7 changes: 7 additions & 0 deletions ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ public async Task<CallResult<BybitOrderId>> CancelOrderAsync(Category category,
});

return await QueryAsync(BaseAddress.AppendPath("/v5/trade"), query, ct).ConfigureAwait(false);
}

public async Task<CallResult<UpdateSubscription>> SubscribeToDisconnectCancelAllTopicAsync(ProductType productType, CancellationToken ct = default)
{
var product = productType == ProductType.Spot ? "spot" : productType == ProductType.Options ? "option" : "future";
var subscription = new BybitSubscription<object>(_logger, new[] { "dcp." + product }, x => { }, true);
return await SubscribeAsync(BaseAddress.AppendPath("/v5/private"), subscription, ct).ConfigureAwait(false);
}
}
}
29 changes: 29 additions & 0 deletions ByBit.Net/Enums/ProductType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CryptoExchange.Net.Attributes;
using System;
using System.Collections.Generic;
using System.Text;

namespace Bybit.Net.Enums
{
/// <summary>
/// Product type
/// </summary>
public enum ProductType
{
/// <summary>
/// Options
/// </summary>
[Map("OPTIONS")]
Options,
/// <summary>
/// Derivatives
/// </summary>
[Map("DERIVATIVES")]
Derivatives,
/// <summary>
/// Spot
/// </summary>
[Map("SPOT")]
Spot
}
}
11 changes: 10 additions & 1 deletion ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,18 @@ Task<WebCallResult<BybitOrderId>> PlaceOrderAsync(
/// <para><a href="https://bybit-exchange.github.io/docs/v5/order/dcp" /></para>
/// </summary>
/// <param name="windowSeconds">Time after which to cancel all orders</param>
/// <param name="productType">Type of product, defaults to Options</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult> SetDisconnectCancelAllAsync(int windowSeconds, CancellationToken ct = default);
Task<WebCallResult> SetDisconnectCancelAllAsync(int windowSeconds, ProductType? productType = null, CancellationToken ct = default);

/// <summary>
/// Get DiconnectCancelAll/dcp configuration
/// <para><a href="https://bybit-exchange.github.io/docs/v5/account/dcp-info" /></para>
/// </summary>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<BybitDcpStatus>>> GetDisconnectCancelAllConfigAsync(CancellationToken ct = default);

/// <summary>
/// Set trading stop parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,13 @@ Task<CallResult<BybitOrderId>> CancelOrderAsync(Category category,
string? clientOrderId = null,
OrderFilter? orderFilter = null,
CancellationToken ct = default);

/// Subscribe to disconnect cancel all topics. It doesn't provide updates, but works with the <see href="https://bybit-exchange.github.io/docs/v5/order/dcp">DisconnectCancelAll</see> configuration
/// <para><a href="https://bybit-exchange.github.io/docs/v5/websocket/private/dcp" /></para>
/// </summary>

Check warning on line 199 in ByBit.Net/Interfaces/Clients/V5/IBybitSocketClientPrivateApi.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'End tag was not expected at this location.'

Check warning on line 199 in ByBit.Net/Interfaces/Clients/V5/IBybitSocketClientPrivateApi.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'End tag was not expected at this location.'

Check warning on line 199 in ByBit.Net/Interfaces/Clients/V5/IBybitSocketClientPrivateApi.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'End tag was not expected at this location.'

Check warning on line 199 in ByBit.Net/Interfaces/Clients/V5/IBybitSocketClientPrivateApi.cs

View workflow job for this annotation

GitHub Actions / build

XML comment has badly formed XML -- 'End tag was not expected at this location.'
/// <param name="productType">Product type</param>
/// <param name="ct">Cancellation token. Cancelling will cancel the subscription</param>
/// <returns></returns>
Task<CallResult<UpdateSubscription>> SubscribeToDisconnectCancelAllTopicAsync(ProductType productType, CancellationToken ct = default);
}
}
36 changes: 36 additions & 0 deletions ByBit.Net/Objects/Models/V5/BybitDcpStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Bybit.Net.Enums;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Bybit.Net.Objects.Models.V5
{
internal record BybitDcpStatusWrapper
{
[JsonProperty("dcpInfos")]
public IEnumerable<BybitDcpStatus> Infos { get; set; } = Array.Empty<BybitDcpStatus>();
}

/// <summary>
/// Dcp status
/// </summary>
public record BybitDcpStatus
{
/// <summary>
/// Product types
/// </summary>
[JsonProperty("product")]
public ProductType Product { get; set; }
/// <summary>
/// Is activated
/// </summary>
[JsonProperty("dcpStatus"), JsonConverter(typeof(BoolConverter))]
public bool Activated { get; set; }
/// <summary>
/// Timewindow in seconds
/// </summary>
[JsonProperty("timeWindow")]
public int? TimeWindow { get; set; }
}
}

0 comments on commit f4d11ae

Please sign in to comment.