Browse Source

止损挂单

master
shanji 3 years ago
parent
commit
6e49c39382
  1. 6
      Binance.TradeRobot.Business/Business/ExchangeBusiness.cs
  2. 2
      Binance.TradeRobot.Business/Business/OrderPublishBusiness/Spot/D21OrderPublishBusiness.cs
  3. 6
      Binance.TradeRobot.Model/Db/Exchange/SymbolInfo.cs

6
Binance.TradeRobot.Business/Business/ExchangeBusiness.cs

@ -46,14 +46,17 @@ namespace Binance.TradeRobot.Business
if (!symbol.EndsWith("USDT")) if (!symbol.EndsWith("USDT"))
continue; continue;
var stepSize = jtoken_symbol["filters"]?.FirstOrDefault(jtoken_filters => jtoken_filters.Value<string>("filterType") == "LOT_SIZE")?.Value<decimal>("stepSize") ?? 0M; var stepSize = jtoken_symbol["filters"]?.FirstOrDefault(jtoken_filters => jtoken_filters.Value<string>("filterType") == "LOT_SIZE")?.Value<decimal>("stepSize") ?? 0M;
var tickSize = jtoken_symbol["filters"]?.FirstOrDefault(jtoken_filters => jtoken_filters.Value<string>("filterType") == "PRICE_FILTER")?.Value<decimal>("tickSize") ?? 0M;
var saleAccuracy = stepSize != 0 ? (1 / stepSize).ToString().Length - 1 : 0; var saleAccuracy = stepSize != 0 ? (1 / stepSize).ToString().Length - 1 : 0;
var priceAccuracy = tickSize != 0 ? (1 / tickSize).ToString().Length - 1 : 0;
var symbolInfo = new SymbolInfo() var symbolInfo = new SymbolInfo()
{ {
Id = idGenerator.NewLong(), Id = idGenerator.NewLong(),
ExchangeId = Enums.Exchange.Binance, ExchangeId = Enums.Exchange.Binance,
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
Symbol = symbol, Symbol = symbol,
SaleQuantityAccuracy = saleAccuracy SaleQuantityAccuracy = saleAccuracy,
PriceAccuracy = priceAccuracy
}; };
symbolList.Add(symbolInfo); symbolList.Add(symbolInfo);
} }
@ -79,7 +82,6 @@ namespace Binance.TradeRobot.Business
return fsql.Select<SymbolInfo>().Where(s => s.ExchangeId == exchange && s.Symbol == symbol).ToOne<SymbolInfoResponse>(); return fsql.Select<SymbolInfo>().Where(s => s.ExchangeId == exchange && s.Symbol == symbol).ToOne<SymbolInfoResponse>();
} }
public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest) public void AddExchangeAccount(AddExchangeAccountRequest addExchangeAccountRequest)
{ {
if (addExchangeAccountRequest.Id == 0 || if (addExchangeAccountRequest.Id == 0 ||

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

@ -276,7 +276,7 @@ namespace Binance.TradeRobot.Business
var positionStopLossRatio = (isFirstStopLoss ? d21Robot.D21Policy.Level1PositionStopLossRatio : d21Robot.D21Policy.Level2PositionStopLossRatio) / 100; var positionStopLossRatio = (isFirstStopLoss ? d21Robot.D21Policy.Level1PositionStopLossRatio : d21Robot.D21Policy.Level2PositionStopLossRatio) / 100;
var priceStopLossRatio = (isFirstStopLoss ? d21Robot.D21Policy.Level1PriceStopLossRatio : d21Robot.D21Policy.Level2PriceStopLossRatio) / 100; var priceStopLossRatio = (isFirstStopLoss ? d21Robot.D21Policy.Level1PriceStopLossRatio : d21Robot.D21Policy.Level2PriceStopLossRatio) / 100;
var stopPrice = avgTradePrice - avgTradePrice * priceStopLossRatio; var stopPrice = (avgTradePrice - avgTradePrice * priceStopLossRatio).CutDecimal(symbolInfo.PriceAccuracy);
var stopQuantity = (buyQuantity * positionStopLossRatio).CutDecimal(symbolInfo.SaleQuantityAccuracy); var stopQuantity = (buyQuantity * positionStopLossRatio).CutDecimal(symbolInfo.SaleQuantityAccuracy);
var stopLossClientOrderId = CreateClientOrderId(d21Robot.Id, d21Robot.TradePolicy); var stopLossClientOrderId = CreateClientOrderId(d21Robot.Id, d21Robot.TradePolicy);
var stopOrderId = baseAPIClient.IsolatedMarginPlaceOrder(d21Robot.Symbol, var stopOrderId = baseAPIClient.IsolatedMarginPlaceOrder(d21Robot.Symbol,

6
Binance.TradeRobot.Model/Db/Exchange/SymbolInfo.cs

@ -24,6 +24,12 @@ namespace Binance.TradeRobot.Model.Db
[Column(DbType = "int")] [Column(DbType = "int")]
public int SaleQuantityAccuracy { get; set; } public int SaleQuantityAccuracy { get; set; }
/// <summary>
/// 价格精度
/// </summary>
[Column(DbType = "int")]
public int PriceAccuracy { get; set; }
[Column(StringLength = 50)] [Column(StringLength = 50)]
public string Symbol { get; set; } public string Symbol { get; set; }

Loading…
Cancel
Save