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; } /// /// 检查订单是否存在 /// /// /// 订单不存在异常 protected void CheckOrderExists(long orderId) { var tryCount = 3; while (tryCount > 0) { var isOrderExists = fsql.Select(orderId).Any(); if (!isOrderExists) { tryCount--; Thread.Sleep(1000); continue; } return; } throw new BusinessException("订单不存在"); } protected void HandleError(Exception ex, List 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}"); } } }