(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:
Ryan O'Hara-Reid
2019-12-03 10:06:08 +11:00
committed by Adrian Gallagher
parent c27b8657e2
commit 0c5d75b22c
70 changed files with 393 additions and 462 deletions

View File

@@ -8,7 +8,6 @@ import (
"strconv"
"strings"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
@@ -428,7 +427,7 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(method, endpoint, param string, re
Message string `json:"message"`
}{}
if err := common.JSONDecode(intermidiary, &errCap); err == nil {
if err := json.Unmarshal(intermidiary, &errCap); err == nil {
if !errCap.Result {
return fmt.Errorf("%s auth request error, code: %d message: %s",
g.Name,
@@ -437,7 +436,7 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(method, endpoint, param string, re
}
}
return common.JSONDecode(intermidiary, result)
return json.Unmarshal(intermidiary, result)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -1,6 +1,7 @@
package gateio
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"time"
"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"
@@ -64,7 +64,7 @@ func (g *Gateio) wsServerSignIn() (*WebsocketAuthenticationResponse, error) {
return nil, err
}
var response WebsocketAuthenticationResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
g.Websocket.SetCanUseAuthenticatedEndpoints(false)
return nil, err
@@ -97,7 +97,7 @@ func (g *Gateio) WsHandleData() {
}
g.Websocket.TrafficAlert <- struct{}{}
var result WebsocketResponse
err = common.JSONDecode(resp.Raw, &result)
err = json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -123,13 +123,13 @@ func (g *Gateio) WsHandleData() {
case strings.Contains(result.Method, "ticker"):
var ticker WebsocketTicker
var c string
err = common.JSONDecode(result.Params[1], &ticker)
err = json.Unmarshal(result.Params[1], &ticker)
if err != nil {
g.Websocket.DataHandler <- err
continue
}
err = common.JSONDecode(result.Params[0], &c)
err = json.Unmarshal(result.Params[0], &c)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -151,13 +151,13 @@ func (g *Gateio) WsHandleData() {
case strings.Contains(result.Method, "trades"):
var trades []WebsocketTrade
var c string
err = common.JSONDecode(result.Params[1], &trades)
err = json.Unmarshal(result.Params[1], &trades)
if err != nil {
g.Websocket.DataHandler <- err
continue
}
err = common.JSONDecode(result.Params[0], &c)
err = json.Unmarshal(result.Params[0], &c)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -179,19 +179,19 @@ func (g *Gateio) WsHandleData() {
var IsSnapshot bool
var c string
var data = make(map[string][][]string)
err = common.JSONDecode(result.Params[0], &IsSnapshot)
err = json.Unmarshal(result.Params[0], &IsSnapshot)
if err != nil {
g.Websocket.DataHandler <- err
continue
}
err = common.JSONDecode(result.Params[2], &c)
err = json.Unmarshal(result.Params[2], &c)
if err != nil {
g.Websocket.DataHandler <- err
continue
}
err = common.JSONDecode(result.Params[1], &data)
err = json.Unmarshal(result.Params[1], &data)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -265,7 +265,7 @@ func (g *Gateio) WsHandleData() {
case strings.Contains(result.Method, "kline"):
var data []interface{}
err = common.JSONDecode(result.Params[0], &data)
err = json.Unmarshal(result.Params[0], &data)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -356,7 +356,7 @@ func (g *Gateio) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscrip
return err
}
var response WebsocketAuthenticationResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}
@@ -380,7 +380,7 @@ func (g *Gateio) Unsubscribe(channelToSubscribe wshandler.WebsocketChannelSubscr
return err
}
var response WebsocketAuthenticationResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}
@@ -404,7 +404,7 @@ func (g *Gateio) wsGetBalance(currencies []string) (*WsGetBalanceResponse, error
return nil, err
}
var balance WsGetBalanceResponse
err = common.JSONDecode(resp, &balance)
err = json.Unmarshal(resp, &balance)
if err != nil {
return &balance, err
}
@@ -430,7 +430,7 @@ func (g *Gateio) wsGetOrderInfo(market string, offset, limit int) (*WebSocketOrd
return nil, err
}
var orderQuery WebSocketOrderQueryResult
err = common.JSONDecode(resp, &orderQuery)
err = json.Unmarshal(resp, &orderQuery)
if err != nil {
return &orderQuery, err
}