From e6e905257a20e84a50fc2b5511fad22478af2c5c Mon Sep 17 00:00:00 2001 From: wspi Date: Sun, 26 Jul 2020 17:31:53 -0300 Subject: [PATCH 1/2] adding support for cummulative quote qtdy on ExecutedOrder struct --- binance.go | 27 ++++++++++--------- service_account.go | 58 +++++++++++++++++++++++------------------ service_account_test.go | 23 ++++++++-------- 3 files changed, 58 insertions(+), 50 deletions(-) diff --git a/binance.go b/binance.go index 8b6b983..cc33866 100644 --- a/binance.go +++ b/binance.go @@ -297,19 +297,20 @@ type QueryOrderRequest struct { // ExecutedOrder represents data about executed order. type ExecutedOrder struct { - Symbol string - OrderID int - ClientOrderID string - Price float64 - OrigQty float64 - ExecutedQty float64 - Status OrderStatus - TimeInForce TimeInForce - Type OrderType - Side OrderSide - StopPrice float64 - IcebergQty float64 - Time time.Time + Symbol string + OrderID int + ClientOrderID string + CummulativeQuoteQty float64 + Price float64 + OrigQty float64 + ExecutedQty float64 + Status OrderStatus + TimeInForce TimeInForce + Type OrderType + Side OrderSide + StopPrice float64 + IcebergQty float64 + Time time.Time } // QueryOrder returns data about existing order. diff --git a/service_account.go b/service_account.go index 508bf17..c0c7556 100644 --- a/service_account.go +++ b/service_account.go @@ -9,19 +9,20 @@ import ( ) type rawExecutedOrder struct { - Symbol string `json:"symbol"` - OrderID int `json:"orderId"` - ClientOrderID string `json:"clientOrderId"` - Price string `json:"price"` - OrigQty string `json:"origQty"` - ExecutedQty string `json:"executedQty"` - Status string `json:"status"` - TimeInForce string `json:"timeInForce"` - Type string `json:"type"` - Side string `json:"side"` - StopPrice string `json:"stopPrice"` - IcebergQty string `json:"icebergQty"` - Time float64 `json:"time"` + Symbol string `json:"symbol"` + OrderID int `json:"orderId"` + ClientOrderID string `json:"clientOrderId"` + CummulativeQuoteQty string `json:"cummulativeQuoteQty"` + Price string `json:"price"` + OrigQty string `json:"origQty"` + ExecutedQty string `json:"executedQty"` + Status string `json:"status"` + TimeInForce string `json:"timeInForce"` + Type string `json:"type"` + Side string `json:"side"` + StopPrice string `json:"stopPrice"` + IcebergQty string `json:"icebergQty"` + Time float64 `json:"time"` } func (as *apiService) NewOrder(or NewOrderRequest) (*ProcessedOrder, error) { @@ -625,20 +626,25 @@ func executedOrderFromRaw(reo *rawExecutedOrder) (*ExecutedOrder, error) { if err != nil { return nil, errors.Wrap(err, "cannot parse Order.CloseTime") } + cummulativeQuoteQty, err := strconv.ParseFloat(reo.CummulativeQuoteQty, 64) + if err != nil { + return nil, errors.Wrap(err, "cannot parse Order.CummulativeQuoteQty") + } return &ExecutedOrder{ - Symbol: reo.Symbol, - OrderID: reo.OrderID, - ClientOrderID: reo.ClientOrderID, - Price: price, - OrigQty: origQty, - ExecutedQty: execQty, - Status: OrderStatus(reo.Status), - TimeInForce: TimeInForce(reo.TimeInForce), - Type: OrderType(reo.Type), - Side: OrderSide(reo.Side), - StopPrice: stopPrice, - IcebergQty: icebergQty, - Time: t, + Symbol: reo.Symbol, + OrderID: reo.OrderID, + CummulativeQuoteQty: cummulativeQuoteQty, + ClientOrderID: reo.ClientOrderID, + Price: price, + OrigQty: origQty, + ExecutedQty: execQty, + Status: OrderStatus(reo.Status), + TimeInForce: TimeInForce(reo.TimeInForce), + Type: OrderType(reo.Type), + Side: OrderSide(reo.Side), + StopPrice: stopPrice, + IcebergQty: icebergQty, + Time: t, }, nil } diff --git a/service_account_test.go b/service_account_test.go index dd9a12a..7118106 100644 --- a/service_account_test.go +++ b/service_account_test.go @@ -65,17 +65,18 @@ func TestQueryOrder(t *testing.T) { Timestamp: time.Now(), } eo := &binance.ExecutedOrder{ - Symbol: "BNBETH", - OrderID: 123, - ClientOrderID: "clientOrderID", - Price: 10.23, - OrigQty: 10.00, - ExecutedQty: 4.44, - Status: binance.StatusPartiallyFilled, - TimeInForce: binance.GTC, - Type: binance.TypeLimit, - Side: binance.SideBuy, - Time: time.Now(), + Symbol: "BNBETH", + OrderID: 123, + ClientOrderID: "clientOrderID", + CummulativeQuoteQty: 45.4212, + Price: 10.23, + OrigQty: 10.00, + ExecutedQty: 4.44, + Status: binance.StatusPartiallyFilled, + TimeInForce: binance.GTC, + Type: binance.TypeLimit, + Side: binance.SideBuy, + Time: time.Now(), } binanceService.On("QueryOrder", qor).Return(eo, nil) From efb186cbc787b0880b23bc1b7633dfaa52ee0092 Mon Sep 17 00:00:00 2001 From: wspi Date: Sun, 26 Jul 2020 17:41:26 -0300 Subject: [PATCH 2/2] fixing identation --- binance.go | 26 +++++++++--------- service_account.go | 58 ++++++++++++++++++++--------------------- service_account_test.go | 22 ++++++++-------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/binance.go b/binance.go index cc33866..bd72d9e 100644 --- a/binance.go +++ b/binance.go @@ -297,20 +297,20 @@ type QueryOrderRequest struct { // ExecutedOrder represents data about executed order. type ExecutedOrder struct { - Symbol string - OrderID int - ClientOrderID string + Symbol string + OrderID int + ClientOrderID string CummulativeQuoteQty float64 - Price float64 - OrigQty float64 - ExecutedQty float64 - Status OrderStatus - TimeInForce TimeInForce - Type OrderType - Side OrderSide - StopPrice float64 - IcebergQty float64 - Time time.Time + Price float64 + OrigQty float64 + ExecutedQty float64 + Status OrderStatus + TimeInForce TimeInForce + Type OrderType + Side OrderSide + StopPrice float64 + IcebergQty float64 + Time time.Time } // QueryOrder returns data about existing order. diff --git a/service_account.go b/service_account.go index c0c7556..ffb8a24 100644 --- a/service_account.go +++ b/service_account.go @@ -9,20 +9,20 @@ import ( ) type rawExecutedOrder struct { - Symbol string `json:"symbol"` - OrderID int `json:"orderId"` - ClientOrderID string `json:"clientOrderId"` + Symbol string `json:"symbol"` + OrderID int `json:"orderId"` + ClientOrderID string `json:"clientOrderId"` CummulativeQuoteQty string `json:"cummulativeQuoteQty"` - Price string `json:"price"` - OrigQty string `json:"origQty"` - ExecutedQty string `json:"executedQty"` - Status string `json:"status"` - TimeInForce string `json:"timeInForce"` - Type string `json:"type"` - Side string `json:"side"` - StopPrice string `json:"stopPrice"` - IcebergQty string `json:"icebergQty"` - Time float64 `json:"time"` + Price string `json:"price"` + OrigQty string `json:"origQty"` + ExecutedQty string `json:"executedQty"` + Status string `json:"status"` + TimeInForce string `json:"timeInForce"` + Type string `json:"type"` + Side string `json:"side"` + StopPrice string `json:"stopPrice"` + IcebergQty string `json:"icebergQty"` + Time float64 `json:"time"` } func (as *apiService) NewOrder(or NewOrderRequest) (*ProcessedOrder, error) { @@ -627,24 +627,24 @@ func executedOrderFromRaw(reo *rawExecutedOrder) (*ExecutedOrder, error) { return nil, errors.Wrap(err, "cannot parse Order.CloseTime") } cummulativeQuoteQty, err := strconv.ParseFloat(reo.CummulativeQuoteQty, 64) - if err != nil { - return nil, errors.Wrap(err, "cannot parse Order.CummulativeQuoteQty") - } + if err != nil { + return nil, errors.Wrap(err, "cannot parse Order.CummulativeQuoteQty") + } return &ExecutedOrder{ - Symbol: reo.Symbol, - OrderID: reo.OrderID, + Symbol: reo.Symbol, + OrderID: reo.OrderID, CummulativeQuoteQty: cummulativeQuoteQty, - ClientOrderID: reo.ClientOrderID, - Price: price, - OrigQty: origQty, - ExecutedQty: execQty, - Status: OrderStatus(reo.Status), - TimeInForce: TimeInForce(reo.TimeInForce), - Type: OrderType(reo.Type), - Side: OrderSide(reo.Side), - StopPrice: stopPrice, - IcebergQty: icebergQty, - Time: t, + ClientOrderID: reo.ClientOrderID, + Price: price, + OrigQty: origQty, + ExecutedQty: execQty, + Status: OrderStatus(reo.Status), + TimeInForce: TimeInForce(reo.TimeInForce), + Type: OrderType(reo.Type), + Side: OrderSide(reo.Side), + StopPrice: stopPrice, + IcebergQty: icebergQty, + Time: t, }, nil } diff --git a/service_account_test.go b/service_account_test.go index 7118106..9bb65b7 100644 --- a/service_account_test.go +++ b/service_account_test.go @@ -65,18 +65,18 @@ func TestQueryOrder(t *testing.T) { Timestamp: time.Now(), } eo := &binance.ExecutedOrder{ - Symbol: "BNBETH", - OrderID: 123, - ClientOrderID: "clientOrderID", + Symbol: "BNBETH", + OrderID: 123, + ClientOrderID: "clientOrderID", CummulativeQuoteQty: 45.4212, - Price: 10.23, - OrigQty: 10.00, - ExecutedQty: 4.44, - Status: binance.StatusPartiallyFilled, - TimeInForce: binance.GTC, - Type: binance.TypeLimit, - Side: binance.SideBuy, - Time: time.Now(), + Price: 10.23, + OrigQty: 10.00, + ExecutedQty: 4.44, + Status: binance.StatusPartiallyFilled, + TimeInForce: binance.GTC, + Type: binance.TypeLimit, + Side: binance.SideBuy, + Time: time.Now(), } binanceService.On("QueryOrder", qor).Return(eo, nil)