|
|
@ -124,7 +124,7 @@ namespace Binance.TradeRobot.Business |
|
|
|
var diffRatio = Math.Round((newestPrice / d21RuningInfo.RecentShortCrossSignalTradePrice.Value - 1) * 100, 2); |
|
|
|
if (diffRatio > d21Robot.D21Policy.MaxFollowPurchaseRatio) |
|
|
|
{ |
|
|
|
throw new BusinessException($"触发限制追高,最近空交叉成交价{d21RuningInfo.RecentShortCrossSignalTradePrice},当前价格{newestPrice},追高比例{d21Robot.D21Policy.MaxFollowPurchaseRatio}%,当前比例{diffRatio}%,终止多交叉信号执行"); |
|
|
|
throw new BusinessException($"触发追高限制,最近空交叉成交价{d21RuningInfo.RecentShortCrossSignalTradePrice},当前价格{newestPrice},最大追高比例{d21Robot.D21Policy.MaxFollowPurchaseRatio}%,当前追高比例{diffRatio}%,终止多交叉信号执行"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
@ -134,10 +134,65 @@ namespace Binance.TradeRobot.Business |
|
|
|
var apiClient = GetBaseAPIClient(robot.ExchangeId, robot.ExchangeAPIKey.AccountId, robot.ExchangeAPIKey.APIKey, robot.ExchangeAPIKey.SecretKey); |
|
|
|
//逐仓杠杆账户余额
|
|
|
|
var balance = apiClient.GetIsolatedMarginAccountAssets().FirstOrDefault(m => m.Symbol == robot.Symbol)?.QuoteFree ?? 0M; |
|
|
|
if (balance == 0M) |
|
|
|
throw new BusinessException("可用资产为0"); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 计算下单数量
|
|
|
|
step = "计算下单数量"; |
|
|
|
var diffAmount = 0M; //借币金额
|
|
|
|
var previewTradeAmount = d21Robot.D21Policy.Position; //预估交易额
|
|
|
|
if (balance < previewTradeAmount) |
|
|
|
{ |
|
|
|
#region 借币
|
|
|
|
step = "借币"; |
|
|
|
diffAmount = previewTradeAmount - balance; |
|
|
|
var diffRatio = diffAmount / balance * 100; //借币比例
|
|
|
|
|
|
|
|
#region 验证策略中的最大借币比例
|
|
|
|
if (diffRatio > d21Robot.D21Policy.MaxExchangeLoanRatio) |
|
|
|
{ |
|
|
|
logList.Add(new ExecutionLog() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
SourceSingal = Enums.SingalType.多交叉, |
|
|
|
RobotId = robot.Id, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Content = $"触发策略中交易所最大借币比例限制,交易所最大借币比例{d21Robot.D21Policy.MaxExchangeLoanRatio}%,当前借币比例{diffRatio}%,按交易所最大借币比例借币" |
|
|
|
}); |
|
|
|
diffAmount = previewTradeAmount * (d21Robot.D21Policy.MaxExchangeLoanRatio / 100M); |
|
|
|
//previewTradeAmount = balance + diffAmount; //在策略允许的借币比例范围内的最大下单金额
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 验证交易所的最大可借额度
|
|
|
|
try |
|
|
|
{ |
|
|
|
var exchangeMaxLoanAmount = apiClient.QueryMaxLoanAmount(robot.Symbol); |
|
|
|
if (exchangeMaxLoanAmount < diffAmount) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception borrowex) |
|
|
|
{ |
|
|
|
logList.Add(new ExecutionLog() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
SourceSingal = Enums.SingalType.多交叉, |
|
|
|
RobotId = robot.Id, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
Content = $"验证交易所的最大可借额度失败 {borrowex.Message}" |
|
|
|
}); |
|
|
|
previewTradeAmount = balance; //无法借币,使用余额下单
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 下单
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|