Skip to content

Commit

Permalink
[Bybit] Changed bybit exchange names (#802)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
TarasMi authored Apr 3, 2023
1 parent eb51abd commit 9585ba9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace ExchangeSharp
{
[ApiName(ExchangeName.Bybit)]
public class ExchangeBybitInverseAPI : ExchangeBybitV5Base
{
protected override MarketCategory MarketCategory => MarketCategory.Inverse;
Expand All @@ -18,4 +17,5 @@ public ExchangeBybitInverseAPI(bool isUnifiedAccount)
IsUnifiedAccount = isUnifiedAccount;
}
}
public partial class ExchangeName { public const string BybitInverse = "BybitInverse"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace ExchangeSharp
{
[ApiName(ExchangeName.Bybit)]
public class ExchangeBybitLinearAPI : ExchangeBybitV5Base
{
protected override MarketCategory MarketCategory => MarketCategory.Linear;
Expand All @@ -18,4 +17,5 @@ public ExchangeBybitLinearAPI(bool isUnifiedAccount)
IsUnifiedAccount = isUnifiedAccount;
}
}
public partial class ExchangeName { public const string BybitLinear = "BybitLinear"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace ExchangeSharp
{
[ApiName(ExchangeName.Bybit)]
public class ExchangeBybitOptionAPI : ExchangeBybitV5Base
{
protected override MarketCategory MarketCategory => MarketCategory.Option;
Expand All @@ -18,4 +17,5 @@ public ExchangeBybitOptionAPI(bool isUnifiedAccount)
IsUnifiedAccount = isUnifiedAccount;
}
}
public partial class ExchangeName { public const string BybitOption = "BybitOption"; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace ExchangeSharp
{
[ApiName(ExchangeName.Bybit)]
public class ExchangeBybitSpotAPI : ExchangeBybitV5Base
{
protected override MarketCategory MarketCategory => MarketCategory.Spot;
Expand All @@ -18,4 +17,5 @@ public ExchangeBybitSpotAPI(bool isUnified)
IsUnifiedAccount = isUnified;
}
}
public partial class ExchangeName { public const string BybitSpot = "BybitSpot"; }
}
11 changes: 8 additions & 3 deletions src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ protected override async Task<IEnumerable<MarketCandle>> 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<MarketCandle> candles = new List<MarketCandle>();
string periodString = PeriodSecondsToString(periodSeconds);
if (startDate == null)
Expand Down Expand Up @@ -244,7 +247,10 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
Dictionary<string, decimal> amounts = new Dictionary<string, decimal>(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
Expand All @@ -253,7 +259,6 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
string balanceKey = accType == "SPOT" ? "free" : "availableToWithdraw";
foreach (var coin in accountBalances["coin"])
{

decimal amount = coin[balanceKey].ConvertInvariant<decimal>();
if (amount > 0m)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExchangeSharp/Model/ExchangeOrderBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public ExchangeOrderPrice(BinaryReader reader)
public sealed class ExchangeOrderBook
{
/// <summary>
/// Needed to distinguish between fool book and deltas
/// Needed to distinguish between full book and deltas
/// </summary>
public bool IsFromSnapshot { get; set; }
public string ExchangeName { get; set; }
Expand Down

0 comments on commit 9585ba9

Please sign in to comment.