-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a custom NextFundingRateConverter that adds the offset to the c…
…urrent time instead (#212)
- Loading branch information
Showing
3 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Kucoin.Net.Converters | ||
{ | ||
/// <summary> | ||
/// Does basically the same thing as the shared DateTimeConverter, with a slight difference. | ||
/// Instead of adding the time to Jan 01 1970, it adds it to the current time. This isn't ideal since | ||
/// it produces inaccuracies, but it's the format the kucoin api returns for the next funding rate time. | ||
/// </summary> | ||
internal class NextFundingRateTimeConverter : JsonConverter<DateTime?> | ||
{ | ||
public override DateTime? ReadJson( | ||
JsonReader reader, | ||
Type objectType, | ||
DateTime? existingValue, | ||
bool hasExistingValue, | ||
JsonSerializer serializer | ||
) | ||
{ | ||
if (reader.Value == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var value = (long)reader.Value; | ||
var now = DateTime.UtcNow; | ||
var offset = TimeSpan.FromMilliseconds(value); | ||
return now + offset; | ||
} | ||
|
||
public override void WriteJson( | ||
JsonWriter writer, | ||
DateTime? value, | ||
JsonSerializer serializer | ||
) | ||
{ | ||
throw new NotSupportedException("This converter only supports reading"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters