mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 07:26:45 +00:00
(Engine) Variety of engine updates (#390)
* drop common uuid v4 func and imported package as needed * removed common functions regarding json marshal and unmarshal and used the json package directly. WRT unmarshal it was calling reflect and converted to string which is also checked in the JSON package so it was doing a double up, this will be a tiny gain as it was directly used in the requester package for all our outbound requests. * add in string * explicitly throw away return error value * atleast return the error that websocket initialise returns * return error when not connected * fix comment * Adds comments * move package declarations * drop append whenever we call supported * remove unused import * Change incorrect spelling * fix tests * fix go import issue
This commit is contained in:
committed by
Adrian Gallagher
parent
c27b8657e2
commit
0c5d75b22c
@@ -1,6 +1,7 @@
|
||||
package huobi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -8,13 +9,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||
@@ -139,7 +138,7 @@ func (h *HUOBI) WsHandleData() {
|
||||
|
||||
func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
||||
var init WsAuthenticatedDataResponse
|
||||
err := common.JSONDecode(resp.Raw, &init)
|
||||
err := json.Unmarshal(resp.Raw, &init)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
@@ -169,14 +168,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
||||
case strings.EqualFold(init.Op, authOp):
|
||||
h.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
||||
var response WsAuthenticatedDataResponse
|
||||
err := common.JSONDecode(resp.Raw, &response)
|
||||
err := json.Unmarshal(resp.Raw, &response)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
}
|
||||
h.Websocket.DataHandler <- response
|
||||
case strings.EqualFold(init.Topic, "accounts"):
|
||||
var response WsAuthenticatedAccountsResponse
|
||||
err := common.JSONDecode(resp.Raw, &response)
|
||||
err := json.Unmarshal(resp.Raw, &response)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
}
|
||||
@@ -184,14 +183,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
||||
case strings.Contains(init.Topic, "orders") &&
|
||||
strings.Contains(init.Topic, "update"):
|
||||
var response WsAuthenticatedOrdersUpdateResponse
|
||||
err := common.JSONDecode(resp.Raw, &response)
|
||||
err := json.Unmarshal(resp.Raw, &response)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
}
|
||||
h.Websocket.DataHandler <- response
|
||||
case strings.Contains(init.Topic, "orders"):
|
||||
var response WsAuthenticatedOrdersResponse
|
||||
err := common.JSONDecode(resp.Raw, &response)
|
||||
err := json.Unmarshal(resp.Raw, &response)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
}
|
||||
@@ -201,7 +200,7 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
||||
|
||||
func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
var init WsResponse
|
||||
err := common.JSONDecode(resp.Raw, &init)
|
||||
err := json.Unmarshal(resp.Raw, &init)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
@@ -228,7 +227,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
switch {
|
||||
case strings.Contains(init.Channel, "depth"):
|
||||
var depth WsDepth
|
||||
err := common.JSONDecode(resp.Raw, &depth)
|
||||
err := json.Unmarshal(resp.Raw, &depth)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
@@ -243,7 +242,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
|
||||
case strings.Contains(init.Channel, "kline"):
|
||||
var kline WsKline
|
||||
err := common.JSONDecode(resp.Raw, &kline)
|
||||
err := json.Unmarshal(resp.Raw, &kline)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
@@ -263,7 +262,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
}
|
||||
case strings.Contains(init.Channel, "trade.detail"):
|
||||
var trade WsTrade
|
||||
err := common.JSONDecode(resp.Raw, &trade)
|
||||
err := json.Unmarshal(resp.Raw, &trade)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
@@ -278,7 +277,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||
}
|
||||
case strings.Contains(init.Channel, "detail"):
|
||||
var ticker WsTick
|
||||
err := common.JSONDecode(resp.Raw, &ticker)
|
||||
err := json.Unmarshal(resp.Raw, &ticker)
|
||||
if err != nil {
|
||||
h.Websocket.DataHandler <- err
|
||||
return
|
||||
@@ -457,7 +456,7 @@ func (h *HUOBI) wsGetAccountsList(pair currency.Pair) (*WsAuthenticatedAccountsL
|
||||
return nil, err
|
||||
}
|
||||
var response WsAuthenticatedAccountsListResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
return &response, err
|
||||
}
|
||||
|
||||
@@ -485,7 +484,7 @@ func (h *HUOBI) wsGetOrdersList(accountID int64, pair currency.Pair) (*WsAuthent
|
||||
return nil, err
|
||||
}
|
||||
var response WsAuthenticatedOrdersResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
return &response, err
|
||||
}
|
||||
|
||||
@@ -511,6 +510,6 @@ func (h *HUOBI) wsGetOrderDetails(orderID string) (*WsAuthenticatedOrderDetailRe
|
||||
return nil, err
|
||||
}
|
||||
var response WsAuthenticatedOrderDetailResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
return &response, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user