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.
72 lines
2.6 KiB
72 lines
2.6 KiB
using Binance.TradeRobot.Model.Base;
|
|
using Binance.TradeRobot.Model.Db;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using SDKAdapter.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace Binance.TradeRobot.Business
|
|
{
|
|
public class BaseSpotOrderPublishBusiness : BaseBusiness
|
|
{
|
|
protected DingBusiness dingBusiness;
|
|
protected RobotBusiness robotBusiness;
|
|
|
|
public BaseSpotOrderPublishBusiness(IFreeSql fsql,
|
|
NLogManager logManager,
|
|
IIdGenerator idGenerator,
|
|
IMemoryCache memoryCache,
|
|
DingBusiness dingBusiness,
|
|
RobotBusiness robotBusiness) : base(fsql, logManager, idGenerator, memoryCache)
|
|
{
|
|
this.dingBusiness = dingBusiness;
|
|
this.robotBusiness = robotBusiness;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查订单是否存在
|
|
/// </summary>
|
|
/// <param name="orderId"></param>
|
|
/// <exception cref="BusinessException">订单不存在异常</exception>
|
|
protected void CheckOrderExists(long orderId)
|
|
{
|
|
var tryCount = 3;
|
|
while (tryCount > 0)
|
|
{
|
|
var isOrderExists = fsql.Select<SpotOrder>(orderId).Any();
|
|
if (!isOrderExists)
|
|
{
|
|
tryCount--;
|
|
Thread.Sleep(1000);
|
|
continue;
|
|
}
|
|
return;
|
|
}
|
|
throw new BusinessException("订单不存在");
|
|
}
|
|
|
|
protected void HandleError(Exception ex,
|
|
List<ExecutionLog> logList,
|
|
string loggerName,
|
|
long robotId,
|
|
long orderId,
|
|
string step)
|
|
{
|
|
logList.Add(new ExecutionLog()
|
|
{
|
|
Id = idGenerator.NewLong(),
|
|
SourceSingal = Enums.SingalType.订单推送,
|
|
RobotId = robotId,
|
|
CreateTime = DateTime.Now,
|
|
Content = ex.Message,
|
|
OrderId = orderId
|
|
});
|
|
try { fsql.Insert(logList).ExecuteAffrows(); } catch { }
|
|
var errorMsg = $"交易警报,{Enums.SingalType.订单推送},{loggerName},robot {robotId},order {orderId},{step}";
|
|
logManager.GetLogger(loggerName).Error(ex, errorMsg);
|
|
dingBusiness.Send($"{errorMsg} {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|