From ce63ef680a961bf002d4e30979276ebca3acb0b1 Mon Sep 17 00:00:00 2001 From: Alex1911 Date: Wed, 28 Aug 2024 15:00:30 +0800 Subject: [PATCH] Copy trading endpoints (#1412) --- Binance.Net/Binance.Net.xml | 82 ++++++++++++++++++- .../GeneralApi/BinanceRestClientGeneralApi.cs | 3 + .../BinanceRestClientGeneralApiCopyTrading.cs | 51 ++++++++++++ .../IBinanceRestClientGeneralApi.cs | 5 ++ ...IBinanceRestClientGeneralApiCopyTrading.cs | 30 +++++++ .../BinanceCopyTradingLeadSymbol.cs | 24 ++++++ .../BinanceCopyTradingUserStatus.cs | 19 +++++ 7 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApiCopyTrading.cs create mode 100644 Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApiCopyTrading.cs create mode 100644 Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingLeadSymbol.cs create mode 100644 Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingUserStatus.cs diff --git a/Binance.Net/Binance.Net.xml b/Binance.Net/Binance.Net.xml index d4ec565c2..753018a5c 100644 --- a/Binance.Net/Binance.Net.xml +++ b/Binance.Net/Binance.Net.xml @@ -616,6 +616,9 @@ + + + @@ -742,6 +745,12 @@ + + + + + + @@ -1109,7 +1118,7 @@ - + @@ -6272,6 +6281,11 @@ Endpoints related to Binance Simple Earn + + + Endpoints related to Binance Copy Trading + + Binance brokerage endpoints. @@ -6725,6 +6739,29 @@ Cancellation token Asset info + + + Binance copy trading endpoints + + + + + Get Futures Lead Trader Status + + + The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + Cancellation token + + + + + Get Futures Lead Trading Symbol Whitelist + + + The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + Cancellation token + + Binance futures interaction endpoints @@ -8276,7 +8313,7 @@ Cancellation token - + Gets the deposit history @@ -8288,6 +8325,7 @@ Filter start time from Filter end time till The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + Include source address to response Cancellation token List of deposits @@ -14749,6 +14787,11 @@ The wallet type + + + Transaction source address. Note: Please note that the source address returned may not be accurate due to network-specific characteristics. If multiple source addresses found, only the first address will be returned + + Dividend record @@ -18915,6 +18958,41 @@ Creation time + + + Copy trading lead symbol + + + + + Symbol + + + + + Base asset + + + + + Quote asset + + + + + Copy trading user status + + + + + Is lead trader + + + + + Time + + Isolated margin symbol info diff --git a/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApi.cs b/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApi.cs index bb8fae1a9..054c109c2 100644 --- a/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApi.cs +++ b/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApi.cs @@ -35,6 +35,8 @@ internal class BinanceRestClientGeneralApi : RestApiClient, IBinanceRestClientGe public IBinanceRestClientGeneralApiStaking Staking { get; } /// public IBinanceRestClientGeneralApiSimpleEarn SimpleEarn { get; } + /// + public IBinanceRestClientGeneralApiCopyTrading CopyTrading { get; } #endregion #region constructor/destructor @@ -51,6 +53,7 @@ internal BinanceRestClientGeneralApi(ILogger logger, HttpClient? httpClient, Bin SubAccount = new BinanceRestClientGeneralApiSubAccount(this); Staking = new BinanceRestClientGeneralApiStaking(this); SimpleEarn = new BinanceRestClientGeneralApiSimpleEarn(this); + CopyTrading = new BinanceRestClientGeneralApiCopyTrading(this); RequestBodyEmptyContent = ""; RequestBodyFormat = RequestBodyFormat.FormData; diff --git a/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApiCopyTrading.cs b/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApiCopyTrading.cs new file mode 100644 index 000000000..b345dd8ff --- /dev/null +++ b/Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApiCopyTrading.cs @@ -0,0 +1,51 @@ +using Binance.Net.Interfaces.Clients.GeneralApi; +using Binance.Net.Objects.Models; +using Binance.Net.Objects.Models.Spot.CopyTrading; + +namespace Binance.Net.Clients.GeneralApi +{ + internal class BinanceRestClientGeneralApiCopyTrading : IBinanceRestClientGeneralApiCopyTrading + { + private static readonly RequestDefinitionCache _definitions = new RequestDefinitionCache(); + + private readonly BinanceRestClientGeneralApi _baseClient; + + internal BinanceRestClientGeneralApiCopyTrading(BinanceRestClientGeneralApi baseClient) + { + _baseClient = baseClient; + } + + #region Get User Status + + /// + public async Task> GetUserStatusAsync(long? receiveWindow = null, CancellationToken ct = default) + { + var parameters = new ParameterCollection(); + parameters.AddOptionalString("recvWindow", receiveWindow ?? (long)_baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds); + + var request = _definitions.GetOrCreate(HttpMethod.Get, "sapi/v1/copyTrading/futures/userStatus", BinanceExchange.RateLimiter.SpotRestUid, 20, true); + var data = await _baseClient.SendAsync>(request, parameters, ct).ConfigureAwait(false); + + return data.As(data.Data.Data); + } + + #endregion + + #region Get Lead Symbol + + /// + public async Task>> GetLeadSymbolAsync(long? receiveWindow = null, CancellationToken ct = default) + { + var parameters = new ParameterCollection(); + parameters.AddOptionalString("recvWindow", receiveWindow ?? (long)_baseClient.ClientOptions.ReceiveWindow.TotalMilliseconds); + + var request = _definitions.GetOrCreate(HttpMethod.Get, "sapi/v1/copyTrading/futures/leadSymbol", BinanceExchange.RateLimiter.SpotRestUid, 20, true); + var data = await _baseClient.SendAsync>>(request, parameters, ct).ConfigureAwait(false); + + return data.As(data.Data.Data); + } + + #endregion + + } +} diff --git a/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApi.cs b/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApi.cs index 6ecfc5488..7a0a682bb 100644 --- a/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApi.cs +++ b/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApi.cs @@ -39,5 +39,10 @@ public interface IBinanceRestClientGeneralApi : IRestApiClient, IDisposable /// Endpoints related to Binance Simple Earn /// IBinanceRestClientGeneralApiSimpleEarn SimpleEarn { get; } + + /// + /// Endpoints related to Binance Copy Trading + /// + IBinanceRestClientGeneralApiCopyTrading CopyTrading { get; } } } diff --git a/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApiCopyTrading.cs b/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApiCopyTrading.cs new file mode 100644 index 000000000..7426db0d1 --- /dev/null +++ b/Binance.Net/Interfaces/Clients/GeneralApi/IBinanceRestClientGeneralApiCopyTrading.cs @@ -0,0 +1,30 @@ +using Binance.Net.Objects.Internal; +using Binance.Net.Objects.Models.Spot.CopyTrading; + +namespace Binance.Net.Interfaces.Clients.GeneralApi +{ + /// + /// Binance copy trading endpoints + /// + public interface IBinanceRestClientGeneralApiCopyTrading + { + /// + /// Get Futures Lead Trader Status + /// + /// + /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + /// Cancellation token + /// + Task> GetUserStatusAsync(long? receiveWindow = null, CancellationToken ct = default); + + + /// + /// Get Futures Lead Trading Symbol Whitelist + /// + /// + /// The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request + /// Cancellation token + /// + Task>> GetLeadSymbolAsync(long? receiveWindow = null, CancellationToken ct = default); + } +} diff --git a/Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingLeadSymbol.cs b/Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingLeadSymbol.cs new file mode 100644 index 000000000..c7ab1496a --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingLeadSymbol.cs @@ -0,0 +1,24 @@ +namespace Binance.Net.Objects.Models.Spot.CopyTrading +{ + /// + /// Copy trading lead symbol + /// + public record BinanceCopyTradingLeadSymbol + { + /// + /// Symbol + /// + [JsonPropertyName("symbol")] + public string Symbol { get; set; } = string.Empty; + /// + /// Base asset + /// + [JsonPropertyName("baseAsset")] + public string BaseAsset { get; set; } = string.Empty; + /// + /// Quote asset + /// + [JsonPropertyName("quoteAsset")] + public string QuoteAsset { get; set; } = string.Empty; + } +} diff --git a/Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingUserStatus.cs b/Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingUserStatus.cs new file mode 100644 index 000000000..e23e8d37d --- /dev/null +++ b/Binance.Net/Objects/Models/Spot/CopyTrading/BinanceCopyTradingUserStatus.cs @@ -0,0 +1,19 @@ +namespace Binance.Net.Objects.Models.Spot.CopyTrading +{ + /// + /// Copy trading user status + /// + public record BinanceCopyTradingUserStatus + { + /// + /// Is lead trader + /// + [JsonPropertyName("isLeadTrader")] + public bool IsLeadTrader { get; set; } + /// + /// Time + /// + [JsonPropertyName("time")] + public long Timestamp { get; set; } + } +}