diff --git a/Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs b/Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs index 3bce41e..a5b5f13 100644 --- a/Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs +++ b/Binance.TradeRobot.Business/Exchange/ExchangeBusiness.cs @@ -6,7 +6,9 @@ using Binance.TradeRobot.Model.Dto; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; -using System.Text; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Yitter.IdGenerator; namespace Binance.TradeRobot.Business.Exchange @@ -50,7 +52,49 @@ namespace Binance.TradeRobot.Business.Exchange public IList GetExchangeAccountList(Enums.TradePolicy tradePolicy) { - return null; + var exchangeAccountList = fsql.Select().Where(ea => ea.TradePolicy == tradePolicy).ToList().Map>(); + var accountIdList = exchangeAccountList.Select(ea => ea.Id); + var exchangeAPIKeyList = fsql.Select().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(); + 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(); + } } } } diff --git a/Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs b/Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs index 915a0f7..38c3516 100644 --- a/Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs +++ b/Binance.TradeRobot.Model/Dto/Response/Exchange/ExchangeAccountResponse.cs @@ -5,7 +5,7 @@ namespace Binance.TradeRobot.Model.Dto { public class ExchangeAccountResponse : ExchangeAccount { - public IList ExchangeAPIKeyList { get; set; } + public List ExchangeAPIKeyList { get; set; } /// /// 合约USDT资产 @@ -21,5 +21,10 @@ namespace Binance.TradeRobot.Model.Dto /// 逐仓杠杆USDT资产 /// public decimal SpotMarginUSDT { get; set; } + + public ExchangeAccountResponse() + { + ExchangeAPIKeyList = new List(); + } } }