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

Added copy trading endpoints #1412

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions Binance.Net/Binance.Net.xml
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@
<member name="P:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApi.SimpleEarn">
<inheritdoc />
</member>
<member name="P:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApi.CopyTrading">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApi.CreateAuthenticationProvider(CryptoExchange.Net.Authentication.ApiCredentials)">
<inheritdoc />
</member>
Expand Down Expand Up @@ -742,6 +745,12 @@
<member name="M:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApiBrokerage.GetBrokerFuturesCommissionRebatesHistoryAsync(Binance.Net.Enums.FuturesAccountType,System.DateTime,System.DateTime,System.Nullable{System.Int32},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApiCopyTrading.GetUserStatusAsync(System.Nullable{System.Int64},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApiCopyTrading.GetLeadSymbolAsync(System.Nullable{System.Int64},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="T:Binance.Net.Clients.GeneralApi.BinanceRestClientGeneralApiFutures">
<inheritdoc />
</member>
Expand Down Expand Up @@ -1109,7 +1118,7 @@
<member name="M:Binance.Net.Clients.SpotApi.BinanceRestClientSpotApiAccount.GetWithdrawalAddressesAsync(System.Nullable{System.Int32},System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.SpotApi.BinanceRestClientSpotApiAccount.GetDepositHistoryAsync(System.String,System.Nullable{Binance.Net.Enums.DepositStatus},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<member name="M:Binance.Net.Clients.SpotApi.BinanceRestClientSpotApiAccount.GetDepositHistoryAsync(System.String,System.Nullable{Binance.Net.Enums.DepositStatus},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Boolean,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:Binance.Net.Clients.SpotApi.BinanceRestClientSpotApiAccount.GetDepositAddressAsync(System.String,System.String,System.Nullable{System.Int32},System.Threading.CancellationToken)">
Expand Down Expand Up @@ -6272,6 +6281,11 @@
Endpoints related to Binance Simple Earn
</summary>
</member>
<member name="P:Binance.Net.Interfaces.Clients.GeneralApi.IBinanceRestClientGeneralApi.CopyTrading">
<summary>
Endpoints related to Binance Copy Trading
</summary>
</member>
<member name="T:Binance.Net.Interfaces.Clients.GeneralApi.IBinanceRestClientGeneralApiBrokerage">
<summary>
Binance brokerage endpoints.
Expand Down Expand Up @@ -6725,6 +6739,29 @@
<param name="ct">Cancellation token</param>
<returns>Asset info</returns>
</member>
<member name="T:Binance.Net.Interfaces.Clients.GeneralApi.IBinanceRestClientGeneralApiCopyTrading">
<summary>
Binance copy trading endpoints
</summary>
</member>
<member name="M:Binance.Net.Interfaces.Clients.GeneralApi.IBinanceRestClientGeneralApiCopyTrading.GetUserStatusAsync(System.Nullable{System.Int64},System.Threading.CancellationToken)">
<summary>
Get Futures Lead Trader Status
<para><a href="https://binance-docs.github.io/apidocs/spot/en/#copy-trading-endpoints" /></para>
</summary>
<param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.GeneralApi.IBinanceRestClientGeneralApiCopyTrading.GetLeadSymbolAsync(System.Nullable{System.Int64},System.Threading.CancellationToken)">
<summary>
Get Futures Lead Trading Symbol Whitelist
<para><a href="https://binance-docs.github.io/apidocs/spot/en/#get-futures-lead-trading-symbol-whitelist-user_data" /></para>
</summary>
<param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="T:Binance.Net.Interfaces.Clients.GeneralApi.IBinanceRestClientGeneralApiFutures">
<summary>
Binance futures interaction endpoints
Expand Down Expand Up @@ -8276,7 +8313,7 @@
<param name="ct">Cancellation token</param>
<returns></returns>
</member>
<member name="M:Binance.Net.Interfaces.Clients.SpotApi.IBinanceRestClientSpotApiAccount.GetDepositHistoryAsync(System.String,System.Nullable{Binance.Net.Enums.DepositStatus},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Threading.CancellationToken)">
<member name="M:Binance.Net.Interfaces.Clients.SpotApi.IBinanceRestClientSpotApiAccount.GetDepositHistoryAsync(System.String,System.Nullable{Binance.Net.Enums.DepositStatus},System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Nullable{System.Int32},System.Boolean,System.Threading.CancellationToken)">
<summary>
Gets the deposit history
<para><a href="https://binance-docs.github.io/apidocs/spot/en/#deposit-history-supporting-network-user_data" /></para>
Expand All @@ -8288,6 +8325,7 @@
<param name="startTime">Filter start time from</param>
<param name="endTime">Filter end time till</param>
<param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
<param name="includeSource">Include source address to response</param>
<param name="ct">Cancellation token</param>
<returns>List of deposits</returns>
</member>
Expand Down Expand Up @@ -14749,6 +14787,11 @@
The wallet type
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.BinanceDeposit.SourceAddress">
<summary>
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
</summary>
</member>
<member name="T:Binance.Net.Objects.Models.Spot.BinanceDividendRecord">
<summary>
Dividend record
Expand Down Expand Up @@ -18915,6 +18958,41 @@
Creation time
</summary>
</member>
<member name="T:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingLeadSymbol">
<summary>
Copy trading lead symbol
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingLeadSymbol.Symbol">
<summary>
Symbol
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingLeadSymbol.BaseAsset">
<summary>
Base asset
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingLeadSymbol.QuoteAsset">
<summary>
Quote asset
</summary>
</member>
<member name="T:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingUserStatus">
<summary>
Copy trading user status
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingUserStatus.IsLeadTrader">
<summary>
Is lead trader
</summary>
</member>
<member name="P:Binance.Net.Objects.Models.Spot.CopyTrading.BinanceCopyTradingUserStatus.Timestamp">
<summary>
Time
</summary>
</member>
<member name="T:Binance.Net.Objects.Models.Spot.IsolatedMargin.BinanceIsolatedMarginSymbol">
<summary>
Isolated margin symbol info
Expand Down
3 changes: 3 additions & 0 deletions Binance.Net/Clients/GeneralApi/BinanceRestClientGeneralApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ internal class BinanceRestClientGeneralApi : RestApiClient, IBinanceRestClientGe
public IBinanceRestClientGeneralApiStaking Staking { get; }
/// <inheritdoc />
public IBinanceRestClientGeneralApiSimpleEarn SimpleEarn { get; }
/// <inheritdoc />
public IBinanceRestClientGeneralApiCopyTrading CopyTrading { get; }
#endregion

#region constructor/destructor
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/// <inheritdoc />
public async Task<WebCallResult<BinanceCopyTradingUserStatus>> 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<BinanceResult<BinanceCopyTradingUserStatus>>(request, parameters, ct).ConfigureAwait(false);

return data.As(data.Data.Data);
}

#endregion

#region Get Lead Symbol

/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<BinanceCopyTradingLeadSymbol>>> 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<BinanceResult<IEnumerable<BinanceCopyTradingLeadSymbol>>>(request, parameters, ct).ConfigureAwait(false);

return data.As(data.Data.Data);
}

#endregion

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ public interface IBinanceRestClientGeneralApi : IRestApiClient, IDisposable
/// Endpoints related to Binance Simple Earn
/// </summary>
IBinanceRestClientGeneralApiSimpleEarn SimpleEarn { get; }

/// <summary>
/// Endpoints related to Binance Copy Trading
/// </summary>
IBinanceRestClientGeneralApiCopyTrading CopyTrading { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Binance.Net.Objects.Internal;
using Binance.Net.Objects.Models.Spot.CopyTrading;

namespace Binance.Net.Interfaces.Clients.GeneralApi
{
/// <summary>
/// Binance copy trading endpoints
/// </summary>
public interface IBinanceRestClientGeneralApiCopyTrading
{
/// <summary>
/// Get Futures Lead Trader Status
/// <para><a href="https://binance-docs.github.io/apidocs/spot/en/#copy-trading-endpoints" /></para>
/// </summary>
/// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<BinanceCopyTradingUserStatus>> GetUserStatusAsync(long? receiveWindow = null, CancellationToken ct = default);


/// <summary>
/// Get Futures Lead Trading Symbol Whitelist
/// <para><a href="https://binance-docs.github.io/apidocs/spot/en/#get-futures-lead-trading-symbol-whitelist-user_data" /></para>
/// </summary>
/// <param name="receiveWindow">The receive window for which this request is active. When the request takes longer than this to complete the server will reject the request</param>
/// <param name="ct">Cancellation token</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<BinanceCopyTradingLeadSymbol>>> GetLeadSymbolAsync(long? receiveWindow = null, CancellationToken ct = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Binance.Net.Objects.Models.Spot.CopyTrading
{
/// <summary>
/// Copy trading lead symbol
/// </summary>
public record BinanceCopyTradingLeadSymbol
{
/// <summary>
/// Symbol
/// </summary>
[JsonPropertyName("symbol")]
public string Symbol { get; set; } = string.Empty;
/// <summary>
/// Base asset
/// </summary>
[JsonPropertyName("baseAsset")]
public string BaseAsset { get; set; } = string.Empty;
/// <summary>
/// Quote asset
/// </summary>
[JsonPropertyName("quoteAsset")]
public string QuoteAsset { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Binance.Net.Objects.Models.Spot.CopyTrading
{
/// <summary>
/// Copy trading user status
/// </summary>
public record BinanceCopyTradingUserStatus
{
/// <summary>
/// Is lead trader
/// </summary>
[JsonPropertyName("isLeadTrader")]
public bool IsLeadTrader { get; set; }
/// <summary>
/// Time
/// </summary>
[JsonPropertyName("time")]
public long Timestamp { get; set; }
}
}
Loading