From be36ad5a5f953d5a9f095d034ed79245ebf47510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20F=C3=BCrst?= Date: Tue, 1 Aug 2023 17:47:18 +0200 Subject: [PATCH 1/4] fix json deserialization issue when LiquidationPrice is null bybit API will return positions with avg. price and other fields set to null --- ByBit.Net/Objects/Models/BybitPositionBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ByBit.Net/Objects/Models/BybitPositionBase.cs b/ByBit.Net/Objects/Models/BybitPositionBase.cs index d29b38fb..f772a576 100644 --- a/ByBit.Net/Objects/Models/BybitPositionBase.cs +++ b/ByBit.Net/Objects/Models/BybitPositionBase.cs @@ -56,7 +56,7 @@ public class BybitPositionBase /// Liquidation price /// [JsonProperty("liq_price")] - public decimal LiquidationPrice { get; set; } + public decimal? LiquidationPrice { get; set; } /// /// Bankruptcy price /// From c2aa0179bc2243c35fac9216a2d19dfa64736686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20F=C3=BCrst?= Date: Tue, 1 Aug 2023 17:48:52 +0200 Subject: [PATCH 2/4] BybitRestClientApiTrading: add takeProfitOrderType and stopLossOrderType parameters defaults are set to TP/Limit and SL/Market as is to be expected on most markets --- ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs | 14 ++++++++++++-- .../Clients/V5/IBybitRestClientApiTrading.cs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs b/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs index 35e547a5..cc3fe07b 100644 --- a/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs +++ b/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs @@ -44,14 +44,17 @@ internal BybitRestClientApiTrading(BybitRestClientApi baseClient) Enums.V5.PositionIdx? positionIdx = null, string? clientOrderId = null, decimal? takeProfit = null, + OrderType takeProfitOrderType = OrderType.Limit, decimal? stopLoss = null, + OrderType stopLossOrderType = OrderType.Market, TriggerType? takeProfitTriggerBy = null, TriggerType? stopLossTriggerBy = null, bool? reduceOnly = null, bool? closeOnTrigger = null, bool? marketMakerProtection = null, - StopLossTakeProfitMode? stopLossTakeProfitMode = null, - CancellationToken ct = default) + StopLossTakeProfitMode? stopLossTakeProfitMode = null, + CancellationToken ct = default + ) { var parameters = new Dictionary() { @@ -81,6 +84,8 @@ internal BybitRestClientApiTrading(BybitRestClientApi baseClient) parameters.AddOptionalParameter("closeOnTrigger", closeOnTrigger?.ToString().ToLowerInvariant()); parameters.AddOptionalParameter("mmp", marketMakerProtection?.ToString().ToLowerInvariant()); parameters.AddOptionalParameter("tpslMode", EnumConverter.GetString(stopLossTakeProfitMode)); + parameters.AddOptionalParameter("tpOrderType", EnumConverter.GetString(takeProfitOrderType )); + parameters.AddOptionalParameter("slOrderType", EnumConverter.GetString(stopLossOrderType)); return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v5/order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); } @@ -517,6 +522,11 @@ public async Task SetTradingStopAsync( return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v5/position/trading-stop"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); } + public Task?> PlaceOrderAsync(Category linear, string symbolName, OrderSide orderSide, NewOrderType value1, decimal quantity, decimal price, bool v, object value2, object value3, object value4, object value5, object value6, TimeInForce postOnly, PositionIdx positionMode, string orderId, decimal takeProfit, object stopLoss, TriggerType lastPrice1, TriggerType lastPrice2, object value7, object value8, object value9, StopLossTakeProfitMode partial, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + #endregion } } diff --git a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs index 3aeb20b0..02589549 100644 --- a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs +++ b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs @@ -205,7 +205,7 @@ public interface IBybitRestClientApiTrading /// StopLoss / TakeProfit mode /// Cancellation token /// - Task> PlaceOrderAsync(Category category, string symbol, OrderSide side, NewOrderType type, decimal quantity, decimal? price = null, bool? isLeverage = null, TriggerDirection? triggerDirection = null, OrderFilter? orderFilter = null, decimal? triggerPrice = null, TriggerType? triggerBy = null, decimal? orderIv = null, TimeInForce? timeInForce = null, Enums.V5.PositionIdx? positionIdx = null, string? clientOrderId = null, decimal? takeProfit = null, decimal? stopLoss = null, TriggerType? takeProfitTriggerBy = null, TriggerType? stopLossTriggerBy = null, bool? reduceOnly = null, bool? closeOnTrigger = null, bool? marketMakerProtection = null, StopLossTakeProfitMode? stopLossTakeProfitMode = null, CancellationToken ct = default); + Task> PlaceOrderAsync(Category category, string symbol, OrderSide side, NewOrderType type, decimal quantity, decimal? price = null, bool? isLeverage = null, TriggerDirection? triggerDirection = null, OrderFilter? orderFilter = null, decimal? triggerPrice = null, TriggerType? triggerBy = null, decimal? orderIv = null, TimeInForce? timeInForce = null, Enums.V5.PositionIdx? positionIdx = null, string? clientOrderId = null, decimal? takeProfit = null, OrderType takeProfitOrderType = OrderType.Limit, decimal? stopLoss = null, OrderType stopLossOrderType = OrderType.Market, TriggerType? takeProfitTriggerBy = null, TriggerType? stopLossTriggerBy = null, bool? reduceOnly = null, bool? closeOnTrigger = null, bool? marketMakerProtection = null, StopLossTakeProfitMode? stopLossTakeProfitMode = null, CancellationToken ct = default); /// /// Set cancel all timeout on websocket disconnect From 8041f9a386254c364d574d7a5b182cc56d213928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20F=C3=BCrst?= Date: Tue, 1 Aug 2023 18:22:20 +0200 Subject: [PATCH 3/4] BybitRestClientApiTrading: add takeProfitOrderType and stopLossOrderType parameters defaults are set to TP/Limit and SL/Market as is to be expected on most markets --- ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs | 8 ++++++-- .../Interfaces/Clients/V5/IBybitRestClientApiTrading.cs | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs b/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs index cc3fe07b..22018d1c 100644 --- a/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs +++ b/ByBit.Net/Clients/V5/BybitRestClientApiTrading.cs @@ -43,10 +43,12 @@ internal BybitRestClientApiTrading(BybitRestClientApi baseClient) TimeInForce? timeInForce = null, Enums.V5.PositionIdx? positionIdx = null, string? clientOrderId = null, - decimal? takeProfit = null, OrderType takeProfitOrderType = OrderType.Limit, - decimal? stopLoss = null, + decimal? takeProfit = null, + decimal? takeProfitLimitPrice = null, OrderType stopLossOrderType = OrderType.Market, + decimal? stopLoss = null, + decimal? stopLossLimitPrice = null, TriggerType? takeProfitTriggerBy = null, TriggerType? stopLossTriggerBy = null, bool? reduceOnly = null, @@ -86,6 +88,8 @@ internal BybitRestClientApiTrading(BybitRestClientApi baseClient) parameters.AddOptionalParameter("tpslMode", EnumConverter.GetString(stopLossTakeProfitMode)); parameters.AddOptionalParameter("tpOrderType", EnumConverter.GetString(takeProfitOrderType )); parameters.AddOptionalParameter("slOrderType", EnumConverter.GetString(stopLossOrderType)); + parameters.AddOptionalParameter("tpLimitPrice", takeProfitLimitPrice?.ToString(CultureInfo.InvariantCulture)); + parameters.AddOptionalParameter("slLimitPrice", stopLossLimitPrice?.ToString(CultureInfo.InvariantCulture)); return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v5/order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); } diff --git a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs index 02589549..a34bb031 100644 --- a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs +++ b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiTrading.cs @@ -195,8 +195,12 @@ public interface IBybitRestClientApiTrading /// Time in force /// Position idx /// Client order id + /// /// Take profit price + /// + /// /// Stop loss price + /// /// Take profit trigger /// Stop loss trigger /// Is reduce only @@ -205,7 +209,7 @@ public interface IBybitRestClientApiTrading /// StopLoss / TakeProfit mode /// Cancellation token /// - Task> PlaceOrderAsync(Category category, string symbol, OrderSide side, NewOrderType type, decimal quantity, decimal? price = null, bool? isLeverage = null, TriggerDirection? triggerDirection = null, OrderFilter? orderFilter = null, decimal? triggerPrice = null, TriggerType? triggerBy = null, decimal? orderIv = null, TimeInForce? timeInForce = null, Enums.V5.PositionIdx? positionIdx = null, string? clientOrderId = null, decimal? takeProfit = null, OrderType takeProfitOrderType = OrderType.Limit, decimal? stopLoss = null, OrderType stopLossOrderType = OrderType.Market, TriggerType? takeProfitTriggerBy = null, TriggerType? stopLossTriggerBy = null, bool? reduceOnly = null, bool? closeOnTrigger = null, bool? marketMakerProtection = null, StopLossTakeProfitMode? stopLossTakeProfitMode = null, CancellationToken ct = default); + Task> PlaceOrderAsync(Category category, string symbol, OrderSide side, NewOrderType type, decimal quantity, decimal? price = null, bool? isLeverage = null, TriggerDirection? triggerDirection = null, OrderFilter? orderFilter = null, decimal? triggerPrice = null, TriggerType? triggerBy = null, decimal? orderIv = null, TimeInForce? timeInForce = null, Enums.V5.PositionIdx? positionIdx = null, string? clientOrderId = null, OrderType takeProfitOrderType = OrderType.Limit, decimal? takeProfit = null, decimal? takeProfitLimitPrice = null, OrderType stopLossOrderType = OrderType.Market, decimal? stopLoss = null, decimal? stopLossLimitPrice = null, TriggerType? takeProfitTriggerBy = null, TriggerType? stopLossTriggerBy = null, bool? reduceOnly = null, bool? closeOnTrigger = null, bool? marketMakerProtection = null, StopLossTakeProfitMode? stopLossTakeProfitMode = null, CancellationToken ct = default); /// /// Set cancel all timeout on websocket disconnect From 2728c539a2e6b42d5f96f5d9c016a24fd80f43e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan=20F=C3=BCrst?= Date: Thu, 8 Feb 2024 21:55:30 +0100 Subject: [PATCH 4/4] upgrade CryptoExchange.Net ahead of bybit.net --- ByBit.Net/Bybit.Net.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ByBit.Net/Bybit.Net.csproj b/ByBit.Net/Bybit.Net.csproj index c934a63a..32a727f4 100644 --- a/ByBit.Net/Bybit.Net.csproj +++ b/ByBit.Net/Bybit.Net.csproj @@ -54,6 +54,6 @@ - + \ No newline at end of file