币安量化交易
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB

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();
}
}
}