diff --git a/Kraken.Net.UnitTests/ConvertersTests/StreamOrderbookConvertersTest.cs b/Kraken.Net.UnitTests/ConvertersTests/StreamOrderbookConvertersTest.cs index d0abd9e..2217caf 100644 --- a/Kraken.Net.UnitTests/ConvertersTests/StreamOrderbookConvertersTest.cs +++ b/Kraken.Net.UnitTests/ConvertersTests/StreamOrderbookConvertersTest.cs @@ -2,6 +2,7 @@ using Kraken.Net.Converters; using Newtonsoft.Json.Linq; using NUnit.Framework; +using NUnit.Framework.Legacy; namespace Kraken.Net.UnitTests.ConvertersTests.StreamOrderbookConvertersTests { @@ -53,14 +54,14 @@ public void Event_Should_ParseCountOfFour() { var testObj = StreamOrderBookConverter.Convert(this._fiveElements!); - Assert.AreEqual(2, testObj!.Data.Asks.Count()); - Assert.AreEqual(1, testObj.Data.Bids.Count()); - Assert.AreEqual(1234, testObj.ChannelId); - Assert.AreEqual("book-10", testObj.ChannelName); - Assert.AreEqual("XBT/USD", testObj.Symbol); + Assert.That(2 == testObj!.Data.Asks.Count()); + Assert.That(1 == testObj.Data.Bids.Count()); + Assert.That(1234 == testObj.ChannelId); + Assert.That("book-10" == testObj.ChannelName); + Assert.That("XBT/USD" == testObj.Symbol); - Assert.AreEqual("0.40100000", testObj.Data.Asks.ElementAt(1).RawQuantity); - Assert.AreEqual("5542.50000", testObj.Data.Asks.ElementAt(1).RawPrice); + Assert.That("0.40100000" == testObj.Data.Asks.ElementAt(1).RawQuantity); + Assert.That("5542.50000" == testObj.Data.Asks.ElementAt(1).RawPrice); } } } \ No newline at end of file diff --git a/Kraken.Net.UnitTests/JsonToObjectComparer.cs b/Kraken.Net.UnitTests/JsonToObjectComparer.cs index 74e3ce4..84f47d6 100644 --- a/Kraken.Net.UnitTests/JsonToObjectComparer.cs +++ b/Kraken.Net.UnitTests/JsonToObjectComparer.cs @@ -1,9 +1,11 @@ using CryptoExchange.Net.Converters; +using CryptoExchange.Net.Converters.JsonNet; using CryptoExchange.Net.Objects; using Kraken.Net.UnitTests.TestImplementations; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NUnit.Framework; +using NUnit.Framework.Legacy; using System; using System.Collections; using System.Collections.Generic; @@ -86,7 +88,7 @@ public async Task ProcessSubject( var result = (CallResult)await TestHelpers.InvokeAsync(method, getSubject(client), input.ToArray()); // asset - Assert.Null(result.Error, method.Name); + ClassicAssert.Null(result.Error, method.Name); var resultProp = result.GetType().GetProperty("Data", BindingFlags.Public | BindingFlags.Instance); if (resultProp == null) @@ -118,8 +120,10 @@ internal static void ProcessData(string method, var resultProperties = resultData.GetType().GetProperties().Select(p => (p, (JsonPropertyAttribute)p.GetCustomAttributes(typeof(JsonPropertyAttribute), true).SingleOrDefault())); var jsonObject = JToken.Parse(json); if (useNestedJsonPropertyForAllCompare?.Any() == true) + { foreach (var c in useNestedJsonPropertyForAllCompare) jsonObject = jsonObject[c]; + } if (useNestedJsonPropertyForCompare?.ContainsKey(method) == true) { @@ -169,9 +173,10 @@ internal static void ProcessData(string method, enumerator.MoveNext(); if (jObj.Type == JTokenType.Object) { - if (enumerator.Current is IDictionary) - ProcessDictionary(method, (IDictionary)enumerator.Current, (JObject)jObj, ignoreProperties); - + if (enumerator.Current is IDictionary dictionary) + { + ProcessDictionary(method, dictionary, (JObject)jObj, ignoreProperties); + } else { foreach (var subProp in ((JObject)jObj).Properties()) @@ -252,10 +257,8 @@ private static void CheckObject(string method, JProperty prop, object obj, Dicti // Property has a value var property = resultProperties.SingleOrDefault(p => p.Item2?.PropertyName == prop.Name).p; - if (property is null) - property = resultProperties.SingleOrDefault(p => p.p.Name == prop.Name).p; - if (property is null) - property = resultProperties.SingleOrDefault(p => p.p.Name.ToUpperInvariant() == prop.Name.ToUpperInvariant()).p; + property ??= resultProperties.SingleOrDefault(p => p.p.Name == prop.Name).p; + property ??= resultProperties.SingleOrDefault(p => p.p.Name.ToUpperInvariant() == prop.Name.ToUpperInvariant()).p; if (property is null) { @@ -274,7 +277,9 @@ private static void CheckPropertyValue(string method, JToken propValue, object p { if ((propValue.Type == JTokenType.Integer || propValue.Type == JTokenType.String) && propValue.ToString() == "0" && (info.PropertyType == typeof(DateTime) || info.PropertyType == typeof(DateTime?))) + { return; + } // Property value not correct throw new Exception($"{method}: Property `{propertyName}` has no value while input json `{propName}` has value {propValue}"); @@ -371,7 +376,9 @@ private static void CheckPropertyValue(string method, JToken propValue, object p { if (info.GetCustomAttribute(true) == null && info.GetCustomAttribute(true)?.ItemConverterType == null) + { CheckValues(method, propertyName, (JValue)propValue, propertyValue); + } } } } @@ -410,7 +417,9 @@ private static void CheckValues(string method, string property, JValue jsonValue // timestamp, hard to check.. } else if (jsonValue.Value.ToString().ToLowerInvariant() != objectValue.ToString().ToLowerInvariant()) + { throw new Exception($"{method}: {property} not equal: {jsonValue.Value()} vs {objectValue.ToString()}"); + } } else if (jsonValue.Type == JTokenType.Integer) { diff --git a/Kraken.Net.UnitTests/Kraken.Net.UnitTests.csproj b/Kraken.Net.UnitTests/Kraken.Net.UnitTests.csproj index f45edbb..cc5772d 100644 --- a/Kraken.Net.UnitTests/Kraken.Net.UnitTests.csproj +++ b/Kraken.Net.UnitTests/Kraken.Net.UnitTests.csproj @@ -6,10 +6,10 @@ - - - - + + + + diff --git a/Kraken.Net.UnitTests/KrakenClientTests.cs b/Kraken.Net.UnitTests/KrakenClientTests.cs index c00005e..66de465 100644 --- a/Kraken.Net.UnitTests/KrakenClientTests.cs +++ b/Kraken.Net.UnitTests/KrakenClientTests.cs @@ -14,6 +14,9 @@ using Kraken.Net.Clients.SpotApi; using Kraken.Net.ExtensionMethods; using CryptoExchange.Net.Objects.Sockets; +using System.Collections.Generic; +using Kraken.Net.Objects.Models.Futures; +using NUnit.Framework.Legacy; namespace Kraken.Net.UnitTests { @@ -57,8 +60,8 @@ public class KrakenClientTests // var data = result.GetType().GetProperty("Data").GetValue(result); // assert - // Assert.AreEqual(true, callResult); - // Assert.IsTrue(TestHelpers.AreEqual(expected, data), method.Name); + // ClassicAssert.AreSame(true, callResult); + // Assert.That(TestHelpers.AreEqual(expected, data), method.Name); // } //} @@ -73,9 +76,9 @@ public async Task TestErrorResult_Should_ResultInFailedCall() var result = await client.SpotApi.ExchangeData.GetSymbolsAsync(); // assert - Assert.IsFalse(result.Success); - Assert.IsTrue(result.Error!.Message.Contains("first error")); - Assert.IsTrue(result.Error!.Message.Contains("another error")); + ClassicAssert.IsFalse(result.Success); + Assert.That(result.Error!.Message.Contains("first error")); + Assert.That(result.Error!.Message.Contains("another error")); } [TestCase()] @@ -88,9 +91,9 @@ public async Task TestHttpError_Should_ResultInFailedCall() var result = await client.SpotApi.ExchangeData.GetSymbolsAsync(); // assert - Assert.IsFalse(result.Success); - Assert.IsTrue(result.ResponseStatusCode == System.Net.HttpStatusCode.BadRequest); - Assert.IsTrue(result.Error!.ToString().Contains("Error request")); + ClassicAssert.IsFalse(result.Success); + Assert.That(result.ResponseStatusCode == System.Net.HttpStatusCode.BadRequest); + Assert.That(result.Error!.ToString().Contains("Error request")); } public string SerializeExpected(T data) @@ -145,8 +148,8 @@ public void CheckValidKrakenWebsocketSymbol(string symbol, bool isValid) public void CheckRestInterfaces() { var assembly = Assembly.GetAssembly(typeof(KrakenRestClientSpotApi)); - var ignore = new string[] { "IKrakenClientSpot" }; - var clientInterfaces = assembly.GetTypes().Where(t => t.Name.StartsWith("IKrakenClientSpot") && !ignore.Contains(t.Name)); + var ignore = new string[] { "IKrakenRestClientSpot" }; + var clientInterfaces = assembly.GetTypes().Where(t => t.Name.StartsWith("IKrakenRestClientSpot") && !ignore.Contains(t.Name)); foreach (var clientInterface in clientInterfaces) { @@ -155,31 +158,88 @@ public void CheckRestInterfaces() foreach (var method in implementation.GetMethods().Where(m => m.ReturnType.IsAssignableTo(typeof(Task)))) { var interfaceMethod = clientInterface.GetMethod(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray()); - Assert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}"); + ClassicAssert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}"); methods++; } Debug.WriteLine($"{clientInterface.Name} {methods} methods validated"); } } - [Test] - public void CheckSocketInterfaces() + [TestCase()] + public async Task ReceivingHttpErrorWithNoJsonOnSpotApi_Should_ReturnErrorAndNotSuccess() { - var assembly = Assembly.GetAssembly(typeof(KrakenSocketClient)); - var clientInterfaces = assembly.GetTypes().Where(t => t.Name.StartsWith("IKrakenSocketClientSpot")); + // arrange + var client = TestHelpers.CreateClient(); + TestHelpers.SetResponse((KrakenRestClient)client, "", System.Net.HttpStatusCode.BadGateway); - foreach (var clientInterface in clientInterfaces) + // act + var result = await client.SpotApi.ExchangeData.GetTickersAsync(); + + // assert + ClassicAssert.IsFalse(result.Success); + ClassicAssert.IsNotNull(result.Error); + Assert.That(System.Net.HttpStatusCode.BadGateway == result.ResponseStatusCode); + } + + [TestCase()] + public async Task ReceivingErrorOnSpotApi_Should_ReturnErrorAndNotSuccess() + { + // arrange + var client = TestHelpers.CreateClient(); + var resultObj = new KrakenResult() { - var implementation = assembly.GetTypes().Single(t => t.IsAssignableTo(clientInterface) && t != clientInterface); - int methods = 0; - foreach (var method in implementation.GetMethods().Where(m => m.ReturnType.IsAssignableTo(typeof(Task>)))) + Error = new List { - var interfaceMethod = clientInterface.GetMethod(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray()); - Assert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}"); - methods++; + "Error occured" } - Debug.WriteLine($"{clientInterface.Name} {methods} methods validated"); - } + }; + + TestHelpers.SetResponse((KrakenRestClient)client, JsonConvert.SerializeObject(resultObj)); + + // act + var result = await client.SpotApi.ExchangeData.GetAssetsAsync(); + + // assert + ClassicAssert.IsFalse(result.Success); + ClassicAssert.IsNotNull(result.Error); + Assert.That(result.Error.Message == "Error occured"); + } + + [TestCase()] + public async Task ReceivingHttpErrorWithNoJsonOnFuturesApi_Should_ReturnErrorAndNotSuccess() + { + // arrange + var client = TestHelpers.CreateClient(); + TestHelpers.SetResponse((KrakenRestClient)client, "", System.Net.HttpStatusCode.BadGateway); + + // act + var result = await client.FuturesApi.ExchangeData.GetTickersAsync(); + + // assert + ClassicAssert.IsFalse(result.Success); + ClassicAssert.IsNotNull(result.Error); + Assert.That(System.Net.HttpStatusCode.BadGateway == result.ResponseStatusCode); + } + + [TestCase()] + public async Task ReceivingErrorOnFuturesApi_Should_ReturnErrorAndNotSuccess() + { + // arrange + var client = TestHelpers.CreateClient(); + var resultObj = new KrakenFuturesResult() + { + Error = "Error occured" + }; + + TestHelpers.SetResponse((KrakenRestClient)client, JsonConvert.SerializeObject(resultObj), System.Net.HttpStatusCode.BadRequest); + + // act + var result = await client.FuturesApi.ExchangeData.GetTickersAsync(); + + // assert + ClassicAssert.IsFalse(result.Success); + ClassicAssert.IsNotNull(result.Error); + Assert.That(result.Error.Message == "Error occured"); } } } diff --git a/Kraken.Net.UnitTests/KrakenSocketClientTests.cs b/Kraken.Net.UnitTests/KrakenSocketClientTests.cs index 04e7fbd..b434a49 100644 --- a/Kraken.Net.UnitTests/KrakenSocketClientTests.cs +++ b/Kraken.Net.UnitTests/KrakenSocketClientTests.cs @@ -1,8 +1,15 @@ using CryptoExchange.Net; +using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Objects.Sockets; +using Kraken.Net.Clients; using Kraken.Net.UnitTests.TestImplementations; using Kucoin.Net.UnitTests.TestImplementations; using Newtonsoft.Json.Linq; using NUnit.Framework; +using NUnit.Framework.Legacy; +using System.Diagnostics; +using System.Linq; +using System.Reflection; using System.Threading.Tasks; namespace Kraken.Net.UnitTests @@ -22,11 +29,11 @@ public async Task Subscribe_Should_SucceedIfAckResponse() var subTask = client.SpotApi.SubscribeToTickerUpdatesAsync("XBT/EUR", test => { }); await Task.Delay(10); var id = JToken.Parse(socket.LastSendMessage!)["reqid"]; - await socket.InvokeMessage($"{{\"channelID\": 1, \"status\": \"subscribed\", \"reqid\":{id}}}"); + socket.InvokeMessage($"{{\"channelID\": 1, \"status\": \"subscribed\", \"reqid\":{id}}}"); var subResult = subTask.Result; // assert - Assert.IsTrue(subResult.Success); + Assert.That(subResult.Success); } [Test] @@ -41,12 +48,32 @@ public async Task Subscribe_Should_FailIfNotAckResponse() var subTask = client.SpotApi.SubscribeToTickerUpdatesAsync("XBT/EUR", test => { }); await Task.Delay(10); var id = JToken.Parse(socket.LastSendMessage!)["reqid"]; - await socket.InvokeMessage($"{{\"channelID\": 1, \"status\": \"error\", \"errormessage\": \"Failed to sub\", \"reqid\":{id}}}"); + socket.InvokeMessage($"{{\"channelID\": 1, \"status\": \"error\", \"errormessage\": \"Failed to sub\", \"reqid\":{id}}}"); var subResult = subTask.Result; // assert - Assert.IsFalse(subResult.Success); - Assert.IsTrue(subResult.Error!.Message.Contains("Failed to sub")); + ClassicAssert.IsFalse(subResult.Success); + Assert.That(subResult.Error!.Message.Contains("Failed to sub")); + } + + [Test] + public void CheckSocketInterfaces() + { + var assembly = Assembly.GetAssembly(typeof(KrakenSocketClient)); + var clientInterfaces = assembly.GetTypes().Where(t => t.Name.StartsWith("IKrakenSocketClientSpot")); + + foreach (var clientInterface in clientInterfaces) + { + var implementation = assembly.GetTypes().Single(t => t.IsAssignableTo(clientInterface) && t != clientInterface); + int methods = 0; + foreach (var method in implementation.GetMethods().Where(m => m.ReturnType.IsAssignableTo(typeof(Task>)))) + { + var interfaceMethod = clientInterface.GetMethod(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray()); + ClassicAssert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}"); + methods++; + } + Debug.WriteLine($"{clientInterface.Name} {methods} methods validated"); + } } } } diff --git a/Kraken.Net.UnitTests/TestImplementations/TestSocket.cs b/Kraken.Net.UnitTests/TestImplementations/TestSocket.cs index 6d3e277..f3e714b 100644 --- a/Kraken.Net.UnitTests/TestImplementations/TestSocket.cs +++ b/Kraken.Net.UnitTests/TestImplementations/TestSocket.cs @@ -21,7 +21,7 @@ public class TestSocket: IWebsocket public event Func OnReconnecting; #pragma warning restore 0067 public event Func OnRequestSent; - public event Func OnStreamMessage; + public event Action> OnStreamMessage; public event Func OnError; public event Func OnOpen; @@ -94,16 +94,14 @@ public void InvokeOpen() OnOpen?.Invoke(); } - public async Task InvokeMessage(string data) + public void InvokeMessage(string data) { - var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)); - await OnStreamMessage?.Invoke(WebSocketMessageType.Text, stream); + OnStreamMessage?.Invoke(WebSocketMessageType.Text, new ReadOnlyMemory(Encoding.UTF8.GetBytes(data))); } - public async Task InvokeMessage(T data) + public void InvokeMessage(T data) { - var stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data))); - await OnStreamMessage?.Invoke(WebSocketMessageType.Text, stream); + OnStreamMessage?.Invoke(WebSocketMessageType.Text, new ReadOnlyMemory(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data)))); } public void InvokeError(Exception error) diff --git a/Kraken.Net/Clients/FuturesApi/KrakenRestClientFuturesApi.cs b/Kraken.Net/Clients/FuturesApi/KrakenRestClientFuturesApi.cs index d71d598..634c0c5 100644 --- a/Kraken.Net/Clients/FuturesApi/KrakenRestClientFuturesApi.cs +++ b/Kraken.Net/Clients/FuturesApi/KrakenRestClientFuturesApi.cs @@ -1,17 +1,8 @@ -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; -using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Clients; using Kraken.Net.Interfaces.Clients.FuturesApi; using Kraken.Net.Objects; using Kraken.Net.Objects.Models.Futures; using Kraken.Net.Objects.Options; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; namespace Kraken.Net.Clients.FuturesApi { @@ -47,10 +38,10 @@ internal KrakenRestClientFuturesApi(ILogger logger, HttpClient? httpClient, Krak ExchangeData = new KrakenRestClientFuturesApiExchangeData(this); Trading = new KrakenRestClientFuturesApiTrading(this); - requestBodyFormat = RequestBodyFormat.FormData; + RequestBodyFormat = RequestBodyFormat.FormData; ParameterPositions[HttpMethod.Put] = HttpMethodParameterPosition.InUri; - arraySerialization = ArrayParametersSerialization.MultipleValues; - requestBodyEmptyContent = ""; + ArraySerialization = ArrayParametersSerialization.MultipleValues; + RequestBodyEmptyContent = ""; } #endregion @@ -123,15 +114,14 @@ internal async Task> ExecuteBase(Uri url, HttpMethod method, } /// - protected override Error ParseErrorResponse(int httpStatusCode, IEnumerable>> responseHeaders, string data) + protected override Error ParseErrorResponse(int httpStatusCode, IEnumerable>> responseHeaders, IMessageAccessor accessor) { - var errorData = ValidateJson(data); - if (!errorData) - return new ServerError(data); + if (!accessor.IsJson) + return new ServerError(accessor.GetOriginalString()); - var result = Deserialize(errorData.Data); + var result = accessor.Deserialize(); if (!result) - return new ServerError(data); + return new ServerError(accessor.GetOriginalString()); if (result.Data.Errors?.Any() == true) { @@ -139,7 +129,7 @@ protected override Error ParseErrorResponse(int httpStatusCode, IEnumerable diff --git a/Kraken.Net/Clients/FuturesApi/KrakenSocketClientFuturesApi.cs b/Kraken.Net/Clients/FuturesApi/KrakenSocketClientFuturesApi.cs index 633a1cd..a416600 100644 --- a/Kraken.Net/Clients/FuturesApi/KrakenSocketClientFuturesApi.cs +++ b/Kraken.Net/Clients/FuturesApi/KrakenSocketClientFuturesApi.cs @@ -3,13 +3,12 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using CryptoExchange.Net; using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; +using CryptoExchange.Net.Converters.MessageParsing; using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Interfaces.Clients.FuturesApi; using Kraken.Net.Objects; using Kraken.Net.Objects.Models.Socket.Futures; diff --git a/Kraken.Net/Clients/KrakenRestClient.cs b/Kraken.Net/Clients/KrakenRestClient.cs index d73bcef..570dde7 100644 --- a/Kraken.Net/Clients/KrakenRestClient.cs +++ b/Kraken.Net/Clients/KrakenRestClient.cs @@ -1,7 +1,7 @@ using System; using System.Net.Http; -using CryptoExchange.Net; using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; using Kraken.Net.Clients.FuturesApi; using Kraken.Net.Clients.SpotApi; using Kraken.Net.Interfaces.Clients; diff --git a/Kraken.Net/Clients/KrakenSocketClient.cs b/Kraken.Net/Clients/KrakenSocketClient.cs index 4768803..f8af9c2 100644 --- a/Kraken.Net/Clients/KrakenSocketClient.cs +++ b/Kraken.Net/Clients/KrakenSocketClient.cs @@ -1,5 +1,5 @@ -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; using Kraken.Net.Clients.SpotApi; using Kraken.Net.Interfaces.Clients; using Kraken.Net.Interfaces.Clients.FuturesApi; diff --git a/Kraken.Net/Clients/SpotApi/KrakenRestClientSpotApi.cs b/Kraken.Net/Clients/SpotApi/KrakenRestClientSpotApi.cs index d0feb29..16ac186 100644 --- a/Kraken.Net/Clients/SpotApi/KrakenRestClientSpotApi.cs +++ b/Kraken.Net/Clients/SpotApi/KrakenRestClientSpotApi.cs @@ -4,8 +4,8 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using CryptoExchange.Net; using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; using CryptoExchange.Net.CommonObjects; using CryptoExchange.Net.Interfaces.CommonClients; using CryptoExchange.Net.Objects; @@ -63,7 +63,7 @@ internal KrakenRestClientSpotApi(ILogger logger, HttpClient? httpClient, KrakenR Trading = new KrakenRestClientSpotApiTrading(this); Staking = new KrakenRestClientSpotStakingApi(this); - requestBodyFormat = RequestBodyFormat.FormData; + RequestBodyFormat = RequestBodyFormat.FormData; } #endregion diff --git a/Kraken.Net/Clients/SpotApi/KrakenSocketClientSpotApi.cs b/Kraken.Net/Clients/SpotApi/KrakenSocketClientSpotApi.cs index 2db17df..4982bd6 100644 --- a/Kraken.Net/Clients/SpotApi/KrakenSocketClientSpotApi.cs +++ b/Kraken.Net/Clients/SpotApi/KrakenSocketClientSpotApi.cs @@ -4,14 +4,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using CryptoExchange.Net; using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; using CryptoExchange.Net.Converters; +using CryptoExchange.Net.Converters.MessageParsing; using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Converters; using Kraken.Net.Enums; using Kraken.Net.ExtensionMethods; diff --git a/Kraken.Net/Kraken.Net.csproj b/Kraken.Net/Kraken.Net.csproj index 0f31c70..c1804c5 100644 --- a/Kraken.Net/Kraken.Net.csproj +++ b/Kraken.Net/Kraken.Net.csproj @@ -2,14 +2,14 @@ netstandard2.0;netstandard2.1 enable - 8.0 + 10.0 KrakenExchange.Net JKorf - 4.3.0 - 4.3.0 - 4.3.0 + 4.4.0 + 4.4.0 + 4.4.0 KrakenExchange.Net is a client library for accessing the Kraken REST and Websocket API. All data is mapped to readable models and enum values. Additional features include an implementation for maintaining a client side order book, easy integration with other exchange client libraries and more. false Kraken;KrakenExchange.Net;Kraken.Net;Kraken Client;Kraken API;CryptoCurrency;CryptoCurrency Exchange @@ -47,14 +47,14 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive + \ No newline at end of file diff --git a/Kraken.Net/Kraken.Net.xml b/Kraken.Net/Kraken.Net.xml index 0966eba..b94e7a7 100644 --- a/Kraken.Net/Kraken.Net.xml +++ b/Kraken.Net/Kraken.Net.xml @@ -22,7 +22,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -409,7 +409,7 @@ - + diff --git a/Kraken.Net/KrakenAuthenticationProvider.cs b/Kraken.Net/KrakenAuthenticationProvider.cs index 6586e81..c0fe2f8 100644 --- a/Kraken.Net/KrakenAuthenticationProvider.cs +++ b/Kraken.Net/KrakenAuthenticationProvider.cs @@ -4,8 +4,8 @@ using System.Net.Http; using System.Security.Cryptography; using System.Text; -using CryptoExchange.Net; using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Objects; using Kraken.Net.Objects; @@ -27,7 +27,7 @@ public KrakenAuthenticationProvider(ApiCredentials credentials, INonceProvider? _hmacSecret = Convert.FromBase64String(credentials.Secret!.GetString()); } - public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, Dictionary providedParameters, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, out SortedDictionary uriParameters, out SortedDictionary bodyParameters, out Dictionary headers) + public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, Dictionary providedParameters, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, RequestBodyFormat bodyFormat, out SortedDictionary uriParameters, out SortedDictionary bodyParameters, out Dictionary headers) { uriParameters = parameterPosition == HttpMethodParameterPosition.InUri ? new SortedDictionary(providedParameters, new KrakenParameterComparer()) : new SortedDictionary(); bodyParameters = parameterPosition == HttpMethodParameterPosition.InBody ? new SortedDictionary(providedParameters, new KrakenParameterComparer()) : new SortedDictionary(); diff --git a/Kraken.Net/KrakenFuturesAuthenticationProvider.cs b/Kraken.Net/KrakenFuturesAuthenticationProvider.cs index f836580..7f8f4a5 100644 --- a/Kraken.Net/KrakenFuturesAuthenticationProvider.cs +++ b/Kraken.Net/KrakenFuturesAuthenticationProvider.cs @@ -1,5 +1,5 @@ -using CryptoExchange.Net; -using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.Clients; using CryptoExchange.Net.Interfaces; using CryptoExchange.Net.Objects; using Kraken.Net.Objects; @@ -27,7 +27,7 @@ public KrakenFuturesAuthenticationProvider(ApiCredentials credentials, INoncePro _hmacSecret = Convert.FromBase64String(credentials.Secret!.GetString()); } - public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, Dictionary providedParameters, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, out SortedDictionary uriParameters, out SortedDictionary bodyParameters, out Dictionary headers) + public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, Dictionary providedParameters, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, RequestBodyFormat bodyFormat, out SortedDictionary uriParameters, out SortedDictionary bodyParameters, out Dictionary headers) { uriParameters = parameterPosition == HttpMethodParameterPosition.InUri ? new SortedDictionary(providedParameters) : new SortedDictionary(); bodyParameters = parameterPosition == HttpMethodParameterPosition.InBody ? new SortedDictionary(providedParameters) : new SortedDictionary(); diff --git a/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesAuthQuery.cs b/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesAuthQuery.cs index 71b3e93..2bece38 100644 --- a/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesAuthQuery.cs +++ b/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesAuthQuery.cs @@ -15,14 +15,14 @@ public KrakenFuturesAuthQuery(string apiKey) : base(new KrakenChallengeRequest { ListenerIdentifiers = new HashSet() { "challenge" }; } - public override Task> HandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) { // TODO test error? var authProvider = (KrakenFuturesAuthenticationProvider)connection.ApiClient.AuthenticationProvider!; var sign = authProvider.AuthenticateWebsocketChallenge(message.Data.Message); connection.Properties["OriginalChallenge"] = message.Data.Message; connection.Properties["SignedChallenge"] = sign; - return Task.FromResult(new CallResult(message.Data, message.OriginalData, null)); + return new CallResult(message.Data, message.OriginalData, null); } } } diff --git a/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesQuery.cs b/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesQuery.cs index 8c42e2a..f74cf7a 100644 --- a/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesQuery.cs +++ b/Kraken.Net/Objects/Sockets/Queries/KrakenFuturesQuery.cs @@ -28,12 +28,12 @@ public KrakenFuturesQuery(KrakenFuturesRequest request, bool authenticated) : ba } } - public override Task> HandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) { if (message.Data.Event == "alert") - return Task.FromResult(new CallResult(new ServerError(message.Data.Message!))); + return new CallResult(new ServerError(message.Data.Message!)); else - return Task.FromResult(new CallResult(message.Data!)); + return new CallResult(message.Data!); } } } diff --git a/Kraken.Net/Objects/Sockets/Queries/KrakenSpotQuery.cs b/Kraken.Net/Objects/Sockets/Queries/KrakenSpotQuery.cs index 0e4bf93..25e2d47 100644 --- a/Kraken.Net/Objects/Sockets/Queries/KrakenSpotQuery.cs +++ b/Kraken.Net/Objects/Sockets/Queries/KrakenSpotQuery.cs @@ -16,12 +16,12 @@ public KrakenSpotQuery(KrakenSocketRequest request, bool authenticated) : base(r ListenerIdentifiers = new HashSet() { request.RequestId.ToString() }; } - public override Task> HandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) { if (message.Data.Status != "error") - return Task.FromResult(new CallResult(message.Data!)); + return new CallResult(message.Data!); else - return Task.FromResult(new CallResult(new ServerError(message.Data.ErrorMessage!))); + return new CallResult(new ServerError(message.Data.ErrorMessage!)); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesAccountLogSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesAccountLogSubscription.cs index c265bbd..6f226ef 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesAccountLogSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesAccountLogSubscription.cs @@ -1,8 +1,7 @@ -using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Converters.MessageParsing; +using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -53,20 +52,20 @@ public KrakenFuturesAccountLogSubscription(ILogger logger, Action DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { if (message.Data is KrakenFuturesAccountLogsSnapshotUpdate snapshot) { _snapshotHandler.Invoke(message.As(snapshot, null, SocketUpdateType.Snapshot)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } else if (message.Data is KrakenFuturesAccountLogsUpdate update) { _updateHandler.Invoke(message.As(update, null, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } public override Type? GetMessageType(IMessageAccessor message) diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesBalanceSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesBalanceSubscription.cs index be29e78..a6ab1e2 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesBalanceSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesBalanceSubscription.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -48,11 +47,11 @@ public KrakenFuturesBalanceSubscription(ILogger logger, Action DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (KrakenFuturesBalancesUpdate)message.Data; _handler.Invoke(message.As(data, null, data.Feed == "balances_snapshot" ? SocketUpdateType.Snapshot : SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } public override Type? GetMessageType(IMessageAccessor message) => typeof(KrakenFuturesBalancesUpdate); diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesNotificationSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesNotificationSubscription.cs index e3e1346..2a67072 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesNotificationSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesNotificationSubscription.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -51,11 +50,11 @@ public KrakenFuturesNotificationSubscription(ILogger logger, Action typeof(KrakenFuturesNotificationUpdate); - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (KrakenFuturesNotificationUpdate)message.Data; _handler.Invoke(message.As(data, data.Feed, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOpenPositionsSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOpenPositionsSubscription.cs index dda1e29..0f1b4c3 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOpenPositionsSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOpenPositionsSubscription.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -48,10 +47,10 @@ public KrakenFuturesOpenPositionsSubscription(ILogger logger, Action typeof(KrakenFuturesOpenPositionUpdate); - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { _handler.Invoke(message.As((KrakenFuturesOpenPositionUpdate)message.Data, null, ConnectionInvocations == 1 ? SocketUpdateType.Snapshot : SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrderbookSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrderbookSubscription.cs index fa26ada..528fc09 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrderbookSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrderbookSubscription.cs @@ -1,8 +1,7 @@ -using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Converters.MessageParsing; +using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -65,20 +64,20 @@ public KrakenFuturesOrderbookSubscription(ILogger logger, List symbols, return typeof(KrakenFuturesBookUpdate); } - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { if (message.Data is KrakenFuturesBookSnapshotUpdate snapshot) { _snapshotHandler.Invoke(message.As(snapshot, snapshot.Symbol, SocketUpdateType.Snapshot)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } else if (message.Data is KrakenFuturesBookUpdate update) { _updateHandler.Invoke(message.As(update, update.Symbol, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrdersSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrdersSubscription.cs index e20ea9d..f4d070a 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrdersSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesOrdersSubscription.cs @@ -1,8 +1,7 @@ -using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Converters.MessageParsing; +using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -67,20 +66,20 @@ public KrakenFuturesOrdersSubscription(ILogger logger, bool verbose, Action DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { if (message.Data is KrakenFuturesOpenOrdersSnapshotUpdate snapshot) { _snapshotHandler.Invoke(message.As(snapshot, snapshot.Symbol, SocketUpdateType.Snapshot)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } else if (message.Data is KrakenFuturesOpenOrdersUpdate update) { _updateHandler.Invoke(message.As(update, update.Symbol, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesSubscription.cs index af9f314..6220053 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesSubscription.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; using System; @@ -54,11 +53,11 @@ public KrakenFuturesSubscription(ILogger logger, string feed, List? symb Authenticated); } - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (T)message.Data!; _handler.Invoke(message.As(data, data!.Symbol, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesTradesSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesTradesSubscription.cs index 9ec99de..bd709bf 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesTradesSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesTradesSubscription.cs @@ -1,8 +1,7 @@ -using CryptoExchange.Net.Objects; +using CryptoExchange.Net.Converters.MessageParsing; +using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -64,20 +63,20 @@ public KrakenFuturesTradesSubscription(ILogger logger, List symbols, Act return typeof(KrakenFuturesTradeUpdate); } - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { if (message.Data is KrakenFuturesTradesSnapshotUpdate snapshot) { _handler.Invoke(message.As(snapshot.Trades, snapshot.Symbol, SocketUpdateType.Snapshot)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } else if (message.Data is KrakenFuturesTradeUpdate update) { _handler.Invoke(message.As>(new[] { update }, update.Symbol, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesUserTradeSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesUserTradeSubscription.cs index 73f043a..75bc8d0 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesUserTradeSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Futures/KrakenFuturesUserTradeSubscription.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket.Futures; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -49,11 +48,11 @@ public KrakenFuturesUserTradeSubscription(ILogger logger, Action typeof(KrakenFuturesUserTradesUpdate); - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (KrakenFuturesUserTradesUpdate)message.Data; _handler.Invoke(message.As(data, null, data.Feed == "fills_snapshot" ? SocketUpdateType.Snapshot : SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/HeartbeatSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/HeartbeatSubscription.cs index 94176e6..86beb51 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/HeartbeatSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/HeartbeatSubscription.cs @@ -1,9 +1,5 @@ -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.Objects.Sockets; +using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using Microsoft.Extensions.Logging; -using System.Collections.Generic; -using System.Threading.Tasks; namespace Kraken.Net.Objects.Sockets.Subscriptions.Spot { @@ -15,6 +11,6 @@ public HeartbeatSubscription(ILogger logger) : base(logger, false) { } - public override Task HandleMessageAsync(SocketConnection connection, DataEvent message) => Task.FromResult(new CallResult(null)); + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) => new CallResult(null); } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenAutSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenAutSubscription.cs index eab3816..58c28c2 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenAutSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenAutSubscription.cs @@ -2,7 +2,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Internal; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -68,11 +67,11 @@ public override void HandleSubQueryResponse(KrakenSubscriptionEvent message) ListenerIdentifiers = new HashSet { message.ChannelName }; } - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (KrakenAuthSocketUpdate)message.Data!; _handler.Invoke(message.As(data, data.ChannelName, data.Sequence.Sequence == 1 ? SocketUpdateType.Snapshot : SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenBookSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenBookSubscription.cs index 9cfeec7..ccfb4d2 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenBookSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenBookSubscription.cs @@ -2,7 +2,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Converters; using Kraken.Net.Objects.Internal; using Kraken.Net.Objects.Models; @@ -56,9 +55,9 @@ public KrakenBookSubscription(ILogger logger, IEnumerable? symbols, int? Authenticated); } - public override object Deserialize(IMessageAccessor message, Type type) + public override CallResult Deserialize(IMessageAccessor message, Type type) { - return StreamOrderBookConverter.Convert((JArray)message.Underlying!)!; + return new CallResult(StreamOrderBookConverter.Convert((JArray)message.Underlying!)!); } public override void HandleSubQueryResponse(KrakenSubscriptionEvent message) @@ -66,11 +65,11 @@ public override void HandleSubQueryResponse(KrakenSubscriptionEvent message) ListenerIdentifiers = _symbols?.Any() == true ? new HashSet(_symbols.Select(s => message.ChannelName + "-" + s.ToLowerInvariant())) : new HashSet { message.ChannelName }; } - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (KrakenSocketUpdate)message.Data!; _handler.Invoke(message.As(data.Data, data.Symbol, data.Data.Snapshot ? SocketUpdateType.Snapshot : SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSubscription.cs index aef018a..281287e 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSubscription.cs @@ -2,7 +2,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Internal; using Kraken.Net.Objects.Sockets.Queries; using Microsoft.Extensions.Logging; @@ -85,11 +84,11 @@ public override void HandleSubQueryResponse(KrakenSubscriptionEvent message) ListenerIdentifiers = _symbols?.Any() == true ? new HashSet(_symbols.Select(s => message.ChannelName + "-" + GetSymbolTopic(s))) : new HashSet { message.ChannelName }; } - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { var data = (KrakenSocketUpdate)message.Data!; _handler.Invoke(message.As(data.Data, data.Symbol, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } } diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSystemStatusSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSystemStatusSubscription.cs index 077cae5..d19749c 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSystemStatusSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/KrakenSystemStatusSubscription.cs @@ -1,7 +1,6 @@ using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Sockets; using CryptoExchange.Net.Sockets; -using CryptoExchange.Net.Sockets.MessageParsing.Interfaces; using Kraken.Net.Objects.Models.Socket; using Microsoft.Extensions.Logging; using System; @@ -25,10 +24,10 @@ public KrakenSystemStatusSubscription(ILogger logger, Action null; - public override Task DoHandleMessageAsync(SocketConnection connection, DataEvent message) + public override CallResult DoHandleMessage(SocketConnection connection, DataEvent message) { _handler.Invoke(message.As((KrakenStreamSystemStatus)message.Data!, null, SocketUpdateType.Update)); - return Task.FromResult(new CallResult(null)); + return new CallResult(null); } public override Type? GetMessageType(IMessageAccessor message) => typeof(KrakenStreamSystemStatus); diff --git a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/SystemStatusSubscription.cs b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/SystemStatusSubscription.cs index 164d673..721c26e 100644 --- a/Kraken.Net/Objects/Sockets/Subscriptions/Spot/SystemStatusSubscription.cs +++ b/Kraken.Net/Objects/Sockets/Subscriptions/Spot/SystemStatusSubscription.cs @@ -16,6 +16,6 @@ public SystemStatusSubscription(ILogger logger) : base(logger, false) { } - public override Task HandleMessageAsync(SocketConnection connection, DataEvent message) => Task.FromResult(new CallResult(null)); // TODO + public override CallResult HandleMessage(SocketConnection connection, DataEvent message) => new CallResult(null); // TODO } } diff --git a/Kraken.Net/Usings.cs b/Kraken.Net/Usings.cs new file mode 100644 index 0000000..d7109a0 --- /dev/null +++ b/Kraken.Net/Usings.cs @@ -0,0 +1,17 @@ +global using CryptoExchange.Net; +global using CryptoExchange.Net.Authentication; +global using CryptoExchange.Net.Converters.JsonNet; +global using CryptoExchange.Net.Interfaces; +global using CryptoExchange.Net.Objects; +global using Microsoft.Extensions.Logging; +global using Newtonsoft.Json; +global using Newtonsoft.Json.Linq; +global using Newtonsoft.Json.Serialization; +global using System; +global using System.Collections.Generic; +global using System.Globalization; +global using System.Linq; +global using System.Net.Http; +global using System.Security; +global using System.Threading; +global using System.Threading.Tasks; \ No newline at end of file diff --git a/README.md b/README.md index 0f6a0e4..3ce5c17 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,10 @@ Make a one time donation in a crypto currency of your choice. If you prefer to d Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf). ## Release notes +* Version 4.4.0 - 16 Mar 2024 + * Updated CryptoExchange.Net to 7.1.0, see https://github.com/JKorf/CryptoExchange.Net?tab=readme-ov-file#release-notes for release notes + * Updated unit test package dependencies and updated tests accordingly + * Version 4.3.0 - 25 Feb 2024 * Updated CryptoExchange.Net and implemented reworked websocket message handling. For release notes for the CryptoExchange.Net base library see: https://github.com/JKorf/CryptoExchange.Net?tab=readme-ov-file#release-notes * Fixed issue in DI registration causing http client to not be correctly injected