mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-28 07:26:57 +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
@@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
@@ -339,7 +338,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(httpMethod string, params url.Values,
|
||||
return err
|
||||
}
|
||||
|
||||
err = common.JSONDecode(intermediary, &errCap)
|
||||
err = json.Unmarshal(intermediary, &errCap)
|
||||
if err == nil {
|
||||
if errCap.Code > 1000 {
|
||||
return fmt.Errorf("sendAuthenticatedHTTPRequest error code: %d message %s",
|
||||
@@ -348,7 +347,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(httpMethod string, params url.Values,
|
||||
}
|
||||
}
|
||||
|
||||
return common.JSONDecode(intermediary, result)
|
||||
return json.Unmarshal(intermediary, result)
|
||||
}
|
||||
|
||||
// GetFee returns an estimate of fee based on type of transaction
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package zb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -506,10 +507,10 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
// TestZBInvalidJSON ZB sends poorly formed JSON. this tests the JSON fixer
|
||||
// Then JSON decode it to test if successful
|
||||
func TestZBInvalidJSON(t *testing.T) {
|
||||
json := `{"success":true,"code":1000,"channel":"getSubUserList","message":"[{"isOpenApi":false,"memo":"Memo","userName":"hello@imgoodthanksandyou.com@good","userId":1337,"isFreez":false}]","no":"0"}`
|
||||
fixedJSON := z.wsFixInvalidJSON([]byte(json))
|
||||
data := `{"success":true,"code":1000,"channel":"getSubUserList","message":"[{"isOpenApi":false,"memo":"Memo","userName":"hello@imgoodthanksandyou.com@good","userId":1337,"isFreez":false}]","no":"0"}`
|
||||
fixedJSON := z.wsFixInvalidJSON([]byte(data))
|
||||
var response WsGetSubUserListResponse
|
||||
err := common.JSONDecode(fixedJSON, &response)
|
||||
err := json.Unmarshal(fixedJSON, &response)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -517,10 +518,10 @@ func TestZBInvalidJSON(t *testing.T) {
|
||||
t.Fatal("Expected extracted JSON USERID to equal 1337")
|
||||
}
|
||||
|
||||
json = `{"success":true,"code":1000,"channel":"createSubUserKey","message":"{"apiKey":"thisisnotareallykeyyousillybilly","apiSecret":"lol"}","no":"123"}`
|
||||
fixedJSON = z.wsFixInvalidJSON([]byte(json))
|
||||
data = `{"success":true,"code":1000,"channel":"createSubUserKey","message":"{"apiKey":"thisisnotareallykeyyousillybilly","apiSecret":"lol"}","no":"123"}`
|
||||
fixedJSON = z.wsFixInvalidJSON([]byte(data))
|
||||
var response2 WsRequestResponse
|
||||
err = common.JSONDecode(fixedJSON, &response2)
|
||||
err = json.Unmarshal(fixedJSON, &response2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package zb
|
||||
|
||||
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 (z *ZB) WsHandleData() {
|
||||
z.Websocket.TrafficAlert <- struct{}{}
|
||||
fixedJSON := z.wsFixInvalidJSON(resp.Raw)
|
||||
var result Generic
|
||||
err = common.JSONDecode(fixedJSON, &result)
|
||||
err = json.Unmarshal(fixedJSON, &result)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -80,7 +80,7 @@ func (z *ZB) WsHandleData() {
|
||||
switch {
|
||||
case strings.Contains(result.Channel, "markets"):
|
||||
var markets Markets
|
||||
err := common.JSONDecode(result.Data, &markets)
|
||||
err := json.Unmarshal(result.Data, &markets)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -89,7 +89,7 @@ func (z *ZB) WsHandleData() {
|
||||
case strings.Contains(result.Channel, "ticker"):
|
||||
cPair := strings.Split(result.Channel, "_")
|
||||
var ticker WsTicker
|
||||
err := common.JSONDecode(fixedJSON, &ticker)
|
||||
err := json.Unmarshal(fixedJSON, &ticker)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -111,7 +111,7 @@ func (z *ZB) WsHandleData() {
|
||||
|
||||
case strings.Contains(result.Channel, "depth"):
|
||||
var depth WsDepth
|
||||
err := common.JSONDecode(fixedJSON, &depth)
|
||||
err := json.Unmarshal(fixedJSON, &depth)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -156,7 +156,7 @@ func (z *ZB) WsHandleData() {
|
||||
|
||||
case strings.Contains(result.Channel, "trades"):
|
||||
var trades WsTrades
|
||||
err := common.JSONDecode(fixedJSON, &trades)
|
||||
err := json.Unmarshal(fixedJSON, &trades)
|
||||
if err != nil {
|
||||
z.Websocket.DataHandler <- err
|
||||
continue
|
||||
@@ -252,7 +252,7 @@ func (z *ZB) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscription
|
||||
}
|
||||
|
||||
func (z *ZB) wsGenerateSignature(request interface{}) string {
|
||||
jsonResponse, err := common.JSONEncode(request)
|
||||
jsonResponse, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
return ""
|
||||
@@ -296,7 +296,7 @@ func (z *ZB) wsAddSubUser(username, password string) (*WsGetSubUserListResponse,
|
||||
return nil, err
|
||||
}
|
||||
var genericResponse Generic
|
||||
err = common.JSONDecode(resp, &genericResponse)
|
||||
err = json.Unmarshal(resp, &genericResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -304,7 +304,7 @@ func (z *ZB) wsAddSubUser(username, password string) (*WsGetSubUserListResponse,
|
||||
return nil, fmt.Errorf("%v request failed, message: %v, error code: %v", z.Name, genericResponse.Message, wsErrCodes[genericResponse.Code])
|
||||
}
|
||||
var response WsGetSubUserListResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -327,7 +327,7 @@ func (z *ZB) wsGetSubUserList() (*WsGetSubUserListResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
var response WsGetSubUserListResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -358,7 +358,7 @@ func (z *ZB) wsDoTransferFunds(pair currency.Code, amount float64, fromUserName,
|
||||
return nil, err
|
||||
}
|
||||
var response WsRequestResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -391,7 +391,7 @@ func (z *ZB) wsCreateSubUserKey(assetPerm, entrustPerm, leverPerm, moneyPerm boo
|
||||
return nil, err
|
||||
}
|
||||
var response WsRequestResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -421,7 +421,7 @@ func (z *ZB) wsSubmitOrder(pair currency.Pair, amount, price float64, tradeType
|
||||
return nil, err
|
||||
}
|
||||
var response WsSubmitOrderResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -449,7 +449,7 @@ func (z *ZB) wsCancelOrder(pair currency.Pair, orderID int64) (*WsCancelOrderRes
|
||||
return nil, err
|
||||
}
|
||||
var response WsCancelOrderResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -477,7 +477,7 @@ func (z *ZB) wsGetOrder(pair currency.Pair, orderID int64) (*WsGetOrderResponse,
|
||||
return nil, err
|
||||
}
|
||||
var response WsGetOrderResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -505,7 +505,7 @@ func (z *ZB) wsGetOrders(pair currency.Pair, pageIndex, tradeType int64) (*WsGet
|
||||
return nil, err
|
||||
}
|
||||
var response WsGetOrdersResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -534,7 +534,7 @@ func (z *ZB) wsGetOrdersIgnoreTradeType(pair currency.Pair, pageIndex, pageSize
|
||||
return nil, err
|
||||
}
|
||||
var response WsGetOrdersIgnoreTradeTypeResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -561,7 +561,7 @@ func (z *ZB) wsGetAccountInfoRequest() (*WsGetAccountInfoResponse, error) {
|
||||
return nil, err
|
||||
}
|
||||
var response WsGetAccountInfoResponse
|
||||
err = common.JSONDecode(resp, &response)
|
||||
err = json.Unmarshal(resp, &response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user