1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-24 03:50:55 +00:00
Files
CryptoExchange.Net/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetBalancesOptions.cs
T
Jkorf d0ce2563de wip
2026-08-25 16:09:15 +02:00

99 lines
3.0 KiB
C#

using CryptoExchange.Net.Objects;
using System.Linq;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Options for requesting a transfer
/// </summary>
public class GetBalancesOptions : EndpointOptions<GetBalancesRequest, IGetBalancesEndpoint>
{
/// <inheritdoc />
public override string Description => "Retrieve account balances";
/// <summary>
/// Supported account types
/// </summary>
public AccountTypeFilter[] SupportedAccountTypes { get; set; }
/// <summary>
/// ctor
/// </summary>
public GetBalancesOptions(string exchange, params AccountTypeFilter[] accountTypes) : base(exchange, true, nameof(IGetBalancesEndpoint.GetBalancesAsync))
{
SupportedAccountTypes = accountTypes;
}
/// <summary>
/// Validate a request
/// </summary>
public override Error? ValidateRequest(
GetBalancesRequest request,
IGetBalancesEndpoint client)
{
if (request.AccountType != null && !IsValid(request.AccountType.Value))
return ArgumentError.Invalid(nameof(request.AccountType), "Invalid AccountType");
return base.ValidateRequest(request, client);
}
/// <summary>
/// Is the account type valid for this client
/// </summary>
/// <param name="accountType"></param>
/// <returns></returns>
public bool IsValid(SharedAccountType accountType)
{
if (accountType == SharedAccountType.Funding)
return SupportedAccountTypes.Contains(AccountTypeFilter.Funding);
if (accountType == SharedAccountType.Spot)
return SupportedAccountTypes.Contains(AccountTypeFilter.Spot);
if (accountType == SharedAccountType.PerpetualLinearFutures
|| accountType == SharedAccountType.PerpetualInverseFutures
|| accountType == SharedAccountType.DeliveryLinearFutures
|| accountType == SharedAccountType.DeliveryInverseFutures)
{
return SupportedAccountTypes.Contains(AccountTypeFilter.Futures);
}
if (accountType == SharedAccountType.CrossMargin
|| accountType == SharedAccountType.IsolatedMargin)
{
return SupportedAccountTypes.Contains(AccountTypeFilter.Margin);
}
return SupportedAccountTypes.Contains(AccountTypeFilter.Option);
}
}
/// <summary>
/// Account type filter
/// </summary>
public enum AccountTypeFilter
{
/// <summary>
/// Funding account
/// </summary>
Funding,
/// <summary>
/// Spot account
/// </summary>
Spot,
/// <summary>
/// Futures account
/// </summary>
Futures,
/// <summary>
/// Margin account
/// </summary>
Margin,
/// <summary>
/// Option account
/// </summary>
Option
}
}