mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 23:16:53 +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:
@@ -291,18 +291,18 @@ type Order struct {
|
||||
ClOrdID string `json:"clOrdID"`
|
||||
ClOrdLinkID string `json:"clOrdLinkID"`
|
||||
ContingencyType string `json:"contingencyType"`
|
||||
CumQty int64 `json:"cumQty"`
|
||||
CumQty float64 `json:"cumQty"`
|
||||
Currency string `json:"currency"`
|
||||
DisplayQuantity int64 `json:"displayQty"`
|
||||
ExDestination string `json:"exDestination"`
|
||||
ExecInst string `json:"execInst"`
|
||||
LeavesQty int64 `json:"leavesQty"`
|
||||
LeavesQty float64 `json:"leavesQty"`
|
||||
MultiLegReportingType string `json:"multiLegReportingType"`
|
||||
OrdRejReason string `json:"ordRejReason"`
|
||||
OrdStatus string `json:"ordStatus"`
|
||||
OrdType int64 `json:"ordType,string"`
|
||||
OrderID string `json:"orderID"`
|
||||
OrderQty int64 `json:"orderQty"`
|
||||
OrderQty float64 `json:"orderQty"`
|
||||
PegOffsetValue float64 `json:"pegOffsetValue"`
|
||||
PegPriceType string `json:"pegPriceType"`
|
||||
Price float64 `json:"price"`
|
||||
@@ -316,7 +316,7 @@ type Order struct {
|
||||
Text string `json:"text"`
|
||||
TimeInForce string `json:"timeInForce"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
TransactTime string `json:"transactTime"`
|
||||
TransactTime time.Time `json:"transactTime"`
|
||||
Triggered string `json:"triggered"`
|
||||
WorkingIndicator bool `json:"workingIndicator"`
|
||||
}
|
||||
|
||||
@@ -748,20 +748,26 @@ func (b *Bitmex) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
for i := range resp {
|
||||
orderSide := orderSideMap[resp[i].Side]
|
||||
orderStatus, err := order.StringToOrderStatus(resp[i].OrdStatus)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
orderType := orderTypeMap[resp[i].OrdType]
|
||||
if orderType == "" {
|
||||
orderType = order.UnknownType
|
||||
}
|
||||
|
||||
orderDetail := order.Detail{
|
||||
Date: resp[i].Timestamp,
|
||||
Price: resp[i].Price,
|
||||
Amount: float64(resp[i].OrderQty),
|
||||
Exchange: b.Name,
|
||||
ID: resp[i].OrderID,
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Status: order.Status(resp[i].OrdStatus),
|
||||
Date: resp[i].Timestamp,
|
||||
Price: resp[i].Price,
|
||||
Amount: resp[i].OrderQty,
|
||||
ExecutedAmount: resp[i].CumQty,
|
||||
RemainingAmount: resp[i].LeavesQty,
|
||||
Exchange: b.Name,
|
||||
ID: resp[i].OrderID,
|
||||
Side: orderSide,
|
||||
Status: orderStatus,
|
||||
Type: orderType,
|
||||
Pair: currency.NewPairWithDelimiter(resp[i].Symbol,
|
||||
resp[i].SettlCurrency,
|
||||
format.Delimiter),
|
||||
@@ -799,23 +805,32 @@ func (b *Bitmex) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
|
||||
|
||||
for i := range resp {
|
||||
orderSide := orderSideMap[resp[i].Side]
|
||||
orderStatus, err := order.StringToOrderStatus(resp[i].OrdStatus)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", b.Name, err)
|
||||
}
|
||||
orderType := orderTypeMap[resp[i].OrdType]
|
||||
if orderType == "" {
|
||||
orderType = order.UnknownType
|
||||
}
|
||||
pair := currency.NewPairWithDelimiter(resp[i].Symbol, resp[i].SettlCurrency, format.Delimiter)
|
||||
|
||||
orderDetail := order.Detail{
|
||||
Price: resp[i].Price,
|
||||
Amount: float64(resp[i].OrderQty),
|
||||
Exchange: b.Name,
|
||||
ID: resp[i].OrderID,
|
||||
Side: orderSide,
|
||||
Type: orderType,
|
||||
Status: order.Status(resp[i].OrdStatus),
|
||||
Pair: currency.NewPairWithDelimiter(resp[i].Symbol,
|
||||
resp[i].SettlCurrency,
|
||||
format.Delimiter),
|
||||
Price: resp[i].Price,
|
||||
AverageExecutedPrice: resp[i].AvgPx,
|
||||
Amount: resp[i].OrderQty,
|
||||
ExecutedAmount: resp[i].CumQty,
|
||||
RemainingAmount: resp[i].LeavesQty,
|
||||
Date: resp[i].TransactTime,
|
||||
CloseTime: resp[i].Timestamp,
|
||||
Exchange: b.Name,
|
||||
ID: resp[i].OrderID,
|
||||
Side: orderSide,
|
||||
Status: orderStatus,
|
||||
Type: orderType,
|
||||
Pair: pair,
|
||||
}
|
||||
orderDetail.InferCostsAndTimes()
|
||||
|
||||
orders = append(orders, orderDetail)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user