Browse Source

空交叉取消限价单再卖出

master
shanji 3 years ago
parent
commit
924ccf2203
  1. 50
      Binance.TradeRobot.Business/Business/OrderPublishBusiness/Spot/D21OrderPublishBusiness.cs
  2. 16
      Binance.TradeRobot.Business/Business/TradeBusiness/BaseTradeBusiness.cs
  3. 6
      Binance.TradeRobot.Business/Business/TradeBusiness/Spot/D21TradeBusiness.cs
  4. 2
      SDKAdapter/APIClient/BinanceAPIClient.cs

50
Binance.TradeRobot.Business/Business/OrderPublishBusiness/Spot/D21OrderPublishBusiness.cs

@ -134,25 +134,25 @@ namespace Binance.TradeRobot.Business
updateUserList = new List<IUpdate<User>>(); updateUserList = new List<IUpdate<User>>();
insertUserAccountProfitLossRecordList = new List<UserAccountProfitLossRecord>(); insertUserAccountProfitLossRecordList = new List<UserAccountProfitLossRecord>();
if (spotOrderPublishInfo.OrderType == Enums.OrderType.MARKET) //if (spotOrderPublishInfo.OrderType == Enums.OrderType.MARKET)
{ //{
//市价卖单完全成交,取消尚未触发的限价止损单 //市价卖单完全成交,取消尚未触发的限价止损单
try //try
{ //{
CancelStopLossOrder(robot, apiClient); // CancelStopLossOrder(robot, apiClient);
} //}
catch (Exception ex) //catch (Exception ex)
{ //{
logList.Add(new ExecutionLog() // logList.Add(new ExecutionLog()
{ // {
Id = idGenerator.NewLong(), // Id = idGenerator.NewLong(),
SourceSingal = Enums.SingalType., // SourceSingal = Enums.SingalType.订单推送,
RobotId = robot.Id, // RobotId = robot.Id,
CreateTime = DateTime.Now, // CreateTime = DateTime.Now,
Content = $"取消止损单失败,{ex.Message}" // Content = $"取消止损单失败,{ex.Message}"
}); // });
} //}
} //}
var interest = 0M; //借币利息 var interest = 0M; //借币利息
var loanAmount = robot.RobotAccount.LoanAmount; //借币金额 var loanAmount = robot.RobotAccount.LoanAmount; //借币金额
@ -297,17 +297,5 @@ namespace Binance.TradeRobot.Business
Content = $"{(isFirstStopLoss ? 1 : 2)}级止损挂单成功,订单号:{stopOrderId},挂单数量:{stopQuantity}" Content = $"{(isFirstStopLoss ? 1 : 2)}级止损挂单成功,订单号:{stopOrderId},挂单数量:{stopQuantity}"
}); });
} }
private void CancelStopLossOrder(D21PolicyRobotResponse d21Robot, BaseAPIClient baseAPIClient)
{
var stopLossOrderIdList = fsql.Select<SpotOrder>().Where(o => o.OrderType == Enums.OrderType.STOP_LOSS_LIMIT &&
o.State == Enums.SpotOrderState.Created &&
o.RobotId == d21Robot.Id).ToList(o => o.Id);
if (stopLossOrderIdList == null || stopLossOrderIdList.Count() == 0)
return;
foreach (var stopLossOrderId in stopLossOrderIdList)
baseAPIClient.CancelIsolateMarginOrder(d21Robot.Symbol, stopLossOrderId);
}
} }
} }

16
Binance.TradeRobot.Business/Business/TradeBusiness/BaseTradeBusiness.cs

@ -2,8 +2,10 @@
using Binance.TradeRobot.Model.Db; using Binance.TradeRobot.Model.Db;
using Binance.TradeRobot.Model.Dto; using Binance.TradeRobot.Model.Dto;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using SDKAdapter.APIClient;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using Yitter.IdGenerator; using Yitter.IdGenerator;
@ -53,5 +55,19 @@ namespace Binance.TradeRobot.Business
var random = new Random(guid.GetHashCode()); var random = new Random(guid.GetHashCode());
return $"{Convert.ToChar(random.Next(97, 123))}{guid.ToString().Substring(0, 4)}_{robotId}_{(int)tradePolicy}"; return $"{Convert.ToChar(random.Next(97, 123))}{guid.ToString().Substring(0, 4)}_{robotId}_{(int)tradePolicy}";
} }
protected void CancelStopLossOrder(RobotResponse d21Robot, BaseAPIClient baseAPIClient = null)
{
if (baseAPIClient == null)
baseAPIClient = GetBaseAPIClient(d21Robot.ExchangeId, d21Robot.ExchangeAPIKey.AccountId, d21Robot.ExchangeAPIKey.APIKey, d21Robot.ExchangeAPIKey.SecretKey);
var stopLossOrderIdList = fsql.Select<SpotOrder>().Where(o => o.OrderType == Enums.OrderType.STOP_LOSS_LIMIT &&
o.State == Enums.SpotOrderState.Created &&
o.RobotId == d21Robot.Id).ToList(o => o.Id);
if (stopLossOrderIdList == null || stopLossOrderIdList.Count() == 0)
return;
foreach (var stopLossOrderId in stopLossOrderIdList)
baseAPIClient.CancelIsolateMarginOrder(d21Robot.Symbol, stopLossOrderId);
}
} }
} }

6
Binance.TradeRobot.Business/Business/TradeBusiness/Spot/D21TradeBusiness.cs

@ -304,8 +304,14 @@ namespace Binance.TradeRobot.Business
} }
#endregion #endregion
#region 取消止损限价单
step = "取消止损限价单";
CancelStopLossOrder(robot);
#endregion
#region 验证卖币数量 #region 验证卖币数量
step = "验证卖币数量"; step = "验证卖币数量";
Thread.Sleep(1000);
var saleQuantity = robot.RobotAccount.SpotCurrencyQuantity.CutDecimal(symbolInfo.SaleQuantityAccuracy); var saleQuantity = robot.RobotAccount.SpotCurrencyQuantity.CutDecimal(symbolInfo.SaleQuantityAccuracy);
if (saleQuantity == 0M) if (saleQuantity == 0M)
throw new BusinessException("没有足够的卖币数量"); throw new BusinessException("没有足够的卖币数量");

2
SDKAdapter/APIClient/BinanceAPIClient.cs

@ -137,7 +137,7 @@ namespace SDKAdapter.APIClient
public override void CancelIsolateMarginOrder(string symbol, long orderId) public override void CancelIsolateMarginOrder(string symbol, long orderId)
{ {
_ = binanceClient.SpotApi.Trading.CancelMarginOrderAsync(symbol, orderId, isIsolated: true); _ = binanceClient.SpotApi.Trading.CancelMarginOrderAsync(symbol, orderId, isIsolated: true).Result;
} }
} }
} }

Loading…
Cancel
Save