(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

@@ -2,6 +2,7 @@ package alphapoint
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"strings"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
@@ -513,7 +513,7 @@ func (a *Alphapoint) SendHTTPRequest(method, path string, data map[string]interf
headers["Content-Type"] = "application/json"
path = fmt.Sprintf("%s/ajax/v%s/%s", a.API.Endpoints.URL, alphapointAPIVersion, path)
PayloadJSON, err := common.JSONEncode(data)
PayloadJSON, err := json.Marshal(data)
if err != nil {
return errors.New("unable to JSON request")
}
@@ -548,7 +548,7 @@ func (a *Alphapoint) SendAuthenticatedHTTPRequest(method, path string, data map[
data["apiSig"] = strings.ToUpper(crypto.HexEncodeToString(hmac))
path = fmt.Sprintf("%s/ajax/v%s/%s", a.API.Endpoints.URL, alphapointAPIVersion, path)
PayloadJSON, err := common.JSONEncode(data)
PayloadJSON, err := json.Marshal(data)
if err != nil {
return errors.New("unable to JSON request")
}

View File

@@ -1,6 +1,7 @@
package alphapoint
import (
"encoding/json"
"testing"
"github.com/thrasher-corp/gocryptotrader/common"
@@ -63,7 +64,7 @@ func TestGetTicker(t *testing.T) {
string(`{"high":253.101,"last":249.76,"bid":248.8901,"volume":5.813354,"low":231.21,"ask":248.9012,"Total24HrQtyTraded":52.654968,"Total24HrProduct2Traded":569.05762,"Total24HrNumTrades":4,"sellOrderCount":7,"buyOrderCount":11,"numOfCreateOrders":0,"isAccepted":true}`),
)
err = common.JSONDecode(mockResp, &ticker)
err = json.Unmarshal(mockResp, &ticker)
if err != nil {
t.Fatal("Alphapoint GetTicker unmarshalling error: ", err)
}
@@ -100,7 +101,7 @@ func TestGetTrades(t *testing.T) {
string(`{"isAccepted":true,"dateTimeUtc":635507981548085938,"ins":"BTCUSD","startIndex":0,"count":10,"trades":[{"tid":0,"px":231.8379,"qty":4.913,"unixtime":1399951989,"utcticks":635355487898355234,"incomingOrderSide":0,"incomingServerOrderId":2598,"bookServerOrderId":2588},{"tid":1,"px":7895.1487,"qty":0.25,"unixtime":1403143708,"utcticks":635387405087297421,"incomingOrderSide":0,"incomingServerOrderId":284241,"bookServerOrderId":284235},{"tid":2,"px":7935.058,"qty":0.25,"unixtime":1403195348,"utcticks":635387921488684140,"incomingOrderSide":0,"incomingServerOrderId":575845,"bookServerOrderId":574078},{"tid":3,"px":7935.0448,"qty":0.25,"unixtime":1403195378,"utcticks":635387921780090390,"incomingOrderSide":0,"incomingServerOrderId":576028,"bookServerOrderId":575946},{"tid":4,"px":7933.9566,"qty":0.1168,"unixtime":1403195510,"utcticks":635387923108371640,"incomingOrderSide":0,"incomingServerOrderId":576974,"bookServerOrderId":576947},{"tid":5,"px":7961.0856,"qty":0.25,"unixtime":1403202307,"utcticks":635387991073850156,"incomingOrderSide":0,"incomingServerOrderId":600547,"bookServerOrderId":600338},{"tid":6,"px":7961.1388,"qty":0.011,"unixtime":1403202307,"utcticks":635387991073850156,"incomingOrderSide":0,"incomingServerOrderId":600547,"bookServerOrderId":600418},{"tid":7,"px":7961.2451,"qty":0.02,"unixtime":1403202307,"utcticks":635387991073850156,"incomingOrderSide":0,"incomingServerOrderId":600547,"bookServerOrderId":600428},{"tid":8,"px":7947.1437,"qty":0.09,"unixtime":1403202749,"utcticks":635387995498225156,"incomingOrderSide":0,"incomingServerOrderId":602183,"bookServerOrderId":601745},{"tid":9,"px":7818.5073,"qty":0.25,"unixtime":1403219720,"utcticks":635388165206506406,"incomingOrderSide":0,"incomingServerOrderId":661909,"bookServerOrderId":661620}]}`),
)
err = common.JSONDecode(mockResp, &trades)
err = json.Unmarshal(mockResp, &trades)
if err != nil {
t.Fatal("GetTrades unmarshalling error: ", err)
}
@@ -140,7 +141,7 @@ func TestGetTradesByDate(t *testing.T) {
string(`{"isAccepted":true,"dateTimeUtc":635504540880633671,"ins":"BTCUSD","startDate":1414799400,"endDate":1414800000,"trades":[{"tid":11505,"px":334.669,"qty":0.1211,"unixtime":1414799403,"utcticks":635503962032459843,"incomingOrderSide":1,"incomingServerOrderId":5185651,"bookServerOrderId":5162440},{"tid":11506,"px":334.669,"qty":0.1211,"unixtime":1414799405,"utcticks":635503962058446171,"incomingOrderSide":1,"incomingServerOrderId":5186245,"bookServerOrderId":5162440},{"tid":11507,"px":336.498,"qty":0.011,"unixtime":1414799407,"utcticks":635503962072967656,"incomingOrderSide":0,"incomingServerOrderId":5186530,"bookServerOrderId":5178944},{"tid":11508,"px":335.948,"qty":0.011,"unixtime":1414799410,"utcticks":635503962108055546,"incomingOrderSide":0,"incomingServerOrderId":5187260,"bookServerOrderId":5186531}]}`),
)
err = common.JSONDecode(mockResp, &trades)
err = json.Unmarshal(mockResp, &trades)
if err != nil {
t.Fatal("GetTradesByDate unmarshalling error: ", err)
}
@@ -188,7 +189,7 @@ func TestGetOrderbook(t *testing.T) {
string(`{"bids":[{"qty":725,"px":66},{"qty":1289,"px":65},{"qty":1266,"px":64}],"asks":[{"qty":1,"px":67},{"qty":1,"px":69},{"qty":2,"px":70}],"isAccepted":true}`),
)
err = common.JSONDecode(mockResp, &orderBook)
err = json.Unmarshal(mockResp, &orderBook)
if err != nil {
t.Fatal("TestGetOrderbook unmarshalling error: ", err)
}
@@ -228,7 +229,7 @@ func TestGetProductPairs(t *testing.T) {
string(`{"productPairs":[{"name":"LTCUSD","productPairCode":100,"product1Label":"LTC","product1DecimalPlaces":8,"product2Label":"USD","product2DecimalPlaces":6}, {"name":"BTCUSD","productPairCode":99,"product1Label":"BTC","product1DecimalPlaces":8,"product2Label":"USD","product2DecimalPlaces":6}],"isAccepted":true}`),
)
err = common.JSONDecode(mockResp, &products)
err = json.Unmarshal(mockResp, &products)
if err != nil {
t.Fatal("TestGetProductPairs unmarshalling error: ", err)
}
@@ -268,7 +269,7 @@ func TestGetProducts(t *testing.T) {
string(`{"products": [{"name": "USD","isDigital": false,"productCode": 0,"decimalPlaces": 4,"fullName": "US Dollar"},{"name": "BTC","isDigital": true,"productCode": 1,"decimalPlaces": 6,"fullName": "Bitcoin"}],"isAccepted": true}`),
)
err = common.JSONDecode(mockResp, &products)
err = json.Unmarshal(mockResp, &products)
if err != nil {
t.Fatal("TestGetProducts unmarshalling error: ", err)
}

View File

@@ -1,10 +1,10 @@
package alphapoint
import (
"encoding/json"
"net/http"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
log "github.com/thrasher-corp/gocryptotrader/logger"
)
@@ -49,7 +49,7 @@ func (a *Alphapoint) WebsocketClient() {
}
msgType := MsgType{}
err := common.JSONDecode(resp, &msgType)
err := json.Unmarshal(resp, &msgType)
if err != nil {
log.Error(log.ExchangeSys, err)
continue
@@ -57,7 +57,7 @@ func (a *Alphapoint) WebsocketClient() {
if msgType.MessageType == "Ticker" {
ticker := WebsocketTicker{}
err = common.JSONDecode(resp, &ticker)
err = json.Unmarshal(resp, &ticker)
if err != nil {
log.Error(log.ExchangeSys, err)
continue

View File

@@ -2,13 +2,13 @@ package anx
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"time"
"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"
@@ -357,7 +357,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
req[key] = value
}
PayloadJSON, err := common.JSONEncode(req)
PayloadJSON, err := json.Marshal(req)
if err != nil {
return errors.New("unable to JSON request")
}

View File

@@ -23,21 +23,21 @@ const (
DownsideProfitContract = Item("downsideprofitcontract")
)
var supported = Items{
Spot,
Margin,
Index,
Binary,
PerpetualContract,
PerpetualSwap,
Futures,
UpsideProfitContract,
DownsideProfitContract,
}
// Supported returns a list of supported asset types
func Supported() Items {
var a Items
a = append(a,
Spot,
Margin,
Index,
Binary,
PerpetualContract,
PerpetualSwap,
Futures,
UpsideProfitContract,
DownsideProfitContract,
)
return a
return supported
}
// returns an Item to string

View File

@@ -526,13 +526,13 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
return err
}
if err := common.JSONDecode(interim, &errCap); err == nil {
if err := json.Unmarshal(interim, &errCap); err == nil {
if !errCap.Success && errCap.Message != "" {
return errors.New(errCap.Message)
}
}
return common.JSONDecode(interim, result)
return json.Unmarshal(interim, result)
}
// CheckLimit checks value against a variable list

View File

@@ -1,6 +1,7 @@
package binance
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/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -92,7 +92,7 @@ func (b *Binance) WsHandleData() {
}
b.Websocket.TrafficAlert <- struct{}{}
var multiStreamData MultiStreamData
err = common.JSONDecode(read.Raw, &multiStreamData)
err = json.Unmarshal(read.Raw, &multiStreamData)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not load multi stream data: %s",
b.Name,
@@ -103,7 +103,7 @@ func (b *Binance) WsHandleData() {
switch streamType[1] {
case "trade":
trade := TradeStream{}
err := common.JSONDecode(multiStreamData.Data, &trade)
err := json.Unmarshal(multiStreamData.Data, &trade)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not unmarshal trade data: %s",
b.Name,
@@ -140,7 +140,7 @@ func (b *Binance) WsHandleData() {
continue
case "ticker":
t := TickerStream{}
err := common.JSONDecode(multiStreamData.Data, &t)
err := json.Unmarshal(multiStreamData.Data, &t)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to a TickerStream structure %s",
b.Name,
@@ -168,7 +168,7 @@ func (b *Binance) WsHandleData() {
continue
case "kline":
kline := KlineStream{}
err := common.JSONDecode(multiStreamData.Data, &kline)
err := json.Unmarshal(multiStreamData.Data, &kline)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to a KlineStream structure %s",
b.Name,
@@ -194,7 +194,7 @@ func (b *Binance) WsHandleData() {
continue
case "depth":
depth := WebsocketDepthStream{}
err := common.JSONDecode(multiStreamData.Data, &depth)
err := json.Unmarshal(multiStreamData.Data, &depth)
if err != nil {
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to depthStream structure %s",
b.Name,

View File

@@ -1,6 +1,7 @@
package bitfinex
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -953,7 +954,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
req[key] = value
}
PayloadJSON, err := common.JSONEncode(req)
PayloadJSON, err := json.Marshal(req)
if err != nil {
return errors.New("sendAuthenticatedAPIRequest: unable to JSON request")
}

View File

@@ -1,6 +1,7 @@
package bitfinex
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"
@@ -139,7 +139,7 @@ func (b *Bitfinex) WsConnect() error {
}
b.Websocket.TrafficAlert <- struct{}{}
var hs WebsocketHandshake
err = common.JSONDecode(resp.Raw, &hs)
err = json.Unmarshal(resp.Raw, &hs)
if err != nil {
return err
}
@@ -184,7 +184,7 @@ func (b *Bitfinex) WsDataHandler() {
if stream.Type == websocket.TextMessage {
var result interface{}
err = common.JSONDecode(stream.Raw, &result)
err = json.Unmarshal(stream.Raw, &result)
if err != nil {
b.Websocket.DataHandler <- err
return

View File

@@ -11,7 +11,6 @@ import (
"strconv"
"strings"
"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"
@@ -110,7 +109,7 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
continue
}
var newTicker Ticker
err := common.JSONDecode(v, &newTicker)
err := json.Unmarshal(v, &newTicker)
if err != nil {
return nil, err
}
@@ -518,7 +517,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
return err
}
err = common.JSONDecode(intermediary, &errCapture)
err = json.Unmarshal(intermediary, &errCapture)
if err == nil {
if errCapture.Status != "" && errCapture.Status != noError {
return fmt.Errorf("sendAuthenticatedAPIRequest error code: %s message:%s",
@@ -527,7 +526,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
}
}
return common.JSONDecode(intermediary, result)
return json.Unmarshal(intermediary, result)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -9,7 +9,6 @@ import (
"strings"
"time"
"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"
@@ -829,7 +828,7 @@ func (b *Bitmex) SendAuthenticatedHTTPRequest(verb, path string, params Paramete
if err != nil {
return err
}
data, err := common.JSONEncode(params)
data, err := json.Marshal(params)
if err != nil {
return err
}
@@ -870,14 +869,14 @@ func (b *Bitmex) CaptureError(resp, reType interface{}) error {
return err
}
err = common.JSONDecode(marshalled, &Error)
err = json.Unmarshal(marshalled, &Error)
if err == nil {
return fmt.Errorf("bitmex error %s: %s",
Error.Error.Name,
Error.Error.Message)
}
return common.JSONDecode(marshalled, reType)
return json.Unmarshal(marshalled, reType)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -1,6 +1,7 @@
package bitmex
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"
@@ -85,7 +85,7 @@ func (b *Bitmex) WsConnect() error {
}
b.Websocket.TrafficAlert <- struct{}{}
var welcomeResp WebsocketWelcome
err = common.JSONDecode(p.Raw, &welcomeResp)
err = json.Unmarshal(p.Raw, &welcomeResp)
if err != nil {
return err
}
@@ -143,7 +143,7 @@ func (b *Bitmex) wsHandleIncomingData() {
}
quickCapture := make(map[string]interface{})
err = common.JSONDecode(resp.Raw, &quickCapture)
err = json.Unmarshal(resp.Raw, &quickCapture)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -151,7 +151,7 @@ func (b *Bitmex) wsHandleIncomingData() {
var respError WebsocketErrorResponse
if _, ok := quickCapture["status"]; ok {
err = common.JSONDecode(resp.Raw, &respError)
err = json.Unmarshal(resp.Raw, &respError)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -162,7 +162,7 @@ func (b *Bitmex) wsHandleIncomingData() {
if _, ok := quickCapture["success"]; ok {
var decodedResp WebsocketSubscribeResp
err := common.JSONDecode(resp.Raw, &decodedResp)
err := json.Unmarshal(resp.Raw, &decodedResp)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -189,7 +189,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Name, decodedResp.Subscribe)
} else if _, ok := quickCapture["table"]; ok {
var decodedResp WebsocketMainResponse
err := common.JSONDecode(resp.Raw, &decodedResp)
err := json.Unmarshal(resp.Raw, &decodedResp)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -198,7 +198,7 @@ func (b *Bitmex) wsHandleIncomingData() {
switch decodedResp.Table {
case bitmexWSOrderbookL2:
var orderbooks OrderBookData
err = common.JSONDecode(resp.Raw, &orderbooks)
err = json.Unmarshal(resp.Raw, &orderbooks)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -223,7 +223,7 @@ func (b *Bitmex) wsHandleIncomingData() {
case bitmexWSTrade:
var trades TradeData
err = common.JSONDecode(resp.Raw, &trades)
err = json.Unmarshal(resp.Raw, &trades)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -254,7 +254,7 @@ func (b *Bitmex) wsHandleIncomingData() {
case bitmexWSAnnouncement:
var announcement AnnouncementData
err = common.JSONDecode(resp.Raw, &announcement)
err = json.Unmarshal(resp.Raw, &announcement)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -267,7 +267,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- announcement.Data
case bitmexWSAffiliate:
var response WsAffiliateResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -275,7 +275,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSExecution:
var response WsExecutionResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -283,7 +283,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSOrder:
var response WsOrderResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -291,7 +291,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSMargin:
var response WsMarginResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -299,7 +299,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSPosition:
var response WsPositionResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -307,7 +307,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSPrivateNotifications:
var response WsPrivateNotificationsResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -315,7 +315,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSTransact:
var response WsTransactResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -323,7 +323,7 @@ func (b *Bitmex) wsHandleIncomingData() {
b.Websocket.DataHandler <- response
case bitmexWSWallet:
var response WsWalletResponse
err = common.JSONDecode(resp.Raw, &response)
err = json.Unmarshal(resp.Raw, &response)
if err != nil {
b.Websocket.DataHandler <- err
continue

View File

@@ -676,7 +676,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
return err
}
if err := common.JSONDecode(interim, &errCap); err == nil {
if err := json.Unmarshal(interim, &errCap); err == nil {
if errCap.Error != "" {
return errors.New(errCap.Error)
}
@@ -697,7 +697,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
}
}
return common.JSONDecode(interim, result)
return json.Unmarshal(interim, result)
}
func parseTime(dateTime string) (time.Time, error) {

View File

@@ -1,6 +1,7 @@
package bitstamp
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/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -67,7 +67,7 @@ func (b *Bitstamp) WsHandleData() {
}
b.Websocket.TrafficAlert <- struct{}{}
wsResponse := websocketResponse{}
err = common.JSONDecode(resp.Raw, &wsResponse)
err = json.Unmarshal(resp.Raw, &wsResponse)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -82,7 +82,7 @@ func (b *Bitstamp) WsHandleData() {
case "data":
wsOrderBookTemp := websocketOrderBookResponse{}
err := common.JSONDecode(resp.Raw, &wsOrderBookTemp)
err := json.Unmarshal(resp.Raw, &wsOrderBookTemp)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -100,7 +100,7 @@ func (b *Bitstamp) WsHandleData() {
case "trade":
wsTradeTemp := websocketTradeResponse{}
err := common.JSONDecode(resp.Raw, &wsTradeTemp)
err := json.Unmarshal(resp.Raw, &wsTradeTemp)
if err != nil {
b.Websocket.DataHandler <- err
continue

View File

@@ -2,6 +2,7 @@ package btcmarkets
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -391,7 +392,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data, result
payload := []byte("")
if data != nil {
payload, err = common.JSONEncode(data)
payload, err = json.Marshal(data)
if err != nil {
return err
}

View File

@@ -1,13 +1,13 @@
package btcmarkets
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -58,7 +58,7 @@ func (b *BTCMarkets) WsHandleData() {
}
b.Websocket.TrafficAlert <- struct{}{}
var wsResponse WsMessageType
err = common.JSONDecode(resp.Raw, &wsResponse)
err = json.Unmarshal(resp.Raw, &wsResponse)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -70,7 +70,7 @@ func (b *BTCMarkets) WsHandleData() {
}
case "orderbook":
var ob WsOrderbook
err := common.JSONDecode(resp.Raw, &ob)
err := json.Unmarshal(resp.Raw, &ob)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -131,7 +131,7 @@ func (b *BTCMarkets) WsHandleData() {
}
case "trade":
var trade WsTrade
err := common.JSONDecode(resp.Raw, &trade)
err := json.Unmarshal(resp.Raw, &trade)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -147,7 +147,7 @@ func (b *BTCMarkets) WsHandleData() {
}
case "tick":
var tick WsTick
err := common.JSONDecode(resp.Raw, &tick)
err := json.Unmarshal(resp.Raw, &tick)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -168,7 +168,7 @@ func (b *BTCMarkets) WsHandleData() {
}
case "error":
var wsErr WsError
err := common.JSONDecode(resp.Raw, &wsErr)
err := json.Unmarshal(resp.Raw, &wsErr)
if err != nil {
b.Websocket.DataHandler <- err
continue

View File

@@ -2,6 +2,7 @@ package btse
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
@@ -9,7 +10,6 @@ import (
"strconv"
"time"
"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"
@@ -215,7 +215,7 @@ func (b *BTSE) SendAuthenticatedHTTPRequest(method, endpoint string, req map[str
var payload []byte
if len(req) != 0 {
var err error
payload, err = common.JSONEncode(req)
payload, err = json.Marshal(req)
if err != nil {
return err
}

View File

@@ -1,6 +1,7 @@
package btse
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/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
@@ -63,7 +63,7 @@ func (b *BTSE) WsHandleData() {
type Result map[string]interface{}
result := Result{}
err = common.JSONDecode(resp.Raw, &result)
err = json.Unmarshal(resp.Raw, &result)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -76,7 +76,7 @@ func (b *BTSE) WsHandleData() {
"sell side",
b.Name)
var tradeHistory wsTradeHistory
err = common.JSONDecode(resp.Raw, &tradeHistory)
err = json.Unmarshal(resp.Raw, &tradeHistory)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -98,7 +98,7 @@ func (b *BTSE) WsHandleData() {
}
case strings.Contains(result["topic"].(string), "orderBookApi"):
var t wsOrderBook
err = common.JSONDecode(resp.Raw, &t)
err = json.Unmarshal(resp.Raw, &t)
if err != nil {
b.Websocket.DataHandler <- err
continue

View File

@@ -2,6 +2,7 @@ package coinbasepro
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -733,7 +734,7 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m
payload := []byte("")
if params != nil {
payload, err = common.JSONEncode(params)
payload, err = json.Marshal(params)
if err != nil {
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
}

View File

@@ -1,6 +1,7 @@
package coinbasepro
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -8,7 +9,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"
@@ -67,7 +67,7 @@ func (c *CoinbasePro) WsHandleData() {
}
msgType := MsgType{}
err = common.JSONDecode(resp.Raw, &msgType)
err = json.Unmarshal(resp.Raw, &msgType)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -83,7 +83,7 @@ func (c *CoinbasePro) WsHandleData() {
case "ticker":
ticker := WebsocketTicker{}
err := common.JSONDecode(resp.Raw, &ticker)
err := json.Unmarshal(resp.Raw, &ticker)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -105,7 +105,7 @@ func (c *CoinbasePro) WsHandleData() {
case "snapshot":
snapshot := WebsocketOrderbookSnapshot{}
err := common.JSONDecode(resp.Raw, &snapshot)
err := json.Unmarshal(resp.Raw, &snapshot)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -119,7 +119,7 @@ func (c *CoinbasePro) WsHandleData() {
case "l2update":
update := WebsocketL2Update{}
err := common.JSONDecode(resp.Raw, &update)
err := json.Unmarshal(resp.Raw, &update)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -133,7 +133,7 @@ func (c *CoinbasePro) WsHandleData() {
case "received":
// We currently use l2update to calculate orderbook changes
received := WebsocketReceived{}
err := common.JSONDecode(resp.Raw, &received)
err := json.Unmarshal(resp.Raw, &received)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -142,7 +142,7 @@ func (c *CoinbasePro) WsHandleData() {
case "open":
// We currently use l2update to calculate orderbook changes
open := WebsocketOpen{}
err := common.JSONDecode(resp.Raw, &open)
err := json.Unmarshal(resp.Raw, &open)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -151,7 +151,7 @@ func (c *CoinbasePro) WsHandleData() {
case "done":
// We currently use l2update to calculate orderbook changes
done := WebsocketDone{}
err := common.JSONDecode(resp.Raw, &done)
err := json.Unmarshal(resp.Raw, &done)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -160,7 +160,7 @@ func (c *CoinbasePro) WsHandleData() {
case "change":
// We currently use l2update to calculate orderbook changes
change := WebsocketChange{}
err := common.JSONDecode(resp.Raw, &change)
err := json.Unmarshal(resp.Raw, &change)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -169,7 +169,7 @@ func (c *CoinbasePro) WsHandleData() {
case "activate":
// We currently use l2update to calculate orderbook changes
activate := WebsocketActivate{}
err := common.JSONDecode(resp.Raw, &activate)
err := json.Unmarshal(resp.Raw, &activate)
if err != nil {
c.Websocket.DataHandler <- err
continue

View File

@@ -1,6 +1,7 @@
package coinbene
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"
@@ -102,7 +102,7 @@ func (c *Coinbene) WsDataHandler() {
continue
}
var result map[string]interface{}
err = common.JSONDecode(stream.Raw, &result)
err = json.Unmarshal(stream.Raw, &result)
if err != nil {
c.Websocket.DataHandler <- err
}
@@ -127,7 +127,7 @@ func (c *Coinbene) WsDataHandler() {
switch {
case strings.Contains(result[topic].(string), "ticker"):
var ticker WsTicker
err = common.JSONDecode(stream.Raw, &ticker)
err = json.Unmarshal(stream.Raw, &ticker)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -147,7 +147,7 @@ func (c *Coinbene) WsDataHandler() {
}
case strings.Contains(result[topic].(string), "tradeList"):
var tradeList WsTradeList
err = common.JSONDecode(stream.Raw, &tradeList)
err = json.Unmarshal(stream.Raw, &tradeList)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -183,7 +183,7 @@ func (c *Coinbene) WsDataHandler() {
}
case strings.Contains(result[topic].(string), "orderBook"):
var orderBook WsOrderbook
err = common.JSONDecode(stream.Raw, &orderBook)
err = json.Unmarshal(stream.Raw, &orderBook)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -264,7 +264,7 @@ func (c *Coinbene) WsDataHandler() {
var kline WsKline
var tempFloat float64
var tempKline []float64
err = common.JSONDecode(stream.Raw, &kline)
err = json.Unmarshal(stream.Raw, &kline)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -293,7 +293,7 @@ func (c *Coinbene) WsDataHandler() {
}
case strings.Contains(result[topic].(string), "user.account"):
var userinfo WsUserInfo
err = common.JSONDecode(stream.Raw, &userinfo)
err = json.Unmarshal(stream.Raw, &userinfo)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -301,7 +301,7 @@ func (c *Coinbene) WsDataHandler() {
c.Websocket.DataHandler <- userinfo
case strings.Contains(result[topic].(string), "user.position"):
var position WsPosition
err = common.JSONDecode(stream.Raw, &position)
err = json.Unmarshal(stream.Raw, &position)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -309,7 +309,7 @@ func (c *Coinbene) WsDataHandler() {
c.Websocket.DataHandler <- position
case strings.Contains(result[topic].(string), "user.order"):
var orders WsUserOrders
err = common.JSONDecode(stream.Raw, &orders)
err = json.Unmarshal(stream.Raw, &orders)
if err != nil {
c.Websocket.DataHandler <- err
continue

View File

@@ -8,7 +8,6 @@ import (
"net/http"
"strings"
"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"
@@ -284,7 +283,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
params["nonce"] = n
params["request"] = apiRequest
payload, err := common.JSONEncode(params)
payload, err := json.Marshal(params)
if err != nil {
return errors.New("sendHTTPRequest: Unable to JSON request")
}
@@ -317,7 +316,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
}
var genResp GenericResponse
err = common.JSONDecode(rawMsg, &genResp)
err = json.Unmarshal(rawMsg, &genResp)
if err != nil {
return err
}
@@ -327,7 +326,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
genResp.Status[0])
}
return common.JSONDecode(rawMsg, result)
return json.Unmarshal(rawMsg, result)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -1,6 +1,7 @@
package coinut
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -8,7 +9,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"
@@ -85,7 +85,7 @@ func (c *COINUT) WsHandleData() {
if strings.HasPrefix(string(resp.Raw), "[") {
var incoming []wsResponse
err = common.JSONDecode(resp.Raw, &incoming)
err = json.Unmarshal(resp.Raw, &incoming)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -96,7 +96,7 @@ func (c *COINUT) WsHandleData() {
break
}
var individualJSON []byte
individualJSON, err = common.JSONEncode(incoming[i])
individualJSON, err = json.Marshal(incoming[i])
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -105,7 +105,7 @@ func (c *COINUT) WsHandleData() {
}
} else {
var incoming wsResponse
err = common.JSONDecode(resp.Raw, &incoming)
err = json.Unmarshal(resp.Raw, &incoming)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -119,7 +119,7 @@ func (c *COINUT) WsHandleData() {
func (c *COINUT) wsProcessResponse(resp []byte) {
var incoming wsResponse
err := common.JSONDecode(resp, &incoming)
err := json.Unmarshal(resp, &incoming)
if err != nil {
c.Websocket.DataHandler <- err
return
@@ -129,7 +129,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
channels["hb"] <- resp
case "inst_tick":
var ticker WsTicker
err := common.JSONDecode(resp, &ticker)
err := json.Unmarshal(resp, &ticker)
if err != nil {
c.Websocket.DataHandler <- err
return
@@ -154,7 +154,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
case "inst_order_book":
var orderbooksnapshot WsOrderbookSnapshot
err := common.JSONDecode(resp, &orderbooksnapshot)
err := json.Unmarshal(resp, &orderbooksnapshot)
if err != nil {
c.Websocket.DataHandler <- err
return
@@ -174,7 +174,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
}
case "inst_order_book_update":
var orderbookUpdate WsOrderbookUpdate
err := common.JSONDecode(resp, &orderbookUpdate)
err := json.Unmarshal(resp, &orderbookUpdate)
if err != nil {
c.Websocket.DataHandler <- err
return
@@ -194,7 +194,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
}
case "inst_trade":
var tradeSnap WsTradeSnapshot
err := common.JSONDecode(resp, &tradeSnap)
err := json.Unmarshal(resp, &tradeSnap)
if err != nil {
c.Websocket.DataHandler <- err
return
@@ -202,7 +202,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
case "inst_trade_update":
var tradeUpdate WsTradeUpdate
err := common.JSONDecode(resp, &tradeUpdate)
err := json.Unmarshal(resp, &tradeUpdate)
if err != nil {
c.Websocket.DataHandler <- err
return
@@ -250,7 +250,7 @@ func (c *COINUT) WsSetInstrumentList() error {
return err
}
var list WsInstrumentList
err = common.JSONDecode(resp, &list)
err = json.Unmarshal(resp, &list)
if err != nil {
return err
}
@@ -357,7 +357,7 @@ func (c *COINUT) Unsubscribe(channelToSubscribe wshandler.WebsocketChannelSubscr
return err
}
var response map[string]interface{}
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}
@@ -394,7 +394,7 @@ func (c *COINUT) wsAuthenticate() error {
return err
}
var response map[string]interface{}
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}
@@ -419,7 +419,7 @@ func (c *COINUT) wsGetAccountBalance() (*WsGetAccountBalanceResponse, error) {
return nil, err
}
var response WsGetAccountBalanceResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -466,14 +466,14 @@ func (c *COINUT) wsSubmitOrder(order *WsSubmitOrderParameters) (*WsStandardOrder
func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderResponse, error) {
var response WsStandardOrderResponse
var incoming wsResponse
err := common.JSONDecode(resp, &incoming)
err := json.Unmarshal(resp, &incoming)
if err != nil {
return response, err
}
switch incoming.Reply {
case "order_accepted":
var orderAccepted WsOrderAcceptedResponse
err := common.JSONDecode(resp, &orderAccepted)
err := json.Unmarshal(resp, &orderAccepted)
if err != nil {
return response, err
}
@@ -492,7 +492,7 @@ func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderRespons
}
case "order_filled":
var orderFilled WsOrderFilledResponse
err := common.JSONDecode(resp, &orderFilled)
err := json.Unmarshal(resp, &orderFilled)
if err != nil {
return response, err
}
@@ -511,7 +511,7 @@ func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderRespons
}
case "order_rejected":
var orderRejected WsOrderRejectedResponse
err := common.JSONDecode(resp, &orderRejected)
err := json.Unmarshal(resp, &orderRejected)
if err != nil {
return response, err
}
@@ -561,14 +561,14 @@ func (c *COINUT) wsSubmitOrders(orders []WsSubmitOrderParameters) ([]WsStandardO
return nil, errors
}
var incoming []interface{}
err = common.JSONDecode(resp, &incoming)
err = json.Unmarshal(resp, &incoming)
if err != nil {
errors = append(errors, err)
return nil, errors
}
for i := range incoming {
var individualJSON []byte
individualJSON, err = common.JSONEncode(incoming[i])
individualJSON, err = json.Marshal(incoming[i])
if err != nil {
errors = append(errors, err)
continue
@@ -612,7 +612,7 @@ func (c *COINUT) wsGetOpenOrders(p currency.Pair) error {
return err
}
var response map[string]interface{}
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}
@@ -640,7 +640,7 @@ func (c *COINUT) wsCancelOrder(cancellation WsCancelOrderParameters) error {
return err
}
var response map[string]interface{}
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}
@@ -675,7 +675,7 @@ func (c *COINUT) wsCancelOrders(cancellations []WsCancelOrderParameters) (*WsCan
return nil, []error{err}
}
var response WsCancelOrdersResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, []error{err}
}
@@ -711,7 +711,7 @@ func (c *COINUT) wsGetTradeHistory(p currency.Pair, start, limit int64) error {
return err
}
var response map[string]interface{}
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return err
}

View File

@@ -82,7 +82,7 @@ func (e *Base) SetClientProxyAddress(addr string) error {
// No needs to check err here as the only err condition is an empty
// string which is already checked above
e.Requester.SetProxy(proxy)
_ = e.Requester.SetProxy(proxy)
if e.Websocket != nil {
err = e.Websocket.SetProxyAddress(addr)
@@ -460,7 +460,7 @@ func (e *Base) SetupDefaults(exch *config.ExchangeConfig) error {
}
if e.Features.Supports.Websocket {
e.Websocket.Initialise()
return e.Websocket.Initialise()
}
return nil
}

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
}

View File

@@ -1,6 +1,7 @@
package gemini
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -371,7 +372,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st
req[key] = value
}
PayloadJSON, err := common.JSONEncode(req)
PayloadJSON, err := json.Marshal(req)
if err != nil {
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
}

View File

@@ -3,6 +3,7 @@
package gemini
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -11,7 +12,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"
@@ -99,7 +99,7 @@ func (g *Gemini) WsSecureSubscribe(dialer *websocket.Dialer, url string) error {
Request: fmt.Sprintf("/v1/%v", url),
Nonce: time.Now().UnixNano(),
}
PayloadJSON, err := common.JSONEncode(payload)
PayloadJSON, err := json.Marshal(payload)
if err != nil {
return fmt.Errorf("%v sendAuthenticatedHTTPRequest: Unable to JSON request", g.Name)
}
@@ -166,7 +166,7 @@ func (g *Gemini) WsHandleData() {
continue
}
var result map[string]interface{}
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- fmt.Errorf("%v Error: %v, Raw: %v", g.Name, err, string(resp.Raw))
continue
@@ -174,7 +174,7 @@ func (g *Gemini) WsHandleData() {
switch result["type"] {
case "subscription_ack":
var result WsSubscriptionAcknowledgementResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -182,7 +182,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "initial":
var result WsSubscriptionAcknowledgementResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -190,7 +190,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "accepted":
var result WsActiveOrdersResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -198,7 +198,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "booked":
var result WsOrderBookedResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -206,7 +206,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "fill":
var result WsOrderFilledResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -214,7 +214,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "cancelled":
var result WsOrderCancelledResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -222,7 +222,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "closed":
var result WsOrderClosedResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -230,7 +230,7 @@ func (g *Gemini) WsHandleData() {
g.Websocket.DataHandler <- result
case "heartbeat":
var result WsHeartbeatResponse
err := common.JSONDecode(resp.Raw, &result)
err := json.Unmarshal(resp.Raw, &result)
if err != nil {
g.Websocket.DataHandler <- err
continue
@@ -243,7 +243,7 @@ func (g *Gemini) WsHandleData() {
continue
}
var marketUpdate WsMarketUpdateResponse
err := common.JSONDecode(resp.Raw, &marketUpdate)
err := json.Unmarshal(resp.Raw, &marketUpdate)
if err != nil {
g.Websocket.DataHandler <- err
continue

View File

@@ -1,6 +1,7 @@
package hitbtc
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -8,7 +9,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"
@@ -71,7 +71,7 @@ func (h *HitBTC) WsHandleData() {
h.Websocket.TrafficAlert <- struct{}{}
var init capture
err = common.JSONDecode(resp.Raw, &init)
err = json.Unmarshal(resp.Raw, &init)
if err != nil {
h.Websocket.DataHandler <- err
continue
@@ -105,7 +105,7 @@ func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, ini
switch init.Method {
case "ticker":
var ticker WsTicker
err := common.JSONDecode(resp.Raw, &ticker)
err := json.Unmarshal(resp.Raw, &ticker)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -132,7 +132,7 @@ func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, ini
}
case "snapshotOrderbook":
var obSnapshot WsOrderbook
err := common.JSONDecode(resp.Raw, &obSnapshot)
err := json.Unmarshal(resp.Raw, &obSnapshot)
if err != nil {
h.Websocket.DataHandler <- err
}
@@ -142,33 +142,33 @@ func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, ini
}
case "updateOrderbook":
var obUpdate WsOrderbook
err := common.JSONDecode(resp.Raw, &obUpdate)
err := json.Unmarshal(resp.Raw, &obUpdate)
if err != nil {
h.Websocket.DataHandler <- err
}
h.WsProcessOrderbookUpdate(obUpdate)
case "snapshotTrades":
var tradeSnapshot WsTrade
err := common.JSONDecode(resp.Raw, &tradeSnapshot)
err := json.Unmarshal(resp.Raw, &tradeSnapshot)
if err != nil {
h.Websocket.DataHandler <- err
}
case "updateTrades":
var tradeUpdates WsTrade
err := common.JSONDecode(resp.Raw, &tradeUpdates)
err := json.Unmarshal(resp.Raw, &tradeUpdates)
if err != nil {
h.Websocket.DataHandler <- err
}
case "activeOrders":
var activeOrders WsActiveOrdersResponse
err := common.JSONDecode(resp.Raw, &activeOrders)
err := json.Unmarshal(resp.Raw, &activeOrders)
if err != nil {
h.Websocket.DataHandler <- err
}
h.Websocket.DataHandler <- activeOrders
case "report":
var reportData WsReportResponse
err := common.JSONDecode(resp.Raw, &reportData)
err := json.Unmarshal(resp.Raw, &reportData)
if err != nil {
h.Websocket.DataHandler <- err
}
@@ -182,21 +182,21 @@ func (h *HitBTC) handleCommandResponses(resp wshandler.WebsocketResponse, init c
switch resultType["reportType"].(string) {
case "new":
var response WsSubmitOrderSuccessResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
h.Websocket.DataHandler <- response
case "canceled":
var response WsCancelOrderResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
h.Websocket.DataHandler <- response
case "replaced":
var response WsReplaceOrderResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
@@ -210,14 +210,14 @@ func (h *HitBTC) handleCommandResponses(resp wshandler.WebsocketResponse, init c
data := resultType[0].(map[string]interface{})
if _, ok := data["clientOrderId"]; ok {
var response WsActiveOrdersResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
h.Websocket.DataHandler <- response
} else if _, ok := data["available"]; ok {
var response WsGetTradingBalanceResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
@@ -437,7 +437,7 @@ func (h *HitBTC) wsPlaceOrder(pair currency.Pair, side string, price, quantity f
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsSubmitOrderSuccessResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -464,7 +464,7 @@ func (h *HitBTC) wsCancelOrder(clientOrderID string) (*WsCancelOrderResponse, er
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsCancelOrderResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -494,7 +494,7 @@ func (h *HitBTC) wsReplaceOrder(clientOrderID string, quantity, price float64) (
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsReplaceOrderResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -519,7 +519,7 @@ func (h *HitBTC) wsGetActiveOrders() (*WsActiveOrdersResponse, error) {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsActiveOrdersResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -544,7 +544,7 @@ func (h *HitBTC) wsGetTradingBalance() (*WsGetTradingBalanceResponse, error) {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsGetTradingBalanceResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -568,7 +568,7 @@ func (h *HitBTC) wsGetCurrencies(currencyItem currency.Code) (*WsGetCurrenciesRe
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsGetCurrenciesResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -592,7 +592,7 @@ func (h *HitBTC) wsGetSymbols(currencyItem currency.Pair) (*WsGetSymbolsResponse
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsGetSymbolsResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}
@@ -619,7 +619,7 @@ func (h *HitBTC) wsGetTrades(currencyItem currency.Pair, limit int64, sort, by s
return nil, fmt.Errorf("%v %v", h.Name, err)
}
var response WsGetTradesResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, fmt.Errorf("%v %v", h.Name, err)
}

View File

@@ -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
}

View File

@@ -305,7 +305,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
var err error
if params != nil {
PayloadJSON, err = common.JSONEncode(req)
PayloadJSON, err = json.Marshal(req)
if err != nil {
return err
}
@@ -317,7 +317,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
n := i.Requester.GetNonce(true).String()
timestamp := strconv.FormatInt(time.Now().UnixNano()/1000000, 10)
message, err := common.JSONEncode([]string{method, urlPath, string(PayloadJSON), n, timestamp})
message, err := json.Marshal([]string{method, urlPath, string(PayloadJSON), n, timestamp})
if err != nil {
return err
}
@@ -354,7 +354,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
return err
}
err = common.JSONDecode(intermediary, &errCheck)
err = json.Unmarshal(intermediary, &errCheck)
if err == nil {
if errCheck.Code != 0 || errCheck.Description != "" {
return fmt.Errorf("itbit.go SendAuthRequest error code: %d description: %s",
@@ -363,7 +363,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
}
}
return common.JSONDecode(intermediary, result)
return json.Unmarshal(intermediary, result)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -1,6 +1,7 @@
package kraken
import (
"encoding/json"
"errors"
"fmt"
"math"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -116,14 +116,14 @@ func (k *Kraken) WsHandleData() {
k.Websocket.TrafficAlert <- struct{}{}
// event response handling
var eventResponse WebsocketEventResponse
err = common.JSONDecode(resp.Raw, &eventResponse)
err = json.Unmarshal(resp.Raw, &eventResponse)
if err == nil && eventResponse.Event != "" {
k.WsHandleEventResponse(&eventResponse, resp.Raw)
continue
}
// Data response handling
var dataResponse WebsocketDataResponse
err = common.JSONDecode(resp.Raw, &dataResponse)
err = json.Unmarshal(resp.Raw, &dataResponse)
if err == nil && dataResponse[0].(float64) >= 0 {
k.WsHandleDataResponse(dataResponse)
continue

View File

@@ -1,13 +1,13 @@
package lakebtc
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"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"
@@ -302,7 +302,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
postData["id"] = 1
postData["params"] = strings.Split(params, ",")
data, err := common.JSONEncode(postData)
data, err := json.Marshal(postData)
if err != nil {
return err
}

View File

@@ -1,13 +1,13 @@
package lakebtc
import (
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
@@ -141,7 +141,7 @@ func (l *LakeBTC) wsHandleIncomingData() {
func (l *LakeBTC) processTrades(data, channel string) error {
var tradeData WsTrades
err := common.JSONDecode([]byte(data), &tradeData)
err := json.Unmarshal([]byte(data), &tradeData)
if err != nil {
return err
}
@@ -164,7 +164,7 @@ func (l *LakeBTC) processTrades(data, channel string) error {
func (l *LakeBTC) processOrderbook(obUpdate, channel string) error {
var update WsOrderbookUpdate
err := common.JSONDecode([]byte(obUpdate), &update)
err := json.Unmarshal([]byte(obUpdate), &update)
if err != nil {
return err
}
@@ -236,7 +236,7 @@ func (l *LakeBTC) getCurrencyFromChannel(channel string) currency.Pair {
func (l *LakeBTC) processTicker(ticker string) error {
var tUpdate map[string]interface{}
err := common.JSONDecode([]byte(ticker), &tUpdate)
err := json.Unmarshal([]byte(ticker), &tUpdate)
if err != nil {
l.Websocket.DataHandler <- err
return err

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,6 @@ import (
"time"
"github.com/google/go-querystring/query"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
@@ -566,7 +565,7 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
payload := []byte("")
if data != nil {
payload, err = common.JSONEncode(data)
payload, err = json.Marshal(data)
if err != nil {
return errors.New("sendHTTPRequest: Unable to JSON request")
}
@@ -617,7 +616,7 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
return err
}
err = common.JSONDecode(intermediary, &errCap)
err = json.Unmarshal(intermediary, &errCap)
if err == nil {
if errCap.ErrorMessage != "" {
return fmt.Errorf("error: %v", errCap.ErrorMessage)
@@ -631,7 +630,7 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
}
}
return common.JSONDecode(intermediary, result)
return json.Unmarshal(intermediary, result)
}
// SetCheckVarDefaults sets main variables that will be used in requests because

View File

@@ -1,6 +1,7 @@
package okgroup
import (
"encoding/json"
"errors"
"fmt"
"hash/crc32"
@@ -11,7 +12,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"
@@ -226,7 +226,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
}
o.Websocket.TrafficAlert <- struct{}{}
var dataResponse WebsocketDataResponse
err = common.JSONDecode(resp.Raw, &dataResponse)
err = json.Unmarshal(resp.Raw, &dataResponse)
if err == nil && dataResponse.Table != "" {
if len(dataResponse.Data) > 0 {
o.WsHandleDataResponse(&dataResponse)
@@ -234,7 +234,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
continue
}
var errorResponse WebsocketErrorResponse
err = common.JSONDecode(resp.Raw, &errorResponse)
err = json.Unmarshal(resp.Raw, &errorResponse)
if err == nil && errorResponse.ErrorCode > 0 {
if o.Verbose {
log.Debugf(log.ExchangeSys,
@@ -247,7 +247,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
continue
}
var eventResponse WebsocketEventResponse
err = common.JSONDecode(resp.Raw, &eventResponse)
err = json.Unmarshal(resp.Raw, &eventResponse)
if err == nil && eventResponse.Event != "" {
if eventResponse.Event == "login" {
o.Websocket.SetCanUseAuthenticatedEndpoints(eventResponse.Success)

View File

@@ -1,6 +1,7 @@
package poloniex
import (
"encoding/json"
"net/http"
"testing"
"time"
@@ -425,7 +426,7 @@ func TestWsHandleAccountData(t *testing.T) {
}
for i := range jsons {
var result [][]interface{}
err := common.JSONDecode([]byte(jsons[i]), &result)
err := json.Unmarshal([]byte(jsons[i]), &result)
if err != nil {
t.Error(err)
}

View File

@@ -1,6 +1,7 @@
package poloniex
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"
@@ -95,7 +95,7 @@ func (p *Poloniex) WsHandleData() {
}
p.Websocket.TrafficAlert <- struct{}{}
var result interface{}
err = common.JSONDecode(resp.Raw, &result)
err = json.Unmarshal(resp.Raw, &result)
if err != nil {
p.Websocket.DataHandler <- err
continue

View File

@@ -2,6 +2,7 @@ package request
import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io"
@@ -329,7 +330,7 @@ func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, re
}
if result != nil {
return common.JSONDecode(contents, result)
return json.Unmarshal(contents, result)
}
return nil

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"compress/flate"
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
@@ -15,7 +16,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/config"
log "github.com/thrasher-corp/gocryptotrader/logger"
)
@@ -653,7 +653,7 @@ func (w *WebsocketConnection) SendMessage(data interface{}) error {
if !w.IsConnected() {
return fmt.Errorf("%v cannot send message to a disconnected websocket", w.ExchangeName)
}
json, err := common.JSONEncode(data)
json, err := json.Marshal(data)
if err != nil {
return err
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"compress/flate"
"compress/gzip"
"encoding/json"
"errors"
"net"
"net/http"
@@ -14,7 +15,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
)
@@ -666,7 +666,7 @@ func readMessages(wc *WebsocketConnection, t *testing.T) {
return
}
var incoming testResponse
err = common.JSONDecode(resp.Raw, &incoming)
err = json.Unmarshal(resp.Raw, &incoming)
if err != nil {
t.Error(err)
return

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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
}