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.
83 lines
4.3 KiB
83 lines
4.3 KiB
using Binance.TradeRobot.Common.DI;
|
|
using Binance.TradeRobot.Model.Base;
|
|
using Binance.TradeRobot.Model.Db;
|
|
using Binance.TradeRobot.Model.Dto;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace Binance.TradeRobot.Business
|
|
{
|
|
[BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Self)]
|
|
public class SingalBusiness : BaseBusiness
|
|
{
|
|
private RobotBusiness robotBusiness;
|
|
private ExchangeBusiness exchangeBusiness;
|
|
private IEnumerable<ITradeBusiness> tradeBusinessList;
|
|
private TaskSchedulerManager taskSchedulerManager;
|
|
|
|
public SingalBusiness(IFreeSql fsql,
|
|
NLogManager logManager,
|
|
IIdGenerator idGenerator,
|
|
IMemoryCache memoryCache,
|
|
RobotBusiness robotBusiness,
|
|
ExchangeBusiness exchangeBusiness,
|
|
IEnumerable<ITradeBusiness> tradeBusinessList,
|
|
TaskSchedulerManager taskSchedulerManager) : base(fsql, logManager, idGenerator, memoryCache)
|
|
{
|
|
this.robotBusiness = robotBusiness;
|
|
this.exchangeBusiness = exchangeBusiness;
|
|
this.tradeBusinessList = tradeBusinessList;
|
|
this.taskSchedulerManager = taskSchedulerManager;
|
|
}
|
|
|
|
public void D21Singal(D21SingalRequest d21SingalRequest)
|
|
{
|
|
//logManager.GetLogger("D21").Info(JsonConvert.SerializeObject(d21SingalRequest));
|
|
var robotList = robotBusiness.GetD21PolicyRobotList(d21SingalRequest.RobotId,
|
|
Enums.RobotState.Runing,
|
|
d21SingalRequest.KLinePeriodic,
|
|
d21SingalRequest.Symbol,
|
|
false,
|
|
true);
|
|
if (robotList == null || robotList.Count() == 0)
|
|
throw new BusinessException("未找到符合条件的机器人");
|
|
|
|
var symbolInfo = exchangeBusiness.GetSymbol(robotList[0].ExchangeId,
|
|
robotList[0].Symbol);
|
|
if (symbolInfo == null)
|
|
throw new BusinessException($"未找到交易对{robotList[0].Symbol}({robotList[0].ExchangeId})");
|
|
var d21TradeBusiness = tradeBusinessList.FirstOrDefault(t => t.TradePolicy == Enums.TradePolicy.D21);
|
|
|
|
foreach (var robot in robotList)
|
|
{
|
|
switch (d21SingalRequest.SingalType)
|
|
{
|
|
case Enums.SingalType.小趋势看空:
|
|
case Enums.SingalType.小趋势看多:
|
|
Task.Factory.StartNew(() => d21TradeBusiness.TrendChanged(d21SingalRequest, robot, symbolInfo),
|
|
CancellationToken.None,
|
|
TaskCreationOptions.LongRunning,
|
|
taskSchedulerManager.SingalTaskScheduler);
|
|
break;
|
|
case Enums.SingalType.多交叉:
|
|
Task.Factory.StartNew(() => d21TradeBusiness.LongCross(d21SingalRequest, robot, false, symbolInfo),
|
|
CancellationToken.None,
|
|
TaskCreationOptions.LongRunning,
|
|
taskSchedulerManager.SingalTaskScheduler);
|
|
break;
|
|
case Enums.SingalType.空交叉:
|
|
Task.Factory.StartNew(() => d21TradeBusiness.ShortCross(d21SingalRequest, robot, false, symbolInfo),
|
|
CancellationToken.None,
|
|
TaskCreationOptions.LongRunning,
|
|
taskSchedulerManager.SingalTaskScheduler);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|