mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
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:
@@ -127,18 +127,17 @@ type Orders struct {
|
||||
|
||||
// OrderData contains all individual order details
|
||||
type OrderData struct {
|
||||
OrderID string `json:"order_id"`
|
||||
OrderCurrency string `json:"order_currency"`
|
||||
OrderDate int64 `json:"order_date"`
|
||||
PaymentCurrency string `json:"payment_currency"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Units float64 `json:"units,string"`
|
||||
UnitsRemaining float64 `json:"units_remaining,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
Fee float64 `json:"fee,string"`
|
||||
Total float64 `json:"total,string"`
|
||||
DateCompleted int64 `json:"date_completed"`
|
||||
OrderID string `json:"order_id"`
|
||||
OrderCurrency string `json:"order_currency"`
|
||||
OrderDate bithumbTime `json:"order_date"`
|
||||
PaymentCurrency string `json:"payment_currency"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
Units float64 `json:"units,string"`
|
||||
UnitsRemaining float64 `json:"units_remaining,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
Fee float64 `json:"fee,string"`
|
||||
Total float64 `json:"total,string"`
|
||||
}
|
||||
|
||||
// UserTransactions holds users full transaction list
|
||||
|
||||
@@ -692,12 +692,12 @@ func (b *Bithumb) GetActiveOrders(ctx context.Context, req *order.GetOrdersReque
|
||||
continue
|
||||
}
|
||||
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
Exchange: b.Name,
|
||||
ExecutedAmount: resp.Data[i].Units - resp.Data[i].UnitsRemaining,
|
||||
ID: resp.Data[i].OrderID,
|
||||
Date: orderDate,
|
||||
Date: resp.Data[i].OrderDate.Time(),
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Status: order.Active,
|
||||
@@ -750,14 +750,14 @@ func (b *Bithumb) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
|
||||
continue
|
||||
}
|
||||
|
||||
orderDate := time.Unix(resp.Data[i].OrderDate, 0)
|
||||
orderDetail := order.Detail{
|
||||
Amount: resp.Data[i].Units,
|
||||
ExecutedAmount: resp.Data[i].Units - resp.Data[i].UnitsRemaining,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Exchange: b.Name,
|
||||
ID: resp.Data[i].OrderID,
|
||||
Date: orderDate,
|
||||
Date: resp.Data[i].OrderDate.Time(),
|
||||
Price: resp.Data[i].Price,
|
||||
RemainingAmount: resp.Data[i].UnitsRemaining,
|
||||
Pair: currency.NewPairWithDelimiter(resp.Data[i].OrderCurrency,
|
||||
resp.Data[i].PaymentCurrency,
|
||||
format.Delimiter),
|
||||
@@ -769,6 +769,7 @@ func (b *Bithumb) GetOrderHistory(ctx context.Context, req *order.GetOrdersReque
|
||||
orderDetail.Side = order.Sell
|
||||
}
|
||||
|
||||
orderDetail.InferCostsAndTimes()
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user