|
|
@ -1,11 +1,13 @@ |
|
|
|
using Binance.TradeRobot.Common.DI; |
|
|
|
using Binance.TradeRobot.Model.Base; |
|
|
|
using Binance.TradeRobot.Model.Db; |
|
|
|
using FreeSql; |
|
|
|
using Microsoft.Extensions.Caching.Memory; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using SDKAdapter.Model; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace Binance.TradeRobot.Business |
|
|
@ -15,20 +17,33 @@ namespace Binance.TradeRobot.Business |
|
|
|
{ |
|
|
|
public Enums.TradePolicy TradePolicy => Enums.TradePolicy.D21; |
|
|
|
|
|
|
|
public RobotBusiness robotBusiness; |
|
|
|
|
|
|
|
public D21OrderPublishBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator, IMemoryCache memoryCache, DingBusiness dingBusiness, RobotBusiness robotBusiness) : base(fsql, logManager, idGenerator, memoryCache, dingBusiness) |
|
|
|
public D21OrderPublishBusiness(IFreeSql fsql, NLogManager logManager, IIdGenerator idGenerator, IMemoryCache memoryCache, DingBusiness dingBusiness, RobotBusiness robotBusiness) : base(fsql, logManager, idGenerator, memoryCache, dingBusiness, robotBusiness) |
|
|
|
{ |
|
|
|
this.robotBusiness = robotBusiness; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void OnSpotOrderPublish(SpotOrderPublishInfo spotOrderPublishInfo) |
|
|
|
{ |
|
|
|
var logger = logManager.GetLogger(spotOrderPublishInfo.LoggerName); |
|
|
|
//var logger = logManager.GetLogger(spotOrderPublishInfo.LoggerName);
|
|
|
|
var step = ""; |
|
|
|
var logList = new List<ExecutionLog>(); |
|
|
|
try |
|
|
|
{ |
|
|
|
CheckOrderExists(spotOrderPublishInfo.OrderId); |
|
|
|
|
|
|
|
var robot = robotBusiness.GetD21PolicyRobotList(spotOrderPublishInfo.RobotId, isLoadRecentTradeProfit: false, isLoadAPIKey: true).FirstOrDefault(); |
|
|
|
if (robot == null) |
|
|
|
throw new BusinessException($"未找到机器人"); |
|
|
|
|
|
|
|
IUpdate<SpotOrder> updateSpotOrder = fsql.Update<SpotOrder>(spotOrderPublishInfo.OrderId).Set(o => o.State, spotOrderPublishInfo.SpotOrderState); |
|
|
|
|
|
|
|
if (spotOrderPublishInfo.SpotOrderState == Enums.SpotOrderState.Rejected || spotOrderPublishInfo.SpotOrderState == Enums.SpotOrderState.Expired) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (spotOrderPublishInfo.SpotOrderState == Enums.SpotOrderState.Filled) |
|
|
|
{ |
|
|
|
logList.Add(new ExecutionLog() |
|
|
|
{ |
|
|
@ -37,10 +52,16 @@ namespace Binance.TradeRobot.Business |
|
|
|
OrderId = spotOrderPublishInfo.OrderId, |
|
|
|
RobotId = spotOrderPublishInfo.RobotId, |
|
|
|
SourceSingal = Enums.SingalType.订单推送, |
|
|
|
Content = $"收到订单推送,订单号:{spotOrderPublishInfo.OrderId},订单方向:{spotOrderPublishInfo.TradeDirection},订单类型:{spotOrderPublishInfo.OrderType},订单状态:{spotOrderPublishInfo.SpotOrderState},本次成交额:{spotOrderPublishInfo.LastTradeAmount}" |
|
|
|
Content = $"收到订单推送,订单号:{spotOrderPublishInfo.OrderId},订单方向:{spotOrderPublishInfo.TradeDirection},订单类型:{spotOrderPublishInfo.OrderType},订单状态:{spotOrderPublishInfo.SpotOrderState},成交额:{spotOrderPublishInfo.LastTradeAmount},成交量:{spotOrderPublishInfo.LastTradeQuantity},成交价:{spotOrderPublishInfo.LastTradePrice},手续费({spotOrderPublishInfo.FeeUnit}):{spotOrderPublishInfo.Fee}" |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
updateSpotOrder = fsql.Update<SpotOrder>(spotOrderPublishInfo.OrderId) |
|
|
|
//.Set(o => o.TradeCount + 1)
|
|
|
|
.Set(o => o.TradeAmount, spotOrderPublishInfo.CummulativeTradeAmount) |
|
|
|
.Set(o => o.TradeQuantity, spotOrderPublishInfo.CummulativeTradeQuantity) |
|
|
|
.Set(o => o.TradePrice, spotOrderPublishInfo.CummulativeTradeAmount / spotOrderPublishInfo.CummulativeTradeQuantity) |
|
|
|
.Set(o => o.TradeFee, spotOrderPublishInfo.Fee) |
|
|
|
.Set(o => o.TradeFeeUnit, spotOrderPublishInfo.FeeUnit); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|