(Engine) Variety of engine updates (#390)

* drop common uuid v4 func and imported package as needed

* removed common functions regarding json marshal and unmarshal and used the json package directly. WRT unmarshal it was calling reflect and converted to string which is also checked in the JSON package so it was doing a double up, this will be a tiny gain as it was directly used in the requester package for all our outbound requests.

* add in string

* explicitly throw away return error value

* atleast return the error that websocket initialise returns

* return error when not connected

* fix comment

* Adds comments

* move package declarations

* drop append whenever we call supported

* remove unused import

* Change incorrect spelling

* fix tests

* fix go import issue
This commit is contained in:
Ryan O'Hara-Reid
2019-12-03 10:06:08 +11:00
committed by Adrian Gallagher
parent c27b8657e2
commit 0c5d75b22c
70 changed files with 393 additions and 462 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,13 +2,13 @@ package anx
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -357,7 +357,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
req[key] = value
}
PayloadJSON, err := common.JSONEncode(req)
PayloadJSON, err := json.Marshal(req)
if err != nil {
return errors.New("unable to JSON request")
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package bitfinex
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -139,7 +139,7 @@ func (b *Bitfinex) WsConnect() error {
}
b.Websocket.TrafficAlert <- struct{}{}
var hs WebsocketHandshake
err = common.JSONDecode(resp.Raw, &hs)
err = json.Unmarshal(resp.Raw, &hs)
if err != nil {
return err
}
@@ -184,7 +184,7 @@ func (b *Bitfinex) WsDataHandler() {
if stream.Type == websocket.TextMessage {
var result interface{}
err = common.JSONDecode(stream.Raw, &result)
err = json.Unmarshal(stream.Raw, &result)
if err != nil {
b.Websocket.DataHandler <- err
return

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package bitstamp
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -67,7 +67,7 @@ func (b *Bitstamp) WsHandleData() {
}
b.Websocket.TrafficAlert <- struct{}{}
wsResponse := websocketResponse{}
err = common.JSONDecode(resp.Raw, &wsResponse)
err = json.Unmarshal(resp.Raw, &wsResponse)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -82,7 +82,7 @@ func (b *Bitstamp) WsHandleData() {
case "data":
wsOrderBookTemp := websocketOrderBookResponse{}
err := common.JSONDecode(resp.Raw, &wsOrderBookTemp)
err := json.Unmarshal(resp.Raw, &wsOrderBookTemp)
if err != nil {
b.Websocket.DataHandler <- err
continue
@@ -100,7 +100,7 @@ func (b *Bitstamp) WsHandleData() {
case "trade":
wsTradeTemp := websocketTradeResponse{}
err := common.JSONDecode(resp.Raw, &wsTradeTemp)
err := json.Unmarshal(resp.Raw, &wsTradeTemp)
if err != nil {
b.Websocket.DataHandler <- err
continue

View File

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

View File

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

View File

@@ -2,6 +2,7 @@ package btse
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
@@ -9,7 +10,6 @@ import (
"strconv"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -215,7 +215,7 @@ func (b *BTSE) SendAuthenticatedHTTPRequest(method, endpoint string, req map[str
var payload []byte
if len(req) != 0 {
var err error
payload, err = common.JSONEncode(req)
payload, err = json.Marshal(req)
if err != nil {
return err
}

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package coinbene
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -102,7 +102,7 @@ func (c *Coinbene) WsDataHandler() {
continue
}
var result map[string]interface{}
err = common.JSONDecode(stream.Raw, &result)
err = json.Unmarshal(stream.Raw, &result)
if err != nil {
c.Websocket.DataHandler <- err
}
@@ -127,7 +127,7 @@ func (c *Coinbene) WsDataHandler() {
switch {
case strings.Contains(result[topic].(string), "ticker"):
var ticker WsTicker
err = common.JSONDecode(stream.Raw, &ticker)
err = json.Unmarshal(stream.Raw, &ticker)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -147,7 +147,7 @@ func (c *Coinbene) WsDataHandler() {
}
case strings.Contains(result[topic].(string), "tradeList"):
var tradeList WsTradeList
err = common.JSONDecode(stream.Raw, &tradeList)
err = json.Unmarshal(stream.Raw, &tradeList)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -183,7 +183,7 @@ func (c *Coinbene) WsDataHandler() {
}
case strings.Contains(result[topic].(string), "orderBook"):
var orderBook WsOrderbook
err = common.JSONDecode(stream.Raw, &orderBook)
err = json.Unmarshal(stream.Raw, &orderBook)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -264,7 +264,7 @@ func (c *Coinbene) WsDataHandler() {
var kline WsKline
var tempFloat float64
var tempKline []float64
err = common.JSONDecode(stream.Raw, &kline)
err = json.Unmarshal(stream.Raw, &kline)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -293,7 +293,7 @@ func (c *Coinbene) WsDataHandler() {
}
case strings.Contains(result[topic].(string), "user.account"):
var userinfo WsUserInfo
err = common.JSONDecode(stream.Raw, &userinfo)
err = json.Unmarshal(stream.Raw, &userinfo)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -301,7 +301,7 @@ func (c *Coinbene) WsDataHandler() {
c.Websocket.DataHandler <- userinfo
case strings.Contains(result[topic].(string), "user.position"):
var position WsPosition
err = common.JSONDecode(stream.Raw, &position)
err = json.Unmarshal(stream.Raw, &position)
if err != nil {
c.Websocket.DataHandler <- err
continue
@@ -309,7 +309,7 @@ func (c *Coinbene) WsDataHandler() {
c.Websocket.DataHandler <- position
case strings.Contains(result[topic].(string), "user.order"):
var orders WsUserOrders
err = common.JSONDecode(stream.Raw, &orders)
err = json.Unmarshal(stream.Raw, &orders)
if err != nil {
c.Websocket.DataHandler <- err
continue

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package huobi
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -8,13 +9,11 @@ import (
"strings"
"time"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
log "github.com/thrasher-corp/gocryptotrader/logger"
@@ -139,7 +138,7 @@ func (h *HUOBI) WsHandleData() {
func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
var init WsAuthenticatedDataResponse
err := common.JSONDecode(resp.Raw, &init)
err := json.Unmarshal(resp.Raw, &init)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -169,14 +168,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
case strings.EqualFold(init.Op, authOp):
h.Websocket.SetCanUseAuthenticatedEndpoints(true)
var response WsAuthenticatedDataResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
h.Websocket.DataHandler <- response
case strings.EqualFold(init.Topic, "accounts"):
var response WsAuthenticatedAccountsResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
@@ -184,14 +183,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
case strings.Contains(init.Topic, "orders") &&
strings.Contains(init.Topic, "update"):
var response WsAuthenticatedOrdersUpdateResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
h.Websocket.DataHandler <- response
case strings.Contains(init.Topic, "orders"):
var response WsAuthenticatedOrdersResponse
err := common.JSONDecode(resp.Raw, &response)
err := json.Unmarshal(resp.Raw, &response)
if err != nil {
h.Websocket.DataHandler <- err
}
@@ -201,7 +200,7 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
var init WsResponse
err := common.JSONDecode(resp.Raw, &init)
err := json.Unmarshal(resp.Raw, &init)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -228,7 +227,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
switch {
case strings.Contains(init.Channel, "depth"):
var depth WsDepth
err := common.JSONDecode(resp.Raw, &depth)
err := json.Unmarshal(resp.Raw, &depth)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -243,7 +242,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
case strings.Contains(init.Channel, "kline"):
var kline WsKline
err := common.JSONDecode(resp.Raw, &kline)
err := json.Unmarshal(resp.Raw, &kline)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -263,7 +262,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
}
case strings.Contains(init.Channel, "trade.detail"):
var trade WsTrade
err := common.JSONDecode(resp.Raw, &trade)
err := json.Unmarshal(resp.Raw, &trade)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -278,7 +277,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
}
case strings.Contains(init.Channel, "detail"):
var ticker WsTick
err := common.JSONDecode(resp.Raw, &ticker)
err := json.Unmarshal(resp.Raw, &ticker)
if err != nil {
h.Websocket.DataHandler <- err
return
@@ -457,7 +456,7 @@ func (h *HUOBI) wsGetAccountsList(pair currency.Pair) (*WsAuthenticatedAccountsL
return nil, err
}
var response WsAuthenticatedAccountsListResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
return &response, err
}
@@ -485,7 +484,7 @@ func (h *HUOBI) wsGetOrdersList(accountID int64, pair currency.Pair) (*WsAuthent
return nil, err
}
var response WsAuthenticatedOrdersResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
return &response, err
}
@@ -511,6 +510,6 @@ func (h *HUOBI) wsGetOrderDetails(orderID string) (*WsAuthenticatedOrderDetailRe
return nil, err
}
var response WsAuthenticatedOrderDetailResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
return &response, err
}

View File

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

View File

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

View File

@@ -1,13 +1,13 @@
package lakebtc
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -302,7 +302,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
postData["id"] = 1
postData["params"] = strings.Split(params, ",")
data, err := common.JSONEncode(postData)
data, err := json.Marshal(postData)
if err != nil {
return err
}

View File

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package poloniex
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -95,7 +95,7 @@ func (p *Poloniex) WsHandleData() {
}
p.Websocket.TrafficAlert <- struct{}{}
var result interface{}
err = common.JSONDecode(resp.Raw, &result)
err = json.Unmarshal(resp.Raw, &result)
if err != nil {
p.Websocket.DataHandler <- err
continue

View File

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

View File

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

View File

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

View File

@@ -10,7 +10,6 @@ import (
"strings"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/convert"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
@@ -339,7 +338,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(httpMethod string, params url.Values,
return err
}
err = common.JSONDecode(intermediary, &errCap)
err = json.Unmarshal(intermediary, &errCap)
if err == nil {
if errCap.Code > 1000 {
return fmt.Errorf("sendAuthenticatedHTTPRequest error code: %d message %s",
@@ -348,7 +347,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(httpMethod string, params url.Values,
}
}
return common.JSONDecode(intermediary, result)
return json.Unmarshal(intermediary, result)
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -1,6 +1,7 @@
package zb
import (
"encoding/json"
"fmt"
"net/http"
"testing"
@@ -506,10 +507,10 @@ func TestGetDepositAddress(t *testing.T) {
// TestZBInvalidJSON ZB sends poorly formed JSON. this tests the JSON fixer
// Then JSON decode it to test if successful
func TestZBInvalidJSON(t *testing.T) {
json := `{"success":true,"code":1000,"channel":"getSubUserList","message":"[{"isOpenApi":false,"memo":"Memo","userName":"hello@imgoodthanksandyou.com@good","userId":1337,"isFreez":false}]","no":"0"}`
fixedJSON := z.wsFixInvalidJSON([]byte(json))
data := `{"success":true,"code":1000,"channel":"getSubUserList","message":"[{"isOpenApi":false,"memo":"Memo","userName":"hello@imgoodthanksandyou.com@good","userId":1337,"isFreez":false}]","no":"0"}`
fixedJSON := z.wsFixInvalidJSON([]byte(data))
var response WsGetSubUserListResponse
err := common.JSONDecode(fixedJSON, &response)
err := json.Unmarshal(fixedJSON, &response)
if err != nil {
t.Fatal(err)
}
@@ -517,10 +518,10 @@ func TestZBInvalidJSON(t *testing.T) {
t.Fatal("Expected extracted JSON USERID to equal 1337")
}
json = `{"success":true,"code":1000,"channel":"createSubUserKey","message":"{"apiKey":"thisisnotareallykeyyousillybilly","apiSecret":"lol"}","no":"123"}`
fixedJSON = z.wsFixInvalidJSON([]byte(json))
data = `{"success":true,"code":1000,"channel":"createSubUserKey","message":"{"apiKey":"thisisnotareallykeyyousillybilly","apiSecret":"lol"}","no":"123"}`
fixedJSON = z.wsFixInvalidJSON([]byte(data))
var response2 WsRequestResponse
err = common.JSONDecode(fixedJSON, &response2)
err = json.Unmarshal(fixedJSON, &response2)
if err != nil {
t.Error(err)
}

View File

@@ -1,6 +1,7 @@
package zb
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
@@ -64,7 +64,7 @@ func (z *ZB) WsHandleData() {
z.Websocket.TrafficAlert <- struct{}{}
fixedJSON := z.wsFixInvalidJSON(resp.Raw)
var result Generic
err = common.JSONDecode(fixedJSON, &result)
err = json.Unmarshal(fixedJSON, &result)
if err != nil {
z.Websocket.DataHandler <- err
continue
@@ -80,7 +80,7 @@ func (z *ZB) WsHandleData() {
switch {
case strings.Contains(result.Channel, "markets"):
var markets Markets
err := common.JSONDecode(result.Data, &markets)
err := json.Unmarshal(result.Data, &markets)
if err != nil {
z.Websocket.DataHandler <- err
continue
@@ -89,7 +89,7 @@ func (z *ZB) WsHandleData() {
case strings.Contains(result.Channel, "ticker"):
cPair := strings.Split(result.Channel, "_")
var ticker WsTicker
err := common.JSONDecode(fixedJSON, &ticker)
err := json.Unmarshal(fixedJSON, &ticker)
if err != nil {
z.Websocket.DataHandler <- err
continue
@@ -111,7 +111,7 @@ func (z *ZB) WsHandleData() {
case strings.Contains(result.Channel, "depth"):
var depth WsDepth
err := common.JSONDecode(fixedJSON, &depth)
err := json.Unmarshal(fixedJSON, &depth)
if err != nil {
z.Websocket.DataHandler <- err
continue
@@ -156,7 +156,7 @@ func (z *ZB) WsHandleData() {
case strings.Contains(result.Channel, "trades"):
var trades WsTrades
err := common.JSONDecode(fixedJSON, &trades)
err := json.Unmarshal(fixedJSON, &trades)
if err != nil {
z.Websocket.DataHandler <- err
continue
@@ -252,7 +252,7 @@ func (z *ZB) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscription
}
func (z *ZB) wsGenerateSignature(request interface{}) string {
jsonResponse, err := common.JSONEncode(request)
jsonResponse, err := json.Marshal(request)
if err != nil {
log.Error(log.ExchangeSys, err)
return ""
@@ -296,7 +296,7 @@ func (z *ZB) wsAddSubUser(username, password string) (*WsGetSubUserListResponse,
return nil, err
}
var genericResponse Generic
err = common.JSONDecode(resp, &genericResponse)
err = json.Unmarshal(resp, &genericResponse)
if err != nil {
return nil, err
}
@@ -304,7 +304,7 @@ func (z *ZB) wsAddSubUser(username, password string) (*WsGetSubUserListResponse,
return nil, fmt.Errorf("%v request failed, message: %v, error code: %v", z.Name, genericResponse.Message, wsErrCodes[genericResponse.Code])
}
var response WsGetSubUserListResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -327,7 +327,7 @@ func (z *ZB) wsGetSubUserList() (*WsGetSubUserListResponse, error) {
return nil, err
}
var response WsGetSubUserListResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -358,7 +358,7 @@ func (z *ZB) wsDoTransferFunds(pair currency.Code, amount float64, fromUserName,
return nil, err
}
var response WsRequestResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -391,7 +391,7 @@ func (z *ZB) wsCreateSubUserKey(assetPerm, entrustPerm, leverPerm, moneyPerm boo
return nil, err
}
var response WsRequestResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -421,7 +421,7 @@ func (z *ZB) wsSubmitOrder(pair currency.Pair, amount, price float64, tradeType
return nil, err
}
var response WsSubmitOrderResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -449,7 +449,7 @@ func (z *ZB) wsCancelOrder(pair currency.Pair, orderID int64) (*WsCancelOrderRes
return nil, err
}
var response WsCancelOrderResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -477,7 +477,7 @@ func (z *ZB) wsGetOrder(pair currency.Pair, orderID int64) (*WsGetOrderResponse,
return nil, err
}
var response WsGetOrderResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -505,7 +505,7 @@ func (z *ZB) wsGetOrders(pair currency.Pair, pageIndex, tradeType int64) (*WsGet
return nil, err
}
var response WsGetOrdersResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -534,7 +534,7 @@ func (z *ZB) wsGetOrdersIgnoreTradeType(pair currency.Pair, pageIndex, pageSize
return nil, err
}
var response WsGetOrdersIgnoreTradeTypeResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
@@ -561,7 +561,7 @@ func (z *ZB) wsGetAccountInfoRequest() (*WsGetAccountInfoResponse, error) {
return nil, err
}
var response WsGetAccountInfoResponse
err = common.JSONDecode(resp, &response)
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}

View File

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