Skip to content

Commit

Permalink
Merge branch 'master' into feature/rate-limit-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Apr 17, 2024
2 parents 180a106 + f87758c commit 949bd0c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Kucoin.Net/Clients/SpotApi/KucoinRestClientSpotApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public async Task<WebCallResult<KucoinNewMarginOrder>> PlaceMarginOrderAsync(
string? remark = null,
MarginMode? marginMode = null,
bool? autoBorrow = null,
bool? autoRepay = null,
SelfTradePrevention? selfTradePrevention = null,
string? clientOrderId = null,
CancellationToken ct = default)
Expand Down Expand Up @@ -193,6 +194,7 @@ public async Task<WebCallResult<KucoinNewMarginOrder>> PlaceMarginOrderAsync(
parameters.AddOptionalParameter("remark", remark);
parameters.AddOptionalParameter("marginMode", marginMode.HasValue ? JsonConvert.SerializeObject(marginMode.Value, new MarginModeConverter(false)) : null);
parameters.AddOptionalParameter("autoBorrow", autoBorrow);
parameters.AddOptionalParameter("autoRepay", autoRepay);
parameters.AddOptionalParameter("stp", selfTradePrevention.HasValue ? JsonConvert.SerializeObject(selfTradePrevention.Value, new SelfTradePreventionConverter(false)) : null);
var request = _definitions.GetOrCreate(HttpMethod.Post, $"api/v1/margin/order", KucoinExchange.RateLimiter.SpotRest, 5, true);
return await _baseClient.SendAsync<KucoinNewMarginOrder>(request, parameters, ct).ConfigureAwait(false);
Expand All @@ -215,6 +217,7 @@ public async Task<WebCallResult<KucoinNewMarginOrder>> PlaceTestMarginOrderAsync
string? remark = null,
MarginMode? marginMode = null,
bool? autoBorrow = null,
bool? autoRepay = null,
SelfTradePrevention? selfTradePrevention = null,
string? clientOrderId = null,
CancellationToken ct = default)
Expand Down Expand Up @@ -251,6 +254,7 @@ public async Task<WebCallResult<KucoinNewMarginOrder>> PlaceTestMarginOrderAsync
parameters.AddOptionalParameter("remark", remark);
parameters.AddOptionalParameter("marginMode", marginMode.HasValue ? JsonConvert.SerializeObject(marginMode.Value, new MarginModeConverter(false)) : null);
parameters.AddOptionalParameter("autoBorrow", autoBorrow);
parameters.AddOptionalParameter("autoRepay", autoRepay);
parameters.AddOptionalParameter("stp", selfTradePrevention.HasValue ? JsonConvert.SerializeObject(selfTradePrevention.Value, new SelfTradePreventionConverter(false)) : null);
var request = _definitions.GetOrCreate(HttpMethod.Post, $"api/v1/margin/order/test", KucoinExchange.RateLimiter.SpotRest, 5, true);
return await _baseClient.SendAsync<KucoinNewMarginOrder>(request, parameters, ct).ConfigureAwait(false);
Expand Down
41 changes: 41 additions & 0 deletions Kucoin.Net/Converters/NextFundingRateTimeConverter.cs
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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Task<WebCallResult<KucoinNewOrder>> PlaceTestOrderAsync(
/// <param name="selfTradePrevention">Self trade prevention setting</param>
/// <param name="marginMode">The type of trading, including 'cross' and 'isolated'</param>
/// <param name="autoBorrow">Auto-borrow to place order.</param>
/// <param name="autoRepay">Auto-repay to place order.</param>
/// <param name="price">The price of the order. Only valid for limit orders.</param>
/// <param name="quantity">Quantity of base asset to buy or sell of the order</param>
/// <param name="timeInForce">The time the order is in force</param>
Expand Down Expand Up @@ -131,6 +132,7 @@ Task<WebCallResult<KucoinNewMarginOrder>> PlaceMarginOrderAsync(
string? remark = null,
MarginMode? marginMode = null,
bool? autoBorrow = null,
bool? autoRepay = null,
SelfTradePrevention? selfTradePrevention = null,
string? clientOrderId = null,
CancellationToken ct = default);
Expand All @@ -147,6 +149,7 @@ Task<WebCallResult<KucoinNewMarginOrder>> PlaceMarginOrderAsync(
/// <param name="selfTradePrevention">Self trade prevention setting</param>
/// <param name="marginMode">The type of trading, including 'cross' and 'isolated'</param>
/// <param name="autoBorrow">Auto-borrow to place order.</param>
/// <param name="autoRepay">Auto-repay to place order.</param>
/// <param name="price">The price of the order. Only valid for limit orders.</param>
/// <param name="quantity">Quantity of base asset to buy or sell of the order</param>
/// <param name="timeInForce">The time the order is in force</param>
Expand Down Expand Up @@ -174,6 +177,7 @@ Task<WebCallResult<KucoinNewMarginOrder>> PlaceTestMarginOrderAsync(
string? remark = null,
MarginMode? marginMode = null,
bool? autoBorrow = null,
bool? autoRepay = null,
SelfTradePrevention? selfTradePrevention = null,
string? clientOrderId = null,
CancellationToken ct = default);
Expand Down
21 changes: 16 additions & 5 deletions Kucoin.Net/Kucoin.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Kucoin.Net/Objects/Models/Futures/KucoinContract.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using CryptoExchange.Net.Converters;
using Kucoin.Net.Converters;
using Newtonsoft.Json;

namespace Kucoin.Net.Objects.Models.Futures
Expand Down Expand Up @@ -206,9 +207,11 @@ public class KucoinContract
/// </summary>
public decimal? PredictedFundingFeeRate { get; set; }
/// <summary>
/// Next funding rate time
/// Next funding rate time. This time may not be accurate up to a couple of seconds.
/// This is due to the fact that the API returns this value as an offset from the current time,
/// but we have no way of knowing the exact time the API returned this value.
/// </summary>
[JsonConverter(typeof(DateTimeConverter))]
[JsonConverter(typeof(NextFundingRateTimeConverter))]
public DateTime? NextFundingRateTime { get; set; }
/// <summary>
/// Source exchanges
Expand Down Expand Up @@ -243,4 +246,4 @@ public class KucoinContract
/// </summary>
public string? FundingQuoteSymbol1M { get; set; }
}
}
}

0 comments on commit 949bd0c

Please sign in to comment.