diff --git a/Binance.TradeRobot.API/Binance.TradeRobot.API.xml b/Binance.TradeRobot.API/Binance.TradeRobot.API.xml index a4bb4d5..1144f50 100644 --- a/Binance.TradeRobot.API/Binance.TradeRobot.API.xml +++ b/Binance.TradeRobot.API/Binance.TradeRobot.API.xml @@ -23,19 +23,26 @@ 交易策略 - + 获取APIKey未使用的交易所账户列表 + - 创建金字塔策略合约机器人 + 创建金字塔策略机器人 + + + 创建动2.1策略机器人 + + + 用户登录 diff --git a/Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs b/Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs index eb88f78..64b17cb 100644 --- a/Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs +++ b/Binance.TradeRobot.API/Controllers/ExchangeAccountController.cs @@ -53,11 +53,12 @@ namespace Binance.TradeRobot.API.Controllers /// 获取APIKey未使用的交易所账户列表 /// /// + /// /// [HttpGet("{tradePolicy}")] - public IList GetNoUsedExchangeAccountList([FromRoute]Enums.TradePolicy tradePolicy) + public IList GetNoUsedExchangeAccountList([FromRoute] Enums.TradePolicy tradePolicy, [FromRoute] Enums.Exchange exchangeId) { - return exchangeBusiness.GetNoUsedExchangeAccountList(tradePolicy); + return exchangeBusiness.GetNoUsedExchangeAccountList(tradePolicy, exchangeId); } } } diff --git a/Binance.TradeRobot.API/Controllers/RobotController.cs b/Binance.TradeRobot.API/Controllers/RobotController.cs index 7e51e55..ae9f540 100644 --- a/Binance.TradeRobot.API/Controllers/RobotController.cs +++ b/Binance.TradeRobot.API/Controllers/RobotController.cs @@ -3,6 +3,7 @@ using Binance.TradeRobot.Model.Dto; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; namespace Binance.TradeRobot.API.Controllers { @@ -17,7 +18,7 @@ namespace Binance.TradeRobot.API.Controllers } /// - /// 创建金字塔策略合约机器人 + /// 创建金字塔策略机器人 /// /// [HttpPost] @@ -25,5 +26,24 @@ namespace Binance.TradeRobot.API.Controllers { robotBusiness.AddPyramidPolicyRobot(addPyramidPolicyRobotRequest); } + + /// + /// 创建动2.1策略机器人 + /// + /// + public void AddD21PolicyRobot([FromBody] AddD21PolicyRobotRequest addD21PolicyRobotRequest) + { + robotBusiness.AddD21PolicyRobot(addD21PolicyRobotRequest); + } + + /// + /// 获取动2.1机器人列表 + /// + /// + [HttpGet] + public IList GetD21PolicyRobotList() + { + return robotBusiness.GetD21PolicyRobotList(); + } } } diff --git a/Binance.TradeRobot.Business/Binance.TradeRobot.Business.xml b/Binance.TradeRobot.Business/Binance.TradeRobot.Business.xml index 0d455e1..b6095d5 100644 --- a/Binance.TradeRobot.Business/Binance.TradeRobot.Business.xml +++ b/Binance.TradeRobot.Business/Binance.TradeRobot.Business.xml @@ -4,11 +4,12 @@ Binance.TradeRobot.Business - + 获取APIKey未使用交易所账户列表 + @@ -25,6 +26,12 @@ + + + 添加动2.1策略机器人 + + + 单向资产变更 diff --git a/Binance.TradeRobot.Business/Business/ExchangeBusiness.cs b/Binance.TradeRobot.Business/Business/ExchangeBusiness.cs index 15fa929..adce801 100644 --- a/Binance.TradeRobot.Business/Business/ExchangeBusiness.cs +++ b/Binance.TradeRobot.Business/Business/ExchangeBusiness.cs @@ -134,10 +134,12 @@ namespace Binance.TradeRobot.Business.Exchange /// 获取APIKey未使用交易所账户列表 /// /// + /// /// - public IList GetNoUsedExchangeAccountList(Enums.TradePolicy tradePolicy) + public IList GetNoUsedExchangeAccountList(Enums.TradePolicy tradePolicy, Enums.Exchange exchangeId) { - var exchangeAccountList = fsql.Select().Where(ea => ea.TradePolicy == tradePolicy).ToList().Map>(); + var exchangeAccountList = fsql.Select().Where(ea => ea.TradePolicy == tradePolicy && ea.ExchangeId == exchangeId) + .ToList().Map>(); var accountIdList = exchangeAccountList.Select(ea => ea.Id); var exchangeAPIKeyList = fsql.Select().Where(k => k.RobotId == null && accountIdList.Contains(k.AccountId)) .ToList() diff --git a/Binance.TradeRobot.Business/Business/RobotBusiness.cs b/Binance.TradeRobot.Business/Business/RobotBusiness.cs index 6f798b1..7c3b541 100644 --- a/Binance.TradeRobot.Business/Business/RobotBusiness.cs +++ b/Binance.TradeRobot.Business/Business/RobotBusiness.cs @@ -6,6 +6,7 @@ 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.Data.Common; using Yitter.IdGenerator; @@ -44,27 +45,33 @@ namespace Binance.TradeRobot.Business throw new BusinessException("同一个交易所账号下只允许存在一个交易对"); } - private Robot CreateRobot(AddRobotRequest addRobotRequest) + /// + /// 添加机器人和账户 + /// + /// + /// + /// 机器人Id + private long AddRobotWithTran(AddRobotRequest addRobotRequest, DbTransaction tran) { - return new Robot() + var robotId = idGenerator.NewLong(); + fsql.Insert(new Robot() { - Id = idGenerator.NewLong(), + Id = robotId, Symbol = addRobotRequest.Symbol, TradePolicy = addRobotRequest.TradePolicy, - BusinessType = addRobotRequest.TradePolicy.GetBusinessType() - }; - } + BusinessType = addRobotRequest.TradePolicy.GetBusinessType(), + ExchangeId = addRobotRequest.ExchangeId, + }).WithTransaction(tran).ExecuteAffrows(); - private RobotAccount CreateRobotAccount(long robotId) - { - return new RobotAccount() { Id = idGenerator.NewLong(), RobotId = robotId }; - } + fsql.Insert(new RobotAccount() + { + Id = idGenerator.NewLong(), + RobotId = robotId + }).WithTransaction(tran).ExecuteAffrows(); - private void ExecuteAddRobotWithTran(Robot robot, RobotAccount robotAccount, long exchangeAPIKeyId, DbTransaction tran) - { - fsql.Insert(robot).WithTransaction(tran).ExecuteAffrows(); - fsql.Insert(robotAccount).WithTransaction(tran).ExecuteAffrows(); - fsql.Update(exchangeAPIKeyId).WithTransaction(tran).Set(ek => ek.RobotId, robot.Id).ExecuteAffrows(); + fsql.Update(addRobotRequest.ExchangeAPIKeyId).WithTransaction(tran).Set(ek => ek.RobotId, robotId).ExecuteAffrows(); + + return robotId; } /// @@ -74,20 +81,70 @@ namespace Binance.TradeRobot.Business public void AddPyramidPolicyRobot(AddPyramidPolicyRobotRequest addPyramidPolicyRobotRequest) { CheckRobotRegister(addPyramidPolicyRobotRequest, out ExchangeAPIKey exchangeAPIKey); - var robot = CreateRobot(addPyramidPolicyRobotRequest); - var robotAccount = CreateRobotAccount(robot.Id); var pyramidPolicy = addPyramidPolicyRobotRequest.Map(); pyramidPolicy.Id = idGenerator.NewLong(); - pyramidPolicy.RobotId = robot.Id; fsql.Transaction(() => { var tran = fsql.Ado.TransactionCurrentThread; - ExecuteAddRobotWithTran(robot, robotAccount, addPyramidPolicyRobotRequest.ExchangeAPIKeyId, tran); + pyramidPolicy.RobotId = AddRobotWithTran(addPyramidPolicyRobotRequest, tran); fsql.Insert(pyramidPolicy).ExecuteAffrows(); }); //调整仓位杠杆倍数 + } + + /// + /// 添加动2.1策略机器人 + /// + /// + public void AddD21PolicyRobot(AddD21PolicyRobotRequest addD21PolicyRobotRequest) + { + CheckRobotRegister(addD21PolicyRobotRequest, out _); + var d21Policy = addD21PolicyRobotRequest.Map(); + d21Policy.Id = idGenerator.NewLong(); + fsql.Transaction(() => + { + var tran = fsql.Ado.TransactionCurrentThread; + d21Policy.RobotId = AddRobotWithTran(addD21PolicyRobotRequest, tran); + fsql.Insert(d21Policy).ExecuteAffrows(); + }); + } + + public IList GetD21PolicyRobotList() + { + var robotList = fsql.Select().InnerJoin((r, ra, d) => r.Id == ra.RobotId) + .InnerJoin((r, ra, d) => r.Id == d.RobotId) + .ToList((r, ra, d) => new Robot() + { + Id = r.Id, + BusinessType = r.BusinessType, + ExchangeId = r.ExchangeId, + Symbol = r.Symbol, + State = r.State, + RunningTime = r.RunningTime, + CreateTime = r.CreateTime, + TradePolicy = r.TradePolicy, + + RobotAccountId = ra.Id, + ClosePositionCount = ra.ClosePositionCount, + WinCount = ra.WinCount, + LoanAmount = ra.LoanAmount, + SoptCurrentcyAmount = ra.SoptCurrentcyAmount, + SpotCurrencyQuantity = ra.SpotCurrencyQuantity, + TotalProfit = ra.TotalProfit, + + D21ExecutionMode = d.ExecutionMode, + D21IsEnabledIncreasePurchase = d.IsEnabledIncreasePurchase, + D21IsEnableRemedyForErrorCrossSignal = d.IsEnableRemedyForErrorCrossSignal, + D21MaxFollowPurchaseRatio = d.MaxFollowPurchaseRatio, + D21PeriodicSignal = d.PeriodicSignal, + D21PolicyId = d.Id, + D21Position = d.Position, + D21StopLossRatio = d.StopLossRatio + }).Map>(); + + return robotList; } } } diff --git a/Binance.TradeRobot.Business/Extensions/RobotExtension.cs b/Binance.TradeRobot.Business/Extensions/RobotExtension.cs index af53670..f4ff5fe 100644 --- a/Binance.TradeRobot.Business/Extensions/RobotExtension.cs +++ b/Binance.TradeRobot.Business/Extensions/RobotExtension.cs @@ -8,7 +8,8 @@ namespace Binance.TradeRobot.Business.Extensions private static IDictionary BusinessTypeDic = new Dictionary() { {Enums.TradePolicy.金字塔, Enums.BusinessType.UPrep }, - { Enums.TradePolicy.动量趋势v2, Enums.BusinessType.Spot_Margin} + { Enums.TradePolicy.动量趋势v2, Enums.BusinessType.Spot_Margin}, + { Enums.TradePolicy.动量趋势v21, Enums.BusinessType.Spot_Margin} }; /// diff --git a/Binance.TradeRobot.Model/Base/Enums.cs b/Binance.TradeRobot.Model/Base/Enums.cs index eed48b6..40154fc 100644 --- a/Binance.TradeRobot.Model/Base/Enums.cs +++ b/Binance.TradeRobot.Model/Base/Enums.cs @@ -58,23 +58,73 @@ namespace Binance.TradeRobot.Model.Base /// /// 机器人状态 Stop=0,Runing=1 /// - public enum RobotStatus + public enum RobotState { Stop = 0, Runing = 1 } /// - /// 交易策略 动量趋势v2=2,金字塔=11 + /// 交易策略 动量趋势v2=0,动量趋势v21=1,金字塔=11 /// public enum TradePolicy { - 动量趋势v2 = 2, - + 动量趋势v2 = 0, + 动量趋势v21 = 1, 金字塔 = 11 } + /// + /// 执行模式 Both=0,OnlyBuy=1,OnlySell=2 + /// + public enum ExecutionMode + { + Both = 0, OnlyBuy = 1, OnlySell = 2 + } + #endregion + + #region 交易所 + + /// + /// Binance=0, Gate.io=1 + /// + public enum Exchange + { + /// + /// 币安 + /// + Binance = 0, + /// + /// 芝麻开门 + /// + Gate_IO = 1 + } + + /// + /// 借币状态 Loading=0 returned=1 + /// + public enum LoanState + { + Loaning, retured + } + + /// + /// 订单状态 + /// + public enum OrderState + { + Created + } + + /// + /// 交易方向 Buy=0,Sell=1 + /// + public enum TradeDirection + { + Buy, Sell + } + /// /// 信号周期 1m=0,3m=1,5m=2,15m=3,30m=4,1h=5,2h=6,4h=7,6h=8,8h=9,12h=10,1d=11,3d=12,1w=13,1M=14 /// diff --git a/Binance.TradeRobot.Model/Base/MappingProfiles.cs b/Binance.TradeRobot.Model/Base/MappingProfiles.cs index b5ea5f2..9ac3a42 100644 --- a/Binance.TradeRobot.Model/Base/MappingProfiles.cs +++ b/Binance.TradeRobot.Model/Base/MappingProfiles.cs @@ -17,6 +17,27 @@ namespace Binance.TradeRobot.Model.Base CreateMap(); CreateMap(); + CreateMap(); + + CreateMap().ForPath(t => t.RobotAccount.Id, opt => opt.MapFrom(f => f.RobotAccountId)) + .ForPath(t => t.RobotAccount.RobotId, opt => opt.MapFrom(f => f.Id)) + .ForPath(t => t.RobotAccount.SoptCurrentcyAmount, opt => opt.MapFrom(f => f.SoptCurrentcyAmount)) + .ForPath(t => t.RobotAccount.SpotCurrencyQuantity, opt => opt.MapFrom(f => f.SpotCurrencyQuantity)) + .ForPath(t => t.RobotAccount.ClosePositionCount, opt => opt.MapFrom(f => f.ClosePositionCount)) + .ForPath(t => t.RobotAccount.LoanAmount, opt => opt.MapFrom(f => f.LoanAmount)) + .ForPath(t => t.RobotAccount.TotalProfit, opt => opt.MapFrom(f => f.TotalProfit)) + .ForPath(t => t.RobotAccount.WinCount, opt => opt.MapFrom(f => f.WinCount)); + CreateMap().IncludeBase() + .ForPath(t => t.D21Policy.Id, opt => opt.MapFrom(f => f.D21PolicyId)) + .ForPath(t => t.D21Policy.RobotId, opt => opt.MapFrom(f => f.Id)) + .ForPath(t => t.D21Policy.Position, opt => opt.MapFrom(f => f.D21Position)) + .ForPath(t => t.D21Policy.IsEnabledIncreasePurchase, opt => opt.MapFrom(f => f.D21IsEnabledIncreasePurchase)) + .ForPath(t => t.D21Policy.IsEnableRemedyForErrorCrossSignal, opt => opt.MapFrom(f => f.D21IsEnableRemedyForErrorCrossSignal)) + .ForPath(t => t.D21Policy.PeriodicSignal, opt => opt.MapFrom(f => f.D21PeriodicSignal)) + .ForPath(t => t.D21Policy.MaxFollowPurchaseRatio, opt => opt.MapFrom(f => f.D21MaxFollowPurchaseRatio)) + .ForPath(t => t.D21Policy.StopLossRatio, opt => opt.MapFrom(f => f.D21StopLossRatio)) + .ForPath(t => t.D21Policy.CreateTime, opt => opt.MapFrom(f => f.D21CreateTime)) + .ForPath(t => t.D21Policy.ExecutionMode, opt => opt.MapFrom(f => f.D21ExecutionMode)); } } } diff --git a/Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml b/Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml index 4ce0f16..1b4e917 100644 --- a/Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml +++ b/Binance.TradeRobot.Model/Binance.TradeRobot.Model.xml @@ -59,14 +59,49 @@ U本位合约 - + 机器人状态 Stop=0,Runing=1 - 交易策略 动量趋势v2=2,金字塔=11 + 交易策略 动量趋势v2=0,动量趋势v21=1,金字塔=11 + + + + + 执行模式 Both=0,OnlyBuy=1,OnlySell=2 + + + + + Binance=0, Gate.io=1 + + + + + 币安 + + + + + 芝麻开门 + + + + + 借币状态 Loading=0 returned=1 + + + + + 订单状态 + + + + + 交易方向 Buy=0,Sell=1 @@ -94,6 +129,111 @@ 交易所账号Id + + + 交易所Id + + + + + 借币金额 + + + + + 借币利息 + + + + + 交易所Id + + + + + 历史利润 + + + + + 最后交易时间 + + + + + 交易策略 + + + + + 订单利润 + + + + + 成交总额 + + + + + 交易次数 + + + + + 手续费 + + + + + 交易手续费单位 + + + + + 成交均价 + + + + + 交易量 + + + + + 执行模式 + + + + + 是否开启增购 + + + + + 是否开启错误信号补救 + + + + + 最大追高比例 + + + + + 信号周期 + + + + + 仓位 + + + + + 止损比例 + + 杠杆倍数(1-125整数) @@ -139,6 +279,11 @@ 盈利次数 + + + 总借币金额 + + 投资本金 @@ -204,6 +349,36 @@ 交易策略 + + + 是否开启增购 + + + + + 是否开启错误信号补救 + + + + + 最大追高比例 + + + + + 信号周期 + + + + + 仓位 + + + + + 止损比例 + + 信号周期 diff --git a/Binance.TradeRobot.Model/Db/Exchange/ExchangeAccount.cs b/Binance.TradeRobot.Model/Db/Exchange/ExchangeAccount.cs index d04fced..5b6c0c2 100644 --- a/Binance.TradeRobot.Model/Db/Exchange/ExchangeAccount.cs +++ b/Binance.TradeRobot.Model/Db/Exchange/ExchangeAccount.cs @@ -37,6 +37,9 @@ namespace Binance.TradeRobot.Model.Db [Column(MapType = typeof(int))] public Enums.TradePolicy TradePolicy { get; set; } + [Column(MapType = typeof(int))] + public Enums.Exchange ExchangeId { get; set; } + } } diff --git a/Binance.TradeRobot.Model/Db/Order/ExecutionLog.cs b/Binance.TradeRobot.Model/Db/Order/ExecutionLog.cs new file mode 100644 index 0000000..41aac46 --- /dev/null +++ b/Binance.TradeRobot.Model/Db/Order/ExecutionLog.cs @@ -0,0 +1,24 @@ +using FreeSql.DataAnnotations; +using System; + +namespace Binance.TradeRobot.Model.Db +{ + + [Table(DisableSyncStructure = true)] + public partial class ExecutionLog { + + [ Column(IsPrimary = true)] + public long Id { get; set; } + + [Column(StringLength = 250, IsNullable = false)] + public string Content { get; set; } + + [Column(InsertValueSql = "getdate()")] + public DateTime CreateTime { get; set; } + + + public long RobotId { get; set; } + + } + +} diff --git a/Binance.TradeRobot.Model/Db/Order/LoanOrder.cs b/Binance.TradeRobot.Model/Db/Order/LoanOrder.cs new file mode 100644 index 0000000..05c59e1 --- /dev/null +++ b/Binance.TradeRobot.Model/Db/Order/LoanOrder.cs @@ -0,0 +1,54 @@ +using Binance.TradeRobot.Model.Base; +using FreeSql.DataAnnotations; +using System; + +namespace Binance.TradeRobot.Model.Db +{ + + [Table(DisableSyncStructure = true)] + public partial class LoanOrder + { + + [Column(IsPrimary = true)] + public long Id { get; set; } + + [Column(InsertValueSql = "getdate()")] + public DateTime CreateTime { get; set; } + + /// + /// 交易所Id + /// + + public int ExchangeId { get; set; } + + + [Column(MapType = typeof(int))] + public Enums.LoanState LoadState { get; set; } = Enums.LoanState.Loaning; + + /// + /// 借币金额 + /// + [Column(DbType = "decimal(18,8)")] + public decimal LoanAmount { get; set; } = 0.0M; + + /// + /// 借币利息 + /// + [Column(DbType = "decimal(18,8)")] + public decimal LoanFee { get; set; } = 0.0M; + + [Column(StringLength = 50, IsNullable = false)] + public string LoanOrderId { get; set; } + + + public DateTime ReturnTime { get; set; } + + + public long RobotId { get; set; } + + + public long SpotOrderId { get; set; } + + } + +} diff --git a/Binance.TradeRobot.Model/Db/Order/SpotOrder.cs b/Binance.TradeRobot.Model/Db/Order/SpotOrder.cs new file mode 100644 index 0000000..93dee84 --- /dev/null +++ b/Binance.TradeRobot.Model/Db/Order/SpotOrder.cs @@ -0,0 +1,99 @@ +using Binance.TradeRobot.Model.Base; +using FreeSql.DataAnnotations; +using System; + +namespace Binance.TradeRobot.Model.Db +{ + + [Table(DisableSyncStructure = true)] + public partial class SpotOrder + { + + [Column(IsPrimary = true)] + public long Id { get; set; } + + [Column(InsertValueSql = "getdate()")] + public DateTime CreateTime { get; set; } + + /// + /// 交易所Id + /// + + public int ExchangeId { get; set; } + + /// + /// 历史利润 + /// + [Column(DbType = "decimal(18,8)")] + public decimal HistoryTotalProfit { get; set; } = 0.0M; + + /// + /// 最后交易时间 + /// + + public DateTime? LastTradeTime { get; set; } + + /// + /// 交易策略 + /// + + public int PolicyType { get; set; } + + /// + /// 订单利润 + /// + [Column(DbType = "decimal(18,8)")] + public decimal Profit { get; set; } = 0.0M; + + + public long RobotId { get; set; } + + + [Column(MapType = typeof(int))] + public Enums.OrderState States { get; set; } + + [Column(MapType = typeof(int))] + public Enums.TradeDirection TradeDirection { get; set; } + + [Column(StringLength = 50, IsNullable = false)] + public string Symbol { get; set; } + + /// + /// 成交总额 + /// + [Column(DbType = "decimal(18,8)")] + public decimal TradeAmount { get; set; } = 0.0M; + + /// + /// 交易次数 + /// + + public int TradeCount { get; set; } = 0; + + /// + /// 手续费 + /// + [Column(DbType = "decimal(18,8)")] + public decimal TradeFee { get; set; } = 0.0M; + + /// + /// 交易手续费单位 + /// + [Column(StringLength = 15, IsNullable = false)] + public string TradeFeeUnit { get; set; } + + /// + /// 成交均价 + /// + [Column(DbType = "decimal(18,8)")] + public decimal TradePrice { get; set; } = 0.0M; + + /// + /// 交易量 + /// + [Column(DbType = "decimal(18,8)")] + public decimal TradeQuantity { get; set; } + + } + +} diff --git a/Binance.TradeRobot.Model/Db/Policy/Spot/D21Policy.cs b/Binance.TradeRobot.Model/Db/Policy/Spot/D21Policy.cs new file mode 100644 index 0000000..61492af --- /dev/null +++ b/Binance.TradeRobot.Model/Db/Policy/Spot/D21Policy.cs @@ -0,0 +1,63 @@ +using Binance.TradeRobot.Model.Base; +using FreeSql.DataAnnotations; +using System; + +namespace Binance.TradeRobot.Model.Db +{ + + [Table(DisableSyncStructure = true)] + public partial class D21Policy + { + + [Column(IsPrimary = true)] + public long Id { get; set; } + + [Column(InsertValueSql = "getdate()")] + public DateTime CreateTime { get; set; } + + /// + /// 执行模式 + /// + [Column(MapType = typeof(int))] + public Enums.ExecutionMode ExecutionMode { get; set; } = Enums.ExecutionMode.Both; + + /// + /// 是否开启增购 + /// + + public bool IsEnabledIncreasePurchase { get; set; } = true; + + /// + /// 是否开启错误信号补救 + /// + + public bool IsEnableRemedyForErrorCrossSignal { get; set; } = true; + + /// + /// 最大追高比例 + /// + [Column(DbType = "decimal(18,2)")] + public decimal MaxFollowPurchaseRatio { get; set; } = 0.0M; + + /// + /// 信号周期 + /// + + public Enums.SignalPeriod PeriodicSignal { get; set; } + + /// + /// 仓位 + /// + [Column(DbType = "decimal(18,8)")] + public decimal Position { get; set; } = 0.0M; + + + public long RobotId { get; set; } + + /// + /// 止损比例 + /// + public decimal StopLossRatio { get; set; } + } + +} diff --git a/Binance.TradeRobot.Model/Db/Robot/Robot.cs b/Binance.TradeRobot.Model/Db/Robot/Robot.cs index e361767..737d1e2 100644 --- a/Binance.TradeRobot.Model/Db/Robot/Robot.cs +++ b/Binance.TradeRobot.Model/Db/Robot/Robot.cs @@ -24,7 +24,7 @@ namespace Binance.TradeRobot.Model.Db public long RunningTime { get; set; } = 0; [Column(MapType = (typeof(int)))] - public Enums.RobotStatus State { get; set; } + public Enums.RobotState State { get; set; } [Column(StringLength = 50, IsNullable = false)] public string Symbol { get; set; } @@ -32,6 +32,99 @@ namespace Binance.TradeRobot.Model.Db [Column(MapType = (typeof(int)))] public Enums.BusinessType BusinessType { get; set; } - } + [Column(MapType = (typeof(int)))] + public Enums.Exchange ExchangeId { get; set; } + + #region RobotAccount Extension + + [Column(IsIgnore = true)] + public long RobotAccountId { get; set; } + + /// + /// 平仓次数 + /// + [Column(IsIgnore = true)] + public long ClosePositionCount { get; set; } = 0; + + /// + /// 现货/杠杆持仓金额 + /// + [Column(IsIgnore = true)] + public decimal SoptCurrentcyAmount { get; set; } = 0.0M; + + /// + /// 现货/杠杆持仓数量 + /// + [Column(IsIgnore = true)] + public decimal SpotCurrencyQuantity { get; set; } = 0.0M; + + /// + /// 总收益 + /// + [Column(IsIgnore = true)] + public decimal TotalProfit { get; set; } = 0.0M; + + /// + /// 盈利次数 + /// + [Column(IsIgnore = true)] + public long WinCount { get; set; } = 0; + + /// + /// 总借币金额 + /// + [Column(IsIgnore = true)] + public decimal LoanAmount { get; set; } = 0.0M; + #endregion + + #region D21Policy Extension + [Column(IsIgnore = true)] + public long D21PolicyId { get; set; } + /// + /// 执行模式 + /// + [Column(IsIgnore = true)] + public Enums.ExecutionMode D21ExecutionMode { get; set; } = Enums.ExecutionMode.Both; + + /// + /// 是否开启增购 + /// + [Column(IsIgnore = true)] + public bool D21IsEnabledIncreasePurchase { get; set; } = true; + + /// + /// 是否开启错误信号补救 + /// + [Column(IsIgnore = true)] + public bool D21IsEnableRemedyForErrorCrossSignal { get; set; } = true; + + /// + /// 最大追高比例 + /// + [Column(IsIgnore = true)] + public decimal D21MaxFollowPurchaseRatio { get; set; } = 0.0M; + + /// + /// 信号周期 + /// + [Column(IsIgnore = true)] + public Enums.SignalPeriod D21PeriodicSignal { get; set; } + + /// + /// 仓位 + /// + [Column(IsIgnore = true)] + public decimal D21Position { get; set; } = 0.0M; + + /// + /// 止损比例 + /// + [Column(IsIgnore = true)] + public decimal D21StopLossRatio { get; set; } + + [Column(IsIgnore = true)] + public DateTime D21CreateTime { get; set; } + #endregion + } } diff --git a/Binance.TradeRobot.Model/Db/Robot/RobotAccount.cs b/Binance.TradeRobot.Model/Db/Robot/RobotAccount.cs index 838922f..5b8b0e3 100644 --- a/Binance.TradeRobot.Model/Db/Robot/RobotAccount.cs +++ b/Binance.TradeRobot.Model/Db/Robot/RobotAccount.cs @@ -41,6 +41,23 @@ namespace Binance.TradeRobot.Model.Db /// public long WinCount { get; set; } = 0; + /// + /// 总借币金额 + /// + [Column(DbType = "decimal(18,8)")] + public decimal LoanAmount { get; set; } = 0.0M; + + /// + /// 现货持仓均价 + /// + [Column(IsIgnore = true)] + public decimal SpotCurrencyAcgPrice + { + get + { + return SpotCurrencyQuantity == 0M ? 0M : SoptCurrentcyAmount / SpotCurrencyQuantity; + } + } } } diff --git a/Binance.TradeRobot.Model/Db/User/UserAccountProfitLossRecord.cs b/Binance.TradeRobot.Model/Db/User/UserAccountProfitLossRecord.cs index 46b3e86..fb08e16 100644 --- a/Binance.TradeRobot.Model/Db/User/UserAccountProfitLossRecord.cs +++ b/Binance.TradeRobot.Model/Db/User/UserAccountProfitLossRecord.cs @@ -54,6 +54,9 @@ namespace Binance.TradeRobot.Model.Db [Column(DbType = "decimal(18,8)")] public decimal UserProfit { get; set; } = 0.0M; + [Column(MapType = (typeof(int)))] + public Enums.Exchange ExchangeId { get; set; } + } } diff --git a/Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAccountRequest.cs b/Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAccountRequest.cs index a4b5f7d..0dce341 100644 --- a/Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAccountRequest.cs +++ b/Binance.TradeRobot.Model/Dto/Request/Exchange/AddExchangeAccountRequest.cs @@ -8,6 +8,8 @@ namespace Binance.TradeRobot.Model.Dto public string LoginName { get; set; } + public Enums.Exchange ExchangeId { get; set; } + /// /// 交易策略 /// diff --git a/Binance.TradeRobot.Model/Dto/Request/Robot/AddD21PolicyRobotRequest.cs b/Binance.TradeRobot.Model/Dto/Request/Robot/AddD21PolicyRobotRequest.cs new file mode 100644 index 0000000..d0f84e5 --- /dev/null +++ b/Binance.TradeRobot.Model/Dto/Request/Robot/AddD21PolicyRobotRequest.cs @@ -0,0 +1,41 @@ +using Binance.TradeRobot.Model.Base; + +namespace Binance.TradeRobot.Model.Dto +{ + public class AddD21PolicyRobotRequest : AddRobotRequest + { + public Enums.ExecutionMode ExecutionMode { get; set; } = Enums.ExecutionMode.Both; + + /// + /// 是否开启增购 + /// + + public bool IsEnabledIncreasePurchase { get; set; } = true; + + /// + /// 是否开启错误信号补救 + /// + + public bool IsEnableRemedyForErrorCrossSignal { get; set; } = true; + + /// + /// 最大追高比例 + /// + public decimal MaxFollowPurchaseRatio { get; set; } = 0.0M; + + /// + /// 信号周期 + /// + public Enums.SignalPeriod PeriodicSignal { get; set; } + + /// + /// 仓位 + /// + public decimal Position { get; set; } = 0.0M; + + /// + /// 止损比例 + /// + public decimal StopLossRatio { get; set; } + } +} diff --git a/Binance.TradeRobot.Model/Dto/Request/Robot/AddRobotRequest.cs b/Binance.TradeRobot.Model/Dto/Request/Robot/AddRobotRequest.cs index e1f86fe..3b13762 100644 --- a/Binance.TradeRobot.Model/Dto/Request/Robot/AddRobotRequest.cs +++ b/Binance.TradeRobot.Model/Dto/Request/Robot/AddRobotRequest.cs @@ -13,5 +13,7 @@ namespace Binance.TradeRobot.Model.Dto /// 交易所APIKeyId /// public long ExchangeAPIKeyId { get; set; } + + public Enums.Exchange ExchangeId { get; set; } } } diff --git a/Binance.TradeRobot.Model/Dto/Response/Policy/D21PolicyResponse.cs b/Binance.TradeRobot.Model/Dto/Response/Policy/D21PolicyResponse.cs new file mode 100644 index 0000000..f7e71b3 --- /dev/null +++ b/Binance.TradeRobot.Model/Dto/Response/Policy/D21PolicyResponse.cs @@ -0,0 +1,8 @@ +using Binance.TradeRobot.Model.Db; + +namespace Binance.TradeRobot.Model.Dto +{ + public class D21PolicyResponse : D21Policy + { + } +} diff --git a/Binance.TradeRobot.Model/Dto/Response/Robot/D21PolicyRobotResponse.cs b/Binance.TradeRobot.Model/Dto/Response/Robot/D21PolicyRobotResponse.cs new file mode 100644 index 0000000..667a7a6 --- /dev/null +++ b/Binance.TradeRobot.Model/Dto/Response/Robot/D21PolicyRobotResponse.cs @@ -0,0 +1,7 @@ +namespace Binance.TradeRobot.Model.Dto +{ + public class D21PolicyRobotResponse : RobotResponse + { + public D21PolicyResponse D21Policy { get; set; } + } +} diff --git a/Binance.TradeRobot.Model/Dto/Response/Robot/RobotAccountResponse.cs b/Binance.TradeRobot.Model/Dto/Response/Robot/RobotAccountResponse.cs new file mode 100644 index 0000000..ecb090c --- /dev/null +++ b/Binance.TradeRobot.Model/Dto/Response/Robot/RobotAccountResponse.cs @@ -0,0 +1,8 @@ +using Binance.TradeRobot.Model.Db; + +namespace Binance.TradeRobot.Model.Dto +{ + public class RobotAccountResponse : RobotAccount + { + } +} diff --git a/Binance.TradeRobot.Model/Dto/Response/Robot/RobotResponse.cs b/Binance.TradeRobot.Model/Dto/Response/Robot/RobotResponse.cs new file mode 100644 index 0000000..f432d27 --- /dev/null +++ b/Binance.TradeRobot.Model/Dto/Response/Robot/RobotResponse.cs @@ -0,0 +1,27 @@ +using Binance.TradeRobot.Model.Base; +using System; + +namespace Binance.TradeRobot.Model.Dto +{ + public class RobotResponse + { + public long Id { get; set; } + public DateTime CreateTime { get; set; } + public Enums.TradePolicy TradePolicy { get; set; } + + /// + /// 运行时长(s) + /// + public long RunningTime { get; set; } = 0; + + public Enums.RobotState State { get; set; } + + public string Symbol { get; set; } + + public Enums.BusinessType BusinessType { get; set; } + + public Enums.Exchange ExchangeId { get; set; } + + public RobotAccountResponse RobotAccount { get; set; } + } +}