diff --git a/cmd/exchange_wrapper_issues/main.go b/cmd/exchange_wrapper_issues/main.go index 377c36584f4..e4d2b6e4451 100644 --- a/cmd/exchange_wrapper_issues/main.go +++ b/cmd/exchange_wrapper_issues/main.go @@ -13,7 +13,6 @@ import ( "sync" "text/template" - "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/common/file" "github.com/thrasher-corp/gocryptotrader/config" "github.com/thrasher-corp/gocryptotrader/currency" @@ -737,7 +736,7 @@ func loadConfig() (Config, error) { return config, err } - err = common.JSONDecode(keys, &config) + err = json.Unmarshal(keys, &config) return config, err } diff --git a/cmd/websocket_client/main.go b/cmd/websocket_client/main.go index c71b8876cad..858dbc86fa2 100644 --- a/cmd/websocket_client/main.go +++ b/cmd/websocket_client/main.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "errors" "fmt" "log" @@ -113,13 +114,13 @@ func main() { } log.Printf("Fetched config.") - dataJSON, err := common.JSONEncode(&wsResp.Data) + dataJSON, err := json.Marshal(&wsResp.Data) if err != nil { log.Fatal(err) } var resultCfg config.Config - err = common.JSONDecode(dataJSON, &resultCfg) + err = json.Unmarshal(dataJSON, &resultCfg) if err != nil { log.Fatal(err) } diff --git a/common/common.go b/common/common.go index dcabebf82bd..83229675637 100644 --- a/common/common.go +++ b/common/common.go @@ -12,13 +12,11 @@ import ( "os" "os/user" "path/filepath" - "reflect" "regexp" "strconv" "strings" "time" - "github.com/gofrs/uuid" log "github.com/thrasher-corp/gocryptotrader/logger" ) @@ -43,11 +41,6 @@ const ( WeiPerEther = 1000000000000000000 ) -// GetV4UUID returns a RFC 4122 UUID based on random numbers -func GetV4UUID() (uuid.UUID, error) { - return uuid.NewV4() -} - func initialiseHTTPClient() { // If the HTTPClient isn't set, start a new client with a default timeout of 15 seconds if HTTPClient == nil { @@ -227,7 +220,7 @@ func SendHTTPGetRequest(urlPath string, jsonDecode, isVerbose bool, result inter defer res.Body.Close() if jsonDecode { - err := JSONDecode(contents, result) + err := json.Unmarshal(contents, result) if err != nil { return err } @@ -236,19 +229,6 @@ func SendHTTPGetRequest(urlPath string, jsonDecode, isVerbose bool, result inter return nil } -// JSONEncode encodes structure data into JSON -func JSONEncode(v interface{}) ([]byte, error) { - return json.Marshal(v) -} - -// JSONDecode decodes JSON data into a structure -func JSONDecode(data []byte, to interface{}) error { - if !strings.Contains(reflect.ValueOf(to).Type().String(), "*") { - return errors.New("json decode error - memory address not supplied") - } - return json.Unmarshal(data, to) -} - // EncodeURLValues concatenates url values onto a url string and returns a // string func EncodeURLValues(urlPath string, values url.Values) string { diff --git a/common/common_test.go b/common/common_test.go index 10a7a858c73..7f892fbf907 100644 --- a/common/common_test.go +++ b/common/common_test.go @@ -263,62 +263,6 @@ func TestSendHTTPGetRequest(t *testing.T) { } } -func TestJSONEncode(t *testing.T) { - t.Parallel() - type test struct { - Status int `json:"status"` - Data []struct { - Address string `json:"address"` - Balance float64 `json:"balance"` - Nonce interface{} `json:"nonce"` - Code string `json:"code"` - Name interface{} `json:"name"` - Storage interface{} `json:"storage"` - FirstSeen interface{} `json:"firstSeen"` - } `json:"data"` - } - expectOutputString := `{"status":0,"data":null}` - v := test{} - - bitey, err := JSONEncode(v) - if err != nil { - t.Errorf("common JSONEncode error: %s", err) - } - if string(bitey) != expectOutputString { - t.Error("common JSONEncode error") - } - _, err = JSONEncode("WigWham") - if err != nil { - t.Errorf("common JSONEncode error: %s", err) - } -} - -func TestJSONDecode(t *testing.T) { - t.Parallel() - var data []byte - result := "Not a memory address" - err := JSONDecode(data, result) - if err == nil { - t.Error("Common JSONDecode, unmarshalled when address not supplied") - } - - type test struct { - Status int `json:"status"` - Data []struct { - Address string `json:"address"` - Balance float64 `json:"balance"` - } `json:"data"` - } - - var v test - data = []byte(`{"status":1,"data":null}`) - err = JSONDecode(data, &v) - if err != nil || v.Status != 1 { - t.Errorf("Common JSONDecode. Data: %v \nError: %s", - v, err) - } -} - func TestEncodeURLValues(t *testing.T) { t.Parallel() urlstring := "https://www.test.com" diff --git a/communications/communications_test.go b/communications/communications_test.go index cbc90dc58d5..82717bc6e76 100644 --- a/communications/communications_test.go +++ b/communications/communications_test.go @@ -10,7 +10,7 @@ func TestNewComm(t *testing.T) { var cfg config.CommunicationsConfig _, err := NewComm(&cfg) if err == nil { - t.Error("NewComm should failed on no enabled communication mediums") + t.Error("NewComm should have failed on no enabled communication mediums") } cfg.TelegramConfig.Enabled = true diff --git a/communications/slack/slack.go b/communications/slack/slack.go index 900925a32dd..eb7b0b81db3 100644 --- a/communications/slack/slack.go +++ b/communications/slack/slack.go @@ -82,7 +82,7 @@ func (s *Slack) PushEvent(event base.Event) error { return s.WebsocketSend("message", fmt.Sprintf("event: %s %s", event.Type, event.Message)) } - return nil + return errors.New("slack not connected") } // BuildURL returns an appended token string with the SlackURL @@ -212,7 +212,7 @@ func (s *Slack) WebsocketReader() { } var data WebsocketResponse - err = common.JSONDecode(resp, &data) + err = json.Unmarshal(resp, &data) if err != nil { log.Errorln(log.CommunicationMgr, err) continue @@ -253,7 +253,7 @@ func (s *Slack) WebsocketReader() { func (s *Slack) handlePresenceChange(resp []byte) error { var pres PresenceChange - err := common.JSONDecode(resp, &pres) + err := json.Unmarshal(resp, &pres) if err != nil { return err } @@ -270,7 +270,7 @@ func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error return errors.New("reply to is != 0") } var msg Message - err := common.JSONDecode(resp, &msg) + err := json.Unmarshal(resp, &msg) if err != nil { return err } @@ -318,7 +318,7 @@ func (s *Slack) handleReconnectResponse(resp []byte) error { URL string `json:"url"` } var recURL reconnectResponse - err := common.JSONDecode(resp, &recURL) + err := json.Unmarshal(resp, &recURL) if err != nil { return err } diff --git a/communications/slack/slack_test.go b/communications/slack/slack_test.go index 4996d2b17b6..5b1563c02d7 100644 --- a/communications/slack/slack_test.go +++ b/communications/slack/slack_test.go @@ -1,9 +1,9 @@ package slack import ( + "encoding/json" "testing" - "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/communications/base" "github.com/thrasher-corp/gocryptotrader/config" ) @@ -198,7 +198,7 @@ func TestHandlePresenceChange(t *testing.T) { t.Error("slack handlePresenceChange(), unmarshalled malformed json") } - data, _ := common.JSONEncode(pres) + data, _ := json.Marshal(pres) err = s.handlePresenceChange(data) if err != nil { t.Errorf("slack handlePresenceChange() Error: %s", err) @@ -225,7 +225,7 @@ func TestHandleMessageResponse(t *testing.T) { var msg Message msg.User = "1337" msg.Text = "Hello World!" - resp, _ := common.JSONEncode(msg) + resp, _ := json.Marshal(msg) err = s.handleMessageResponse(resp, data) if err != nil { @@ -233,7 +233,7 @@ func TestHandleMessageResponse(t *testing.T) { } msg.Text = "!notacommand" - resp, _ = common.JSONEncode(msg) + resp, _ = json.Marshal(msg) err = s.handleMessageResponse(resp, data) if err == nil { @@ -270,7 +270,7 @@ func TestHandleReconnectResponse(t *testing.T) { } testURL.URL = "https://www.thrasher.io" - data, _ := common.JSONEncode(testURL) + data, _ := json.Marshal(testURL) err = s.handleReconnectResponse(data) if err != nil || s.ReconnectURL != "https://www.thrasher.io" { diff --git a/communications/telegram/telegram.go b/communications/telegram/telegram.go index 05c9bb122a7..30a41b33eae 100644 --- a/communications/telegram/telegram.go +++ b/communications/telegram/telegram.go @@ -5,6 +5,7 @@ package telegram import ( "bytes" + "encoding/json" "errors" "fmt" "net/http" @@ -219,7 +220,7 @@ func (t *Telegram) SendMessage(text string, chatID int64) error { text, } - json, err := common.JSONEncode(&messageToSend) + json, err := json.Marshal(&messageToSend) if err != nil { return err } @@ -241,14 +242,17 @@ func (t *Telegram) SendMessage(text string, chatID int64) error { } // SendHTTPRequest sends an authenticated HTTP request -func (t *Telegram) SendHTTPRequest(path string, json []byte, result interface{}) error { +func (t *Telegram) SendHTTPRequest(path string, data []byte, result interface{}) error { headers := make(map[string]string) headers["content-type"] = "application/json" - resp, err := common.SendHTTPRequest(http.MethodPost, path, headers, bytes.NewBuffer(json)) + resp, err := common.SendHTTPRequest(http.MethodPost, + path, + headers, + bytes.NewBuffer(data)) if err != nil { return err } - return common.JSONDecode([]byte(resp), result) + return json.Unmarshal([]byte(resp), result) } diff --git a/config/config_encryption.go b/config/config_encryption.go index 6ec7d3d4ee1..51f9464da39 100644 --- a/config/config_encryption.go +++ b/config/config_encryption.go @@ -5,6 +5,7 @@ import ( "crypto/aes" "crypto/cipher" "crypto/rand" + "encoding/json" "errors" "fmt" "io" @@ -168,7 +169,7 @@ func DecryptConfigFile(configData, key []byte) ([]byte, error) { // ConfirmConfigJSON confirms JSON in file func ConfirmConfigJSON(file []byte, result interface{}) error { - return common.JSONDecode(file, &result) + return json.Unmarshal(file, &result) } // ConfirmSalt checks whether the encrypted data contains a salt diff --git a/currency/code.go b/currency/code.go index e19915306b8..eadae29339a 100644 --- a/currency/code.go +++ b/currency/code.go @@ -1,6 +1,7 @@ package currency import ( + "encoding/json" "errors" "fmt" "strings" @@ -11,7 +12,7 @@ import ( func (r Role) String() string { switch r { case Unset: - return UnsetRollString + return UnsetRoleString case Fiat: return FiatCurrencyString case Cryptocurrency: @@ -25,21 +26,21 @@ func (r Role) String() string { } } -// MarshalJSON conforms Roll to the marshaller interface +// MarshalJSON conforms Role to the marshaller interface func (r Role) MarshalJSON() ([]byte, error) { - return common.JSONEncode(r.String()) + return json.Marshal(r.String()) } -// UnmarshalJSON conforms Roll to the unmarshaller interface +// UnmarshalJSON conforms Role to the unmarshaller interface func (r *Role) UnmarshalJSON(d []byte) error { var incoming string - err := common.JSONDecode(d, &incoming) + err := json.Unmarshal(d, &incoming) if err != nil { return err } switch incoming { - case UnsetRollString: + case UnsetRoleString: *r = Unset case FiatCurrencyString: *r = Fiat @@ -400,7 +401,7 @@ func (c Code) Upper() Code { // UnmarshalJSON comforms type to the umarshaler interface func (c *Code) UnmarshalJSON(d []byte) error { var newcode string - err := common.JSONDecode(d, &newcode) + err := json.Unmarshal(d, &newcode) if err != nil { return err } @@ -411,9 +412,9 @@ func (c *Code) UnmarshalJSON(d []byte) error { // MarshalJSON conforms type to the marshaler interface func (c Code) MarshalJSON() ([]byte, error) { if c.Item == nil { - return common.JSONEncode("") + return json.Marshal("") } - return common.JSONEncode(c.String()) + return json.Marshal(c.String()) } // IsEmpty returns true if the code is empty diff --git a/currency/code_test.go b/currency/code_test.go index e27dc4c6252..1568a7e403a 100644 --- a/currency/code_test.go +++ b/currency/code_test.go @@ -1,15 +1,14 @@ package currency import ( + "encoding/json" "testing" - - "github.com/thrasher-corp/gocryptotrader/common" ) func TestRoleString(t *testing.T) { - if Unset.String() != UnsetRollString { + if Unset.String() != UnsetRoleString { t.Errorf("Role String() error expected %s but received %s", - UnsetRollString, + UnsetRoleString, Unset) } @@ -47,7 +46,7 @@ func TestRoleString(t *testing.T) { } func TestRoleMarshalJSON(t *testing.T) { - d, err := common.JSONEncode(Fiat) + d, err := json.Marshal(Fiat) if err != nil { t.Error("Role MarshalJSON() error", err) } @@ -79,23 +78,23 @@ func TestRoleUnmarshalJSON(t *testing.T) { RoleFive: Contract, } - e, err := common.JSONEncode(1337) + e, err := json.Marshal(1337) if err != nil { t.Fatal("Role UnmarshalJSON() error", err) } var incoming AllTheRoles - err = common.JSONDecode(e, &incoming) + err = json.Unmarshal(e, &incoming) if err == nil { t.Fatal("Role UnmarshalJSON() Expected error") } - e, err = common.JSONEncode(outgoing) + e, err = json.Marshal(outgoing) if err != nil { t.Fatal("Role UnmarshalJSON() error", err) } - err = common.JSONDecode(e, &incoming) + err = json.Unmarshal(e, &incoming) if err != nil { t.Fatal("Role UnmarshalJSON() error", err) } @@ -365,17 +364,17 @@ func TestCodeUpper(t *testing.T) { func TestCodeUnmarshalJSON(t *testing.T) { var unmarshalHere Code expected := "BRO" - encoded, err := common.JSONEncode(expected) + encoded, err := json.Marshal(expected) if err != nil { t.Fatal("Currency Code UnmarshalJSON error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Currency Code UnmarshalJSON error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Currency Code UnmarshalJSON error", err) } @@ -396,7 +395,7 @@ func TestCodeMarshalJSON(t *testing.T) { expectedJSON := `{"sweetCodes":"BRO"}` - encoded, err := common.JSONEncode(quickstruct) + encoded, err := json.Marshal(quickstruct) if err != nil { t.Fatal("Currency Code UnmarshalJSON error", err) } @@ -413,7 +412,7 @@ func TestCodeMarshalJSON(t *testing.T) { Codey: Code{}, // nil code } - encoded, err = common.JSONEncode(quickstruct) + encoded, err = json.Marshal(quickstruct) if err != nil { t.Fatal("Currency Code UnmarshalJSON error", err) } diff --git a/currency/code_types.go b/currency/code_types.go index cff8e6e3e2d..d387a076226 100644 --- a/currency/code_types.go +++ b/currency/code_types.go @@ -5,7 +5,7 @@ import ( "time" ) -// Bitmasks const for currency rolls +// Bitmasks const for currency roles const ( Unset Role = 0 Fiat Role = 1 << (iota - 1) @@ -13,14 +13,14 @@ const ( Token Contract - UnsetRollString = "roleUnset" + UnsetRoleString = "roleUnset" FiatCurrencyString = "fiatCurrency" CryptocurrencyString = "cryptocurrency" TokenString = "token" ContractString = "contract" ) -// Role defines a bitmask for the full currency rolls either; fiat, +// Role defines a bitmask for the full currency roles either; fiat, // cryptocurrency, token, or contract type Role uint8 diff --git a/currency/currencies.go b/currency/currencies.go index 7c3b5338ebe..2647fbc128b 100644 --- a/currency/currencies.go +++ b/currency/currencies.go @@ -1,9 +1,8 @@ package currency import ( + "encoding/json" "strings" - - "github.com/thrasher-corp/gocryptotrader/common" ) // NewCurrenciesFromStringArray returns a Currencies object from strings @@ -48,7 +47,7 @@ func (c Currencies) Join() string { // UnmarshalJSON comforms type to the umarshaler interface func (c *Currencies) UnmarshalJSON(d []byte) error { var configCurrencies string - err := common.JSONDecode(d, &configCurrencies) + err := json.Unmarshal(d, &configCurrencies) if err != nil { return err } @@ -64,7 +63,7 @@ func (c *Currencies) UnmarshalJSON(d []byte) error { // MarshalJSON conforms type to the marshaler interface func (c Currencies) MarshalJSON() ([]byte, error) { - return common.JSONEncode(c.Join()) + return json.Marshal(c.Join()) } // Match returns if the full list equals the supplied list diff --git a/currency/currencies_test.go b/currency/currencies_test.go index 6805ebf18bf..d97df832760 100644 --- a/currency/currencies_test.go +++ b/currency/currencies_test.go @@ -1,25 +1,24 @@ package currency import ( + "encoding/json" "testing" - - "github.com/thrasher-corp/gocryptotrader/common" ) func TestCurrenciesUnmarshalJSON(t *testing.T) { var unmarshalHere Currencies expected := "btc,usd,ltc,bro,things" - encoded, err := common.JSONEncode(expected) + encoded, err := json.Marshal(expected) if err != nil { t.Fatal("Currencies UnmarshalJSON() error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Currencies UnmarshalJSON() error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Currencies UnmarshalJSON() error", err) } @@ -37,7 +36,7 @@ func TestCurrenciesMarshalJSON(t *testing.T) { C: NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "things"}), } - encoded, err := common.JSONEncode(quickStruct) + encoded, err := json.Marshal(quickStruct) if err != nil { t.Fatal("Currencies MarshalJSON() error", err) } diff --git a/currency/pair.go b/currency/pair.go index e3c6fcddf56..cd699ebb099 100644 --- a/currency/pair.go +++ b/currency/pair.go @@ -1,10 +1,9 @@ package currency import ( + "encoding/json" "fmt" "strings" - - "github.com/thrasher-corp/gocryptotrader/common" ) // NewPairDelimiter splits the desired currency string at delimeter, the returns @@ -113,7 +112,7 @@ func (p Pair) Upper() Pair { // UnmarshalJSON comforms type to the umarshaler interface func (p *Pair) UnmarshalJSON(d []byte) error { var pair string - err := common.JSONDecode(d, &pair) + err := json.Unmarshal(d, &pair) if err != nil { return err } @@ -124,7 +123,7 @@ func (p *Pair) UnmarshalJSON(d []byte) error { // MarshalJSON conforms type to the marshaler interface func (p Pair) MarshalJSON() ([]byte, error) { - return common.JSONEncode(p.String()) + return json.Marshal(p.String()) } // Format changes the currency based on user preferences overriding the default diff --git a/currency/pair_test.go b/currency/pair_test.go index 87b7c5ffed4..837d52e2f0d 100644 --- a/currency/pair_test.go +++ b/currency/pair_test.go @@ -1,9 +1,8 @@ package currency import ( + "encoding/json" "testing" - - "github.com/thrasher-corp/gocryptotrader/common" ) const ( @@ -37,17 +36,17 @@ func TestPairUnmarshalJSON(t *testing.T) { var unmarshalHere Pair configPair := NewPairDelimiter("btc_usd", "_") - encoded, err := common.JSONEncode(configPair) + encoded, err := json.Marshal(configPair) if err != nil { t.Fatal("Pair UnmarshalJSON() error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Pair UnmarshalJSON() error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Pair UnmarshalJSON() error", err) } @@ -65,7 +64,7 @@ func TestPairMarshalJSON(t *testing.T) { Pair{Base: BTC, Quote: USD, Delimiter: "-"}, } - encoded, err := common.JSONEncode(quickstruct) + encoded, err := json.Marshal(quickstruct) if err != nil { t.Fatal("Pair MarshalJSON() error", err) } diff --git a/currency/pairs.go b/currency/pairs.go index f383f99dfe5..66dd4617879 100644 --- a/currency/pairs.go +++ b/currency/pairs.go @@ -1,10 +1,10 @@ package currency import ( + "encoding/json" "math/rand" "strings" - "github.com/thrasher-corp/gocryptotrader/common" log "github.com/thrasher-corp/gocryptotrader/logger" ) @@ -68,7 +68,7 @@ func (p Pairs) Format(delimiter, index string, uppercase bool) Pairs { // UnmarshalJSON comforms type to the umarshaler interface func (p *Pairs) UnmarshalJSON(d []byte) error { var pairs string - err := common.JSONDecode(d, &pairs) + err := json.Unmarshal(d, &pairs) if err != nil { return err } @@ -89,7 +89,7 @@ func (p *Pairs) UnmarshalJSON(d []byte) error { // MarshalJSON conforms type to the marshaler interface func (p Pairs) MarshalJSON() ([]byte, error) { - return common.JSONEncode(p.Join()) + return json.Marshal(p.Join()) } // Upper returns an upper formatted pair list diff --git a/currency/pairs_test.go b/currency/pairs_test.go index d58d57d1b89..1af69a8fa7e 100644 --- a/currency/pairs_test.go +++ b/currency/pairs_test.go @@ -1,9 +1,8 @@ package currency import ( + "encoding/json" "testing" - - "github.com/thrasher-corp/gocryptotrader/common" ) func TestPairsUpper(t *testing.T) { @@ -69,33 +68,33 @@ func TestPairsFormat(t *testing.T) { func TestPairsUnmarshalJSON(t *testing.T) { var unmarshalHere Pairs configPairs := "" - encoded, err := common.JSONEncode(configPairs) + encoded, err := json.Marshal(configPairs) if err != nil { t.Fatal("Pairs UnmarshalJSON() error", err) } - err = common.JSONDecode([]byte{1, 3, 3, 7}, &unmarshalHere) + err = json.Unmarshal([]byte{1, 3, 3, 7}, &unmarshalHere) if err == nil { t.Fatal("error cannot be nil") } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Pairs UnmarshalJSON() error", err) } configPairs = "btc_usd,btc_aud,btc_ltc" - encoded, err = common.JSONEncode(configPairs) + encoded, err = json.Marshal(configPairs) if err != nil { t.Fatal("Pairs UnmarshalJSON() error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Pairs UnmarshalJSON() error", err) } - err = common.JSONDecode(encoded, &unmarshalHere) + err = json.Unmarshal(encoded, &unmarshalHere) if err != nil { t.Fatal("Pairs UnmarshalJSON() error", err) } @@ -113,7 +112,7 @@ func TestPairsMarshalJSON(t *testing.T) { Pairs: NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"}), } - encoded, err := common.JSONEncode(quickstruct) + encoded, err := json.Marshal(quickstruct) if err != nil { t.Fatal("Pairs MarshalJSON() error", err) } diff --git a/currency/storage.go b/currency/storage.go index e4148647896..b0452f0edb6 100644 --- a/currency/storage.go +++ b/currency/storage.go @@ -8,7 +8,6 @@ import ( "path/filepath" "time" - "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/common/file" "github.com/thrasher-corp/gocryptotrader/currency/coinmarketcap" "github.com/thrasher-corp/gocryptotrader/currency/forexprovider" @@ -264,7 +263,7 @@ func (s *Storage) SeedCurrencyAnalysisData() error { } var fromFile File - err = common.JSONDecode(b, &fromFile) + err = json.Unmarshal(b, &fromFile) if err != nil { return err } @@ -364,7 +363,7 @@ func (s *Storage) LoadFileCurrencyData(f *File) error { return nil } -// UpdateCurrencies updates currency roll and information using coin market cap +// UpdateCurrencies updates currency role and information using coin market cap func (s *Storage) UpdateCurrencies() error { m, err := s.currencyAnalysis.GetCryptocurrencyIDMap() if err != nil { diff --git a/dispatch/mux.go b/dispatch/mux.go index 1c741e67981..38037403b24 100644 --- a/dispatch/mux.go +++ b/dispatch/mux.go @@ -62,12 +62,11 @@ func (m *Mux) Publish(ids []uuid.UUID, data interface{}) error { return nil } -// GetID gets a lovely new ID +// GetID a new unique ID to track routing information in the dispatch system func (m *Mux) GetID() (uuid.UUID, error) { if m == nil { return uuid.UUID{}, errors.New("mux is nil") } - return m.d.getNewID() } diff --git a/engine/connection.go b/engine/connection.go index beb97324af5..01f46db6274 100644 --- a/engine/connection.go +++ b/engine/connection.go @@ -15,10 +15,12 @@ type connectionManager struct { conn *connchecker.Checker } +// Started returns if the connection manager has started func (c *connectionManager) Started() bool { return atomic.LoadInt32(&c.started) == 1 } +// Start starts an instance of the connection manager func (c *connectionManager) Start() error { if atomic.AddInt32(&c.started, 1) != 1 { return errors.New("connection manager already started") @@ -38,6 +40,7 @@ func (c *connectionManager) Start() error { return nil } +// Stop stops the connection manager func (c *connectionManager) Stop() error { if atomic.LoadInt32(&c.started) == 0 { return errors.New("connection manager not started") @@ -55,6 +58,7 @@ func (c *connectionManager) Stop() error { return nil } +// IsOnline returns if the connection manager is online func (c *connectionManager) IsOnline() bool { if c.conn == nil { log.Warnln(log.ConnectionMgr, "Connection manager: IsOnline called but conn is nil") diff --git a/engine/orders.go b/engine/orders.go index e23671ff311..303df5346fc 100644 --- a/engine/orders.go +++ b/engine/orders.go @@ -6,6 +6,7 @@ import ( "sync/atomic" "time" + "github.com/gofrs/uuid" "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/communications/base" "github.com/thrasher-corp/gocryptotrader/exchanges/order" @@ -207,7 +208,7 @@ func (o *orderManager) Submit(exchName string, newOrder *order.Submit) (*orderSu return nil, errors.New("unable to get exchange by name") } - id, err := common.GetV4UUID() + id, err := uuid.NewV4() if err != nil { log.Warnf(log.OrderMgr, "Order manager: Unable to generate UUID. Err: %s\n", diff --git a/engine/websocket.go b/engine/websocket.go index 21613fd426a..2f3c1431f25 100644 --- a/engine/websocket.go +++ b/engine/websocket.go @@ -1,12 +1,12 @@ package engine import ( + "encoding/json" "errors" "net/http" "strings" "github.com/gorilla/websocket" - "github.com/thrasher-corp/gocryptotrader/common" "github.com/thrasher-corp/gocryptotrader/common/crypto" "github.com/thrasher-corp/gocryptotrader/config" "github.com/thrasher-corp/gocryptotrader/currency" @@ -79,7 +79,7 @@ func (h *WebsocketHub) run() { // SendWebsocketMessage sends a websocket event to the client func (c *WebsocketClient) SendWebsocketMessage(evt interface{}) error { - data, err := common.JSONEncode(evt) + data, err := json.Marshal(evt) if err != nil { log.Errorf(log.WebsocketMgr, "websocket: failed to send message: %s\n", err) return err @@ -106,7 +106,7 @@ func (c *WebsocketClient) read() { if msgType == websocket.TextMessage { var evt WebsocketEvent - err := common.JSONDecode(message, &evt) + err := json.Unmarshal(message, &evt) if err != nil { log.Errorf(log.WebsocketMgr, "websocket: failed to decode JSON sent from client %s\n", err) continue @@ -117,7 +117,7 @@ func (c *WebsocketClient) read() { continue } - dataJSON, err := common.JSONEncode(evt.Data) + dataJSON, err := json.Marshal(evt.Data) if err != nil { log.Errorln(log.WebsocketMgr, "websocket: client sent data we couldn't JSON decode") break @@ -197,7 +197,7 @@ func BroadcastWebsocketMessage(evt WebsocketEvent) error { return errors.New("websocket service not started") } - data, err := common.JSONEncode(evt) + data, err := json.Marshal(evt) if err != nil { return err } @@ -257,7 +257,7 @@ func wsAuth(client *WebsocketClient, data interface{}) error { } var auth WebsocketAuth - err := common.JSONDecode(data.([]byte), &auth) + err := json.Unmarshal(data.([]byte), &auth) if err != nil { wsResp.Error = err.Error() client.SendWebsocketMessage(wsResp) @@ -303,7 +303,7 @@ func wsSaveConfig(client *WebsocketClient, data interface{}) error { Event: "SaveConfig", } var cfg config.Config - err := common.JSONDecode(data.([]byte), &cfg) + err := json.Unmarshal(data.([]byte), &cfg) if err != nil { wsResp.Error = err.Error() client.SendWebsocketMessage(wsResp) @@ -344,7 +344,7 @@ func wsGetTicker(client *WebsocketClient, data interface{}) error { Event: "GetTicker", } var tickerReq WebsocketOrderbookTickerRequest - err := common.JSONDecode(data.([]byte), &tickerReq) + err := json.Unmarshal(data.([]byte), &tickerReq) if err != nil { wsResp.Error = err.Error() client.SendWebsocketMessage(wsResp) @@ -376,7 +376,7 @@ func wsGetOrderbook(client *WebsocketClient, data interface{}) error { Event: "GetOrderbook", } var orderbookReq WebsocketOrderbookTickerRequest - err := common.JSONDecode(data.([]byte), &orderbookReq) + err := json.Unmarshal(data.([]byte), &orderbookReq) if err != nil { wsResp.Error = err.Error() client.SendWebsocketMessage(wsResp) diff --git a/exchanges/alphapoint/alphapoint.go b/exchanges/alphapoint/alphapoint.go index f1ea56dbbd0..33400dd2156 100644 --- a/exchanges/alphapoint/alphapoint.go +++ b/exchanges/alphapoint/alphapoint.go @@ -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") } diff --git a/exchanges/alphapoint/alphapoint_test.go b/exchanges/alphapoint/alphapoint_test.go index eed2d25319d..964cd0d8519 100644 --- a/exchanges/alphapoint/alphapoint_test.go +++ b/exchanges/alphapoint/alphapoint_test.go @@ -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) } diff --git a/exchanges/alphapoint/alphapoint_websocket.go b/exchanges/alphapoint/alphapoint_websocket.go index 05f389b2186..ebb1329d786 100644 --- a/exchanges/alphapoint/alphapoint_websocket.go +++ b/exchanges/alphapoint/alphapoint_websocket.go @@ -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 diff --git a/exchanges/anx/anx.go b/exchanges/anx/anx.go index 666aaddf6a6..09bf290a665 100644 --- a/exchanges/anx/anx.go +++ b/exchanges/anx/anx.go @@ -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") } diff --git a/exchanges/asset/asset.go b/exchanges/asset/asset.go index 771374823b5..43947812656 100644 --- a/exchanges/asset/asset.go +++ b/exchanges/asset/asset.go @@ -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 diff --git a/exchanges/binance/binance.go b/exchanges/binance/binance.go index 2dbbdf94998..17e609f1a36 100644 --- a/exchanges/binance/binance.go +++ b/exchanges/binance/binance.go @@ -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 diff --git a/exchanges/binance/binance_websocket.go b/exchanges/binance/binance_websocket.go index f555d48d703..ab4379354c9 100644 --- a/exchanges/binance/binance_websocket.go +++ b/exchanges/binance/binance_websocket.go @@ -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, diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index 80113385903..5e185410b17 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -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") } diff --git a/exchanges/bitfinex/bitfinex_websocket.go b/exchanges/bitfinex/bitfinex_websocket.go index be6ff69ebd5..3fb9a7f9117 100644 --- a/exchanges/bitfinex/bitfinex_websocket.go +++ b/exchanges/bitfinex/bitfinex_websocket.go @@ -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 diff --git a/exchanges/bithumb/bithumb.go b/exchanges/bithumb/bithumb.go index 77589394277..3cdd892adc2 100644 --- a/exchanges/bithumb/bithumb.go +++ b/exchanges/bithumb/bithumb.go @@ -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 diff --git a/exchanges/bitmex/bitmex.go b/exchanges/bitmex/bitmex.go index 33f1723802f..a073a9238aa 100644 --- a/exchanges/bitmex/bitmex.go +++ b/exchanges/bitmex/bitmex.go @@ -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 diff --git a/exchanges/bitmex/bitmex_websocket.go b/exchanges/bitmex/bitmex_websocket.go index a31316484ad..b0338ad96a0 100644 --- a/exchanges/bitmex/bitmex_websocket.go +++ b/exchanges/bitmex/bitmex_websocket.go @@ -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 diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index 202944d6c4a..61b7b5fc8d2 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -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) { diff --git a/exchanges/bitstamp/bitstamp_websocket.go b/exchanges/bitstamp/bitstamp_websocket.go index 3cee9712de7..8bc002491cc 100644 --- a/exchanges/bitstamp/bitstamp_websocket.go +++ b/exchanges/bitstamp/bitstamp_websocket.go @@ -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 diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index 88679ad64e8..11882328f2c 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -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 } diff --git a/exchanges/btcmarkets/btcmarkets_websocket.go b/exchanges/btcmarkets/btcmarkets_websocket.go index 285eef431c5..7b5d39172c8 100644 --- a/exchanges/btcmarkets/btcmarkets_websocket.go +++ b/exchanges/btcmarkets/btcmarkets_websocket.go @@ -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 diff --git a/exchanges/btse/btse.go b/exchanges/btse/btse.go index bf2e2ac671e..99faa3b7303 100644 --- a/exchanges/btse/btse.go +++ b/exchanges/btse/btse.go @@ -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 } diff --git a/exchanges/btse/btse_websocket.go b/exchanges/btse/btse_websocket.go index e12d3eebdf6..b5bc399741d 100644 --- a/exchanges/btse/btse_websocket.go +++ b/exchanges/btse/btse_websocket.go @@ -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 diff --git a/exchanges/coinbasepro/coinbasepro.go b/exchanges/coinbasepro/coinbasepro.go index da81870cbbe..8ebcab1afe3 100644 --- a/exchanges/coinbasepro/coinbasepro.go +++ b/exchanges/coinbasepro/coinbasepro.go @@ -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") } diff --git a/exchanges/coinbasepro/coinbasepro_websocket.go b/exchanges/coinbasepro/coinbasepro_websocket.go index 7cd93295e16..96c80b44b85 100644 --- a/exchanges/coinbasepro/coinbasepro_websocket.go +++ b/exchanges/coinbasepro/coinbasepro_websocket.go @@ -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 diff --git a/exchanges/coinbene/coinbene_websocket.go b/exchanges/coinbene/coinbene_websocket.go index 791cabae832..c1245a7c697 100644 --- a/exchanges/coinbene/coinbene_websocket.go +++ b/exchanges/coinbene/coinbene_websocket.go @@ -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 diff --git a/exchanges/coinut/coinut.go b/exchanges/coinut/coinut.go index 034c3e22138..4ba2ec97b3c 100644 --- a/exchanges/coinut/coinut.go +++ b/exchanges/coinut/coinut.go @@ -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 diff --git a/exchanges/coinut/coinut_websocket.go b/exchanges/coinut/coinut_websocket.go index 9b0935dc0e7..6d242239132 100644 --- a/exchanges/coinut/coinut_websocket.go +++ b/exchanges/coinut/coinut_websocket.go @@ -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 } diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 4932817e604..0f76eb909c9 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -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 } diff --git a/exchanges/gateio/gateio.go b/exchanges/gateio/gateio.go index fef8d55b3dd..d9551eb94b0 100644 --- a/exchanges/gateio/gateio.go +++ b/exchanges/gateio/gateio.go @@ -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 diff --git a/exchanges/gateio/gateio_websocket.go b/exchanges/gateio/gateio_websocket.go index 7534760814f..04545179098 100644 --- a/exchanges/gateio/gateio_websocket.go +++ b/exchanges/gateio/gateio_websocket.go @@ -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 } diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index 794677e44ee..cc5d96a69bf 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -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") } diff --git a/exchanges/gemini/gemini_websocket.go b/exchanges/gemini/gemini_websocket.go index c4926252e08..9815ab366a5 100644 --- a/exchanges/gemini/gemini_websocket.go +++ b/exchanges/gemini/gemini_websocket.go @@ -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 diff --git a/exchanges/hitbtc/hitbtc_websocket.go b/exchanges/hitbtc/hitbtc_websocket.go index ea0cf2fd9f1..e77522ffab6 100644 --- a/exchanges/hitbtc/hitbtc_websocket.go +++ b/exchanges/hitbtc/hitbtc_websocket.go @@ -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) } diff --git a/exchanges/huobi/huobi_websocket.go b/exchanges/huobi/huobi_websocket.go index 0b1d8cecf22..fa7022f4b5d 100644 --- a/exchanges/huobi/huobi_websocket.go +++ b/exchanges/huobi/huobi_websocket.go @@ -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 } diff --git a/exchanges/itbit/itbit.go b/exchanges/itbit/itbit.go index 9a4a69581cc..555853f50dc 100644 --- a/exchanges/itbit/itbit.go +++ b/exchanges/itbit/itbit.go @@ -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 diff --git a/exchanges/kraken/kraken_websocket.go b/exchanges/kraken/kraken_websocket.go index f4c2ceb9fa5..1be268b1fb5 100644 --- a/exchanges/kraken/kraken_websocket.go +++ b/exchanges/kraken/kraken_websocket.go @@ -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 diff --git a/exchanges/lakebtc/lakebtc.go b/exchanges/lakebtc/lakebtc.go index 498e88df2db..1aef5c5bb68 100644 --- a/exchanges/lakebtc/lakebtc.go +++ b/exchanges/lakebtc/lakebtc.go @@ -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 } diff --git a/exchanges/lakebtc/lakebtc_websocket.go b/exchanges/lakebtc/lakebtc_websocket.go index 81879957ce2..0639ddc3fe8 100644 --- a/exchanges/lakebtc/lakebtc_websocket.go +++ b/exchanges/lakebtc/lakebtc_websocket.go @@ -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 diff --git a/exchanges/okcoin/okcoin_test.go b/exchanges/okcoin/okcoin_test.go index 5c57708c70d..8b7fa4903c8 100644 --- a/exchanges/okcoin/okcoin_test.go +++ b/exchanges/okcoin/okcoin_test.go @@ -1,6 +1,7 @@ package okcoin import ( + "encoding/json" "net/http" "strings" "sync" @@ -878,7 +879,7 @@ func TestOrderBookUpdateChecksumCalculator(t *testing.T) { original := `{"table":"spot/depth","action":"partial","data":[{"instrument_id":"BTC-USDT","asks":[["3864.6786","0.145",1],["3864.7682","0.005",1],["3864.9851","0.57",1],["3864.9852","0.30137754",1],["3864.9986","2.81818419",1],["3864.9995","0.002",1],["3865","0.0597",1],["3865.0309","0.4",1],["3865.1995","0.004",1],["3865.3995","0.004",1],["3865.5995","0.004",1],["3865.7995","0.004",1],["3865.9995","0.004",1],["3866.0961","0.25865886",1],["3866.1995","0.004",1],["3866.3995","0.004",1],["3866.4004","0.3243",2],["3866.5995","0.004",1],["3866.7633","0.44247086",1],["3866.7995","0.004",1],["3866.9197","0.511",1],["3867.256","0.51716256",1],["3867.3951","0.02588112",1],["3867.4014","0.025",1],["3867.4566","0.02499999",1],["3867.4675","4.01155057",5],["3867.5515","1.1",1],["3867.6113","0.009",1],["3867.7349","0.026",1],["3867.7781","0.03738652",1],["3867.9163","0.0521",1],["3868.0381","0.34354941",1],["3868.0436","0.051",1],["3868.0657","0.90552172",3],["3868.1819","0.03863346",1],["3868.2013","0.194",1],["3868.346","0.051",1],["3868.3863","0.01155",1],["3868.7716","0.009",1],["3868.947","0.025",1],["3868.98","0.001",1],["3869.0764","1.03487931",1],["3869.2773","0.07724578",1],["3869.4039","0.025",1],["3869.4068","1.03",1],["3869.7068","2.06976398",1],["3870","0.5",1],["3870.0465","0.01",1],["3870.7042","0.02099651",1],["3870.9451","2.07047375",1],["3871.5254","1.2",1],["3871.5596","0.001",1],["3871.6605","0.01035032",1],["3871.7179","2.07047375",1],["3871.8816","0.51751625",1],["3872.1","0.75",1],["3872.2464","0.0646",1],["3872.3747","0.283",1],["3872.4039","0.2",1],["3872.7655","0.23179307",1],["3872.8005","2.06976398",1],["3873.1509","2",1],["3873.3215","0.26",1],["3874.1392","0.001",1],["3874.1487","3.88224364",4],["3874.1685","1.8",1],["3874.5571","0.08974762",1],["3874.734","2.06976398",1],["3874.99","0.3",1],["3875","1.001",2],["3875.0041","1.03505051",1],["3875.45","0.3",1],["3875.4766","0.15",1],["3875.7057","0.51751625",1],["3876","0.001",1],["3876.68","0.3",1],["3876.7188","0.001",1],["3877","0.75",1],["3877.31","0.035",1],["3877.38","0.3",1],["3877.7","0.3",1],["3877.88","0.3",1],["3878.0364","0.34770122",1],["3878.4525","0.48579748",1],["3878.4955","0.02812511",1],["3878.8855","0.00258579",1],["3878.9605","0.895",1],["3879","0.001",1],["3879.2984","0.002",2],["3879.432","0.001",1],["3879.6313","6",1],["3879.9999","0.002",2],["3880","1.25132834",5],["3880.2526","0.04075162",1],["3880.7145","0.0647",1],["3881.2469","1.883",1],["3881.878","0.002",2],["3884.4576","0.002",2],["3885","0.002",2],["3885.2233","0.28304103",1],["3885.7416","18",1],["3886","0.001",1],["3886.1554","5.4",1],["3887","0.001",1],["3887.0372","0.002",2],["3887.2559","0.05214011",1],["3887.9238","0.0019",1],["3888","0.15810538",4],["3889","0.001",1],["3889.5175","0.50510653",1],["3889.6168","0.002",2],["3889.9999","0.001",1],["3890","2.34968109",4],["3890.5222","0.00257806",1],["3891.2659","5",1],["3891.9999","0.00893897",1],["3892.1964","0.002",2],["3892.4358","0.0176",1],["3893.1388","1.4279",1],["3894","0.0026321",1],["3894.776","0.001",1],["3895","1.501",2],["3895.379","0.25881288",1],["3897","0.05",1],["3897.3556","0.001",1],["3897.8432","0.73708079",1],["3898","3.31353018",7],["3898.4462","4.757",1],["3898.6","0.47159638",1],["3898.8769","0.0129",1],["3899","6",2],["3899.6516","0.025",1],["3899.9352","0.001",1],["3899.9999","0.013",2],["3900","22.37447743",24],["3900.9999","0.07763916",1],["3901","0.10192487",1],["3902.1937","0.00257034",1],["3902.3991","1.5532141",1],["3902.5148","0.001",1],["3904","1.49331984",1],["3904.9999","0.95905447",1],["3905","0.501",2],["3905.0944","0.001",1],["3905.61","0.099",1],["3905.6801","0.54343686",1],["3906.2901","0.0258",1],["3907.674","0.001",1],["3907.85","1.35778084",1],["3908","0.03846153",1],["3908.23","1.95189531",1],["3908.906","0.03148978",1],["3909","0.001",1],["3909.9999","0.01398721",2],["3910","0.016",2],["3910.2536","0.001",1],["3912.5406","0.88270517",1],["3912.8332","0.001",1],["3913","1.2640608",1],["3913.87","1.69114184",1],["3913.9003","0.00256266",1],["3914","1.21766411",1],["3915","0.001",1],["3915.4128","0.001",1],["3915.7425","6.848",1],["3916","0.0050949",1],["3917.36","1.28658296",1],["3917.9924","0.001",1],["3919","0.001",1],["3919.9999","0.001",1],["3920","1.21171832",3],["3920.0002","0.20217038",1],["3920.572","0.001",1],["3921","0.128",1],["3923.0756","0.00148064",1],["3923.1516","0.001",1],["3923.86","1.38831714",1],["3925","0.01867801",2],["3925.642","0.00255499",1],["3925.7312","0.001",1],["3926","0.04290757",1],["3927","0.023",1],["3927.3175","0.01212865",1],["3927.65","1.51375612",1],["3928","0.5",1],["3928.3108","0.001",1],["3929","0.001",1],["3929.9999","0.01519338",2],["3930","0.0174985",3],["3930.21","1.49335799",1],["3930.8904","0.001",1],["3932.2999","0.01953",1],["3932.8962","7.96",1],["3933.0387","11.808",1],["3933.47","0.001",1],["3934","1.40839932",1],["3935","0.001",1],["3936.8","0.62879518",1],["3937.23","1.56977841",1],["3937.4189","0.00254735",1]],"bids":[["3864.5217","0.00540709",1],["3864.5216","0.14068758",2],["3864.2275","0.01033576",1],["3864.0989","0.00825047",1],["3864.0273","0.38",1],["3864.0272","0.4",1],["3863.9957","0.01083539",1],["3863.9184","0.01653723",1],["3863.8282","0.25588165",1],["3863.8153","0.154",1],["3863.7791","1.14122492",1],["3863.6866","0.01733662",1],["3863.6093","0.02645958",1],["3863.3775","0.02773862",1],["3863.0297","0.513",1],["3863.0286","1.1028564",2],["3862.8489","0.01",1],["3862.5972","0.01890179",1],["3862.3431","0.01152944",1],["3862.313","0.009",1],["3862.2445","0.90551002",3],["3862.0734","0.014",1],["3862.0539","0.64976067",1],["3861.8586","0.025",1],["3861.7888","0.025",1],["3861.7673","0.008",1],["3861.5785","0.01",1],["3861.3895","0.005",1],["3861.3338","0.25875855",1],["3861.161","0.01",1],["3861.1111","0.03863352",1],["3861.0732","0.51703882",1],["3860.9116","0.17754895",1],["3860.75","0.19",1],["3860.6554","0.015",1],["3860.6172","0.005",1],["3860.6088","0.008",1],["3860.4724","0.12940042",1],["3860.4424","0.25880084",1],["3860.42","0.01",1],["3860.3725","0.51760102",1],["3859.8449","0.005",1],["3859.8285","0.03738652",1],["3859.7638","0.07726703",1],["3859.4502","0.008",1],["3859.3772","0.05173471",1],["3859.3409","0.194",1],["3859","5",1],["3858.827","0.0521",1],["3858.8208","0.001",1],["3858.679","0.26",1],["3858.4814","0.07477305",1],["3858.1669","1.03503422",1],["3857.6005","0.006",1],["3857.4005","0.004",1],["3857.2005","0.004",1],["3857.1871","1.218",1],["3857.0005","0.004",1],["3856.8135","0.0646",1],["3856.8005","0.004",1],["3856.2412","0.001",1],["3856.2349","1.03503422",1],["3856.0197","0.01037339",1],["3855.8781","0.23178117",1],["3855.8005","0.004",1],["3855.7165","0.00259355",1],["3855.4858","0.25875855",1],["3854.4584","0.01",1],["3853.6616","0.001",1],["3853.1373","0.92",1],["3852.5072","0.48599702",1],["3851.3926","0.13008333",1],["3851.082","0.001",1],["3850.9317","2",1],["3850.6359","0.34770165",1],["3850.2058","0.51751624",1],["3850.0823","0.15",1],["3850.0042","0.5175171",1],["3850","0.001",1],["3849.6325","1.8",1],["3849.41","0.3",1],["3848.9686","1.85",1],["3848.7426","0.18511466",1],["3848.52","0.3",1],["3848.5024","0.001",1],["3848.42","0.3",1],["3848.1618","2.204",1],["3847.77","0.3",1],["3847.48","0.3",1],["3847.3581","2.05",1],["3846.8259","0.0646",1],["3846.59","0.3",1],["3846.49","0.3",1],["3845.9228","0.001",1],["3844.184","0.00260133",1],["3844.0092","6.3",1],["3843.3432","0.001",1],["3841","0.06300963",1],["3840.7636","0.001",1],["3840","0.201",3],["3839.7681","18",1],["3839.5328","0.05214011",1],["3838.184","0.001",1],["3837.2344","0.27589557",1],["3836.6479","5.2",1],["3836","2.37196773",3],["3835.6044","0.001",1],["3833.6053","0.25873556",1],["3833.0248","0.001",1],["3833","0.8726502",1],["3832.6859","0.00260913",1],["3832","0.007",1],["3831.637","6",1],["3831.0602","0.001",1],["3830.4452","0.001",1],["3830","0.20375718",4],["3829.7125","0.07833486",1],["3829.6283","0.3519681",1],["3829","0.0039261",1],["3827.8656","0.001",1],["3826.0001","0.53251232",1],["3826","0.0509",1],["3825.7834","0.00698562",1],["3825.286","0.001",1],["3823.0001","0.03010127",1],["3822.8014","0.00261588",1],["3822.7064","0.001",1],["3822.2","1",1],["3822.1121","0.35994101",1],["3821.2222","0.00261696",1],["3821","0.001",1],["3820.1268","0.001",1],["3820","1.12992803",4],["3819","0.01331195",2],["3817.5472","0.001",1],["3816","1.13807184",2],["3815.8343","0.32463428",1],["3815.7834","0.00525295",1],["3815","28.99386799",4],["3814.9676","0.001",1],["3813","0.91303023",4],["3812.388","0.002",2],["3811.2257","0.07",1],["3810","0.32573997",2],["3809.8084","0.001",1],["3809.7928","0.00262481",1],["3807.2288","0.001",1],["3806.8421","0.07003461",1],["3806","0.19",1],["3805.8041","0.05678805",1],["3805","1.01",2],["3804.6492","0.001",1],["3804.3551","0.1",1],["3803","0.005",1],["3802.22","2.05042631",1],["3802.0696","0.001",1],["3802","1.63290092",1],["3801.2257","0.07",1],["3801","57.4",3],["3800.9853","0.02492278",1],["3800.8421","0.06503533",1],["3800.7844","0.02812628",1],["3800.0001","0.00409473",1],["3800","17.91401074",15],["3799.49","0.001",1],["3799","0.1",1],["3796.9104","0.001",1],["3796","9.00128053",2],["3795.5441","0.0028",1],["3794.3308","0.001",1],["3791","55",1],["3790.7777","0.07",1],["3790","12.03238184",7],["3789","1",1],["3788","0.21110454",2],["3787.2959","9",1],["3786.592","0.001",1],["3786","9.01916822",2],["3785","12.87914268",5],["3784.0124","0.001",1],["3781.4328","0.002",2],["3781","56.3",2],["3780.7777","0.07",1],["3780","23.41537654",10],["3778.8532","0.002",2],["3776","9",1],["3774","0.003",1],["3772.2481","0.06901672",1],["3771","55.1",2],["3770.7777","0.07",1],["3770","7.30268416",5],["3769","0.25",1],["3768","1.3725",3],["3766.66","0.02",1],["3766","7.64837924",2],["3765.58","1.22775492",1],["3762.58","1.22873383",1],["3761","51.68262164",1],["3760.8031","0.0399",1],["3760.7777","0.07",1]],"timestamp":"2019-03-06T23:19:17.705Z","checksum":-1785549915}]}` update := `{"table":"spot/depth","action":"update","data":[{"instrument_id":"BTC-USDT","asks":[["3864.6786","0",0],["3864.9852","0",0],["3865.9994","0.48402971",1],["3866.4004","0.001",1],["3866.7995","0.3273",2],["3867.4566","0",0],["3867.7031","0.025",1],["3868.0436","0",0],["3868.346","0",0],["3868.3695","0.051",1],["3870.9243","0.642",1],["3874.9942","0.51751796",1],["3875.7057","0",0],["3939","0.001",1]],"bids":[["3864.55","0.0565449",1],["3863.8282","0",0],["3863.8153","0",0],["3863.7898","0.01320077",1],["3863.4807","0.02112123",1],["3863.3002","0.04233533",1],["3863.1717","0.03379397",1],["3863.0685","0.04438179",1],["3863.0286","0.7362564",1],["3862.9912","0.06773651",1],["3862.8626","0.05407035",1],["3862.7595","0.07101087",1],["3862.313","0.3756",2],["3862.1848","0.012",1],["3862.0734","0",0],["3861.8391","0.025",1],["3861.7888","0",0],["3856.6716","0.38893641",1],["3768","0",0],["3766.66","0",0],["3766","0",0],["3765.58","0",0],["3762.58","0",0],["3761","0",0],["3760.8031","0",0],["3760.7777","0",0]],"timestamp":"2019-03-06T23:19:18.239Z","checksum":-1587788848}]}` var dataResponse okgroup.WebsocketDataResponse - err := common.JSONDecode([]byte(original), &dataResponse) + err := json.Unmarshal([]byte(original), &dataResponse) if err != nil { t.Error(err) } @@ -888,7 +889,7 @@ func TestOrderBookUpdateChecksumCalculator(t *testing.T) { return } var updateResponse okgroup.WebsocketDataResponse - err = common.JSONDecode([]byte(update), &updateResponse) + err = json.Unmarshal([]byte(update), &updateResponse) if err != nil { t.Error(err) } @@ -908,7 +909,7 @@ func TestOrderBookUpdateChecksumCalculatorWith8DecimalPlaces(t *testing.T) { original := `{"table":"spot/depth","action":"partial","data":[{"instrument_id":"WAVES-BTC","asks":[["0.000714","1.15414979",1],["0.000715","3.3",2],["0.000717","426.71348",2],["0.000719","140.84507042",1],["0.00072","590.77",1],["0.000721","991.77",1],["0.000724","0.3532032",1],["0.000725","58.82698567",1],["0.000726","1033.15469748",2],["0.000729","0.35320321",1],["0.00073","352.77",1],["0.000735","0.38469748",1],["0.000736","625.77",1],["0.00075191","152.44796961",1],["0.00075192","114.3359772",1],["0.00075193","85.7519829",1],["0.00075194","64.31398718",1],["0.00075195","48.23549038",1],["0.00075196","36.17661779",1],["0.00075199","61.04804253",1],["0.0007591","70.71318474",1],["0.0007621","53.03488855",1],["0.00076211","39.77616642",1],["0.00076212","29.83212481",1],["0.0007635","22.37409361",1],["0.00076351","29.36599786",2],["0.00076352","9.43907074",1],["0.00076353","7.07930306",1],["0.00076354","14.15860612",1],["0.00076355","3.53965153",1],["0.00076369","3.53965153",1],["0.0008","34.36841101",1],["0.00082858","1.69936503",1],["0.00083232","2.8",1],["0.00084","15.69220129",1],["0.00085","4.42785042",1],["0.00088","0.1",1],["0.000891","0.1",1],["0.0009","12.41486491",2],["0.00093","5",1],["0.0012","12.31486492",1],["0.00531314","6.91803114",1],["0.00799999","0.02",1],["0.0084","0.05989",1],["0.00931314","5.18852336",1],["0.0799999","0.02",1],["0.499","6.00423396",1],["0.5","0.4995",1],["0.799999","0.02",1],["4.99","2",1],["5","3.98583144",1],["7.99999999","0.02",1],["79.99999999","0.02",1],["799.99999999","0.02986704",1]],"bids":[["0.000709","222.91679881",3],["0.000703","0.47161952",1],["0.000701","140.73015789",2],["0.0007","0.3",1],["0.000699","401",1],["0.000698","232.61801667",2],["0.000689","0.71396896",1],["0.000688","0.69910125",1],["0.000613","227.54771052",1],["0.0005","0.01",1],["0.00026789","3.69905341",1],["0.000238","2.4",1],["0.00022","0.53",1],["0.0000055","374.09871696",1],["0.00000056","222",1],["0.00000055","736.84761363",1],["0.0000002","999",1],["0.00000009","1222.22222417",1],["0.00000008","20868.64520447",1],["0.00000002","110000",1],["0.00000001","10000",1]],"timestamp":"2019-03-12T22:22:42.274Z","checksum":1319037905}]}` update := `{"table":"spot/depth","action":"update","data":[{"instrument_id":"WAVES-BTC","asks":[["0.000715","100.48199596",3],["0.000716","62.21679881",1]],"bids":[["0.000713","38.95772168",1]],"timestamp":"2019-03-12T22:22:42.938Z","checksum":-131160897}]}` var dataResponse okgroup.WebsocketDataResponse - err := common.JSONDecode([]byte(original), &dataResponse) + err := json.Unmarshal([]byte(original), &dataResponse) if err != nil { t.Error(err) } @@ -918,7 +919,7 @@ func TestOrderBookUpdateChecksumCalculatorWith8DecimalPlaces(t *testing.T) { return } var updateResponse okgroup.WebsocketDataResponse - err = common.JSONDecode([]byte(update), &updateResponse) + err = json.Unmarshal([]byte(update), &updateResponse) if err != nil { t.Error(err) } @@ -933,7 +934,7 @@ func TestOrderBookUpdateChecksumCalculatorWith8DecimalPlaces(t *testing.T) { func TestOrderBookPartialChecksumCalculator(t *testing.T) { orderbookPartialJSON := `{"table":"spot/depth","action":"partial","data":[{"instrument_id":"EOS-USDT","asks":[["3.5196","0.1077",1],["3.5198","21.71",1],["3.5199","51.1805",1],["3.5208","75.09",1],["3.521","196.3333",1],["3.5213","0.1",1],["3.5218","39.276",2],["3.5219","395.6334",1],["3.522","27.956",1],["3.5222","404.9595",1],["3.5225","300",1],["3.5227","143.5442",2],["3.523","42.4746",1],["3.5231","852.64",2],["3.5235","34.9602",1],["3.5237","442.0918",2],["3.5238","352.8404",2],["3.5239","341.6759",2],["3.524","84.9493",1],["3.5241","148.4882",1],["3.5242","261.64",1],["3.5243","142.045",1],["3.5246","10",1],["3.5247","284.0788",1],["3.5248","720",1],["3.5249","89.2518",2],["3.5251","1201.8965",2],["3.5254","426.2938",1],["3.5255","213.0863",1],["3.5257","568.1576",1],["3.5258","0.3",1],["3.5259","34.4602",1],["3.526","0.1",1],["3.5263","850.771",1],["3.5265","5.9",1],["3.5268","10.5064",2],["3.5272","1136.8965",1],["3.5274","255.1481",1],["3.5276","29.5374",1],["3.5278","50",1],["3.5282","284.1797",1],["3.5283","1136.8965",1],["3.5284","0.4275",1],["3.5285","100",1],["3.5292","90.9",1],["3.5298","0.2",1],["3.5303","568.1576",1],["3.5305","279.9999",1],["3.532","0.409",1],["3.5321","568.1576",1],["3.5326","6016.8756",1],["3.5328","4.9849",1],["3.533","92.88",2],["3.5343","1200.2383",2],["3.5344","100",1],["3.535","359.7047",1],["3.5354","100",1],["3.5355","100",1],["3.5356","10",1],["3.5358","200",2],["3.5362","435.139",1],["3.5365","2152",1],["3.5366","284.1756",1],["3.5367","568.4644",1],["3.5369","33.9878",1],["3.537","337.1191",2],["3.5373","0.4045",1],["3.5383","1136.7188",1],["3.5386","12.1614",1],["3.5387","90.89",1],["3.54","4.54",1],["3.5423","90.8",1],["3.5436","0.1",1],["3.5454","853.4156",1],["3.5468","142.0656",1],["3.5491","0.0008",1],["3.55","14478.8206",6],["3.5537","21521",1],["3.5555","11.53",1],["3.5573","50.6001",1],["3.5599","4591.4221",1],["3.56","1227.0002",4],["3.5603","2670",1],["3.5608","58.6638",1],["3.5613","0.1",1],["3.5621","45.9473",1],["3.57","2141.7274",3],["3.5712","2956.9816",1],["3.5717","27.9978",1],["3.5718","0.9285",1],["3.5739","299.73",1],["3.5761","864",1],["3.579","22.5225",1],["3.5791","38.26",2],["3.58","7618.4634",5],["3.5801","457.2184",1],["3.582","24.5",1],["3.5822","1572.6425",1],["3.5845","14.1438",1],["3.585","527.169",1],["3.5865","20",1],["3.5867","4490",1],["3.5876","39.0493",1],["3.5879","392.9083",1],["3.5888","436.42",2],["3.5896","50",1],["3.59","2608.9128",8],["3.5913","19.5246",1],["3.5938","7082",1],["3.597","0.1",1],["3.5979","399",1],["3.5995","315.1509",1],["3.5999","2566.2648",1],["3.6","18511.2292",35],["3.603","22.3379",2],["3.605","499.5",1],["3.6055","100",1],["3.6058","499.5",1],["3.608","1021.1485",1],["3.61","11755.4596",13],["3.611","42.8571",1],["3.6131","6690",1],["3.6157","19.5247",1],["3.618","2500",1],["3.6197","525.7146",1],["3.6198","0.4455",1],["3.62","6440.6295",8],["3.6219","0.4175",1],["3.6237","168",1],["3.6265","0.1001",1],["3.628","64.9345",1],["3.63","4435.4985",6],["3.6308","1.7815",1],["3.6331","0.1",1],["3.6338","355.527",2],["3.6358","50",1],["3.6363","2074.7096",1],["3.6376","4000",1],["3.6396","11090",1],["3.6399","0.4055",1],["3.64","4161.9805",4],["3.6437","117.6524",1],["3.648","190",1],["3.6488","200",1],["3.65","11740.5045",25],["3.6512","0.1",1],["3.6521","728",1],["3.6555","100",1],["3.6598","36.6914",1],["3.66","4331.2148",6],["3.6638","200",1],["3.6673","100",1],["3.6679","38",1],["3.6688","2",1],["3.6695","0.1",1],["3.67","7984.698",6],["3.672","300",1],["3.6777","257.8247",1],["3.6789","393.4217",2],["3.68","9202.3222",11],["3.6818","500",1],["3.6823","299.7",1],["3.6839","422.3748",1],["3.685","100",1],["3.6878","0.1",1],["3.6888","72.0958",2],["3.6889","2876",1],["3.689","28",1],["3.6891","28",1],["3.6892","28",1],["3.6895","28",1],["3.6898","28",1],["3.69","643.96",7],["3.6908","118",2],["3.691","28",1],["3.6916","28",1],["3.6918","28",1],["3.6926","28",1],["3.6928","28",1],["3.6932","28",1],["3.6933","200",1],["3.6935","28",1],["3.6936","28",1],["3.6938","28",1],["3.694","28",1],["3.698","1498.5",1],["3.6988","2014.2004",2],["3.7","21904.2689",22],["3.7029","71.95",1],["3.704","3690.1362",1],["3.7055","100",1],["3.7063","0.1",1],["3.71","4421.3468",4],["3.719","17.3491",1],["3.72","1304.5995",3],["3.7211","10",1],["3.7248","0.1",1],["3.725","1900",1],["3.73","31.1785",2],["3.7375","38",1]],"bids":[["3.5182","151.5343",6],["3.5181","0.3691",1],["3.518","271.3967",2],["3.5179","257.8352",1],["3.5178","12.3811",1],["3.5173","34.1921",2],["3.5171","1013.8256",2],["3.517","272.1119",2],["3.5168","395.3376",1],["3.5166","317.1756",2],["3.5165","348.302",3],["3.5164","142.0414",1],["3.5163","96.8933",2],["3.516","600.1034",3],["3.5159","27.481",1],["3.5158","27.33",1],["3.5157","583.1898",2],["3.5156","24.6819",2],["3.5154","25",1],["3.5153","0.429",1],["3.5152","453.9204",3],["3.5151","2131.592",4],["3.515","335",3],["3.5149","37.1586",1],["3.5147","41.6759",1],["3.5146","54.569",1],["3.5145","70.3515",1],["3.5143","68.206",3],["3.5142","359.4538",2],["3.5139","45.4123",2],["3.5137","71.673",2],["3.5136","25",1],["3.5135","300",1],["3.5134","442.57",2],["3.5132","83.3518",1],["3.513","1245.2529",3],["3.5127","20",1],["3.512","284.1353",1],["3.5119","1136.8319",1],["3.5113","56.9351",1],["3.5111","588.1898",2],["3.5109","255.0946",1],["3.5105","48.65",1],["3.5103","50.2",1],["3.5098","720",1],["3.5096","148.95",1],["3.5094","570.5758",2],["3.509","2.386",1],["3.5089","0.4065",1],["3.5087","282.3859",2],["3.5086","145.036",2],["3.5084","2.386",1],["3.5082","90.98",1],["3.5081","2.386",1],["3.5079","2.386",1],["3.5078","857.6229",2],["3.5075","2.386",1],["3.5074","284.1877",1],["3.5073","100",1],["3.5071","100",1],["3.507","768.4159",3],["3.5069","313.0863",2],["3.5068","426.2938",1],["3.5066","568.3594",1],["3.5063","1136.6865",1],["3.5059","0.3",1],["3.5054","9.9999",1],["3.5053","0.2",1],["3.5051","392.428",1],["3.505","13.79",1],["3.5048","99.5497",2],["3.5047","78.5331",2],["3.5046","2153",1],["3.5041","5983.999",1],["3.5037","668.5682",1],["3.5036","160.5948",1],["3.5024","534.8075",1],["3.5014","28.5604",1],["3.5011","91",1],["3.5","1058.8771",2],["3.4997","50.2",1],["3.4985","3430.0414",1],["3.4949","232.0591",1],["3.4942","21521",1],["3.493","2",1],["3.4928","2",1],["3.4925","0.44",1],["3.4917","142.0656",1],["3.49","2051.8826",4],["3.488","280.7459",1],["3.4852","643.4038",1],["3.4851","86.0807",1],["3.485","213.2436",1],["3.484","0.1",1],["3.4811","144.3399",1],["3.4808","89",1],["3.4803","12.1999",1],["3.4801","2390",1],["3.48","930.8453",9],["3.4791","310",1],["3.4768","206",1],["3.4767","0.9415",1],["3.4754","1.4387",1],["3.4728","20",1],["3.4701","1219.2873",1],["3.47","1904.3139",7],["3.468","0.4035",1],["3.4667","0.1",1],["3.4666","3020.0101",1],["3.465","10",1],["3.464","0.4485",1],["3.462","2119.6556",1],["3.46","1305.6113",8],["3.4589","8.0228",1],["3.457","100",1],["3.456","70.3859",2],["3.4538","20",1],["3.4536","4323.9486",2],["3.4531","827.0427",1],["3.4528","0.439",1],["3.4522","8.0381",1],["3.4513","441.1873",1],["3.4512","50.707",1],["3.451","87.0902",1],["3.4509","200",1],["3.4506","100",1],["3.4505","86.4045",2],["3.45","12409.4595",28],["3.4494","0.5365",2],["3.449","10761",1],["3.4482","8.0476",1],["3.4469","0.449",1],["3.445","2000",1],["3.4427","14",1],["3.4421","100",1],["3.4416","8.0631",1],["3.4404","1",1],["3.44","4580.733",11],["3.4388","1868.2085",1],["3.438","937.7246",2],["3.4367","1500",1],["3.4366","62",1],["3.436","29.8743",1],["3.4356","25.4801",1],["3.4349","4.3086",1],["3.4343","43.2402",1],["3.433","2.0688",1],["3.4322","2.7335",2],["3.432","93.3233",1],["3.4302","328.8301",2],["3.43","4440.8158",11],["3.4288","754.574",2],["3.4283","125.7043",2],["3.428","744.3154",2],["3.4273","5460",1],["3.4258","50",1],["3.4255","109.005",1],["3.4248","100",1],["3.4241","129.2048",2],["3.4233","5.3598",1],["3.4228","4498.866",1],["3.4222","3.5435",1],["3.4217","404.3252",2],["3.4211","1000",1],["3.4208","31",1],["3.42","1834.024",9],["3.4175","300",1],["3.4162","400",1],["3.4152","0.1",1],["3.4151","4.3336",1],["3.415","1.5974",1],["3.414","1146",1],["3.4134","306.4246",1],["3.4129","7.5556",1],["3.4111","198.5188",1],["3.4109","500",1],["3.4106","4305",1],["3.41","2150.7635",13],["3.4085","4.342",1],["3.4054","5.6985",1],["3.4019","5.438",1],["3.4015","1010.846",1],["3.4009","8610",1],["3.4005","1.9122",1],["3.4004","1",1],["3.4","27081.1806",67],["3.3955","3.2682",1],["3.3953","5.4486",1],["3.3937","1591.3805",1],["3.39","3221.4155",8],["3.3899","3.2736",1],["3.3888","1500",2],["3.3887","5.4592",1],["3.385","117.0969",2],["3.3821","5.4699",1],["3.382","100.0529",1],["3.3818","172.0164",1],["3.3815","165.6288",1],["3.381","887.3115",1],["3.3808","100",1]],"timestamp":"2019-03-04T00:15:04.155Z","checksum":-2036653089}]}` var dataResponse okgroup.WebsocketDataResponse - err := common.JSONDecode([]byte(orderbookPartialJSON), &dataResponse) + err := json.Unmarshal([]byte(orderbookPartialJSON), &dataResponse) if err != nil { t.Error(err) } diff --git a/exchanges/okex/okex_test.go b/exchanges/okex/okex_test.go index f033e4c57eb..fa9d6e2a257 100644 --- a/exchanges/okex/okex_test.go +++ b/exchanges/okex/okex_test.go @@ -1,6 +1,7 @@ package okex import ( + "encoding/json" "fmt" "net/http" "strconv" @@ -1614,7 +1615,7 @@ func TestOrderBookUpdateChecksumCalculator(t *testing.T) { original := `{"table":"spot/depth","action":"partial","data":[{"instrument_id":"BTC-USDT","asks":[["3864.6786","0.145",1],["3864.7682","0.005",1],["3864.9851","0.57",1],["3864.9852","0.30137754",1],["3864.9986","2.81818419",1],["3864.9995","0.002",1],["3865","0.0597",1],["3865.0309","0.4",1],["3865.1995","0.004",1],["3865.3995","0.004",1],["3865.5995","0.004",1],["3865.7995","0.004",1],["3865.9995","0.004",1],["3866.0961","0.25865886",1],["3866.1995","0.004",1],["3866.3995","0.004",1],["3866.4004","0.3243",2],["3866.5995","0.004",1],["3866.7633","0.44247086",1],["3866.7995","0.004",1],["3866.9197","0.511",1],["3867.256","0.51716256",1],["3867.3951","0.02588112",1],["3867.4014","0.025",1],["3867.4566","0.02499999",1],["3867.4675","4.01155057",5],["3867.5515","1.1",1],["3867.6113","0.009",1],["3867.7349","0.026",1],["3867.7781","0.03738652",1],["3867.9163","0.0521",1],["3868.0381","0.34354941",1],["3868.0436","0.051",1],["3868.0657","0.90552172",3],["3868.1819","0.03863346",1],["3868.2013","0.194",1],["3868.346","0.051",1],["3868.3863","0.01155",1],["3868.7716","0.009",1],["3868.947","0.025",1],["3868.98","0.001",1],["3869.0764","1.03487931",1],["3869.2773","0.07724578",1],["3869.4039","0.025",1],["3869.4068","1.03",1],["3869.7068","2.06976398",1],["3870","0.5",1],["3870.0465","0.01",1],["3870.7042","0.02099651",1],["3870.9451","2.07047375",1],["3871.5254","1.2",1],["3871.5596","0.001",1],["3871.6605","0.01035032",1],["3871.7179","2.07047375",1],["3871.8816","0.51751625",1],["3872.1","0.75",1],["3872.2464","0.0646",1],["3872.3747","0.283",1],["3872.4039","0.2",1],["3872.7655","0.23179307",1],["3872.8005","2.06976398",1],["3873.1509","2",1],["3873.3215","0.26",1],["3874.1392","0.001",1],["3874.1487","3.88224364",4],["3874.1685","1.8",1],["3874.5571","0.08974762",1],["3874.734","2.06976398",1],["3874.99","0.3",1],["3875","1.001",2],["3875.0041","1.03505051",1],["3875.45","0.3",1],["3875.4766","0.15",1],["3875.7057","0.51751625",1],["3876","0.001",1],["3876.68","0.3",1],["3876.7188","0.001",1],["3877","0.75",1],["3877.31","0.035",1],["3877.38","0.3",1],["3877.7","0.3",1],["3877.88","0.3",1],["3878.0364","0.34770122",1],["3878.4525","0.48579748",1],["3878.4955","0.02812511",1],["3878.8855","0.00258579",1],["3878.9605","0.895",1],["3879","0.001",1],["3879.2984","0.002",2],["3879.432","0.001",1],["3879.6313","6",1],["3879.9999","0.002",2],["3880","1.25132834",5],["3880.2526","0.04075162",1],["3880.7145","0.0647",1],["3881.2469","1.883",1],["3881.878","0.002",2],["3884.4576","0.002",2],["3885","0.002",2],["3885.2233","0.28304103",1],["3885.7416","18",1],["3886","0.001",1],["3886.1554","5.4",1],["3887","0.001",1],["3887.0372","0.002",2],["3887.2559","0.05214011",1],["3887.9238","0.0019",1],["3888","0.15810538",4],["3889","0.001",1],["3889.5175","0.50510653",1],["3889.6168","0.002",2],["3889.9999","0.001",1],["3890","2.34968109",4],["3890.5222","0.00257806",1],["3891.2659","5",1],["3891.9999","0.00893897",1],["3892.1964","0.002",2],["3892.4358","0.0176",1],["3893.1388","1.4279",1],["3894","0.0026321",1],["3894.776","0.001",1],["3895","1.501",2],["3895.379","0.25881288",1],["3897","0.05",1],["3897.3556","0.001",1],["3897.8432","0.73708079",1],["3898","3.31353018",7],["3898.4462","4.757",1],["3898.6","0.47159638",1],["3898.8769","0.0129",1],["3899","6",2],["3899.6516","0.025",1],["3899.9352","0.001",1],["3899.9999","0.013",2],["3900","22.37447743",24],["3900.9999","0.07763916",1],["3901","0.10192487",1],["3902.1937","0.00257034",1],["3902.3991","1.5532141",1],["3902.5148","0.001",1],["3904","1.49331984",1],["3904.9999","0.95905447",1],["3905","0.501",2],["3905.0944","0.001",1],["3905.61","0.099",1],["3905.6801","0.54343686",1],["3906.2901","0.0258",1],["3907.674","0.001",1],["3907.85","1.35778084",1],["3908","0.03846153",1],["3908.23","1.95189531",1],["3908.906","0.03148978",1],["3909","0.001",1],["3909.9999","0.01398721",2],["3910","0.016",2],["3910.2536","0.001",1],["3912.5406","0.88270517",1],["3912.8332","0.001",1],["3913","1.2640608",1],["3913.87","1.69114184",1],["3913.9003","0.00256266",1],["3914","1.21766411",1],["3915","0.001",1],["3915.4128","0.001",1],["3915.7425","6.848",1],["3916","0.0050949",1],["3917.36","1.28658296",1],["3917.9924","0.001",1],["3919","0.001",1],["3919.9999","0.001",1],["3920","1.21171832",3],["3920.0002","0.20217038",1],["3920.572","0.001",1],["3921","0.128",1],["3923.0756","0.00148064",1],["3923.1516","0.001",1],["3923.86","1.38831714",1],["3925","0.01867801",2],["3925.642","0.00255499",1],["3925.7312","0.001",1],["3926","0.04290757",1],["3927","0.023",1],["3927.3175","0.01212865",1],["3927.65","1.51375612",1],["3928","0.5",1],["3928.3108","0.001",1],["3929","0.001",1],["3929.9999","0.01519338",2],["3930","0.0174985",3],["3930.21","1.49335799",1],["3930.8904","0.001",1],["3932.2999","0.01953",1],["3932.8962","7.96",1],["3933.0387","11.808",1],["3933.47","0.001",1],["3934","1.40839932",1],["3935","0.001",1],["3936.8","0.62879518",1],["3937.23","1.56977841",1],["3937.4189","0.00254735",1]],"bids":[["3864.5217","0.00540709",1],["3864.5216","0.14068758",2],["3864.2275","0.01033576",1],["3864.0989","0.00825047",1],["3864.0273","0.38",1],["3864.0272","0.4",1],["3863.9957","0.01083539",1],["3863.9184","0.01653723",1],["3863.8282","0.25588165",1],["3863.8153","0.154",1],["3863.7791","1.14122492",1],["3863.6866","0.01733662",1],["3863.6093","0.02645958",1],["3863.3775","0.02773862",1],["3863.0297","0.513",1],["3863.0286","1.1028564",2],["3862.8489","0.01",1],["3862.5972","0.01890179",1],["3862.3431","0.01152944",1],["3862.313","0.009",1],["3862.2445","0.90551002",3],["3862.0734","0.014",1],["3862.0539","0.64976067",1],["3861.8586","0.025",1],["3861.7888","0.025",1],["3861.7673","0.008",1],["3861.5785","0.01",1],["3861.3895","0.005",1],["3861.3338","0.25875855",1],["3861.161","0.01",1],["3861.1111","0.03863352",1],["3861.0732","0.51703882",1],["3860.9116","0.17754895",1],["3860.75","0.19",1],["3860.6554","0.015",1],["3860.6172","0.005",1],["3860.6088","0.008",1],["3860.4724","0.12940042",1],["3860.4424","0.25880084",1],["3860.42","0.01",1],["3860.3725","0.51760102",1],["3859.8449","0.005",1],["3859.8285","0.03738652",1],["3859.7638","0.07726703",1],["3859.4502","0.008",1],["3859.3772","0.05173471",1],["3859.3409","0.194",1],["3859","5",1],["3858.827","0.0521",1],["3858.8208","0.001",1],["3858.679","0.26",1],["3858.4814","0.07477305",1],["3858.1669","1.03503422",1],["3857.6005","0.006",1],["3857.4005","0.004",1],["3857.2005","0.004",1],["3857.1871","1.218",1],["3857.0005","0.004",1],["3856.8135","0.0646",1],["3856.8005","0.004",1],["3856.2412","0.001",1],["3856.2349","1.03503422",1],["3856.0197","0.01037339",1],["3855.8781","0.23178117",1],["3855.8005","0.004",1],["3855.7165","0.00259355",1],["3855.4858","0.25875855",1],["3854.4584","0.01",1],["3853.6616","0.001",1],["3853.1373","0.92",1],["3852.5072","0.48599702",1],["3851.3926","0.13008333",1],["3851.082","0.001",1],["3850.9317","2",1],["3850.6359","0.34770165",1],["3850.2058","0.51751624",1],["3850.0823","0.15",1],["3850.0042","0.5175171",1],["3850","0.001",1],["3849.6325","1.8",1],["3849.41","0.3",1],["3848.9686","1.85",1],["3848.7426","0.18511466",1],["3848.52","0.3",1],["3848.5024","0.001",1],["3848.42","0.3",1],["3848.1618","2.204",1],["3847.77","0.3",1],["3847.48","0.3",1],["3847.3581","2.05",1],["3846.8259","0.0646",1],["3846.59","0.3",1],["3846.49","0.3",1],["3845.9228","0.001",1],["3844.184","0.00260133",1],["3844.0092","6.3",1],["3843.3432","0.001",1],["3841","0.06300963",1],["3840.7636","0.001",1],["3840","0.201",3],["3839.7681","18",1],["3839.5328","0.05214011",1],["3838.184","0.001",1],["3837.2344","0.27589557",1],["3836.6479","5.2",1],["3836","2.37196773",3],["3835.6044","0.001",1],["3833.6053","0.25873556",1],["3833.0248","0.001",1],["3833","0.8726502",1],["3832.6859","0.00260913",1],["3832","0.007",1],["3831.637","6",1],["3831.0602","0.001",1],["3830.4452","0.001",1],["3830","0.20375718",4],["3829.7125","0.07833486",1],["3829.6283","0.3519681",1],["3829","0.0039261",1],["3827.8656","0.001",1],["3826.0001","0.53251232",1],["3826","0.0509",1],["3825.7834","0.00698562",1],["3825.286","0.001",1],["3823.0001","0.03010127",1],["3822.8014","0.00261588",1],["3822.7064","0.001",1],["3822.2","1",1],["3822.1121","0.35994101",1],["3821.2222","0.00261696",1],["3821","0.001",1],["3820.1268","0.001",1],["3820","1.12992803",4],["3819","0.01331195",2],["3817.5472","0.001",1],["3816","1.13807184",2],["3815.8343","0.32463428",1],["3815.7834","0.00525295",1],["3815","28.99386799",4],["3814.9676","0.001",1],["3813","0.91303023",4],["3812.388","0.002",2],["3811.2257","0.07",1],["3810","0.32573997",2],["3809.8084","0.001",1],["3809.7928","0.00262481",1],["3807.2288","0.001",1],["3806.8421","0.07003461",1],["3806","0.19",1],["3805.8041","0.05678805",1],["3805","1.01",2],["3804.6492","0.001",1],["3804.3551","0.1",1],["3803","0.005",1],["3802.22","2.05042631",1],["3802.0696","0.001",1],["3802","1.63290092",1],["3801.2257","0.07",1],["3801","57.4",3],["3800.9853","0.02492278",1],["3800.8421","0.06503533",1],["3800.7844","0.02812628",1],["3800.0001","0.00409473",1],["3800","17.91401074",15],["3799.49","0.001",1],["3799","0.1",1],["3796.9104","0.001",1],["3796","9.00128053",2],["3795.5441","0.0028",1],["3794.3308","0.001",1],["3791","55",1],["3790.7777","0.07",1],["3790","12.03238184",7],["3789","1",1],["3788","0.21110454",2],["3787.2959","9",1],["3786.592","0.001",1],["3786","9.01916822",2],["3785","12.87914268",5],["3784.0124","0.001",1],["3781.4328","0.002",2],["3781","56.3",2],["3780.7777","0.07",1],["3780","23.41537654",10],["3778.8532","0.002",2],["3776","9",1],["3774","0.003",1],["3772.2481","0.06901672",1],["3771","55.1",2],["3770.7777","0.07",1],["3770","7.30268416",5],["3769","0.25",1],["3768","1.3725",3],["3766.66","0.02",1],["3766","7.64837924",2],["3765.58","1.22775492",1],["3762.58","1.22873383",1],["3761","51.68262164",1],["3760.8031","0.0399",1],["3760.7777","0.07",1]],"timestamp":"2019-03-06T23:19:17.705Z","checksum":-1785549915}]}` update := `{"table":"spot/depth","action":"update","data":[{"instrument_id":"BTC-USDT","asks":[["3864.6786","0",0],["3864.9852","0",0],["3865.9994","0.48402971",1],["3866.4004","0.001",1],["3866.7995","0.3273",2],["3867.4566","0",0],["3867.7031","0.025",1],["3868.0436","0",0],["3868.346","0",0],["3868.3695","0.051",1],["3870.9243","0.642",1],["3874.9942","0.51751796",1],["3875.7057","0",0],["3939","0.001",1]],"bids":[["3864.55","0.0565449",1],["3863.8282","0",0],["3863.8153","0",0],["3863.7898","0.01320077",1],["3863.4807","0.02112123",1],["3863.3002","0.04233533",1],["3863.1717","0.03379397",1],["3863.0685","0.04438179",1],["3863.0286","0.7362564",1],["3862.9912","0.06773651",1],["3862.8626","0.05407035",1],["3862.7595","0.07101087",1],["3862.313","0.3756",2],["3862.1848","0.012",1],["3862.0734","0",0],["3861.8391","0.025",1],["3861.7888","0",0],["3856.6716","0.38893641",1],["3768","0",0],["3766.66","0",0],["3766","0",0],["3765.58","0",0],["3762.58","0",0],["3761","0",0],["3760.8031","0",0],["3760.7777","0",0]],"timestamp":"2019-03-06T23:19:18.239Z","checksum":-1587788848}]}` var dataResponse okgroup.WebsocketDataResponse - err := common.JSONDecode([]byte(original), &dataResponse) + err := json.Unmarshal([]byte(original), &dataResponse) if err != nil { t.Error(err) } @@ -1624,7 +1625,7 @@ func TestOrderBookUpdateChecksumCalculator(t *testing.T) { return } var updateResponse okgroup.WebsocketDataResponse - err = common.JSONDecode([]byte(update), &updateResponse) + err = json.Unmarshal([]byte(update), &updateResponse) if err != nil { t.Error(err) } @@ -1641,7 +1642,7 @@ func TestOrderBookUpdateChecksumCalculatorWith8DecimalPlaces(t *testing.T) { original := `{"table":"spot/depth","action":"partial","data":[{"instrument_id":"WAVES-BTC","asks":[["0.000714","1.15414979",1],["0.000715","3.3",2],["0.000717","426.71348",2],["0.000719","140.84507042",1],["0.00072","590.77",1],["0.000721","991.77",1],["0.000724","0.3532032",1],["0.000725","58.82698567",1],["0.000726","1033.15469748",2],["0.000729","0.35320321",1],["0.00073","352.77",1],["0.000735","0.38469748",1],["0.000736","625.77",1],["0.00075191","152.44796961",1],["0.00075192","114.3359772",1],["0.00075193","85.7519829",1],["0.00075194","64.31398718",1],["0.00075195","48.23549038",1],["0.00075196","36.17661779",1],["0.00075199","61.04804253",1],["0.0007591","70.71318474",1],["0.0007621","53.03488855",1],["0.00076211","39.77616642",1],["0.00076212","29.83212481",1],["0.0007635","22.37409361",1],["0.00076351","29.36599786",2],["0.00076352","9.43907074",1],["0.00076353","7.07930306",1],["0.00076354","14.15860612",1],["0.00076355","3.53965153",1],["0.00076369","3.53965153",1],["0.0008","34.36841101",1],["0.00082858","1.69936503",1],["0.00083232","2.8",1],["0.00084","15.69220129",1],["0.00085","4.42785042",1],["0.00088","0.1",1],["0.000891","0.1",1],["0.0009","12.41486491",2],["0.00093","5",1],["0.0012","12.31486492",1],["0.00531314","6.91803114",1],["0.00799999","0.02",1],["0.0084","0.05989",1],["0.00931314","5.18852336",1],["0.0799999","0.02",1],["0.499","6.00423396",1],["0.5","0.4995",1],["0.799999","0.02",1],["4.99","2",1],["5","3.98583144",1],["7.99999999","0.02",1],["79.99999999","0.02",1],["799.99999999","0.02986704",1]],"bids":[["0.000709","222.91679881",3],["0.000703","0.47161952",1],["0.000701","140.73015789",2],["0.0007","0.3",1],["0.000699","401",1],["0.000698","232.61801667",2],["0.000689","0.71396896",1],["0.000688","0.69910125",1],["0.000613","227.54771052",1],["0.0005","0.01",1],["0.00026789","3.69905341",1],["0.000238","2.4",1],["0.00022","0.53",1],["0.0000055","374.09871696",1],["0.00000056","222",1],["0.00000055","736.84761363",1],["0.0000002","999",1],["0.00000009","1222.22222417",1],["0.00000008","20868.64520447",1],["0.00000002","110000",1],["0.00000001","10000",1]],"timestamp":"2019-03-12T22:22:42.274Z","checksum":1319037905}]}` update := `{"table":"spot/depth","action":"update","data":[{"instrument_id":"WAVES-BTC","asks":[["0.000715","100.48199596",3],["0.000716","62.21679881",1]],"bids":[["0.000713","38.95772168",1]],"timestamp":"2019-03-12T22:22:42.938Z","checksum":-131160897}]}` var dataResponse okgroup.WebsocketDataResponse - err := common.JSONDecode([]byte(original), &dataResponse) + err := json.Unmarshal([]byte(original), &dataResponse) if err != nil { t.Error(err) } @@ -1651,7 +1652,7 @@ func TestOrderBookUpdateChecksumCalculatorWith8DecimalPlaces(t *testing.T) { return } var updateResponse okgroup.WebsocketDataResponse - err = common.JSONDecode([]byte(update), &updateResponse) + err = json.Unmarshal([]byte(update), &updateResponse) if err != nil { t.Error(err) } @@ -1666,7 +1667,7 @@ func TestOrderBookUpdateChecksumCalculatorWith8DecimalPlaces(t *testing.T) { func TestOrderBookPartialChecksumCalculator(t *testing.T) { orderbookPartialJSON := `{"table":"spot/depth","action":"partial","data":[{"instrument_id":"EOS-USDT","asks":[["3.5196","0.1077",1],["3.5198","21.71",1],["3.5199","51.1805",1],["3.5208","75.09",1],["3.521","196.3333",1],["3.5213","0.1",1],["3.5218","39.276",2],["3.5219","395.6334",1],["3.522","27.956",1],["3.5222","404.9595",1],["3.5225","300",1],["3.5227","143.5442",2],["3.523","42.4746",1],["3.5231","852.64",2],["3.5235","34.9602",1],["3.5237","442.0918",2],["3.5238","352.8404",2],["3.5239","341.6759",2],["3.524","84.9493",1],["3.5241","148.4882",1],["3.5242","261.64",1],["3.5243","142.045",1],["3.5246","10",1],["3.5247","284.0788",1],["3.5248","720",1],["3.5249","89.2518",2],["3.5251","1201.8965",2],["3.5254","426.2938",1],["3.5255","213.0863",1],["3.5257","568.1576",1],["3.5258","0.3",1],["3.5259","34.4602",1],["3.526","0.1",1],["3.5263","850.771",1],["3.5265","5.9",1],["3.5268","10.5064",2],["3.5272","1136.8965",1],["3.5274","255.1481",1],["3.5276","29.5374",1],["3.5278","50",1],["3.5282","284.1797",1],["3.5283","1136.8965",1],["3.5284","0.4275",1],["3.5285","100",1],["3.5292","90.9",1],["3.5298","0.2",1],["3.5303","568.1576",1],["3.5305","279.9999",1],["3.532","0.409",1],["3.5321","568.1576",1],["3.5326","6016.8756",1],["3.5328","4.9849",1],["3.533","92.88",2],["3.5343","1200.2383",2],["3.5344","100",1],["3.535","359.7047",1],["3.5354","100",1],["3.5355","100",1],["3.5356","10",1],["3.5358","200",2],["3.5362","435.139",1],["3.5365","2152",1],["3.5366","284.1756",1],["3.5367","568.4644",1],["3.5369","33.9878",1],["3.537","337.1191",2],["3.5373","0.4045",1],["3.5383","1136.7188",1],["3.5386","12.1614",1],["3.5387","90.89",1],["3.54","4.54",1],["3.5423","90.8",1],["3.5436","0.1",1],["3.5454","853.4156",1],["3.5468","142.0656",1],["3.5491","0.0008",1],["3.55","14478.8206",6],["3.5537","21521",1],["3.5555","11.53",1],["3.5573","50.6001",1],["3.5599","4591.4221",1],["3.56","1227.0002",4],["3.5603","2670",1],["3.5608","58.6638",1],["3.5613","0.1",1],["3.5621","45.9473",1],["3.57","2141.7274",3],["3.5712","2956.9816",1],["3.5717","27.9978",1],["3.5718","0.9285",1],["3.5739","299.73",1],["3.5761","864",1],["3.579","22.5225",1],["3.5791","38.26",2],["3.58","7618.4634",5],["3.5801","457.2184",1],["3.582","24.5",1],["3.5822","1572.6425",1],["3.5845","14.1438",1],["3.585","527.169",1],["3.5865","20",1],["3.5867","4490",1],["3.5876","39.0493",1],["3.5879","392.9083",1],["3.5888","436.42",2],["3.5896","50",1],["3.59","2608.9128",8],["3.5913","19.5246",1],["3.5938","7082",1],["3.597","0.1",1],["3.5979","399",1],["3.5995","315.1509",1],["3.5999","2566.2648",1],["3.6","18511.2292",35],["3.603","22.3379",2],["3.605","499.5",1],["3.6055","100",1],["3.6058","499.5",1],["3.608","1021.1485",1],["3.61","11755.4596",13],["3.611","42.8571",1],["3.6131","6690",1],["3.6157","19.5247",1],["3.618","2500",1],["3.6197","525.7146",1],["3.6198","0.4455",1],["3.62","6440.6295",8],["3.6219","0.4175",1],["3.6237","168",1],["3.6265","0.1001",1],["3.628","64.9345",1],["3.63","4435.4985",6],["3.6308","1.7815",1],["3.6331","0.1",1],["3.6338","355.527",2],["3.6358","50",1],["3.6363","2074.7096",1],["3.6376","4000",1],["3.6396","11090",1],["3.6399","0.4055",1],["3.64","4161.9805",4],["3.6437","117.6524",1],["3.648","190",1],["3.6488","200",1],["3.65","11740.5045",25],["3.6512","0.1",1],["3.6521","728",1],["3.6555","100",1],["3.6598","36.6914",1],["3.66","4331.2148",6],["3.6638","200",1],["3.6673","100",1],["3.6679","38",1],["3.6688","2",1],["3.6695","0.1",1],["3.67","7984.698",6],["3.672","300",1],["3.6777","257.8247",1],["3.6789","393.4217",2],["3.68","9202.3222",11],["3.6818","500",1],["3.6823","299.7",1],["3.6839","422.3748",1],["3.685","100",1],["3.6878","0.1",1],["3.6888","72.0958",2],["3.6889","2876",1],["3.689","28",1],["3.6891","28",1],["3.6892","28",1],["3.6895","28",1],["3.6898","28",1],["3.69","643.96",7],["3.6908","118",2],["3.691","28",1],["3.6916","28",1],["3.6918","28",1],["3.6926","28",1],["3.6928","28",1],["3.6932","28",1],["3.6933","200",1],["3.6935","28",1],["3.6936","28",1],["3.6938","28",1],["3.694","28",1],["3.698","1498.5",1],["3.6988","2014.2004",2],["3.7","21904.2689",22],["3.7029","71.95",1],["3.704","3690.1362",1],["3.7055","100",1],["3.7063","0.1",1],["3.71","4421.3468",4],["3.719","17.3491",1],["3.72","1304.5995",3],["3.7211","10",1],["3.7248","0.1",1],["3.725","1900",1],["3.73","31.1785",2],["3.7375","38",1]],"bids":[["3.5182","151.5343",6],["3.5181","0.3691",1],["3.518","271.3967",2],["3.5179","257.8352",1],["3.5178","12.3811",1],["3.5173","34.1921",2],["3.5171","1013.8256",2],["3.517","272.1119",2],["3.5168","395.3376",1],["3.5166","317.1756",2],["3.5165","348.302",3],["3.5164","142.0414",1],["3.5163","96.8933",2],["3.516","600.1034",3],["3.5159","27.481",1],["3.5158","27.33",1],["3.5157","583.1898",2],["3.5156","24.6819",2],["3.5154","25",1],["3.5153","0.429",1],["3.5152","453.9204",3],["3.5151","2131.592",4],["3.515","335",3],["3.5149","37.1586",1],["3.5147","41.6759",1],["3.5146","54.569",1],["3.5145","70.3515",1],["3.5143","68.206",3],["3.5142","359.4538",2],["3.5139","45.4123",2],["3.5137","71.673",2],["3.5136","25",1],["3.5135","300",1],["3.5134","442.57",2],["3.5132","83.3518",1],["3.513","1245.2529",3],["3.5127","20",1],["3.512","284.1353",1],["3.5119","1136.8319",1],["3.5113","56.9351",1],["3.5111","588.1898",2],["3.5109","255.0946",1],["3.5105","48.65",1],["3.5103","50.2",1],["3.5098","720",1],["3.5096","148.95",1],["3.5094","570.5758",2],["3.509","2.386",1],["3.5089","0.4065",1],["3.5087","282.3859",2],["3.5086","145.036",2],["3.5084","2.386",1],["3.5082","90.98",1],["3.5081","2.386",1],["3.5079","2.386",1],["3.5078","857.6229",2],["3.5075","2.386",1],["3.5074","284.1877",1],["3.5073","100",1],["3.5071","100",1],["3.507","768.4159",3],["3.5069","313.0863",2],["3.5068","426.2938",1],["3.5066","568.3594",1],["3.5063","1136.6865",1],["3.5059","0.3",1],["3.5054","9.9999",1],["3.5053","0.2",1],["3.5051","392.428",1],["3.505","13.79",1],["3.5048","99.5497",2],["3.5047","78.5331",2],["3.5046","2153",1],["3.5041","5983.999",1],["3.5037","668.5682",1],["3.5036","160.5948",1],["3.5024","534.8075",1],["3.5014","28.5604",1],["3.5011","91",1],["3.5","1058.8771",2],["3.4997","50.2",1],["3.4985","3430.0414",1],["3.4949","232.0591",1],["3.4942","21521",1],["3.493","2",1],["3.4928","2",1],["3.4925","0.44",1],["3.4917","142.0656",1],["3.49","2051.8826",4],["3.488","280.7459",1],["3.4852","643.4038",1],["3.4851","86.0807",1],["3.485","213.2436",1],["3.484","0.1",1],["3.4811","144.3399",1],["3.4808","89",1],["3.4803","12.1999",1],["3.4801","2390",1],["3.48","930.8453",9],["3.4791","310",1],["3.4768","206",1],["3.4767","0.9415",1],["3.4754","1.4387",1],["3.4728","20",1],["3.4701","1219.2873",1],["3.47","1904.3139",7],["3.468","0.4035",1],["3.4667","0.1",1],["3.4666","3020.0101",1],["3.465","10",1],["3.464","0.4485",1],["3.462","2119.6556",1],["3.46","1305.6113",8],["3.4589","8.0228",1],["3.457","100",1],["3.456","70.3859",2],["3.4538","20",1],["3.4536","4323.9486",2],["3.4531","827.0427",1],["3.4528","0.439",1],["3.4522","8.0381",1],["3.4513","441.1873",1],["3.4512","50.707",1],["3.451","87.0902",1],["3.4509","200",1],["3.4506","100",1],["3.4505","86.4045",2],["3.45","12409.4595",28],["3.4494","0.5365",2],["3.449","10761",1],["3.4482","8.0476",1],["3.4469","0.449",1],["3.445","2000",1],["3.4427","14",1],["3.4421","100",1],["3.4416","8.0631",1],["3.4404","1",1],["3.44","4580.733",11],["3.4388","1868.2085",1],["3.438","937.7246",2],["3.4367","1500",1],["3.4366","62",1],["3.436","29.8743",1],["3.4356","25.4801",1],["3.4349","4.3086",1],["3.4343","43.2402",1],["3.433","2.0688",1],["3.4322","2.7335",2],["3.432","93.3233",1],["3.4302","328.8301",2],["3.43","4440.8158",11],["3.4288","754.574",2],["3.4283","125.7043",2],["3.428","744.3154",2],["3.4273","5460",1],["3.4258","50",1],["3.4255","109.005",1],["3.4248","100",1],["3.4241","129.2048",2],["3.4233","5.3598",1],["3.4228","4498.866",1],["3.4222","3.5435",1],["3.4217","404.3252",2],["3.4211","1000",1],["3.4208","31",1],["3.42","1834.024",9],["3.4175","300",1],["3.4162","400",1],["3.4152","0.1",1],["3.4151","4.3336",1],["3.415","1.5974",1],["3.414","1146",1],["3.4134","306.4246",1],["3.4129","7.5556",1],["3.4111","198.5188",1],["3.4109","500",1],["3.4106","4305",1],["3.41","2150.7635",13],["3.4085","4.342",1],["3.4054","5.6985",1],["3.4019","5.438",1],["3.4015","1010.846",1],["3.4009","8610",1],["3.4005","1.9122",1],["3.4004","1",1],["3.4","27081.1806",67],["3.3955","3.2682",1],["3.3953","5.4486",1],["3.3937","1591.3805",1],["3.39","3221.4155",8],["3.3899","3.2736",1],["3.3888","1500",2],["3.3887","5.4592",1],["3.385","117.0969",2],["3.3821","5.4699",1],["3.382","100.0529",1],["3.3818","172.0164",1],["3.3815","165.6288",1],["3.381","887.3115",1],["3.3808","100",1]],"timestamp":"2019-03-04T00:15:04.155Z","checksum":-2036653089}]}` var dataResponse okgroup.WebsocketDataResponse - err := common.JSONDecode([]byte(orderbookPartialJSON), &dataResponse) + err := json.Unmarshal([]byte(orderbookPartialJSON), &dataResponse) if err != nil { t.Error(err) } diff --git a/exchanges/okgroup/okgroup.go b/exchanges/okgroup/okgroup.go index 1b24871ea77..afd95cf5746 100644 --- a/exchanges/okgroup/okgroup.go +++ b/exchanges/okgroup/okgroup.go @@ -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 diff --git a/exchanges/okgroup/okgroup_websocket.go b/exchanges/okgroup/okgroup_websocket.go index 19ee8b79823..13f95a2053c 100644 --- a/exchanges/okgroup/okgroup_websocket.go +++ b/exchanges/okgroup/okgroup_websocket.go @@ -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) diff --git a/exchanges/poloniex/poloniex_test.go b/exchanges/poloniex/poloniex_test.go index 3ce7d352b46..a89aca41421 100644 --- a/exchanges/poloniex/poloniex_test.go +++ b/exchanges/poloniex/poloniex_test.go @@ -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) } diff --git a/exchanges/poloniex/poloniex_websocket.go b/exchanges/poloniex/poloniex_websocket.go index 648a64c8d61..b5078c45182 100644 --- a/exchanges/poloniex/poloniex_websocket.go +++ b/exchanges/poloniex/poloniex_websocket.go @@ -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 diff --git a/exchanges/request/request.go b/exchanges/request/request.go index 10141a3620b..ed2cfd9a234 100644 --- a/exchanges/request/request.go +++ b/exchanges/request/request.go @@ -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 diff --git a/exchanges/websocket/wshandler/wshandler.go b/exchanges/websocket/wshandler/wshandler.go index 596a631bf92..27895cbdc96 100644 --- a/exchanges/websocket/wshandler/wshandler.go +++ b/exchanges/websocket/wshandler/wshandler.go @@ -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 } diff --git a/exchanges/websocket/wshandler/wshandler_test.go b/exchanges/websocket/wshandler/wshandler_test.go index 0c7cb7ec0f5..25ac23f6700 100644 --- a/exchanges/websocket/wshandler/wshandler_test.go +++ b/exchanges/websocket/wshandler/wshandler_test.go @@ -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 diff --git a/exchanges/zb/zb.go b/exchanges/zb/zb.go index 63fe8428eb7..998d4016ed3 100644 --- a/exchanges/zb/zb.go +++ b/exchanges/zb/zb.go @@ -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 diff --git a/exchanges/zb/zb_test.go b/exchanges/zb/zb_test.go index d097d40643e..c0bf48d4104 100644 --- a/exchanges/zb/zb_test.go +++ b/exchanges/zb/zb_test.go @@ -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) } diff --git a/exchanges/zb/zb_websocket.go b/exchanges/zb/zb_websocket.go index 0ac7d39d587..4560f582d26 100644 --- a/exchanges/zb/zb_websocket.go +++ b/exchanges/zb/zb_websocket.go @@ -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 } diff --git a/logger/logger_types.go b/logger/logger_types.go index a96087448e1..19a8aabfb29 100644 --- a/logger/logger_types.go +++ b/logger/logger_types.go @@ -5,9 +5,31 @@ import ( "sync" ) -const timestampFormat = " 02/01/2006 15:04:05 " +const ( + timestampFormat = " 02/01/2006 15:04:05 " + spacer = "|" +) -const spacer = "|" +var ( + logger = &Logger{} + // FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements + FileLoggingConfiguredCorrectly bool + // GlobalLogConfig holds global configuration options for logger + GlobalLogConfig = &Config{} + // GlobalLogFile hold global configuration options for file logger + GlobalLogFile = &Rotate{} + + eventPool = &sync.Pool{ + New: func() interface{} { + return &LogEvent{ + data: make([]byte, 0, 80), + } + }, + } + + // LogPath system path to store log files in + LogPath string +) // Config holds configuration settings loaded from bot config type Config struct { @@ -72,24 +94,3 @@ type multiWriter struct { writers []io.Writer mu sync.RWMutex } - -var ( - logger = &Logger{} - // FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements - FileLoggingConfiguredCorrectly bool - // GlobalLogConfig holds global configuration options for logger - GlobalLogConfig = &Config{} - // GlobalLogFile hold global configuration options for file logger - GlobalLogFile = &Rotate{} - - eventPool = &sync.Pool{ - New: func() interface{} { - return &LogEvent{ - data: make([]byte, 0, 80), - } - }, - } - - // LogPath system path to store log files in - LogPath string -)