1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 00:46:19 +00:00

Added UTC converter, added UTC DateTimeZoneHandling

This commit is contained in:
JKorf 2018-06-08 13:33:50 +02:00
parent 45ede8b06a
commit 1fcb15472f
2 changed files with 32 additions and 1 deletions

View File

@ -0,0 +1,26 @@
using System;
using Newtonsoft.Json;
namespace CryptoExchange.Net.Converters
{
public class UTCDateTimeConverter: JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(JsonConvert.SerializeObject(value));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.Value == null)
return null;
return DateTime.SpecifyKind((DateTime)reader.Value, DateTimeKind.Utc);
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(DateTime) || objectType == typeof(DateTime?);
}
}
}

View File

@ -25,6 +25,11 @@ namespace CryptoExchange.Net
protected AuthenticationProvider authProvider;
private List<IRateLimiter> rateLimiters;
private static JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc
});
protected ExchangeClient(ExchangeOptions exchangeOptions, AuthenticationProvider authenticationProvider)
{
log = new Log();
@ -208,7 +213,7 @@ namespace CryptoExchange.Net
}
}
return new CallResult<T>(obj.ToObject<T>(), null);
return new CallResult<T>(obj.ToObject<T>(serializer), null);
}
catch (JsonReaderException jre)
{