Skip to content

Commit f4183aa

Browse files
committed
[binance] calculate the order average price
1 parent 02204a5 commit f4183aa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

binance/Binance.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,22 @@ func (bn *Binance) adaptOrder(currencyPair CurrencyPair, orderMap map[string]int
651651
orderSide = BUY
652652
}
653653

654+
quoteQty := ToFloat64(orderMap["cummulativeQuoteQty"])
655+
qty := ToFloat64(orderMap["executedQty"])
656+
avgPrice := 0.0
657+
if qty > 0 {
658+
avgPrice = FloatToFixed(quoteQty/qty, 8)
659+
}
660+
654661
return Order{
655662
OrderID: ToInt(orderMap["orderId"]),
656-
OrderID2: fmt.Sprintf("%.0f",orderMap["orderId"]),
663+
OrderID2: fmt.Sprintf("%.0f", orderMap["orderId"]),
657664
Cid: orderMap["clientOrderId"].(string),
658665
Currency: currencyPair,
659666
Price: ToFloat64(orderMap["price"]),
660667
Amount: ToFloat64(orderMap["origQty"]),
661668
DealAmount: ToFloat64(orderMap["executedQty"]),
662-
AvgPrice: FloatToFixed(ToFloat64(orderMap["cummulativeQuoteQty"])/ToFloat64(orderMap["executedQty"]), 8),
669+
AvgPrice: avgPrice,
663670
Side: TradeSide(orderSide),
664671
Status: adaptOrderStatus(orderMap["status"].(string)),
665672
OrderTime: ToInt(orderMap["time"]),

0 commit comments

Comments
 (0)