|
|
|
using Binance.TradeRobot.Common.DI;
|
|
|
|
using Binance.TradeRobot.Model.Base;
|
|
|
|
using Binance.TradeRobot.Model.Db;
|
|
|
|
using Binance.TradeRobot.Model.Dto;
|
|
|
|
using Binance.TradeRobot.Model.RuningInfo;
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using System;
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
namespace Binance.TradeRobot.Business
|
|
|
|
{
|
|
|
|
[BatchRegistration(ServiceLifetime.Singleton, RegistrationType.Interface)]
|
|
|
|
public class D21TradeBusiness : BaseBusiness, ITradeBusiness
|
|
|
|
{
|
|
|
|
public D21TradeBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator, IMemoryCache memoryCache) : base(fsql, logManager, idGenerator, memoryCache)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public Enums.TradePolicy TradePolicy => Enums.TradePolicy.D21;
|
|
|
|
|
|
|
|
public void TrendChanged<T, T1>(T singalRequest, T1 robot) where T : BaseSingalRequest where T1 : RobotResponse
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var executionLog = new ExecutionLog()
|
|
|
|
{
|
|
|
|
Id = idGenerator.NewLong(),
|
|
|
|
RobotId = robot.Id,
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
SourceSingal = singalRequest.SingalType,
|
|
|
|
Content = $"收到趋势信号【{singalRequest.SingalType}】"
|
|
|
|
};
|
|
|
|
fsql.Insert(executionLog).ExecuteAffrows();
|
|
|
|
var d21RuningInfo = RedisHelper.Get<D21RuningInfo>(robot.Id.ToString());
|
|
|
|
if (d21RuningInfo == null)
|
|
|
|
d21RuningInfo = new D21RuningInfo() { RobotId = robot.Id };
|
|
|
|
d21RuningInfo.RecentSmallTrendSingal = singalRequest.SingalType;
|
|
|
|
RedisHelper.Set(robot.Id.ToString(), d21RuningInfo);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|