diff --git a/ByBit.Net/Bybit.Net.csproj b/ByBit.Net/Bybit.Net.csproj index 2cafe6af..b249f497 100644 --- a/ByBit.Net/Bybit.Net.csproj +++ b/ByBit.Net/Bybit.Net.csproj @@ -52,6 +52,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file diff --git a/ByBit.Net/BybitExchange.cs b/ByBit.Net/BybitExchange.cs new file mode 100644 index 00000000..3a3c4880 --- /dev/null +++ b/ByBit.Net/BybitExchange.cs @@ -0,0 +1,26 @@ +namespace Bybit.Net +{ + /// + /// Bybit exchange information and configuration + /// + public static class BybitExchange + { + /// + /// Exchange name + /// + public static string ExchangeName => "Bybit"; + + /// + /// Url to the main website + /// + public static string Url { get; } = "https://www.bybit.com"; + + /// + /// Urls to the API documentation + /// + public static string[] ApiDocsUrl { get; } = new[] { + "https://bybit-exchange.github.io/docs/v3/intro", + "https://bybit-exchange.github.io/docs/v5/intro" + }; + } +} diff --git a/ByBit.Net/Clients/CopyTradingApi/BybitRestClientCopyTradingApi.cs b/ByBit.Net/Clients/CopyTradingApi/BybitRestClientCopyTradingApi.cs index 4386746c..e4f55421 100644 --- a/ByBit.Net/Clients/CopyTradingApi/BybitRestClientCopyTradingApi.cs +++ b/ByBit.Net/Clients/CopyTradingApi/BybitRestClientCopyTradingApi.cs @@ -57,6 +57,9 @@ internal BybitRestClientCopyTradingApi(ILogger logger, HttpClient? httpClient, B } #endregion + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); diff --git a/ByBit.Net/Clients/DerivativesApi/BybitRestClientDerivativesApi.cs b/ByBit.Net/Clients/DerivativesApi/BybitRestClientDerivativesApi.cs index 84d6f0a5..2734f52f 100644 --- a/ByBit.Net/Clients/DerivativesApi/BybitRestClientDerivativesApi.cs +++ b/ByBit.Net/Clients/DerivativesApi/BybitRestClientDerivativesApi.cs @@ -68,6 +68,9 @@ internal BybitRestClientDerivativesApi(ILogger logger, HttpClient? httpClient, B protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// /// Get url for an endpoint /// diff --git a/ByBit.Net/Clients/DerivativesApi/BybitSocketClientDerivativesPublicApi.cs b/ByBit.Net/Clients/DerivativesApi/BybitSocketClientDerivativesPublicApi.cs index db982e0e..ebabbdc8 100644 --- a/ByBit.Net/Clients/DerivativesApi/BybitSocketClientDerivativesPublicApi.cs +++ b/ByBit.Net/Clients/DerivativesApi/BybitSocketClientDerivativesPublicApi.cs @@ -43,6 +43,9 @@ internal BybitSocketClientDerivativesPublicApi(ILogger log, BybitSocketOptions o RegisterPeriodicQuery("Heartbeat", TimeSpan.FromSeconds(20), x => new BybitQuery("ping", null), x => { }); } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// public override string? GetListenerIdentifier(IMessageAccessor message) { diff --git a/ByBit.Net/Clients/DerivativesApi/ContractApi/BybitSocketClientContractApi.cs b/ByBit.Net/Clients/DerivativesApi/ContractApi/BybitSocketClientContractApi.cs index bab2e8f9..bd22952b 100644 --- a/ByBit.Net/Clients/DerivativesApi/ContractApi/BybitSocketClientContractApi.cs +++ b/ByBit.Net/Clients/DerivativesApi/ContractApi/BybitSocketClientContractApi.cs @@ -38,6 +38,9 @@ internal BybitSocketClientContractApi(ILogger log, BybitSocketOptions options) RegisterPeriodicQuery("Heartbeat", TimeSpan.FromSeconds(20), x => new BybitQuery("ping", null), x => { }); } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); diff --git a/ByBit.Net/Clients/DerivativesApi/UnifiedMarginApi/BybitSocketClientUnifiedMarginApi.cs b/ByBit.Net/Clients/DerivativesApi/UnifiedMarginApi/BybitSocketClientUnifiedMarginApi.cs index de3267d1..e7db8f1b 100644 --- a/ByBit.Net/Clients/DerivativesApi/UnifiedMarginApi/BybitSocketClientUnifiedMarginApi.cs +++ b/ByBit.Net/Clients/DerivativesApi/UnifiedMarginApi/BybitSocketClientUnifiedMarginApi.cs @@ -40,6 +40,9 @@ internal BybitSocketClientUnifiedMarginApi(ILogger log, BybitSocketOptions optio RegisterPeriodicQuery("Heartbeat", TimeSpan.FromSeconds(20), x => new BybitPingQuery(), x => { }); } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); diff --git a/ByBit.Net/Clients/SpotApi/v3/BybitRestClientSpotApiV3.cs b/ByBit.Net/Clients/SpotApi/v3/BybitRestClientSpotApiV3.cs index ae259a9e..7091a98d 100644 --- a/ByBit.Net/Clients/SpotApi/v3/BybitRestClientSpotApiV3.cs +++ b/ByBit.Net/Clients/SpotApi/v3/BybitRestClientSpotApiV3.cs @@ -43,6 +43,9 @@ internal BybitRestClientSpotApiV3(ILogger logger, HttpClient? httpClient, BybitR } #endregion + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + #region Common interface /// diff --git a/ByBit.Net/Clients/SpotApi/v3/BybitSocketClientSpotApiV3.cs b/ByBit.Net/Clients/SpotApi/v3/BybitSocketClientSpotApiV3.cs index dfaa1be0..1801d1dc 100644 --- a/ByBit.Net/Clients/SpotApi/v3/BybitSocketClientSpotApiV3.cs +++ b/ByBit.Net/Clients/SpotApi/v3/BybitSocketClientSpotApiV3.cs @@ -40,6 +40,9 @@ internal BybitSocketClientSpotApiV3(ILogger logger, BybitSocketOptions options) protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// public override string? GetListenerIdentifier(IMessageAccessor message) { diff --git a/ByBit.Net/Clients/V5/BybitRestClientApi.cs b/ByBit.Net/Clients/V5/BybitRestClientApi.cs index 7901cf68..85ec4e8d 100644 --- a/ByBit.Net/Clients/V5/BybitRestClientApi.cs +++ b/ByBit.Net/Clients/V5/BybitRestClientApi.cs @@ -75,6 +75,9 @@ internal BybitRestClientApi(ILogger logger, HttpClient? httpClient, BybitRestOpt protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// /// Get url for an endpoint /// @@ -103,6 +106,18 @@ protected override async Task> GetServerTimestampAsync() public override TimeSpan? GetTimeOffset() => _timeSyncState.TimeOffset; + internal async Task SendAsync(RequestDefinition definition, ParameterCollection? parameters, CancellationToken cancellationToken, int? weight = null) + { + var result = await base.SendAsync>(BaseAddress, definition, parameters, cancellationToken, null, weight).ConfigureAwait(false); + if (!result) + return result.AsDataless(); + + if (result.Data.ReturnCode != 0) + return result.AsDatalessError(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); + + return result.AsDataless(); + } + internal async Task>> SendRequestFullResponseAsync( Uri uri, HttpMethod method, diff --git a/ByBit.Net/Clients/V5/BybitRestClientApiAccount.cs b/ByBit.Net/Clients/V5/BybitRestClientApiAccount.cs index 45cdac27..efd9a0c6 100644 --- a/ByBit.Net/Clients/V5/BybitRestClientApiAccount.cs +++ b/ByBit.Net/Clients/V5/BybitRestClientApiAccount.cs @@ -12,12 +12,15 @@ using System.Globalization; using Bybit.Net.Interfaces.Clients.V5; using Bybit.Net.Objects.Internal; +using System.Linq; namespace Bybit.Net.Clients.V5 { /// public class BybitRestClientApiAccount : IBybitRestClientApiAccount { + private static readonly RequestDefinitionCache _definitions = new RequestDefinitionCache(); + private BybitRestClientApi _baseClient; internal BybitRestClientApiAccount(BybitRestClientApi baseClient) @@ -1005,5 +1008,19 @@ public async Task>> RepayLiab } #endregion + + #region Request Demo Funds + + /// + public async Task RequestDemoFundsAsync(Dictionary funds, CancellationToken ct = default) + { + var parameters = new ParameterCollection(); + parameters.AddOptionalParameter("utaDemoApplyMoney", funds.Select(f => new { coin = f.Key, amountStr = f.Value.ToString(CultureInfo.InvariantCulture) })); + + var request = _definitions.GetOrCreate(HttpMethod.Post, "v5/account/demo-apply-money", true); + return await _baseClient.SendAsync(request, parameters, ct).ConfigureAwait(false); + } + + #endregion } } diff --git a/ByBit.Net/Clients/V5/BybitSocketClientBaseApi.cs b/ByBit.Net/Clients/V5/BybitSocketClientBaseApi.cs index 91b9a9e4..b3dcac6e 100644 --- a/ByBit.Net/Clients/V5/BybitSocketClientBaseApi.cs +++ b/ByBit.Net/Clients/V5/BybitSocketClientBaseApi.cs @@ -37,6 +37,9 @@ internal BybitSocketClientBaseApi(ILogger log, BybitSocketOptions options, strin HandleMessageBeforeConfirmation = true; } + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// public virtual Task> SubscribeToOrderbookUpdatesAsync(string symbol, int depth, Action> updateHandler, CancellationToken ct = default) => SubscribeToOrderbookUpdatesAsync(new string[] { symbol }, depth, updateHandler, ct); diff --git a/ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs b/ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs index 46f990cd..fe5258f0 100644 --- a/ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs +++ b/ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs @@ -38,6 +38,9 @@ internal BybitSocketClientPrivateApi(ILogger logger, BybitSocketOptions options) /// protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BybitAuthenticationProvider(credentials); + /// + public override string FormatSymbol(string baseAsset, string quoteAsset) => baseAsset.ToUpperInvariant() + quoteAsset.ToUpperInvariant(); + /// protected override Query? GetAuthenticationRequest() { diff --git a/ByBit.Net/Enums/TransactionLogType.cs b/ByBit.Net/Enums/TransactionLogType.cs index e0742a1c..2211a9c6 100644 --- a/ByBit.Net/Enums/TransactionLogType.cs +++ b/ByBit.Net/Enums/TransactionLogType.cs @@ -38,6 +38,11 @@ public enum TransactionLogType [Map("LIQUIDATION")] Liquidation, /// + /// Auto deleveraging + /// + [Map("ADL")] + Adl, + /// /// Airdrop /// [Map("AIRDROP")] @@ -168,5 +173,33 @@ public enum TransactionLogType /// [Map("PREMARKET_ROLLBACK_PLEDGE_PENALTY_TO_BUYER")] PreMarketRollbackPledgePenaltyToBuyer, + /// + /// + [Map("CUSTODY_NETWORK_FEE")] + CustodyNetworkFee, + /// + /// + [Map("CUSTODY_SETTLE_FEE")] + CustodySettleFee, + /// + /// + [Map("CUSTODY_LOCK")] + CustodyLock, + /// + /// + [Map("CUSTODY_UNLOCK")] + CustodyUnlock, + /// + /// + [Map("CUSTODY_UNLOCK_REFUND")] + CustodyUnlockRefund, + /// + /// + [Map("LOANS_BORROW_FUNDS")] + LoansBorrowFunds, + /// + /// + [Map("LOANS_ASSET_REDEMPTION")] + LoansAssetRedemption, } } diff --git a/ByBit.Net/ExtensionMethods/ServiceCollectionExtensions.cs b/ByBit.Net/ExtensionMethods/ServiceCollectionExtensions.cs index 74da1bbf..36018ab0 100644 --- a/ByBit.Net/ExtensionMethods/ServiceCollectionExtensions.cs +++ b/ByBit.Net/ExtensionMethods/ServiceCollectionExtensions.cs @@ -59,7 +59,7 @@ public static IServiceCollection AddBybit( services.AddTransient(); services.AddTransient(); - services.AddSingleton(); + services.AddTransient(); services.AddTransient(x => x.GetRequiredService().V5Api.CommonSpotClient); if (socketClientLifeTime == null) services.AddSingleton(); diff --git a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiAccount.cs b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiAccount.cs index be578714..22c7e44b 100644 --- a/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiAccount.cs +++ b/ByBit.Net/Interfaces/Clients/V5/IBybitRestClientApiAccount.cs @@ -575,5 +575,14 @@ Task> AddOrReduceMarginAsync( /// Cancellation token /// Task>> RepayLiabilitiesAsync(string? asset = null, CancellationToken ct = default); + + /// + /// Request funds for demo trading + /// + /// + /// Dictionary of the asset and amount you want to receive. Only BTC, ETH, USDT or USDC supported + /// Cancellation token + /// + Task RequestDemoFundsAsync(Dictionary funds, CancellationToken ct = default); } } \ No newline at end of file diff --git a/ByBit.Net/Interfaces/IBybitOrderBookFactory.cs b/ByBit.Net/Interfaces/IBybitOrderBookFactory.cs index 742951de..32e54685 100644 --- a/ByBit.Net/Interfaces/IBybitOrderBookFactory.cs +++ b/ByBit.Net/Interfaces/IBybitOrderBookFactory.cs @@ -10,6 +10,21 @@ namespace Bybit.Net.Interfaces /// public interface IBybitOrderBookFactory { + /// + /// Spot order book factory methods + /// + public IOrderBookFactory Spot { get; } + + /// + /// Options order book factory methods + /// + public IOrderBookFactory Options { get; } + + /// + /// Linear/Inverse order book factory methods + /// + public IOrderBookFactory LinearInverse { get; } + /// /// Create a SymbolOrderBook specifying the category /// diff --git a/ByBit.Net/Objects/Models/V5/BybitInsurance.cs b/ByBit.Net/Objects/Models/V5/BybitInsurance.cs index 065e1116..a1bacb14 100644 --- a/ByBit.Net/Objects/Models/V5/BybitInsurance.cs +++ b/ByBit.Net/Objects/Models/V5/BybitInsurance.cs @@ -13,6 +13,11 @@ public class BybitInsurance [JsonProperty("coin")] public string Asset { get; set; } = string.Empty; /// + /// Symbols + /// + [JsonProperty("symbols")] + public string Symbols { get; set; } = string.Empty; + /// /// Balance /// public decimal Balance { get; set; } diff --git a/ByBit.Net/SymbolOrderBooks/BybitOrderBookFactory.cs b/ByBit.Net/SymbolOrderBooks/BybitOrderBookFactory.cs index 6e60bc60..04480a4a 100644 --- a/ByBit.Net/SymbolOrderBooks/BybitOrderBookFactory.cs +++ b/ByBit.Net/SymbolOrderBooks/BybitOrderBookFactory.cs @@ -3,6 +3,7 @@ using Bybit.Net.Interfaces.Clients; using Bybit.Net.Objects.Options; using CryptoExchange.Net.Interfaces; +using CryptoExchange.Net.OrderBook; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using System; @@ -14,6 +15,15 @@ public class BybitOrderBookFactory : IBybitOrderBookFactory { private readonly IServiceProvider _serviceProvider; + /// + public IOrderBookFactory Spot { get; } + + /// + public IOrderBookFactory Options { get; } + + /// + public IOrderBookFactory LinearInverse { get; } + /// /// ctor /// @@ -21,6 +31,10 @@ public class BybitOrderBookFactory : IBybitOrderBookFactory public BybitOrderBookFactory(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; + + Spot = new OrderBookFactory((symbol, options) => CreateSpot(symbol, options), (baseAsset, quoteAsset, options) => CreateSpot(baseAsset + quoteAsset, options)); + Options = new OrderBookFactory((symbol, options) => CreateOption(symbol, options), (baseAsset, quoteAsset, options) => CreateOption(baseAsset + quoteAsset, options)); + LinearInverse = new OrderBookFactory((symbol, options) => CreateLinearInverse(symbol, options), (baseAsset, quoteAsset, options) => CreateLinearInverse(baseAsset + quoteAsset, options)); } ///