|
|
@ -223,6 +223,37 @@ namespace Binance.TradeRobot.Business |
|
|
|
}).Map<IList<RobotResponse>>(); |
|
|
|
} |
|
|
|
|
|
|
|
private void GetSpotRobotRecentProfit<T>(IList<T> robotList) where T : RobotResponse |
|
|
|
{ |
|
|
|
var robotIds = robotList.Select(r => r.Id).ToList(); |
|
|
|
var recentProftList = fsql.Select<Robot>().Where(r => robotIds.Contains(r.Id)).ToList(r => new |
|
|
|
{ |
|
|
|
RobotId = r.Id, |
|
|
|
FiveTimesProfit = fsql.Select<SpotOrder>().Where(o => o.RobotId == r.Id).OrderByDescending(o => o.CreateTime).Take(5).Sum(o => o.Profit), |
|
|
|
TenTimesProfit = fsql.Select<SpotOrder>().Where(o => o.RobotId == r.Id).OrderByDescending(o => o.CreateTime).Take(10).Sum(o => o.Profit) |
|
|
|
}); |
|
|
|
foreach (var recentProft in recentProftList) |
|
|
|
{ |
|
|
|
var robot = robotList.FirstOrDefault(r => r.Id == recentProft.RobotId); |
|
|
|
if (robot != null) |
|
|
|
{ |
|
|
|
robot.RobotAccount.FiveTimesProfit = recentProft.FiveTimesProfit; |
|
|
|
robot.RobotAccount.TenTimesProfit = recentProft.TenTimesProfit; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void GetSpotRobotFloatingProfitAndLoss<T>(IList<T> robotList) where T : RobotResponse |
|
|
|
{ |
|
|
|
foreach (var robot in robotList) |
|
|
|
{ |
|
|
|
var newestPrice = globalContext.GetSpotNewestPrice(robot.KLineKey) ?? 0; |
|
|
|
if (newestPrice == 0) |
|
|
|
continue; |
|
|
|
robot.RobotAccount.FloatingProfitAndLoss = (newestPrice - robot.RobotAccount.SpotCurrencyAvgPrice) * robot.RobotAccount.SpotCurrencyQuantity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取动2.1策略机器人列表
|
|
|
|
/// </summary>
|
|
|
@ -302,6 +333,8 @@ namespace Binance.TradeRobot.Business |
|
|
|
if (isLoadRecentTradeProfit) |
|
|
|
{ |
|
|
|
//统计近期订单利润
|
|
|
|
GetSpotRobotRecentProfit(robotList); |
|
|
|
GetSpotRobotFloatingProfitAndLoss(robotList); |
|
|
|
} |
|
|
|
|
|
|
|
if (!isLoadAPIKey) |
|
|
@ -312,6 +345,10 @@ namespace Binance.TradeRobot.Business |
|
|
|
return robotList; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 补救检查
|
|
|
|
/// </summary>
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
public void D21Remedy() |
|
|
|
{ |
|
|
|
var d21RobotList = GetD21PolicyRobotList(robotState: Enums.RobotState.Runing, isLoadRecentTradeProfit: false, isLoadAPIKey: true); |
|
|
|