Commit 4305269b authored by Cranky Kernel's avatar Cranky Kernel

limit sell by price: respect tick size

Found limit sell price to respect tick size when placing
a limit order
parent f0cff8a1
......@@ -781,12 +781,24 @@ func (s *TradeService) limitSellByPrice(trade *types.Trade, price float64) error
}
s.addClientOrderId(trade, clientOrderId)
log.WithFields(log.Fields{
"price": fmt.Sprintf("%.8f", price),
"symbol": trade.State.Symbol,
"tradeId": trade.State.TradeID,
"quantity": trade.State.SellableQuantity,
}).Debugf("Posting limit sell order at price.")
tickSize, err := s.binanceExchangeInfo.GetTickSize(trade.State.Symbol)
if err != nil {
log.WithError(err).WithFields(log.Fields{
"symbol": trade.State.Symbol,
}).Errorf("Limit sell by price failed, no tick size for symbol")
return err
}
// Adjust price for tick size.
fixedPrice := util.Roundx(price, 1/tickSize)
logFields := log.Fields{
"price": fmt.Sprintf("%.8f", price),
"symbol": trade.State.Symbol,
"tradeId": trade.State.TradeID,
"quantity": trade.State.SellableQuantity,
"tickSizeAdjustedPrice": fmt.Sprintf("%.8f", fixedPrice),
}
order := binanceapi.OrderParameters{
Symbol: trade.State.Symbol,
......@@ -794,19 +806,17 @@ func (s *TradeService) limitSellByPrice(trade *types.Trade, price float64) error
Type: binanceapi.OrderTypeLimit,
TimeInForce: binanceapi.TimeInForceGTC,
Quantity: trade.State.SellableQuantity,
Price: price,
Price: fixedPrice,
NewClientOrderId: clientOrderId,
}
_, err = binanceex.GetBinanceRestClient().PostOrder(order)
if err != nil {
log.WithFields(log.Fields{}).WithError(err).Error("Failed to send sell order.")
log.WithFields(logFields).WithError(err).Error("Failed to send sell order.")
return err
}
log.WithFields(log.Fields{
"price": price,
"symbol": trade.State.Symbol,
"tradeId": trade.State.TradeID,
}).Info("Sell order posted.")
log.WithFields(logFields).Infof("Posting limit sell order at price")
db.DbUpdateTrade(trade)
return nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment