Skip to content

Commit

Permalink
Added/updated DCP configuration endpoints and subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Jun 18, 2024
1 parent 3d40a1c commit 74a396c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 4 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
11 changes: 10 additions & 1 deletion ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bybit.Net.Interfaces.Clients.V5;
using Bybit.Net.Enums;
using Bybit.Net.Interfaces.Clients.V5;
using Bybit.Net.Objects.Models.V5;
using Bybit.Net.Objects.Options;
using Bybit.Net.Objects.Sockets.Queries;
Expand Down Expand Up @@ -108,5 +109,13 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToGreekUpdatesAsync(A
var subscription = new BybitSubscription<IEnumerable<BybitGreeks>>(_logger, new[] { "greeks" }, handler, true);
return await SubscribeAsync(BaseAddress.AppendPath("/v5/private"), subscription, ct).ConfigureAwait(false);
}

/// <inheritdoc />
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
12 changes: 11 additions & 1 deletion ByBit.Net/Interfaces/Clients/V5/IBybitSocketClientPrivateApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bybit.Net.Objects.Models.V5;
using Bybit.Net.Enums;
using Bybit.Net.Objects.Models.V5;
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Objects.Sockets;
Expand Down Expand Up @@ -67,5 +68,14 @@ public interface IBybitSocketClientPrivateApi : ISocketApiClient
/// <param name="ct">Cancellation token. Cancelling will cancel the subscription</param>
/// <returns></returns>
Task<CallResult<UpdateSubscription>> SubscribeToWalletUpdatesAsync(Action<DataEvent<IEnumerable<BybitBalance>>> handler, CancellationToken ct = default);

/// <summary>
/// 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>
/// <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 74a396c

Please sign in to comment.