Browse Source

账户列表查询接口完善

master
shanji 3 years ago
parent
commit
5a9706ae90
  1. 48
      Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs
  2. 7
      Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs

48
Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs

@ -6,7 +6,9 @@ using Binance.TradeRobot.Model.Dto;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Yitter.IdGenerator; using Yitter.IdGenerator;
namespace Binance.TradeRobot.Business.Exchange namespace Binance.TradeRobot.Business.Exchange
@ -50,7 +52,49 @@ namespace Binance.TradeRobot.Business.Exchange
public IList<ExchangeAccountResponse> GetExchangeAccountList(Enums.TradePolicy tradePolicy) public IList<ExchangeAccountResponse> GetExchangeAccountList(Enums.TradePolicy tradePolicy)
{ {
return null; var exchangeAccountList = fsql.Select<ExchangeAccount>().Where(ea => ea.TradePolicy == tradePolicy).ToList().Map<IList<ExchangeAccountResponse>>();
var accountIdList = exchangeAccountList.Select(ea => ea.Id);
var exchangeAPIKeyList = fsql.Select<ExchangeAPIKey, Robot>().LeftJoin((k, r) => k.RobotId == r.Id)
.Where((k, r) => accountIdList.Contains(k.AccountId))
.ToList((k, r) => new ExchangeAPIKeyResponse()
{
Id = k.Id,
AccountId = k.AccountId,
APIKey = k.APIKey,
SecretKey = k.SecretKey,
CreateTime = k.CreateTime,
RobotId = k.RobotId,
RobotSymbol = r.Symbol
});
var waitList = new List<WaitHandle>();
foreach (var exchangeAccount in exchangeAccountList)
{
var currentExchangeAccountAPIKeyList = exchangeAPIKeyList.Where(k => k.AccountId == exchangeAccount.Id);
if (currentExchangeAccountAPIKeyList.Count() > 0)
exchangeAccount.ExchangeAPIKeyList.AddRange(currentExchangeAccountAPIKeyList);
var ewh = new ManualResetEvent(false);
waitList.Add(ewh);
Task.Factory.StartNew(() => GetExchangeAssets(exchangeAccount, ewh));
}
WaitHandle.WaitAll(waitList.ToArray(), 5000);
return exchangeAccountList;
}
private void GetExchangeAssets(ExchangeAccountResponse exchangeAccount, EventWaitHandle ewh)
{
try
{
}
catch (Exception ex)
{
}
finally
{
ewh.Set();
}
} }
} }
} }

7
Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs

@ -5,7 +5,7 @@ namespace Binance.TradeRobot.Model.Dto
{ {
public class ExchangeAccountResponse : ExchangeAccount public class ExchangeAccountResponse : ExchangeAccount
{ {
public IList<ExchangeAPIKeyResponse> ExchangeAPIKeyList { get; set; } public List<ExchangeAPIKeyResponse> ExchangeAPIKeyList { get; set; }
/// <summary> /// <summary>
/// 合约USDT资产 /// 合约USDT资产
@ -21,5 +21,10 @@ namespace Binance.TradeRobot.Model.Dto
/// 逐仓杠杆USDT资产 /// 逐仓杠杆USDT资产
/// </summary> /// </summary>
public decimal SpotMarginUSDT { get; set; } public decimal SpotMarginUSDT { get; set; }
public ExchangeAccountResponse()
{
ExchangeAPIKeyList = new List<ExchangeAPIKeyResponse>();
}
} }
} }

Loading…
Cancel
Save