From f3634ea289dbc163d6f5b327097f1e7a1e77be62 Mon Sep 17 00:00:00 2001 From: JKorf Date: Tue, 27 Mar 2018 09:38:11 +0200 Subject: [PATCH] Made ExecuteRequest virtual, added TimestampSecondsConverter --- CryptoExchange.Net/ApiProxy.cs | 5 ++++ ...kenArrayConverter.cs => ArrayConverter.cs} | 2 +- .../Converters/TimestampSecondsConverter.cs | 26 +++++++++++++++++++ CryptoExchange.Net/CryptoExchange.Net.csproj | 2 +- CryptoExchange.Net/ExchangeClient.cs | 2 +- .../Implementation/BaseSocket.cs | 1 - 6 files changed, 34 insertions(+), 4 deletions(-) rename CryptoExchange.Net/Converters/{KrakenArrayConverter.cs => ArrayConverter.cs} (97%) create mode 100644 CryptoExchange.Net/Converters/TimestampSecondsConverter.cs diff --git a/CryptoExchange.Net/ApiProxy.cs b/CryptoExchange.Net/ApiProxy.cs index f84f86a..9152d64 100644 --- a/CryptoExchange.Net/ApiProxy.cs +++ b/CryptoExchange.Net/ApiProxy.cs @@ -13,6 +13,11 @@ namespace CryptoExchange.Net /// public int Port { get; } + /// + /// Create new settings for a proxy + /// + /// The proxy hostname/ip + /// The proxy port public ApiProxy(string host, int port) { if(string.IsNullOrEmpty(host) || port <= 0) diff --git a/CryptoExchange.Net/Converters/KrakenArrayConverter.cs b/CryptoExchange.Net/Converters/ArrayConverter.cs similarity index 97% rename from CryptoExchange.Net/Converters/KrakenArrayConverter.cs rename to CryptoExchange.Net/Converters/ArrayConverter.cs index 1718c95..b0d9bd0 100644 --- a/CryptoExchange.Net/Converters/KrakenArrayConverter.cs +++ b/CryptoExchange.Net/Converters/ArrayConverter.cs @@ -9,7 +9,7 @@ namespace CryptoExchange.Net.Converters { public override bool CanConvert(Type objectType) { - throw new NotImplementedException(); + return true; } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) diff --git a/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs b/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs new file mode 100644 index 0000000..6fff4d5 --- /dev/null +++ b/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace CryptoExchange.Net.Converters +{ + public class TimestampSecondsConverter : JsonConverter + { + public override bool CanConvert(Type objectType) + { + return objectType == typeof(DateTime); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var t = long.Parse(reader.Value.ToString()); + return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(t); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + writer.WriteValue(Math.Round((((DateTime)value) - new DateTime(1970, 1, 1)).TotalSeconds)); + } + } +} diff --git a/CryptoExchange.Net/CryptoExchange.Net.csproj b/CryptoExchange.Net/CryptoExchange.Net.csproj index 283ab1d..ae8699a 100644 --- a/CryptoExchange.Net/CryptoExchange.Net.csproj +++ b/CryptoExchange.Net/CryptoExchange.Net.csproj @@ -7,7 +7,7 @@ CryptoExchange.Net JKorf - 0.0.15 + 0.0.16 false https://github.com/JKorf/CryptoExchange.Net https://github.com/JKorf/CryptoExchange.Net/blob/master/LICENSE diff --git a/CryptoExchange.Net/ExchangeClient.cs b/CryptoExchange.Net/ExchangeClient.cs index 42893c8..72faf0d 100644 --- a/CryptoExchange.Net/ExchangeClient.cs +++ b/CryptoExchange.Net/ExchangeClient.cs @@ -77,7 +77,7 @@ namespace CryptoExchange.Net authProvider = authentictationProvider; } - protected async Task> ExecuteRequest(Uri uri, string method = "GET", Dictionary parameters = null, bool signed = false) where T : class + protected virtual async Task> ExecuteRequest(Uri uri, string method = "GET", Dictionary parameters = null, bool signed = false) where T : class { if(signed && authProvider == null) return new CallResult(null, new NoApiCredentialsError()); diff --git a/CryptoExchange.Net/Implementation/BaseSocket.cs b/CryptoExchange.Net/Implementation/BaseSocket.cs index ba9e0de..50f9df1 100644 --- a/CryptoExchange.Net/Implementation/BaseSocket.cs +++ b/CryptoExchange.Net/Implementation/BaseSocket.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Net; using System.Security.Authentication;