mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
(Engine) Variety of engine updates (#390)
* drop common uuid v4 func and imported package as needed * removed common functions regarding json marshal and unmarshal and used the json package directly. WRT unmarshal it was calling reflect and converted to string which is also checked in the JSON package so it was doing a double up, this will be a tiny gain as it was directly used in the requester package for all our outbound requests. * add in string * explicitly throw away return error value * atleast return the error that websocket initialise returns * return error when not connected * fix comment * Adds comments * move package declarations * drop append whenever we call supported * remove unused import * Change incorrect spelling * fix tests * fix go import issue
This commit is contained in:
committed by
Adrian Gallagher
parent
c27b8657e2
commit
0c5d75b22c
@@ -13,7 +13,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
"github.com/thrasher-corp/gocryptotrader/config"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
@@ -737,7 +736,7 @@ func loadConfig() (Config, error) {
|
|||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(keys, &config)
|
err = json.Unmarshal(keys, &config)
|
||||||
return config, err
|
return config, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -113,13 +114,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Printf("Fetched config.")
|
log.Printf("Fetched config.")
|
||||||
|
|
||||||
dataJSON, err := common.JSONEncode(&wsResp.Data)
|
dataJSON, err := json.Marshal(&wsResp.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultCfg config.Config
|
var resultCfg config.Config
|
||||||
err = common.JSONDecode(dataJSON, &resultCfg)
|
err = json.Unmarshal(dataJSON, &resultCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofrs/uuid"
|
|
||||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,11 +41,6 @@ const (
|
|||||||
WeiPerEther = 1000000000000000000
|
WeiPerEther = 1000000000000000000
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetV4UUID returns a RFC 4122 UUID based on random numbers
|
|
||||||
func GetV4UUID() (uuid.UUID, error) {
|
|
||||||
return uuid.NewV4()
|
|
||||||
}
|
|
||||||
|
|
||||||
func initialiseHTTPClient() {
|
func initialiseHTTPClient() {
|
||||||
// If the HTTPClient isn't set, start a new client with a default timeout of 15 seconds
|
// If the HTTPClient isn't set, start a new client with a default timeout of 15 seconds
|
||||||
if HTTPClient == nil {
|
if HTTPClient == nil {
|
||||||
@@ -227,7 +220,7 @@ func SendHTTPGetRequest(urlPath string, jsonDecode, isVerbose bool, result inter
|
|||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
if jsonDecode {
|
if jsonDecode {
|
||||||
err := JSONDecode(contents, result)
|
err := json.Unmarshal(contents, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -236,19 +229,6 @@ func SendHTTPGetRequest(urlPath string, jsonDecode, isVerbose bool, result inter
|
|||||||
return nil
|
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
|
// EncodeURLValues concatenates url values onto a url string and returns a
|
||||||
// string
|
// string
|
||||||
func EncodeURLValues(urlPath string, values url.Values) string {
|
func EncodeURLValues(urlPath string, values url.Values) string {
|
||||||
|
|||||||
@@ -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) {
|
func TestEncodeURLValues(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
urlstring := "https://www.test.com"
|
urlstring := "https://www.test.com"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func TestNewComm(t *testing.T) {
|
|||||||
var cfg config.CommunicationsConfig
|
var cfg config.CommunicationsConfig
|
||||||
_, err := NewComm(&cfg)
|
_, err := NewComm(&cfg)
|
||||||
if err == nil {
|
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
|
cfg.TelegramConfig.Enabled = true
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func (s *Slack) PushEvent(event base.Event) error {
|
|||||||
return s.WebsocketSend("message",
|
return s.WebsocketSend("message",
|
||||||
fmt.Sprintf("event: %s %s", event.Type, event.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
|
// BuildURL returns an appended token string with the SlackURL
|
||||||
@@ -212,7 +212,7 @@ func (s *Slack) WebsocketReader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var data WebsocketResponse
|
var data WebsocketResponse
|
||||||
err = common.JSONDecode(resp, &data)
|
err = json.Unmarshal(resp, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln(log.CommunicationMgr, err)
|
log.Errorln(log.CommunicationMgr, err)
|
||||||
continue
|
continue
|
||||||
@@ -253,7 +253,7 @@ func (s *Slack) WebsocketReader() {
|
|||||||
|
|
||||||
func (s *Slack) handlePresenceChange(resp []byte) error {
|
func (s *Slack) handlePresenceChange(resp []byte) error {
|
||||||
var pres PresenceChange
|
var pres PresenceChange
|
||||||
err := common.JSONDecode(resp, &pres)
|
err := json.Unmarshal(resp, &pres)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error
|
|||||||
return errors.New("reply to is != 0")
|
return errors.New("reply to is != 0")
|
||||||
}
|
}
|
||||||
var msg Message
|
var msg Message
|
||||||
err := common.JSONDecode(resp, &msg)
|
err := json.Unmarshal(resp, &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ func (s *Slack) handleReconnectResponse(resp []byte) error {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
var recURL reconnectResponse
|
var recURL reconnectResponse
|
||||||
err := common.JSONDecode(resp, &recURL)
|
err := json.Unmarshal(resp, &recURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package slack
|
package slack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
"github.com/thrasher-corp/gocryptotrader/config"
|
||||||
)
|
)
|
||||||
@@ -198,7 +198,7 @@ func TestHandlePresenceChange(t *testing.T) {
|
|||||||
t.Error("slack handlePresenceChange(), unmarshalled malformed json")
|
t.Error("slack handlePresenceChange(), unmarshalled malformed json")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, _ := common.JSONEncode(pres)
|
data, _ := json.Marshal(pres)
|
||||||
err = s.handlePresenceChange(data)
|
err = s.handlePresenceChange(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("slack handlePresenceChange() Error: %s", err)
|
t.Errorf("slack handlePresenceChange() Error: %s", err)
|
||||||
@@ -225,7 +225,7 @@ func TestHandleMessageResponse(t *testing.T) {
|
|||||||
var msg Message
|
var msg Message
|
||||||
msg.User = "1337"
|
msg.User = "1337"
|
||||||
msg.Text = "Hello World!"
|
msg.Text = "Hello World!"
|
||||||
resp, _ := common.JSONEncode(msg)
|
resp, _ := json.Marshal(msg)
|
||||||
|
|
||||||
err = s.handleMessageResponse(resp, data)
|
err = s.handleMessageResponse(resp, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -233,7 +233,7 @@ func TestHandleMessageResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg.Text = "!notacommand"
|
msg.Text = "!notacommand"
|
||||||
resp, _ = common.JSONEncode(msg)
|
resp, _ = json.Marshal(msg)
|
||||||
|
|
||||||
err = s.handleMessageResponse(resp, data)
|
err = s.handleMessageResponse(resp, data)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -270,7 +270,7 @@ func TestHandleReconnectResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
testURL.URL = "https://www.thrasher.io"
|
testURL.URL = "https://www.thrasher.io"
|
||||||
|
|
||||||
data, _ := common.JSONEncode(testURL)
|
data, _ := json.Marshal(testURL)
|
||||||
|
|
||||||
err = s.handleReconnectResponse(data)
|
err = s.handleReconnectResponse(data)
|
||||||
if err != nil || s.ReconnectURL != "https://www.thrasher.io" {
|
if err != nil || s.ReconnectURL != "https://www.thrasher.io" {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package telegram
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -219,7 +220,7 @@ func (t *Telegram) SendMessage(text string, chatID int64) error {
|
|||||||
text,
|
text,
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := common.JSONEncode(&messageToSend)
|
json, err := json.Marshal(&messageToSend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -241,14 +242,17 @@ func (t *Telegram) SendMessage(text string, chatID int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendHTTPRequest sends an authenticated HTTP request
|
// 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 := make(map[string]string)
|
||||||
headers["content-type"] = "application/json"
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return common.JSONDecode([]byte(resp), result)
|
return json.Unmarshal([]byte(resp), result)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -168,7 +169,7 @@ func DecryptConfigFile(configData, key []byte) ([]byte, error) {
|
|||||||
|
|
||||||
// ConfirmConfigJSON confirms JSON in file
|
// ConfirmConfigJSON confirms JSON in file
|
||||||
func ConfirmConfigJSON(file []byte, result interface{}) error {
|
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
|
// ConfirmSalt checks whether the encrypted data contains a salt
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,7 +12,7 @@ import (
|
|||||||
func (r Role) String() string {
|
func (r Role) String() string {
|
||||||
switch r {
|
switch r {
|
||||||
case Unset:
|
case Unset:
|
||||||
return UnsetRollString
|
return UnsetRoleString
|
||||||
case Fiat:
|
case Fiat:
|
||||||
return FiatCurrencyString
|
return FiatCurrencyString
|
||||||
case Cryptocurrency:
|
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) {
|
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 {
|
func (r *Role) UnmarshalJSON(d []byte) error {
|
||||||
var incoming string
|
var incoming string
|
||||||
err := common.JSONDecode(d, &incoming)
|
err := json.Unmarshal(d, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch incoming {
|
switch incoming {
|
||||||
case UnsetRollString:
|
case UnsetRoleString:
|
||||||
*r = Unset
|
*r = Unset
|
||||||
case FiatCurrencyString:
|
case FiatCurrencyString:
|
||||||
*r = Fiat
|
*r = Fiat
|
||||||
@@ -400,7 +401,7 @@ func (c Code) Upper() Code {
|
|||||||
// UnmarshalJSON comforms type to the umarshaler interface
|
// UnmarshalJSON comforms type to the umarshaler interface
|
||||||
func (c *Code) UnmarshalJSON(d []byte) error {
|
func (c *Code) UnmarshalJSON(d []byte) error {
|
||||||
var newcode string
|
var newcode string
|
||||||
err := common.JSONDecode(d, &newcode)
|
err := json.Unmarshal(d, &newcode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -411,9 +412,9 @@ func (c *Code) UnmarshalJSON(d []byte) error {
|
|||||||
// MarshalJSON conforms type to the marshaler interface
|
// MarshalJSON conforms type to the marshaler interface
|
||||||
func (c Code) MarshalJSON() ([]byte, error) {
|
func (c Code) MarshalJSON() ([]byte, error) {
|
||||||
if c.Item == nil {
|
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
|
// IsEmpty returns true if the code is empty
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRoleString(t *testing.T) {
|
func TestRoleString(t *testing.T) {
|
||||||
if Unset.String() != UnsetRollString {
|
if Unset.String() != UnsetRoleString {
|
||||||
t.Errorf("Role String() error expected %s but received %s",
|
t.Errorf("Role String() error expected %s but received %s",
|
||||||
UnsetRollString,
|
UnsetRoleString,
|
||||||
Unset)
|
Unset)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +46,7 @@ func TestRoleString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRoleMarshalJSON(t *testing.T) {
|
func TestRoleMarshalJSON(t *testing.T) {
|
||||||
d, err := common.JSONEncode(Fiat)
|
d, err := json.Marshal(Fiat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Role MarshalJSON() error", err)
|
t.Error("Role MarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
@@ -79,23 +78,23 @@ func TestRoleUnmarshalJSON(t *testing.T) {
|
|||||||
RoleFive: Contract,
|
RoleFive: Contract,
|
||||||
}
|
}
|
||||||
|
|
||||||
e, err := common.JSONEncode(1337)
|
e, err := json.Marshal(1337)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Role UnmarshalJSON() error", err)
|
t.Fatal("Role UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var incoming AllTheRoles
|
var incoming AllTheRoles
|
||||||
err = common.JSONDecode(e, &incoming)
|
err = json.Unmarshal(e, &incoming)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Role UnmarshalJSON() Expected error")
|
t.Fatal("Role UnmarshalJSON() Expected error")
|
||||||
}
|
}
|
||||||
|
|
||||||
e, err = common.JSONEncode(outgoing)
|
e, err = json.Marshal(outgoing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Role UnmarshalJSON() error", err)
|
t.Fatal("Role UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(e, &incoming)
|
err = json.Unmarshal(e, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Role UnmarshalJSON() error", err)
|
t.Fatal("Role UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
@@ -365,17 +364,17 @@ func TestCodeUpper(t *testing.T) {
|
|||||||
func TestCodeUnmarshalJSON(t *testing.T) {
|
func TestCodeUnmarshalJSON(t *testing.T) {
|
||||||
var unmarshalHere Code
|
var unmarshalHere Code
|
||||||
expected := "BRO"
|
expected := "BRO"
|
||||||
encoded, err := common.JSONEncode(expected)
|
encoded, err := json.Marshal(expected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currency Code UnmarshalJSON error", err)
|
t.Fatal("Currency Code UnmarshalJSON error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currency Code UnmarshalJSON error", err)
|
t.Fatal("Currency Code UnmarshalJSON error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currency Code UnmarshalJSON error", err)
|
t.Fatal("Currency Code UnmarshalJSON error", err)
|
||||||
}
|
}
|
||||||
@@ -396,7 +395,7 @@ func TestCodeMarshalJSON(t *testing.T) {
|
|||||||
|
|
||||||
expectedJSON := `{"sweetCodes":"BRO"}`
|
expectedJSON := `{"sweetCodes":"BRO"}`
|
||||||
|
|
||||||
encoded, err := common.JSONEncode(quickstruct)
|
encoded, err := json.Marshal(quickstruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currency Code UnmarshalJSON error", err)
|
t.Fatal("Currency Code UnmarshalJSON error", err)
|
||||||
}
|
}
|
||||||
@@ -413,7 +412,7 @@ func TestCodeMarshalJSON(t *testing.T) {
|
|||||||
Codey: Code{}, // nil code
|
Codey: Code{}, // nil code
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded, err = common.JSONEncode(quickstruct)
|
encoded, err = json.Marshal(quickstruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currency Code UnmarshalJSON error", err)
|
t.Fatal("Currency Code UnmarshalJSON error", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bitmasks const for currency rolls
|
// Bitmasks const for currency roles
|
||||||
const (
|
const (
|
||||||
Unset Role = 0
|
Unset Role = 0
|
||||||
Fiat Role = 1 << (iota - 1)
|
Fiat Role = 1 << (iota - 1)
|
||||||
@@ -13,14 +13,14 @@ const (
|
|||||||
Token
|
Token
|
||||||
Contract
|
Contract
|
||||||
|
|
||||||
UnsetRollString = "roleUnset"
|
UnsetRoleString = "roleUnset"
|
||||||
FiatCurrencyString = "fiatCurrency"
|
FiatCurrencyString = "fiatCurrency"
|
||||||
CryptocurrencyString = "cryptocurrency"
|
CryptocurrencyString = "cryptocurrency"
|
||||||
TokenString = "token"
|
TokenString = "token"
|
||||||
ContractString = "contract"
|
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
|
// cryptocurrency, token, or contract
|
||||||
type Role uint8
|
type Role uint8
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCurrenciesFromStringArray returns a Currencies object from strings
|
// NewCurrenciesFromStringArray returns a Currencies object from strings
|
||||||
@@ -48,7 +47,7 @@ func (c Currencies) Join() string {
|
|||||||
// UnmarshalJSON comforms type to the umarshaler interface
|
// UnmarshalJSON comforms type to the umarshaler interface
|
||||||
func (c *Currencies) UnmarshalJSON(d []byte) error {
|
func (c *Currencies) UnmarshalJSON(d []byte) error {
|
||||||
var configCurrencies string
|
var configCurrencies string
|
||||||
err := common.JSONDecode(d, &configCurrencies)
|
err := json.Unmarshal(d, &configCurrencies)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -64,7 +63,7 @@ func (c *Currencies) UnmarshalJSON(d []byte) error {
|
|||||||
|
|
||||||
// MarshalJSON conforms type to the marshaler interface
|
// MarshalJSON conforms type to the marshaler interface
|
||||||
func (c Currencies) MarshalJSON() ([]byte, error) {
|
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
|
// Match returns if the full list equals the supplied list
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCurrenciesUnmarshalJSON(t *testing.T) {
|
func TestCurrenciesUnmarshalJSON(t *testing.T) {
|
||||||
var unmarshalHere Currencies
|
var unmarshalHere Currencies
|
||||||
expected := "btc,usd,ltc,bro,things"
|
expected := "btc,usd,ltc,bro,things"
|
||||||
encoded, err := common.JSONEncode(expected)
|
encoded, err := json.Marshal(expected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currencies UnmarshalJSON() error", err)
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currencies UnmarshalJSON() error", err)
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currencies UnmarshalJSON() error", err)
|
t.Fatal("Currencies UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ func TestCurrenciesMarshalJSON(t *testing.T) {
|
|||||||
C: NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "things"}),
|
C: NewCurrenciesFromStringArray([]string{"btc", "usd", "ltc", "bro", "things"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded, err := common.JSONEncode(quickStruct)
|
encoded, err := json.Marshal(quickStruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Currencies MarshalJSON() error", err)
|
t.Fatal("Currencies MarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewPairDelimiter splits the desired currency string at delimeter, the returns
|
// 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
|
// UnmarshalJSON comforms type to the umarshaler interface
|
||||||
func (p *Pair) UnmarshalJSON(d []byte) error {
|
func (p *Pair) UnmarshalJSON(d []byte) error {
|
||||||
var pair string
|
var pair string
|
||||||
err := common.JSONDecode(d, &pair)
|
err := json.Unmarshal(d, &pair)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -124,7 +123,7 @@ func (p *Pair) UnmarshalJSON(d []byte) error {
|
|||||||
|
|
||||||
// MarshalJSON conforms type to the marshaler interface
|
// MarshalJSON conforms type to the marshaler interface
|
||||||
func (p Pair) MarshalJSON() ([]byte, error) {
|
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
|
// Format changes the currency based on user preferences overriding the default
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -37,17 +36,17 @@ func TestPairUnmarshalJSON(t *testing.T) {
|
|||||||
var unmarshalHere Pair
|
var unmarshalHere Pair
|
||||||
configPair := NewPairDelimiter("btc_usd", "_")
|
configPair := NewPairDelimiter("btc_usd", "_")
|
||||||
|
|
||||||
encoded, err := common.JSONEncode(configPair)
|
encoded, err := json.Marshal(configPair)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pair UnmarshalJSON() error", err)
|
t.Fatal("Pair UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pair UnmarshalJSON() error", err)
|
t.Fatal("Pair UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pair UnmarshalJSON() error", err)
|
t.Fatal("Pair UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
@@ -65,7 +64,7 @@ func TestPairMarshalJSON(t *testing.T) {
|
|||||||
Pair{Base: BTC, Quote: USD, Delimiter: "-"},
|
Pair{Base: BTC, Quote: USD, Delimiter: "-"},
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded, err := common.JSONEncode(quickstruct)
|
encoded, err := json.Marshal(quickstruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pair MarshalJSON() error", err)
|
t.Fatal("Pair MarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
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
|
// UnmarshalJSON comforms type to the umarshaler interface
|
||||||
func (p *Pairs) UnmarshalJSON(d []byte) error {
|
func (p *Pairs) UnmarshalJSON(d []byte) error {
|
||||||
var pairs string
|
var pairs string
|
||||||
err := common.JSONDecode(d, &pairs)
|
err := json.Unmarshal(d, &pairs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ func (p *Pairs) UnmarshalJSON(d []byte) error {
|
|||||||
|
|
||||||
// MarshalJSON conforms type to the marshaler interface
|
// MarshalJSON conforms type to the marshaler interface
|
||||||
func (p Pairs) MarshalJSON() ([]byte, error) {
|
func (p Pairs) MarshalJSON() ([]byte, error) {
|
||||||
return common.JSONEncode(p.Join())
|
return json.Marshal(p.Join())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upper returns an upper formatted pair list
|
// Upper returns an upper formatted pair list
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package currency
|
package currency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPairsUpper(t *testing.T) {
|
func TestPairsUpper(t *testing.T) {
|
||||||
@@ -69,33 +68,33 @@ func TestPairsFormat(t *testing.T) {
|
|||||||
func TestPairsUnmarshalJSON(t *testing.T) {
|
func TestPairsUnmarshalJSON(t *testing.T) {
|
||||||
var unmarshalHere Pairs
|
var unmarshalHere Pairs
|
||||||
configPairs := ""
|
configPairs := ""
|
||||||
encoded, err := common.JSONEncode(configPairs)
|
encoded, err := json.Marshal(configPairs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pairs UnmarshalJSON() error", err)
|
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 {
|
if err == nil {
|
||||||
t.Fatal("error cannot be nil")
|
t.Fatal("error cannot be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pairs UnmarshalJSON() error", err)
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configPairs = "btc_usd,btc_aud,btc_ltc"
|
configPairs = "btc_usd,btc_aud,btc_ltc"
|
||||||
encoded, err = common.JSONEncode(configPairs)
|
encoded, err = json.Marshal(configPairs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pairs UnmarshalJSON() error", err)
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pairs UnmarshalJSON() error", err)
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(encoded, &unmarshalHere)
|
err = json.Unmarshal(encoded, &unmarshalHere)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pairs UnmarshalJSON() error", err)
|
t.Fatal("Pairs UnmarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
@@ -113,7 +112,7 @@ func TestPairsMarshalJSON(t *testing.T) {
|
|||||||
Pairs: NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"}),
|
Pairs: NewPairsFromStrings([]string{"btc_usd", "btc_aud", "btc_ltc"}),
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded, err := common.JSONEncode(quickstruct)
|
encoded, err := json.Marshal(quickstruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Pairs MarshalJSON() error", err)
|
t.Fatal("Pairs MarshalJSON() error", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency/coinmarketcap"
|
"github.com/thrasher-corp/gocryptotrader/currency/coinmarketcap"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider"
|
"github.com/thrasher-corp/gocryptotrader/currency/forexprovider"
|
||||||
@@ -264,7 +263,7 @@ func (s *Storage) SeedCurrencyAnalysisData() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fromFile File
|
var fromFile File
|
||||||
err = common.JSONDecode(b, &fromFile)
|
err = json.Unmarshal(b, &fromFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -364,7 +363,7 @@ func (s *Storage) LoadFileCurrencyData(f *File) error {
|
|||||||
return nil
|
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 {
|
func (s *Storage) UpdateCurrencies() error {
|
||||||
m, err := s.currencyAnalysis.GetCryptocurrencyIDMap()
|
m, err := s.currencyAnalysis.GetCryptocurrencyIDMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -62,12 +62,11 @@ func (m *Mux) Publish(ids []uuid.UUID, data interface{}) error {
|
|||||||
return nil
|
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) {
|
func (m *Mux) GetID() (uuid.UUID, error) {
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return uuid.UUID{}, errors.New("mux is nil")
|
return uuid.UUID{}, errors.New("mux is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.d.getNewID()
|
return m.d.getNewID()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,12 @@ type connectionManager struct {
|
|||||||
conn *connchecker.Checker
|
conn *connchecker.Checker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Started returns if the connection manager has started
|
||||||
func (c *connectionManager) Started() bool {
|
func (c *connectionManager) Started() bool {
|
||||||
return atomic.LoadInt32(&c.started) == 1
|
return atomic.LoadInt32(&c.started) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start starts an instance of the connection manager
|
||||||
func (c *connectionManager) Start() error {
|
func (c *connectionManager) Start() error {
|
||||||
if atomic.AddInt32(&c.started, 1) != 1 {
|
if atomic.AddInt32(&c.started, 1) != 1 {
|
||||||
return errors.New("connection manager already started")
|
return errors.New("connection manager already started")
|
||||||
@@ -38,6 +40,7 @@ func (c *connectionManager) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop stops the connection manager
|
||||||
func (c *connectionManager) Stop() error {
|
func (c *connectionManager) Stop() error {
|
||||||
if atomic.LoadInt32(&c.started) == 0 {
|
if atomic.LoadInt32(&c.started) == 0 {
|
||||||
return errors.New("connection manager not started")
|
return errors.New("connection manager not started")
|
||||||
@@ -55,6 +58,7 @@ func (c *connectionManager) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsOnline returns if the connection manager is online
|
||||||
func (c *connectionManager) IsOnline() bool {
|
func (c *connectionManager) IsOnline() bool {
|
||||||
if c.conn == nil {
|
if c.conn == nil {
|
||||||
log.Warnln(log.ConnectionMgr, "Connection manager: IsOnline called but conn is nil")
|
log.Warnln(log.ConnectionMgr, "Connection manager: IsOnline called but conn is nil")
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gofrs/uuid"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
"github.com/thrasher-corp/gocryptotrader/communications/base"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
"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")
|
return nil, errors.New("unable to get exchange by name")
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := common.GetV4UUID()
|
id, err := uuid.NewV4()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf(log.OrderMgr,
|
log.Warnf(log.OrderMgr,
|
||||||
"Order manager: Unable to generate UUID. Err: %s\n",
|
"Order manager: Unable to generate UUID. Err: %s\n",
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
"github.com/thrasher-corp/gocryptotrader/config"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
@@ -79,7 +79,7 @@ func (h *WebsocketHub) run() {
|
|||||||
|
|
||||||
// SendWebsocketMessage sends a websocket event to the client
|
// SendWebsocketMessage sends a websocket event to the client
|
||||||
func (c *WebsocketClient) SendWebsocketMessage(evt interface{}) error {
|
func (c *WebsocketClient) SendWebsocketMessage(evt interface{}) error {
|
||||||
data, err := common.JSONEncode(evt)
|
data, err := json.Marshal(evt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(log.WebsocketMgr, "websocket: failed to send message: %s\n", err)
|
log.Errorf(log.WebsocketMgr, "websocket: failed to send message: %s\n", err)
|
||||||
return err
|
return err
|
||||||
@@ -106,7 +106,7 @@ func (c *WebsocketClient) read() {
|
|||||||
|
|
||||||
if msgType == websocket.TextMessage {
|
if msgType == websocket.TextMessage {
|
||||||
var evt WebsocketEvent
|
var evt WebsocketEvent
|
||||||
err := common.JSONDecode(message, &evt)
|
err := json.Unmarshal(message, &evt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(log.WebsocketMgr, "websocket: failed to decode JSON sent from client %s\n", err)
|
log.Errorf(log.WebsocketMgr, "websocket: failed to decode JSON sent from client %s\n", err)
|
||||||
continue
|
continue
|
||||||
@@ -117,7 +117,7 @@ func (c *WebsocketClient) read() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dataJSON, err := common.JSONEncode(evt.Data)
|
dataJSON, err := json.Marshal(evt.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln(log.WebsocketMgr, "websocket: client sent data we couldn't JSON decode")
|
log.Errorln(log.WebsocketMgr, "websocket: client sent data we couldn't JSON decode")
|
||||||
break
|
break
|
||||||
@@ -197,7 +197,7 @@ func BroadcastWebsocketMessage(evt WebsocketEvent) error {
|
|||||||
return errors.New("websocket service not started")
|
return errors.New("websocket service not started")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := common.JSONEncode(evt)
|
data, err := json.Marshal(evt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ func wsAuth(client *WebsocketClient, data interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var auth WebsocketAuth
|
var auth WebsocketAuth
|
||||||
err := common.JSONDecode(data.([]byte), &auth)
|
err := json.Unmarshal(data.([]byte), &auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wsResp.Error = err.Error()
|
wsResp.Error = err.Error()
|
||||||
client.SendWebsocketMessage(wsResp)
|
client.SendWebsocketMessage(wsResp)
|
||||||
@@ -303,7 +303,7 @@ func wsSaveConfig(client *WebsocketClient, data interface{}) error {
|
|||||||
Event: "SaveConfig",
|
Event: "SaveConfig",
|
||||||
}
|
}
|
||||||
var cfg config.Config
|
var cfg config.Config
|
||||||
err := common.JSONDecode(data.([]byte), &cfg)
|
err := json.Unmarshal(data.([]byte), &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wsResp.Error = err.Error()
|
wsResp.Error = err.Error()
|
||||||
client.SendWebsocketMessage(wsResp)
|
client.SendWebsocketMessage(wsResp)
|
||||||
@@ -344,7 +344,7 @@ func wsGetTicker(client *WebsocketClient, data interface{}) error {
|
|||||||
Event: "GetTicker",
|
Event: "GetTicker",
|
||||||
}
|
}
|
||||||
var tickerReq WebsocketOrderbookTickerRequest
|
var tickerReq WebsocketOrderbookTickerRequest
|
||||||
err := common.JSONDecode(data.([]byte), &tickerReq)
|
err := json.Unmarshal(data.([]byte), &tickerReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wsResp.Error = err.Error()
|
wsResp.Error = err.Error()
|
||||||
client.SendWebsocketMessage(wsResp)
|
client.SendWebsocketMessage(wsResp)
|
||||||
@@ -376,7 +376,7 @@ func wsGetOrderbook(client *WebsocketClient, data interface{}) error {
|
|||||||
Event: "GetOrderbook",
|
Event: "GetOrderbook",
|
||||||
}
|
}
|
||||||
var orderbookReq WebsocketOrderbookTickerRequest
|
var orderbookReq WebsocketOrderbookTickerRequest
|
||||||
err := common.JSONDecode(data.([]byte), &orderbookReq)
|
err := json.Unmarshal(data.([]byte), &orderbookReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wsResp.Error = err.Error()
|
wsResp.Error = err.Error()
|
||||||
client.SendWebsocketMessage(wsResp)
|
client.SendWebsocketMessage(wsResp)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package alphapoint
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
"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"
|
headers["Content-Type"] = "application/json"
|
||||||
path = fmt.Sprintf("%s/ajax/v%s/%s", a.API.Endpoints.URL, alphapointAPIVersion, path)
|
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 {
|
if err != nil {
|
||||||
return errors.New("unable to JSON request")
|
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))
|
data["apiSig"] = strings.ToUpper(crypto.HexEncodeToString(hmac))
|
||||||
path = fmt.Sprintf("%s/ajax/v%s/%s", a.API.Endpoints.URL, alphapointAPIVersion, path)
|
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 {
|
if err != nil {
|
||||||
return errors.New("unable to JSON request")
|
return errors.New("unable to JSON request")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package alphapoint
|
package alphapoint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"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}`),
|
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 {
|
if err != nil {
|
||||||
t.Fatal("Alphapoint GetTicker unmarshalling error: ", err)
|
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}]}`),
|
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 {
|
if err != nil {
|
||||||
t.Fatal("GetTrades unmarshalling error: ", err)
|
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}]}`),
|
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 {
|
if err != nil {
|
||||||
t.Fatal("GetTradesByDate unmarshalling error: ", err)
|
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}`),
|
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 {
|
if err != nil {
|
||||||
t.Fatal("TestGetOrderbook unmarshalling error: ", err)
|
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}`),
|
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 {
|
if err != nil {
|
||||||
t.Fatal("TestGetProductPairs unmarshalling error: ", err)
|
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}`),
|
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 {
|
if err != nil {
|
||||||
t.Fatal("TestGetProducts unmarshalling error: ", err)
|
t.Fatal("TestGetProducts unmarshalling error: ", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package alphapoint
|
package alphapoint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ func (a *Alphapoint) WebsocketClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgType := MsgType{}
|
msgType := MsgType{}
|
||||||
err := common.JSONDecode(resp, &msgType)
|
err := json.Unmarshal(resp, &msgType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(log.ExchangeSys, err)
|
log.Error(log.ExchangeSys, err)
|
||||||
continue
|
continue
|
||||||
@@ -57,7 +57,7 @@ func (a *Alphapoint) WebsocketClient() {
|
|||||||
|
|
||||||
if msgType.MessageType == "Ticker" {
|
if msgType.MessageType == "Ticker" {
|
||||||
ticker := WebsocketTicker{}
|
ticker := WebsocketTicker{}
|
||||||
err = common.JSONDecode(resp, &ticker)
|
err = json.Unmarshal(resp, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(log.ExchangeSys, err)
|
log.Error(log.ExchangeSys, err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package anx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -357,7 +357,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
|
|||||||
req[key] = value
|
req[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
PayloadJSON, err := common.JSONEncode(req)
|
PayloadJSON, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to JSON request")
|
return errors.New("unable to JSON request")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,21 +23,21 @@ const (
|
|||||||
DownsideProfitContract = Item("downsideprofitcontract")
|
DownsideProfitContract = Item("downsideprofitcontract")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var supported = Items{
|
||||||
|
Spot,
|
||||||
|
Margin,
|
||||||
|
Index,
|
||||||
|
Binary,
|
||||||
|
PerpetualContract,
|
||||||
|
PerpetualSwap,
|
||||||
|
Futures,
|
||||||
|
UpsideProfitContract,
|
||||||
|
DownsideProfitContract,
|
||||||
|
}
|
||||||
|
|
||||||
// Supported returns a list of supported asset types
|
// Supported returns a list of supported asset types
|
||||||
func Supported() Items {
|
func Supported() Items {
|
||||||
var a Items
|
return supported
|
||||||
a = append(a,
|
|
||||||
Spot,
|
|
||||||
Margin,
|
|
||||||
Index,
|
|
||||||
Binary,
|
|
||||||
PerpetualContract,
|
|
||||||
PerpetualSwap,
|
|
||||||
Futures,
|
|
||||||
UpsideProfitContract,
|
|
||||||
DownsideProfitContract,
|
|
||||||
)
|
|
||||||
return a
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an Item to string
|
// returns an Item to string
|
||||||
|
|||||||
@@ -526,13 +526,13 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := common.JSONDecode(interim, &errCap); err == nil {
|
if err := json.Unmarshal(interim, &errCap); err == nil {
|
||||||
if !errCap.Success && errCap.Message != "" {
|
if !errCap.Success && errCap.Message != "" {
|
||||||
return errors.New(errCap.Message)
|
return errors.New(errCap.Message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return common.JSONDecode(interim, result)
|
return json.Unmarshal(interim, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckLimit checks value against a variable list
|
// CheckLimit checks value against a variable list
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package binance
|
package binance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||||
@@ -92,7 +92,7 @@ func (b *Binance) WsHandleData() {
|
|||||||
}
|
}
|
||||||
b.Websocket.TrafficAlert <- struct{}{}
|
b.Websocket.TrafficAlert <- struct{}{}
|
||||||
var multiStreamData MultiStreamData
|
var multiStreamData MultiStreamData
|
||||||
err = common.JSONDecode(read.Raw, &multiStreamData)
|
err = json.Unmarshal(read.Raw, &multiStreamData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not load multi stream data: %s",
|
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not load multi stream data: %s",
|
||||||
b.Name,
|
b.Name,
|
||||||
@@ -103,7 +103,7 @@ func (b *Binance) WsHandleData() {
|
|||||||
switch streamType[1] {
|
switch streamType[1] {
|
||||||
case "trade":
|
case "trade":
|
||||||
trade := TradeStream{}
|
trade := TradeStream{}
|
||||||
err := common.JSONDecode(multiStreamData.Data, &trade)
|
err := json.Unmarshal(multiStreamData.Data, &trade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not unmarshal trade data: %s",
|
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not unmarshal trade data: %s",
|
||||||
b.Name,
|
b.Name,
|
||||||
@@ -140,7 +140,7 @@ func (b *Binance) WsHandleData() {
|
|||||||
continue
|
continue
|
||||||
case "ticker":
|
case "ticker":
|
||||||
t := TickerStream{}
|
t := TickerStream{}
|
||||||
err := common.JSONDecode(multiStreamData.Data, &t)
|
err := json.Unmarshal(multiStreamData.Data, &t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to a TickerStream structure %s",
|
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to a TickerStream structure %s",
|
||||||
b.Name,
|
b.Name,
|
||||||
@@ -168,7 +168,7 @@ func (b *Binance) WsHandleData() {
|
|||||||
continue
|
continue
|
||||||
case "kline":
|
case "kline":
|
||||||
kline := KlineStream{}
|
kline := KlineStream{}
|
||||||
err := common.JSONDecode(multiStreamData.Data, &kline)
|
err := json.Unmarshal(multiStreamData.Data, &kline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to a KlineStream structure %s",
|
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to a KlineStream structure %s",
|
||||||
b.Name,
|
b.Name,
|
||||||
@@ -194,7 +194,7 @@ func (b *Binance) WsHandleData() {
|
|||||||
continue
|
continue
|
||||||
case "depth":
|
case "depth":
|
||||||
depth := WebsocketDepthStream{}
|
depth := WebsocketDepthStream{}
|
||||||
err := common.JSONDecode(multiStreamData.Data, &depth)
|
err := json.Unmarshal(multiStreamData.Data, &depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to depthStream structure %s",
|
b.Websocket.DataHandler <- fmt.Errorf("%v - Could not convert to depthStream structure %s",
|
||||||
b.Name,
|
b.Name,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package bitfinex
|
package bitfinex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -953,7 +954,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
|
|||||||
req[key] = value
|
req[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
PayloadJSON, err := common.JSONEncode(req)
|
PayloadJSON, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("sendAuthenticatedAPIRequest: unable to JSON request")
|
return errors.New("sendAuthenticatedAPIRequest: unable to JSON request")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package bitfinex
|
package bitfinex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -139,7 +139,7 @@ func (b *Bitfinex) WsConnect() error {
|
|||||||
}
|
}
|
||||||
b.Websocket.TrafficAlert <- struct{}{}
|
b.Websocket.TrafficAlert <- struct{}{}
|
||||||
var hs WebsocketHandshake
|
var hs WebsocketHandshake
|
||||||
err = common.JSONDecode(resp.Raw, &hs)
|
err = json.Unmarshal(resp.Raw, &hs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,7 @@ func (b *Bitfinex) WsDataHandler() {
|
|||||||
|
|
||||||
if stream.Type == websocket.TextMessage {
|
if stream.Type == websocket.TextMessage {
|
||||||
var result interface{}
|
var result interface{}
|
||||||
err = common.JSONDecode(stream.Raw, &result)
|
err = json.Unmarshal(stream.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -110,7 +109,7 @@ func (b *Bithumb) GetAllTickers() (map[string]Ticker, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var newTicker Ticker
|
var newTicker Ticker
|
||||||
err := common.JSONDecode(v, &newTicker)
|
err := json.Unmarshal(v, &newTicker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -518,7 +517,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(intermediary, &errCapture)
|
err = json.Unmarshal(intermediary, &errCapture)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if errCapture.Status != "" && errCapture.Status != noError {
|
if errCapture.Status != "" && errCapture.Status != noError {
|
||||||
return fmt.Errorf("sendAuthenticatedAPIRequest error code: %s message:%s",
|
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
|
// GetFee returns an estimate of fee based on type of transaction
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -829,7 +828,7 @@ func (b *Bitmex) SendAuthenticatedHTTPRequest(verb, path string, params Paramete
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data, err := common.JSONEncode(params)
|
data, err := json.Marshal(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -870,14 +869,14 @@ func (b *Bitmex) CaptureError(resp, reType interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(marshalled, &Error)
|
err = json.Unmarshal(marshalled, &Error)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("bitmex error %s: %s",
|
return fmt.Errorf("bitmex error %s: %s",
|
||||||
Error.Error.Name,
|
Error.Error.Name,
|
||||||
Error.Error.Message)
|
Error.Error.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
return common.JSONDecode(marshalled, reType)
|
return json.Unmarshal(marshalled, reType)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFee returns an estimate of fee based on type of transaction
|
// GetFee returns an estimate of fee based on type of transaction
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package bitmex
|
package bitmex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -85,7 +85,7 @@ func (b *Bitmex) WsConnect() error {
|
|||||||
}
|
}
|
||||||
b.Websocket.TrafficAlert <- struct{}{}
|
b.Websocket.TrafficAlert <- struct{}{}
|
||||||
var welcomeResp WebsocketWelcome
|
var welcomeResp WebsocketWelcome
|
||||||
err = common.JSONDecode(p.Raw, &welcomeResp)
|
err = json.Unmarshal(p.Raw, &welcomeResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
quickCapture := make(map[string]interface{})
|
quickCapture := make(map[string]interface{})
|
||||||
err = common.JSONDecode(resp.Raw, &quickCapture)
|
err = json.Unmarshal(resp.Raw, &quickCapture)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -151,7 +151,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
|
|
||||||
var respError WebsocketErrorResponse
|
var respError WebsocketErrorResponse
|
||||||
if _, ok := quickCapture["status"]; ok {
|
if _, ok := quickCapture["status"]; ok {
|
||||||
err = common.JSONDecode(resp.Raw, &respError)
|
err = json.Unmarshal(resp.Raw, &respError)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -162,7 +162,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
|
|
||||||
if _, ok := quickCapture["success"]; ok {
|
if _, ok := quickCapture["success"]; ok {
|
||||||
var decodedResp WebsocketSubscribeResp
|
var decodedResp WebsocketSubscribeResp
|
||||||
err := common.JSONDecode(resp.Raw, &decodedResp)
|
err := json.Unmarshal(resp.Raw, &decodedResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -189,7 +189,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Name, decodedResp.Subscribe)
|
b.Name, decodedResp.Subscribe)
|
||||||
} else if _, ok := quickCapture["table"]; ok {
|
} else if _, ok := quickCapture["table"]; ok {
|
||||||
var decodedResp WebsocketMainResponse
|
var decodedResp WebsocketMainResponse
|
||||||
err := common.JSONDecode(resp.Raw, &decodedResp)
|
err := json.Unmarshal(resp.Raw, &decodedResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -198,7 +198,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
switch decodedResp.Table {
|
switch decodedResp.Table {
|
||||||
case bitmexWSOrderbookL2:
|
case bitmexWSOrderbookL2:
|
||||||
var orderbooks OrderBookData
|
var orderbooks OrderBookData
|
||||||
err = common.JSONDecode(resp.Raw, &orderbooks)
|
err = json.Unmarshal(resp.Raw, &orderbooks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -223,7 +223,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
|
|
||||||
case bitmexWSTrade:
|
case bitmexWSTrade:
|
||||||
var trades TradeData
|
var trades TradeData
|
||||||
err = common.JSONDecode(resp.Raw, &trades)
|
err = json.Unmarshal(resp.Raw, &trades)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -254,7 +254,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
|
|
||||||
case bitmexWSAnnouncement:
|
case bitmexWSAnnouncement:
|
||||||
var announcement AnnouncementData
|
var announcement AnnouncementData
|
||||||
err = common.JSONDecode(resp.Raw, &announcement)
|
err = json.Unmarshal(resp.Raw, &announcement)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -267,7 +267,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- announcement.Data
|
b.Websocket.DataHandler <- announcement.Data
|
||||||
case bitmexWSAffiliate:
|
case bitmexWSAffiliate:
|
||||||
var response WsAffiliateResponse
|
var response WsAffiliateResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -275,7 +275,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSExecution:
|
case bitmexWSExecution:
|
||||||
var response WsExecutionResponse
|
var response WsExecutionResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -283,7 +283,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSOrder:
|
case bitmexWSOrder:
|
||||||
var response WsOrderResponse
|
var response WsOrderResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -291,7 +291,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSMargin:
|
case bitmexWSMargin:
|
||||||
var response WsMarginResponse
|
var response WsMarginResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -299,7 +299,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSPosition:
|
case bitmexWSPosition:
|
||||||
var response WsPositionResponse
|
var response WsPositionResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -307,7 +307,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSPrivateNotifications:
|
case bitmexWSPrivateNotifications:
|
||||||
var response WsPrivateNotificationsResponse
|
var response WsPrivateNotificationsResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -315,7 +315,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSTransact:
|
case bitmexWSTransact:
|
||||||
var response WsTransactResponse
|
var response WsTransactResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -323,7 +323,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- response
|
b.Websocket.DataHandler <- response
|
||||||
case bitmexWSWallet:
|
case bitmexWSWallet:
|
||||||
var response WsWalletResponse
|
var response WsWalletResponse
|
||||||
err = common.JSONDecode(resp.Raw, &response)
|
err = json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -676,7 +676,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := common.JSONDecode(interim, &errCap); err == nil {
|
if err := json.Unmarshal(interim, &errCap); err == nil {
|
||||||
if errCap.Error != "" {
|
if errCap.Error != "" {
|
||||||
return errors.New(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) {
|
func parseTime(dateTime string) (time.Time, error) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package bitstamp
|
package bitstamp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||||
@@ -67,7 +67,7 @@ func (b *Bitstamp) WsHandleData() {
|
|||||||
}
|
}
|
||||||
b.Websocket.TrafficAlert <- struct{}{}
|
b.Websocket.TrafficAlert <- struct{}{}
|
||||||
wsResponse := websocketResponse{}
|
wsResponse := websocketResponse{}
|
||||||
err = common.JSONDecode(resp.Raw, &wsResponse)
|
err = json.Unmarshal(resp.Raw, &wsResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -82,7 +82,7 @@ func (b *Bitstamp) WsHandleData() {
|
|||||||
|
|
||||||
case "data":
|
case "data":
|
||||||
wsOrderBookTemp := websocketOrderBookResponse{}
|
wsOrderBookTemp := websocketOrderBookResponse{}
|
||||||
err := common.JSONDecode(resp.Raw, &wsOrderBookTemp)
|
err := json.Unmarshal(resp.Raw, &wsOrderBookTemp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -100,7 +100,7 @@ func (b *Bitstamp) WsHandleData() {
|
|||||||
case "trade":
|
case "trade":
|
||||||
wsTradeTemp := websocketTradeResponse{}
|
wsTradeTemp := websocketTradeResponse{}
|
||||||
|
|
||||||
err := common.JSONDecode(resp.Raw, &wsTradeTemp)
|
err := json.Unmarshal(resp.Raw, &wsTradeTemp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package btcmarkets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -391,7 +392,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data, result
|
|||||||
payload := []byte("")
|
payload := []byte("")
|
||||||
|
|
||||||
if data != nil {
|
if data != nil {
|
||||||
payload, err = common.JSONEncode(data)
|
payload, err = json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package btcmarkets
|
package btcmarkets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||||
@@ -58,7 +58,7 @@ func (b *BTCMarkets) WsHandleData() {
|
|||||||
}
|
}
|
||||||
b.Websocket.TrafficAlert <- struct{}{}
|
b.Websocket.TrafficAlert <- struct{}{}
|
||||||
var wsResponse WsMessageType
|
var wsResponse WsMessageType
|
||||||
err = common.JSONDecode(resp.Raw, &wsResponse)
|
err = json.Unmarshal(resp.Raw, &wsResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -70,7 +70,7 @@ func (b *BTCMarkets) WsHandleData() {
|
|||||||
}
|
}
|
||||||
case "orderbook":
|
case "orderbook":
|
||||||
var ob WsOrderbook
|
var ob WsOrderbook
|
||||||
err := common.JSONDecode(resp.Raw, &ob)
|
err := json.Unmarshal(resp.Raw, &ob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -131,7 +131,7 @@ func (b *BTCMarkets) WsHandleData() {
|
|||||||
}
|
}
|
||||||
case "trade":
|
case "trade":
|
||||||
var trade WsTrade
|
var trade WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &trade)
|
err := json.Unmarshal(resp.Raw, &trade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -147,7 +147,7 @@ func (b *BTCMarkets) WsHandleData() {
|
|||||||
}
|
}
|
||||||
case "tick":
|
case "tick":
|
||||||
var tick WsTick
|
var tick WsTick
|
||||||
err := common.JSONDecode(resp.Raw, &tick)
|
err := json.Unmarshal(resp.Raw, &tick)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -168,7 +168,7 @@ func (b *BTCMarkets) WsHandleData() {
|
|||||||
}
|
}
|
||||||
case "error":
|
case "error":
|
||||||
var wsErr WsError
|
var wsErr WsError
|
||||||
err := common.JSONDecode(resp.Raw, &wsErr)
|
err := json.Unmarshal(resp.Raw, &wsErr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package btse
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -215,7 +215,7 @@ func (b *BTSE) SendAuthenticatedHTTPRequest(method, endpoint string, req map[str
|
|||||||
var payload []byte
|
var payload []byte
|
||||||
if len(req) != 0 {
|
if len(req) != 0 {
|
||||||
var err error
|
var err error
|
||||||
payload, err = common.JSONEncode(req)
|
payload, err = json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package btse
|
package btse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||||
@@ -63,7 +63,7 @@ func (b *BTSE) WsHandleData() {
|
|||||||
|
|
||||||
type Result map[string]interface{}
|
type Result map[string]interface{}
|
||||||
result := Result{}
|
result := Result{}
|
||||||
err = common.JSONDecode(resp.Raw, &result)
|
err = json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -76,7 +76,7 @@ func (b *BTSE) WsHandleData() {
|
|||||||
"sell side",
|
"sell side",
|
||||||
b.Name)
|
b.Name)
|
||||||
var tradeHistory wsTradeHistory
|
var tradeHistory wsTradeHistory
|
||||||
err = common.JSONDecode(resp.Raw, &tradeHistory)
|
err = json.Unmarshal(resp.Raw, &tradeHistory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -98,7 +98,7 @@ func (b *BTSE) WsHandleData() {
|
|||||||
}
|
}
|
||||||
case strings.Contains(result["topic"].(string), "orderBookApi"):
|
case strings.Contains(result["topic"].(string), "orderBookApi"):
|
||||||
var t wsOrderBook
|
var t wsOrderBook
|
||||||
err = common.JSONDecode(resp.Raw, &t)
|
err = json.Unmarshal(resp.Raw, &t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Websocket.DataHandler <- err
|
b.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package coinbasepro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -733,7 +734,7 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m
|
|||||||
payload := []byte("")
|
payload := []byte("")
|
||||||
|
|
||||||
if params != nil {
|
if params != nil {
|
||||||
payload, err = common.JSONEncode(params)
|
payload, err = json.Marshal(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
|
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package coinbasepro
|
package coinbasepro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -8,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -67,7 +67,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
msgType := MsgType{}
|
msgType := MsgType{}
|
||||||
err = common.JSONDecode(resp.Raw, &msgType)
|
err = json.Unmarshal(resp.Raw, &msgType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -83,7 +83,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
|
|
||||||
case "ticker":
|
case "ticker":
|
||||||
ticker := WebsocketTicker{}
|
ticker := WebsocketTicker{}
|
||||||
err := common.JSONDecode(resp.Raw, &ticker)
|
err := json.Unmarshal(resp.Raw, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -105,7 +105,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
|
|
||||||
case "snapshot":
|
case "snapshot":
|
||||||
snapshot := WebsocketOrderbookSnapshot{}
|
snapshot := WebsocketOrderbookSnapshot{}
|
||||||
err := common.JSONDecode(resp.Raw, &snapshot)
|
err := json.Unmarshal(resp.Raw, &snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -119,7 +119,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
|
|
||||||
case "l2update":
|
case "l2update":
|
||||||
update := WebsocketL2Update{}
|
update := WebsocketL2Update{}
|
||||||
err := common.JSONDecode(resp.Raw, &update)
|
err := json.Unmarshal(resp.Raw, &update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -133,7 +133,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
case "received":
|
case "received":
|
||||||
// We currently use l2update to calculate orderbook changes
|
// We currently use l2update to calculate orderbook changes
|
||||||
received := WebsocketReceived{}
|
received := WebsocketReceived{}
|
||||||
err := common.JSONDecode(resp.Raw, &received)
|
err := json.Unmarshal(resp.Raw, &received)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -142,7 +142,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
case "open":
|
case "open":
|
||||||
// We currently use l2update to calculate orderbook changes
|
// We currently use l2update to calculate orderbook changes
|
||||||
open := WebsocketOpen{}
|
open := WebsocketOpen{}
|
||||||
err := common.JSONDecode(resp.Raw, &open)
|
err := json.Unmarshal(resp.Raw, &open)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -151,7 +151,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
case "done":
|
case "done":
|
||||||
// We currently use l2update to calculate orderbook changes
|
// We currently use l2update to calculate orderbook changes
|
||||||
done := WebsocketDone{}
|
done := WebsocketDone{}
|
||||||
err := common.JSONDecode(resp.Raw, &done)
|
err := json.Unmarshal(resp.Raw, &done)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -160,7 +160,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
case "change":
|
case "change":
|
||||||
// We currently use l2update to calculate orderbook changes
|
// We currently use l2update to calculate orderbook changes
|
||||||
change := WebsocketChange{}
|
change := WebsocketChange{}
|
||||||
err := common.JSONDecode(resp.Raw, &change)
|
err := json.Unmarshal(resp.Raw, &change)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -169,7 +169,7 @@ func (c *CoinbasePro) WsHandleData() {
|
|||||||
case "activate":
|
case "activate":
|
||||||
// We currently use l2update to calculate orderbook changes
|
// We currently use l2update to calculate orderbook changes
|
||||||
activate := WebsocketActivate{}
|
activate := WebsocketActivate{}
|
||||||
err := common.JSONDecode(resp.Raw, &activate)
|
err := json.Unmarshal(resp.Raw, &activate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package coinbene
|
package coinbene
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -102,7 +102,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var result map[string]interface{}
|
var result map[string]interface{}
|
||||||
err = common.JSONDecode(stream.Raw, &result)
|
err = json.Unmarshal(stream.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
switch {
|
switch {
|
||||||
case strings.Contains(result[topic].(string), "ticker"):
|
case strings.Contains(result[topic].(string), "ticker"):
|
||||||
var ticker WsTicker
|
var ticker WsTicker
|
||||||
err = common.JSONDecode(stream.Raw, &ticker)
|
err = json.Unmarshal(stream.Raw, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -147,7 +147,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
}
|
}
|
||||||
case strings.Contains(result[topic].(string), "tradeList"):
|
case strings.Contains(result[topic].(string), "tradeList"):
|
||||||
var tradeList WsTradeList
|
var tradeList WsTradeList
|
||||||
err = common.JSONDecode(stream.Raw, &tradeList)
|
err = json.Unmarshal(stream.Raw, &tradeList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -183,7 +183,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
}
|
}
|
||||||
case strings.Contains(result[topic].(string), "orderBook"):
|
case strings.Contains(result[topic].(string), "orderBook"):
|
||||||
var orderBook WsOrderbook
|
var orderBook WsOrderbook
|
||||||
err = common.JSONDecode(stream.Raw, &orderBook)
|
err = json.Unmarshal(stream.Raw, &orderBook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -264,7 +264,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
var kline WsKline
|
var kline WsKline
|
||||||
var tempFloat float64
|
var tempFloat float64
|
||||||
var tempKline []float64
|
var tempKline []float64
|
||||||
err = common.JSONDecode(stream.Raw, &kline)
|
err = json.Unmarshal(stream.Raw, &kline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -293,7 +293,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
}
|
}
|
||||||
case strings.Contains(result[topic].(string), "user.account"):
|
case strings.Contains(result[topic].(string), "user.account"):
|
||||||
var userinfo WsUserInfo
|
var userinfo WsUserInfo
|
||||||
err = common.JSONDecode(stream.Raw, &userinfo)
|
err = json.Unmarshal(stream.Raw, &userinfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -301,7 +301,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
c.Websocket.DataHandler <- userinfo
|
c.Websocket.DataHandler <- userinfo
|
||||||
case strings.Contains(result[topic].(string), "user.position"):
|
case strings.Contains(result[topic].(string), "user.position"):
|
||||||
var position WsPosition
|
var position WsPosition
|
||||||
err = common.JSONDecode(stream.Raw, &position)
|
err = json.Unmarshal(stream.Raw, &position)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -309,7 +309,7 @@ func (c *Coinbene) WsDataHandler() {
|
|||||||
c.Websocket.DataHandler <- position
|
c.Websocket.DataHandler <- position
|
||||||
case strings.Contains(result[topic].(string), "user.order"):
|
case strings.Contains(result[topic].(string), "user.order"):
|
||||||
var orders WsUserOrders
|
var orders WsUserOrders
|
||||||
err = common.JSONDecode(stream.Raw, &orders)
|
err = json.Unmarshal(stream.Raw, &orders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
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["nonce"] = n
|
||||||
params["request"] = apiRequest
|
params["request"] = apiRequest
|
||||||
|
|
||||||
payload, err := common.JSONEncode(params)
|
payload, err := json.Marshal(params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("sendHTTPRequest: Unable to JSON request")
|
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
|
var genResp GenericResponse
|
||||||
err = common.JSONDecode(rawMsg, &genResp)
|
err = json.Unmarshal(rawMsg, &genResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -327,7 +326,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
|
|||||||
genResp.Status[0])
|
genResp.Status[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return common.JSONDecode(rawMsg, result)
|
return json.Unmarshal(rawMsg, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFee returns an estimate of fee based on type of transaction
|
// GetFee returns an estimate of fee based on type of transaction
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package coinut
|
package coinut
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -8,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -85,7 +85,7 @@ func (c *COINUT) WsHandleData() {
|
|||||||
|
|
||||||
if strings.HasPrefix(string(resp.Raw), "[") {
|
if strings.HasPrefix(string(resp.Raw), "[") {
|
||||||
var incoming []wsResponse
|
var incoming []wsResponse
|
||||||
err = common.JSONDecode(resp.Raw, &incoming)
|
err = json.Unmarshal(resp.Raw, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -96,7 +96,7 @@ func (c *COINUT) WsHandleData() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
var individualJSON []byte
|
var individualJSON []byte
|
||||||
individualJSON, err = common.JSONEncode(incoming[i])
|
individualJSON, err = json.Marshal(incoming[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -105,7 +105,7 @@ func (c *COINUT) WsHandleData() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var incoming wsResponse
|
var incoming wsResponse
|
||||||
err = common.JSONDecode(resp.Raw, &incoming)
|
err = json.Unmarshal(resp.Raw, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -119,7 +119,7 @@ func (c *COINUT) WsHandleData() {
|
|||||||
|
|
||||||
func (c *COINUT) wsProcessResponse(resp []byte) {
|
func (c *COINUT) wsProcessResponse(resp []byte) {
|
||||||
var incoming wsResponse
|
var incoming wsResponse
|
||||||
err := common.JSONDecode(resp, &incoming)
|
err := json.Unmarshal(resp, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -129,7 +129,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
|
|||||||
channels["hb"] <- resp
|
channels["hb"] <- resp
|
||||||
case "inst_tick":
|
case "inst_tick":
|
||||||
var ticker WsTicker
|
var ticker WsTicker
|
||||||
err := common.JSONDecode(resp, &ticker)
|
err := json.Unmarshal(resp, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -154,7 +154,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
|
|||||||
|
|
||||||
case "inst_order_book":
|
case "inst_order_book":
|
||||||
var orderbooksnapshot WsOrderbookSnapshot
|
var orderbooksnapshot WsOrderbookSnapshot
|
||||||
err := common.JSONDecode(resp, &orderbooksnapshot)
|
err := json.Unmarshal(resp, &orderbooksnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -174,7 +174,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
|
|||||||
}
|
}
|
||||||
case "inst_order_book_update":
|
case "inst_order_book_update":
|
||||||
var orderbookUpdate WsOrderbookUpdate
|
var orderbookUpdate WsOrderbookUpdate
|
||||||
err := common.JSONDecode(resp, &orderbookUpdate)
|
err := json.Unmarshal(resp, &orderbookUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -194,7 +194,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
|
|||||||
}
|
}
|
||||||
case "inst_trade":
|
case "inst_trade":
|
||||||
var tradeSnap WsTradeSnapshot
|
var tradeSnap WsTradeSnapshot
|
||||||
err := common.JSONDecode(resp, &tradeSnap)
|
err := json.Unmarshal(resp, &tradeSnap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -202,7 +202,7 @@ func (c *COINUT) wsProcessResponse(resp []byte) {
|
|||||||
|
|
||||||
case "inst_trade_update":
|
case "inst_trade_update":
|
||||||
var tradeUpdate WsTradeUpdate
|
var tradeUpdate WsTradeUpdate
|
||||||
err := common.JSONDecode(resp, &tradeUpdate)
|
err := json.Unmarshal(resp, &tradeUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Websocket.DataHandler <- err
|
c.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -250,7 +250,7 @@ func (c *COINUT) WsSetInstrumentList() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var list WsInstrumentList
|
var list WsInstrumentList
|
||||||
err = common.JSONDecode(resp, &list)
|
err = json.Unmarshal(resp, &list)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -357,7 +357,7 @@ func (c *COINUT) Unsubscribe(channelToSubscribe wshandler.WebsocketChannelSubscr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -394,7 +394,7 @@ func (c *COINUT) wsAuthenticate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -419,7 +419,7 @@ func (c *COINUT) wsGetAccountBalance() (*WsGetAccountBalanceResponse, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsGetAccountBalanceResponse
|
var response WsGetAccountBalanceResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -466,14 +466,14 @@ func (c *COINUT) wsSubmitOrder(order *WsSubmitOrderParameters) (*WsStandardOrder
|
|||||||
func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderResponse, error) {
|
func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderResponse, error) {
|
||||||
var response WsStandardOrderResponse
|
var response WsStandardOrderResponse
|
||||||
var incoming wsResponse
|
var incoming wsResponse
|
||||||
err := common.JSONDecode(resp, &incoming)
|
err := json.Unmarshal(resp, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
switch incoming.Reply {
|
switch incoming.Reply {
|
||||||
case "order_accepted":
|
case "order_accepted":
|
||||||
var orderAccepted WsOrderAcceptedResponse
|
var orderAccepted WsOrderAcceptedResponse
|
||||||
err := common.JSONDecode(resp, &orderAccepted)
|
err := json.Unmarshal(resp, &orderAccepted)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
@@ -492,7 +492,7 @@ func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderRespons
|
|||||||
}
|
}
|
||||||
case "order_filled":
|
case "order_filled":
|
||||||
var orderFilled WsOrderFilledResponse
|
var orderFilled WsOrderFilledResponse
|
||||||
err := common.JSONDecode(resp, &orderFilled)
|
err := json.Unmarshal(resp, &orderFilled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
@@ -511,7 +511,7 @@ func (c *COINUT) wsStandardiseOrderResponse(resp []byte) (WsStandardOrderRespons
|
|||||||
}
|
}
|
||||||
case "order_rejected":
|
case "order_rejected":
|
||||||
var orderRejected WsOrderRejectedResponse
|
var orderRejected WsOrderRejectedResponse
|
||||||
err := common.JSONDecode(resp, &orderRejected)
|
err := json.Unmarshal(resp, &orderRejected)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
@@ -561,14 +561,14 @@ func (c *COINUT) wsSubmitOrders(orders []WsSubmitOrderParameters) ([]WsStandardO
|
|||||||
return nil, errors
|
return nil, errors
|
||||||
}
|
}
|
||||||
var incoming []interface{}
|
var incoming []interface{}
|
||||||
err = common.JSONDecode(resp, &incoming)
|
err = json.Unmarshal(resp, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
return nil, errors
|
return nil, errors
|
||||||
}
|
}
|
||||||
for i := range incoming {
|
for i := range incoming {
|
||||||
var individualJSON []byte
|
var individualJSON []byte
|
||||||
individualJSON, err = common.JSONEncode(incoming[i])
|
individualJSON, err = json.Marshal(incoming[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
continue
|
continue
|
||||||
@@ -612,7 +612,7 @@ func (c *COINUT) wsGetOpenOrders(p currency.Pair) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -640,7 +640,7 @@ func (c *COINUT) wsCancelOrder(cancellation WsCancelOrderParameters) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -675,7 +675,7 @@ func (c *COINUT) wsCancelOrders(cancellations []WsCancelOrderParameters) (*WsCan
|
|||||||
return nil, []error{err}
|
return nil, []error{err}
|
||||||
}
|
}
|
||||||
var response WsCancelOrdersResponse
|
var response WsCancelOrdersResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, []error{err}
|
return nil, []error{err}
|
||||||
}
|
}
|
||||||
@@ -711,7 +711,7 @@ func (c *COINUT) wsGetTradeHistory(p currency.Pair, start, limit int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
// No needs to check err here as the only err condition is an empty
|
||||||
// string which is already checked above
|
// string which is already checked above
|
||||||
e.Requester.SetProxy(proxy)
|
_ = e.Requester.SetProxy(proxy)
|
||||||
|
|
||||||
if e.Websocket != nil {
|
if e.Websocket != nil {
|
||||||
err = e.Websocket.SetProxyAddress(addr)
|
err = e.Websocket.SetProxyAddress(addr)
|
||||||
@@ -460,7 +460,7 @@ func (e *Base) SetupDefaults(exch *config.ExchangeConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if e.Features.Supports.Websocket {
|
if e.Features.Supports.Websocket {
|
||||||
e.Websocket.Initialise()
|
return e.Websocket.Initialise()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
@@ -428,7 +427,7 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(method, endpoint, param string, re
|
|||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
if err := common.JSONDecode(intermidiary, &errCap); err == nil {
|
if err := json.Unmarshal(intermidiary, &errCap); err == nil {
|
||||||
if !errCap.Result {
|
if !errCap.Result {
|
||||||
return fmt.Errorf("%s auth request error, code: %d message: %s",
|
return fmt.Errorf("%s auth request error, code: %d message: %s",
|
||||||
g.Name,
|
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
|
// GetFee returns an estimate of fee based on type of transaction
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gateio
|
package gateio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -64,7 +64,7 @@ func (g *Gateio) wsServerSignIn() (*WebsocketAuthenticationResponse, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WebsocketAuthenticationResponse
|
var response WebsocketAuthenticationResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
g.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -97,7 +97,7 @@ func (g *Gateio) WsHandleData() {
|
|||||||
}
|
}
|
||||||
g.Websocket.TrafficAlert <- struct{}{}
|
g.Websocket.TrafficAlert <- struct{}{}
|
||||||
var result WebsocketResponse
|
var result WebsocketResponse
|
||||||
err = common.JSONDecode(resp.Raw, &result)
|
err = json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -123,13 +123,13 @@ func (g *Gateio) WsHandleData() {
|
|||||||
case strings.Contains(result.Method, "ticker"):
|
case strings.Contains(result.Method, "ticker"):
|
||||||
var ticker WebsocketTicker
|
var ticker WebsocketTicker
|
||||||
var c string
|
var c string
|
||||||
err = common.JSONDecode(result.Params[1], &ticker)
|
err = json.Unmarshal(result.Params[1], &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(result.Params[0], &c)
|
err = json.Unmarshal(result.Params[0], &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -151,13 +151,13 @@ func (g *Gateio) WsHandleData() {
|
|||||||
case strings.Contains(result.Method, "trades"):
|
case strings.Contains(result.Method, "trades"):
|
||||||
var trades []WebsocketTrade
|
var trades []WebsocketTrade
|
||||||
var c string
|
var c string
|
||||||
err = common.JSONDecode(result.Params[1], &trades)
|
err = json.Unmarshal(result.Params[1], &trades)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(result.Params[0], &c)
|
err = json.Unmarshal(result.Params[0], &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -179,19 +179,19 @@ func (g *Gateio) WsHandleData() {
|
|||||||
var IsSnapshot bool
|
var IsSnapshot bool
|
||||||
var c string
|
var c string
|
||||||
var data = make(map[string][][]string)
|
var data = make(map[string][][]string)
|
||||||
err = common.JSONDecode(result.Params[0], &IsSnapshot)
|
err = json.Unmarshal(result.Params[0], &IsSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(result.Params[2], &c)
|
err = json.Unmarshal(result.Params[2], &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(result.Params[1], &data)
|
err = json.Unmarshal(result.Params[1], &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -265,7 +265,7 @@ func (g *Gateio) WsHandleData() {
|
|||||||
|
|
||||||
case strings.Contains(result.Method, "kline"):
|
case strings.Contains(result.Method, "kline"):
|
||||||
var data []interface{}
|
var data []interface{}
|
||||||
err = common.JSONDecode(result.Params[0], &data)
|
err = json.Unmarshal(result.Params[0], &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -356,7 +356,7 @@ func (g *Gateio) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscrip
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response WebsocketAuthenticationResponse
|
var response WebsocketAuthenticationResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -380,7 +380,7 @@ func (g *Gateio) Unsubscribe(channelToSubscribe wshandler.WebsocketChannelSubscr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response WebsocketAuthenticationResponse
|
var response WebsocketAuthenticationResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ func (g *Gateio) wsGetBalance(currencies []string) (*WsGetBalanceResponse, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var balance WsGetBalanceResponse
|
var balance WsGetBalanceResponse
|
||||||
err = common.JSONDecode(resp, &balance)
|
err = json.Unmarshal(resp, &balance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &balance, err
|
return &balance, err
|
||||||
}
|
}
|
||||||
@@ -430,7 +430,7 @@ func (g *Gateio) wsGetOrderInfo(market string, offset, limit int) (*WebSocketOrd
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var orderQuery WebSocketOrderQueryResult
|
var orderQuery WebSocketOrderQueryResult
|
||||||
err = common.JSONDecode(resp, &orderQuery)
|
err = json.Unmarshal(resp, &orderQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &orderQuery, err
|
return &orderQuery, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gemini
|
package gemini
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -371,7 +372,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st
|
|||||||
req[key] = value
|
req[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
PayloadJSON, err := common.JSONEncode(req)
|
PayloadJSON, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
|
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON request")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package gemini
|
package gemini
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -11,7 +12,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
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),
|
Request: fmt.Sprintf("/v1/%v", url),
|
||||||
Nonce: time.Now().UnixNano(),
|
Nonce: time.Now().UnixNano(),
|
||||||
}
|
}
|
||||||
PayloadJSON, err := common.JSONEncode(payload)
|
PayloadJSON, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v sendAuthenticatedHTTPRequest: Unable to JSON request", g.Name)
|
return fmt.Errorf("%v sendAuthenticatedHTTPRequest: Unable to JSON request", g.Name)
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var result map[string]interface{}
|
var result map[string]interface{}
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- fmt.Errorf("%v Error: %v, Raw: %v", g.Name, err, string(resp.Raw))
|
g.Websocket.DataHandler <- fmt.Errorf("%v Error: %v, Raw: %v", g.Name, err, string(resp.Raw))
|
||||||
continue
|
continue
|
||||||
@@ -174,7 +174,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
switch result["type"] {
|
switch result["type"] {
|
||||||
case "subscription_ack":
|
case "subscription_ack":
|
||||||
var result WsSubscriptionAcknowledgementResponse
|
var result WsSubscriptionAcknowledgementResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -182,7 +182,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "initial":
|
case "initial":
|
||||||
var result WsSubscriptionAcknowledgementResponse
|
var result WsSubscriptionAcknowledgementResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -190,7 +190,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "accepted":
|
case "accepted":
|
||||||
var result WsActiveOrdersResponse
|
var result WsActiveOrdersResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -198,7 +198,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "booked":
|
case "booked":
|
||||||
var result WsOrderBookedResponse
|
var result WsOrderBookedResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -206,7 +206,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "fill":
|
case "fill":
|
||||||
var result WsOrderFilledResponse
|
var result WsOrderFilledResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -214,7 +214,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "cancelled":
|
case "cancelled":
|
||||||
var result WsOrderCancelledResponse
|
var result WsOrderCancelledResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -222,7 +222,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "closed":
|
case "closed":
|
||||||
var result WsOrderClosedResponse
|
var result WsOrderClosedResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -230,7 +230,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
g.Websocket.DataHandler <- result
|
g.Websocket.DataHandler <- result
|
||||||
case "heartbeat":
|
case "heartbeat":
|
||||||
var result WsHeartbeatResponse
|
var result WsHeartbeatResponse
|
||||||
err := common.JSONDecode(resp.Raw, &result)
|
err := json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -243,7 +243,7 @@ func (g *Gemini) WsHandleData() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var marketUpdate WsMarketUpdateResponse
|
var marketUpdate WsMarketUpdateResponse
|
||||||
err := common.JSONDecode(resp.Raw, &marketUpdate)
|
err := json.Unmarshal(resp.Raw, &marketUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Websocket.DataHandler <- err
|
g.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package hitbtc
|
package hitbtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -8,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -71,7 +71,7 @@ func (h *HitBTC) WsHandleData() {
|
|||||||
h.Websocket.TrafficAlert <- struct{}{}
|
h.Websocket.TrafficAlert <- struct{}{}
|
||||||
|
|
||||||
var init capture
|
var init capture
|
||||||
err = common.JSONDecode(resp.Raw, &init)
|
err = json.Unmarshal(resp.Raw, &init)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -105,7 +105,7 @@ func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, ini
|
|||||||
switch init.Method {
|
switch init.Method {
|
||||||
case "ticker":
|
case "ticker":
|
||||||
var ticker WsTicker
|
var ticker WsTicker
|
||||||
err := common.JSONDecode(resp.Raw, &ticker)
|
err := json.Unmarshal(resp.Raw, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -132,7 +132,7 @@ func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, ini
|
|||||||
}
|
}
|
||||||
case "snapshotOrderbook":
|
case "snapshotOrderbook":
|
||||||
var obSnapshot WsOrderbook
|
var obSnapshot WsOrderbook
|
||||||
err := common.JSONDecode(resp.Raw, &obSnapshot)
|
err := json.Unmarshal(resp.Raw, &obSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
@@ -142,33 +142,33 @@ func (h *HitBTC) handleSubscriptionUpdates(resp wshandler.WebsocketResponse, ini
|
|||||||
}
|
}
|
||||||
case "updateOrderbook":
|
case "updateOrderbook":
|
||||||
var obUpdate WsOrderbook
|
var obUpdate WsOrderbook
|
||||||
err := common.JSONDecode(resp.Raw, &obUpdate)
|
err := json.Unmarshal(resp.Raw, &obUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.WsProcessOrderbookUpdate(obUpdate)
|
h.WsProcessOrderbookUpdate(obUpdate)
|
||||||
case "snapshotTrades":
|
case "snapshotTrades":
|
||||||
var tradeSnapshot WsTrade
|
var tradeSnapshot WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &tradeSnapshot)
|
err := json.Unmarshal(resp.Raw, &tradeSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
case "updateTrades":
|
case "updateTrades":
|
||||||
var tradeUpdates WsTrade
|
var tradeUpdates WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &tradeUpdates)
|
err := json.Unmarshal(resp.Raw, &tradeUpdates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
case "activeOrders":
|
case "activeOrders":
|
||||||
var activeOrders WsActiveOrdersResponse
|
var activeOrders WsActiveOrdersResponse
|
||||||
err := common.JSONDecode(resp.Raw, &activeOrders)
|
err := json.Unmarshal(resp.Raw, &activeOrders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.Websocket.DataHandler <- activeOrders
|
h.Websocket.DataHandler <- activeOrders
|
||||||
case "report":
|
case "report":
|
||||||
var reportData WsReportResponse
|
var reportData WsReportResponse
|
||||||
err := common.JSONDecode(resp.Raw, &reportData)
|
err := json.Unmarshal(resp.Raw, &reportData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
@@ -182,21 +182,21 @@ func (h *HitBTC) handleCommandResponses(resp wshandler.WebsocketResponse, init c
|
|||||||
switch resultType["reportType"].(string) {
|
switch resultType["reportType"].(string) {
|
||||||
case "new":
|
case "new":
|
||||||
var response WsSubmitOrderSuccessResponse
|
var response WsSubmitOrderSuccessResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.Websocket.DataHandler <- response
|
h.Websocket.DataHandler <- response
|
||||||
case "canceled":
|
case "canceled":
|
||||||
var response WsCancelOrderResponse
|
var response WsCancelOrderResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.Websocket.DataHandler <- response
|
h.Websocket.DataHandler <- response
|
||||||
case "replaced":
|
case "replaced":
|
||||||
var response WsReplaceOrderResponse
|
var response WsReplaceOrderResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
@@ -210,14 +210,14 @@ func (h *HitBTC) handleCommandResponses(resp wshandler.WebsocketResponse, init c
|
|||||||
data := resultType[0].(map[string]interface{})
|
data := resultType[0].(map[string]interface{})
|
||||||
if _, ok := data["clientOrderId"]; ok {
|
if _, ok := data["clientOrderId"]; ok {
|
||||||
var response WsActiveOrdersResponse
|
var response WsActiveOrdersResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.Websocket.DataHandler <- response
|
h.Websocket.DataHandler <- response
|
||||||
} else if _, ok := data["available"]; ok {
|
} else if _, ok := data["available"]; ok {
|
||||||
var response WsGetTradingBalanceResponse
|
var response WsGetTradingBalanceResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsSubmitOrderSuccessResponse
|
var response WsSubmitOrderSuccessResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsCancelOrderResponse
|
var response WsCancelOrderResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsReplaceOrderResponse
|
var response WsReplaceOrderResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsActiveOrdersResponse
|
var response WsActiveOrdersResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsGetTradingBalanceResponse
|
var response WsGetTradingBalanceResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsGetCurrenciesResponse
|
var response WsGetCurrenciesResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsGetSymbolsResponse
|
var response WsGetSymbolsResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
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)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
var response WsGetTradesResponse
|
var response WsGetTradesResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%v %v", h.Name, err)
|
return nil, fmt.Errorf("%v %v", h.Name, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package huobi
|
package huobi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -8,13 +9,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
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/orderbook"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||||
@@ -139,7 +138,7 @@ func (h *HUOBI) WsHandleData() {
|
|||||||
|
|
||||||
func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
||||||
var init WsAuthenticatedDataResponse
|
var init WsAuthenticatedDataResponse
|
||||||
err := common.JSONDecode(resp.Raw, &init)
|
err := json.Unmarshal(resp.Raw, &init)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -169,14 +168,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
|||||||
case strings.EqualFold(init.Op, authOp):
|
case strings.EqualFold(init.Op, authOp):
|
||||||
h.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
h.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
||||||
var response WsAuthenticatedDataResponse
|
var response WsAuthenticatedDataResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.Websocket.DataHandler <- response
|
h.Websocket.DataHandler <- response
|
||||||
case strings.EqualFold(init.Topic, "accounts"):
|
case strings.EqualFold(init.Topic, "accounts"):
|
||||||
var response WsAuthenticatedAccountsResponse
|
var response WsAuthenticatedAccountsResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
@@ -184,14 +183,14 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
|||||||
case strings.Contains(init.Topic, "orders") &&
|
case strings.Contains(init.Topic, "orders") &&
|
||||||
strings.Contains(init.Topic, "update"):
|
strings.Contains(init.Topic, "update"):
|
||||||
var response WsAuthenticatedOrdersUpdateResponse
|
var response WsAuthenticatedOrdersUpdateResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
h.Websocket.DataHandler <- response
|
h.Websocket.DataHandler <- response
|
||||||
case strings.Contains(init.Topic, "orders"):
|
case strings.Contains(init.Topic, "orders"):
|
||||||
var response WsAuthenticatedOrdersResponse
|
var response WsAuthenticatedOrdersResponse
|
||||||
err := common.JSONDecode(resp.Raw, &response)
|
err := json.Unmarshal(resp.Raw, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
}
|
}
|
||||||
@@ -201,7 +200,7 @@ func (h *HUOBI) wsHandleAuthenticatedData(resp WsMessage) {
|
|||||||
|
|
||||||
func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
||||||
var init WsResponse
|
var init WsResponse
|
||||||
err := common.JSONDecode(resp.Raw, &init)
|
err := json.Unmarshal(resp.Raw, &init)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -228,7 +227,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
|||||||
switch {
|
switch {
|
||||||
case strings.Contains(init.Channel, "depth"):
|
case strings.Contains(init.Channel, "depth"):
|
||||||
var depth WsDepth
|
var depth WsDepth
|
||||||
err := common.JSONDecode(resp.Raw, &depth)
|
err := json.Unmarshal(resp.Raw, &depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -243,7 +242,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
|||||||
|
|
||||||
case strings.Contains(init.Channel, "kline"):
|
case strings.Contains(init.Channel, "kline"):
|
||||||
var kline WsKline
|
var kline WsKline
|
||||||
err := common.JSONDecode(resp.Raw, &kline)
|
err := json.Unmarshal(resp.Raw, &kline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -263,7 +262,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
|||||||
}
|
}
|
||||||
case strings.Contains(init.Channel, "trade.detail"):
|
case strings.Contains(init.Channel, "trade.detail"):
|
||||||
var trade WsTrade
|
var trade WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &trade)
|
err := json.Unmarshal(resp.Raw, &trade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -278,7 +277,7 @@ func (h *HUOBI) wsHandleMarketData(resp WsMessage) {
|
|||||||
}
|
}
|
||||||
case strings.Contains(init.Channel, "detail"):
|
case strings.Contains(init.Channel, "detail"):
|
||||||
var ticker WsTick
|
var ticker WsTick
|
||||||
err := common.JSONDecode(resp.Raw, &ticker)
|
err := json.Unmarshal(resp.Raw, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Websocket.DataHandler <- err
|
h.Websocket.DataHandler <- err
|
||||||
return
|
return
|
||||||
@@ -457,7 +456,7 @@ func (h *HUOBI) wsGetAccountsList(pair currency.Pair) (*WsAuthenticatedAccountsL
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsAuthenticatedAccountsListResponse
|
var response WsAuthenticatedAccountsListResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
return &response, err
|
return &response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,7 +484,7 @@ func (h *HUOBI) wsGetOrdersList(accountID int64, pair currency.Pair) (*WsAuthent
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsAuthenticatedOrdersResponse
|
var response WsAuthenticatedOrdersResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
return &response, err
|
return &response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,6 +510,6 @@ func (h *HUOBI) wsGetOrderDetails(orderID string) (*WsAuthenticatedOrderDetailRe
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsAuthenticatedOrderDetailResponse
|
var response WsAuthenticatedOrderDetailResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
return &response, err
|
return &response, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if params != nil {
|
if params != nil {
|
||||||
PayloadJSON, err = common.JSONEncode(req)
|
PayloadJSON, err = json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -317,7 +317,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
|
|||||||
|
|
||||||
n := i.Requester.GetNonce(true).String()
|
n := i.Requester.GetNonce(true).String()
|
||||||
timestamp := strconv.FormatInt(time.Now().UnixNano()/1000000, 10)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method, path string, params map[str
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(intermediary, &errCheck)
|
err = json.Unmarshal(intermediary, &errCheck)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if errCheck.Code != 0 || errCheck.Description != "" {
|
if errCheck.Code != 0 || errCheck.Description != "" {
|
||||||
return fmt.Errorf("itbit.go SendAuthRequest error code: %d description: %s",
|
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
|
// GetFee returns an estimate of fee based on type of transaction
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package kraken
|
package kraken
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||||
@@ -116,14 +116,14 @@ func (k *Kraken) WsHandleData() {
|
|||||||
k.Websocket.TrafficAlert <- struct{}{}
|
k.Websocket.TrafficAlert <- struct{}{}
|
||||||
// event response handling
|
// event response handling
|
||||||
var eventResponse WebsocketEventResponse
|
var eventResponse WebsocketEventResponse
|
||||||
err = common.JSONDecode(resp.Raw, &eventResponse)
|
err = json.Unmarshal(resp.Raw, &eventResponse)
|
||||||
if err == nil && eventResponse.Event != "" {
|
if err == nil && eventResponse.Event != "" {
|
||||||
k.WsHandleEventResponse(&eventResponse, resp.Raw)
|
k.WsHandleEventResponse(&eventResponse, resp.Raw)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Data response handling
|
// Data response handling
|
||||||
var dataResponse WebsocketDataResponse
|
var dataResponse WebsocketDataResponse
|
||||||
err = common.JSONDecode(resp.Raw, &dataResponse)
|
err = json.Unmarshal(resp.Raw, &dataResponse)
|
||||||
if err == nil && dataResponse[0].(float64) >= 0 {
|
if err == nil && dataResponse[0].(float64) >= 0 {
|
||||||
k.WsHandleDataResponse(dataResponse)
|
k.WsHandleDataResponse(dataResponse)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package lakebtc
|
package lakebtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -302,7 +302,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
|
|||||||
postData["id"] = 1
|
postData["id"] = 1
|
||||||
postData["params"] = strings.Split(params, ",")
|
postData["params"] = strings.Split(params, ",")
|
||||||
|
|
||||||
data, err := common.JSONEncode(postData)
|
data, err := json.Marshal(postData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package lakebtc
|
package lakebtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||||
@@ -141,7 +141,7 @@ func (l *LakeBTC) wsHandleIncomingData() {
|
|||||||
|
|
||||||
func (l *LakeBTC) processTrades(data, channel string) error {
|
func (l *LakeBTC) processTrades(data, channel string) error {
|
||||||
var tradeData WsTrades
|
var tradeData WsTrades
|
||||||
err := common.JSONDecode([]byte(data), &tradeData)
|
err := json.Unmarshal([]byte(data), &tradeData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ func (l *LakeBTC) processTrades(data, channel string) error {
|
|||||||
|
|
||||||
func (l *LakeBTC) processOrderbook(obUpdate, channel string) error {
|
func (l *LakeBTC) processOrderbook(obUpdate, channel string) error {
|
||||||
var update WsOrderbookUpdate
|
var update WsOrderbookUpdate
|
||||||
err := common.JSONDecode([]byte(obUpdate), &update)
|
err := json.Unmarshal([]byte(obUpdate), &update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ func (l *LakeBTC) getCurrencyFromChannel(channel string) currency.Pair {
|
|||||||
|
|
||||||
func (l *LakeBTC) processTicker(ticker string) error {
|
func (l *LakeBTC) processTicker(ticker string) error {
|
||||||
var tUpdate map[string]interface{}
|
var tUpdate map[string]interface{}
|
||||||
err := common.JSONDecode([]byte(ticker), &tUpdate)
|
err := json.Unmarshal([]byte(ticker), &tUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Websocket.DataHandler <- err
|
l.Websocket.DataHandler <- err
|
||||||
return 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
@@ -13,7 +13,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
"github.com/google/go-querystring/query"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
@@ -566,7 +565,7 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
|
|||||||
payload := []byte("")
|
payload := []byte("")
|
||||||
|
|
||||||
if data != nil {
|
if data != nil {
|
||||||
payload, err = common.JSONEncode(data)
|
payload, err = json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("sendHTTPRequest: Unable to JSON request")
|
return errors.New("sendHTTPRequest: Unable to JSON request")
|
||||||
}
|
}
|
||||||
@@ -617,7 +616,7 @@ func (o *OKGroup) SendHTTPRequest(httpMethod, requestType, requestPath string, d
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(intermediary, &errCap)
|
err = json.Unmarshal(intermediary, &errCap)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if errCap.ErrorMessage != "" {
|
if errCap.ErrorMessage != "" {
|
||||||
return fmt.Errorf("error: %v", 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
|
// SetCheckVarDefaults sets main variables that will be used in requests because
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package okgroup
|
package okgroup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
@@ -11,7 +12,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -226,7 +226,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
|
|||||||
}
|
}
|
||||||
o.Websocket.TrafficAlert <- struct{}{}
|
o.Websocket.TrafficAlert <- struct{}{}
|
||||||
var dataResponse WebsocketDataResponse
|
var dataResponse WebsocketDataResponse
|
||||||
err = common.JSONDecode(resp.Raw, &dataResponse)
|
err = json.Unmarshal(resp.Raw, &dataResponse)
|
||||||
if err == nil && dataResponse.Table != "" {
|
if err == nil && dataResponse.Table != "" {
|
||||||
if len(dataResponse.Data) > 0 {
|
if len(dataResponse.Data) > 0 {
|
||||||
o.WsHandleDataResponse(&dataResponse)
|
o.WsHandleDataResponse(&dataResponse)
|
||||||
@@ -234,7 +234,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var errorResponse WebsocketErrorResponse
|
var errorResponse WebsocketErrorResponse
|
||||||
err = common.JSONDecode(resp.Raw, &errorResponse)
|
err = json.Unmarshal(resp.Raw, &errorResponse)
|
||||||
if err == nil && errorResponse.ErrorCode > 0 {
|
if err == nil && errorResponse.ErrorCode > 0 {
|
||||||
if o.Verbose {
|
if o.Verbose {
|
||||||
log.Debugf(log.ExchangeSys,
|
log.Debugf(log.ExchangeSys,
|
||||||
@@ -247,7 +247,7 @@ func (o *OKGroup) WsHandleData(wg *sync.WaitGroup) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var eventResponse WebsocketEventResponse
|
var eventResponse WebsocketEventResponse
|
||||||
err = common.JSONDecode(resp.Raw, &eventResponse)
|
err = json.Unmarshal(resp.Raw, &eventResponse)
|
||||||
if err == nil && eventResponse.Event != "" {
|
if err == nil && eventResponse.Event != "" {
|
||||||
if eventResponse.Event == "login" {
|
if eventResponse.Event == "login" {
|
||||||
o.Websocket.SetCanUseAuthenticatedEndpoints(eventResponse.Success)
|
o.Websocket.SetCanUseAuthenticatedEndpoints(eventResponse.Success)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package poloniex
|
package poloniex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -425,7 +426,7 @@ func TestWsHandleAccountData(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for i := range jsons {
|
for i := range jsons {
|
||||||
var result [][]interface{}
|
var result [][]interface{}
|
||||||
err := common.JSONDecode([]byte(jsons[i]), &result)
|
err := json.Unmarshal([]byte(jsons[i]), &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package poloniex
|
package poloniex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -95,7 +95,7 @@ func (p *Poloniex) WsHandleData() {
|
|||||||
}
|
}
|
||||||
p.Websocket.TrafficAlert <- struct{}{}
|
p.Websocket.TrafficAlert <- struct{}{}
|
||||||
var result interface{}
|
var result interface{}
|
||||||
err = common.JSONDecode(resp.Raw, &result)
|
err = json.Unmarshal(resp.Raw, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Websocket.DataHandler <- err
|
p.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package request
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -329,7 +330,7 @@ func (r *Requester) DoRequest(req *http.Request, path string, body io.Reader, re
|
|||||||
}
|
}
|
||||||
|
|
||||||
if result != nil {
|
if result != nil {
|
||||||
return common.JSONDecode(contents, result)
|
return json.Unmarshal(contents, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -15,7 +16,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
"github.com/thrasher-corp/gocryptotrader/config"
|
||||||
log "github.com/thrasher-corp/gocryptotrader/logger"
|
log "github.com/thrasher-corp/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
@@ -653,7 +653,7 @@ func (w *WebsocketConnection) SendMessage(data interface{}) error {
|
|||||||
if !w.IsConnected() {
|
if !w.IsConnected() {
|
||||||
return fmt.Errorf("%v cannot send message to a disconnected websocket", w.ExchangeName)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -14,7 +15,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||||
)
|
)
|
||||||
@@ -666,7 +666,7 @@ func readMessages(wc *WebsocketConnection, t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var incoming testResponse
|
var incoming testResponse
|
||||||
err = common.JSONDecode(resp.Raw, &incoming)
|
err = json.Unmarshal(resp.Raw, &incoming)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
@@ -339,7 +338,7 @@ func (z *ZB) SendAuthenticatedHTTPRequest(httpMethod string, params url.Values,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = common.JSONDecode(intermediary, &errCap)
|
err = json.Unmarshal(intermediary, &errCap)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if errCap.Code > 1000 {
|
if errCap.Code > 1000 {
|
||||||
return fmt.Errorf("sendAuthenticatedHTTPRequest error code: %d message %s",
|
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
|
// GetFee returns an estimate of fee based on type of transaction
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package zb
|
package zb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -506,10 +507,10 @@ func TestGetDepositAddress(t *testing.T) {
|
|||||||
// TestZBInvalidJSON ZB sends poorly formed JSON. this tests the JSON fixer
|
// TestZBInvalidJSON ZB sends poorly formed JSON. this tests the JSON fixer
|
||||||
// Then JSON decode it to test if successful
|
// Then JSON decode it to test if successful
|
||||||
func TestZBInvalidJSON(t *testing.T) {
|
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"}`
|
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(json))
|
fixedJSON := z.wsFixInvalidJSON([]byte(data))
|
||||||
var response WsGetSubUserListResponse
|
var response WsGetSubUserListResponse
|
||||||
err := common.JSONDecode(fixedJSON, &response)
|
err := json.Unmarshal(fixedJSON, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -517,10 +518,10 @@ func TestZBInvalidJSON(t *testing.T) {
|
|||||||
t.Fatal("Expected extracted JSON USERID to equal 1337")
|
t.Fatal("Expected extracted JSON USERID to equal 1337")
|
||||||
}
|
}
|
||||||
|
|
||||||
json = `{"success":true,"code":1000,"channel":"createSubUserKey","message":"{"apiKey":"thisisnotareallykeyyousillybilly","apiSecret":"lol"}","no":"123"}`
|
data = `{"success":true,"code":1000,"channel":"createSubUserKey","message":"{"apiKey":"thisisnotareallykeyyousillybilly","apiSecret":"lol"}","no":"123"}`
|
||||||
fixedJSON = z.wsFixInvalidJSON([]byte(json))
|
fixedJSON = z.wsFixInvalidJSON([]byte(data))
|
||||||
var response2 WsRequestResponse
|
var response2 WsRequestResponse
|
||||||
err = common.JSONDecode(fixedJSON, &response2)
|
err = json.Unmarshal(fixedJSON, &response2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package zb
|
package zb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -64,7 +64,7 @@ func (z *ZB) WsHandleData() {
|
|||||||
z.Websocket.TrafficAlert <- struct{}{}
|
z.Websocket.TrafficAlert <- struct{}{}
|
||||||
fixedJSON := z.wsFixInvalidJSON(resp.Raw)
|
fixedJSON := z.wsFixInvalidJSON(resp.Raw)
|
||||||
var result Generic
|
var result Generic
|
||||||
err = common.JSONDecode(fixedJSON, &result)
|
err = json.Unmarshal(fixedJSON, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
z.Websocket.DataHandler <- err
|
z.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -80,7 +80,7 @@ func (z *ZB) WsHandleData() {
|
|||||||
switch {
|
switch {
|
||||||
case strings.Contains(result.Channel, "markets"):
|
case strings.Contains(result.Channel, "markets"):
|
||||||
var markets Markets
|
var markets Markets
|
||||||
err := common.JSONDecode(result.Data, &markets)
|
err := json.Unmarshal(result.Data, &markets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
z.Websocket.DataHandler <- err
|
z.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -89,7 +89,7 @@ func (z *ZB) WsHandleData() {
|
|||||||
case strings.Contains(result.Channel, "ticker"):
|
case strings.Contains(result.Channel, "ticker"):
|
||||||
cPair := strings.Split(result.Channel, "_")
|
cPair := strings.Split(result.Channel, "_")
|
||||||
var ticker WsTicker
|
var ticker WsTicker
|
||||||
err := common.JSONDecode(fixedJSON, &ticker)
|
err := json.Unmarshal(fixedJSON, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
z.Websocket.DataHandler <- err
|
z.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -111,7 +111,7 @@ func (z *ZB) WsHandleData() {
|
|||||||
|
|
||||||
case strings.Contains(result.Channel, "depth"):
|
case strings.Contains(result.Channel, "depth"):
|
||||||
var depth WsDepth
|
var depth WsDepth
|
||||||
err := common.JSONDecode(fixedJSON, &depth)
|
err := json.Unmarshal(fixedJSON, &depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
z.Websocket.DataHandler <- err
|
z.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -156,7 +156,7 @@ func (z *ZB) WsHandleData() {
|
|||||||
|
|
||||||
case strings.Contains(result.Channel, "trades"):
|
case strings.Contains(result.Channel, "trades"):
|
||||||
var trades WsTrades
|
var trades WsTrades
|
||||||
err := common.JSONDecode(fixedJSON, &trades)
|
err := json.Unmarshal(fixedJSON, &trades)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
z.Websocket.DataHandler <- err
|
z.Websocket.DataHandler <- err
|
||||||
continue
|
continue
|
||||||
@@ -252,7 +252,7 @@ func (z *ZB) Subscribe(channelToSubscribe wshandler.WebsocketChannelSubscription
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZB) wsGenerateSignature(request interface{}) string {
|
func (z *ZB) wsGenerateSignature(request interface{}) string {
|
||||||
jsonResponse, err := common.JSONEncode(request)
|
jsonResponse, err := json.Marshal(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(log.ExchangeSys, err)
|
log.Error(log.ExchangeSys, err)
|
||||||
return ""
|
return ""
|
||||||
@@ -296,7 +296,7 @@ func (z *ZB) wsAddSubUser(username, password string) (*WsGetSubUserListResponse,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var genericResponse Generic
|
var genericResponse Generic
|
||||||
err = common.JSONDecode(resp, &genericResponse)
|
err = json.Unmarshal(resp, &genericResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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])
|
return nil, fmt.Errorf("%v request failed, message: %v, error code: %v", z.Name, genericResponse.Message, wsErrCodes[genericResponse.Code])
|
||||||
}
|
}
|
||||||
var response WsGetSubUserListResponse
|
var response WsGetSubUserListResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ func (z *ZB) wsGetSubUserList() (*WsGetSubUserListResponse, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsGetSubUserListResponse
|
var response WsGetSubUserListResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ func (z *ZB) wsDoTransferFunds(pair currency.Code, amount float64, fromUserName,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsRequestResponse
|
var response WsRequestResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -391,7 +391,7 @@ func (z *ZB) wsCreateSubUserKey(assetPerm, entrustPerm, leverPerm, moneyPerm boo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsRequestResponse
|
var response WsRequestResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -421,7 +421,7 @@ func (z *ZB) wsSubmitOrder(pair currency.Pair, amount, price float64, tradeType
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsSubmitOrderResponse
|
var response WsSubmitOrderResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -449,7 +449,7 @@ func (z *ZB) wsCancelOrder(pair currency.Pair, orderID int64) (*WsCancelOrderRes
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsCancelOrderResponse
|
var response WsCancelOrderResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -477,7 +477,7 @@ func (z *ZB) wsGetOrder(pair currency.Pair, orderID int64) (*WsGetOrderResponse,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsGetOrderResponse
|
var response WsGetOrderResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -505,7 +505,7 @@ func (z *ZB) wsGetOrders(pair currency.Pair, pageIndex, tradeType int64) (*WsGet
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsGetOrdersResponse
|
var response WsGetOrdersResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -534,7 +534,7 @@ func (z *ZB) wsGetOrdersIgnoreTradeType(pair currency.Pair, pageIndex, pageSize
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsGetOrdersIgnoreTradeTypeResponse
|
var response WsGetOrdersIgnoreTradeTypeResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -561,7 +561,7 @@ func (z *ZB) wsGetAccountInfoRequest() (*WsGetAccountInfoResponse, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response WsGetAccountInfoResponse
|
var response WsGetAccountInfoResponse
|
||||||
err = common.JSONDecode(resp, &response)
|
err = json.Unmarshal(resp, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,31 @@ import (
|
|||||||
"sync"
|
"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
|
// Config holds configuration settings loaded from bot config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -72,24 +94,3 @@ type multiWriter struct {
|
|||||||
writers []io.Writer
|
writers []io.Writer
|
||||||
mu sync.RWMutex
|
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
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user