Exchanges: enrich order history with avg executed price, cost, and more (#792)

* Exchanges: enrich order history with avg executed price, cost, and more

* Fix division by zero in order detail enrichment

* Remove DateCompleted from Bithumb OrderData and fix OrderDate parsing

* Fixes on order detail fields and rename EnrichOrderDetail to CalculateCostsAndAmounts

* BTSE order history populate name and id

* Calculate average executed price for market order or when order amount is zero

* Minor fixes on infer order amounts, costs, and times

* Attach InferAmountsCostsAndTimes to Order.Detail

* Binance: fix order status

* Always use order.StringToOrderStatus() and ensure order has at least one of executed/remaining amount set
This commit is contained in:
khcchiu
2021-10-26 08:22:30 +08:00
committed by GitHub
parent 6345014612
commit 8617b50ff6
33 changed files with 556 additions and 259 deletions

View File

@@ -614,6 +614,10 @@ func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest
}
side := order.Side(strings.ToUpper(allOrders[j].Side))
status, err := order.StringToOrderStatus(allOrders[j].Status)
if err != nil {
log.Errorf(log.ExchangeSys, "%s %v", i.Name, err)
}
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
if err != nil {
log.Errorf(log.ExchangeSys,
@@ -624,16 +628,21 @@ func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequest
allOrders[j].CreatedTime)
}
orders = append(orders, order.Detail{
ID: allOrders[j].ID,
Side: side,
Amount: allOrders[j].Amount,
ExecutedAmount: allOrders[j].AmountFilled,
RemainingAmount: (allOrders[j].Amount - allOrders[j].AmountFilled),
Exchange: i.Name,
Date: orderDate,
Pair: symbol,
})
detail := order.Detail{
ID: allOrders[j].ID,
Side: side,
Status: status,
Amount: allOrders[j].Amount,
ExecutedAmount: allOrders[j].AmountFilled,
RemainingAmount: allOrders[j].Amount - allOrders[j].AmountFilled,
Price: allOrders[j].Price,
AverageExecutedPrice: allOrders[j].VolumeWeightedAveragePrice,
Exchange: i.Name,
Date: orderDate,
Pair: symbol,
}
detail.InferCostsAndTimes()
orders = append(orders, detail)
}
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)