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