mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 23:07:01 +08:00
feat(kucoin): add order sync and fix price precision
- Add KuCoin order sync with proper API response parsing - Use openFeePay/closeFeePay to determine open/close trades - Get contract multiplier from API for accurate qty calculation - Fix price rounding: 2 decimals -> 8 decimals for low-price coins - Add comprehensive tests for trades, positions, and P&L
This commit is contained in:
@@ -156,7 +156,8 @@ func (s *PositionStore) UpdatePositionQuantityAndPrice(id int64, addQty float64,
|
||||
newQty := math.Round((pos.Quantity+addQty)*10000) / 10000
|
||||
newEntryQty := math.Round((currentEntryQty+addQty)*10000) / 10000
|
||||
newEntryPrice := (pos.EntryPrice*pos.Quantity + addPrice*addQty) / newQty
|
||||
newEntryPrice = math.Round(newEntryPrice*100) / 100
|
||||
// Use 8 decimal places for price precision (crypto standard)
|
||||
newEntryPrice = math.Round(newEntryPrice*100000000) / 100000000
|
||||
newFee := pos.Fee + addFee
|
||||
nowMs := time.Now().UTC().UnixMilli()
|
||||
|
||||
@@ -187,7 +188,8 @@ func (s *PositionStore) ReducePositionQuantity(id int64, reduceQty float64, exit
|
||||
var newExitPrice float64
|
||||
if newClosedQty > 0 {
|
||||
newExitPrice = (pos.ExitPrice*closedQty + exitPrice*reduceQty) / newClosedQty
|
||||
newExitPrice = math.Round(newExitPrice*100) / 100
|
||||
// Use 8 decimal places for price precision (crypto standard)
|
||||
newExitPrice = math.Round(newExitPrice*100000000) / 100000000
|
||||
}
|
||||
|
||||
nowMs := time.Now().UTC().UnixMilli()
|
||||
|
||||
@@ -147,7 +147,8 @@ func (pb *PositionBuilder) handleClose(
|
||||
var finalExitPrice float64
|
||||
if totalClosed > 0 {
|
||||
finalExitPrice = (position.ExitPrice*closedBefore + price*closeQty) / totalClosed
|
||||
finalExitPrice = math.Round(finalExitPrice*100) / 100
|
||||
// Use 8 decimal places for price precision (crypto standard)
|
||||
finalExitPrice = math.Round(finalExitPrice*100000000) / 100000000
|
||||
} else {
|
||||
finalExitPrice = price
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user