Fix order issues on GateIo, Huobi, OkGroup and Poloniex (#280)

* fix balance responce

* Fixed OrderHistory unmarshalling on the GateIo

* fix int convertation in the GetOrderHistory function

* fix issue on order submit : Binance exchange raw response: {"code":-1102,"msg":"Mandatory parameter 'timeInForce' was not sent, was empty/null, or malformed."}

* Okgroup: fix issue on empty notional GetSpotOrderResponse

* Okgroup: fix issue with empty order status. order start is required for orderHistory request

* HUOBU: fix order currency mapping in GetActiveOrders method

* OKGroup: fix currency name on GetAccountInfo

* ZB: fixed wrong error code on order send method

* OKGroup: add missing fields to GetActiveOrders mapping

* huobi: add missing fields to GetActiveOrders/GetOrderHistory response mapping

* gateio: add order status field to GetActiveOrders response

* gateio: fix orderId on SubmitOrder response

* - poloniex: fix 422 on private API call
- poloniex: fix empty order history

* - poloniex: fix 422 on private API call (revert)

* GateIo: Fix unmarshalling issue

* Huobi: removing redundant breaks

* Huobi: fix rangeValCopy in GetActiveOrders/GetOrderHistory methods
This commit is contained in:
Vadim Zhuk
2019-04-18 10:38:47 +03:00
committed by Adrian Gallagher
parent c449568f6d
commit b02d03da8b
6 changed files with 67 additions and 37 deletions

View File

@@ -124,11 +124,12 @@ type SpotNewOrderRequestParams struct {
// SpotNewOrderResponse Order response
type SpotNewOrderResponse struct {
OrderNumber int64 `json:"orderNumber"` // OrderID number
Price float64 `json:"rate,string"` // Order price
LeftAmount float64 `json:"leftAmount,string"` // The remaining amount to fill
FilledAmount float64 `json:"filledAmount,string"` // The filled amount
Filledrate float64 `json:"filledRate,string"` // FilledPrice
OrderNumber int64 `json:"orderNumber"` // OrderID number
Price float64 `json:"rate,string"` // Order price
LeftAmount float64 `json:"leftAmount,string"` // The remaining amount to fill
FilledAmount float64 `json:"filledAmount,string"` // The filled amount
Filledrate interface{} `json:"filledRate"` // FilledPrice. if we send a market order, the exchange returns float64.
// if we set a limit order, which will remain in the order book, the exchange will return the string
}
// OpenOrdersResponse the main response from GetOpenOrders

View File

@@ -224,7 +224,7 @@ func (g *Gateio) SubmitOrder(p currency.Pair, side exchange.OrderSide, _ exchang
response, err := g.SpotNewOrder(spotNewOrderRequestParams)
if response.OrderNumber > 0 {
submitOrderResponse.OrderID = fmt.Sprintf("%v", response)
submitOrderResponse.OrderID = fmt.Sprintf("%v", response.OrderNumber)
}
if err == nil {
@@ -371,6 +371,7 @@ func (g *Gateio) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([
OrderSide: side,
Exchange: g.Name,
CurrencyPair: symbol,
Status: resp.Orders[i].Status,
})
}

View File

@@ -422,18 +422,22 @@ func (h *HUOBI) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) ([]
}
for i := range resp {
orderDate := time.Unix(resp[i].CreatedAt, 0)
orderDetail := exchange.OrderDetail{
ID: fmt.Sprintf("%v", resp[i].ID),
Price: resp[i].Price,
Amount: resp[i].Amount,
CurrencyPair: c,
Exchange: h.Name,
ExecutedAmount: resp[i].FilledAmount,
OrderDate: time.Unix(resp[i].CreatedAt, 0),
Status: resp[i].State,
AccountID: strconv.FormatFloat(resp[i].AccountID, 'f', -1, 64),
Fee: resp[i].FilledFees,
}
orders = append(orders, exchange.OrderDetail{
ID: fmt.Sprintf("%v", resp[i].ID),
Exchange: h.Name,
Amount: resp[i].Amount,
Price: resp[i].Price,
OrderDate: orderDate,
ExecutedAmount: resp[i].FilledAmount,
RemainingAmount: (resp[i].Amount - resp[i].FilledAmount),
CurrencyPair: c,
})
setOrderSideAndType(resp[i].Type, &orderDetail)
orders = append(orders, orderDetail)
}
}
@@ -466,16 +470,22 @@ func (h *HUOBI) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
}
for i := range resp {
orderDate := time.Unix(resp[i].CreatedAt, 0)
orderDetail := exchange.OrderDetail{
ID: fmt.Sprintf("%v", resp[i].ID),
Price: resp[i].Price,
Amount: resp[i].Amount,
CurrencyPair: c,
Exchange: h.Name,
ExecutedAmount: resp[i].FilledAmount,
OrderDate: time.Unix(resp[i].CreatedAt, 0),
Status: resp[i].State,
AccountID: strconv.FormatFloat(resp[i].AccountID, 'f', -1, 64),
Fee: resp[i].FilledFees,
}
orders = append(orders, exchange.OrderDetail{
ID: fmt.Sprintf("%v", resp[i].ID),
Exchange: h.Name,
Amount: resp[i].Amount,
Price: resp[i].Price,
OrderDate: orderDate,
CurrencyPair: c,
})
setOrderSideAndType(resp[i].Type, &orderDetail)
orders = append(orders, orderDetail)
}
}
@@ -484,3 +494,20 @@ func (h *HUOBI) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest) ([]
return orders, nil
}
func setOrderSideAndType(requestType string, orderDetail *exchange.OrderDetail) {
switch SpotNewOrderRequestParamsType(requestType) {
case SpotNewOrderRequestTypeBuyMarket:
orderDetail.OrderSide = exchange.BuyOrderSide
orderDetail.OrderType = exchange.MarketOrderType
case SpotNewOrderRequestTypeSellMarket:
orderDetail.OrderSide = exchange.SellOrderSide
orderDetail.OrderType = exchange.MarketOrderType
case SpotNewOrderRequestTypeBuyLimit:
orderDetail.OrderSide = exchange.BuyOrderSide
orderDetail.OrderType = exchange.LimitOrderType
case SpotNewOrderRequestTypeSellLimit:
orderDetail.OrderSide = exchange.SellOrderSide
orderDetail.OrderType = exchange.LimitOrderType
}
}

View File

@@ -364,9 +364,13 @@ func (o *OKGroup) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest) (
}
for i := range spotOpenOrders {
resp = append(resp, exchange.OrderDetail{
ID: spotOpenOrders[i].OrderID,
Price: spotOpenOrders[i].Price,
Amount: spotOpenOrders[i].Size,
CurrencyPair: currency,
Exchange: o.Name,
OrderSide: exchange.OrderSide(spotOpenOrders[i].Side),
OrderType: exchange.OrderType(spotOpenOrders[i].Type),
ExecutedAmount: spotOpenOrders[i].FilledSize,
OrderDate: spotOpenOrders[i].Timestamp,
Status: spotOpenOrders[i].Status,

View File

@@ -53,6 +53,8 @@ const (
poloniexAuthRate = 6
poloniexUnauthRate = 6
poloniexDateLayout = "2006-01-02 15:04:05"
)
// Poloniex is the overarching type across the poloniex package
@@ -477,20 +479,14 @@ func (p *Poloniex) GetAuthenticatedTradeHistory(start, end, limit int64) (Authen
}
values.Set("currencyPair", "all")
var result interface{}
var result AuthenticatedTradeHistoryAll
err := p.SendAuthenticatedHTTPRequest(http.MethodPost, poloniexTradeHistory, values, &result)
err := p.SendAuthenticatedHTTPRequest(http.MethodPost, poloniexTradeHistory, values, &result.Data)
if err != nil {
return AuthenticatedTradeHistoryAll{}, err
}
// If there are no orders, Poloniex returns an empty array
switch r := result.(type) {
case AuthenticatedTradeHistoryAll:
return r, nil
default:
return AuthenticatedTradeHistoryAll{}, nil
}
return result, nil
}
// PlaceOrder places a new order on the exchange
@@ -878,6 +874,7 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values
} else {
p.Nonce.Inc()
}
values.Set("nonce", p.Nonce.String())
values.Set("command", endpoint)

View File

@@ -331,7 +331,7 @@ func (p *Poloniex) GetActiveOrders(getOrdersRequest *exchange.GetOrdersRequest)
for _, order := range openOrders {
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
orderDate, err := time.Parse(time.RFC3339, order.Date)
orderDate, err := time.Parse(poloniexDateLayout, order.Date)
if err != nil {
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
p.Name, "GetActiveOrders", order.OrderNumber, order.Date)
@@ -373,7 +373,7 @@ func (p *Poloniex) GetOrderHistory(getOrdersRequest *exchange.GetOrdersRequest)
for _, order := range historicOrders {
orderSide := exchange.OrderSide(strings.ToUpper(order.Type))
orderDate, err := time.Parse(time.RFC3339, order.Date)
orderDate, err := time.Parse(poloniexDateLayout, order.Date)
if err != nil {
log.Warnf("Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
p.Name, "GetActiveOrders", order.OrderNumber, order.Date)