From 9585ba9c8bb7ced2ccb664ffb3939293ef9aecd4 Mon Sep 17 00:00:00 2001 From: TarasMi Date: Mon, 3 Apr 2023 00:22:36 +0000 Subject: [PATCH] [Bybit] Changed bybit exchange names (#802) * Implementation of Bybit V5 unified API Implemented main private and public methods, some public (candles and orderbook) and private WebSockets. A decision was made to split spot, inverse, linear, and option branches into different APIs because: 1) market symbols intersect, 2) there are no any method to get all the markets (all orders, all positions) from different branches in one call. Branches behave as separate exchanges. * [Bybit] Changed bybit exchange names Added custom names instead of generic Bybit that was used previously, to get bybit exchange branches by name in ExchangeAPI.GetExchangeAPIAsync<>(). Also minor refactoring. --- .../API/Exchanges/Bybit/ExchangeBybitInverseAPI.cs | 2 +- .../API/Exchanges/Bybit/ExchangeBybitLinearAPI.cs | 2 +- .../API/Exchanges/Bybit/ExchangeBybitOptionAPI.cs | 2 +- .../API/Exchanges/Bybit/ExchangeBybitSpotAPI.cs | 2 +- .../API/Exchanges/Bybit/ExchangeBybitV5Base.cs | 11 ++++++++--- src/ExchangeSharp/Model/ExchangeOrderBook.cs | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitInverseAPI.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitInverseAPI.cs index 82fc49fe..3250daaf 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitInverseAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitInverseAPI.cs @@ -5,7 +5,6 @@ namespace ExchangeSharp { - [ApiName(ExchangeName.Bybit)] public class ExchangeBybitInverseAPI : ExchangeBybitV5Base { protected override MarketCategory MarketCategory => MarketCategory.Inverse; @@ -18,4 +17,5 @@ public ExchangeBybitInverseAPI(bool isUnifiedAccount) IsUnifiedAccount = isUnifiedAccount; } } + public partial class ExchangeName { public const string BybitInverse = "BybitInverse"; } } diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitLinearAPI.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitLinearAPI.cs index 723827a1..49458d09 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitLinearAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitLinearAPI.cs @@ -5,7 +5,6 @@ namespace ExchangeSharp { - [ApiName(ExchangeName.Bybit)] public class ExchangeBybitLinearAPI : ExchangeBybitV5Base { protected override MarketCategory MarketCategory => MarketCategory.Linear; @@ -18,4 +17,5 @@ public ExchangeBybitLinearAPI(bool isUnifiedAccount) IsUnifiedAccount = isUnifiedAccount; } } + public partial class ExchangeName { public const string BybitLinear = "BybitLinear"; } } diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitOptionAPI.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitOptionAPI.cs index 1cd1252c..fbeba34d 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitOptionAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitOptionAPI.cs @@ -5,7 +5,6 @@ namespace ExchangeSharp { - [ApiName(ExchangeName.Bybit)] public class ExchangeBybitOptionAPI : ExchangeBybitV5Base { protected override MarketCategory MarketCategory => MarketCategory.Option; @@ -18,4 +17,5 @@ public ExchangeBybitOptionAPI(bool isUnifiedAccount) IsUnifiedAccount = isUnifiedAccount; } } + public partial class ExchangeName { public const string BybitOption = "BybitOption"; } } diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitSpotAPI.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitSpotAPI.cs index 90bb9c9b..2d2faf49 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitSpotAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitSpotAPI.cs @@ -5,7 +5,6 @@ namespace ExchangeSharp { - [ApiName(ExchangeName.Bybit)] public class ExchangeBybitSpotAPI : ExchangeBybitV5Base { protected override MarketCategory MarketCategory => MarketCategory.Spot; @@ -18,4 +17,5 @@ public ExchangeBybitSpotAPI(bool isUnified) IsUnifiedAccount = isUnified; } } + public partial class ExchangeName { public const string BybitSpot = "BybitSpot"; } } diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs index 6403af81..e065151f 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs @@ -160,7 +160,10 @@ protected override async Task> OnGetCandlesAsync(strin string url = "/v5/market/kline"; int maxLimit = 200; limit ??= maxLimit; - if (limit.Value > maxLimit) { limit = maxLimit; } + if (limit.Value > maxLimit) + { + limit = maxLimit; + } List candles = new List(); string periodString = PeriodSecondsToString(periodSeconds); if (startDate == null) @@ -244,7 +247,10 @@ protected override async Task> OnGetAmountsAvailable Dictionary amounts = new Dictionary(StringComparer.OrdinalIgnoreCase); var accountBalances = result["list"].FirstOrDefault(i => i["accountType"].ToStringInvariant() == accType); - if (accountBalances == null) return amounts; + if (accountBalances == null) + { + return amounts; + } if (IsUnifiedAccount.Value) { // All assets that can be used as collateral, converted to USD, will be here @@ -253,7 +259,6 @@ protected override async Task> OnGetAmountsAvailable string balanceKey = accType == "SPOT" ? "free" : "availableToWithdraw"; foreach (var coin in accountBalances["coin"]) { - decimal amount = coin[balanceKey].ConvertInvariant(); if (amount > 0m) { diff --git a/src/ExchangeSharp/Model/ExchangeOrderBook.cs b/src/ExchangeSharp/Model/ExchangeOrderBook.cs index c7745233..5966cf21 100644 --- a/src/ExchangeSharp/Model/ExchangeOrderBook.cs +++ b/src/ExchangeSharp/Model/ExchangeOrderBook.cs @@ -68,7 +68,7 @@ public ExchangeOrderPrice(BinaryReader reader) public sealed class ExchangeOrderBook { /// - /// Needed to distinguish between fool book and deltas + /// Needed to distinguish between full book and deltas /// public bool IsFromSnapshot { get; set; } public string ExchangeName { get; set; }