diff --git a/BingX.Net.UnitTests/TestImplementations/JsonToObjectComparer.cs b/BingX.Net.UnitTests/TestImplementations/JsonToObjectComparer.cs index b3b22e3..7650916 100644 --- a/BingX.Net.UnitTests/TestImplementations/JsonToObjectComparer.cs +++ b/BingX.Net.UnitTests/TestImplementations/JsonToObjectComparer.cs @@ -1,4 +1,5 @@ using CryptoExchange.Net.Converters; +using CryptoExchange.Net.Converters.JsonNet; using CryptoExchange.Net.Objects; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/BingX.Net/BingX.Net.xml b/BingX.Net/BingX.Net.xml index c22a6e5..001ce02 100644 --- a/BingX.Net/BingX.Net.xml +++ b/BingX.Net/BingX.Net.xml @@ -154,9 +154,6 @@ - - - @@ -221,6 +218,12 @@ + + + + + + @@ -252,6 +255,86 @@ + + + Kline interval + + + + + One minute + + + + + Three minutes + + + + + Five minutes + + + + + Fifteen minutes + + + + + Thirty minutes + + + + + One hour + + + + + Two hours + + + + + Four hours + + + + + Six hours + + + + + Eight hours + + + + + Twelve hours + + + + + One day + + + + + Three days + + + + + One week + + + + + One month + + Status of a symbol @@ -452,6 +535,27 @@ + + + + + + + + + + + + + + + + + + + + + BingX Spot trading endpoints, placing and managing orders. @@ -521,6 +625,86 @@ The default addresses to connect to the BingX.com API + + + Kline (candlestick) info + + + + + Open timestamp + + + + + Open price + + + + + High price + + + + + Low price + + + + + Close price + + + + + Volume + + + + + Close time + + + + + Quote volume + + + + + Order book info + + + + + List of bids + + + + + List of asks + + + + + Timestamp of the data + + + + + Order book entry + + + + + The price + + + + + The quantity + + Socket update diff --git a/BingX.Net/Clients/FuturesApi/BingXSocketClientFuturesApi.cs b/BingX.Net/Clients/FuturesApi/BingXSocketClientFuturesApi.cs index 6a89812..b73b77f 100644 --- a/BingX.Net/Clients/FuturesApi/BingXSocketClientFuturesApi.cs +++ b/BingX.Net/Clients/FuturesApi/BingXSocketClientFuturesApi.cs @@ -44,12 +44,12 @@ internal BingXSocketClientFuturesApi(ILogger logger, BingXSocketOptions options) protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => new BingXAuthenticationProvider(credentials); - /// - public async Task> SubscribeToBingXUpdatesAsync(Action> onMessage, CancellationToken ct = default) - { - var subscription = new BingXSubscription(_logger, "TOOD", "", onMessage, false); - return await SubscribeAsync(subscription, ct).ConfigureAwait(false); - } + ///// + //public async Task> SubscribeToBingXUpdatesAsync(Action> onMessage, CancellationToken ct = default) + //{ + // var subscription = new BingXSubscription(_logger, "TOOD", "", onMessage, false); + // return await SubscribeAsync(subscription, ct).ConfigureAwait(false); + //} /// public override string? GetListenerIdentifier(IMessageAccessor message) diff --git a/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiExchangeData.cs b/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiExchangeData.cs index 9cc66ca..2f3ad80 100644 --- a/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiExchangeData.cs +++ b/BingX.Net/Clients/SpotApi/BingXRestClientSpotApiExchangeData.cs @@ -1,19 +1,15 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using CryptoExchange.Net; -using CryptoExchange.Net.Converters; using CryptoExchange.Net.Objects; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; +using BingX.Net.Enums; using BingX.Net.Interfaces.Clients.SpotApi; using BingX.Net.Objects.Models; using BingX.Net.Objects.Internal; +using CryptoExchange.Net.Converters.SystemTextJson; namespace BingX.Net.Clients.SpotApi { @@ -56,12 +52,47 @@ public async Task>> GetSymbolsAsync(strin /// public async Task>> GetRecentTradesAsync(string symbol, int? limit = null, CancellationToken ct = default) { - var parameters = new ParameterCollection(); - parameters.AddOptional("symbol", symbol); + var parameters = new ParameterCollection + { + { "symbol", symbol } + }; parameters.AddOptional("limit", limit); return await _baseClient.SendRequestInternal>(_baseClient.GetUri("/openApi/spot/v1/market/trades"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); } #endregion + + #region Get Order Book + + /// + public async Task> GetOrderBookAsync(string symbol, int? limit = null, CancellationToken ct = default) + { + var parameters = new ParameterCollection + { + { "symbol", symbol } + }; + parameters.AddOptional("limit", limit); + return await _baseClient.SendRequestInternal(_baseClient.GetUri("/openApi/spot/v1/market/depth"), 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 ParameterCollection + { + { "symbol", symbol }, + { "interval", EnumConverter.GetString(interval) } + }; + parameters.AddOptionalMilliseconds("startTime", startTime); + parameters.AddOptionalMilliseconds("endTime", endTime); + parameters.AddOptional("limit", limit); + return await _baseClient.SendRequestInternal>(_baseClient.GetUri("/openApi/spot/v1/market/kline"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + } + + #endregion } } diff --git a/BingX.Net/Enums/KlineInterval.cs b/BingX.Net/Enums/KlineInterval.cs new file mode 100644 index 0000000..a5d3e2a --- /dev/null +++ b/BingX.Net/Enums/KlineInterval.cs @@ -0,0 +1,89 @@ +using CryptoExchange.Net.Attributes; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BingX.Net.Enums +{ + /// + /// Kline interval + /// + public enum KlineInterval + { + /// + /// One minute + /// + [Map("1m")] + OneMinute, + /// + /// Three minutes + /// + [Map("3m")] + ThreeMinutes, + /// + /// Five minutes + /// + [Map("5m")] + FiveMinutes, + /// + /// Fifteen minutes + /// + [Map("15m")] + FifteenMinutes, + /// + /// Thirty minutes + /// + [Map("30m")] + ThirtyMinutes, + /// + /// One hour + /// + [Map("1h")] + OneHour, + /// + /// Two hours + /// + [Map("2h")] + TwoHours, + /// + /// Four hours + /// + [Map("4h")] + FourHours, + /// + /// Six hours + /// + [Map("6h")] + SixHours, + /// + /// Eight hours + /// + [Map("8h")] + EightHours, + /// + /// Twelve hours + /// + [Map("12h")] + TwelveHours, + /// + /// One day + /// + [Map("1d")] + OneDay, + /// + /// Three days + /// + [Map("3d")] + ThreeDay, + /// + /// One week + /// + [Map("1w")] + OneWeek, + /// + /// One month + /// + [Map("1M")] + OneMonth + } +} diff --git a/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApiExchangeData.cs b/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApiExchangeData.cs index 5ab69fd..67c20e4 100644 --- a/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApiExchangeData.cs +++ b/BingX.Net/Interfaces/Clients/SpotApi/IBingXRestClientSpotApiExchangeData.cs @@ -2,6 +2,7 @@ using System.Threading; using System.Threading.Tasks; using CryptoExchange.Net.Objects; +using BingX.Net.Enums; using BingX.Net.Objects.Models; using System.Collections.Generic; @@ -36,5 +37,26 @@ public interface IBingXRestClientSpotApiExchangeData /// /// Task>> GetRecentTradesAsync(string symbol, int? limit = null, CancellationToken ct = default); + + /// + /// + /// + /// + /// + /// + /// + Task> GetOrderBookAsync(string symbol, int? limit = null, CancellationToken ct = default); + + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + Task>> GetKlinesAsync(string symbol, KlineInterval interval, DateTime? startTime = null, DateTime? endTime = null, int? limit = null, CancellationToken ct = default); } } diff --git a/BingX.Net/Objects/Models/BingXKline.cs b/BingX.Net/Objects/Models/BingXKline.cs new file mode 100644 index 0000000..a916d61 --- /dev/null +++ b/BingX.Net/Objects/Models/BingXKline.cs @@ -0,0 +1,57 @@ +using CryptoExchange.Net.Converters; +using CryptoExchange.Net.Converters.SystemTextJson; +using System; +using System.Text.Json.Serialization; + +namespace BingX.Net.Objects.Models +{ + /// + /// Kline (candlestick) info + /// + [JsonConverter(typeof(ArrayConverter))] + public record BingXKline + { + /// + /// Open timestamp + /// + [ArrayProperty(0)] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime OpenTime { get; set; } + /// + /// Open price + /// + [ArrayProperty(1)] + public decimal OpenPrice { get; set; } + /// + /// High price + /// + [ArrayProperty(2)] + public decimal HighPrice { get; set; } + /// + /// Low price + /// + [ArrayProperty(3)] + public decimal LowPrice { get; set; } + /// + /// Close price + /// + [ArrayProperty(4)] + public decimal Close { get; set; } + /// + /// Volume + /// + [ArrayProperty(5)] + public decimal Volume { get; set; } + /// + /// Close time + /// + [ArrayProperty(6)] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime CloseTime { get; set; } + /// + /// Quote volume + /// + [ArrayProperty(7)] + public decimal QuoteVolume { get; set; } + } +} diff --git a/BingX.Net/Objects/Models/BingXOrderBook.cs b/BingX.Net/Objects/Models/BingXOrderBook.cs new file mode 100644 index 0000000..e4e2f6d --- /dev/null +++ b/BingX.Net/Objects/Models/BingXOrderBook.cs @@ -0,0 +1,48 @@ +using CryptoExchange.Net.Converters; +using CryptoExchange.Net.Converters.SystemTextJson; +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace BingX.Net.Objects.Models +{ + /// + /// Order book info + /// + public record BingXOrderBook + { + /// + /// List of bids + /// + [JsonPropertyName("bids")] + public IEnumerable Bids { get; set; } = Array.Empty(); + /// + /// List of asks + /// + [JsonPropertyName("asks")] + public IEnumerable Asks { get; set; } = Array.Empty(); + /// + /// Timestamp of the data + /// + [JsonPropertyName("ts")] + public DateTime Timestamp { get; set; } + } + + /// + /// Order book entry + /// + [JsonConverter(typeof(ArrayConverter))] + public record BingXOrderBookEntry + { + /// + /// The price + /// + [ArrayProperty(0)] + public decimal Price { get; set; } + /// + /// The quantity + /// + [ArrayProperty(1)] + public decimal Quantity { get; set; } + } +} diff --git a/BingX.Net/Objects/Models/BingXTrade.cs b/BingX.Net/Objects/Models/BingXTrade.cs index 1c75773..156fcf5 100644 --- a/BingX.Net/Objects/Models/BingXTrade.cs +++ b/BingX.Net/Objects/Models/BingXTrade.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using System; +using System.Text.Json.Serialization; namespace BingX.Net.Objects.Models { @@ -12,26 +13,31 @@ public record BingXTrade /// Trade id /// [JsonProperty("id")] + [JsonPropertyName("id")] public long Id { get; set; } /// /// Trade price /// [JsonProperty("price")] + [JsonPropertyName("price")] public decimal Price { get; set; } /// /// Quantity /// [JsonProperty("qty")] + [JsonPropertyName("qty")] public decimal Quantity { get; set; } /// /// timestamp /// [JsonProperty("time")] + [JsonPropertyName("time")] public DateTime Timestamp { get; set; } /// /// Whether buyer was the maker /// [JsonProperty("buyerMaker")] + [JsonPropertyName("buyerMaker")] public bool BuyerIsMaker { get; set; } } }