Skip to content

Commit

Permalink
[binance] calculate the order average price
Browse files Browse the repository at this point in the history
  • Loading branch information
nntaoli committed Feb 28, 2021
1 parent 02204a5 commit f4183aa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions binance/Binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,22 @@ func (bn *Binance) adaptOrder(currencyPair CurrencyPair, orderMap map[string]int
orderSide = BUY
}

quoteQty := ToFloat64(orderMap["cummulativeQuoteQty"])
qty := ToFloat64(orderMap["executedQty"])
avgPrice := 0.0
if qty > 0 {
avgPrice = FloatToFixed(quoteQty/qty, 8)
}

return Order{
OrderID: ToInt(orderMap["orderId"]),
OrderID2: fmt.Sprintf("%.0f",orderMap["orderId"]),
OrderID2: fmt.Sprintf("%.0f", orderMap["orderId"]),
Cid: orderMap["clientOrderId"].(string),
Currency: currencyPair,
Price: ToFloat64(orderMap["price"]),
Amount: ToFloat64(orderMap["origQty"]),
DealAmount: ToFloat64(orderMap["executedQty"]),
AvgPrice: FloatToFixed(ToFloat64(orderMap["cummulativeQuoteQty"])/ToFloat64(orderMap["executedQty"]), 8),
AvgPrice: avgPrice,
Side: TradeSide(orderSide),
Status: adaptOrderStatus(orderMap["status"].(string)),
OrderTime: ToInt(orderMap["time"]),
Expand Down

0 comments on commit f4183aa

Please sign in to comment.