15 changed files with 311 additions and 38 deletions
@ -0,0 +1,38 @@ |
|||
using Binance.TradeRobot.Model.Base; |
|||
using SDKAdapter.Model; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace SDKAdapter.APIClient |
|||
{ |
|||
public class BaseAPIClient |
|||
{ |
|||
public static BaseAPIClient Create(Enums.Exchange exchange, long uid, string apiKey, string secret) |
|||
{ |
|||
if (exchange == Enums.Exchange.Binance) |
|||
return new BinanceAPIClient(uid, apiKey, secret); |
|||
return null; |
|||
} |
|||
|
|||
protected long AccountId { get; private set; } |
|||
protected string ApiKey { get; private set; } |
|||
protected string Secret { get; private set; } |
|||
|
|||
public BaseAPIClient(long uid, string apiKey, string secret) |
|||
{ |
|||
this.AccountId = uid; |
|||
this.ApiKey = apiKey; |
|||
this.Secret = secret; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取逐仓杠杆账户资产
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="NotImplementedException"></exception>
|
|||
public virtual IList<IsolatedMarginAccountAsset> GetIsolatedMarginAccountAssets() |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
using Binance.Net.Clients; |
|||
using Binance.Net.Objects; |
|||
using CryptoExchange.Net.Authentication; |
|||
using SDKAdapter.Model; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace SDKAdapter.APIClient |
|||
{ |
|||
public class BinanceAPIClient : BaseAPIClient |
|||
{ |
|||
private BinanceClient binanceClient; |
|||
|
|||
public BinanceAPIClient(long uid, string apiKey, string secret) : base(uid, apiKey, secret) |
|||
{ |
|||
var spotClientOption = new BinanceApiClientOptions() |
|||
{ |
|||
BaseAddress = "https://api.binance.com", |
|||
ApiCredentials = new ApiCredentials(apiKey, secret) |
|||
}; |
|||
var usdFuturesClientOption = new BinanceApiClientOptions() |
|||
{ |
|||
BaseAddress = "https://fapi.binance.com", |
|||
ApiCredentials = new ApiCredentials(apiKey, secret) |
|||
}; |
|||
binanceClient = new BinanceClient(new BinanceClientOptions() |
|||
{ |
|||
UsdFuturesApiOptions = usdFuturesClientOption, |
|||
SpotApiOptions = spotClientOption |
|||
}); |
|||
} |
|||
|
|||
public override IList<IsolatedMarginAccountAsset> GetIsolatedMarginAccountAssets() |
|||
{ |
|||
var r = binanceClient.SpotApi.Account.GetIsolatedMarginAccountAsync().Result; |
|||
if (!r.Success) |
|||
throw new Exception($"获取逐仓杠杆账户信息失败 {r.Error?.Message}"); |
|||
|
|||
return r.Data.Assets.Select(asset => new IsolatedMarginAccountAsset() |
|||
{ |
|||
Symbol = asset.Symbol, |
|||
|
|||
BaseAsset = asset.BaseAsset.Asset, |
|||
BaseBorrowed = asset.BaseAsset.Borrowed, |
|||
BaseFree = asset.BaseAsset.Free, |
|||
BaseInterest = asset.BaseAsset.Interest, |
|||
BaseLocked = asset.BaseAsset.Locked, |
|||
BaseNetAsset = asset.BaseAsset.NetAsset, |
|||
|
|||
QuoteAsset = asset.QuoteAsset.Asset, |
|||
QuoteBorrowed = asset.QuoteAsset.Borrowed, |
|||
QuoteFree = asset.QuoteAsset.Free, |
|||
QuoteInterest = asset.QuoteAsset.Interest, |
|||
QuoteLocked = asset.QuoteAsset.Locked, |
|||
QuoteNetAsset = asset.QuoteAsset.NetAsset |
|||
}).ToList(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,65 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace SDKAdapter.Model |
|||
{ |
|||
/// <summary>
|
|||
/// 逐仓杠杆账户资产
|
|||
/// </summary>
|
|||
public class IsolatedMarginAccountAsset |
|||
{ |
|||
public string Symbol { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 基础币
|
|||
/// </summary>
|
|||
public string BaseAsset { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 基础币借币金额
|
|||
/// </summary>
|
|||
public decimal BaseBorrowed { get; set; } |
|||
/// <summary>
|
|||
/// 基础币可用资产
|
|||
/// </summary>
|
|||
public decimal BaseFree { get; set; } |
|||
/// <summary>
|
|||
/// 基础币借币利息
|
|||
/// </summary>
|
|||
public decimal BaseInterest { get; set; } |
|||
/// <summary>
|
|||
/// 基础币锁定资产
|
|||
/// </summary>
|
|||
public decimal BaseLocked { get; set; } |
|||
/// <summary>
|
|||
/// 基础币净资产
|
|||
/// </summary>
|
|||
public decimal BaseNetAsset { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 报价币
|
|||
/// </summary>
|
|||
public string QuoteAsset { get; set; } |
|||
/// <summary>
|
|||
/// 报价币借币金额
|
|||
/// </summary>
|
|||
public decimal QuoteBorrowed { get; set; } |
|||
/// <summary>
|
|||
/// 报价币可用资产
|
|||
/// </summary>
|
|||
public decimal QuoteFree { get; set; } |
|||
/// <summary>
|
|||
/// 报价币借币利息
|
|||
/// </summary>
|
|||
public decimal QuoteInterest { get; set; } |
|||
/// <summary>
|
|||
/// 报价币锁定资产
|
|||
/// </summary>
|
|||
public decimal QuoteLocked { get; set; } |
|||
/// <summary>
|
|||
/// 报价币净资产
|
|||
/// </summary>
|
|||
public decimal QuoteNetAsset { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,25 @@ |
|||
using Binance.Net.Clients; |
|||
using Binance.Net.Objects; |
|||
using Binance.TradeRobot.Model.Base; |
|||
using CryptoExchange.Net.Authentication; |
|||
using Newtonsoft.Json; |
|||
using SDKAdapter.APIClient; |
|||
using System; |
|||
|
|||
namespace SDKTestConsole |
|||
{ |
|||
internal class Program |
|||
{ |
|||
static void Main(string[] args) |
|||
{ |
|||
var apiKey = "NnLXgcdUAZ8FAye4Qge3zrrdg5o7ufoWbgtYsKzgfIXz0OMz27G1Kx4SykMzw7YS"; |
|||
var secret = "lpJ3t50osPx6lEUerVFMdoKsZ6uHPc769OFPGtfhcoPANpv97CEcvR3pz3Bezhhv"; |
|||
|
|||
var marginList = BaseAPIClient.Create(Enums.Exchange.Binance, 0, apiKey, secret).GetIsolatedMarginAccountAssets(); |
|||
|
|||
var s = JsonConvert.SerializeObject(marginList); |
|||
Console.WriteLine(s); |
|||
Console.ReadKey(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Binance.Net" Version="8.0.13" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Binance.TradeRobot.Model\Binance.TradeRobot.Model.csproj" /> |
|||
<ProjectReference Include="..\SDKAdapter\SDKAdapter.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
Loading…
Reference in new issue