diff --git a/ByBit.Net/Clients/BybitRestClient.cs b/ByBit.Net/Clients/BybitRestClient.cs index 6ba6b447..a610abbc 100644 --- a/ByBit.Net/Clients/BybitRestClient.cs +++ b/ByBit.Net/Clients/BybitRestClient.cs @@ -1,17 +1,7 @@ using Bybit.Net.Clients.CopyTradingApi; -using Bybit.Net.Clients.GeneralApi; -using Bybit.Net.Clients.InverseFuturesApi; -using Bybit.Net.Clients.InversePerpetualApi; -using Bybit.Net.Clients.UsdPerpetualApi; using Bybit.Net.Interfaces.Clients; using Bybit.Net.Interfaces.Clients.CopyTradingApi; -using Bybit.Net.Interfaces.Clients.GeneralApi; -using Bybit.Net.Interfaces.Clients.InverseFuturesApi; -using Bybit.Net.Interfaces.Clients.InversePerpetualApi; -using Bybit.Net.Interfaces.Clients.SpotApi.v1; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; using CryptoExchange.Net; -using Bybit.Net.Clients.SpotApi.v1; using Bybit.Net.Clients.SpotApi.v3; using Bybit.Net.Interfaces.Clients.SpotApi.v3; using Bybit.Net.Interfaces.Clients.DerivativesApi; @@ -27,19 +17,9 @@ namespace Bybit.Net.Clients /// public class BybitRestClient : BaseRestClient, IBybitRestClient { - /// - public IBybitRestClientGeneralApi GeneralApi { get; } - /// - public IBybitRestClientSpotApiV1 SpotApiV1 { get; } /// public IBybitRestClientSpotApiV3 SpotApiV3 { get; } /// - public IBybitRestClientInversePerpetualApi InversePerpetualApi { get; } - /// - public IBybitRestClientInverseFuturesApi InverseFuturesApi { get; } - /// - public IBybitRestClientUsdPerpetualApi UsdPerpetualApi { get; } - /// public IBybitRestClientCopyTradingApi CopyTradingApi { get; } /// public IBybitRestClientDerivativesApi DerivativesApi { get; } @@ -69,12 +49,7 @@ public BybitRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, Ac optionsDelegate(options); Initialize(options); - InversePerpetualApi = AddApiClient(new BybitRestClientInversePerpetualApi(_logger, httpClient, options)); - InverseFuturesApi = AddApiClient(new BybitRestClientInverseFuturesApi(_logger, httpClient, options)); - UsdPerpetualApi = AddApiClient(new BybitRestClientUsdPerpetualApi(_logger, httpClient, options)); - SpotApiV1 = AddApiClient(new BybitRestClientSpotApiV1(_logger, httpClient, options)); SpotApiV3 = AddApiClient(new BybitRestClientSpotApiV3(_logger, httpClient, options)); - GeneralApi = AddApiClient(new BybitRestClientGeneralApi(_logger, this, httpClient, options)); CopyTradingApi = AddApiClient(new BybitRestClientCopyTradingApi(_logger, httpClient, options)); DerivativesApi = AddApiClient(new BybitRestClientDerivativesApi(_logger, httpClient, options)); V5Api = AddApiClient(new V5.BybitRestClientApi(_logger, httpClient, options)); @@ -96,12 +71,7 @@ public static void SetDefaultOptions(Action optionsDelegate) /// public void SetApiCredentials(ApiCredentials credentials) { - InversePerpetualApi.SetApiCredentials(credentials); - InverseFuturesApi.SetApiCredentials(credentials); - UsdPerpetualApi.SetApiCredentials(credentials); - SpotApiV1.SetApiCredentials(credentials); SpotApiV3.SetApiCredentials(credentials); - GeneralApi.SetApiCredentials(credentials); CopyTradingApi.SetApiCredentials(credentials); DerivativesApi.SetApiCredentials(credentials); V5Api.SetApiCredentials(credentials); diff --git a/ByBit.Net/Clients/BybitSocketClient.cs b/ByBit.Net/Clients/BybitSocketClient.cs index c94bb105..83bb1a1e 100644 --- a/ByBit.Net/Clients/BybitSocketClient.cs +++ b/ByBit.Net/Clients/BybitSocketClient.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net; using System; using Bybit.Net.Interfaces.Clients; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; using Bybit.Net.Interfaces.Clients.SpotApi.v3; using Bybit.Net.Interfaces.Clients.DerivativesApi.UnifiedMarginApi; using Bybit.Net.Interfaces.Clients.DerivativesApi.ContractApi; diff --git a/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApi.cs b/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApi.cs deleted file mode 100644 index 0a6dd397..00000000 --- a/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApi.cs +++ /dev/null @@ -1,101 +0,0 @@ -using Bybit.Net.Clients.CopyTradingApi; -using Bybit.Net.Clients.InversePerpetualApi; -using Bybit.Net.Interfaces.Clients.GeneralApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Options; -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; -using CryptoExchange.Net.Objects; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.GeneralApi -{ - /// - public class BybitRestClientGeneralApi : RestApiClient, IBybitRestClientGeneralApi - { - private readonly BybitRestClient _baseClient; - - /// - /// Options - /// - public new BybitRestOptions ClientOptions => (BybitRestOptions)base.ClientOptions; - - /// - public IBybitRestClientGeneralApiTransfer Transfer { get; } - /// - public IBybitRestClientGeneralApiWithdrawDeposit WithdrawDeposit { get; } - - #region ctor - internal BybitRestClientGeneralApi(ILogger logger, BybitRestClient restClient, HttpClient? httpClient, BybitRestOptions options) : - base(logger, httpClient, options.Environment.RestBaseAddress, options, options.InversePerpetualOptions) - { - if (!string.IsNullOrEmpty(options.Referer)) - { - StandardRequestHeaders = new Dictionary - { - { "x-referer", options.Referer! } - }; - } - - _baseClient = restClient; - - Transfer = new BybitRestClientGeneralApiTransfer(this); - WithdrawDeposit = new BybitRestClientGeneralApiWithdrawDeposit(this); - - requestBodyFormat = RequestBodyFormat.Json; - ParameterPositions[HttpMethod.Delete] = HttpMethodParameterPosition.InUri; - } - #endregion - - /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) - => new BybitAuthenticationProvider(credentials); - - /// - /// Get url for an endpoint - /// - /// - /// - internal Uri GetUrl(string endpoint) - { - return new Uri(BaseAddress.AppendPath(endpoint)); - } - - internal async Task> SendRequestAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null) - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer).ConfigureAwait(false); - if (!result) - return result.As(default); - - if (result.Data.ReturnCode != 0) - return result.AsError(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data.Result); - } - - - /// - protected override Task> GetServerTimestampAsync() - => _baseClient.InversePerpetualApi.ExchangeData.GetServerTimeAsync(); - - /// - public override TimeSyncInfo? GetTimeSyncInfo() - => new TimeSyncInfo(_logger, (ApiOptions.AutoTimestamp ?? ClientOptions.AutoTimestamp), (ApiOptions.TimestampRecalculationInterval ?? ClientOptions.TimestampRecalculationInterval), BybitRestClientInversePerpetualApi._timeSyncState); - - /// - public override TimeSpan? GetTimeOffset() - => BybitRestClientCopyTradingApi._timeSyncState.TimeOffset; - } -} diff --git a/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApiTransfer.cs b/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApiTransfer.cs deleted file mode 100644 index cd5303b8..00000000 --- a/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApiTransfer.cs +++ /dev/null @@ -1,236 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.GeneralApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.GeneralApi -{ - /// - public class BybitRestClientGeneralApiTransfer : IBybitRestClientGeneralApiTransfer - { - private BybitRestClientGeneralApi _baseClient; - - internal BybitRestClientGeneralApiTransfer(BybitRestClientGeneralApi baseClient) - { - _baseClient = baseClient; - } - - #region Create internal transfer - - /// - public async Task> CreateInternalTransferAsync(string transferId, string asset, decimal quantity, AccountType fromAccountType, AccountType toAccountType, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "transfer_id", transferId }, - { "coin", asset }, - { "amount", quantity.ToString(CultureInfo.InvariantCulture) }, - { "from_account_type", EnumConverter.GetString(fromAccountType)! }, - { "to_account_type", EnumConverter.GetString(toAccountType)! }, - }; - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("asset/v1/private/transfer"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Create subaccount transfer - - /// - public async Task> CreateSubAccountTransferAsync(string transferId, string asset, decimal quantity, string subAccountId, TransferType type, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "transfer_id", transferId }, - { "coin", asset }, - { "amount", quantity.ToString(CultureInfo.InvariantCulture) }, - { "sub_user_id", subAccountId }, - { "type", EnumConverter.GetString(type)! }, - }; - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("asset/v1/private/sub-member/transfer"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get transfer history - - /// - public async Task>>> GetTransferHistoryAsync( - string? transferId = null, - string? asset = null, - TransferStatus? status = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("transfer_id", transferId); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("status", EnumConverter.GetString(status)); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToMilliseconds(endTime)); - parameters.AddOptionalParameter("direction", transferId); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("asset/v1/private/transfer/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get subaccount transfer history - - /// - public async Task>>> GetSubAccountTransferHistoryAsync( - string? transferId = null, - string? asset = null, - TransferStatus? status = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("transfer_id", transferId); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("status", EnumConverter.GetString(status)); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToMilliseconds(endTime)); - parameters.AddOptionalParameter("direction", transferId); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("asset/v1/private/sub-member/transfer/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get subaccounts - - /// - public async Task> GetSubAccountsAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("asset/v1/private/sub-member/member-ids"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Enable Subaccounts Universal Transfer - - /// - public async Task EnableSubaccountsUniversalTransferAsync(IEnumerable? subaccountIds = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("transferable_sub_ids", subaccountIds == null ? null : string.Join(",", subaccountIds)); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("/asset/v1/private/transferable-subs/save"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Enable Subaccounts Universal Transfer - - /// - public async Task> UniversalTransferAsync(string transferId, string asset, decimal quantity, string fromMemberId, string toMemberId, AccountType fromAccountType, AccountType toAccountType, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "transfer_id", transferId }, - { "coin", asset }, - { "amount", quantity.ToString(CultureInfo.InvariantCulture) }, - { "from_member_id", fromMemberId }, - { "to_member_id", toMemberId }, - { "from_account_type", EnumConverter.GetString(fromAccountType) }, - { "to_account_type", EnumConverter.GetString(toAccountType) }, - }; - - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("/asset/v1/private/universal/transfer"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get universal transfer history - - /// - public async Task>>> GetUniversalTransferHistoryAsync( - string? transferId = null, - string? asset = null, - TransferStatus? status = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("transfer_id", transferId); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("status", EnumConverter.GetString(status)); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToMilliseconds(endTime)); - parameters.AddOptionalParameter("direction", transferId); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("asset/v1/private/universal/transfer/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get transfer balance - - /// - public async Task> GetAssetBalanceAsync(AccountType accountType, string asset, long? receiveWindow = null, CancellationToken ct = default) - { - string queryUrl = "asset/v3/private/transfer/account-coin/balance/query"; - - var parameters = new Dictionary() - { - { "accountType", EnumConverter.GetString(accountType) }, - { "coin", asset } - }; - - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl(queryUrl), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApiWithdrawDeposit.cs b/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApiWithdrawDeposit.cs deleted file mode 100644 index d9e3f64f..00000000 --- a/ByBit.Net/Clients/GeneralApi/BybitRestClientGeneralApiWithdrawDeposit.cs +++ /dev/null @@ -1,210 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.GeneralApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.GeneralApi -{ - /// - public class BybitRestClientGeneralApiWithdrawDeposit : IBybitRestClientGeneralApiWithdrawDeposit - { - private readonly BybitRestClientGeneralApi _baseClient; - - internal BybitRestClientGeneralApiWithdrawDeposit(BybitRestClientGeneralApi baseClient) - { - _baseClient = baseClient; - } - - #region Get supported deposit methods - - /// - public async Task>> GetSupportedDepositMethodsAsync( - string? asset = null, - string? network = null, - int? page = null, - int? pageSize = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("chain", network); - parameters.AddOptionalParameter("page_index", page); - parameters.AddOptionalParameter("page_size", pageSize); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("/asset/v1/public/deposit/allowed-deposit-list"), HttpMethod.Get, ct, parameters, false).ConfigureAwait(false); - return result.As(result.Data?.ConfigList!); - } - - #endregion - - #region Get deposit history - - /// - public async Task>>> GetDepositHistoryAsync( - string? asset = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToSeconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToSeconds(endTime)); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("/asset/v1/private/deposit/record/query"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get withdrawal history - - /// - public async Task>>> GetWithdrawalHistoryAsync( - string? withdrawalId = null, - string? asset = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("withdraw_id", withdrawalId); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToSeconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToSeconds(endTime)); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("/asset/v1/private/withdraw/record/query"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get asset info - - /// - public async Task>> GetAssetInfoAsync( - string? asset = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("/asset/v1/private/coin-info/query"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - return result.As>(result.Data?.Data); - } - - #endregion - - #region Get account info - - /// - public async Task>> GetAccountInfoAsync( - string? asset = null, - string? accountType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("account_type", accountType); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("/asset/v1/private/asset-info/query"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Withdraw - - /// - public async Task> WithdrawAsync( - string asset, - string network, - string address, - decimal quantity, - string? tag = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "coin", asset }, - { "chain", network }, - { "address", address }, - { "amount", quantity.ToString(CultureInfo.InvariantCulture) } - }; - parameters.AddOptionalParameter("tag", tag); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("/asset/v1/private/withdraw"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Cancel withdrawal - - /// - public async Task CancelWithdrawalAsync( - string withdrawalId, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "id", withdrawalId } - }; - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("/asset/v1/private/withdraw/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Get account info - - /// - public async Task> GetDepositAddressesAsync( - string asset, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("/asset/v1/private/deposit/address"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApi.cs b/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApi.cs deleted file mode 100644 index bedd569c..00000000 --- a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApi.cs +++ /dev/null @@ -1,134 +0,0 @@ -using Bybit.Net.Interfaces.Clients.InverseFuturesApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Options; -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; -using CryptoExchange.Net.Objects; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InverseFuturesApi -{ - /// - public class BybitRestClientInverseFuturesApi : RestApiClient, IBybitRestClientInverseFuturesApi - { - - internal static TimeSyncState _timeSyncState = new TimeSyncState("Inverse Futures Api"); - /// - /// Options - /// - public new BybitRestOptions ClientOptions => (BybitRestOptions)base.ClientOptions; - - /// - public IBybitRestClientInverseFuturesApiAccount Account { get; } - /// - public IBybitRestClientInverseFuturesApiExchangeData ExchangeData { get; } - /// - public IBybitRestClientInverseFuturesApiTrading Trading { get; } - - #region ctor - internal BybitRestClientInverseFuturesApi(ILogger logger, HttpClient? httpClient, BybitRestOptions options) : - base(logger, httpClient, options.Environment.RestBaseAddress, options, options.InverseFuturesOptions) - { - if (!string.IsNullOrEmpty(options.Referer)) - { - StandardRequestHeaders = new Dictionary - { - { "x-referer", options.Referer! } - }; - } - - manualParseError = true; - - Account = new BybitRestClientInverseFuturesApiAccount(this); - ExchangeData = new BybitRestClientInverseFuturesApiExchangeData(this); - Trading = new BybitRestClientInverseFuturesApiTrading(this); - - requestBodyFormat = RequestBodyFormat.FormData; - ParameterPositions[HttpMethod.Delete] = HttpMethodParameterPosition.InUri; - } - #endregion - - /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) - => new BybitAuthenticationProvider(credentials); - - /// - /// Get url for an endpoint - /// - /// - /// - internal Uri GetUrl(string endpoint) - { - return new Uri(BaseAddress.AppendPath(endpoint)); - } - - /// - protected override Task TryParseErrorAsync(JToken data) - { - var responseCode = data["ret_code"]; - if (responseCode != null && responseCode.ToString() != "0") - { - var errorMessage = data["ret_msg"]; - return Task.FromResult(new ServerError(responseCode.Value(), errorMessage!.ToString()))!; - } - - return Task.FromResult(null); - } - - internal async Task>> SendRequestWrapperAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null, - bool ignoreRatelimit = false) where T : class - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer, ignoreRatelimit: ignoreRatelimit).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.ReturnCode != 0) - return result.AsError>(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data); - } - - internal async Task> SendRequestAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null) - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer).ConfigureAwait(false); - if (!result) - return result.As(default); - - if (result.Data.ReturnCode != 0) - return result.AsError(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data.Result); - } - - /// - protected override Task> GetServerTimestampAsync() - => ExchangeData.GetServerTimeAsync(); - - /// - public override TimeSyncInfo? GetTimeSyncInfo() - => new TimeSyncInfo(_logger, (ApiOptions.AutoTimestamp ?? ClientOptions.AutoTimestamp), (ApiOptions.TimestampRecalculationInterval ?? ClientOptions.TimestampRecalculationInterval), _timeSyncState); - - /// - public override TimeSpan? GetTimeOffset() - => _timeSyncState.TimeOffset; - } -} diff --git a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiAccount.cs b/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiAccount.cs deleted file mode 100644 index 5a4c9001..00000000 --- a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiAccount.cs +++ /dev/null @@ -1,323 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.InverseFuturesApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InverseFuturesApi -{ - /// - public class BybitRestClientInverseFuturesApiAccount : IBybitRestClientInverseFuturesApiAccount - { - private BybitRestClientInverseFuturesApi _baseClient; - - internal BybitRestClientInverseFuturesApiAccount(BybitRestClientInverseFuturesApi baseClient) - { - _baseClient = baseClient; - } - - #region Get risk limit - - /// - public async Task>> GetRiskLimitAsync(string? symbol = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/risk-limit/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Set risk limit - - /// - public async Task> SetRiskLimitAsync(string symbol, long riskId, PositionMode? mode = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "risk_id", riskId.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("position_idx", mode == null ? null : JsonConvert.SerializeObject(mode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/position/risk-limit"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get positions - /// - public async Task>> GetPositionAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("futures/private/position/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - foreach (var position in result.Data) - position.Data.IsValid = position.IsValid; - - return result.As(result.Data.Select(d => d.Data)); - } - - - /// - public async Task>> GetPositionsAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("futures/private/position/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - foreach (var position in result.Data) - position.Data.IsValid = position.IsValid; - - return result.As(result.Data.Select(d => d.Data)); - } - - #endregion - - #region Change margin - - /// - public async Task> ChangeMarginAsync(string symbol, PositionMode mode, decimal margin, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "position_idx", JsonConvert.SerializeObject(mode, new PositionModeConverter(false)) }, - { "margin", margin.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/position/change-position-margin"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set leverage - - /// - public async Task> SetLeverageAsync(string symbol, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "buy_leverage", buyLeverage.ToString(CultureInfo.InvariantCulture) }, - { "sell_leverage", sellLeverage.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/position/leverage/save"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get Profit And Loss History - - /// - public async Task>>> GetProfitAndLossHistoryAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, TradeType? type = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToSeconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToSeconds(endTime)); - parameters.AddOptionalParameter("exec_type", type == null ? null : JsonConvert.SerializeObject(type.Value, new TradeTypeConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("futures/private/trade/closed-pnl/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - if (result && result.Data.Data == null) - result.Data.Data = new BybitPnlEntry[0]; - - return result; - } - - #endregion - - #region Set full / partial position mode - - /// - public async Task> SetFullPartialPositionModeAsync(string symbol, StopLossTakeProfitMode mode, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "tp_sl_mode", JsonConvert.SerializeObject(mode, new StopLossTakeProfitModeConverter(false)) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/tpsl/switch-mode"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set position mode - - /// - public async Task SetPositionModeAsync(string symbol, string asset, bool hedgeMode, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - if (string.IsNullOrWhiteSpace(asset)) - { - parameters.Add("symbol", symbol); - } - else if (string.IsNullOrWhiteSpace(symbol)) - { - parameters.Add("coin", asset); - } - else - { - throw new ArgumentNullException("One of 'coin' or 'symbol' parameters is required!"); - } - - parameters.Add("mode", hedgeMode ? 3 : 0); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/position/switch-mode"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Set isolated mode - - /// - public async Task SetIsolatedPositionModeAsync(string symbol, bool isIsolated, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "is_isolated", isIsolated.ToString() }, - { "buy_leverage", buyLeverage.ToString(CultureInfo.InvariantCulture) }, - { "sell_leverage", sellLeverage.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/position/switch-isolated"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Get balances - - /// - public async Task>> GetBalancesAsync(string? asset = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/wallet/balance"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get wallet fund history - - /// - public async Task>> GetWalletFundHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WalletFundType? type = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_date", startTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("end_date", endTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("wallet_fund_type", type == null ? null : JsonConvert.SerializeObject(type, new WalletFundTypeConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString()); - parameters.AddOptionalParameter("limit", pageSize?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/wallet/fund/records"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Data == null) - return result.As>(new BybitWalletFundRecord[0]); - - return result.As(result.Data.Data); - } - - #endregion - - #region Get withdrawal history - - /// - public async Task>> GetWithdrawalHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WithdrawStatus? status = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_date", startTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("end_date", endTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("status", status == null ? null : JsonConvert.SerializeObject(status, new WithdrawStatusConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString()); - parameters.AddOptionalParameter("limit", pageSize?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/wallet/withdraw/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Data == null) - return result.As>(new BybitWithdrawal[0]); - - return result.As(result.Data.Data); - } - - #endregion - - #region Get asset exchange history - - /// - public async Task>> GetAssetExchangeHistoryAsync(long? fromId = null, SearchDirection? direction = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("from", fromId?.ToString()); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/exchange-order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get api key info - - /// - public async Task>> GetApiKeyInfoAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/account/api-key"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiExchangeData.cs b/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiExchangeData.cs deleted file mode 100644 index ab7cdc28..00000000 --- a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiExchangeData.cs +++ /dev/null @@ -1,211 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.InverseFuturesApi; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InverseFuturesApi -{ - /// - public class BybitRestClientInverseFuturesApiExchangeData : IBybitRestClientInverseFuturesApiExchangeData - { - private BybitRestClientInverseFuturesApi _baseClient; - - internal BybitRestClientInverseFuturesApiExchangeData(BybitRestClientInverseFuturesApi baseClient) - { - _baseClient = baseClient; - } - - #region Get klines - - /// - public async Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/kline/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get trade history - - /// - public async Task>> GetTradeHistoryAsync(string symbol, long? fromId = null, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("fromId", fromId?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/trading-records"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get mark price klines - - /// - public async Task>> GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/mark-price-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get index price klines - - /// - public async Task>> GetIndexPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from) }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/index-price-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get server time - - /// - public async Task> GetServerTimeAsync(CancellationToken ct = default) - { - var result = await _baseClient.SendRequestWrapperAsync(_baseClient.GetUrl("v2/public/time"), HttpMethod.Get, ct, null, ignoreRatelimit: true).ConfigureAwait(false); - if (!result) - return result.As(default); - - return result.As(result.Data.Timestamp); - } - - #endregion - - #region Get announcements - - /// - public async Task>> GetAnnouncementsAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/announcement"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get order book - - /// - public async Task>> GetOrderBookAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/orderBook/L2"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get ticker - - /// - public async Task>> GetTickerAsync(string? symbol = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/tickers"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get symbols - - /// - public async Task>> GetSymbolsAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/symbols"), HttpMethod.Get, ct).ConfigureAwait(false); - } - - #endregion - - #region Get open interest - - /// - public async Task>> GetOpenInterestAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "period", JsonConvert.SerializeObject(period, new DataPeriodConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/open-interest"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get recent big trades - - /// - public async Task>> GetRecentBigTradesAsync(string symbol, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/big-deal"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get long short ratio - - /// - public async Task>> GetLongShortRatioAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "period", JsonConvert.SerializeObject(period, new DataPeriodConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/account-ratio"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiTrading.cs b/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiTrading.cs deleted file mode 100644 index 7c64c1c5..00000000 --- a/ByBit.Net/Clients/InverseFuturesApi/BybitRestClientInverseFuturesApiTrading.cs +++ /dev/null @@ -1,527 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.InverseFuturesApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InverseFuturesApi -{ - /// - public class BybitRestClientInverseFuturesApiTrading : IBybitRestClientInverseFuturesApiTrading - { - private BybitRestClientInverseFuturesApi _baseClient; - - internal BybitRestClientInverseFuturesApiTrading(BybitRestClientInverseFuturesApi baseClient) - { - _baseClient = baseClient; - } - - #region Place order - - /// - public async Task> PlaceOrderAsync( - string symbol, - OrderSide side, - OrderType type, - PositionMode positionMode, - decimal quantity, - TimeInForce timeInForce, - decimal? price = null, - bool? closeOnTrigger = null, - string? clientOrderId = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - bool? reduceOnly = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "position_idx", JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false)) }, - { "symbol", symbol }, - { "order_type", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) }, - { "time_in_force", JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) }, - }; - - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("close_on_trigger", closeOnTrigger?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("reduce_only", reduceOnly?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get orders - - /// - public async Task>>> GetOrdersAsync( - string symbol, - OrderStatus? status = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_status", status == null ? null : JsonConvert.SerializeObject(status, new OrderStatusConverter(false))); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("futures/private/order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel order - - /// - public async Task> CancelOrderAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/order/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel all order - - /// - public async Task>> CancelAllOrdersAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("futures/private/order/cancelAll"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - if (result && result.Data == null) - return result.As>(new BybitCanceledOrder[0]); - - return result; - } - - #endregion - - #region Modify order - - /// - public async Task> ModifyOrderAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - decimal? newPrice = null, - decimal? newQuantity = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("p_r_price", newPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_qty", newQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/order/replace"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Get open orders realtime - - /// - public async Task> GetOpenOrderRealTimeAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - /// - public async Task>> GetOpenOrdersRealTimeAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("futures/private/order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Place conditional order - - /// - public async Task> PlaceConditionalOrderAsync( - string symbol, - OrderSide side, - OrderType type, - PositionMode positionMode, - decimal quantity, - decimal basePrice, - decimal triggerPrice, - TimeInForce timeInForce, - decimal? price = null, - TriggerType? triggerType = null, - bool? closeOnTrigger = null, - string? clientOrderId = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "position_idx", JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false)) }, - { "symbol", symbol }, - { "order_type", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) }, - { "base_price", basePrice.ToString(CultureInfo.InvariantCulture) }, - { "stop_px", triggerPrice.ToString(CultureInfo.InvariantCulture) }, - { "time_in_force", JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) }, - }; - - parameters.AddOptionalParameter("trigger_by", triggerType == null ? null : JsonConvert.SerializeObject(triggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("close_on_trigger", closeOnTrigger?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/stop-order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get conditional orders - - /// - public async Task>>> GetConditionalOrdersAsync( - string symbol, - StopOrderStatus? status = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_status", status == null ? null : JsonConvert.SerializeObject(status, new StopOrderStatusConverter(false))); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("futures/private/stop-order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel conditional order - - /// - public async Task> CancelConditionalOrderAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/stop-order/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel all conditional orders - - /// - public async Task>> CancelAllConditionalOrdersAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("futures/private/stop-order/cancelAll"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - if (result && result.Data == null) - return result.As>(new BybitCanceledConditionalOrder[0]); - - return result; - } - - #endregion - - #region Modify order - - /// - public async Task> ModifyConditionalOrderAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - decimal? newPrice = null, - decimal? newTriggerPrice = null, - decimal? newQuantity = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("p_r_price", newPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_qty", newQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_trigger_price", newTriggerPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/stop-order/replace"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Get open orders realtime - - /// - public async Task> GetOpenConditionalOrderRealTimeAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/stop-order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - /// - public async Task>> GetOpenConditionalOrdersRealTimeAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("futures/private/stop-order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region User trades - - /// - public async Task>> GetUserTradesAsync( - string symbol, - string? orderId = null, - DateTime? startTime = null, - int? page = null, - int? pageSize = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/execution/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Trades == null) - return result.As>(new BybitUserTrade[0]); - - return result.As(result.Data.Trades); - } - - #endregion - - #region Set Trading Stop - /// - public async Task> SetTradingStopAsync( - string symbol, - PositionMode positionMode, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - decimal? trailingStopPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - decimal? trailingStopTriggerPrice = null, - decimal? takeProfitQuantity = null, - decimal? stopLossQuantity = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "position_idx", JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false)) } - }; - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("trailing_stop", trailingStopPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("new_trailing_active", trailingStopTriggerPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("sl_size", stopLossQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_size", takeProfitQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("futures/private/position/trading-stop"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - #endregion - } -} diff --git a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApi.cs b/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApi.cs deleted file mode 100644 index 7dee171f..00000000 --- a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApi.cs +++ /dev/null @@ -1,134 +0,0 @@ -using Bybit.Net.Interfaces.Clients.InversePerpetualApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Options; -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; -using CryptoExchange.Net.Objects; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InversePerpetualApi -{ - /// - public class BybitRestClientInversePerpetualApi : RestApiClient, IBybitRestClientInversePerpetualApi - { - internal static TimeSyncState _timeSyncState = new TimeSyncState("Inverse Perpetual Api"); - - /// - /// Options - /// - public new BybitRestOptions ClientOptions => (BybitRestOptions)base.ClientOptions; - - /// - public IBybitRestClientInversePerpetualApiAccount Account { get; } - /// - public IBybitRestClientInversePerpetualApiExchangeData ExchangeData { get; } - /// - public IBybitRestClientInversePerpetualApiTrading Trading { get; } - - #region ctor - internal BybitRestClientInversePerpetualApi(ILogger logger, HttpClient? httpClient, BybitRestOptions options) : - base(logger, httpClient, options.Environment.RestBaseAddress, options, options.InversePerpetualOptions) - { - if (!string.IsNullOrEmpty(options.Referer)) - { - StandardRequestHeaders = new Dictionary - { - { "x-referer", options.Referer! } - }; - } - - manualParseError = true; - - Account = new BybitRestClientInversePerpetualApiAccount(this); - ExchangeData = new BybitRestClientInversePerpetualApiExchangeData(this); - Trading = new BybitRestClientInversePerpetualApiTrading(this); - - requestBodyFormat = RequestBodyFormat.FormData; - ParameterPositions[HttpMethod.Delete] = HttpMethodParameterPosition.InUri; - } - #endregion - - /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) - => new BybitAuthenticationProvider(credentials); - - /// - /// Get url for an endpoint - /// - /// - /// - internal Uri GetUrl(string endpoint) - { - return new Uri(BaseAddress.AppendPath(endpoint)); - } - - /// - protected override Task TryParseErrorAsync(JToken data) - { - var responseCode = data["ret_code"]; - if (responseCode != null && responseCode.ToString() != "0") - { - var errorMessage = data["ret_msg"]; - return Task.FromResult(new ServerError(responseCode.Value(), errorMessage!.ToString()))!; - } - - return Task.FromResult(null); - } - - internal async Task>> SendRequestWrapperAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null, - bool ignoreRatelimit = false) where T : class - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer, ignoreRatelimit: ignoreRatelimit).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.ReturnCode != 0) - return result.AsError>(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data); - } - - internal async Task> SendRequestAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null) - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer).ConfigureAwait(false); - if (!result) - return result.As(default); - - if (result.Data.ReturnCode != 0) - return result.AsError(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data.Result); - } - - /// - protected override Task> GetServerTimestampAsync() - => ExchangeData.GetServerTimeAsync(); - - /// - public override TimeSyncInfo? GetTimeSyncInfo() - => new TimeSyncInfo(_logger, (ApiOptions.AutoTimestamp ?? ClientOptions.AutoTimestamp), (ApiOptions.TimestampRecalculationInterval ?? ClientOptions.TimestampRecalculationInterval), _timeSyncState); - - /// - public override TimeSpan? GetTimeOffset() - => _timeSyncState.TimeOffset; - } -} diff --git a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiAccount.cs b/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiAccount.cs deleted file mode 100644 index 3a06b46d..00000000 --- a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiAccount.cs +++ /dev/null @@ -1,314 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.InversePerpetualApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InversePerpetualApi -{ - /// - public class BybitRestClientInversePerpetualApiAccount : IBybitRestClientInversePerpetualApiAccount - { - private BybitRestClientInversePerpetualApi _baseClient; - - internal BybitRestClientInversePerpetualApiAccount(BybitRestClientInversePerpetualApi baseClient) - { - _baseClient = baseClient; - } - - #region Get risk limit - - /// - public async Task>> GetRiskLimitAsync(string? symbol = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/risk-limit/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Set risk limit - - /// - public async Task> SetRiskLimitAsync(string symbol, long riskId, PositionMode? mode = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "risk_id", riskId.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("position_idx", mode == null ? null : JsonConvert.SerializeObject(mode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/position/risk-limit"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get positions - /// - public async Task> GetPositionAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/position/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - /// - public async Task>> GetPositionsAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/position/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - foreach (var position in result.Data) - position.Data.IsValid = position.IsValid; - - return result.As(result.Data.Select(d => d.Data)); - } - - #endregion - - #region Change margin - - /// - public async Task> ChangeMarginAsync(string symbol, decimal margin, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "margin", margin.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/position/change-position-margin"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set leverage - - /// - public async Task> SetLeverageAsync(string symbol, decimal leverage, bool? leverageOnly = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "leverage", leverage.ToString(CultureInfo.InvariantCulture) } - }; - parameters.AddOptionalParameter("leverage_only", leverageOnly); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/position/leverage/save"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get Profit And Loss History - - /// - public async Task>>> GetProfitAndLossHistoryAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, TradeType? type = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToSeconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToSeconds(endTime)); - parameters.AddOptionalParameter("exec_type", type == null ? null : JsonConvert.SerializeObject(type.Value, new TradeTypeConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/trade/closed-pnl/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - if (result && result.Data.Data == null) - result.Data.Data = new BybitPnlEntry[0]; - - return result; - } - - #endregion - - #region Set full / partial position mode - - /// - public async Task> SetFullPartialPositionModeAsync(string symbol, StopLossTakeProfitMode mode, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "tp_sl_mode", JsonConvert.SerializeObject(mode, new StopLossTakeProfitModeConverter(false)) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/tpsl/switch-mode"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set isolated mode - - /// - public async Task SetIsolatedPositionModeAsync(string symbol, bool isIsolated, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "is_isolated", isIsolated.ToString() }, - { "buy_leverage", buyLeverage.ToString(CultureInfo.InvariantCulture) }, - { "sell_leverage", sellLeverage.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/position/switch-isolated"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Get balances - - /// - public async Task>> GetBalancesAsync(string? asset = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/wallet/balance"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get last user funding fee - - /// - public async Task> GetLastUserFundingFeeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/funding/prev-funding"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get predicted user funding fee - - /// - public async Task> GetPredictedUserFundingFeeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/funding/predicted-funding"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get wallet fund history - - /// - public async Task>> GetWalletFundHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WalletFundType? type = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_date", startTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("end_date", endTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("wallet_fund_type", type == null ? null : JsonConvert.SerializeObject(type, new WalletFundTypeConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString()); - parameters.AddOptionalParameter("limit", pageSize?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/wallet/fund/records"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Data == null) - return result.As>(new BybitWalletFundRecord[0]); - - return result.As(result.Data.Data); - } - - #endregion - - #region Get withdrawal history - - /// - public async Task>> GetWithdrawalHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WithdrawStatus? status = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_date", startTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("end_date", endTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("status", status == null ? null : JsonConvert.SerializeObject(status, new WithdrawStatusConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString()); - parameters.AddOptionalParameter("limit", pageSize?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/wallet/withdraw/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Data == null) - return result.As>(new BybitWithdrawal[0]); - - return result.As(result.Data.Data); - } - - #endregion - - #region Get asset exchange history - - /// - public async Task>> GetAssetExchangeHistoryAsync(long? fromId = null, SearchDirection? direction = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("from", fromId?.ToString()); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/exchange-order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get api key info - - /// - public async Task>> GetApiKeyInfoAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/account/api-key"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiExchangeData.cs b/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiExchangeData.cs deleted file mode 100644 index a55c3192..00000000 --- a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiExchangeData.cs +++ /dev/null @@ -1,245 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.InversePerpetualApi; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InversePerpetualApi -{ - /// - public class BybitRestClientInversePerpetualApiExchangeData : IBybitRestClientInversePerpetualApiExchangeData - { - private BybitRestClientInversePerpetualApi _baseClient; - - internal BybitRestClientInversePerpetualApiExchangeData(BybitRestClientInversePerpetualApi baseClient) - { - _baseClient = baseClient; - } - - #region Get klines - - /// - public async Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/kline/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get trade history - - /// - public async Task>> GetTradeHistoryAsync(string symbol, long? fromId = null, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("fromId", fromId?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/trading-records"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get last funding rate - - /// - public async Task> GetLastFundingRateAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/public/funding/prev-funding-rate"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get mark price klines - - /// - public async Task>> GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/mark-price-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get index price klines - - /// - public async Task>> GetIndexPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from) }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/index-price-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get premium index price klines - - /// - public async Task>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/premium-index-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get server time - - /// - public async Task> GetServerTimeAsync(CancellationToken ct = default) - { - var result = await _baseClient.SendRequestWrapperAsync(_baseClient.GetUrl("v2/public/time"), HttpMethod.Get, ct, null, ignoreRatelimit: true).ConfigureAwait(false); - if (!result) - return result.As(default); - - return result.As(result.Data.Timestamp); - } - - #endregion - - #region Get announcement - - /// - public async Task>> GetAnnouncementsAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/announcement"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get order book - - /// - public async Task>> GetOrderBookAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/orderBook/L2"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get tickers - - /// - public async Task>> GetTickersAsync(string? symbol = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/tickers"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get symbols - - /// - public async Task>> GetSymbolsAsync(CancellationToken ct = default) - { - var parameters = new Dictionary(); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/symbols"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get open interest - - /// - public async Task>> GetOpenInterestAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "period", JsonConvert.SerializeObject(period, new DataPeriodConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/open-interest"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get recent big trades - - /// - public async Task>> GetRecentBigTradesAsync(string symbol, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/big-deal"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get long short ratio - - /// - public async Task>> GetLongShortRatioAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "period", JsonConvert.SerializeObject(period, new DataPeriodConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/account-ratio"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiTrading.cs b/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiTrading.cs deleted file mode 100644 index 497a9b16..00000000 --- a/ByBit.Net/Clients/InversePerpetualApi/BybitRestClientInversePerpetualApiTrading.cs +++ /dev/null @@ -1,523 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.InversePerpetualApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.InversePerpetualApi -{ - /// - public class BybitRestClientInversePerpetualApiTrading : IBybitRestClientInversePerpetualApiTrading - { - private BybitRestClientInversePerpetualApi _baseClient; - - internal BybitRestClientInversePerpetualApiTrading(BybitRestClientInversePerpetualApi baseClient) - { - _baseClient = baseClient; - } - - #region Place order - - /// - public async Task> PlaceOrderAsync( - string symbol, - OrderSide side, - OrderType type, - decimal quantity, - TimeInForce timeInForce, - decimal? price = null, - bool? closeOnTrigger = null, - string? clientOrderId = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - bool? reduceOnly = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "symbol", symbol }, - { "order_type", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) }, - { "time_in_force", JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) }, - }; - - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("close_on_trigger", closeOnTrigger?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("reduce_only", reduceOnly?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get orders - - /// - public async Task>>> GetOrdersAsync( - string symbol, - OrderStatus? status = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_status", status == null ? null : JsonConvert.SerializeObject(status, new OrderStatusConverter(false))); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel order - - /// - public async Task> CancelOrderAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/order/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel all order - - /// - public async Task>> CancelAllOrdersAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/order/cancelAll"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - if (result && result.Data == null) - return result.As>(new BybitCanceledOrder[0]); - - return result; - } - - #endregion - - #region Modify order - - /// - public async Task> ModifyOrderAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - decimal? newPrice = null, - decimal? newQuantity = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("p_r_price", newPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_qty", newQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/order/replace"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Get open orders realtime - - /// - public async Task> GetOpenOrderRealTimeAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - /// - public async Task>> GetOpenOrdersRealTimeAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Place conditional order - - /// - public async Task> PlaceConditionalOrderAsync( - string symbol, - OrderSide side, - OrderType type, - PositionMode positionMode, - decimal quantity, - decimal basePrice, - decimal triggerPrice, - TimeInForce timeInForce, - decimal? price = null, - TriggerType? triggerType = null, - bool? closeOnTrigger = null, - string? clientOrderId = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "position_idx", JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false)) }, - { "symbol", symbol }, - { "order_type", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) }, - { "base_price", basePrice.ToString(CultureInfo.InvariantCulture) }, - { "stop_px", triggerPrice.ToString(CultureInfo.InvariantCulture) }, - { "time_in_force", JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) }, - }; - - parameters.AddOptionalParameter("trigger_by", triggerType == null ? null : JsonConvert.SerializeObject(triggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("close_on_trigger", closeOnTrigger?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/stop-order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get conditional orders - - /// - public async Task>>> GetConditionalOrdersAsync( - string symbol, - StopOrderStatus? status = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_status", status == null ? null : JsonConvert.SerializeObject(status, new StopOrderStatusConverter(false))); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("cursor", cursor); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/stop-order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel conditional order - - /// - public async Task> CancelConditionalOrderAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/stop-order/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel all conditional orders - - /// - public async Task>> CancelAllConditionalOrdersAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/stop-order/cancelAll"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - if (result && result.Data == null) - return result.As>(new BybitCanceledConditionalOrder[0]); - - return result; - } - - #endregion - - #region Modify order - - /// - public async Task> ModifyConditionalOrderAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - decimal? newPrice = null, - decimal? newTriggerPrice = null, - decimal? newQuantity = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("p_r_price", newPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_qty", newQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_trigger_price", newTriggerPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/stop-order/replace"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Get open orders realtime - - /// - public async Task> GetOpenConditionalOrderRealTimeAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/stop-order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - /// - public async Task>> GetOpenConditionalOrdersRealTimeAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/stop-order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region User trades - - /// - public async Task>> GetUserTradesAsync( - string symbol, - string? orderId = null, - DateTime? startTime = null, - int? page = null, - int? pageSize = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/execution/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Trades == null) - return result.As>(new BybitUserTrade[0]); - - return result.As(result.Data.Trades); - } - - #endregion - - #region Set Trading Stop - /// - public async Task> SetTradingStopAsync( - string symbol, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - decimal? trailingStopPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - decimal? trailingStopTriggerPrice = null, - decimal? takeProfitQuantity = null, - decimal? stopLossQuantity = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("trailing_stop", trailingStopPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("new_trailing_active", trailingStopTriggerPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("sl_size", stopLossQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_size", takeProfitQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("v2/private/position/trading-stop"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - #endregion - } -} diff --git a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiAccountV1.cs b/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiAccountV1.cs deleted file mode 100644 index 2249f7ab..00000000 --- a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiAccountV1.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Bybit.Net.Interfaces.Clients.SpotApi.v1; -using Bybit.Net.Objects.Models.Spot; -using CryptoExchange.Net; -using CryptoExchange.Net.Objects; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.SpotApi.v1 -{ - /// - public class BybitRestClientSpotApiAccountV1 : IBybitRestClientSpotApiAccountV1 - { - private BybitRestClientBaseSpotApi _baseClient; - - internal BybitRestClientSpotApiAccountV1(BybitRestClientBaseSpotApi baseClient) - { - _baseClient = baseClient; - } - - #region Get balances - - /// - public async Task>> GetBalancesAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/account"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - return result.As(result.Data?.Balances!); - } - - #endregion - - #region Get margin account info - - /// - public async Task> GetMarginAccountInfoAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/cross-margin/accounts/balance"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiExchangeDataV1.cs b/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiExchangeDataV1.cs deleted file mode 100644 index c6c02147..00000000 --- a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiExchangeDataV1.cs +++ /dev/null @@ -1,207 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Bybit.Net.Objects.Models.Spot; -using Bybit.Net.Interfaces.Clients.SpotApi.v1; -using Bybit.Net.Objects.Models.Spot.v1; - -namespace Bybit.Net.Clients.SpotApi.v1 -{ - /// - public class BybitRestClientSpotApiExchangeDataV1 : IBybitRestClientSpotApiExchangeDataV1 - { - private BybitRestClientBaseSpotApi _baseClient; - - internal BybitRestClientSpotApiExchangeDataV1(BybitRestClientBaseSpotApi baseClient) - { - _baseClient = baseClient; - } - - #region Get server time - - /// - public async Task> GetServerTimeAsync(CancellationToken ct = default) - { - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/time"), HttpMethod.Get, ct, null, ignoreRatelimit: true).ConfigureAwait(false); - return result.As(result.Data?.ServerTime ?? default); - } - - #endregion - - #region Get symbols - - /// - public async Task>> GetSymbolsAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/v1/symbols"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get Order book - - /// - public async Task> GetOrderBookAsync(string symbol, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/quote/v1/depth"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get Merged order book - - /// - public async Task> GetMergedOrderBookAsync(string symbol, int? scale = null, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("scale", scale?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/quote/v1/depth/merged"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get trade history - - /// - public async Task>> GetTradeHistoryAsync(string symbol, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/quote/v1/trades"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get klines - - /// - public async Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalSpotConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/quote/v1/kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get ticker - - /// - public async Task> GetTickerAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/quote/v1/ticker/24hr"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get tickers - - /// - public async Task>> GetTickersAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/quote/v1/ticker/24hr"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get price - - /// - public async Task> GetPriceAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/quote/v1/ticker/price"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get prices - - /// - public async Task>> GetPricesAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/quote/v1/ticker/price"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get book price - - /// - public async Task> GetBookPriceAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/quote/v1/ticker/book_ticker"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get prices - - /// - public async Task>> GetBookPricesAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/quote/v1/ticker/book_ticker"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get Borrow info - - /// - public async Task> GetBorrowInterestAndQuotaAsync(string asset, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "currency", asset } - }; - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/cross-margin/loan-info"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiTradingV1.cs b/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiTradingV1.cs deleted file mode 100644 index 3ca6a90c..00000000 --- a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiTradingV1.cs +++ /dev/null @@ -1,235 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Objects.Models.Spot; -using CryptoExchange.Net; -using CryptoExchange.Net.CommonObjects; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Bybit.Net.Interfaces.Clients.SpotApi.v1; -using Bybit.Net.Objects.Models.Spot.v1; - -namespace Bybit.Net.Clients.SpotApi.v1 -{ - /// - public class BybitRestClientSpotApiTradingV1 : IBybitRestClientSpotApiTradingV1 - { - private readonly BybitRestClientBaseSpotApi _baseClient; - - internal BybitRestClientSpotApiTradingV1(BybitRestClientBaseSpotApi baseClient) - { - _baseClient = baseClient; - } - - #region Place order - - /// - public async Task> PlaceOrderAsync(string symbol, OrderSide side, OrderType type, decimal quantity, decimal? price = null, TimeInForce? timeInForce = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "type", JsonConvert.SerializeObject(type, new OrderTypeSpotConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) } - }; - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("timeInForce", timeInForce == null ? null : JsonConvert.SerializeObject(timeInForce, new TimeInForceSpotConverter(false))); - parameters.AddOptionalParameter("orderLinkId", clientOrderId); - parameters.AddOptionalParameter("agentSource", _baseClient.ClientOptions.Referer); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/order"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - if (result) - _baseClient.InvokeOrderPlaced(new OrderId { SourceObject = result.Data, Id = result.Data.Id.ToString(CultureInfo.InvariantCulture) }); - return result; - } - - #endregion - - #region Get order - - /// - public async Task> GetOrderAsync(long? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary(); - parameters.AddOptionalParameter("orderId", orderId); - parameters.AddOptionalParameter("orderLinkId", clientOrderId); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get open orders - - /// - public async Task>> GetOpenOrdersAsync(string? symbol = null, long? orderId = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("orderId", orderId); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("limit", limit); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/v1/open-orders"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get open orders - - /// - public async Task>> GetOrdersAsync(string? symbol = null, long? orderId = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("orderId", orderId); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("limit", limit); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/v1/history-orders"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Cancel order - - /// - public async Task> CancelOrderAsync(long? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary(); - parameters.AddOptionalParameter("orderId", orderId); - parameters.AddOptionalParameter("orderLinkId", clientOrderId); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/order"), HttpMethod.Delete, ct, parameters, true).ConfigureAwait(false); - if (result) - _baseClient.InvokeOrderCanceled(new OrderId { SourceObject = result.Data, Id = result.Data.Id.ToString(CultureInfo.InvariantCulture) }); - return result; - } - - #endregion - - #region Cancel MultipleOrders - /// - public async Task CancelMultipleOrderAsync(string symbol, OrderSide? side = null, IEnumerable? orderTypes = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("side", side.HasValue ? JsonConvert.SerializeObject(side, new OrderSideConverter(false)) : null); - parameters.AddOptionalParameter("orderTypes", orderTypes != null && orderTypes.Any() ? string.Join(",", orderTypes.Select(o => JsonConvert.SerializeObject(o, new OrderTypeConverter(false)))) : null); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/order/batch-cancel"), HttpMethod.Delete, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - #endregion - - #region Get user trades - - /// - public async Task>> GetUserTradesAsync(string? symbol = null, long? fromId = null, long? toId = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("fromId", fromId); - parameters.AddOptionalParameter("toId", toId); - parameters.AddOptionalParameter("symbol", symbol); - parameters.AddOptionalParameter("limit", limit); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/v1/myTrades"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Cross marging - - #region Place borrow order - - /// - public async Task> PlaceBorrowOrderAsync(string asset, decimal quantity, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "currency", asset }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) } - }; - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/cross-margin/loan"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Place repay order - - /// - public async Task> PlaceRepayOrderAsync(string asset, decimal quantity, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "currency", asset }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) } - }; - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("spot/v1/cross-margin/repay"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get borrow info - - /// - public async Task>> GetBorrowRecordsAsync(DateTime? startTime = null, DateTime? endTime = null, string? asset = null, BorrowStatus? status = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime)); - parameters.AddOptionalParameter("currency", asset); - parameters.AddOptionalParameter("status", EnumConverter.GetString(status)); - parameters.AddOptionalParameter("limit", limit); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/v1/cross-margin/order"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get repayment history - - /// - public async Task>> GetRepayRecordsAsync(DateTime? startTime = null, DateTime? endTime = null, string? asset = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime)); - parameters.AddOptionalParameter("currency", asset); - parameters.AddOptionalParameter("limit", limit); - parameters.AddOptionalParameter("recvWindow", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("spot/v1/cross-margin/repay/history"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #endregion - } -} diff --git a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiV1.cs b/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiV1.cs deleted file mode 100644 index 68d6c4dd..00000000 --- a/ByBit.Net/Clients/SpotApi/v1/BybitRestClientSpotApiV1.cs +++ /dev/null @@ -1,319 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.SpotApi.v1; -using Bybit.Net.Objects.Options; -using CryptoExchange.Net.CommonObjects; -using CryptoExchange.Net.Interfaces.CommonClients; -using CryptoExchange.Net.Objects; -using Microsoft.Extensions.Logging; - -namespace Bybit.Net.Clients.SpotApi.v1 -{ - /// - public class BybitRestClientSpotApiV1 : BybitRestClientBaseSpotApi, IBybitRestClientSpotApiV1 - { - /// - public IBybitRestClientSpotApiAccountV1 Account { get; } - /// - public IBybitRestClientSpotApiExchangeDataV1 ExchangeData { get; } - /// - public IBybitRestClientSpotApiTradingV1 Trading { get; } - #region ctor - internal BybitRestClientSpotApiV1(ILogger log, HttpClient? httpClient, BybitRestOptions options) - : base(log, httpClient, options.Environment.RestBaseAddress, options, options.SpotOptions) - { - if (!string.IsNullOrEmpty(options.Referer)) - { - StandardRequestHeaders = new Dictionary - { - { "x-referer", options.Referer! } - }; - } - - Account = new BybitRestClientSpotApiAccountV1(this); - ExchangeData = new BybitRestClientSpotApiExchangeDataV1(this); - Trading = new BybitRestClientSpotApiTradingV1(this); - } - #endregion - - - #region Common interface - - /// - public override async Task>> GetSymbolsAsync(CancellationToken ct) - { - var result = await ExchangeData.GetSymbolsAsync(ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Symbol - { - SourceObject = r, - Name = r.Name, - MinTradeQuantity = r.MinOrderQuantity, - PriceStep = r.PricePrecision, - QuantityStep = r.BasePrecision - })); - } - - /// - public override async Task>> GetTickersAsync(CancellationToken ct) - { - var result = await ExchangeData.GetTickersAsync(ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Ticker - { - SourceObject = r, - Symbol = r.Symbol, - HighPrice = r.HighPrice, - LastPrice = r.LastPrice, - LowPrice = r.LowPrice, - Price24H = r.OpenPrice, - Volume = r.Volume - })); - } - - /// - public override async Task> GetTickerAsync(string symbol, CancellationToken ct) - { - if (string.IsNullOrEmpty(symbol)) - throw new ArgumentException(nameof(symbol) + " required for Bybit " + nameof(ISpotClient.GetTickerAsync), nameof(symbol)); - - var result = await ExchangeData.GetTickerAsync(symbol, ct: ct).ConfigureAwait(false); - if (!result) - return result.As(null); - - return result.As(new Ticker - { - SourceObject = result.Data, - Symbol = result.Data.Symbol, - HighPrice = result.Data.HighPrice, - LastPrice = result.Data.LastPrice, - LowPrice = result.Data.LowPrice, - Price24H = result.Data.OpenPrice, - Volume = result.Data.Volume - }); - } - - /// - public override async Task>> GetKlinesAsync(string symbol, TimeSpan timespan, DateTime? startTime, DateTime? endTime, int? limit, CancellationToken ct) - { - if (string.IsNullOrEmpty(symbol)) - throw new ArgumentException(nameof(symbol) + " required for Bybit " + nameof(ISpotClient.GetKlinesAsync), nameof(symbol)); - - var result = await ExchangeData.GetKlinesAsync(symbol, TimeSpanToInterval(timespan), startTime, endTime, limit, ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Kline - { - SourceObject = r, - HighPrice = r.HighPrice, - LowPrice = r.LowPrice, - Volume = r.Volume, - ClosePrice = r.ClosePrice, - OpenPrice = r.OpenPrice, - OpenTime = r.OpenTime - })); - } - - /// - public override async Task> GetOrderBookAsync(string symbol, CancellationToken ct) - { - if (string.IsNullOrEmpty(symbol)) - throw new ArgumentException(nameof(symbol) + " required for Bybit " + nameof(ISpotClient.GetOrderBookAsync), nameof(symbol)); - - var result = await ExchangeData.GetOrderBookAsync(symbol, ct: ct).ConfigureAwait(false); - if (!result) - return result.As(null); - - return result.As(new OrderBook - { - SourceObject = result.Data, - Asks = result.Data.Asks.Select(a => new OrderBookEntry { Price = a.Price, Quantity = a.Quantity }), - Bids = result.Data.Bids.Select(b => new OrderBookEntry { Price = b.Price, Quantity = b.Quantity }) - }); - } - - /// - public override async Task>> GetRecentTradesAsync(string symbol, CancellationToken ct) - { - if (string.IsNullOrEmpty(symbol)) - throw new ArgumentException(nameof(symbol) + " required for Bybit " + nameof(ISpotClient.GetRecentTradesAsync), nameof(symbol)); - - var result = await ExchangeData.GetTradeHistoryAsync(symbol).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Trade - { - SourceObject = r, - Price = r.Price, - Quantity = r.Quantity, - Symbol = symbol, - Timestamp = r.TradeTime - })); - } - - /// - public override async Task> PlaceOrderAsync(string symbol, CommonOrderSide side, CommonOrderType type, decimal quantity, decimal? price, string? accountId, string? clientOrderId, CancellationToken ct) - { - if (string.IsNullOrEmpty(symbol)) - throw new ArgumentException(nameof(symbol) + " required for Bybit " + nameof(ISpotClient.PlaceOrderAsync), nameof(symbol)); - - var result = await Trading.PlaceOrderAsync( - symbol, - side == CommonOrderSide.Buy ? OrderSide.Buy : OrderSide.Sell, - type == CommonOrderType.Limit ? OrderType.Limit : OrderType.Market, - quantity, - price, - type == CommonOrderType.Limit ? TimeInForce.GoodTillCanceled : (TimeInForce?)null, - clientOrderId: clientOrderId, - ct: ct).ConfigureAwait(false); - if (!result) - return result.As(null); - - return result.As(new OrderId - { - SourceObject = result.Data, - Id = result.Data.Id.ToString(CultureInfo.InvariantCulture) - }); - } - - /// - public override async Task> GetOrderAsync(string orderId, string? symbol, CancellationToken ct) - { - if (!long.TryParse(orderId, out var id)) - throw new ArgumentException($"Invalid order id for Bybit {nameof(ISpotClient.GetOrderAsync)}", nameof(orderId)); - - var result = await Trading.GetOrderAsync(id, ct: ct).ConfigureAwait(false); - if (!result) - return result.As(null); - - return result.As(new Order - { - SourceObject = result.Data, - Id = result.Data.Id.ToString(CultureInfo.InvariantCulture), - Price = result.Data.Price, - Quantity = result.Data.Quantity, - QuantityFilled = result.Data.QuantityFilled, - Timestamp = result.Data.CreateTime, - Symbol = result.Data.Symbol, - Side = result.Data.Side == OrderSide.Buy ? CommonOrderSide.Buy : CommonOrderSide.Sell, - Type = result.Data.Type == OrderType.Limit ? CommonOrderType.Limit : result.Data.Type == OrderType.Market ? CommonOrderType.Market : CommonOrderType.Other, - Status = result.Data.Status == OrderStatus.Canceled ? CommonOrderStatus.Canceled : result.Data.Status == OrderStatus.Filled ? CommonOrderStatus.Filled : CommonOrderStatus.Active - }); - } - - /// - public override async Task>> GetOrderTradesAsync(string orderId, string? symbol, CancellationToken ct) - { - if (!long.TryParse(orderId, out var id)) - throw new ArgumentException($"Invalid order id for Bybit {nameof(ISpotClient.GetOrderAsync)}", nameof(orderId)); - - var result = await Trading.GetUserTradesAsync(fromId: id, toId: long.Parse(orderId), ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new UserTrade - { - SourceObject = r, - Id = r.Id.ToString(CultureInfo.InvariantCulture), - OrderId = r.OrderId.ToString(CultureInfo.InvariantCulture), - Symbol = r.Symbol, - Fee = r.Fee, - FeeAsset = r.FeeAsset, - Price = r.Price, - Quantity = r.Quantity, - Timestamp = r.TradeTime - })); - } - - /// - public override async Task>> GetOpenOrdersAsync(string? symbol, CancellationToken ct) - { - var result = await Trading.GetOpenOrdersAsync(symbol, ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Order - { - SourceObject = r, - Id = r.Id.ToString(CultureInfo.InvariantCulture), - Price = r.Price, - Quantity = r.Quantity, - QuantityFilled = r.QuantityFilled, - Timestamp = r.CreateTime, - Symbol = r.Symbol, - Side = r.Side == OrderSide.Buy ? CommonOrderSide.Buy : CommonOrderSide.Sell, - Type = r.Type == OrderType.Limit ? CommonOrderType.Limit: r.Type == OrderType.Market ? CommonOrderType.Market: CommonOrderType.Other, - Status = r.Status == OrderStatus.Canceled ? CommonOrderStatus.Canceled: r.Status == OrderStatus.Filled ? CommonOrderStatus.Filled: CommonOrderStatus.Active - })); - } - - /// - public override async Task>> GetClosedOrdersAsync(string? symbol, CancellationToken ct) - { - var result = await Trading.GetOrdersAsync(symbol, ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Order - { - SourceObject = r, - Id = r.Id.ToString(CultureInfo.InvariantCulture), - Price = r.Price, - Quantity = r.Quantity, - QuantityFilled = r.QuantityFilled, - Timestamp = r.CreateTime, - Symbol = r.Symbol, - Side = r.Side == OrderSide.Buy ? CommonOrderSide.Buy : CommonOrderSide.Sell, - Type = r.Type == OrderType.Limit ? CommonOrderType.Limit : r.Type == OrderType.Market ? CommonOrderType.Market : CommonOrderType.Other, - Status = r.Status == OrderStatus.Canceled ? CommonOrderStatus.Canceled : r.Status == OrderStatus.Filled ? CommonOrderStatus.Filled : CommonOrderStatus.Active - })); - } - - /// - public override async Task> CancelOrderAsync(string orderId, string? symbol, CancellationToken ct) - { - if (!long.TryParse(orderId, out var id)) - throw new ArgumentException($"Invalid order id for Bybit {nameof(ISpotClient.GetOrderAsync)}", nameof(orderId)); - - var result = await Trading.CancelOrderAsync(id, ct: ct).ConfigureAwait(false); - if (!result) - return result.As(null); - - return result.As(new OrderId { SourceObject = result.Data, Id = result.Data.Id.ToString(CultureInfo.InvariantCulture) }); - } - - /// - public override async Task>> GetBalancesAsync(string? accountId, CancellationToken ct) - { - var result = await Account.GetBalancesAsync(ct: ct).ConfigureAwait(false); - if (!result) - return result.As>(null); - - return result.As(result.Data.Select(r => new Balance - { - SourceObject = r, - Asset = r.Asset, - Available = r.Available, - Total = r.Total - })); - } - - #endregion - - /// - protected override Task> GetServerTimestampAsync() - => ExchangeData.GetServerTimeAsync(); - } -} diff --git a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApi.cs b/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApi.cs deleted file mode 100644 index c853d14c..00000000 --- a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApi.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Options; -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; -using CryptoExchange.Net.Objects; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.UsdPerpetualApi -{ - /// - public class BybitRestClientUsdPerpetualApi : RestApiClient, IBybitRestClientUsdPerpetualApi - { - internal static TimeSyncState _timeSyncState = new TimeSyncState("USD Perpetual Api"); - - /// - /// Options - /// - public new BybitRestOptions ClientOptions => (BybitRestOptions)base.ClientOptions; - - /// - public IBybitRestClientUsdPerpetualApiAccount Account { get; } - /// - public IBybitRestClientUsdPerpetualApiExchangeData ExchangeData { get; } - /// - public IBybitRestClientUsdPerpetualApiTrading Trading { get; } - - #region ctor - internal BybitRestClientUsdPerpetualApi(ILogger logger, HttpClient? httpClient, BybitRestOptions options) : - base(logger, httpClient, options.Environment.RestBaseAddress, options, options.UsdPerpetualOptions) - { - if (!string.IsNullOrEmpty(options.Referer)) - { - StandardRequestHeaders = new Dictionary - { - { "x-referer", options.Referer! } - }; - } - - manualParseError = true; - - Account = new BybitRestClientUsdPerpetualApiAccount(this); - ExchangeData = new BybitRestClientUsdPerpetualApiExchangeData(this); - Trading = new BybitRestClientUsdPerpetualApiTrading(this); - requestBodyFormat = RequestBodyFormat.FormData; - ParameterPositions[HttpMethod.Delete] = HttpMethodParameterPosition.InUri; - } - #endregion - - /// - protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) - => new BybitAuthenticationProvider(credentials); - - /// - /// Get url for an endpoint - /// - /// - /// - internal Uri GetUrl(string endpoint) - { - return new Uri(BaseAddress.AppendPath(endpoint)); - } - - /// - protected override Task TryParseErrorAsync(JToken data) - { - var responseCode = data["ret_code"]; - if (responseCode != null && responseCode.ToString() != "0") - { - var errorMessage = data["ret_msg"]; - return Task.FromResult(new ServerError(responseCode.Value(), errorMessage!.ToString()))!; - } - - return Task.FromResult(null); - } - - internal async Task>> SendRequestWrapperAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null, - bool ignoreRatelimit = false) where T : class - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer, ignoreRatelimit: ignoreRatelimit).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.ReturnCode != 0) - return result.AsError>(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data); - } - - internal async Task> SendRequestAsync( - Uri uri, - HttpMethod method, - CancellationToken cancellationToken, - Dictionary? parameters = null, - bool signed = false, - JsonSerializer? deserializer = null) - { - var result = await base.SendRequestAsync>(uri, method, cancellationToken, parameters, signed, deserializer: deserializer).ConfigureAwait(false); - if (!result) - return result.As(default); - - if (result.Data.ReturnCode != 0) - return result.AsError(new ServerError(result.Data.ReturnCode, result.Data.ReturnMessage)); - - return result.As(result.Data.Result); - } - - /// - protected override Task> GetServerTimestampAsync() - => ExchangeData.GetServerTimeAsync(); - - /// - public override TimeSyncInfo? GetTimeSyncInfo() - => new TimeSyncInfo(_logger, (ApiOptions.AutoTimestamp ?? ClientOptions.AutoTimestamp), (ApiOptions.TimestampRecalculationInterval ?? ClientOptions.TimestampRecalculationInterval), _timeSyncState); - - /// - public override TimeSpan? GetTimeOffset() - => _timeSyncState.TimeOffset; - } -} diff --git a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiAccount.cs b/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiAccount.cs deleted file mode 100644 index 8d84cd1c..00000000 --- a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiAccount.cs +++ /dev/null @@ -1,377 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.UsdPerpetualApi -{ - /// - public class BybitRestClientUsdPerpetualApiAccount : IBybitRestClientUsdPerpetualApiAccount - { - private BybitRestClientUsdPerpetualApi _baseClient; - - internal BybitRestClientUsdPerpetualApiAccount(BybitRestClientUsdPerpetualApi baseClient) - { - _baseClient = baseClient; - } - - #region Get last funding rate - - /// - public async Task> GetUserLastFundingFeeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/funding/prev-funding"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get predicted funding rate - - /// - public async Task> GetUserPredictedFundingRateAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/funding/predicted-funding"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get risk limit - - /// - public async Task>> GetRiskLimitAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("public/linear/risk-limit"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set risk limit - - /// - public async Task> SetRiskLimitAsync(string symbol, OrderSide side, long riskId, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "risk_id", riskId.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("position_idx", positionMode == null ? null : JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/set-risk"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get position - - /// - public async Task>> GetPositionAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("private/linear/position/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get positions - - /// - public async Task>> GetPositionsAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("private/linear/position/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - foreach (var position in result.Data) - position.Data.IsValid = position.IsValid; - - return result.As(result.Data.Select(d => d.Data)); - } - - #endregion - - #region Set auto add margin - - /// - public async Task SetAutoAddMarginAsync(string symbol, OrderSide side, bool autoAddMargin, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "auto_add_margin", autoAddMargin.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("position_idx", positionMode == null ? null : JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/set-auto-add-margin"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Add / Reduce margin - - /// - public async Task> AddReduceMarginAsync(string symbol, OrderSide side, decimal margin, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "margin", margin.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("position_idx", positionMode == null ? null : JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/add-margin"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set leverage - - /// - public async Task SetLeverageAsync(string symbol, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "buy_leverage", buyLeverage.ToString(CultureInfo.InvariantCulture) }, - { "sell_leverage", sellLeverage.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/set-leverage"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Get Profit And Loss History - - /// - public async Task>>> GetProfitAndLossHistoryAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, TradeType? type = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToSeconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToSeconds(endTime)); - parameters.AddOptionalParameter("exec_type", type == null ? null : JsonConvert.SerializeObject(type.Value, new TradeTypeConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("private/linear/trade/closed-pnl/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - if (result && result.Data.Data == null) - result.Data.Data = new BybitPnlEntry[0]; - - return result; - } - - #endregion - - #region Set full / partial position mode - - /// - public async Task> SetFullPartialPositionModeAsync(string symbol, StopLossTakeProfitMode mode, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "tp_sl_mode", JsonConvert.SerializeObject(mode, new StopLossTakeProfitModeConverter(false)) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/tpsl/switch-mode"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set Position Mode Switch - - /// - public async Task SetPositionModeAsync(string symbol, string asset, bool hedgeMode, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - if (string.IsNullOrWhiteSpace(asset)) - { - parameters.Add("symbol", symbol); - } - else if (string.IsNullOrWhiteSpace(symbol)) - { - parameters.Add("coin", asset); - } - else - { - throw new ArgumentNullException("One of 'coin' or 'symbol' parameters is required!"); - } - - parameters.Add("mode", hedgeMode ? "BothSide" : "MergedSingle"); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/switch-mode"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Set position mode - - /// - public async Task SetIsolatedPositionModeAsync(string symbol, bool isIsolated, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "is_isolated", isIsolated.ToString() }, - { "buy_leverage", buyLeverage.ToString(CultureInfo.InvariantCulture) }, - { "sell_leverage", sellLeverage.ToString(CultureInfo.InvariantCulture) }, - }; - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/switch-isolated"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - - #endregion - - #region Get balances - - /// - public async Task>> GetBalancesAsync(string? asset = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/wallet/balance"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get wallet fund history - - /// - public async Task>> GetWalletFundHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WalletFundType? type = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_date", startTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("end_date", endTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("wallet_fund_type", type == null ? null : JsonConvert.SerializeObject(type, new WalletFundTypeConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString()); - parameters.AddOptionalParameter("limit", pageSize?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/wallet/fund/records"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Data == null) - return result.As>(new BybitWalletFundRecord[0]); - - return result.As(result.Data.Data); - } - - #endregion - - #region Get withdrawal history - - /// - public async Task>> GetWithdrawalHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WithdrawStatus? status = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("coin", asset); - parameters.AddOptionalParameter("start_date", startTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("end_date", endTime?.ToString("yyyy-MM-dd")); - parameters.AddOptionalParameter("status", status == null ? null : JsonConvert.SerializeObject(status, new WithdrawStatusConverter(false))); - parameters.AddOptionalParameter("page", page?.ToString()); - parameters.AddOptionalParameter("limit", pageSize?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("v2/private/wallet/withdraw/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - if (!result) - return result.As>(default); - - if (result.Data.Data == null) - return result.As>(new BybitWithdrawal[0]); - - return result.As(result.Data.Data); - } - - #endregion - - #region Get asset exchange history - - /// - public async Task>> GetAssetExchangeHistoryAsync(long? fromId = null, SearchDirection? direction = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("from", fromId?.ToString()); - parameters.AddOptionalParameter("direction", direction == null ? null : JsonConvert.SerializeObject(direction, new SearchDirectionConverter(false))); - parameters.AddOptionalParameter("limit", limit?.ToString()); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/exchange-order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get api key info - - /// - public async Task>> GetApiKeyInfoAsync(long? receiveWindow = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/private/account/api-key"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiExchangeData.cs b/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiExchangeData.cs deleted file mode 100644 index 3cbeedbb..00000000 --- a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiExchangeData.cs +++ /dev/null @@ -1,242 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.UsdPerpetualApi -{ - /// - public class BybitRestClientUsdPerpetualApiExchangeData : IBybitRestClientUsdPerpetualApiExchangeData - { - private BybitRestClientUsdPerpetualApi _baseClient; - - internal BybitRestClientUsdPerpetualApiExchangeData(BybitRestClientUsdPerpetualApi baseClient) - { - _baseClient = baseClient; - } - - #region Get klines - - /// - public async Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("public/linear/kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get trade history - - /// - public async Task>> GetTradeHistoryAsync(string symbol, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("public/linear/recent-trading-records"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get last funding rate - - /// - public async Task> GetLastFundingRateAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("public/linear/funding/prev-funding-rate"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get mark price klines - - /// - public async Task>> GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from)! }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("public/linear/mark-price-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get index price klines - - /// - public async Task>> GetIndexPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from) }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("public/linear/index-price-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get premium index price klines - - /// - public async Task>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "interval", JsonConvert.SerializeObject(interval, new KlineIntervalConverter(false)) }, - { "from", DateTimeConverter.ConvertToSeconds(from) }, - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("public/linear/premium-index-kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get server time - - /// - public async Task> GetServerTimeAsync(CancellationToken ct = default) - { - var result = await _baseClient.SendRequestWrapperAsync(_baseClient.GetUrl("v2/public/time"), HttpMethod.Get, ct, null, ignoreRatelimit: true).ConfigureAwait(false); - if (!result) - return result.As(default); - - return result.As(result.Data.Timestamp); - } - - #endregion - - #region Get announcement - - /// - public async Task>> GetAnnouncementsAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/announcement"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get order book - - /// - public async Task>> GetOrderBookAsync(string symbol, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/orderBook/L2"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get ticker - - /// - public async Task>> GetTickerAsync(string? symbol = null, CancellationToken ct = default) - { - var parameters = new Dictionary(); - parameters.AddOptionalParameter("symbol", symbol); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/tickers"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get symbols - - /// - public async Task>> GetSymbolsAsync(CancellationToken ct = default) - { - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/symbols"), HttpMethod.Get, ct, null).ConfigureAwait(false); - } - - #endregion - - #region Get open interest - - /// - public async Task>> GetOpenInterestAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "period", JsonConvert.SerializeObject(period, new DataPeriodConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/open-interest"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get recent big trades - - /// - public async Task>> GetRecentBigTradesAsync(string symbol, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/big-deal"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - - #region Get long short ratio - - /// - public async Task>> GetLongShortRatioAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "period", JsonConvert.SerializeObject(period, new DataPeriodConverter(false)) } - }; - parameters.AddOptionalParameter("limit", limit?.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("v2/public/account-ratio"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); - } - - #endregion - } -} diff --git a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiTrading.cs b/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiTrading.cs deleted file mode 100644 index a262a9a7..00000000 --- a/ByBit.Net/Clients/UsdPerpetualApi/BybitRestClientUsdPerpetualApiTrading.cs +++ /dev/null @@ -1,533 +0,0 @@ -using Bybit.Net.Converters; -using Bybit.Net.Enums; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; -using CryptoExchange.Net.Objects; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Clients.UsdPerpetualApi -{ - /// - public class BybitRestClientUsdPerpetualApiTrading : IBybitRestClientUsdPerpetualApiTrading - { - private BybitRestClientUsdPerpetualApi _baseClient; - - internal BybitRestClientUsdPerpetualApiTrading(BybitRestClientUsdPerpetualApi baseClient) - { - _baseClient = baseClient; - } - - #region Place order - - /// - public async Task> PlaceOrderAsync( - string symbol, - OrderSide side, - OrderType type, - decimal quantity, - TimeInForce timeInForce, - bool reduceOnly, - bool closeOnTrigger, - decimal? price = null, - string? clientOrderId = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - PositionMode? positionMode = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "symbol", symbol }, - { "order_type", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) }, - { "time_in_force", JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) }, - { "reduce_only", reduceOnly.ToString() }, - { "close_on_trigger", closeOnTrigger.ToString() } - }; - - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("position_idx", positionMode == null ? null : JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get orders - - /// - public async Task>>> GetOrdersAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - OrderStatus? status = null, - SortOrder? order = null, - int? pageSize = null, - int? page = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("order_status", status == null ? null : JsonConvert.SerializeObject(status, new OrderStatusConverter(false))); - parameters.AddOptionalParameter("order", order == null ? null : JsonConvert.SerializeObject(order, new SortOrderConverter(false))); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("private/linear/order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel order - - /// - public async Task> CancelOrderAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/order/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel all order - - /// - public async Task>> CancelAllOrdersAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("private/linear/order/cancel-all"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - if (result && result.Data == null) - return result.As>(new string[0]); - - return result; - } - - #endregion - - #region Modify order - - /// - public async Task> ModifyOrderAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - decimal? newPrice = null, - decimal? newQuantity = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("p_r_price", newPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_qty", newQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/order/replace"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Get open orders realtime - - /// - public async Task> GetOpenOrderRealTimeAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (orderId == null && clientOrderId == null || orderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(orderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/order/search"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - /// - public async Task>> GetOpenOrdersRealTimeAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("private/linear/order/search"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Place conditional order - - /// - public async Task> PlaceConditionalOrderAsync( - string symbol, - OrderSide side, - OrderType type, - decimal quantity, - decimal basePrice, - decimal triggerPrice, - TimeInForce timeInForce, - bool closeOnTrigger, - bool reduceOnly, - decimal? price = null, - TriggerType? triggerType = null, - string? clientOrderId = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - PositionMode? positionMode = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "side", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) }, - { "symbol", symbol }, - { "order_type", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) }, - { "qty", quantity.ToString(CultureInfo.InvariantCulture) }, - { "base_price", basePrice.ToString(CultureInfo.InvariantCulture) }, - { "stop_px", triggerPrice.ToString(CultureInfo.InvariantCulture) }, - { "time_in_force", JsonConvert.SerializeObject(timeInForce, new TimeInForceConverter(false)) }, - { "close_on_trigger", closeOnTrigger.ToString(CultureInfo.InvariantCulture) }, - { "reduce_only", reduceOnly.ToString(CultureInfo.InvariantCulture) }, - }; - - parameters.AddOptionalParameter("trigger_by", triggerType == null ? null : JsonConvert.SerializeObject(triggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("position_idx", positionMode == null ? null : JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/stop-order/create"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Get conditional orders - - /// - public async Task>>> GetConditionalOrdersAsync( - string symbol, - string? orderId = null, - string? clientOrderId = null, - OrderStatus? status = null, - SortOrder? order = null, - int? pageSize = null, - int? page = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("stop_order_id", orderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("stop_order_status", status == null ? null : JsonConvert.SerializeObject(status, new OrderStatusConverter(false))); - parameters.AddOptionalParameter("order", order == null ? null : JsonConvert.SerializeObject(order, new SortOrderConverter(false))); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("private/linear/stop-order/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel conditional order - - /// - public async Task> CancelConditionalOrderAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/stop-order/cancel"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Cancel all conditional orders - - /// - public async Task>> CancelAllConditionalOrdersAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync>(_baseClient.GetUrl("private/linear/stop-order/cancel-all"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - if (result && result.Data == null) - return result.As>(new string[0]); - - return result; - } - - #endregion - - #region Modify order - - /// - public async Task> ModifyConditionalOrderAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - decimal? newPrice = null, - decimal? newTriggerPrice = null, - decimal? newQuantity = null, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("p_r_price", newPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_qty", newQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("p_r_trigger_price", newTriggerPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/stop-order/replace"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region Get open orders realtime - - /// - public async Task> GetOpenConditionalOrderRealTimeAsync( - string symbol, - string? stopOrderId = null, - string? clientOrderId = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - if (stopOrderId == null && clientOrderId == null || stopOrderId != null && clientOrderId != null) - throw new ArgumentException($"1 of {nameof(stopOrderId)} or {nameof(clientOrderId)} should be provided"); - - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("stop_order_id", stopOrderId); - parameters.AddOptionalParameter("order_link_id", clientOrderId); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/stop-order/search"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - /// - public async Task>> GetOpenConditionalOrdersRealTimeAsync( - string symbol, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>(_baseClient.GetUrl("private/linear/stop-order/search"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - - } - - #endregion - - #region User trades - - /// - public async Task>>> GetUserTradesAsync( - string symbol, - DateTime? startTime = null, - DateTime? endTime = null, - int? page = null, - int? pageSize = null, - TradeType? type = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - }; - parameters.AddOptionalParameter("exec_type", type == null ? null : JsonConvert.SerializeObject(type, new TradeTypeConverter(false))); - parameters.AddOptionalParameter("start_time", DateTimeConverter.ConvertToMilliseconds(startTime)); - parameters.AddOptionalParameter("end_time", DateTimeConverter.ConvertToMilliseconds(endTime)); - parameters.AddOptionalParameter("page", page?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("limit", pageSize?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - return await _baseClient.SendRequestAsync>>(_baseClient.GetUrl("private/linear/trade/execution/list"), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false); - } - - #endregion - - #region Set Trading Stop - /// - public async Task SetTradingStopAsync( - string symbol, - PositionSide side, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - decimal? trailingStopPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - decimal? takeProfitQuantity = null, - decimal? stopLossQuantity = null, - PositionMode? positionMode = null, - long? receiveWindow = null, - CancellationToken ct = default) - { - var parameters = new Dictionary() - { - { "symbol", symbol }, - { "side", JsonConvert.SerializeObject(side, new PositionSideConverter(false)) } - }; - parameters.AddOptionalParameter("take_profit", takeProfitPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("stop_loss", stopLossPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("trailing_stop", trailingStopPrice?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_trigger_by", takeProfitTriggerType == null ? null : JsonConvert.SerializeObject(takeProfitTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_trigger_by", stopLossTriggerType == null ? null : JsonConvert.SerializeObject(stopLossTriggerType, new TriggerTypeConverter(false))); - parameters.AddOptionalParameter("sl_size", stopLossQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("tp_size", takeProfitQuantity?.ToString(CultureInfo.InvariantCulture)); - parameters.AddOptionalParameter("position_idx", positionMode == null ? null : JsonConvert.SerializeObject(positionMode, new PositionModeConverter(false))); - parameters.AddOptionalParameter("recv_window", receiveWindow?.ToString(CultureInfo.InvariantCulture) ?? _baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); - - var result = await _baseClient.SendRequestAsync(_baseClient.GetUrl("private/linear/position/trading-stop"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false); - return result.AsDataless(); - } - #endregion - } -} diff --git a/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApi.cs b/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApi.cs deleted file mode 100644 index d6b2a40e..00000000 --- a/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApi.cs +++ /dev/null @@ -1,20 +0,0 @@ -using CryptoExchange.Net.Interfaces; -using System; - -namespace Bybit.Net.Interfaces.Clients.GeneralApi -{ - /// - /// Bybit general API endpoints - /// - public interface IBybitRestClientGeneralApi : IRestApiClient, IDisposable - { - /// - /// Endpoints related to asset transfer - /// - IBybitRestClientGeneralApiTransfer Transfer { get; } - /// - /// Endpoint related to withrawing/depositing - /// - IBybitRestClientGeneralApiWithdrawDeposit WithdrawDeposit { get; } - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApiTransfer.cs b/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApiTransfer.cs deleted file mode 100644 index 49ff34e9..00000000 --- a/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApiTransfer.cs +++ /dev/null @@ -1,173 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.GeneralApi -{ - /// - /// Bybit asset transfer endpoints - /// - public interface IBybitRestClientGeneralApiTransfer - { - /// - /// Create a new transfer from one account type to the other - /// - /// - /// A generated UUID, should be unique - /// The asset to transfer - /// Quantity to transfer - /// From account - /// To account - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CreateInternalTransferAsync(string transferId, string asset, decimal quantity, AccountType fromAccountType, AccountType toAccountType, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Create a new transfer for a subaccount - /// - /// - /// A generated UUID, should be unique - /// The asset to transfer - /// Quantity to transfer - /// The sub account id - /// The type of the transfer - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CreateSubAccountTransferAsync(string transferId, string asset, decimal quantity, string subAccountId, TransferType type, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get history of transfers - /// - /// - /// Filter by transfer id - /// Filter by asset - /// Filter by status - /// Filter by start time - /// Filter by end time - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetTransferHistoryAsync( - string? transferId = null, - string? asset = null, - TransferStatus? status = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get history of sub account transfers - /// - /// - /// Filter by transfer id - /// Filter by asset - /// Filter by status - /// Filter by start time - /// Filter by end time - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetSubAccountTransferHistoryAsync( - string? transferId = null, - string? asset = null, - TransferStatus? status = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get a list of subaccount ids - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetSubAccountsAsync(long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Enable universal transfers between sub accounts - /// - /// - /// Sub account ids to enable - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task EnableSubaccountsUniversalTransferAsync(IEnumerable? subaccountIds = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Create a new universal transfer - /// - /// - /// Unique id - /// Asset - /// Quantity - /// From id - /// To id - /// From type - /// To type - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> UniversalTransferAsync(string transferId, string asset, decimal quantity, string fromMemberId, string toMemberId, AccountType fromAccountType, AccountType toAccountType, long? receiveWindow = null, CancellationToken ct = default); - - - /// - /// Get history of universal account transfers - /// - /// - /// Filter by transfer id - /// Filter by asset - /// Filter by status - /// Filter by start time - /// Filter by end time - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetUniversalTransferHistoryAsync( - string? transferId = null, - string? asset = null, - TransferStatus? status = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Coin balance for an account type including Earn - /// - /// - /// Account type - /// Asset - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetAssetBalanceAsync(AccountType accountType, string asset, long? receiveWindow = null, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApiWithdrawDeposit.cs b/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApiWithdrawDeposit.cs deleted file mode 100644 index 5bd3b0e5..00000000 --- a/ByBit.Net/Interfaces/Clients/GeneralApi/IBybitRestClientGeneralApiWithdrawDeposit.cs +++ /dev/null @@ -1,159 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.GeneralApi -{ - /// - /// Bybit withdrawal and deposit endpoints - /// - public interface IBybitRestClientGeneralApiWithdrawDeposit - { - /// - /// Get deposit information - /// - /// - /// Filter by asset - /// Filter by network - /// Page number - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetSupportedDepositMethodsAsync( - string? asset = null, - string? network = null, - int? page = null, - int? pageSize = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get deposit history - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetDepositHistoryAsync( - string? asset = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get withdrawal history - /// - /// - /// Filter by withdrawal id - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetWithdrawalHistoryAsync( - string? withdrawalId = null, - string? asset = null, - DateTime? startTime = null, - DateTime? endTime = null, - SearchDirection? direction = null, - int? limit = null, - string? cursor = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get asset information regarding withdrawal/deposits - /// - /// - /// Filter by asset - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetAssetInfoAsync( - string? asset = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get account info - /// - /// - /// Filter asset - /// Filter account type - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetAccountInfoAsync( - string? asset = null, - string? accountType = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Create a withdrawal request - /// - /// - /// Asset to withdraw - /// Network to use - /// Address to withdraw to, should be whitelisted - /// Quantity to withdraw - /// Tag - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> WithdrawAsync( - string asset, - string network, - string address, - decimal quantity, - string? tag = null, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Cancel withdrawal - /// - /// - /// Id to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task CancelWithdrawalAsync( - string withdrawalId, - long? receiveWindow = null, - CancellationToken ct = default); - - /// - /// Get deposit addresses for an asset - /// - /// - /// The asset to get addresses for - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetDepositAddressesAsync( - string asset, - long? receiveWindow = null, - CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/IBybitRestClient.cs b/ByBit.Net/Interfaces/Clients/IBybitRestClient.cs index ef376aba..e1cf8b19 100644 --- a/ByBit.Net/Interfaces/Clients/IBybitRestClient.cs +++ b/ByBit.Net/Interfaces/Clients/IBybitRestClient.cs @@ -1,11 +1,6 @@ using Bybit.Net.Interfaces.Clients.CopyTradingApi; using Bybit.Net.Interfaces.Clients.DerivativesApi; -using Bybit.Net.Interfaces.Clients.GeneralApi; -using Bybit.Net.Interfaces.Clients.InverseFuturesApi; -using Bybit.Net.Interfaces.Clients.InversePerpetualApi; -using Bybit.Net.Interfaces.Clients.SpotApi.v1; using Bybit.Net.Interfaces.Clients.SpotApi.v3; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces; @@ -16,26 +11,6 @@ namespace Bybit.Net.Interfaces.Clients /// public interface IBybitRestClient: IRestClient { - /// - /// General API endpoints - /// - IBybitRestClientGeneralApi GeneralApi { get; } - /// - /// Inverse perpetual API endpoints - /// - IBybitRestClientInversePerpetualApi InversePerpetualApi { get; } - /// - /// USD perpetual API endpoints - /// - IBybitRestClientUsdPerpetualApi UsdPerpetualApi { get; } - /// - /// Inverse futures API endpoints - /// - IBybitRestClientInverseFuturesApi InverseFuturesApi { get; } - /// - /// Spot API endpoints (v1) - /// - IBybitRestClientSpotApiV1 SpotApiV1 { get; } /// /// Spot API endpoints (v3) /// diff --git a/ByBit.Net/Interfaces/Clients/IBybitSocketClient.cs b/ByBit.Net/Interfaces/Clients/IBybitSocketClient.cs index 469c22a0..8c81e754 100644 --- a/ByBit.Net/Interfaces/Clients/IBybitSocketClient.cs +++ b/ByBit.Net/Interfaces/Clients/IBybitSocketClient.cs @@ -2,7 +2,6 @@ using Bybit.Net.Interfaces.Clients.DerivativesApi.ContractApi; using Bybit.Net.Interfaces.Clients.DerivativesApi.UnifiedMarginApi; using Bybit.Net.Interfaces.Clients.SpotApi.v3; -using Bybit.Net.Interfaces.Clients.UsdPerpetualApi; using Bybit.Net.Interfaces.Clients.V5; using CryptoExchange.Net.Authentication; using CryptoExchange.Net.Interfaces; diff --git a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApi.cs b/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApi.cs deleted file mode 100644 index 54345465..00000000 --- a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApi.cs +++ /dev/null @@ -1,26 +0,0 @@ -using CryptoExchange.Net.Interfaces; -using System; - -namespace Bybit.Net.Interfaces.Clients.InverseFuturesApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16/30 OCTOBER, USE V5 API INSTEAD] Bybit inverse futures API endpoints - /// - public interface IBybitRestClientInverseFuturesApi : IRestApiClient, IDisposable - { - /// - /// Endpoints related to account settings, info or actions - /// - IBybitRestClientInverseFuturesApiAccount Account { get; } - - /// - /// Endpoints related to retrieving market and system data - /// - IBybitRestClientInverseFuturesApiExchangeData ExchangeData { get; } - - /// - /// Endpoints related to orders and trades - /// - IBybitRestClientInverseFuturesApiTrading Trading { get; } - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiAccount.cs b/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiAccount.cs deleted file mode 100644 index f72e6f17..00000000 --- a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiAccount.cs +++ /dev/null @@ -1,208 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.InverseFuturesApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit account endpoints. Account endpoints include balance info, withdraw/deposit info and requesting and account settings - /// - public interface IBybitRestClientInverseFuturesApiAccount - { - #region Risk - - /// - /// Get position risk limit - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetRiskLimitAsync(string? symbol = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set position risk - /// - /// - /// The symbol - /// The risk id to set - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetRiskLimitAsync(string symbol, long riskId, PositionMode? mode = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Positions - - /// - /// Get user positions for a symbol - /// - /// - /// Filter by symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetPositionAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get user positions - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetPositionsAsync(long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change margin - /// - /// - /// The symbol - /// The position mode - /// The margin - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ChangeMarginAsync(string symbol, PositionMode mode, decimal margin, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set leerage - /// - /// - /// The symbol - /// Buy leverage - /// Sell leverage - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetLeverageAsync(string symbol, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch beteen onway and hedge position mode. - /// If you are in One-Way Mode, you can only open one position on Buy or Sell side; - /// If you are in Hedge Mode, you can open both Buy and Sell side positions simultaneously. - /// - /// - /// Symbol. Required if not passing coin - /// Currency alias. Required if not passing symbol - /// Hedgemode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetPositionModeAsync(string symbol, string asset, bool hedgeMode, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch between full or partial Stop loss/Take profit mode - /// - /// - /// The symbol - /// New mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetFullPartialPositionModeAsync(string symbol, StopLossTakeProfitMode mode, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch between cross and isolated mode. - /// - /// - /// The symbol - /// Is isolated - /// Buy leverage - /// Sell leverage - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetIsolatedPositionModeAsync(string symbol, bool isIsolated, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get user's profit and loss records - /// - /// - /// The symbol to get records for - /// Filter by startTime - /// Filter by endTime - /// Filter by type - /// Page - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetProfitAndLossHistoryAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, TradeType? type = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Wallet - - /// - /// Get wallet balances - /// - /// - /// Filter by asset - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetBalancesAsync(string? asset = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get wallet fund endpoints - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by type - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetWalletFundHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WalletFundType? type = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get withdrawal history - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by status - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetWithdrawalHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WithdrawStatus? status = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get asset exchange history - /// - /// - /// Filter by id - /// Filter by direction - /// Max records - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetAssetExchangeHistoryAsync(long? fromId = null, SearchDirection? direction = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - /// - /// Get Api key info - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetApiKeyInfoAsync(long? receiveWindow = null, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiExchangeData.cs b/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiExchangeData.cs deleted file mode 100644 index 1af36588..00000000 --- a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiExchangeData.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.InverseFuturesApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16 OCTOBER, USE V5 API INSTEAD] Bybit exchange data endpoints. Exchange data includes market data (tickers, order books, etc) and system status. - /// - public interface IBybitRestClientInverseFuturesApiExchangeData - { - /// - /// Get the server time - /// - /// - /// Cancellation token - /// - Task> GetServerTimeAsync(CancellationToken ct = default); - - /// - /// The API announcements for the last 30 days - /// - /// - /// Cancellation token - /// - Task>> GetAnnouncementsAsync(CancellationToken ct = default); - - /// - /// Get all supported symbols - /// - /// - /// Cancellation token - /// - Task>> GetSymbolsAsync(CancellationToken ct = default); - - /// - /// The ticker info for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task>> GetTickerAsync(string? symbol = null, CancellationToken ct = default); - - /// - /// Get public trade history - /// - /// - /// The symbol - /// Filter by records after this id - /// Max amount of results - /// Cancellation token - /// - Task>> GetTradeHistoryAsync(string symbol, long? fromId = null, int? limit = null, CancellationToken ct = default); - - /// - /// Get the current order book for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task>> GetOrderBookAsync(string symbol, CancellationToken ct = default); - - /// - /// Get price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get index price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetIndexPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get mark price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get long/short ratio - /// - /// - /// The symbol - /// The data period - /// Max amount of results - /// Cancellation token - /// - Task>> GetLongShortRatioAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default); - - /// - /// Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions. - /// - /// - /// The symbol - /// The period of data - /// Max amount of results - /// Cancellation token - /// - Task>> GetOpenInterestAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default); - - /// - /// Obtain filled orders worth more than 500,000 USD within the last 24h. - /// - /// - /// The symbol - /// The max amount of results - /// Cancellation token - /// - Task>> GetRecentBigTradesAsync(string symbol, int? limit = null, CancellationToken ct = default); - - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiTrading.cs b/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiTrading.cs deleted file mode 100644 index 4b2dcfc8..00000000 --- a/ByBit.Net/Interfaces/Clients/InverseFuturesApi/IBybitRestClientInverseFuturesApiTrading.cs +++ /dev/null @@ -1,269 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.InverseFuturesApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit trading endpoints, placing and managing orders. - /// - public interface IBybitRestClientInverseFuturesApiTrading - { - #region Orders - /// - /// Place a new order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Position mode - /// Quantity - /// Time in force - /// Price - /// True means your position can only reduce in size if this order is triggered - /// For a closing order. It can only reduce your position, not increase it. If the account has insufficient available balance when the closing order is triggered, then other active orders of similar contracts will be cancelled or reduced. It can be used to ensure your stop loss reduces your position regardless of current available margin. - /// Client order id - /// Take profit price, only take effect upon opening the position - /// Stop loss price, only take effect upon opening the position - /// Take profit trigger price type, default: LastPrice - /// Stop loss trigger price type, default: LastPrice - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceOrderAsync(string symbol, OrderSide side, OrderType type, PositionMode positionMode, decimal quantity, TimeInForce timeInForce, decimal? price = null, bool? closeOnTrigger = null, string? clientOrderId = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, bool? reduceOnly = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change an exising order. Either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// Stop order id - /// Client order id - /// New price to set - /// New quantity to set - /// New take profit price - /// New stop loss price - /// New take profit trigger type - /// New stop loss profit price - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ModifyOrderAsync(string symbol, string? orderId = null, string? clientOrderId = null, decimal? newPrice = null, decimal? newQuantity = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information. Either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// - /// - /// - /// - /// - Task> GetOpenOrderRealTimeAsync(string symbol, string? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information for up to 500 orders - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenOrdersRealTimeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get orders - /// - /// - /// The symbol - /// Filter by status - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetOrdersAsync(string symbol, OrderStatus? status = null, SearchDirection? direction = null, int? limit = null, string? cursor = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel an order, either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The id of the order to cancel - /// The client order id of the conditional order to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelOrderAsync(string symbol, string? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel all active orders for a symbol - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> CancelAllOrdersAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Conditional orders - /// - /// Place a new conditional order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Position mode - /// Quantity - /// It will be used to compare with the value of trigger price, to decide whether your conditional order will be triggered by crossing trigger price from upper side or lower side. Mainly used to identify the expected direction of the current conditional order. - /// Trigger price - /// Time in force - /// Price - /// Trigger type - /// For a closing order. It can only reduce your position, not increase it. If the account has insufficient available balance when the closing order is triggered, then other active orders of similar contracts will be cancelled or reduced. It can be used to ensure your stop loss reduces your position regardless of current available margin. - /// Client order id - /// Take profit price, only take effect upon opening the position - /// Stop loss price, only take effect upon opening the position - /// Take profit trigger price type, default: LastPrice - /// Stop loss trigger price type, default: LastPrice - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceConditionalOrderAsync(string symbol, OrderSide side, OrderType type, PositionMode positionMode, decimal quantity, decimal basePrice, decimal triggerPrice, TimeInForce timeInForce, decimal? price = null, TriggerType? triggerType = null, bool? closeOnTrigger = null, string? clientOrderId = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change an exising order. Either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// Stop order id - /// Client order id - /// New price to set - /// New trigger price to set - /// New quantity to set - /// New take profit price - /// New stop loss price - /// New take profit trigger type - /// New stop loss profit price - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ModifyConditionalOrderAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, decimal? newPrice = null, decimal? newTriggerPrice = null, decimal? newQuantity = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get a list of conditional orders - /// - /// - /// The symbol - /// Filter by status - /// Filter by direction - /// Max number of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetConditionalOrdersAsync(string symbol, StopOrderStatus? status = null, SearchDirection? direction = null, int? limit = null, string? cursor = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get conditional order information. Either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The order id - /// The client order id - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetOpenConditionalOrderRealTimeAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information for up to 10 conditional orders - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenConditionalOrdersRealTimeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel a conditional order, either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The id of the conditional order to cancel - /// The client order id of the conditional order to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelConditionalOrderAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel all active conditional orders for a symbol - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> CancelAllConditionalOrdersAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - /// - /// Get executed user trades - /// - /// - /// The symbol - /// Filter by order id - /// Filter by start time - /// Page - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetUserTradesAsync(string symbol, string? orderId = null, DateTime? startTime = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set take profit, stop loss, and trailing stop for your open position - /// - /// - /// The symbol - /// The position mode - /// The new take profit price. Setting it to null will not change the value, setting it to 0 will remove the current TakeProfit - /// The new stop loss price. Setting it to null will not change the value, setting it to 0 will remove the current StopLoss - /// Setting it to null will not change the value, setting it to 0 will remove the current TrailingStop - /// Take profit trigger type, defaults to LastPrice - /// Stop loss trigger type, defaults to LastPrice - /// Trailing stop trigger price. Trailing stops are triggered only when the price reaches the specified price. Trailing stops are triggered immediately by default. - /// Take profit quantity when in Partial mode - /// Stop loss quantity when in Partial mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetTradingStopAsync( - string symbol, - PositionMode positionMode, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - decimal? trailingStopPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - decimal? trailingStopTriggerPrice = null, - decimal? takeProfitQuantity = null, - decimal? stopLossQuantity = null, - long? receiveWindow = null, - CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApi.cs b/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApi.cs deleted file mode 100644 index 40e9a4f6..00000000 --- a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApi.cs +++ /dev/null @@ -1,26 +0,0 @@ -using CryptoExchange.Net.Interfaces; -using System; - -namespace Bybit.Net.Interfaces.Clients.InversePerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16/30 OCTOBER, USE V5 API INSTEAD] Bybit inverse perpetual API endpoints - /// - public interface IBybitRestClientInversePerpetualApi : IRestApiClient, IDisposable - { - /// - /// Endpoints related to account settings, info or actions - /// - IBybitRestClientInversePerpetualApiAccount Account { get; } - - /// - /// Endpoints related to retrieving market and system data - /// - IBybitRestClientInversePerpetualApiExchangeData ExchangeData { get; } - - /// - /// Endpoints related to orders and trades - /// - IBybitRestClientInversePerpetualApiTrading Trading { get; } - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiAccount.cs b/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiAccount.cs deleted file mode 100644 index fcc99687..00000000 --- a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiAccount.cs +++ /dev/null @@ -1,217 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.InversePerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit account endpoints. Account endpoints include balance info, withdraw/deposit info and requesting and account settings - /// - public interface IBybitRestClientInversePerpetualApiAccount - { - #region Risk limit - - /// - /// Get position risk limit - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetRiskLimitAsync(string? symbol = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set position risk - /// - /// - /// The symbol - /// The risk id to set - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetRiskLimitAsync(string symbol, long riskId, PositionMode? mode = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Positions - - /// - /// Get user position for a symbol - /// - /// - /// Symbol to retrieve position for - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetPositionAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get user positions - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetPositionsAsync(long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change margin - /// - /// - /// The symbol - /// The margin - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ChangeMarginAsync(string symbol, decimal margin, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set leverage - /// - /// - /// The symbol - /// Leverage, must be greater than 0 and less than the risk limit leverage - /// Use this parameter to set leverage while in cross margin mode. If this field is set to false, when leverage is equal to 0 the position will use cross margin; when leverage is greater than 0 the position will use isolated margin. If this field is set to true, you can set leverage in cross margin with leverage. leverage must be greater than 0. - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetLeverageAsync(string symbol, decimal leverage, bool? leverageOnly = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get user's profit and loss records - /// - /// - /// The symbol to get records for - /// Filter by startTime - /// Filter by endTime - /// Filter by type - /// Page - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetProfitAndLossHistoryAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, TradeType? type = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch between full or partial Stop loss/Take profit mode - /// - /// - /// The symbol - /// New mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetFullPartialPositionModeAsync(string symbol, StopLossTakeProfitMode mode, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch between cross and isolated mode. - /// - /// - /// The symbol - /// Is isolated - /// Buy leverage - /// Sell leverage - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetIsolatedPositionModeAsync(string symbol, bool isIsolated, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Wallet - - /// - /// Get wallet balances - /// - /// - /// Filter by asset - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetBalancesAsync(string? asset = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get wallet fund endpoints - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by type - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetWalletFundHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WalletFundType? type = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get withdrawal history - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by status - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetWithdrawalHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WithdrawStatus? status = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get asset exchange history - /// - /// - /// Filter by id - /// Filter by direction - /// Max records - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetAssetExchangeHistoryAsync(long? fromId = null, SearchDirection? direction = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Funding - - /// - /// Get user last funding fee - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetLastUserFundingFeeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get predicted next funding rate - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetPredictedUserFundingFeeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - /// - /// Get Api key info - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetApiKeyInfoAsync(long? receiveWindow = null, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiExchangeData.cs b/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiExchangeData.cs deleted file mode 100644 index e08b233d..00000000 --- a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiExchangeData.cs +++ /dev/null @@ -1,159 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.InversePerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16 OCTOBER, USE V5 API INSTEAD] Bybit exchange data endpoints. Exchange data includes market data (tickers, order books, etc) and system status. - /// - public interface IBybitRestClientInversePerpetualApiExchangeData - { - /// - /// Get the server time - /// - /// - /// Cancellation token - /// - Task> GetServerTimeAsync(CancellationToken ct = default); - - /// - /// The API announcements for the last 30 days - /// - /// - /// Cancellation token - /// - Task>> GetAnnouncementsAsync(CancellationToken ct = default); - - /// - /// Get all supported symbols - /// - /// - /// Cancellation token - /// - Task>> GetSymbolsAsync(CancellationToken ct = default); - - /// - /// The ticker info for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task>> GetTickersAsync(string? symbol = null, CancellationToken ct = default); - - /// - /// Get public trade history - /// - /// - /// The symbol - /// Filter by records after this id - /// Max amount of results - /// Cancellation token - /// - Task>> GetTradeHistoryAsync(string symbol, long? fromId = null, int? limit = null, CancellationToken ct = default); - - /// - /// Get the current order book for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task>> GetOrderBookAsync(string symbol, CancellationToken ct = default); - - /// - /// Get price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get index price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetIndexPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get premium index klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get mark price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get long/short ratio - /// - /// - /// The symbol - /// The data period - /// Max amount of results - /// Cancellation token - /// - Task>> GetLongShortRatioAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default); - - /// - /// Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions. - /// - /// - /// The symbol - /// The period of data - /// Max amount of results - /// Cancellation token - /// - Task>> GetOpenInterestAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default); - - /// - /// Obtain filled orders worth more than 500,000 USD within the last 24h. - /// - /// - /// The symbol - /// The max amount of results - /// Cancellation token - /// - Task>> GetRecentBigTradesAsync(string symbol, int? limit = null, CancellationToken ct = default); - - /// - /// Get last funding rate - /// - /// - /// The symbol - /// Cancellation token - /// - Task> GetLastFundingRateAsync(string symbol, CancellationToken ct = default); - - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiTrading.cs b/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiTrading.cs deleted file mode 100644 index 6a7c46d4..00000000 --- a/ByBit.Net/Interfaces/Clients/InversePerpetualApi/IBybitRestClientInversePerpetualApiTrading.cs +++ /dev/null @@ -1,264 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.InversePerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit trading endpoints, placing and managing orders. - /// - public interface IBybitRestClientInversePerpetualApiTrading - { - #region Orders - /// - /// Place a new order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Quantity - /// Time in force - /// Price - /// True means your position can only reduce in size if this order is triggered - /// For a closing order. It can only reduce your position, not increase it. If the account has insufficient available balance when the closing order is triggered, then other active orders of similar contracts will be cancelled or reduced. It can be used to ensure your stop loss reduces your position regardless of current available margin. - /// Client order id - /// Take profit price, only take effect upon opening the position - /// Stop loss price, only take effect upon opening the position - /// Take profit trigger price type, default: LastPrice - /// Stop loss trigger price type, default: LastPrice - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceOrderAsync(string symbol, OrderSide side, OrderType type, decimal quantity, TimeInForce timeInForce, decimal? price = null, bool? closeOnTrigger = null, string? clientOrderId = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, bool? reduceOnly = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change an exising order. Either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// Stop order id - /// Client order id - /// New price to set - /// New quantity to set - /// New take profit price - /// New stop loss price - /// New take profit trigger type - /// New stop loss profit price - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ModifyOrderAsync(string symbol, string? orderId = null, string? clientOrderId = null, decimal? newPrice = null, decimal? newQuantity = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get orders - /// - /// - /// The symbol - /// Filter by status - /// Filter by direction - /// Max amount of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetOrdersAsync(string symbol, OrderStatus? status = null, SearchDirection? direction = null, int? limit = null, string? cursor = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information. Either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// - /// - /// - /// - /// - Task> GetOpenOrderRealTimeAsync(string symbol, string? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information for up to 500 orders - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenOrdersRealTimeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel an order, either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The id of the order to cancel - /// The client order id of the conditional order to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelOrderAsync(string symbol, string? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel all active orders for a symbol - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> CancelAllOrdersAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - #endregion - - #region Conditional orders - /// - /// Place a new conditional order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Position mode - /// Quantity - /// It will be used to compare with the value of trigger price, to decide whether your conditional order will be triggered by crossing trigger price from upper side or lower side. Mainly used to identify the expected direction of the current conditional order. - /// Trigger price - /// Time in force - /// Price - /// Trigger type - /// For a closing order. It can only reduce your position, not increase it. If the account has insufficient available balance when the closing order is triggered, then other active orders of similar contracts will be cancelled or reduced. It can be used to ensure your stop loss reduces your position regardless of current available margin. - /// Client order id - /// Take profit price, only take effect upon opening the position - /// Stop loss price, only take effect upon opening the position - /// Take profit trigger price type, default: LastPrice - /// Stop loss trigger price type, default: LastPrice - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceConditionalOrderAsync(string symbol, OrderSide side, OrderType type, PositionMode positionMode, decimal quantity, decimal basePrice, decimal triggerPrice, TimeInForce timeInForce, decimal? price = null, TriggerType? triggerType = null, bool? closeOnTrigger = null, string? clientOrderId = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change an exising order. Either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// Stop order id - /// Client order id - /// New price to set - /// New trigger price to set - /// New quantity to set - /// New take profit price - /// New stop loss price - /// New take profit trigger type - /// New stop loss profit price - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ModifyConditionalOrderAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, decimal? newPrice = null, decimal? newTriggerPrice = null, decimal? newQuantity = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get a list of conditional orders - /// - /// - /// The symbol - /// Filter by status - /// Filter by direction - /// Max number of results - /// Page cursor - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetConditionalOrdersAsync(string symbol, StopOrderStatus? status = null, SearchDirection? direction = null, int? limit = null, string? cursor = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information for up to 10 conditional orders - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenConditionalOrdersRealTimeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get conditional order information. Either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The order id - /// The client order id - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetOpenConditionalOrderRealTimeAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel a conditional order, either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The id of the conditional order to cancel - /// The client order id of the conditional order to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelConditionalOrderAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel all active conditional orders for a symbol - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> CancelAllConditionalOrdersAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - #endregion - - /// - /// Get executed user trades - /// - /// - /// The symbol - /// Filter by order id - /// Filter by start time - /// Page - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetUserTradesAsync(string symbol, string? orderId = null, DateTime? startTime = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set take profit, stop loss, and trailing stop for your open position - /// - /// - /// The symbol - /// The new take profit price. Setting it to null will not change the value, setting it to 0 will remove the current TakeProfit - /// The new stop loss price. Setting it to null will not change the value, setting it to 0 will remove the current StopLoss - /// Setting it to null will not change the value, setting it to 0 will remove the current TrailingStop - /// Take profit trigger type, defaults to LastPrice - /// Stop loss trigger type, defaults to LastPrice - /// Trailing stop trigger price. Trailing stops are triggered only when the price reaches the specified price. Trailing stops are triggered immediately by default. - /// Take profit quantity when in Partial mode - /// Stop loss quantity when in Partial mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetTradingStopAsync( - string symbol, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - decimal? trailingStopPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - decimal? trailingStopTriggerPrice = null, - decimal? takeProfitQuantity = null, - decimal? stopLossQuantity = null, - long? receiveWindow = null, - CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiAccountV1.cs b/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiAccountV1.cs deleted file mode 100644 index ab8c681b..00000000 --- a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiAccountV1.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Bybit.Net.Objects.Models.Spot; -using CryptoExchange.Net.Objects; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.SpotApi.v1 -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit account endpoints. Account endpoints include balance info, withdraw/deposit info and requesting and account settings - /// - public interface IBybitRestClientSpotApiAccountV1 - { - /// - /// Get wallet balances - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetBalancesAsync(long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get margin account info - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetMarginAccountInfoAsync(long? receiveWindow = null, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiExchangeDataV1.cs b/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiExchangeDataV1.cs deleted file mode 100644 index aab48a2e..00000000 --- a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiExchangeDataV1.cs +++ /dev/null @@ -1,136 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Models.Spot; -using Bybit.Net.Objects.Models.Spot.v1; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.SpotApi.v1 -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16 OCTOBER, USE V5 API INSTEAD] Bybit exchange data endpoints. Exchange data includes market data (tickers, order books, etc) and system status. - /// - public interface IBybitRestClientSpotApiExchangeDataV1 - { - /// - /// Get the server time - /// - /// - /// Cancellation token - /// - Task> GetServerTimeAsync(CancellationToken ct = default); - - /// - /// Get all supported symbols - /// - /// - /// Cancellation token - /// - Task>> GetSymbolsAsync(CancellationToken ct = default); - - /// - /// Get the current order book for a symbol - /// - /// - /// The symbol - /// The number of rows - /// Cancellation token - /// - Task> GetOrderBookAsync(string symbol, int? limit = null, CancellationToken ct = default); - - /// - /// Get merged order book based on the scale - /// - /// - /// The symbol - /// The scale of the order book. 1 means 1 digit - /// The amount of rows - /// Cancellation token - /// - Task> GetMergedOrderBookAsync(string symbol, int? scale = null, int? limit = null, CancellationToken ct = default); - - /// - /// Get public trade history - /// - /// - /// The symbol - /// Max amount of results - /// Cancellation token - /// - Task>> GetTradeHistoryAsync(string symbol, int? limit = null, CancellationToken ct = default); - - /// - /// Get price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// End time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default); - - /// - /// The ticker info for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task> GetTickerAsync(string symbol, CancellationToken ct = default); - - /// - /// The ticker info for all symbols - /// - /// - /// Cancellation token - /// - Task>> GetTickersAsync(CancellationToken ct = default); - - /// - /// Get the last trade price of a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task> GetPriceAsync(string symbol, CancellationToken ct = default); - - /// - /// Get the last trade price of all symbols - /// - /// - /// Cancellation token - /// - Task>> GetPricesAsync(CancellationToken ct = default); - - /// - /// Get the best ask/bid price for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task> GetBookPriceAsync(string symbol, CancellationToken ct = default); - - /// - /// Get the best ask/bid prices for all symbols - /// - /// - /// Cancellation token - /// - Task>> GetBookPricesAsync(CancellationToken ct = default); - - /// - /// Get borrow info - /// - /// The asset to retrieve info on - /// Cancellation token - /// - Task> GetBorrowInterestAndQuotaAsync(string asset, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiTradingV1.cs b/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiTradingV1.cs deleted file mode 100644 index 80cb0a55..00000000 --- a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiTradingV1.cs +++ /dev/null @@ -1,152 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Models.Spot; -using Bybit.Net.Objects.Models.Spot.v1; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.SpotApi.v1 -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit trading endpoints, placing and managing orders. - /// - public interface IBybitRestClientSpotApiTradingV1 - { - /// - /// Place a new order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Quantity of the order. Note that for market buy orders this is the quantity of quote asset, otherwise it's in base asset - /// Price - /// Time in force - /// Client order id - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceOrderAsync(string symbol, OrderSide side, OrderType type, decimal quantity, decimal? price = null, TimeInForce? timeInForce = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order, either orderId or clientOrderId should be provided - /// - /// - /// The id of the order - /// The client order id - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetOrderAsync(long? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get open orders - /// - /// - /// The symbol - /// Filter by order id, will only return orders with an orderId smaller than this - /// Max amount of results - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenOrdersAsync(string? symbol = null, long? orderId = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get orders - /// - /// - /// Filter by symbol - /// Filter by order id, will only return orders with an orderId smaller than this - /// Max amount of results - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOrdersAsync(string? symbol = null, long? orderId = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel an active order. Either orderId or clientOrderId should be provided - /// - /// - /// The order id - /// The client order id - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelOrderAsync(long? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel multiple orders based on the provided parameters - /// - /// The symbol to cancel orders on - /// Only cancel buy or sell orders - /// Only cancel orders fitting the order types, default only cancels Limit orders (not LimitMaker orders) - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task CancelMultipleOrderAsync(string symbol, OrderSide? side = null, IEnumerable? orderTypes = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get user trade history - /// - /// - /// Filter by symbol - /// Filter by start id - /// Filter by end id - /// Max amount of results - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetUserTradesAsync(string? symbol = null, long? fromId = null, long? toId = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Place a new borrow order - /// - /// - /// The asset to borrow - /// The quantity to borrow - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceBorrowOrderAsync(string asset, decimal quantity, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Place a new borrow order - /// - /// - /// The asset to repay - /// The quantity to repay - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceRepayOrderAsync(string asset, decimal quantity, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get borrow records - /// - /// - /// Filter by borrow time - /// Filter by borrow time - /// Filter by asset - /// Filter by status - /// Max amount of results - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetBorrowRecordsAsync(DateTime? startTime = null, DateTime? endTime = null, string? asset = null, BorrowStatus? status = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get repayment records - /// - /// - /// Filter by borrow time - /// Filter by borrow time - /// Filter by asset - /// Max amount of results - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetRepayRecordsAsync(DateTime? startTime = null, DateTime? endTime = null, string? asset = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiV1.cs b/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiV1.cs deleted file mode 100644 index 66557e64..00000000 --- a/ByBit.Net/Interfaces/Clients/SpotApi/v1/IBybitRestClientSpotApiV1.cs +++ /dev/null @@ -1,33 +0,0 @@ -using CryptoExchange.Net.Interfaces; -using CryptoExchange.Net.Interfaces.CommonClients; -using System; - -namespace Bybit.Net.Interfaces.Clients.SpotApi.v1 -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16/30 OCTOBER, USE V5 API INSTEAD] Bybit spot API endpoints (v1) - /// - public interface IBybitRestClientSpotApiV1 : IRestApiClient, IDisposable - { - /// - /// Endpoints related to account settings, info or actions - /// - IBybitRestClientSpotApiAccountV1 Account { get; } - - /// - /// Endpoints related to retrieving market and system data - /// - IBybitRestClientSpotApiExchangeDataV1 ExchangeData { get; } - - /// - /// Endpoints related to orders and trades - /// - IBybitRestClientSpotApiTradingV1 Trading { get; } - - /// - /// Get the ISpotClient for this client. This is a common interface which allows for some basic operations without knowing any details of the exchange. - /// - /// - public ISpotClient CommonSpotClient { get; } - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApi.cs b/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApi.cs deleted file mode 100644 index f17ff9a0..00000000 --- a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApi.cs +++ /dev/null @@ -1,26 +0,0 @@ -using CryptoExchange.Net.Interfaces; -using System; - -namespace Bybit.Net.Interfaces.Clients.UsdPerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16/30 OCTOBER, USE V5 API INSTEAD] Bybit USD perpetual API endpoints - /// - public interface IBybitRestClientUsdPerpetualApi : IRestApiClient, IDisposable - { - /// - /// Endpoints related to account settings, info or actions - /// - IBybitRestClientUsdPerpetualApiAccount Account { get; } - - /// - /// Endpoints related to retrieving market and system data - /// - IBybitRestClientUsdPerpetualApiExchangeData ExchangeData { get; } - - /// - /// Endpoints related to orders and trades - /// - IBybitRestClientUsdPerpetualApiTrading Trading { get; } - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiAccount.cs b/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiAccount.cs deleted file mode 100644 index e06f4628..00000000 --- a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiAccount.cs +++ /dev/null @@ -1,242 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.UsdPerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit account endpoints. Account endpoints include balance info, withdraw/deposit info and requesting and changing account settings - /// - public interface IBybitRestClientUsdPerpetualApiAccount - { - #region Risk - /// - /// Get position risk limit - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetRiskLimitAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set position risk - /// - /// - /// The symbol - /// The risk id to set - /// Side - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetRiskLimitAsync(string symbol, OrderSide side, long riskId, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Positions - /// - /// Get user positions - /// - /// - /// Filter by symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetPositionAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - /// - /// Get user positions - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetPositionsAsync(long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set auto add margin switch - /// - /// - /// Symbol - /// Side - /// Auto add or not - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetAutoAddMarginAsync(string symbol, OrderSide side, bool autoAddMargin, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch Cross/Isolated; must set leverage value when switching from Cross to Isolated - /// - /// - /// The symbol - /// True is Isolated; false is Cross - /// Buy leverage - /// Sell leverage - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetIsolatedPositionModeAsync(string symbol, bool isIsolated, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch position mode. If you are in One-Way Mode, you can only open one position on Buy or Sell side; - /// If you are in Hedge Mode, you can open both Buy and Sell side positions simultaneously. - /// - /// - /// Symbol. Required if not passing coin - /// Currency alias. Required if not passing symbol - /// True = HedgeMode, False = OneWayMode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetPositionModeAsync(string symbol, string asset, bool hedgeMode, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Switch between full or partial Stop loss/Take profit mode - /// - /// - /// The symbol - /// New mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> SetFullPartialPositionModeAsync(string symbol, StopLossTakeProfitMode mode, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Add/reduce margin - /// - /// The symbol - /// The side - /// Margin to add (positive) or remove (negative) - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> AddReduceMarginAsync(string symbol, OrderSide side, decimal margin, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set leverage - /// - /// - /// The symbol - /// Buy leverage - /// Sell leverage - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetLeverageAsync(string symbol, decimal buyLeverage, decimal sellLeverage, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get user's profit and loss records - /// - /// - /// The symbol to get records for - /// Filter by startTime - /// Filter by endTime - /// Filter by type - /// Page - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetProfitAndLossHistoryAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, TradeType? type = null, int? page = null, int? pageSize = null, long? receiveWindow = null, CancellationToken ct = default); - #endregion - - #region Wallet - - /// - /// Get wallet fund endpoints - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by type - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetWalletFundHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WalletFundType? type = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get asset exchange history - /// - /// - /// Filter by id - /// Filter by direction - /// Max records - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetAssetExchangeHistoryAsync(long? fromId = null, SearchDirection? direction = null, int? limit = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get wallet balances - /// - /// - /// Filter by asset - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetBalancesAsync(string? asset = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get withdrawal history - /// - /// - /// Filter by asset - /// Filter by start time - /// Filter by end time - /// Filter by status - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetWithdrawalHistoryAsync(string? asset = null, DateTime? startTime = null, DateTime? endTime = null, WithdrawStatus? status = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - #region Funding - - /// - /// Get user last funding fee - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetUserLastFundingFeeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get predicted next funding rate - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetUserPredictedFundingRateAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - /// - /// Get Api key info - /// - /// - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetApiKeyInfoAsync(long? receiveWindow = null, CancellationToken ct = default); - - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiExchangeData.cs b/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiExchangeData.cs deleted file mode 100644 index ae169a26..00000000 --- a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiExchangeData.cs +++ /dev/null @@ -1,157 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.UsdPerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 16 OCTOBER, USE V5 API INSTEAD] Bybit exchange data endpoints. Exchange data includes market data (tickers, order books, etc) and system status. - /// - public interface IBybitRestClientUsdPerpetualApiExchangeData - { - /// - /// Get the server time - /// - /// - /// Cancellation token - /// - Task> GetServerTimeAsync(CancellationToken ct = default); - - /// - /// The API announcements for the last 30 days - /// - /// - /// Cancellation token - /// - Task>> GetAnnouncementsAsync(CancellationToken ct = default); - - /// - /// Get all supported symbols - /// - /// - /// Cancellation token - /// - Task>> GetSymbolsAsync(CancellationToken ct = default); - - /// - /// The ticker info for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task>> GetTickerAsync(string? symbol = null, CancellationToken ct = default); - - /// - /// Get the current order book for a symbol - /// - /// - /// The symbol - /// Cancellation token - /// - Task>> GetOrderBookAsync(string symbol, CancellationToken ct = default); - - /// - /// Get public trade history - /// - /// - /// The symbol - /// Max amount of results - /// Cancellation token - /// - Task>> GetTradeHistoryAsync(string symbol, int? limit = null, CancellationToken ct = default); - - /// - /// Get price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get index price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetIndexPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get mark price klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetMarkPriceKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get premium index klines - /// - /// - /// Symbol of the klines - /// Interval of the kline data - /// Start time of the data - /// Max amount of candles - /// Cancellation token - /// - Task>> GetPremiumIndexKlinesAsync(string symbol, KlineInterval interval, DateTime from, int? limit = null, CancellationToken ct = default); - - /// - /// Get long/short ratio - /// - /// - /// The symbol - /// The data period - /// Max amount of results - /// Cancellation token - /// - Task>> GetLongShortRatioAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default); - - /// - /// Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions. - /// - /// - /// The symbol - /// The period of data - /// Max amount of results - /// Cancellation token - /// - Task>> GetOpenInterestAsync(string symbol, DataPeriod period, int? limit = null, CancellationToken ct = default); - - /// - /// Obtain filled orders worth more than 500,000 USD within the last 24h. - /// - /// - /// The symbol - /// The max amount of results - /// Cancellation token - /// - Task>> GetRecentBigTradesAsync(string symbol, int? limit = null, CancellationToken ct = default); - - /// - /// Get last funding rate - /// - /// - /// The symbol - /// Cancellation token - /// - Task> GetLastFundingRateAsync(string symbol, CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiTrading.cs b/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiTrading.cs deleted file mode 100644 index c6c567c5..00000000 --- a/ByBit.Net/Interfaces/Clients/UsdPerpetualApi/IBybitRestClientUsdPerpetualApiTrading.cs +++ /dev/null @@ -1,274 +0,0 @@ -using Bybit.Net.Enums; -using Bybit.Net.Objects.Internal; -using Bybit.Net.Objects.Models; -using CryptoExchange.Net.Objects; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace Bybit.Net.Interfaces.Clients.UsdPerpetualApi -{ - /// - /// [DEPRECATED, WILL STOP WORKING ON 30 OCTOBER, USE V5 API INSTEAD] Bybit trading endpoints, placing and managing orders. - /// - public interface IBybitRestClientUsdPerpetualApiTrading - { - #region Orders - /// - /// Place a new order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Quantity - /// Time in force - /// Price - /// True means your position can only reduce in size if this order is triggered - /// For a closing order. It can only reduce your position, not increase it. If the account has insufficient available balance when the closing order is triggered, then other active orders of similar contracts will be cancelled or reduced. It can be used to ensure your stop loss reduces your position regardless of current available margin. - /// Client order id - /// Take profit price, only take effect upon opening the position - /// Stop loss price, only take effect upon opening the position - /// Take profit trigger price type, default: LastPrice - /// Stop loss trigger price type, default: LastPrice - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceOrderAsync(string symbol, OrderSide side, OrderType type, decimal quantity, TimeInForce timeInForce, bool reduceOnly, bool closeOnTrigger, decimal? price = null, string? clientOrderId = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change an exising order. Either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// Stop order id - /// Client order id - /// New price to set - /// New quantity to set - /// New take profit price - /// New stop loss price - /// New take profit trigger type - /// New stop loss profit price - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ModifyOrderAsync(string symbol, string? orderId = null, string? clientOrderId = null, decimal? newPrice = null, decimal? newQuantity = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get orders - /// - /// - /// The symbol - /// Filter by order id - /// Filter by client order id - /// Filter by status - /// The result order - /// The page - /// The page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetOrdersAsync(string symbol, string? orderId = null, string? clientOrderId = null, OrderStatus? status = null, SortOrder? order = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information for up to 500 orders - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenOrdersRealTimeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information. Either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// - /// - /// - /// - /// - Task> GetOpenOrderRealTimeAsync(string symbol, string? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel an order, either orderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The id of the order to cancel - /// The client order id of the conditional order to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelOrderAsync(string symbol, string? orderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel all active orders for a symbol - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> CancelAllOrdersAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - #endregion - - #region Conditional orders - /// - /// Place a new conditional order - /// - /// - /// The symbol - /// Order side - /// Order type - /// Quantity - /// It will be used to compare with the value of trigger price, to decide whether your conditional order will be triggered by crossing trigger price from upper side or lower side. Mainly used to identify the expected direction of the current conditional order. - /// Trigger price - /// Time in force - /// Price - /// Trigger type - /// True means your position can only reduce in size if this order is triggered. When reduce_only is true, take profit/stop loss cannot be set - /// For a closing order. It can only reduce your position, not increase it. If the account has insufficient available balance when the closing order is triggered, then other active orders of similar contracts will be cancelled or reduced. It can be used to ensure your stop loss reduces your position regardless of current available margin. - /// Client order id - /// Take profit price, only take effect upon opening the position - /// Stop loss price, only take effect upon opening the position - /// Take profit trigger price type, default: LastPrice - /// Stop loss trigger price type, default: LastPrice - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> PlaceConditionalOrderAsync(string symbol, OrderSide side, OrderType type, decimal quantity, decimal basePrice, decimal triggerPrice, TimeInForce timeInForce, bool closeOnTrigger, bool reduceOnly, decimal? price = null, TriggerType? triggerType = null, string? clientOrderId = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, PositionMode? positionMode = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Change an exising order. Either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// Stop order id - /// Client order id - /// New price to set - /// New trigger price to set - /// New quantity to set - /// New take profit price - /// New stop loss price - /// New take profit trigger type - /// New stop loss profit price - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> ModifyConditionalOrderAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, decimal? newPrice = null, decimal? newTriggerPrice = null, decimal? newQuantity = null, decimal? takeProfitPrice = null, decimal? stopLossPrice = null, TriggerType? takeProfitTriggerType = null, TriggerType? stopLossTriggerType = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get order information for up to 10 conditional orders - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> GetOpenConditionalOrdersRealTimeAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get conditional order information. Either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The order id - /// The client order id - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> GetOpenConditionalOrderRealTimeAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Get a list of conditional orders - /// - /// - /// The symbol - /// Filter by order id - /// Filter by client order id - /// Filter by status - /// Result order - /// Page size - /// Page - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetConditionalOrdersAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, OrderStatus? status = null, SortOrder? order = null, int? pageSize = null, int? page = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel a conditional order, either stopOrderId or clientOrderId should be provided - /// - /// - /// The symbol - /// The id of the conditional order to cancel - /// The client order id of the conditional order to cancel - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task> CancelConditionalOrderAsync(string symbol, string? stopOrderId = null, string? clientOrderId = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Cancel all active conditional orders for a symbol - /// - /// - /// The symbol - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>> CancelAllConditionalOrdersAsync(string symbol, long? receiveWindow = null, CancellationToken ct = default); - - #endregion - - /// - /// Get executed user trades - /// - /// - /// The symbol - /// Filter by start time - /// Filter by end time - /// Filter by type - /// Page - /// Page size - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task>>> GetUserTradesAsync(string symbol, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, TradeType? type = null, long? receiveWindow = null, CancellationToken ct = default); - - /// - /// Set take profit, stop loss, and trailing stop for your open position - /// - /// - /// The symbol - /// The position side - /// The new take profit price. Setting it to null will not change the value, setting it to 0 will remove the current TakeProfit - /// The new stop loss price. Setting it to null will not change the value, setting it to 0 will remove the current StopLoss - /// Setting it to null will not change the value, setting it to 0 will remove the current TrailingStop - /// Take profit trigger type, defaults to LastPrice - /// Stop loss trigger type, defaults to LastPrice - /// Take profit quantity when in Partial mode - /// Stop loss quantity when in Partial mode - /// Position mode - /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request - /// Cancellation token - /// - Task SetTradingStopAsync( - string symbol, - PositionSide side, - decimal? takeProfitPrice = null, - decimal? stopLossPrice = null, - decimal? trailingStopPrice = null, - TriggerType? takeProfitTriggerType = null, - TriggerType? stopLossTriggerType = null, - decimal? takeProfitQuantity = null, - decimal? stopLossQuantity = null, - PositionMode? positionMode = null, - long? receiveWindow = null, - CancellationToken ct = default); - } -} \ No newline at end of file diff --git a/ByBit.Net/Objects/Models/Spot/v3/BybitSpotOrderV3.cs b/ByBit.Net/Objects/Models/Spot/v3/BybitSpotOrderV3.cs index 9be12de1..aaaff097 100644 --- a/ByBit.Net/Objects/Models/Spot/v3/BybitSpotOrderV3.cs +++ b/ByBit.Net/Objects/Models/Spot/v3/BybitSpotOrderV3.cs @@ -33,7 +33,7 @@ public class BybitSpotOrderV3 /// Order id /// [JsonProperty("orderId")] - public string OrderId { get; set; } = string.Empty; + public string Id { get; set; } = string.Empty; /// /// Order price @@ -84,14 +84,14 @@ public class BybitSpotOrderV3 /// [JsonProperty("orderType")] [JsonConverter(typeof(OrderTypeSpotConverter))] - public OrderType OrderType { get; set; } + public OrderType Type { get; set; } /// /// Order side /// [JsonProperty("side")] [JsonConverter(typeof(OrderSideConverter))] - public OrderSide OrderSide { get; set; } + public OrderSide Side { get; set; } /// /// Stop price @@ -109,7 +109,7 @@ public class BybitSpotOrderV3 /// Create time /// [JsonProperty("createTime"), JsonConverter(typeof(DateTimeConverter))] - public DateTime? CreateTime { get; set; } + public DateTime CreateTime { get; set; } /// /// Update time diff --git a/ByBit.Net/Objects/Options/BybitRestOptions.cs b/ByBit.Net/Objects/Options/BybitRestOptions.cs index 964882d7..c6a79e63 100644 --- a/ByBit.Net/Objects/Options/BybitRestOptions.cs +++ b/ByBit.Net/Objects/Options/BybitRestOptions.cs @@ -27,21 +27,6 @@ public class BybitRestOptions : RestExchangeOptions public TimeSpan ReceiveWindow { get; set; } = TimeSpan.FromSeconds(5); - /// - /// Options for the Inverse Futures API - /// - public RestApiOptions InverseFuturesOptions { get; private set; } = new RestApiOptions(); - - /// - /// Options for the Inverse Perpetual API - /// - public RestApiOptions InversePerpetualOptions { get; private set; } = new RestApiOptions(); - - /// - /// Options for the Usd Perpetual API - /// - public RestApiOptions UsdPerpetualOptions { get; private set; } = new RestApiOptions(); - /// /// Options for the Spot API /// @@ -67,9 +52,6 @@ internal BybitRestOptions Copy() var options = Copy(); options.Referer = Referer; options.ReceiveWindow = ReceiveWindow; - options.InverseFuturesOptions = InverseFuturesOptions.Copy(); - options.InversePerpetualOptions = InversePerpetualOptions.Copy(); - options.UsdPerpetualOptions = UsdPerpetualOptions.Copy(); options.SpotOptions = SpotOptions.Copy(); options.CopyTradingOptions = CopyTradingOptions.Copy(); options.DerivativesOptions = DerivativesOptions.Copy(); diff --git a/ByBit.Net/Objects/Options/BybitSocketOptions.cs b/ByBit.Net/Objects/Options/BybitSocketOptions.cs index 5c99bb29..9ed651b5 100644 --- a/ByBit.Net/Objects/Options/BybitSocketOptions.cs +++ b/ByBit.Net/Objects/Options/BybitSocketOptions.cs @@ -18,35 +18,11 @@ public class BybitSocketOptions : SocketExchangeOptions SocketNoDataTimeout = TimeSpan.FromSeconds(30) }; - /// - /// Options for the Inverse Futures API - /// - public BybitSocketApiOptions InverseFuturesOptions { get; private set; } = new BybitSocketApiOptions(); - /// - /// Options for the Inverse Perpetual API - /// - public BybitSocketApiOptions InversePerpetualOptions { get; private set; } = new BybitSocketApiOptions(); - /// - /// Options for the Usd Perpetual API - /// - public BybitSocketApiOptions UsdPerpetualOptions { get; private set; } = new BybitSocketApiOptions(); - /// - /// Options for the Spot V1 API - /// - public BybitSocketApiOptions SpotV1Options { get; private set; } = new BybitSocketApiOptions(); - /// - /// Options for the Spot V2 API - /// - public BybitSocketApiOptions SpotV2Options { get; private set; } = new BybitSocketApiOptions(); /// /// Options for the Spot V3 API /// public BybitSocketApiOptions SpotV3Options { get; private set; } = new BybitSocketApiOptions(); /// - /// Options for the Copy Trading API - /// - public BybitSocketApiOptions CopyTradingOptions { get; private set; } = new BybitSocketApiOptions(); - /// /// Options for the Public Derivatives API /// public BybitSocketApiOptions DerivativesPublicOptions { get; private set; } = new BybitSocketApiOptions(); @@ -66,13 +42,7 @@ public class BybitSocketOptions : SocketExchangeOptions internal BybitSocketOptions Copy() { var options = Copy(); - options.InverseFuturesOptions = InverseFuturesOptions.Copy(); - options.InversePerpetualOptions = InversePerpetualOptions.Copy(); - options.UsdPerpetualOptions = UsdPerpetualOptions.Copy(); - options.SpotV1Options = SpotV1Options.Copy(); - options.SpotV2Options = SpotV2Options.Copy(); options.SpotV3Options = SpotV3Options.Copy(); - options.CopyTradingOptions = CopyTradingOptions.Copy(); options.DerivativesPublicOptions = DerivativesPublicOptions.Copy(); options.UnifiedMarginOptions = UnifiedMarginOptions.Copy(); options.ContractOptions = ContractOptions.Copy(); diff --git a/Bybit.UnitTests/JsonTests.cs b/Bybit.UnitTests/JsonTests.cs index 19ae88a1..682e0e15 100644 --- a/Bybit.UnitTests/JsonTests.cs +++ b/Bybit.UnitTests/JsonTests.cs @@ -17,12 +17,6 @@ public class JsonTests x.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "123"); x.SpotOptions.RateLimiters = new List(); x.SpotOptions.OutputOriginalData = true; - x.InverseFuturesOptions.RateLimiters = new List(); - x.InverseFuturesOptions.OutputOriginalData = true; - x.InversePerpetualOptions.RateLimiters = new List(); - x.InversePerpetualOptions.OutputOriginalData = true; - x.UsdPerpetualOptions.RateLimiters = new List(); - x.UsdPerpetualOptions.OutputOriginalData = true; x.DerivativesOptions.RateLimiters = new List(); x.DerivativesOptions.OutputOriginalData = true; x.V5Options.RateLimiters = new List(); @@ -30,193 +24,6 @@ public class JsonTests }, System.Net.HttpStatusCode.OK)); - [Test] - public async Task ValidateFuturesAccountCalls() - { - await _comparer.ProcessSubject("InversePerpetual/Account", c => c.InversePerpetualApi.Account, - useNestedJsonPropertyForCompare: new Dictionary - { - { "GetWalletFundHistoryAsync", "data" }, - { "GetWithdrawalHistoryAsync", "data" } - }, - ignoreProperties: new Dictionary> - { - { "GetWithdrawalHistoryAsync", new List { "current_page", "last_page" } }, - { "GetPositionAsync", new List { "oc_calc_data" } } - }, - useNestedJsonPropertyForAllCompare: new List { "result" }, - parametersToSetNull: new string[] { } - ); - } - - [Test] - public async Task ValidateFuturesExchangeDataCalls() - { - await _comparer.ProcessSubject("InversePerpetual/ExchangeData", c => c.InversePerpetualApi.ExchangeData, - useNestedJsonPropertyForCompare: new Dictionary - { - - }, - ignoreProperties: new Dictionary> - { - }, - useNestedJsonPropertyForAllCompare: new List { "result" }, - parametersToSetNull: new string[] { } - ); - } - - [Test] - public async Task ValidateFuturesTradingCalls() - { - await _comparer.ProcessSubject("InversePerpetual/Trading", c => c.InversePerpetualApi.Trading, - useNestedJsonPropertyForCompare: new Dictionary - { - { "GetUserTradesAsync", "trade_list" } - }, - ignoreProperties: new Dictionary> - { - { "GetOpenOrderRealTimeAsync", new List { "ext_fields" } }, - { "GetOpenOrdersRealTimeAsync", new List { "ext_fields" } }, - { "GetOpenConditionalOrderRealTimeAsync", new List { "ext_fields" } }, - { "GetOpenConditionalOrdersRealTimeAsync", new List { "ext_fields" } }, - { "SetTradingStopAsync", new List { "oc_calc_data", "ext_fields" } } - }, - useNestedJsonPropertyForAllCompare: new List { "result" }, - parametersToSetNull: new string[] { "clientOrderId" } - ); - } - - [Test] - public async Task ValidateSpotAccountCalls() - { - await _comparer.ProcessSubject("Spot/Account", c => c.SpotApiV1.Account, - useNestedJsonPropertyForCompare: new Dictionary - { - { "GetBalancesAsync", "balances" } - }, - ignoreProperties: new Dictionary> - { - }, - useNestedJsonPropertyForAllCompare: new List { "result" }, - parametersToSetNull: new string[] { } - ); - } - - [Test] - public async Task ValidateSpotTradingCalls() - { - await _comparer.ProcessSubject("Spot/Trading", c => c.SpotApiV1.Trading, - useNestedJsonPropertyForCompare: new Dictionary - { - }, - ignoreProperties: new Dictionary> - { - { "PlaceOrderAsync", new List{ "executedQty" } }, - { "CancelOrderAsync", new List{ "executedQty" } } - }, - useNestedJsonPropertyForAllCompare: new List { "result" }, - parametersToSetNull: new string[] { "clientOrderId" } - - ); - } - - [Test] - public async Task ValidateSpotExchangeDataCalls() - { - await _comparer.ProcessSubject("Spot/ExchangeData", c => c.SpotApiV1.ExchangeData, - useNestedJsonPropertyForCompare: new Dictionary - { - }, - ignoreProperties: new Dictionary> - { - { "GetKlinesAsync", new List() { "CloseTime" } } - }, - useNestedJsonPropertyForAllCompare: new List { "result" } - - ); - } - - [Test] - public async Task ValidateGeneralTransferCalls() - { - await _comparer.ProcessSubject("General/Transfer", c => c.GeneralApi.Transfer, - useNestedJsonPropertyForCompare: new Dictionary - { - }, - ignoreProperties: new Dictionary> - { - }, - useNestedJsonPropertyForAllCompare: new List { "result" } - - ); - } - - [Test] - public async Task ValidateGeneralDepositWithdrawalCalls() - { - await _comparer.ProcessSubject("General/DepositWithdraw", c => c.GeneralApi.WithdrawDeposit, - useNestedJsonPropertyForCompare: new Dictionary - { - { "GetSupportedDepositMethodsAsync", "config_list" }, - { "GetAssetInfoAsync", "rows" }, - }, - ignoreProperties: new Dictionary> - { - }, - useNestedJsonPropertyForAllCompare: new List { "result" } - - ); - } - - [Test] - public async Task ValidateUsdPerpetualAccountCalls() - { - await _comparer.ProcessSubject("UsdPerpetual/Account", c => c.UsdPerpetualApi.Account, - useNestedJsonPropertyForCompare: new Dictionary - { - }, - ignoreProperties: new Dictionary> - { - }, - useNestedJsonPropertyForAllCompare: new List { "result" } - - ); - } - - [Test] - public async Task ValidateUsdPerpetualExchangeDataCalls() - { - await _comparer.ProcessSubject("UsdPerpetual/ExchangeData", c => c.UsdPerpetualApi.ExchangeData, - useNestedJsonPropertyForCompare: new Dictionary - { - }, - ignoreProperties: new Dictionary> - { - { "GetKlinesAsync", new List{ "id", "period", "start_at" } } - }, - useNestedJsonPropertyForAllCompare: new List { "result" } - - ); - } - - [Test] - public async Task ValidateUsdPerpetualTradingCalls() - { - await _comparer.ProcessSubject("UsdPerpetual/Trading", c => c.UsdPerpetualApi.Trading, - useNestedJsonPropertyForCompare: new Dictionary - { - }, - ignoreProperties: new Dictionary> - { - { "GetUserTradesAsync", new List { "trade_time" } }, - { "GetOpenConditionalOrdersRealTimeAsync", new List { "ext_fields" } }, - { "GetOpenConditionalOrderRealTimeAsync", new List { "ext_fields" } } - }, - useNestedJsonPropertyForAllCompare: new List { "result" }, - parametersToSetNull: new string[] { "clientOrderId" } - ); - } - [Test] public async Task ValidateCopyTradingAccountCalls() { diff --git a/Bybit.UnitTests/TestHelpers.cs b/Bybit.UnitTests/TestHelpers.cs index cc6a80d9..83127b6e 100644 --- a/Bybit.UnitTests/TestHelpers.cs +++ b/Bybit.UnitTests/TestHelpers.cs @@ -62,13 +62,8 @@ public static BybitRestClient CreateClient(Action options = nu { BybitRestClient client; client = options != null ? new BybitRestClient(options) : new BybitRestClient(); - client.SpotApiV1.RequestFactory = Mock.Of(); client.SpotApiV3.RequestFactory = Mock.Of(); client.CopyTradingApi.RequestFactory = Mock.Of(); - client.GeneralApi.RequestFactory = Mock.Of(); - client.InverseFuturesApi.RequestFactory = Mock.Of(); - client.InversePerpetualApi.RequestFactory = Mock.Of(); - client.UsdPerpetualApi.RequestFactory = Mock.Of(); client.DerivativesApi.RequestFactory = Mock.Of(); client.V5Api.RequestFactory = Mock.Of(); return client; @@ -98,25 +93,10 @@ public static Mock SetResponse(BybitRestClient client, string response request.Setup(c => c.GetResponseAsync(It.IsAny())).Returns(Task.FromResult(response.Object)); request.Setup(c => c.GetHeaders()).Returns(new Dictionary>()); - var factory = Mock.Get(client.SpotApiV1.RequestFactory); - factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(request.Object); - factory = Mock.Get(client.SpotApiV3.RequestFactory); + var factory = Mock.Get(client.SpotApiV3.RequestFactory); factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(request.Object); factory = Mock.Get(client.CopyTradingApi.RequestFactory); - factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(request.Object); - factory = Mock.Get(client.GeneralApi.RequestFactory); - factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(request.Object); - factory = Mock.Get(client.InverseFuturesApi.RequestFactory); - factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(request.Object); - factory = Mock.Get(client.InversePerpetualApi.RequestFactory); - factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(request.Object); - factory = Mock.Get(client.UsdPerpetualApi.RequestFactory); factory.Setup(c => c.Create(It.IsAny(), It.IsAny(), It.IsAny())) .Returns(request.Object); factory = Mock.Get(client.DerivativesApi.RequestFactory);