Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add minFunds property #167

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public async Task<WebCallResult<KucoinWithdrawalQuota>> GetWithdrawalQuotasAsync
}

/// <inheritdoc />
public async Task<WebCallResult<KucoinNewWithdrawal>> WithdrawAsync(string asset, string toAddress, decimal quantity, string? memo = null, bool isInner = false, string? remark = null, string? network = null, FeeDeductType? deductType = null, CancellationToken ct = default)
public async Task<WebCallResult<KucoinNewWithdrawal>> WithdrawAsync(string asset, string toAddress, decimal quantity, string? memo = null, bool? isInner = null, string? remark = null, string? network = null, FeeDeductType? deductType = null, CancellationToken ct = default)
{
asset.ValidateNotNull(nameof(asset));
toAddress.ValidateNotNull(nameof(toAddress));
Expand Down
75 changes: 75 additions & 0 deletions Kucoin.Net/Clients/SpotApi/KucoinRestClientSpotApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -436,6 +437,80 @@ public async Task<WebCallResult<IEnumerable<KucoinStopOrder>>> GetStopOrderByCli
return await _baseClient.Execute<KucoinNewBorrowOrder>(_baseClient.GetUri("margin/borrow"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}


/// <inheritdoc />
public async Task<WebCallResult<KucoinNewBorrow>> MarginBorrowAsync(string asset, decimal quantity, BorrowOrderType type, bool? isIsolated, string? symbol = null, CancellationToken ct = default)
{
var parameters = new Dictionary<string, object>
{
{ "currency", asset },
{ "size", quantity },
{ "timeInForce", JsonConvert.SerializeObject(type, new BorrowOrderTypeConverter(false)) }
};
parameters.AddOptionalParameter("isIsolated", isIsolated);
parameters.AddOptionalParameter("symbol", symbol);
return await _baseClient.Execute<KucoinNewBorrow>(_baseClient.GetUri("margin/borrow", 3), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

}


/// <inheritdoc />
public async Task<WebCallResult<KucoinNewRepay>> MarginRepayAsync(string asset, decimal quantity, bool? isIsolated, string? symbol = null, CancellationToken ct = default)
{
var parameters = new Dictionary<string, object>
{
{ "currency", asset },
{ "size", quantity }
};
parameters.AddOptionalParameter("isIsolated", isIsolated);
parameters.AddOptionalParameter("symbol", symbol);
return await _baseClient.Execute<KucoinNewRepay>(_baseClient.GetUri("margin/repay", 3), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);
}


/// <inheritdoc />
public async Task<WebCallResult<KucoinPaginated<MarginBorrowHistory>>> MarginBorrowHistoryAsync(string asset, bool? isIsolated, string? symbol = null, string? Id = null, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, CancellationToken ct = default)
{

var parameters = new Dictionary<string, object>
{
{ "currency", asset },
};

parameters.AddOptionalParameter("isIsolated", isIsolated);
parameters.AddOptionalParameter("symbol", symbol);
parameters.AddOptionalParameter("orderNo", Id);
parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime));
parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime));
parameters.AddOptionalParameter("currentPage", page);
parameters.AddOptionalParameter("pageSize", pageSize);

return await _baseClient.Execute<KucoinPaginated<MarginBorrowHistory>>(_baseClient.GetUri("margin/borrow", 3), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

}

/// <inheritdoc />
public async Task<WebCallResult<KucoinPaginated<MarginRepayHistory>>> MarginRepayHistoryAsync(string asset, bool? isIsolated, string? symbol = null, string? Id = null, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, CancellationToken ct = default)
{

var parameters = new Dictionary<string, object>
{
{ "currency", asset },
};

parameters.AddOptionalParameter("isIsolated", isIsolated);
parameters.AddOptionalParameter("symbol", symbol);
parameters.AddOptionalParameter("orderNo", Id);
parameters.AddOptionalParameter("startTime", DateTimeConverter.ConvertToMilliseconds(startTime));
parameters.AddOptionalParameter("endTime", DateTimeConverter.ConvertToMilliseconds(endTime));
parameters.AddOptionalParameter("currentPage", page);
parameters.AddOptionalParameter("pageSize", pageSize);

return await _baseClient.Execute<KucoinPaginated<MarginRepayHistory>>(_baseClient.GetUri("margin/repay", 3), HttpMethod.Get, ct, parameters, true).ConfigureAwait(false);

}


/// <inheritdoc />
public async Task<WebCallResult<KucoinBorrowOrder>> GetBorrowOrderAsync(string orderId, CancellationToken ct = default)
{
Expand Down
33 changes: 32 additions & 1 deletion Kucoin.Net/Clients/SpotApi/KucoinSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
using Kucoin.Net.Objects.Models.Spot.Socket;
using CryptoExchange.Net.Authentication;
using Kucoin.Net.Interfaces.Clients.SpotApi;
using CryptoExchange.Net.CommonObjects;
using System.Linq;
using Kucoin.Net.Objects.Options;
using System.Net.Http;
using System.Net;

namespace Kucoin.Net.Clients.SpotApi
{
Expand Down Expand Up @@ -171,6 +174,22 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToKlineUpdatesAsync(s
Action<DataEvent<KucoinStreamOrderBookChanged>> onData, CancellationToken ct = default) =>
SubscribeToOrderBookUpdatesAsync(new[] { symbol }, limit, onData, ct);

/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int symbolPrecision, Action<DataEvent<KucoinStreamOrderBookChanged>> onData, CancellationToken ct = default)
{
symbol.ValidateKucoinSymbol();
limit.ValidateIntValues(nameof(limit), 5, 50);

var innerHandler = new Action<DataEvent<JToken>>(tokenData =>
{
var book = GetData<KucoinStreamOrderBookChanged>(tokenData);
InvokeHandler(tokenData.As(book, TryGetSymbolFromTopic(tokenData)), onData);
});

var request = new KucoinRequest(ExchangeHelpers.NextId().ToString(CultureInfo.InvariantCulture), "subscribe", $"/spotMarket/level2Depth{limit}:" + symbol + "_" + symbolPrecision, false);
return await SubscribeAsync("spot", request, null, false, innerHandler, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsync(IEnumerable<string> symbols, int limit, Action<DataEvent<KucoinStreamOrderBookChanged>> onData, CancellationToken ct = default)
{
Expand Down Expand Up @@ -359,8 +378,20 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToStopOrderUpdatesAsy
/// <inheritdoc />
protected override async Task<CallResult<string?>> GetConnectionUrlAsync(string address, bool authenticated)
{

var apiCredentials = (KucoinApiCredentials?)(ApiOptions.ApiCredentials ?? _baseClient.ClientOptions.ApiCredentials);
using (var restClient = new KucoinRestClient((options) =>

HttpClient httpClient = new HttpClient();
if (_baseClient.ClientOptions?.Proxy != null)
{
httpClient = new HttpClient(new HttpClientHandler()
{
Proxy = new WebProxy(_baseClient.ClientOptions.Proxy.Host, _baseClient.ClientOptions.Proxy.Port)
});

}

using (var restClient = new KucoinRestClient(httpClient, null, (options) =>
{
options.ApiCredentials = apiCredentials;
options.Environment = ClientOptions.Environment;
Expand Down
13 changes: 13 additions & 0 deletions Kucoin.Net/Converters/BorrowStatusConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@ internal class BorrowStatusConverter : BaseConverter<BorrowStatus>
new KeyValuePair<BorrowStatus, string>(BorrowStatus.Done, "Done"),
};
}

internal class RepayStatusConverter : BaseConverter<RepayStatus>
{
public RepayStatusConverter() : this(true) { }
public RepayStatusConverter(bool quotes) : base(quotes) { }
protected override List<KeyValuePair<RepayStatus, string>> Mapping => new List<KeyValuePair<RepayStatus, string>>
{
new KeyValuePair<RepayStatus, string>(RepayStatus.Repaying, "Repaying"),
new KeyValuePair<RepayStatus, string>(RepayStatus.Completed, "Completed"),
new KeyValuePair<RepayStatus, string>(RepayStatus.Failed, "Failed"),

};
}
}
11 changes: 11 additions & 0 deletions Kucoin.Net/Enums/BorrowStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ public enum BorrowStatus
/// </summary>
Done
}

public enum RepayStatus
{

Repaying,

Completed,

Failed

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public interface IKucoinRestClientSpotApiAccount
/// <param name="feeDeductType">Fee deduction type</param>
/// <param name="ct">Cancellation token</param>
/// <returns>Id of the withdrawal</returns>
Task<WebCallResult<KucoinNewWithdrawal>> WithdrawAsync(string asset, string toAddress, decimal quantity, string? memo = null, bool isInner = false, string? remark = null, string? chain = null, FeeDeductType? feeDeductType = null, CancellationToken ct = default);
Task<WebCallResult<KucoinNewWithdrawal>> WithdrawAsync(string asset, string toAddress, decimal quantity, string? memo = null, bool? isInner = null, string? remark = null, string? chain = null, FeeDeductType? feeDeductType = null, CancellationToken ct = default);

/// <summary>
/// Cancel a withdrawal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,5 +558,9 @@ public interface IKucoinRestClientSpotApiTrading
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult> RepaySingleIsolatedBorrowOrderAsync(string symbol, string asset, decimal quantity, string loanId, CancellationToken ct = default);
Task<WebCallResult<KucoinNewBorrow>> MarginBorrowAsync(string asset, decimal quantity, BorrowOrderType type, bool? isIsolated, string? symbol, CancellationToken ct = default);
Task<WebCallResult<KucoinNewRepay>> MarginRepayAsync(string asset, decimal quantity, bool? isIsolated, string? symbol = null, CancellationToken ct = default);
Task<WebCallResult<KucoinPaginated<MarginBorrowHistory>>> MarginBorrowHistoryAsync(string asset, bool? isIsolated, string? symbol = null, string? Id = null, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, CancellationToken ct = default);
Task<WebCallResult<KucoinPaginated<MarginRepayHistory>>> MarginRepayHistoryAsync(string asset, bool? isIsolated, string? symbol = null, string? Id = null, DateTime? startTime = null, DateTime? endTime = null, int? page = null, int? pageSize = null, CancellationToken ct = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ public interface IKucoinSocketClientSpotApi : ISocketApiClient, IDisposable
Task<CallResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsync(string symbol, int limit,
Action<DataEvent<KucoinStreamOrderBookChanged>> onData, CancellationToken ct = default);

/// <summary>
/// Subscribe to full order book updates
/// <para><a href="https://docs.kucoin.com/#level2-5-best-ask-bid-orders" /></para>
/// <para><a href="https://docs.kucoin.com/#level2-50-best-ask-bid-orders" /></para>
/// </summary>
/// <param name="symbol">The symbol to subscribe</param>
/// <param name="limit">The amount of levels to receive, either 5 or 50</param>
/// <param name="onData">Data handler</param>
/// <param name="ct">Cancellation token for closing this subscription</param>
/// <returns>A stream subscription. This stream subscription can be used to be notified when the socket is disconnected/reconnected and to unsubscribe</returns>
Task<CallResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int symbolPrecision, Action<DataEvent<KucoinStreamOrderBookChanged>> onData, CancellationToken ct = default);


/// <summary>
/// Subscribe to full order book updates
/// <para><a href="https://docs.kucoin.com/#level2-5-best-ask-bid-orders" /></para>
Expand Down
5 changes: 3 additions & 2 deletions Kucoin.Net/Kucoin.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<PackageId>Kucoin.Net</PackageId>
<Authors>JKorf</Authors>
<PackageId>Septa.Kucoin.Net</PackageId>
<Authors>majidbigdeli</Authors>
<PackageVersion>5.0.7</PackageVersion>
<AssemblyVersion>5.0.7</AssemblyVersion>
<FileVersion>5.0.7</FileVersion>
Expand Down Expand Up @@ -55,4 +55,5 @@
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="6.2.0" />
</ItemGroup>

</Project>
Loading