mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 15:10:54 +00:00
Implement Logger (#228)
* Added new base logger * updated example and test configs * updated exchange helpers restful router & server * logPath is now passed to the logger to remove dependency on common package * updated everything besides exchanges to use new logger * alphapoint to bitmex done * updated bitmex bitstamp bittrex btcc and also performance changes to logger * btcmarkets coinbase coinut exmo gateio wrappers updated * gateio and gemini logger updated * hitbtc huobi itbit & kraken updated * All exchanges updatd * return correct error for disabled websocket * don't disconnect client on invalid json * updated router internal logging * log.Fatal to t.Error for tests * Changed from fatal to error failure to set maxprocs * output ANSI codes for everything but windows for now due to lack of windows support * added error handling to logger and unit tests * clear wording on print -> log.print * added benchmark test * cleaned up import sections * Updated logger based on PR requests (added default config options on failure/setting errors) * ah this should fix travici enc config issue * Load entire config and clear out logging to hopefully fix travisci issue * wording & test error handling * fixed formatting issues based on feedback * fixed formatting issues based on feedback * changed CheckDir to use mkdirall instead of mkdir and other changes based on feedback
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
|||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -29,6 +28,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Vars for common.go operations
|
// Vars for common.go operations
|
||||||
@@ -390,7 +391,7 @@ func SendHTTPRequest(method, path string, headers map[string]string, body io.Rea
|
|||||||
// on failure.
|
// on failure.
|
||||||
func SendHTTPGetRequest(url string, jsonDecode, isVerbose bool, result interface{}) error {
|
func SendHTTPGetRequest(url string, jsonDecode, isVerbose bool, result interface{}) error {
|
||||||
if isVerbose {
|
if isVerbose {
|
||||||
log.Println("Raw URL: ", url)
|
log.Debugf("Raw URL: %s", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
initialiseHTTPClient()
|
initialiseHTTPClient()
|
||||||
@@ -410,7 +411,7 @@ func SendHTTPGetRequest(url string, jsonDecode, isVerbose bool, result interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if isVerbose {
|
if isVerbose {
|
||||||
log.Println("Raw Resp: ", string(contents[:]))
|
log.Debugf("Raw Resp: %s", string(contents[:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
@@ -639,8 +640,8 @@ func CheckDir(dir string, create bool) error {
|
|||||||
return fmt.Errorf("directory %s does not exist. Err: %s", dir, err)
|
return fmt.Errorf("directory %s does not exist. Err: %s", dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Directory %s does not exist.. creating.", dir)
|
log.Warnf("Directory %s does not exist.. creating.", dir)
|
||||||
err = os.Mkdir(dir, 0777)
|
err = os.MkdirAll(dir, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create dir. Err: %s", err)
|
return fmt.Errorf("failed to create dir. Err: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package base
|
package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IComm is the main interface array across the communication packages
|
// IComm is the main interface array across the communication packages
|
||||||
@@ -33,7 +33,7 @@ func (c IComm) Setup() {
|
|||||||
if c[i].IsEnabled() && !c[i].IsConnected() {
|
if c[i].IsEnabled() && !c[i].IsConnected() {
|
||||||
err := c[i].Connect()
|
err := c[i].Connect()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Communications: %s failed to connect. Err: %s", c[i].GetName(), err)
|
log.Errorf("Communications: %s failed to connect. Err: %s", c[i].GetName(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ func (c IComm) PushEvent(event Event) {
|
|||||||
if c[i].IsEnabled() && c[i].IsConnected() {
|
if c[i].IsEnabled() && c[i].IsConnected() {
|
||||||
err := c[i].PushEvent(event)
|
err := c[i].PushEvent(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Communications error - PushEvent() in package %s with %v",
|
log.Errorf("Communications error - PushEvent() in package %s with %v",
|
||||||
c[i].GetName(), event)
|
c[i].GetName(), event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,12 +58,12 @@ func (c IComm) GetEnabledCommunicationMediums() {
|
|||||||
var count int
|
var count int
|
||||||
for i := range c {
|
for i := range c {
|
||||||
if c[i].IsEnabled() && c[i].IsConnected() {
|
if c[i].IsEnabled() && c[i].IsConnected() {
|
||||||
log.Printf("Communications: Medium %s is enabled.", c[i].GetName())
|
log.Debugf("Communications: Medium %s is enabled.", c[i].GetName())
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
log.Println("Communications: No communication mediums are enabled.")
|
log.Warnf("Communications: No communication mediums are enabled.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -16,6 +15,7 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/communications/base"
|
"github.com/thrasher-/gocryptotrader/communications/base"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// const declares main slack url and commands that will be supported on client
|
// const declares main slack url and commands that will be supported on client
|
||||||
@@ -154,13 +154,13 @@ func (s *Slack) NewConnection() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Printf("%s [%s] connected to %s [%s] \nWebsocket URL: %s.\n",
|
log.Debugf("%s [%s] connected to %s [%s] \nWebsocket URL: %s.\n",
|
||||||
s.Details.Self.Name,
|
s.Details.Self.Name,
|
||||||
s.Details.Self.ID,
|
s.Details.Self.ID,
|
||||||
s.Details.Team.Domain,
|
s.Details.Team.Domain,
|
||||||
s.Details.Team.ID,
|
s.Details.Team.ID,
|
||||||
s.Details.URL)
|
s.Details.URL)
|
||||||
log.Printf("Slack channels: %s", s.GetChannelsString())
|
log.Debugf("Slack channels: %s", s.GetChannelsString())
|
||||||
}
|
}
|
||||||
|
|
||||||
s.TargetChannelID, err = s.GetIDByName(s.TargetChannel)
|
s.TargetChannelID, err = s.GetIDByName(s.TargetChannel)
|
||||||
@@ -197,14 +197,14 @@ func (s *Slack) WebsocketReader() {
|
|||||||
for {
|
for {
|
||||||
_, resp, err := s.WebsocketConn.ReadMessage()
|
_, resp, err := s.WebsocketConn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var data WebsocketResponse
|
var data WebsocketResponse
|
||||||
|
|
||||||
err = common.JSONDecode(resp, &data)
|
err = common.JSONDecode(resp, &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,10 +239,10 @@ func (s *Slack) WebsocketReader() {
|
|||||||
|
|
||||||
case "pong":
|
case "pong":
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Println("Pong received from server")
|
log.Debugf("Pong received from server")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Println(string(resp))
|
log.Debugf(string(resp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ func (s *Slack) handlePresenceChange(resp []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Printf("Presence change. User %s [%s] changed status to %s\n",
|
log.Debugf("Presence change. User %s [%s] changed status to %s\n",
|
||||||
s.GetUsernameByID(pres.User),
|
s.GetUsernameByID(pres.User),
|
||||||
pres.User, pres.Presence)
|
pres.User, pres.Presence)
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Printf("Msg received by %s [%s] with text: %s\n",
|
log.Debugf("Msg received by %s [%s] with text: %s\n",
|
||||||
s.GetUsernameByID(msg.User),
|
s.GetUsernameByID(msg.User),
|
||||||
msg.User, msg.Text)
|
msg.User, msg.Text)
|
||||||
}
|
}
|
||||||
@@ -283,7 +283,7 @@ func (s *Slack) handleMessageResponse(resp []byte, data WebsocketResponse) error
|
|||||||
func (s *Slack) handleErrorResponse(data WebsocketResponse) error {
|
func (s *Slack) handleErrorResponse(data WebsocketResponse) error {
|
||||||
if data.Error.Msg == "Socket URL has expired" {
|
if data.Error.Msg == "Socket URL has expired" {
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Println("Slack websocket URL has expired.. Reconnecting")
|
log.Debugf("Slack websocket URL has expired.. Reconnecting")
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.WebsocketConn == nil {
|
if s.WebsocketConn == nil {
|
||||||
@@ -291,7 +291,7 @@ func (s *Slack) handleErrorResponse(data WebsocketResponse) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := s.WebsocketConn.Close(); err != nil {
|
if err := s.WebsocketConn.Close(); err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ReconnectURL = ""
|
s.ReconnectURL = ""
|
||||||
@@ -303,7 +303,7 @@ func (s *Slack) handleErrorResponse(data WebsocketResponse) error {
|
|||||||
|
|
||||||
func (s *Slack) handleHelloResponse(data WebsocketResponse) {
|
func (s *Slack) handleHelloResponse(data WebsocketResponse) {
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Println("Websocket connected successfully.")
|
log.Debugln("Websocket connected successfully.")
|
||||||
}
|
}
|
||||||
s.Connected = true
|
s.Connected = true
|
||||||
go s.WebsocketKeepAlive()
|
go s.WebsocketKeepAlive()
|
||||||
@@ -320,7 +320,7 @@ func (s *Slack) handleReconnectResponse(resp []byte) error {
|
|||||||
}
|
}
|
||||||
s.ReconnectURL = recURL.URL
|
s.ReconnectURL = recURL.URL
|
||||||
if s.Verbose {
|
if s.Verbose {
|
||||||
log.Printf("Reconnect URL set to %s\n", s.ReconnectURL)
|
log.Debugf("Reconnect URL set to %s\n", s.ReconnectURL)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -332,7 +332,7 @@ func (s *Slack) WebsocketKeepAlive() {
|
|||||||
for {
|
for {
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
if err := s.WebsocketSend("ping", ""); err != nil {
|
if err := s.WebsocketSend("ping", ""); err != nil {
|
||||||
log.Println("slack WebsocketKeepAlive() error", err)
|
log.Debugf("slack WebsocketKeepAlive() error %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/communications/base"
|
"github.com/thrasher-/gocryptotrader/communications/base"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -87,7 +87,7 @@ func (t *Telegram) PollerStart() {
|
|||||||
for {
|
for {
|
||||||
resp, err := t.GetUpdates()
|
resp, err := t.GetUpdates()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range resp.Result {
|
for i := range resp.Result {
|
||||||
@@ -95,7 +95,7 @@ func (t *Telegram) PollerStart() {
|
|||||||
if string(resp.Result[i].Message.Text[0]) == "/" {
|
if string(resp.Result[i].Message.Text[0]) == "/" {
|
||||||
err = t.HandleMessages(resp.Result[i].Message.Text, resp.Result[i].Message.From.ID)
|
err = t.HandleMessages(resp.Result[i].Message.Text, resp.Result[i].Message.From.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.Offset = resp.Result[i].UpdateID
|
t.Offset = resp.Result[i].UpdateID
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -18,6 +17,7 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
"github.com/thrasher-/gocryptotrader/portfolio"
|
"github.com/thrasher-/gocryptotrader/portfolio"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,6 +99,7 @@ type Config struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
EncryptConfig int `json:"encryptConfig"`
|
EncryptConfig int `json:"encryptConfig"`
|
||||||
GlobalHTTPTimeout time.Duration `json:"globalHTTPTimeout"`
|
GlobalHTTPTimeout time.Duration `json:"globalHTTPTimeout"`
|
||||||
|
Logging log.Logging `json:"logging"`
|
||||||
Currency CurrencyConfig `json:"currencyConfig"`
|
Currency CurrencyConfig `json:"currencyConfig"`
|
||||||
Communications CommunicationsConfig `json:"communications"`
|
Communications CommunicationsConfig `json:"communications"`
|
||||||
Portfolio portfolio.Base `json:"portfolioAddresses"`
|
Portfolio portfolio.Base `json:"portfolioAddresses"`
|
||||||
@@ -521,7 +522,7 @@ func (c *Config) CheckPairConsistency(exchName string) error {
|
|||||||
|
|
||||||
if len(pairs) == 0 {
|
if len(pairs) == 0 {
|
||||||
exchCfg.EnabledPairs = pair.RandomPairFromPairs(availPairs).Pair().String()
|
exchCfg.EnabledPairs = pair.RandomPairFromPairs(availPairs).Pair().String()
|
||||||
log.Printf("Exchange %s: No enabled pairs found in available pairs, randomly added %v\n", exchName, exchCfg.EnabledPairs)
|
log.Debugf("Exchange %s: No enabled pairs found in available pairs, randomly added %v\n", exchName, exchCfg.EnabledPairs)
|
||||||
} else {
|
} else {
|
||||||
exchCfg.EnabledPairs = common.JoinStrings(pair.PairsToStringArray(pairs), ",")
|
exchCfg.EnabledPairs = common.JoinStrings(pair.PairsToStringArray(pairs), ",")
|
||||||
}
|
}
|
||||||
@@ -531,7 +532,7 @@ func (c *Config) CheckPairConsistency(exchName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Exchange %s: Removing enabled pair(s) %v from enabled pairs as it isn't an available pair", exchName, pair.PairsToStringArray(pairsRemoved))
|
log.Debugf("Exchange %s: Removing enabled pair(s) %v from enabled pairs as it isn't an available pair", exchName, pair.PairsToStringArray(pairsRemoved))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,11 +731,11 @@ func (c *Config) CheckExchangeConfigValues() error {
|
|||||||
if exch.AuthenticatedAPISupport { // non-fatal error
|
if exch.AuthenticatedAPISupport { // non-fatal error
|
||||||
if exch.APIKey == "" || exch.APISecret == "" || exch.APIKey == "Key" || exch.APISecret == "Secret" {
|
if exch.APIKey == "" || exch.APISecret == "" || exch.APIKey == "Key" || exch.APISecret == "Secret" {
|
||||||
c.Exchanges[i].AuthenticatedAPISupport = false
|
c.Exchanges[i].AuthenticatedAPISupport = false
|
||||||
log.Printf(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
log.Warn(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
||||||
} else if exch.Name == "ITBIT" || exch.Name == "Bitstamp" || exch.Name == "COINUT" || exch.Name == "CoinbasePro" {
|
} else if exch.Name == "ITBIT" || exch.Name == "Bitstamp" || exch.Name == "COINUT" || exch.Name == "CoinbasePro" {
|
||||||
if exch.ClientID == "" || exch.ClientID == "ClientID" {
|
if exch.ClientID == "" || exch.ClientID == "ClientID" {
|
||||||
c.Exchanges[i].AuthenticatedAPISupport = false
|
c.Exchanges[i].AuthenticatedAPISupport = false
|
||||||
log.Printf(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
log.Warn(WarningExchangeAuthAPIDefaultOrEmptyValues, exch.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -742,18 +743,18 @@ func (c *Config) CheckExchangeConfigValues() error {
|
|||||||
lastUpdated := common.UnixTimestampToTime(exch.PairsLastUpdated)
|
lastUpdated := common.UnixTimestampToTime(exch.PairsLastUpdated)
|
||||||
lastUpdated = lastUpdated.AddDate(0, 0, configPairsLastUpdatedWarningThreshold)
|
lastUpdated = lastUpdated.AddDate(0, 0, configPairsLastUpdatedWarningThreshold)
|
||||||
if lastUpdated.Unix() <= time.Now().Unix() {
|
if lastUpdated.Unix() <= time.Now().Unix() {
|
||||||
log.Printf(WarningPairsLastUpdatedThresholdExceeded, exch.Name, configPairsLastUpdatedWarningThreshold)
|
log.Warn(WarningPairsLastUpdatedThresholdExceeded, exch.Name, configPairsLastUpdatedWarningThreshold)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if exch.HTTPTimeout <= 0 {
|
if exch.HTTPTimeout <= 0 {
|
||||||
log.Printf("Exchange %s HTTP Timeout value not set, defaulting to %v.", exch.Name, configDefaultHTTPTimeout)
|
log.Warnf("Exchange %s HTTP Timeout value not set, defaulting to %v.", exch.Name, configDefaultHTTPTimeout)
|
||||||
c.Exchanges[i].HTTPTimeout = configDefaultHTTPTimeout
|
c.Exchanges[i].HTTPTimeout = configDefaultHTTPTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
err := c.CheckPairConsistency(exch.Name)
|
err := c.CheckPairConsistency(exch.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Exchange %s: CheckPairConsistency error: %s", exch.Name, err)
|
log.Errorf("Exchange %s: CheckPairConsistency error: %s", exch.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(exch.BankAccounts) == 0 {
|
if len(exch.BankAccounts) == 0 {
|
||||||
@@ -853,13 +854,13 @@ func (c *Config) CheckCurrencyConfigValues() error {
|
|||||||
for i := range c.Currency.ForexProviders {
|
for i := range c.Currency.ForexProviders {
|
||||||
if c.Currency.ForexProviders[i].Enabled == true {
|
if c.Currency.ForexProviders[i].Enabled == true {
|
||||||
if c.Currency.ForexProviders[i].APIKey == "Key" {
|
if c.Currency.ForexProviders[i].APIKey == "Key" {
|
||||||
log.Printf("WARNING -- %s forex provider API key not set. Please set this in your config.json file", c.Currency.ForexProviders[i].Name)
|
log.Warnf("%s forex provider API key not set. Please set this in your config.json file", c.Currency.ForexProviders[i].Name)
|
||||||
c.Currency.ForexProviders[i].Enabled = false
|
c.Currency.ForexProviders[i].Enabled = false
|
||||||
c.Currency.ForexProviders[i].PrimaryProvider = false
|
c.Currency.ForexProviders[i].PrimaryProvider = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if c.Currency.ForexProviders[i].APIKeyLvl == -1 && c.Currency.ForexProviders[i].Name != "CurrencyConverter" {
|
if c.Currency.ForexProviders[i].APIKeyLvl == -1 && c.Currency.ForexProviders[i].Name != "CurrencyConverter" {
|
||||||
log.Printf("WARNING -- %s APIKey Level not set, functions limited. Please set this in your config.json file",
|
log.Warnf("%s APIKey Level not set, functions limited. Please set this in your config.json file",
|
||||||
c.Currency.ForexProviders[i].Name)
|
c.Currency.ForexProviders[i].Name)
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
@@ -872,7 +873,7 @@ func (c *Config) CheckCurrencyConfigValues() error {
|
|||||||
c.Currency.ForexProviders[x].Enabled = true
|
c.Currency.ForexProviders[x].Enabled = true
|
||||||
c.Currency.ForexProviders[x].APIKey = ""
|
c.Currency.ForexProviders[x].APIKey = ""
|
||||||
c.Currency.ForexProviders[x].PrimaryProvider = true
|
c.Currency.ForexProviders[x].PrimaryProvider = true
|
||||||
log.Printf("WARNING -- No forex providers set, defaulting to free provider CurrencyConverterAPI.")
|
log.Warn("No forex providers set, defaulting to free provider CurrencyConverterAPI.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -959,6 +960,44 @@ func (c *Config) RetrieveConfigCurrencyPairs(enabledOnly bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckLoggerConfig checks to see logger values are present and valid in config
|
||||||
|
// if not creates a default instance of the logger
|
||||||
|
func (c *Config) CheckLoggerConfig() (err error) {
|
||||||
|
m.Lock()
|
||||||
|
defer m.Unlock()
|
||||||
|
|
||||||
|
// check if enabled is nil or level is a blank string
|
||||||
|
if c.Logging.Enabled == nil || c.Logging.Level == "" {
|
||||||
|
// Creates a new pointer to bool and sets it as true
|
||||||
|
t := func(t bool) *bool { return &t }(true)
|
||||||
|
|
||||||
|
log.Warn("Missing or invalid config settings using safe defaults")
|
||||||
|
|
||||||
|
// Set logger to safe defaults
|
||||||
|
|
||||||
|
c.Logging = log.Logging{
|
||||||
|
Enabled: t,
|
||||||
|
Level: "DEBUG|INFO|WARN|ERROR|FATAL",
|
||||||
|
ColourOutput: false,
|
||||||
|
File: "debug.txt",
|
||||||
|
Rotate: false,
|
||||||
|
}
|
||||||
|
log.Logger = &c.Logging
|
||||||
|
} else {
|
||||||
|
log.Logger = &c.Logging
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(c.Logging.File) > 0 {
|
||||||
|
logPath := path.Join(common.GetDefaultDataDir(runtime.GOOS), "logs")
|
||||||
|
err = common.CheckDir(logPath, true)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.LogPath = logPath
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// GetFilePath returns the desired config file or the default config file name
|
// GetFilePath returns the desired config file or the default config file name
|
||||||
// based on if the application is being run under test or normal mode.
|
// based on if the application is being run under test or normal mode.
|
||||||
func GetFilePath(file string) (string, error) {
|
func GetFilePath(file string) (string, error) {
|
||||||
@@ -996,13 +1035,13 @@ func GetFilePath(file string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
log.Printf("Renamed old config file %s to %s", oldDirs[x], newDirs[0])
|
log.Debugf("Renamed old config file %s to %s", oldDirs[x], newDirs[0])
|
||||||
} else {
|
} else {
|
||||||
err = os.Rename(oldDirs[x], newDirs[1])
|
err = os.Rename(oldDirs[x], newDirs[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
log.Printf("Renamed old config file %s to %s", oldDirs[x], newDirs[1])
|
log.Debugf("Renamed old config file %s to %s", oldDirs[x], newDirs[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1086,7 +1125,7 @@ func (c *Config) ReadConfig(configPath string) error {
|
|||||||
}
|
}
|
||||||
key, err := PromptForConfigKey(IsInitialSetup)
|
key, err := PromptForConfigKey(IsInitialSetup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("PromptForConfigKey err: %s", err)
|
log.Errorf("PromptForConfigKey err: %s", err)
|
||||||
errCounter++
|
errCounter++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1095,7 +1134,7 @@ func (c *Config) ReadConfig(configPath string) error {
|
|||||||
f = append(f, file...)
|
f = append(f, file...)
|
||||||
data, err := DecryptConfigFile(f, key)
|
data, err := DecryptConfigFile(f, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("DecryptConfigFile err: %s", err)
|
log.Errorf("DecryptConfigFile err: %s", err)
|
||||||
errCounter++
|
errCounter++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1103,7 +1142,7 @@ func (c *Config) ReadConfig(configPath string) error {
|
|||||||
err = ConfirmConfigJSON(data, &c)
|
err = ConfirmConfigJSON(data, &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errCounter < configMaxAuthFailres {
|
if errCounter < configMaxAuthFailres {
|
||||||
log.Printf("Invalid password.")
|
log.Errorf("Invalid password.")
|
||||||
}
|
}
|
||||||
errCounter++
|
errCounter++
|
||||||
continue
|
continue
|
||||||
@@ -1164,7 +1203,7 @@ func (c *Config) CheckConfig() error {
|
|||||||
if c.Webserver.Enabled {
|
if c.Webserver.Enabled {
|
||||||
err = c.CheckWebserverConfigValues()
|
err = c.CheckWebserverConfigValues()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(fmt.Errorf(ErrCheckingConfigValues, err))
|
log.Errorf(ErrCheckingConfigValues, err)
|
||||||
c.Webserver.Enabled = false
|
c.Webserver.Enabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1175,7 +1214,7 @@ func (c *Config) CheckConfig() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.GlobalHTTPTimeout <= 0 {
|
if c.GlobalHTTPTimeout <= 0 {
|
||||||
log.Printf("Global HTTP Timeout value not set, defaulting to %v.", configDefaultHTTPTimeout)
|
log.Warnf("Global HTTP Timeout value not set, defaulting to %v.", configDefaultHTTPTimeout)
|
||||||
c.GlobalHTTPTimeout = configDefaultHTTPTimeout
|
c.GlobalHTTPTimeout = configDefaultHTTPTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
"golang.org/x/crypto/scrypt"
|
"golang.org/x/crypto/scrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetCurrencyConfig(t *testing.T) {
|
func TestGetCurrencyConfig(t *testing.T) {
|
||||||
@@ -905,3 +906,21 @@ func TestUpdateConfig(t *testing.T) {
|
|||||||
t.Fatalf("Test failed. Cryptocurrencies should have been repopulated")
|
t.Fatalf("Test failed. Cryptocurrencies should have been repopulated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCheckLoggerConfig(t *testing.T) {
|
||||||
|
c := GetConfig()
|
||||||
|
err := c.LoadConfig(ConfigTestFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
c.Logging = log.Logging{}
|
||||||
|
err = c.CheckLoggerConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to create default logger reason: %v", err)
|
||||||
|
}
|
||||||
|
c.LoadConfig(ConfigTestFile)
|
||||||
|
err = c.CheckLoggerConfig()
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to create logger with user settings: reason: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,13 @@
|
|||||||
"name": "Skynet",
|
"name": "Skynet",
|
||||||
"encryptConfig": 0,
|
"encryptConfig": 0,
|
||||||
"globalHTTPTimeout": 15000000000,
|
"globalHTTPTimeout": 15000000000,
|
||||||
|
"logging": {
|
||||||
|
"enabled": true,
|
||||||
|
"file": "debug.txt",
|
||||||
|
"colour": false,
|
||||||
|
"level": "DEBUG|WARN|INFO|ERROR|FATAL",
|
||||||
|
"rotate": false
|
||||||
|
},
|
||||||
"currencyConfig": {
|
"currencyConfig": {
|
||||||
"forexProviders": [
|
"forexProviders": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package currency
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -38,7 +38,7 @@ func SetDefaults() {
|
|||||||
FXProviders = forexprovider.NewDefaultFXProvider()
|
FXProviders = forexprovider.NewDefaultFXProvider()
|
||||||
err := SeedCurrencyData(DefaultCurrencies)
|
err := SeedCurrencyData(DefaultCurrencies)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to seed currency data. Err: %s", err)
|
log.Errorf("Failed to seed currency data. Err: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package base
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IFXProviders contains an array of foreign exchange interfaces
|
// IFXProviders contains an array of foreign exchange interfaces
|
||||||
@@ -24,12 +25,12 @@ func (fxp IFXProviders) GetCurrencyData(baseCurrency, symbols string) (map[strin
|
|||||||
if fxp[x].IsPrimaryProvider() && fxp[x].IsEnabled() {
|
if fxp[x].IsPrimaryProvider() && fxp[x].IsEnabled() {
|
||||||
rates, err := fxp[x].GetRates(baseCurrency, symbols)
|
rates, err := fxp[x].GetRates(baseCurrency, symbols)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
for y := range fxp {
|
for y := range fxp {
|
||||||
if !fxp[y].IsPrimaryProvider() && fxp[x].IsEnabled() {
|
if !fxp[y].IsPrimaryProvider() && fxp[x].IsEnabled() {
|
||||||
rates, err = fxp[y].GetRates(baseCurrency, symbols)
|
rates, err = fxp[y].GetRates(baseCurrency, symbols)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return rates, nil
|
return rates, nil
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ package currencyconverter
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// const declarations consist of endpoints
|
// const declarations consist of endpoints
|
||||||
@@ -61,7 +61,7 @@ func (c *CurrencyConverter) GetRates(baseCurrency, symbols string) (map[string]f
|
|||||||
batch := completedStrings[i : i+2]
|
batch := completedStrings[i : i+2]
|
||||||
result, err := c.ConvertMany(batch)
|
result, err := c.ConvertMany(batch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get batch err: %s", err)
|
log.Errorf("Failed to get batch err: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for k, v := range result {
|
for k, v := range result {
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
package forexprovider
|
package forexprovider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
||||||
currencyconverter "github.com/thrasher-/gocryptotrader/currency/forexprovider/currencyconverterapi"
|
currencyconverter "github.com/thrasher-/gocryptotrader/currency/forexprovider/currencyconverterapi"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider/currencylayer"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider/currencylayer"
|
||||||
fixer "github.com/thrasher-/gocryptotrader/currency/forexprovider/fixer.io"
|
fixer "github.com/thrasher-/gocryptotrader/currency/forexprovider/fixer.io"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider/openexchangerates"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider/openexchangerates"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ForexProviders is an array of foreign exchange interfaces
|
// ForexProviders is an array of foreign exchange interfaces
|
||||||
@@ -61,7 +60,7 @@ func StartFXService(fxProviders []base.Settings) *ForexProviders {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(fxp.IFXProviders) == 0 {
|
if len(fxp.IFXProviders) == 0 {
|
||||||
log.Fatal("No foreign exchange providers enabled")
|
log.Error("No foreign exchange providers enabled")
|
||||||
}
|
}
|
||||||
return fxp
|
return fxp
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package events
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -121,7 +121,7 @@ func (e *Event) ExecuteAction() bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Event triggered: %s", e.String())
|
log.Debugf("Event triggered: %s", e.String())
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ func CheckEvents() {
|
|||||||
if !event.Executed {
|
if !event.Executed {
|
||||||
success := event.CheckCondition()
|
success := event.CheckCondition()
|
||||||
if success {
|
if success {
|
||||||
log.Printf(
|
log.Debugf(
|
||||||
"Event %d triggered on %s successfully.\n", event.ID,
|
"Event %d triggered on %s successfully.\n", event.ID,
|
||||||
event.Exchange,
|
event.Exchange,
|
||||||
)
|
)
|
||||||
|
|||||||
14
exchange.go
14
exchange.go
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
@@ -36,6 +35,7 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/exchanges/wex"
|
"github.com/thrasher-/gocryptotrader/exchanges/wex"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/yobit"
|
"github.com/thrasher-/gocryptotrader/exchanges/yobit"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/zb"
|
"github.com/thrasher-/gocryptotrader/exchanges/zb"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// vars related to exchange functions
|
// vars related to exchange functions
|
||||||
@@ -86,7 +86,7 @@ func ReloadExchange(name string) error {
|
|||||||
|
|
||||||
e := GetExchangeByName(nameLower)
|
e := GetExchangeByName(nameLower)
|
||||||
e.Setup(exchCfg)
|
e.Setup(exchCfg)
|
||||||
log.Printf("%s exchange reloaded successfully.\n", name)
|
log.Debugf("%s exchange reloaded successfully.\n", name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,13 +231,13 @@ func SetupExchanges() {
|
|||||||
if CheckExchangeExists(exch.Name) {
|
if CheckExchangeExists(exch.Name) {
|
||||||
e := GetExchangeByName(exch.Name)
|
e := GetExchangeByName(exch.Name)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
log.Println(ErrExchangeNotFound)
|
log.Errorf("%s", ErrExchangeNotFound)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ReloadExchange(exch.Name)
|
err := ReloadExchange(exch.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("ReloadExchange %s failed: %s", exch.Name, err)
|
log.Errorf("ReloadExchange %s failed: %s", exch.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,16 +249,16 @@ func SetupExchanges() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if !exch.Enabled {
|
if !exch.Enabled {
|
||||||
log.Printf("%s: Exchange support: Disabled", exch.Name)
|
log.Debugf("%s: Exchange support: Disabled", exch.Name)
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
err := LoadExchange(exch.Name, true, &wg)
|
err := LoadExchange(exch.Name, true, &wg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("LoadExchange %s failed: %s", exch.Name, err)
|
log.Errorf("LoadExchange %s failed: %s", exch.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf(
|
log.Debugf(
|
||||||
"%s: Exchange support: Enabled (Authenticated API support: %s - Verbose mode: %s).\n",
|
"%s: Exchange support: Enabled (Authenticated API support: %s - Verbose mode: %s).\n",
|
||||||
exch.Name,
|
exch.Name,
|
||||||
common.IsEnabled(exch.AuthenticatedAPISupport),
|
common.IsEnabled(exch.AuthenticatedAPISupport),
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
)
|
)
|
||||||
@@ -191,7 +190,7 @@ func (a *Alphapoint) CreateAccount(firstName, lastName, email, phone, password s
|
|||||||
|
|
||||||
err := a.SendAuthenticatedHTTPRequest("POST", alphapointCreateAccount, request, &response)
|
err := a.SendAuthenticatedHTTPRequest("POST", alphapointCreateAccount, request, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
return fmt.Errorf("Alphapoint Error - CreateAccount HTTPRequest - reason: %s", err)
|
||||||
}
|
}
|
||||||
if !response.IsAccepted {
|
if !response.IsAccepted {
|
||||||
return errors.New(response.RejectReason)
|
return errors.New(response.RejectReason)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package alphapoint
|
package alphapoint
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -20,25 +20,25 @@ func (a *Alphapoint) WebsocketClient() {
|
|||||||
a.WebsocketConn, _, err = Dialer.Dial(a.WebsocketURL, http.Header{})
|
a.WebsocketConn, _, err = Dialer.Dial(a.WebsocketURL, http.Header{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Unable to connect to Websocket. Error: %s\n", a.Name, err)
|
log.Errorf("%s Unable to connect to Websocket. Error: %s\n", a.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Verbose {
|
if a.Verbose {
|
||||||
log.Printf("%s Connected to Websocket.\n", a.Name)
|
log.Debugf("%s Connected to Websocket.\n", a.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.WebsocketConn.WriteMessage(websocket.TextMessage, []byte(`{"messageType": "logon"}`))
|
err = a.WebsocketConn.WriteMessage(websocket.TextMessage, []byte(`{"messageType": "logon"}`))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for a.Enabled {
|
for a.Enabled {
|
||||||
msgType, resp, err := a.WebsocketConn.ReadMessage()
|
msgType, resp, err := a.WebsocketConn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func (a *Alphapoint) WebsocketClient() {
|
|||||||
msgType := MsgType{}
|
msgType := MsgType{}
|
||||||
err := common.JSONDecode(resp, &msgType)
|
err := common.JSONDecode(resp, &msgType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,13 +60,13 @@ func (a *Alphapoint) WebsocketClient() {
|
|||||||
ticker := WebsocketTicker{}
|
ticker := WebsocketTicker{}
|
||||||
err = common.JSONDecode(resp, &ticker)
|
err = common.JSONDecode(resp, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a.WebsocketConn.Close()
|
a.WebsocketConn.Close()
|
||||||
log.Printf("%s Websocket client disconnected.", a.Name)
|
log.Debugf("%s Websocket client disconnected.", a.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,16 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -274,7 +273,7 @@ func (a *ANX) GetOrderList(isActiveOrdersOnly bool) ([]OrderResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.ResultCode != "OK" {
|
if response.ResultCode != "OK" {
|
||||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||||
return nil, errors.New(response.ResultCode)
|
return nil, errors.New(response.ResultCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,7 +299,7 @@ func (a *ANX) OrderInfo(orderID string) (OrderResponse, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.ResultCode != "OK" {
|
if response.ResultCode != "OK" {
|
||||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||||
return OrderResponse{}, errors.New(response.ResultCode)
|
return OrderResponse{}, errors.New(response.ResultCode)
|
||||||
}
|
}
|
||||||
return response.Order, nil
|
return response.Order, nil
|
||||||
@@ -331,7 +330,7 @@ func (a *ANX) Send(currency, address, otp, amount string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.ResultCode != "OK" {
|
if response.ResultCode != "OK" {
|
||||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||||
return "", errors.New(response.ResultCode)
|
return "", errors.New(response.ResultCode)
|
||||||
}
|
}
|
||||||
return response.TransactionID, nil
|
return response.TransactionID, nil
|
||||||
@@ -357,7 +356,7 @@ func (a *ANX) CreateNewSubAccount(currency, name string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.ResultCode != "OK" {
|
if response.ResultCode != "OK" {
|
||||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||||
return "", errors.New(response.ResultCode)
|
return "", errors.New(response.ResultCode)
|
||||||
}
|
}
|
||||||
return response.SubAccount, nil
|
return response.SubAccount, nil
|
||||||
@@ -392,7 +391,7 @@ func (a *ANX) GetDepositAddressByCurrency(currency, name string, new bool) (stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.ResultCode != "OK" {
|
if response.ResultCode != "OK" {
|
||||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||||
return "", errors.New(response.ResultCode)
|
return "", errors.New(response.ResultCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,7 +431,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
if a.Verbose {
|
if a.Verbose {
|
||||||
log.Printf("Request JSON: %s\n", PayloadJSON)
|
log.Debugf("Request JSON: %s\n", PayloadJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
hmac := common.GetHMAC(common.HashSHA512, []byte(path+string("\x00")+string(PayloadJSON)), []byte(a.APISecret))
|
hmac := common.GetHMAC(common.HashSHA512, []byte(path+string("\x00")+string(PayloadJSON)), []byte(a.APISecret))
|
||||||
@@ -497,7 +496,7 @@ func (a *ANX) GetAccountInformation() (AccountInformation, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if response.ResultCode != "OK" {
|
if response.ResultCode != "OK" {
|
||||||
log.Printf("Response code is not OK: %s\n", response.ResultCode)
|
log.Errorf("Response code is not OK: %s\n", response.ResultCode)
|
||||||
return response, errors.New(response.ResultCode)
|
return response, errors.New(response.ResultCode)
|
||||||
}
|
}
|
||||||
return response, nil
|
return response, nil
|
||||||
@@ -520,7 +519,7 @@ func (a *ANX) CheckAPIWithdrawPermission() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !apiAllowsWithdraw {
|
if !apiAllowsWithdraw {
|
||||||
log.Printf("API key is missing withdrawal permissions")
|
log.Warn("API key is missing withdrawal permissions")
|
||||||
}
|
}
|
||||||
|
|
||||||
return apiAllowsWithdraw, nil
|
return apiAllowsWithdraw, nil
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package anx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the ANX go routine
|
// Start starts the ANX go routine
|
||||||
@@ -25,13 +25,13 @@ func (a *ANX) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the ANX wrapper
|
// Run implements the ANX wrapper
|
||||||
func (a *ANX) Run() {
|
func (a *ANX) Run() {
|
||||||
if a.Verbose {
|
if a.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", a.GetName(), a.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", a.GetName(), a.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", a.GetName(), len(a.EnabledPairs), a.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", a.GetName(), len(a.EnabledPairs), a.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := a.GetTradablePairs()
|
exchangeProducts, err := a.GetTradablePairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", a.GetName())
|
log.Debugf("%s Failed to get available symbols.\n", a.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(a.EnabledPairs, "_") || !common.StringDataContains(a.AvailablePairs, "_") {
|
if !common.StringDataContains(a.EnabledPairs, "_") || !common.StringDataContains(a.AvailablePairs, "_") {
|
||||||
@@ -40,16 +40,16 @@ func (a *ANX) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"BTC_USD,BTC_HKD,BTC_EUR,BTC_CAD,BTC_AUD,BTC_SGD,BTC_JPY,BTC_GBP,BTC_NZD,LTC_BTC,DOG_EBTC,STR_BTC,XRP_BTC"}
|
enabledPairs := []string{"BTC_USD,BTC_HKD,BTC_EUR,BTC_CAD,BTC_AUD,BTC_SGD,BTC_JPY,BTC_GBP,BTC_NZD,LTC_BTC,DOG_EBTC,STR_BTC,XRP_BTC"}
|
||||||
log.Println("WARNING: Enabled pairs for ANX reset due to config upgrade, please enable the ones you would like again.")
|
log.Warn("Enabled pairs for ANX reset due to config upgrade, please enable the ones you would like again.")
|
||||||
|
|
||||||
err = a.UpdateCurrencies(enabledPairs, true, true)
|
err = a.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", a.GetName())
|
log.Errorf("%s Failed to get config.\n", a.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = a.UpdateCurrencies(exchangeProducts, false, forceUpgrade)
|
err = a.UpdateCurrencies(exchangeProducts, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", a.GetName())
|
log.Errorf("%s Failed to get config.\n", a.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Binance is the overarching type across the Bithumb package
|
// Binance is the overarching type across the Bithumb package
|
||||||
@@ -609,7 +609,7 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
|
|||||||
headers["X-MBX-APIKEY"] = b.APIKey
|
headers["X-MBX-APIKEY"] = b.APIKey
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("sent path: \n%s\n", path)
|
log.Debugf("sent path: \n%s\n", path)
|
||||||
}
|
}
|
||||||
path = common.EncodeURLValues(path, params)
|
path = common.EncodeURLValues(path, params)
|
||||||
|
|
||||||
@@ -741,7 +741,6 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string
|
|||||||
return resp.ID, nil
|
return resp.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//GetDepositAddressForCurrency retrieves the wallet address for a given currency
|
//GetDepositAddressForCurrency retrieves the wallet address for a given currency
|
||||||
func (b *Binance) GetDepositAddressForCurrency(currency string) error {
|
func (b *Binance) GetDepositAddressForCurrency(currency string) error {
|
||||||
path := fmt.Sprintf("%s%s", b.APIUrl, depositAddress)
|
path := fmt.Sprintf("%s%s", b.APIUrl, depositAddress)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package binance
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the OKEX go routine
|
// Start starts the OKEX go routine
|
||||||
@@ -26,7 +26,7 @@ func (b *Binance) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the OKEX wrapper
|
// Run implements the OKEX wrapper
|
||||||
func (b *Binance) Run() {
|
func (b *Binance) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n%s polling delay: %ds.\n%s %d currencies enabled: %s.\n",
|
log.Debugf("%s Websocket: %s. (url: %s).\n%s polling delay: %ds.\n%s %d currencies enabled: %s.\n",
|
||||||
b.GetName(),
|
b.GetName(),
|
||||||
common.IsEnabled(b.Websocket.IsEnabled()),
|
common.IsEnabled(b.Websocket.IsEnabled()),
|
||||||
b.Websocket.GetWebsocketURL(),
|
b.Websocket.GetWebsocketURL(),
|
||||||
@@ -39,7 +39,7 @@ func (b *Binance) Run() {
|
|||||||
|
|
||||||
symbols, err := b.GetExchangeValidCurrencyPairs()
|
symbols, err := b.GetExchangeValidCurrencyPairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get exchange info.\n", b.GetName())
|
log.Errorf("%s Failed to get exchange info.\n", b.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(b.EnabledPairs, "-") ||
|
if !common.StringDataContains(b.EnabledPairs, "-") ||
|
||||||
@@ -49,16 +49,16 @@ func (b *Binance) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"BTC-USDT"}
|
enabledPairs := []string{"BTC-USDT"}
|
||||||
log.Println("WARNING: Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
|
log.Warn("Available pairs for Binance reset due to config upgrade, please enable the ones you would like again")
|
||||||
|
|
||||||
err = b.UpdateCurrencies(enabledPairs, true, true)
|
err = b.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", b.GetName())
|
log.Errorf("%s Failed to get config.\n", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = b.UpdateCurrencies(symbols, false, forceUpgrade)
|
err = b.UpdateCurrencies(symbols, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", b.GetName())
|
log.Errorf("%s Failed to get config.\n", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package bitfinex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -906,7 +906,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
|
|||||||
}
|
}
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("Request JSON: %s\n", PayloadJSON)
|
log.Debugf("Request JSON: %s\n", PayloadJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
PayloadBase64 := common.Base64Encode(PayloadJSON)
|
PayloadBase64 := common.Base64Encode(PayloadJSON)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package bitfinex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -13,8 +12,9 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -116,7 +116,7 @@ func (b *Bitfinex) WsAddSubscriptionChannel(chanID int, channel, pair string) {
|
|||||||
b.WebsocketSubdChannels[chanID] = chanInfo
|
b.WebsocketSubdChannels[chanID] = chanInfo
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Subscribed to Channel: %s Pair: %s ChannelID: %d\n",
|
log.Debugf("%s Subscribed to Channel: %s Pair: %s ChannelID: %d\n",
|
||||||
b.GetName(),
|
b.GetName(),
|
||||||
channel,
|
channel,
|
||||||
pair,
|
pair,
|
||||||
@@ -160,7 +160,7 @@ func (b *Bitfinex) WsConnect() error {
|
|||||||
|
|
||||||
if hs.Event == "info" {
|
if hs.Event == "info" {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Connected to Websocket.\n", b.GetName())
|
log.Debugf("%s Connected to Websocket.\n", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package bitfinex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Bitfinex go routine
|
// Start starts the Bitfinex go routine
|
||||||
@@ -27,18 +27,18 @@ func (b *Bitfinex) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Bitfinex wrapper
|
// Run implements the Bitfinex wrapper
|
||||||
func (b *Bitfinex) Run() {
|
func (b *Bitfinex) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
log.Debugf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := b.GetSymbols()
|
exchangeProducts, err := b.GetSymbols()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", b.GetName())
|
||||||
} else {
|
} else {
|
||||||
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available symbols.\n", b.GetName())
|
log.Errorf("%s Failed to update available symbols.\n", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package bitflyer
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -14,6 +13,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package bitflyer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Bitflyer go routine
|
// Start starts the Bitflyer go routine
|
||||||
@@ -24,9 +24,9 @@ func (b *Bitflyer) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Bitflyer wrapper
|
// Run implements the Bitflyer wrapper
|
||||||
func (b *Bitflyer) Run() {
|
func (b *Bitflyer) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
log.Debugf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -17,6 +16,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package bithumb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the OKEX go routine
|
// Start starts the OKEX go routine
|
||||||
@@ -24,18 +24,18 @@ func (b *Bithumb) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the OKEX wrapper
|
// Run implements the OKEX wrapper
|
||||||
func (b *Bithumb) Run() {
|
func (b *Bithumb) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := b.GetTradingPairs()
|
exchangeProducts, err := b.GetTradingPairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", b.GetName())
|
||||||
} else {
|
} else {
|
||||||
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available symbols.\n", b.GetName())
|
log.Errorf("%s Failed to update available symbols.\n", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -14,6 +13,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bitmex is the overarching type across this package
|
// Bitmex is the overarching type across this package
|
||||||
|
|||||||
@@ -3,18 +3,17 @@ package bitmex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -98,7 +97,7 @@ func (b *Bitmex) WsConnector() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("Successfully connected to Bitmex %s at time: %s Limit: %d",
|
log.Debugf("Successfully connected to Bitmex %s at time: %s Limit: %d",
|
||||||
welcomeResp.Info,
|
welcomeResp.Info,
|
||||||
welcomeResp.Timestamp,
|
welcomeResp.Timestamp,
|
||||||
welcomeResp.Limit.Remaining)
|
welcomeResp.Limit.Remaining)
|
||||||
@@ -187,14 +186,14 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
quickCapture := make(map[string]interface{})
|
quickCapture := make(map[string]interface{})
|
||||||
err := common.JSONDecode(resp.Raw, &quickCapture)
|
err := common.JSONDecode(resp.Raw, &quickCapture)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var respError WebsocketErrorResponse
|
var respError WebsocketErrorResponse
|
||||||
if _, ok := quickCapture["status"]; ok {
|
if _, ok := quickCapture["status"]; ok {
|
||||||
err = common.JSONDecode(resp.Raw, &respError)
|
err = common.JSONDecode(resp.Raw, &respError)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
b.Websocket.DataHandler <- errors.New(respError.Error)
|
b.Websocket.DataHandler <- errors.New(respError.Error)
|
||||||
continue
|
continue
|
||||||
@@ -204,16 +203,16 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
var decodedResp WebsocketSubscribeResp
|
var decodedResp WebsocketSubscribeResp
|
||||||
err := common.JSONDecode(resp.Raw, &decodedResp)
|
err := common.JSONDecode(resp.Raw, &decodedResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if decodedResp.Success {
|
if decodedResp.Success {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
if len(quickCapture) == 3 {
|
if len(quickCapture) == 3 {
|
||||||
log.Printf("Bitmex Websocket: Successfully subscribed to %s",
|
log.Debugf("Bitmex Websocket: Successfully subscribed to %s",
|
||||||
decodedResp.Subscribe)
|
decodedResp.Subscribe)
|
||||||
} else {
|
} else {
|
||||||
log.Println("Bitmex Websocket: Successfully authenticated websocket connection")
|
log.Debugf("Bitmex Websocket: Successfully authenticated websocket connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@@ -226,7 +225,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
var decodedResp WebsocketMainResponse
|
var decodedResp WebsocketMainResponse
|
||||||
err := common.JSONDecode(resp.Raw, &decodedResp)
|
err := common.JSONDecode(resp.Raw, &decodedResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch decodedResp.Table {
|
switch decodedResp.Table {
|
||||||
@@ -234,20 +233,20 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
var orderbooks OrderBookData
|
var orderbooks OrderBookData
|
||||||
err = common.JSONDecode(resp.Raw, &orderbooks)
|
err = common.JSONDecode(resp.Raw, &orderbooks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p := pair.NewCurrencyPairFromString(orderbooks.Data[0].Symbol)
|
p := pair.NewCurrencyPairFromString(orderbooks.Data[0].Symbol)
|
||||||
err = b.processOrderbook(orderbooks.Data, orderbooks.Action, p, "CONTRACT")
|
err = b.processOrderbook(orderbooks.Data, orderbooks.Action, p, "CONTRACT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case bitmexWSTrade:
|
case bitmexWSTrade:
|
||||||
var trades TradeData
|
var trades TradeData
|
||||||
err = common.JSONDecode(resp.Raw, &trades)
|
err = common.JSONDecode(resp.Raw, &trades)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if trades.Action == bitmexActionInitialData {
|
if trades.Action == bitmexActionInitialData {
|
||||||
@@ -257,7 +256,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
for _, trade := range trades.Data {
|
for _, trade := range trades.Data {
|
||||||
timestamp, err := time.Parse(time.RFC3339, trade.Timestamp)
|
timestamp, err := time.Parse(time.RFC3339, trade.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Websocket.DataHandler <- exchange.TradeData{
|
b.Websocket.DataHandler <- exchange.TradeData{
|
||||||
@@ -276,7 +275,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
|
|
||||||
err = common.JSONDecode(resp.Raw, &announcement)
|
err = common.JSONDecode(resp.Raw, &announcement)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if announcement.Action == bitmexActionInitialData {
|
if announcement.Action == bitmexActionInitialData {
|
||||||
@@ -286,7 +285,7 @@ func (b *Bitmex) wsHandleIncomingData() {
|
|||||||
b.Websocket.DataHandler <- announcement.Data
|
b.Websocket.DataHandler <- announcement.Data
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Fatal("Bitmex websocket error: Table unknown -", decodedResp.Table)
|
log.Errorf("Bitmex websocket error: Table unknown - %s", decodedResp.Table)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package bitmex
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Bitmex go routine
|
// Start starts the Bitmex go routine
|
||||||
@@ -26,14 +26,14 @@ func (b *Bitmex) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Bitmex wrapper
|
// Run implements the Bitmex wrapper
|
||||||
func (b *Bitmex) Run() {
|
func (b *Bitmex) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()), b.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
marketInfo, err := b.GetActiveInstruments(GenericRequestParams{})
|
marketInfo, err := b.GetActiveInstruments(GenericRequestParams{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", b.GetName())
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var exchangeProducts []string
|
var exchangeProducts []string
|
||||||
@@ -43,7 +43,7 @@ func (b *Bitmex) Run() {
|
|||||||
|
|
||||||
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
err = b.UpdateCurrencies(exchangeProducts, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", b.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package bitstamp
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -13,9 +12,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -254,12 +254,12 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
|
|||||||
for _, x := range resp.Bids {
|
for _, x := range resp.Bids {
|
||||||
price, err := strconv.ParseFloat(x[0], 64)
|
price, err := strconv.ParseFloat(x[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(x[1], 64)
|
amount, err := strconv.ParseFloat(x[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
orderbook.Bids = append(orderbook.Bids, OrderbookBase{price, amount})
|
orderbook.Bids = append(orderbook.Bids, OrderbookBase{price, amount})
|
||||||
@@ -268,12 +268,12 @@ func (b *Bitstamp) GetOrderbook(currency string) (Orderbook, error) {
|
|||||||
for _, x := range resp.Asks {
|
for _, x := range resp.Asks {
|
||||||
price, err := strconv.ParseFloat(x[0], 64)
|
price, err := strconv.ParseFloat(x[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(x[1], 64)
|
amount, err := strconv.ParseFloat(x[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
orderbook.Asks = append(orderbook.Asks, OrderbookBase{price, amount})
|
orderbook.Asks = append(orderbook.Asks, OrderbookBase{price, amount})
|
||||||
@@ -605,7 +605,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url
|
|||||||
}
|
}
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Println("Sending POST request to " + path)
|
log.Debugf("Sending POST request to " + path)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package bitstamp
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/toorop/go-pusher"
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
|
pusher "github.com/toorop/go-pusher"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WebsocketConn defins a pusher websocket connection
|
// WebsocketConn defins a pusher websocket connection
|
||||||
@@ -78,7 +78,7 @@ func (b *Bitstamp) WsConnect() error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
if b.Websocket.GetProxyAddress() != "" {
|
if b.Websocket.GetProxyAddress() != "" {
|
||||||
log.Println("bistamp_websocket.go warning - set proxy address error: proxy not supported")
|
log.Warn("bitstamp_websocket.go warning - set proxy address error: proxy not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
b.WebsocketConn.Client, err = pusher.NewClient(BitstampPusherKey)
|
b.WebsocketConn.Client, err = pusher.NewClient(BitstampPusherKey)
|
||||||
@@ -147,7 +147,7 @@ func (b *Bitstamp) WsConnect() error {
|
|||||||
strings.ToLower(p.Pair().String())))
|
strings.ToLower(p.Pair().String())))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
return fmt.Errorf("%s Websocket Trade subscription error: %s",
|
return fmt.Errorf("%s Websocket Trade subscription error: %s",
|
||||||
b.GetName(),
|
b.GetName(),
|
||||||
err)
|
err)
|
||||||
@@ -157,7 +157,7 @@ func (b *Bitstamp) WsConnect() error {
|
|||||||
strings.ToLower(p.Pair().String())))
|
strings.ToLower(p.Pair().String())))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
return fmt.Errorf("%s Websocket Trade subscription error: %s",
|
return fmt.Errorf("%s Websocket Trade subscription error: %s",
|
||||||
b.GetName(),
|
b.GetName(),
|
||||||
err)
|
err)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package bitstamp
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -13,6 +12,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Bitstamp go routine
|
// Start starts the Bitstamp go routine
|
||||||
@@ -27,14 +27,14 @@ func (b *Bitstamp) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Bitstamp wrapper
|
// Run implements the Bitstamp wrapper
|
||||||
func (b *Bitstamp) Run() {
|
func (b *Bitstamp) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
log.Debugf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pairs, err := b.GetTradingPairs()
|
pairs, err := b.GetTradingPairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to get trading pairs. Err: %s", b.Name, err)
|
log.Errorf("%s failed to get trading pairs. Err: %s", b.Name, err)
|
||||||
} else {
|
} else {
|
||||||
var currencies []string
|
var currencies []string
|
||||||
for x := range pairs {
|
for x := range pairs {
|
||||||
@@ -46,7 +46,7 @@ func (b *Bitstamp) Run() {
|
|||||||
}
|
}
|
||||||
err = b.UpdateCurrencies(currencies, false, false)
|
err = b.UpdateCurrencies(currencies, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", b.Name)
|
log.Errorf("%s Failed to update available currencies.\n", b.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package bittrex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package bittrex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
@@ -11,6 +10,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Bittrex go routine
|
// Start starts the Bittrex go routine
|
||||||
@@ -25,13 +25,13 @@ func (b *Bittrex) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Bittrex wrapper
|
// Run implements the Bittrex wrapper
|
||||||
func (b *Bittrex) Run() {
|
func (b *Bittrex) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := b.GetMarkets()
|
exchangeProducts, err := b.GetMarkets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", b.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(b.EnabledPairs, "-") || !common.StringDataContains(b.AvailablePairs, "-") {
|
if !common.StringDataContains(b.EnabledPairs, "-") || !common.StringDataContains(b.AvailablePairs, "-") {
|
||||||
@@ -47,16 +47,16 @@ func (b *Bittrex) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"USDT-BTC"}
|
enabledPairs := []string{"USDT-BTC"}
|
||||||
log.Println("WARNING: Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
|
log.Warn("Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
|
||||||
|
|
||||||
err = b.UpdateCurrencies(enabledPairs, true, true)
|
err = b.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", b.GetName())
|
log.Errorf("%s Failed to get config.", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = b.UpdateCurrencies(currencies, false, forceUpgrade)
|
err = b.UpdateCurrencies(currencies, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", b.GetName())
|
log.Errorf("%s Failed to get config.", b.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package btcc
|
package btcc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package btcc
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -132,48 +132,37 @@ func (b *BTCC) WsHandleData() {
|
|||||||
case msgTypeHeartBeat:
|
case msgTypeHeartBeat:
|
||||||
|
|
||||||
case msgTypeGetActiveContracts:
|
case msgTypeGetActiveContracts:
|
||||||
log.Println("Active Contracts")
|
log.Debugf("Active Contracts: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeQuote:
|
case msgTypeQuote:
|
||||||
log.Println("Quotes")
|
log.Debugf("Quotes: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeLogin:
|
case msgTypeLogin:
|
||||||
log.Println("Login")
|
log.Debugf("Login: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeAccountInfo:
|
case msgTypeAccountInfo:
|
||||||
log.Println("Account info")
|
log.Debugf("Account info: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeExecReport:
|
case msgTypeExecReport:
|
||||||
log.Println("Exec Report")
|
log.Debugf("Exec Report: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypePlaceOrder:
|
case msgTypePlaceOrder:
|
||||||
log.Println("Place order")
|
log.Debugf("Place order: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeCancelAllOrders:
|
case msgTypeCancelAllOrders:
|
||||||
log.Println("Cancel All orders")
|
log.Debugf("Cancel All orders: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeCancelOrder:
|
case msgTypeCancelOrder:
|
||||||
log.Println("Cancel order")
|
log.Debugf("Cancel order: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeCancelReplaceOrder:
|
case msgTypeCancelReplaceOrder:
|
||||||
log.Println("Replace order")
|
log.Debugf("Replace order: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeGetAccountInfo:
|
case msgTypeGetAccountInfo:
|
||||||
log.Println("Account info")
|
log.Debugf("Account info: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeRetrieveOrder:
|
case msgTypeRetrieveOrder:
|
||||||
log.Println("Retrieve order")
|
log.Debugf("Retrieve order: %s", resp.Raw)
|
||||||
log.Fatal(string(resp.Raw))
|
|
||||||
|
|
||||||
case msgTypeGetTrades:
|
case msgTypeGetTrades:
|
||||||
var trades WsTrades
|
var trades WsTrades
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package btcc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
@@ -11,6 +10,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the BTCC go routine
|
// Start starts the BTCC go routine
|
||||||
@@ -25,18 +25,18 @@ func (b *BTCC) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the BTCC wrapper
|
// Run implements the BTCC wrapper
|
||||||
func (b *BTCC) Run() {
|
func (b *BTCC) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
log.Debugf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if common.StringDataContains(b.EnabledPairs, "CNY") || common.StringDataContains(b.AvailablePairs, "CNY") || common.StringDataContains(b.BaseCurrencies, "CNY") {
|
if common.StringDataContains(b.EnabledPairs, "CNY") || common.StringDataContains(b.AvailablePairs, "CNY") || common.StringDataContains(b.BaseCurrencies, "CNY") {
|
||||||
log.Println("WARNING: BTCC only supports BTCUSD now, upgrading available, enabled and base currencies to BTCUSD/USD")
|
log.Warn("BTCC only supports BTCUSD now, upgrading available, enabled and base currencies to BTCUSD/USD")
|
||||||
pairs := []string{"BTCUSD"}
|
pairs := []string{"BTCUSD"}
|
||||||
cfg := config.GetConfig()
|
cfg := config.GetConfig()
|
||||||
exchCfg, err := cfg.GetExchangeConfig(b.Name)
|
exchCfg, err := cfg.GetExchangeConfig(b.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to get exchange config. %s\n", b.Name, err)
|
log.Errorf("%s failed to get exchange config. %s\n", b.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,17 +47,17 @@ func (b *BTCC) Run() {
|
|||||||
|
|
||||||
err = b.UpdateCurrencies(pairs, false, true)
|
err = b.UpdateCurrencies(pairs, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update available currencies. %s\n", b.Name, err)
|
log.Errorf("%s failed to update available currencies. %s\n", b.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = b.UpdateCurrencies(pairs, true, true)
|
err = b.UpdateCurrencies(pairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update enabled currencies. %s\n", b.Name, err)
|
log.Errorf("%s failed to update enabled currencies. %s\n", b.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = cfg.UpdateExchangeConfig(exchCfg)
|
err = cfg.UpdateExchangeConfig(exchCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update config. %s\n", b.Name, err)
|
log.Errorf("%s failed to update config. %s\n", b.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -442,7 +442,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data interfa
|
|||||||
hmac := common.GetHMAC(common.HashSHA512, []byte(request), []byte(b.APISecret))
|
hmac := common.GetHMAC(common.HashSHA512, []byte(request), []byte(b.APISecret))
|
||||||
|
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("Sending %s request to URL %s with params %s\n", reqType, b.APIUrl+path, request)
|
log.Debugf("Sending %s request to URL %s with params %s\n", reqType, b.APIUrl+path, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ package btcmarkets
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the BTC Markets go routine
|
// Start starts the BTC Markets go routine
|
||||||
@@ -27,13 +26,13 @@ func (b *BTCMarkets) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the BTC Markets wrapper
|
// Run implements the BTC Markets wrapper
|
||||||
func (b *BTCMarkets) Run() {
|
func (b *BTCMarkets) Run() {
|
||||||
if b.Verbose {
|
if b.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
markets, err := b.GetMarkets()
|
markets, err := b.GetMarkets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to get active market. Err: %s", b.Name, err)
|
log.Errorf("%s failed to get active market. Err: %s", b.Name, err)
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(b.EnabledPairs, "-") || !common.StringDataContains(b.AvailablePairs, "-") {
|
if !common.StringDataContains(b.EnabledPairs, "-") || !common.StringDataContains(b.AvailablePairs, "-") {
|
||||||
@@ -47,16 +46,16 @@ func (b *BTCMarkets) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"BTC-AUD"}
|
enabledPairs := []string{"BTC-AUD"}
|
||||||
log.Println("WARNING: Available pairs for BTC Makrets reset due to config upgrade, please enable the pairs you would like again.")
|
log.Warn("Available pairs for BTC Makrets reset due to config upgrade, please enable the pairs you would like again.")
|
||||||
|
|
||||||
err = b.UpdateCurrencies(enabledPairs, true, true)
|
err = b.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update currencies. Err: %s", b.Name, err)
|
log.Errorf("%s failed to update currencies. Err: %s", b.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = b.UpdateCurrencies(currencies, false, forceUpgrade)
|
err = b.UpdateCurrencies(currencies, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update currencies. Err: %s", b.Name, err)
|
log.Errorf("%s failed to update currencies. Err: %s", b.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -14,9 +13,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -807,7 +807,7 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Verbose {
|
if c.Verbose {
|
||||||
log.Printf("Request JSON: %s\n", payload)
|
log.Debugf("Request JSON: %s\n", payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package coinbasepro
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -12,8 +11,9 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package coinbasepro
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the coinbasepro go routine
|
// Start starts the coinbasepro go routine
|
||||||
@@ -24,14 +24,14 @@ func (c *CoinbasePro) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the coinbasepro wrapper
|
// Run implements the coinbasepro wrapper
|
||||||
func (c *CoinbasePro) Run() {
|
func (c *CoinbasePro) Run() {
|
||||||
if c.Verbose {
|
if c.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinbaseproWebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinbaseproWebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", c.GetName(), c.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", c.GetName(), c.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", c.GetName(), len(c.EnabledPairs), c.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", c.GetName(), len(c.EnabledPairs), c.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := c.GetProducts()
|
exchangeProducts, err := c.GetProducts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available products.\n", c.GetName())
|
log.Errorf("%s Failed to get available products.\n", c.GetName())
|
||||||
} else {
|
} else {
|
||||||
currencies := []string{}
|
currencies := []string{}
|
||||||
for _, x := range exchangeProducts {
|
for _, x := range exchangeProducts {
|
||||||
@@ -41,7 +41,7 @@ func (c *CoinbasePro) Run() {
|
|||||||
}
|
}
|
||||||
err = c.UpdateCurrencies(currencies, false, false)
|
err = c.UpdateCurrencies(currencies, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", c.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", c.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
@@ -12,9 +11,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency"
|
"github.com/thrasher-/gocryptotrader/currency"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -352,7 +352,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Verbose {
|
if c.Verbose {
|
||||||
log.Printf("Request JSON: %s\n", payload)
|
log.Debugf("Request JSON: %s", payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package coinut
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@@ -11,8 +10,9 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const coinutWebsocketURL = "wss://wsapi.coinut.com"
|
const coinutWebsocketURL = "wss://wsapi.coinut.com"
|
||||||
|
|||||||
@@ -3,17 +3,16 @@ package coinut
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the COINUT go routine
|
// Start starts the COINUT go routine
|
||||||
@@ -28,14 +27,14 @@ func (c *COINUT) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the COINUT wrapper
|
// Run implements the COINUT wrapper
|
||||||
func (c *COINUT) Run() {
|
func (c *COINUT) Run() {
|
||||||
if c.Verbose {
|
if c.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinutWebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", c.GetName(), common.IsEnabled(c.Websocket.IsEnabled()), coinutWebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", c.GetName(), c.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", c.GetName(), c.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", c.GetName(), len(c.EnabledPairs), c.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", c.GetName(), len(c.EnabledPairs), c.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := c.GetInstruments()
|
exchangeProducts, err := c.GetInstruments()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available products.\n", c.GetName())
|
log.Debugf("%s Failed to get available products.\n", c.GetName())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ func (c *COINUT) Run() {
|
|||||||
|
|
||||||
err = c.UpdateCurrencies(currencies, false, false)
|
err = c.UpdateCurrencies(currencies, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", c.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", c.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package exchange
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -17,6 +16,7 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -654,7 +654,7 @@ func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) {
|
|||||||
result, err := common.Base64Decode(APISecret)
|
result, err := common.Base64Decode(APISecret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.AuthenticatedAPISupport = false
|
e.AuthenticatedAPISupport = false
|
||||||
log.Printf(warningBase64DecryptSecretKeyFailed, e.Name)
|
log.Warn(warningBase64DecryptSecretKeyFailed, e.Name)
|
||||||
}
|
}
|
||||||
e.APISecret = string(result)
|
e.APISecret = string(result)
|
||||||
} else {
|
} else {
|
||||||
@@ -728,13 +728,13 @@ func (e *Base) UpdateCurrencies(exchangeProducts []string, enabled, force bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if force {
|
if force {
|
||||||
log.Printf("%s forced update of %s pairs.", e.Name, updateType)
|
log.Debugf("%s forced update of %s pairs.", e.Name, updateType)
|
||||||
} else {
|
} else {
|
||||||
if len(newPairs) > 0 {
|
if len(newPairs) > 0 {
|
||||||
log.Printf("%s Updating pairs - New: %s.\n", e.Name, newPairs)
|
log.Debugf("%s Updating pairs - New: %s.\n", e.Name, newPairs)
|
||||||
}
|
}
|
||||||
if len(removedPairs) > 0 {
|
if len(removedPairs) > 0 {
|
||||||
log.Printf("%s Updating pairs - Removed: %s.\n", e.Name, removedPairs)
|
log.Debugf("%s Updating pairs - Removed: %s.\n", e.Name, removedPairs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,8 +167,7 @@ func (w *Websocket) Connect() error {
|
|||||||
defer w.m.Unlock()
|
defer w.m.Unlock()
|
||||||
|
|
||||||
if !w.IsEnabled() {
|
if !w.IsEnabled() {
|
||||||
return fmt.Errorf("exchange_websocket.go %s error - websocket disabled",
|
return errors.New(WebsocketNotEnabled)
|
||||||
w.GetName())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.connected {
|
if w.connected {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package exmo
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -16,6 +15,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -274,7 +274,7 @@ func (e *EXMO) GetRequiredAmount(pair string, amount float64) (RequiredAmount, e
|
|||||||
func (e *EXMO) GetCryptoDepositAddress() (map[string]string, error) {
|
func (e *EXMO) GetCryptoDepositAddress() (map[string]string, error) {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
err := e.SendAuthenticatedHTTPRequest("POST", exmoDepositAddress, url.Values{}, &result)
|
err := e.SendAuthenticatedHTTPRequest("POST", exmoDepositAddress, url.Values{}, &result)
|
||||||
log.Println(reflect.TypeOf(result).String())
|
log.Debug(reflect.TypeOf(result).String())
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Va
|
|||||||
hash := common.GetHMAC(common.HashSHA512, []byte(payload), []byte(e.APISecret))
|
hash := common.GetHMAC(common.HashSHA512, []byte(payload), []byte(e.APISecret))
|
||||||
|
|
||||||
if e.Verbose {
|
if e.Verbose {
|
||||||
log.Printf("Sending %s request to %s with params %s\n", method, endpoint, payload)
|
log.Debugf("Sending %s request to %s with params %s\n", method, endpoint, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package exmo
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the EXMO go routine
|
// Start starts the EXMO go routine
|
||||||
@@ -26,13 +26,13 @@ func (e *EXMO) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the EXMO wrapper
|
// Run implements the EXMO wrapper
|
||||||
func (e *EXMO) Run() {
|
func (e *EXMO) Run() {
|
||||||
if e.Verbose {
|
if e.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", e.GetName(), e.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", e.GetName(), e.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", e.GetName(), len(e.EnabledPairs), e.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", e.GetName(), len(e.EnabledPairs), e.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := e.GetPairSettings()
|
exchangeProducts, err := e.GetPairSettings()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available products.\n", e.GetName())
|
log.Errorf("%s Failed to get available products.\n", e.GetName())
|
||||||
} else {
|
} else {
|
||||||
var currencies []string
|
var currencies []string
|
||||||
for x := range exchangeProducts {
|
for x := range exchangeProducts {
|
||||||
@@ -40,7 +40,7 @@ func (e *EXMO) Run() {
|
|||||||
}
|
}
|
||||||
err = e.UpdateCurrencies(currencies, false, false)
|
err = e.UpdateCurrencies(currencies, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", e.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", e.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -14,6 +13,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package gateio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the GateIO go routine
|
// Start starts the GateIO go routine
|
||||||
@@ -25,18 +25,18 @@ func (g *Gateio) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the GateIO wrapper
|
// Run implements the GateIO wrapper
|
||||||
func (g *Gateio) Run() {
|
func (g *Gateio) Run() {
|
||||||
if g.Verbose {
|
if g.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", g.GetName(), common.IsEnabled(g.Websocket.IsEnabled()), g.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", g.GetName(), common.IsEnabled(g.Websocket.IsEnabled()), g.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", g.GetName(), g.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", g.GetName(), g.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", g.GetName(), len(g.EnabledPairs), g.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", g.GetName(), len(g.EnabledPairs), g.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
symbols, err := g.GetSymbols()
|
symbols, err := g.GetSymbols()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Unable to fetch symbols.\n", g.GetName())
|
log.Errorf("%s Unable to fetch symbols.\n", g.GetName())
|
||||||
} else {
|
} else {
|
||||||
err = g.UpdateCurrencies(symbols, false, false)
|
err = g.UpdateCurrencies(symbols, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", g.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", g.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package gemini
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,9 +10,10 @@ import (
|
|||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -494,7 +494,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st
|
|||||||
}
|
}
|
||||||
|
|
||||||
if g.Verbose {
|
if g.Verbose {
|
||||||
log.Printf("Request JSON: %s\n", PayloadJSON)
|
log.Debugf("Request JSON: %s", PayloadJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
PayloadBase64 := common.Base64Encode(PayloadJSON)
|
PayloadBase64 := common.Base64Encode(PayloadJSON)
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package gemini
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Gemini go routine
|
// Start starts the Gemini go routine
|
||||||
@@ -27,17 +27,17 @@ func (g *Gemini) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Gemini wrapper
|
// Run implements the Gemini wrapper
|
||||||
func (g *Gemini) Run() {
|
func (g *Gemini) Run() {
|
||||||
if g.Verbose {
|
if g.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", g.GetName(), g.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", g.GetName(), g.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", g.GetName(), len(g.EnabledPairs), g.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", g.GetName(), len(g.EnabledPairs), g.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := g.GetSymbols()
|
exchangeProducts, err := g.GetSymbols()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", g.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", g.GetName())
|
||||||
} else {
|
} else {
|
||||||
err = g.UpdateCurrencies(exchangeProducts, false, false)
|
err = g.UpdateCurrencies(exchangeProducts, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", g.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", g.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -13,9 +12,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package hitbtc
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
@@ -11,8 +10,9 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -149,7 +149,7 @@ func (h *HitBTC) WsHandleData() {
|
|||||||
var init capture
|
var init capture
|
||||||
err := common.JSONDecode(resp.Raw, &init)
|
err := common.JSONDecode(resp.Raw, &init)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if init.Error.Message != "" || init.Error.Code != 0 {
|
if init.Error.Message != "" || init.Error.Code != 0 {
|
||||||
@@ -168,12 +168,12 @@ func (h *HitBTC) WsHandleData() {
|
|||||||
var ticker WsTicker
|
var ticker WsTicker
|
||||||
err := common.JSONDecode(resp.Raw, &ticker)
|
err := common.JSONDecode(resp.Raw, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ts, err := time.Parse(time.RFC3339, ticker.Params.Timestamp)
|
ts, err := time.Parse(time.RFC3339, ticker.Params.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Websocket.DataHandler <- exchange.TickerData{
|
h.Websocket.DataHandler <- exchange.TickerData{
|
||||||
@@ -191,19 +191,19 @@ func (h *HitBTC) WsHandleData() {
|
|||||||
var obSnapshot WsOrderbook
|
var obSnapshot WsOrderbook
|
||||||
err := common.JSONDecode(resp.Raw, &obSnapshot)
|
err := common.JSONDecode(resp.Raw, &obSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.WsProcessOrderbookSnapshot(obSnapshot)
|
err = h.WsProcessOrderbookSnapshot(obSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "updateOrderbook":
|
case "updateOrderbook":
|
||||||
var obUpdate WsOrderbook
|
var obUpdate WsOrderbook
|
||||||
err := common.JSONDecode(resp.Raw, &obUpdate)
|
err := common.JSONDecode(resp.Raw, &obUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.WsProcessOrderbookUpdate(obUpdate)
|
h.WsProcessOrderbookUpdate(obUpdate)
|
||||||
@@ -212,14 +212,14 @@ func (h *HitBTC) WsHandleData() {
|
|||||||
var tradeSnapshot WsTrade
|
var tradeSnapshot WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &tradeSnapshot)
|
err := common.JSONDecode(resp.Raw, &tradeSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case "updateTrades":
|
case "updateTrades":
|
||||||
var tradeUpdates WsTrade
|
var tradeUpdates WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &tradeUpdates)
|
err := common.JSONDecode(resp.Raw, &tradeUpdates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ package hitbtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the HitBTC go routine
|
// Start starts the HitBTC go routine
|
||||||
@@ -25,14 +26,14 @@ func (h *HitBTC) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the HitBTC wrapper
|
// Run implements the HitBTC wrapper
|
||||||
func (h *HitBTC) Run() {
|
func (h *HitBTC) Run() {
|
||||||
if h.Verbose {
|
if h.Verbose {
|
||||||
log.Printf("%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), hitbtcWebsocketAddress)
|
log.Debugf("%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), hitbtcWebsocketAddress)
|
||||||
log.Printf("%s polling delay: %ds.\n", h.GetName(), h.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", h.GetName(), h.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", h.GetName(), len(h.EnabledPairs), h.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", h.GetName(), len(h.EnabledPairs), h.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := h.GetSymbolsDetailed()
|
exchangeProducts, err := h.GetSymbolsDetailed()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", h.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", h.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(h.EnabledPairs, "-") || !common.StringDataContains(h.AvailablePairs, "-") {
|
if !common.StringDataContains(h.EnabledPairs, "-") || !common.StringDataContains(h.AvailablePairs, "-") {
|
||||||
@@ -45,16 +46,16 @@ func (h *HitBTC) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"BTC-USD"}
|
enabledPairs := []string{"BTC-USD"}
|
||||||
log.Println("WARNING: Available pairs for HitBTC reset due to config upgrade, please enable the ones you would like again.")
|
log.Warn("Available pairs for HitBTC reset due to config upgrade, please enable the ones you would like again.")
|
||||||
|
|
||||||
err = h.UpdateCurrencies(enabledPairs, true, true)
|
err = h.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update enabled currencies.\n", h.GetName())
|
log.Errorf("%s Failed to update enabled currencies.\n", h.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = h.UpdateCurrencies(currencies, false, forceUpgrade)
|
err = h.UpdateCurrencies(currencies, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", h.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", h.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -24,6 +23,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -15,8 +14,9 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -81,7 +81,7 @@ func (h *HUOBI) WsReadData() {
|
|||||||
default:
|
default:
|
||||||
_, resp, err := h.WebsocketConn.ReadMessage()
|
_, resp, err := h.WebsocketConn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Websocket.TrafficAlert <- struct{}{}
|
h.Websocket.TrafficAlert <- struct{}{}
|
||||||
@@ -89,12 +89,12 @@ func (h *HUOBI) WsReadData() {
|
|||||||
b := bytes.NewReader(resp)
|
b := bytes.NewReader(resp)
|
||||||
gReader, err := gzip.NewReader(b)
|
gReader, err := gzip.NewReader(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
unzipped, err := ioutil.ReadAll(gReader)
|
unzipped, err := ioutil.ReadAll(gReader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
gReader.Close()
|
gReader.Close()
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ func (h *HUOBI) WsHandleData() {
|
|||||||
var init WsResponse
|
var init WsResponse
|
||||||
err := common.JSONDecode(resp.Raw, &init)
|
err := common.JSONDecode(resp.Raw, &init)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if init.Status == "error" {
|
if init.Status == "error" {
|
||||||
@@ -132,7 +132,7 @@ func (h *HUOBI) WsHandleData() {
|
|||||||
if init.Ping != 0 {
|
if init.Ping != 0 {
|
||||||
err = h.WebsocketConn.WriteJSON(`{"pong":1337}`)
|
err = h.WebsocketConn.WriteJSON(`{"pong":1337}`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ func (h *HUOBI) WsHandleData() {
|
|||||||
var depth WsDepth
|
var depth WsDepth
|
||||||
err := common.JSONDecode(resp.Raw, &depth)
|
err := common.JSONDecode(resp.Raw, &depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := common.SplitStrings(depth.Channel, ".")
|
data := common.SplitStrings(depth.Channel, ".")
|
||||||
@@ -153,7 +153,7 @@ func (h *HUOBI) WsHandleData() {
|
|||||||
var kline WsKline
|
var kline WsKline
|
||||||
err := common.JSONDecode(resp.Raw, &kline)
|
err := common.JSONDecode(resp.Raw, &kline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := common.SplitStrings(kline.Channel, ".")
|
data := common.SplitStrings(kline.Channel, ".")
|
||||||
@@ -174,7 +174,7 @@ func (h *HUOBI) WsHandleData() {
|
|||||||
var trade WsTrade
|
var trade WsTrade
|
||||||
err := common.JSONDecode(resp.Raw, &trade)
|
err := common.JSONDecode(resp.Raw, &trade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := common.SplitStrings(trade.Channel, ".")
|
data := common.SplitStrings(trade.Channel, ".")
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package huobi
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the HUOBI go routine
|
// Start starts the HUOBI go routine
|
||||||
@@ -27,14 +27,14 @@ func (h *HUOBI) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the HUOBI wrapper
|
// Run implements the HUOBI wrapper
|
||||||
func (h *HUOBI) Run() {
|
func (h *HUOBI) Run() {
|
||||||
if h.Verbose {
|
if h.Verbose {
|
||||||
log.Printf("%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), huobiSocketIOAddress)
|
log.Debugf("%s Websocket: %s (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), huobiSocketIOAddress)
|
||||||
log.Printf("%s polling delay: %ds.\n", h.GetName(), h.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", h.GetName(), h.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", h.GetName(), len(h.EnabledPairs), h.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", h.GetName(), len(h.EnabledPairs), h.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := h.GetSymbols()
|
exchangeProducts, err := h.GetSymbols()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", h.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", h.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if common.StringDataContains(h.EnabledPairs, "CNY") || common.StringDataContains(h.AvailablePairs, "CNY") {
|
if common.StringDataContains(h.EnabledPairs, "CNY") || common.StringDataContains(h.AvailablePairs, "CNY") {
|
||||||
@@ -45,7 +45,7 @@ func (h *HUOBI) Run() {
|
|||||||
cfg := config.GetConfig()
|
cfg := config.GetConfig()
|
||||||
exchCfg, errCNY := cfg.GetExchangeConfig(h.Name)
|
exchCfg, errCNY := cfg.GetExchangeConfig(h.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to get exchange config. %s\n", h.Name, errCNY)
|
log.Errorf("%s failed to get exchange config. %s\n", h.Name, errCNY)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
exchCfg.BaseCurrencies = "USD"
|
exchCfg.BaseCurrencies = "USD"
|
||||||
@@ -53,7 +53,7 @@ func (h *HUOBI) Run() {
|
|||||||
|
|
||||||
errCNY = cfg.UpdateExchangeConfig(exchCfg)
|
errCNY = cfg.UpdateExchangeConfig(exchCfg)
|
||||||
if errCNY != nil {
|
if errCNY != nil {
|
||||||
log.Printf("%s failed to update config. %s\n", h.Name, errCNY)
|
log.Errorf("%s failed to update config. %s\n", h.Name, errCNY)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,16 +66,16 @@ func (h *HUOBI) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"btc-usdt"}
|
enabledPairs := []string{"btc-usdt"}
|
||||||
log.Println("WARNING: Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
|
log.Warn("Available and enabled pairs for Huobi reset due to config upgrade, please enable the ones you would like again")
|
||||||
|
|
||||||
err = h.UpdateCurrencies(enabledPairs, true, true)
|
err = h.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update enabled currencies.\n", h.GetName())
|
log.Errorf("%s Failed to update enabled currencies.\n", h.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = h.UpdateCurrencies(currencies, false, forceUpgrade)
|
err = h.UpdateCurrencies(currencies, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", h.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", h.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -13,9 +12,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ package huobihadax
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the OKEX go routine
|
// Start starts the OKEX go routine
|
||||||
@@ -26,14 +26,14 @@ func (h *HUOBIHADAX) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the OKEX wrapper
|
// Run implements the OKEX wrapper
|
||||||
func (h *HUOBIHADAX) Run() {
|
func (h *HUOBIHADAX) Run() {
|
||||||
if h.Verbose {
|
if h.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), h.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", h.GetName(), common.IsEnabled(h.Websocket.IsEnabled()), h.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", h.GetName(), h.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", h.GetName(), h.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", h.GetName(), len(h.EnabledPairs), h.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", h.GetName(), len(h.EnabledPairs), h.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := h.GetSymbols()
|
exchangeProducts, err := h.GetSymbols()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", h.GetName())
|
log.Debugf("%s Failed to get available symbols.\n", h.GetName())
|
||||||
} else {
|
} else {
|
||||||
var currencies []string
|
var currencies []string
|
||||||
for x := range exchangeProducts {
|
for x := range exchangeProducts {
|
||||||
@@ -43,7 +43,7 @@ func (h *HUOBIHADAX) Run() {
|
|||||||
|
|
||||||
err = h.UpdateCurrencies(currencies, false, false)
|
err = h.UpdateCurrencies(currencies, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", h.GetName())
|
log.Debugf("%s Failed to update available currencies.\n", h.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -13,9 +12,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -379,7 +379,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params
|
|||||||
}
|
}
|
||||||
|
|
||||||
if i.Verbose {
|
if i.Verbose {
|
||||||
log.Printf("Request JSON: %s\n", PayloadJSON)
|
log.Debugf("Request JSON: %s\n", PayloadJSON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ package itbit
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the ItBit go routine
|
// Start starts the ItBit go routine
|
||||||
@@ -26,8 +26,8 @@ func (i *ItBit) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the ItBit wrapper
|
// Run implements the ItBit wrapper
|
||||||
func (i *ItBit) Run() {
|
func (i *ItBit) Run() {
|
||||||
if i.Verbose {
|
if i.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", i.GetName(), i.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", i.GetName(), i.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", i.GetName(), len(i.EnabledPairs), i.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", i.GetName(), len(i.EnabledPairs), i.EnabledPairs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,11 +82,11 @@ func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderboo
|
|||||||
data := orderbookNew.Bids[x]
|
data := orderbookNew.Bids[x]
|
||||||
price, err := strconv.ParseFloat(data[0], 64)
|
price, err := strconv.ParseFloat(data[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(data[1], 64)
|
amount, err := strconv.ParseFloat(data[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: amount, Price: price})
|
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: amount, Price: price})
|
||||||
}
|
}
|
||||||
@@ -95,11 +95,11 @@ func (i *ItBit) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderboo
|
|||||||
data := orderbookNew.Asks[x]
|
data := orderbookNew.Asks[x]
|
||||||
price, err := strconv.ParseFloat(data[0], 64)
|
price, err := strconv.ParseFloat(data[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(data[1], 64)
|
amount, err := strconv.ParseFloat(data[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: amount, Price: price})
|
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: amount, Price: price})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package kraken
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,9 +9,10 @@ import (
|
|||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -892,7 +892,7 @@ func GetError(errors []string) error {
|
|||||||
for _, e := range errors {
|
for _, e := range errors {
|
||||||
switch e[0] {
|
switch e[0] {
|
||||||
case 'W':
|
case 'W':
|
||||||
log.Printf("Kraken API warning: %v\n", e[1:])
|
log.Warnf("Kraken API warning: %v\n", e[1:])
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Kraken API error: %v", e[1:])
|
return fmt.Errorf("Kraken API error: %v", e[1:])
|
||||||
}
|
}
|
||||||
@@ -931,7 +931,7 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, params url.Values,
|
|||||||
signature := common.Base64Encode(common.GetHMAC(common.HashSHA512, append([]byte(path), shasum...), secret))
|
signature := common.Base64Encode(common.GetHMAC(common.HashSHA512, append([]byte(path), shasum...), secret))
|
||||||
|
|
||||||
if k.Verbose {
|
if k.Verbose {
|
||||||
log.Printf("Sending POST request to %s, path: %s, params: %s", k.APIUrl, path, encoded)
|
log.Debugf("Sending POST request to %s, path: %s, params: %s", k.APIUrl, path, encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package kraken
|
package kraken
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Kraken go routine
|
// Start starts the Kraken go routine
|
||||||
@@ -24,13 +24,13 @@ func (k *Kraken) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Kraken wrapper
|
// Run implements the Kraken wrapper
|
||||||
func (k *Kraken) Run() {
|
func (k *Kraken) Run() {
|
||||||
if k.Verbose {
|
if k.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", k.GetName(), k.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", k.GetName(), k.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", k.GetName(), len(k.EnabledPairs), k.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", k.GetName(), len(k.EnabledPairs), k.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
assetPairs, err := k.GetAssetPairs()
|
assetPairs, err := k.GetAssetPairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", k.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", k.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(k.EnabledPairs, "-") || !common.StringDataContains(k.AvailablePairs, "-") {
|
if !common.StringDataContains(k.EnabledPairs, "-") || !common.StringDataContains(k.AvailablePairs, "-") {
|
||||||
@@ -55,16 +55,16 @@ func (k *Kraken) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"XBT-USD"}
|
enabledPairs := []string{"XBT-USD"}
|
||||||
log.Println("WARNING: Available pairs for Kraken reset due to config upgrade, please enable the ones you would like again")
|
log.Warn("Available pairs for Kraken reset due to config upgrade, please enable the ones you would like again")
|
||||||
|
|
||||||
err = k.UpdateCurrencies(enabledPairs, true, true)
|
err = k.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", k.GetName())
|
log.Errorf("%s Failed to get config.\n", k.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = k.UpdateCurrencies(exchangeProducts, false, forceUpgrade)
|
err = k.UpdateCurrencies(exchangeProducts, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", k.GetName())
|
log.Errorf("%s Failed to get config.\n", k.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package lakebtc
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -11,9 +10,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -175,12 +175,12 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) {
|
|||||||
for _, x := range resp.Bids {
|
for _, x := range resp.Bids {
|
||||||
price, err := strconv.ParseFloat(x[0], 64)
|
price, err := strconv.ParseFloat(x[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(x[1], 64)
|
amount, err := strconv.ParseFloat(x[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
orderbook.Bids = append(orderbook.Bids, OrderbookStructure{price, amount})
|
orderbook.Bids = append(orderbook.Bids, OrderbookStructure{price, amount})
|
||||||
@@ -189,12 +189,12 @@ func (l *LakeBTC) GetOrderBook(currency string) (Orderbook, error) {
|
|||||||
for _, x := range resp.Asks {
|
for _, x := range resp.Asks {
|
||||||
price, err := strconv.ParseFloat(x[0], 64)
|
price, err := strconv.ParseFloat(x[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(x[1], 64)
|
amount, err := strconv.ParseFloat(x[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
orderbook.Asks = append(orderbook.Asks, OrderbookStructure{price, amount})
|
orderbook.Asks = append(orderbook.Asks, OrderbookStructure{price, amount})
|
||||||
@@ -353,7 +353,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
|
|||||||
hmac := common.GetHMAC(common.HashSHA1, []byte(req), []byte(l.APISecret))
|
hmac := common.GetHMAC(common.HashSHA1, []byte(req), []byte(l.APISecret))
|
||||||
|
|
||||||
if l.Verbose {
|
if l.Verbose {
|
||||||
log.Printf("Sending POST request to %s calling method %s with params %s\n", l.APIUrl, method, req)
|
log.Debugf("Sending POST request to %s calling method %s with params %s\n", l.APIUrl, method, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
postData := make(map[string]interface{})
|
postData := make(map[string]interface{})
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package lakebtc
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the LakeBTC go routine
|
// Start starts the LakeBTC go routine
|
||||||
@@ -27,17 +27,17 @@ func (l *LakeBTC) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the LakeBTC wrapper
|
// Run implements the LakeBTC wrapper
|
||||||
func (l *LakeBTC) Run() {
|
func (l *LakeBTC) Run() {
|
||||||
if l.Verbose {
|
if l.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := l.GetTradablePairs()
|
exchangeProducts, err := l.GetTradablePairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available products.\n", l.GetName())
|
log.Errorf("%s Failed to get available products.\n", l.GetName())
|
||||||
} else {
|
} else {
|
||||||
err = l.UpdateCurrencies(exchangeProducts, false, false)
|
err = l.UpdateCurrencies(exchangeProducts, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", l.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", l.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package liqui
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,9 +10,10 @@ import (
|
|||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -299,7 +299,7 @@ func (l *Liqui) SendAuthenticatedHTTPRequest(method string, values url.Values, r
|
|||||||
hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(l.APISecret))
|
hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(l.APISecret))
|
||||||
|
|
||||||
if l.Verbose {
|
if l.Verbose {
|
||||||
log.Printf("Sending POST request to %s calling method %s with params %s\n",
|
log.Debugf("Sending POST request to %s calling method %s with params %s\n",
|
||||||
l.APIUrlSecondary, method, encoded)
|
l.APIUrlSecondary, method, encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package liqui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Liqui go routine
|
// Start starts the Liqui go routine
|
||||||
@@ -25,19 +25,19 @@ func (l *Liqui) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Liqui wrapper
|
// Run implements the Liqui wrapper
|
||||||
func (l *Liqui) Run() {
|
func (l *Liqui) Run() {
|
||||||
if l.Verbose {
|
if l.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
l.Info, err = l.GetInfo()
|
l.Info, err = l.GetInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Unable to fetch info.\n", l.GetName())
|
log.Errorf("%s Unable to fetch info.\n", l.GetName())
|
||||||
} else {
|
} else {
|
||||||
exchangeProducts := l.GetAvailablePairs(true)
|
exchangeProducts := l.GetAvailablePairs(true)
|
||||||
err = l.UpdateCurrencies(exchangeProducts, false, false)
|
err = l.UpdateCurrencies(exchangeProducts, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", l.GetName())
|
log.Errorf("%s Failed to get config.\n", l.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package localbitcoins
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,8 +10,9 @@ import (
|
|||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -677,12 +677,12 @@ func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) {
|
|||||||
for _, x := range resp.Bids {
|
for _, x := range resp.Bids {
|
||||||
price, err := strconv.ParseFloat(x[0], 64)
|
price, err := strconv.ParseFloat(x[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(x[1], 64)
|
amount, err := strconv.ParseFloat(x[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
orderbook.Bids = append(orderbook.Bids, Price{price, amount})
|
orderbook.Bids = append(orderbook.Bids, Price{price, amount})
|
||||||
@@ -691,12 +691,12 @@ func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) {
|
|||||||
for _, x := range resp.Asks {
|
for _, x := range resp.Asks {
|
||||||
price, err := strconv.ParseFloat(x[0], 64)
|
price, err := strconv.ParseFloat(x[0], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
amount, err := strconv.ParseFloat(x[1], 64)
|
amount, err := strconv.ParseFloat(x[1], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
orderbook.Asks = append(orderbook.Asks, Price{price, amount})
|
orderbook.Asks = append(orderbook.Asks, Price{price, amount})
|
||||||
@@ -734,7 +734,7 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, params
|
|||||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||||
|
|
||||||
if l.Verbose {
|
if l.Verbose {
|
||||||
log.Printf("Sending POST request to `%s`, path: `%s`, params: `%s`.", l.APIUrl, path, encoded)
|
log.Debugf("Sending POST request to `%s`, path: `%s`, params: `%s`.", l.APIUrl, path, encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
if method == "GET" && len(encoded) > 0 {
|
if method == "GET" && len(encoded) > 0 {
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package localbitcoins
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the LocalBitcoins go routine
|
// Start starts the LocalBitcoins go routine
|
||||||
@@ -27,13 +27,13 @@ func (l *LocalBitcoins) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the LocalBitcoins wrapper
|
// Run implements the LocalBitcoins wrapper
|
||||||
func (l *LocalBitcoins) Run() {
|
func (l *LocalBitcoins) Run() {
|
||||||
if l.Verbose {
|
if l.Verbose {
|
||||||
log.Printf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", l.GetName(), l.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", l.GetName(), len(l.EnabledPairs), l.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
currencies, err := l.GetTradableCurrencies()
|
currencies, err := l.GetTradableCurrencies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to obtain available tradable currencies. Err: %s", l.Name, err)
|
log.Errorf("%s failed to obtain available tradable currencies. Err: %s", l.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ func (l *LocalBitcoins) Run() {
|
|||||||
|
|
||||||
err = l.UpdateCurrencies(pairs, false, false)
|
err = l.UpdateCurrencies(pairs, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update available currencies. Err %s", l.Name, err)
|
log.Errorf("%s failed to update available currencies. Err %s", l.Name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package okcoin
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -14,9 +13,10 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -811,7 +811,7 @@ func (o *OKCoin) GetFuturesUserInfo() {
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo, url.Values{}, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo, url.Values{}, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,7 +823,7 @@ func (o *OKCoin) GetFuturesPosition(symbol, contractType string) {
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesPosition, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesPosition, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,7 +841,7 @@ func (o *OKCoin) FuturesTrade(amount, price float64, matchPrice, leverage int64,
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesTrade, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesTrade, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -856,7 +856,7 @@ func (o *OKCoin) FuturesBatchTrade(orderData, symbol, contractType string, lever
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesTradeBatch, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesTradeBatch, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -870,7 +870,7 @@ func (o *OKCoin) CancelFuturesOrder(orderID int64, symbol, contractType string)
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesCancel, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesCancel, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,7 +887,7 @@ func (o *OKCoin) GetFuturesOrderInfo(orderID, status, currentPage, pageLength in
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesOrderInfo, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesOrderInfo, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,7 +901,7 @@ func (o *OKCoin) GetFutureOrdersInfo(orderID int64, contractType, symbol string)
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesOrdersInfo, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesOrdersInfo, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -912,7 +912,7 @@ func (o *OKCoin) GetFuturesUserInfo4Fix() {
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,7 +926,7 @@ func (o *OKCoin) GetFuturesUserPosition4Fix(symbol, contractType string) {
|
|||||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, nil)
|
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -949,7 +949,7 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values, resul
|
|||||||
path := o.APIUrl + method
|
path := o.APIUrl + method
|
||||||
|
|
||||||
if o.Verbose {
|
if o.Verbose {
|
||||||
log.Printf("Sending POST request to %s with params %s\n", path, encoded)
|
log.Debugf("Sending POST request to %s with params %s\n", path, encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -13,7 +12,8 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -132,11 +132,11 @@ func (o *OKCoin) WsHandleData() {
|
|||||||
var init []WsResponse
|
var init []WsResponse
|
||||||
err := common.JSONDecode(resp.Raw, &init)
|
err := common.JSONDecode(resp.Raw, &init)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if init[0].ErrorCode != "" {
|
if init[0].ErrorCode != "" {
|
||||||
log.Fatal(o.WebsocketErrors[init[0].ErrorCode])
|
log.Error(o.WebsocketErrors[init[0].ErrorCode])
|
||||||
}
|
}
|
||||||
|
|
||||||
if init[0].Success {
|
if init[0].Success {
|
||||||
@@ -166,7 +166,7 @@ func (o *OKCoin) WsHandleData() {
|
|||||||
|
|
||||||
err = common.JSONDecode(init[0].Data, &ticker)
|
err = common.JSONDecode(init[0].Data, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ func (o *OKCoin) WsHandleData() {
|
|||||||
|
|
||||||
err = common.JSONDecode(init[0].Data, &orderbook)
|
err = common.JSONDecode(init[0].Data, &orderbook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
o.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||||
@@ -201,7 +201,7 @@ func (o *OKCoin) WsHandleData() {
|
|||||||
|
|
||||||
err = common.JSONDecode(init[0].Data, &klineData)
|
err = common.JSONDecode(init[0].Data, &klineData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var klines []WsKlines
|
var klines []WsKlines
|
||||||
@@ -237,7 +237,7 @@ func (o *OKCoin) WsHandleData() {
|
|||||||
var dealsData [][]interface{}
|
var dealsData [][]interface{}
|
||||||
err = common.JSONDecode(init[0].Data, &dealsData)
|
err = common.JSONDecode(init[0].Data, &dealsData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var deals []WsDeals
|
var deals []WsDeals
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ package okcoin
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the OKCoin go routine
|
// Start starts the OKCoin go routine
|
||||||
@@ -26,9 +26,9 @@ func (o *OKCoin) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the OKCoin wrapper
|
// Run implements the OKCoin wrapper
|
||||||
func (o *OKCoin) Run() {
|
func (o *OKCoin) Run() {
|
||||||
if o.Verbose {
|
if o.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.APIUrl == okcoinAPIURL {
|
if o.APIUrl == okcoinAPIURL {
|
||||||
@@ -40,7 +40,7 @@ func (o *OKCoin) Run() {
|
|||||||
|
|
||||||
prods, err := o.GetSpotInstruments()
|
prods, err := o.GetSpotInstruments()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("OKEX failed to obtain available spot instruments. Err: %d", err)
|
log.Errorf("OKEX failed to obtain available spot instruments. Err: %d", err)
|
||||||
} else {
|
} else {
|
||||||
var pairs []string
|
var pairs []string
|
||||||
for x := range prods {
|
for x := range prods {
|
||||||
@@ -49,17 +49,17 @@ func (o *OKCoin) Run() {
|
|||||||
|
|
||||||
err = o.UpdateCurrencies(pairs, false, forceUpgrade)
|
err = o.UpdateCurrencies(pairs, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("OKEX failed to update available currencies. Err: %s", err)
|
log.Errorf("OKEX failed to update available currencies. Err: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"btc_usd"}
|
enabledPairs := []string{"btc_usd"}
|
||||||
log.Println("WARNING: Available pairs for OKCoin International reset due to config upgrade, please enable the pairs you would like again.")
|
log.Warn("Available pairs for OKCoin International reset due to config upgrade, please enable the pairs you would like again.")
|
||||||
|
|
||||||
err := o.UpdateCurrencies(enabledPairs, true, true)
|
err := o.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s failed to update currencies. Err: %s", o.Name, err)
|
log.Errorf("%s failed to update currencies. Err: %s", o.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -18,6 +17,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -944,7 +944,7 @@ func (o *OKEX) SendAuthenticatedHTTPRequest(method string, values url.Values, re
|
|||||||
path := o.APIUrl + apiVersion + method
|
path := o.APIUrl + apiVersion + method
|
||||||
|
|
||||||
if o.Verbose {
|
if o.Verbose {
|
||||||
log.Printf("Sending POST request to %s with params %s\n", path, encoded)
|
log.Debugf("Sending POST request to %s with params %s\n", path, encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -16,7 +15,8 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -203,7 +203,8 @@ func (o *OKEX) WsHandleData() {
|
|||||||
if strings.Contains(string(resp.Raw), "pong") {
|
if strings.Contains(string(resp.Raw), "pong") {
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
log.Fatal("okex.go error -", err)
|
log.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ func (o *OKEX) WsHandleData() {
|
|||||||
if common.StringContains(string(resp.Raw), "error_msg") {
|
if common.StringContains(string(resp.Raw), "error_msg") {
|
||||||
err = common.JSONDecode(resp.Raw, &errResponse)
|
err = common.JSONDecode(resp.Raw, &errResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
o.Websocket.DataHandler <- fmt.Errorf("okex.go error - %s resp: %s ",
|
o.Websocket.DataHandler <- fmt.Errorf("okex.go error - %s resp: %s ",
|
||||||
errResponse.ErrorMsg,
|
errResponse.ErrorMsg,
|
||||||
@@ -233,7 +234,8 @@ func (o *OKEX) WsHandleData() {
|
|||||||
|
|
||||||
err = common.JSONDecode(multiStreamData.Data, &ticker)
|
err = common.JSONDecode(multiStreamData.Data, &ticker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("OKEX Ticker Decode Error:", err)
|
log.Errorf("OKEX Ticker Decode Error: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Websocket.DataHandler <- exchange.TickerData{
|
o.Websocket.DataHandler <- exchange.TickerData{
|
||||||
@@ -247,7 +249,8 @@ func (o *OKEX) WsHandleData() {
|
|||||||
|
|
||||||
err = common.JSONDecode(multiStreamData.Data, &deals)
|
err = common.JSONDecode(multiStreamData.Data, &deals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("OKEX Deals Decode Error:", err)
|
log.Errorf("OKEX Deals Decode Error: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, trade := range deals {
|
for _, trade := range deals {
|
||||||
@@ -271,7 +274,8 @@ func (o *OKEX) WsHandleData() {
|
|||||||
|
|
||||||
err := common.JSONDecode(multiStreamData.Data, &klines)
|
err := common.JSONDecode(multiStreamData.Data, &klines)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("OKEX Klines Decode Error:", err)
|
log.Errorf("OKEX Klines Decode Error: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, kline := range klines {
|
for _, kline := range klines {
|
||||||
@@ -300,7 +304,8 @@ func (o *OKEX) WsHandleData() {
|
|||||||
|
|
||||||
err := common.JSONDecode(multiStreamData.Data, &depth)
|
err := common.JSONDecode(multiStreamData.Data, &depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("OKEX Depth Decode Error:", err)
|
log.Errorf("OKEX Depth Decode Error: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
o.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
o.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package okex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the OKEX go routine
|
// Start starts the OKEX go routine
|
||||||
@@ -26,14 +26,14 @@ func (o *OKEX) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the OKEX wrapper
|
// Run implements the OKEX wrapper
|
||||||
func (o *OKEX) Run() {
|
func (o *OKEX) Run() {
|
||||||
if o.Verbose {
|
if o.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
prods, err := o.GetSpotInstruments()
|
prods, err := o.GetSpotInstruments()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("OKEX failed to obtain available spot instruments. Err: %d", err)
|
log.Errorf("OKEX failed to obtain available spot instruments. Err: %d", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,8 @@ func (o *OKEX) Run() {
|
|||||||
|
|
||||||
err = o.UpdateCurrencies(pairs, false, false)
|
err = o.UpdateCurrencies(pairs, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("OKEX failed to update available currencies. Err: %s", err)
|
log.Errorf("OKEX failed to update available currencies. Err: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -12,9 +11,10 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -168,7 +168,6 @@ func (p *Poloniex) GetOrderbook(currencyPair string, depth int) (OrderbookAll, e
|
|||||||
return oba, err
|
return oba, err
|
||||||
}
|
}
|
||||||
if len(resp.Error) != 0 {
|
if len(resp.Error) != 0 {
|
||||||
log.Println(resp.Error)
|
|
||||||
return oba, fmt.Errorf("Poloniex GetOrderbook() error: %s", resp.Error)
|
return oba, fmt.Errorf("Poloniex GetOrderbook() error: %s", resp.Error)
|
||||||
}
|
}
|
||||||
ob := Orderbook{}
|
ob := Orderbook{}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package poloniex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -12,8 +11,9 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -132,7 +132,7 @@ func (p *Poloniex) WsHandleData() {
|
|||||||
var check []interface{}
|
var check []interface{}
|
||||||
err := common.JSONDecode(resp.Raw, &check)
|
err := common.JSONDecode(resp.Raw, &check)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("poloniex_websocket.go - ", err)
|
log.Errorf("poloniex websocket decode error - %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch len(check) {
|
switch len(check) {
|
||||||
@@ -176,7 +176,7 @@ func (p *Poloniex) WsHandleData() {
|
|||||||
err := p.WsProcessOrderbookUpdate(datalevel2,
|
err := p.WsProcessOrderbookUpdate(datalevel2,
|
||||||
CurrencyPairID[int64(check[0].(float64))])
|
CurrencyPairID[int64(check[0].(float64))])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
p.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||||
@@ -189,12 +189,12 @@ func (p *Poloniex) WsHandleData() {
|
|||||||
datalevel3 := datalevel2[1].(map[string]interface{})
|
datalevel3 := datalevel2[1].(map[string]interface{})
|
||||||
currencyPair, ok := datalevel3["currencyPair"].(string)
|
currencyPair, ok := datalevel3["currencyPair"].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("poloniex.go error - could not find currency pair in map")
|
log.Error("poloniex.go error - could not find currency pair in map")
|
||||||
}
|
}
|
||||||
|
|
||||||
orderbookData, ok := datalevel3["orderBook"].([]interface{})
|
orderbookData, ok := datalevel3["orderBook"].([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Fatal("poloniex.go error - could not find orderbook data in map")
|
log.Error("poloniex.go error - could not find orderbook data in map")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := p.WsProcessOrderbookSnapshot(orderbookData, currencyPair)
|
err := p.WsProcessOrderbookSnapshot(orderbookData, currencyPair)
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package poloniex
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the Poloniex go routine
|
// Start starts the Poloniex go routine
|
||||||
@@ -25,24 +25,24 @@ func (p *Poloniex) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Poloniex wrapper
|
// Run implements the Poloniex wrapper
|
||||||
func (p *Poloniex) Run() {
|
func (p *Poloniex) Run() {
|
||||||
if p.Verbose {
|
if p.Verbose {
|
||||||
log.Printf("%s Websocket: %s (url: %s).\n", p.GetName(), common.IsEnabled(p.Websocket.IsEnabled()), poloniexWebsocketAddress)
|
log.Debugf("%s Websocket: %s (url: %s).\n", p.GetName(), common.IsEnabled(p.Websocket.IsEnabled()), poloniexWebsocketAddress)
|
||||||
log.Printf("%s polling delay: %ds.\n", p.GetName(), p.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", p.GetName(), p.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", p.GetName(), len(p.EnabledPairs), p.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", p.GetName(), len(p.EnabledPairs), p.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeCurrencies, err := p.GetExchangeCurrencies()
|
exchangeCurrencies, err := p.GetExchangeCurrencies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", p.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", p.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpdate := false
|
forceUpdate := false
|
||||||
if common.StringDataCompare(p.AvailablePairs, "BTC_USDT") {
|
if common.StringDataCompare(p.AvailablePairs, "BTC_USDT") {
|
||||||
log.Printf("%s contains invalid pair, forcing upgrade of available currencies.\n",
|
log.Warnf("%s contains invalid pair, forcing upgrade of available currencies.\n",
|
||||||
p.GetName())
|
p.GetName())
|
||||||
forceUpdate = true
|
forceUpdate = true
|
||||||
}
|
}
|
||||||
err = p.UpdateCurrencies(exchangeCurrencies, false, forceUpdate)
|
err = p.UpdateCurrencies(exchangeCurrencies, false, forceUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies %s.\n", p.GetName(), err)
|
log.Errorf("%s Failed to update available currencies %s.\n", p.GetName(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -13,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportedMethods = []string{"GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS", "CONNECT"}
|
var supportedMethods = []string{"GET", "POST", "HEAD", "PUT", "DELETE", "OPTIONS", "CONNECT"}
|
||||||
@@ -257,11 +257,11 @@ func (r *Requester) checkRequest(method, path string, body io.Reader, headers ma
|
|||||||
// DoRequest performs a HTTP/HTTPS request with the supplied params
|
// DoRequest performs a HTTP/HTTPS request with the supplied params
|
||||||
func (r *Requester) DoRequest(req *http.Request, method, path string, headers map[string]string, body io.Reader, result interface{}, authRequest, verbose bool) error {
|
func (r *Requester) DoRequest(req *http.Request, method, path string, headers map[string]string, body io.Reader, result interface{}, authRequest, verbose bool) error {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("%s exchange request path: %s requires rate limiter: %v", r.Name, path, r.RequiresRateLimiter())
|
log.Debugf("%s exchange request path: %s requires rate limiter: %v", r.Name, path, r.RequiresRateLimiter())
|
||||||
for k, d := range headers {
|
for k, d := range headers {
|
||||||
log.Printf("%s exchange request header [%s]: %s", r.Name, k, d)
|
log.Debugf("%s exchange request header [%s]: %s", r.Name, k, d)
|
||||||
}
|
}
|
||||||
log.Println(body)
|
log.Debug(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeoutError error
|
var timeoutError error
|
||||||
@@ -270,7 +270,7 @@ func (r *Requester) DoRequest(req *http.Request, method, path string, headers ma
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if timeoutErr, ok := err.(net.Error); ok && timeoutErr.Timeout() {
|
if timeoutErr, ok := err.(net.Error); ok && timeoutErr.Timeout() {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("%s request has timed-out retrying request, count %d",
|
log.Errorf("%s request has timed-out retrying request, count %d",
|
||||||
r.Name,
|
r.Name,
|
||||||
i)
|
i)
|
||||||
}
|
}
|
||||||
@@ -308,8 +308,8 @@ func (r *Requester) DoRequest(req *http.Request, method, path string, headers ma
|
|||||||
|
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("HTTP status: %s, Code: %v", resp.Status, resp.StatusCode)
|
log.Debugf("HTTP status: %s, Code: %v", resp.Status, resp.StatusCode)
|
||||||
log.Printf("%s exchange raw response: %s", r.Name, string(contents))
|
log.Debugf("%s exchange raw response: %s", r.Name, string(contents))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result != nil {
|
if result != nil {
|
||||||
@@ -337,7 +337,7 @@ func (r *Requester) worker() {
|
|||||||
limit := r.GetRateLimit(x.AuthRequest)
|
limit := r.GetRateLimit(x.AuthRequest)
|
||||||
diff := limit.GetDuration() - time.Since(r.Cycle)
|
diff := limit.GetDuration() - time.Since(r.Cycle)
|
||||||
if x.Verbose {
|
if x.Verbose {
|
||||||
log.Printf("%s request. Rate limited! Sleeping for %v", r.Name, diff)
|
log.Debugf("%s request. Rate limited! Sleeping for %v", r.Name, diff)
|
||||||
}
|
}
|
||||||
time.Sleep(diff)
|
time.Sleep(diff)
|
||||||
|
|
||||||
@@ -346,7 +346,7 @@ func (r *Requester) worker() {
|
|||||||
r.IncrementRequests(x.AuthRequest)
|
r.IncrementRequests(x.AuthRequest)
|
||||||
|
|
||||||
if x.Verbose {
|
if x.Verbose {
|
||||||
log.Printf("%s request. No longer rate limited! Doing request", r.Name)
|
log.Debugf("%s request. No longer rate limited! Doing request", r.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.DoRequest(x.Request, x.Method, x.Path, x.Headers, x.Body, x.Result, x.AuthRequest, x.Verbose)
|
err := r.DoRequest(x.Request, x.Method, x.Path, x.Headers, x.Body, x.Result, x.AuthRequest, x.Verbose)
|
||||||
@@ -412,17 +412,17 @@ func (r *Requester) SendPayload(method, path string, headers map[string]string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("%s request. Attaching new job.", r.Name)
|
log.Debugf("%s request. Attaching new job.", r.Name)
|
||||||
}
|
}
|
||||||
r.Jobs <- newJob
|
r.Jobs <- newJob
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("%s request. Waiting for job to complete.", r.Name)
|
log.Debugf("%s request. Waiting for job to complete.", r.Name)
|
||||||
}
|
}
|
||||||
resp := <-newJob.JobResult
|
resp := <-newJob.JobResult
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("%s request. Job complete.", r.Name)
|
log.Debugf("%s request. Job complete.", r.Name)
|
||||||
}
|
}
|
||||||
return resp.Error
|
return resp.Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package wex
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -377,7 +377,7 @@ func (w *WEX) SendAuthenticatedHTTPRequest(method string, values url.Values, res
|
|||||||
hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(w.APISecret))
|
hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(w.APISecret))
|
||||||
|
|
||||||
if w.Verbose {
|
if w.Verbose {
|
||||||
log.Printf("Sending POST request to %s calling method %s with params %s\n",
|
log.Debugf("Sending POST request to %s calling method %s with params %s\n",
|
||||||
w.APIUrlSecondary,
|
w.APIUrlSecondary,
|
||||||
method,
|
method,
|
||||||
encoded)
|
encoded)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package wex
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -11,6 +10,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the WEX go routine
|
// Start starts the WEX go routine
|
||||||
@@ -25,14 +25,14 @@ func (w *WEX) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the WEX wrapper
|
// Run implements the WEX wrapper
|
||||||
func (w *WEX) Run() {
|
func (w *WEX) Run() {
|
||||||
if w.Verbose {
|
if w.Verbose {
|
||||||
log.Printf("%s Websocket: %s.", w.GetName(), common.IsEnabled(w.Websocket.IsEnabled()))
|
log.Debugf("%s Websocket: %s.", w.GetName(), common.IsEnabled(w.Websocket.IsEnabled()))
|
||||||
log.Printf("%s polling delay: %ds.\n", w.GetName(), w.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", w.GetName(), w.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", w.GetName(), len(w.EnabledPairs), w.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", w.GetName(), len(w.EnabledPairs), w.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
exchangeProducts, err := w.GetTradablePairs()
|
exchangeProducts, err := w.GetTradablePairs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get available symbols.\n", w.GetName())
|
log.Errorf("%s Failed to get available symbols.\n", w.GetName())
|
||||||
} else {
|
} else {
|
||||||
forceUpgrade := false
|
forceUpgrade := false
|
||||||
if !common.StringDataContains(w.EnabledPairs, "_") || !common.StringDataContains(w.AvailablePairs, "_") {
|
if !common.StringDataContains(w.EnabledPairs, "_") || !common.StringDataContains(w.AvailablePairs, "_") {
|
||||||
@@ -41,16 +41,16 @@ func (w *WEX) Run() {
|
|||||||
|
|
||||||
if forceUpgrade {
|
if forceUpgrade {
|
||||||
enabledPairs := []string{"BTC_USD", "LTC_USD", "LTC_BTC", "ETH_USD"}
|
enabledPairs := []string{"BTC_USD", "LTC_USD", "LTC_BTC", "ETH_USD"}
|
||||||
log.Println("WARNING: Enabled pairs for WEX reset due to config upgrade, please enable the ones you would like again.")
|
log.Warn("Enabled pairs for WEX reset due to config upgrade, please enable the ones you would like again.")
|
||||||
|
|
||||||
err = w.UpdateCurrencies(enabledPairs, true, true)
|
err = w.UpdateCurrencies(enabledPairs, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", w.GetName())
|
log.Errorf("%s Failed to get config.\n", w.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = w.UpdateCurrencies(exchangeProducts, false, forceUpgrade)
|
err = w.UpdateCurrencies(exchangeProducts, false, forceUpgrade)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to get config.\n", w.GetName())
|
log.Errorf("%s Failed to get config.\n", w.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package yobit
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -12,9 +11,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
"github.com/thrasher-/gocryptotrader/currency/symbol"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -345,7 +345,7 @@ func (y *Yobit) SendAuthenticatedHTTPRequest(path string, params url.Values, res
|
|||||||
hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(y.APISecret))
|
hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(y.APISecret))
|
||||||
|
|
||||||
if y.Verbose {
|
if y.Verbose {
|
||||||
log.Printf("Sending POST request to %s calling path %s with params %s\n", apiPrivateURL, path, encoded)
|
log.Debugf("Sending POST request to %s calling path %s with params %s\n", apiPrivateURL, path, encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := make(map[string]string)
|
headers := make(map[string]string)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package yobit
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the WEX go routine
|
// Start starts the WEX go routine
|
||||||
@@ -26,9 +26,9 @@ func (y *Yobit) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the Yobit wrapper
|
// Run implements the Yobit wrapper
|
||||||
func (y *Yobit) Run() {
|
func (y *Yobit) Run() {
|
||||||
if y.Verbose {
|
if y.Verbose {
|
||||||
log.Printf("%s Websocket: %s.", y.GetName(), common.IsEnabled(y.Websocket.IsEnabled()))
|
log.Debugf("%s Websocket: %s.", y.GetName(), common.IsEnabled(y.Websocket.IsEnabled()))
|
||||||
log.Printf("%s polling delay: %ds.\n", y.GetName(), y.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", y.GetName(), y.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", y.GetName(), len(y.EnabledPairs), y.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", y.GetName(), len(y.EnabledPairs), y.EnabledPairs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
"github.com/thrasher-/gocryptotrader/exchanges/request"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,15 +2,15 @@ package zb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start starts the OKEX go routine
|
// Start starts the OKEX go routine
|
||||||
@@ -25,14 +25,14 @@ func (z *ZB) Start(wg *sync.WaitGroup) {
|
|||||||
// Run implements the OKEX wrapper
|
// Run implements the OKEX wrapper
|
||||||
func (z *ZB) Run() {
|
func (z *ZB) Run() {
|
||||||
if z.Verbose {
|
if z.Verbose {
|
||||||
log.Printf("%s Websocket: %s. (url: %s).\n", z.GetName(), common.IsEnabled(z.Websocket.IsEnabled()), z.WebsocketURL)
|
log.Debugf("%s Websocket: %s. (url: %s).\n", z.GetName(), common.IsEnabled(z.Websocket.IsEnabled()), z.WebsocketURL)
|
||||||
log.Printf("%s polling delay: %ds.\n", z.GetName(), z.RESTPollingDelay)
|
log.Debugf("%s polling delay: %ds.\n", z.GetName(), z.RESTPollingDelay)
|
||||||
log.Printf("%s %d currencies enabled: %s.\n", z.GetName(), len(z.EnabledPairs), z.EnabledPairs)
|
log.Debugf("%s %d currencies enabled: %s.\n", z.GetName(), len(z.EnabledPairs), z.EnabledPairs)
|
||||||
}
|
}
|
||||||
|
|
||||||
markets, err := z.GetMarkets()
|
markets, err := z.GetMarkets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Unable to fetch symbols.\n", z.GetName())
|
log.Errorf("%s Unable to fetch symbols.\n", z.GetName())
|
||||||
} else {
|
} else {
|
||||||
var currencies []string
|
var currencies []string
|
||||||
for x := range markets {
|
for x := range markets {
|
||||||
@@ -41,7 +41,7 @@ func (z *ZB) Run() {
|
|||||||
|
|
||||||
err = z.UpdateCurrencies(currencies, false, false)
|
err = z.UpdateCurrencies(currencies, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s Failed to update available currencies.\n", z.GetName())
|
log.Errorf("%s Failed to update available currencies.\n", z.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
helpers.go
41
helpers.go
@@ -3,11 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
|
||||||
"github.com/thrasher-/gocryptotrader/currency"
|
"github.com/thrasher-/gocryptotrader/currency"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/translation"
|
"github.com/thrasher-/gocryptotrader/currency/translation"
|
||||||
@@ -15,39 +11,10 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
"github.com/thrasher-/gocryptotrader/portfolio"
|
"github.com/thrasher-/gocryptotrader/portfolio"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
logFile = "debug.log"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
logFileHandle *os.File
|
|
||||||
)
|
|
||||||
|
|
||||||
// InitLogFile initialises the log file
|
|
||||||
func InitLogFile(lFile string) error {
|
|
||||||
if logFileHandle != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
logFileHandle, err = os.OpenFile(lFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
wrt := io.MultiWriter(os.Stdout, logFileHandle)
|
|
||||||
log.SetOutput(wrt)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLogFile returns the debug.log file
|
|
||||||
func GetLogFile(dir string) string {
|
|
||||||
return dir + common.GetOSPathSlash() + logFile
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAllAvailablePairs returns a list of all available pairs on either enabled
|
// GetAllAvailablePairs returns a list of all available pairs on either enabled
|
||||||
// or disabled exchanges
|
// or disabled exchanges
|
||||||
func GetAllAvailablePairs(enabledExchangesOnly bool) []pair.CurrencyPair {
|
func GetAllAvailablePairs(enabledExchangesOnly bool) []pair.CurrencyPair {
|
||||||
@@ -369,7 +336,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
|
|||||||
if total <= 0 {
|
if total <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("Portfolio: Adding new exchange address: %s, %s, %f, %s\n",
|
log.Debugf("Portfolio: Adding new exchange address: %s, %s, %f, %s\n",
|
||||||
exchangeName, currencyName, total, portfolio.PortfolioAddressExchange)
|
exchangeName, currencyName, total, portfolio.PortfolioAddressExchange)
|
||||||
port.Addresses = append(
|
port.Addresses = append(
|
||||||
port.Addresses,
|
port.Addresses,
|
||||||
@@ -378,7 +345,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if total <= 0 {
|
if total <= 0 {
|
||||||
log.Printf("Portfolio: Removing %s %s entry.\n", exchangeName,
|
log.Debugf("Portfolio: Removing %s %s entry.\n", exchangeName,
|
||||||
currencyName)
|
currencyName)
|
||||||
port.RemoveExchangeAddress(exchangeName, currencyName)
|
port.RemoveExchangeAddress(exchangeName, currencyName)
|
||||||
} else {
|
} else {
|
||||||
@@ -387,7 +354,7 @@ func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if balance != total {
|
if balance != total {
|
||||||
log.Printf("Portfolio: Updating %s %s entry with balance %f.\n",
|
log.Debugf("Portfolio: Updating %s %s entry with balance %f.\n",
|
||||||
exchangeName, currencyName, total)
|
exchangeName, currencyName, total)
|
||||||
port.UpdateExchangeAddressBalance(exchangeName, currencyName, total)
|
port.UpdateExchangeAddressBalance(exchangeName, currencyName, total)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -344,16 +344,16 @@ func TestGetExchangeHighestPriceByCurrencyPair(t *testing.T) {
|
|||||||
stats.Add("Bitstamp", p, ticker.Spot, 1337, 10000)
|
stats.Add("Bitstamp", p, ticker.Spot, 1337, 10000)
|
||||||
exchange, err := GetExchangeHighestPriceByCurrencyPair(p, ticker.Spot)
|
exchange, err := GetExchangeHighestPriceByCurrencyPair(p, ticker.Spot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if exchange != "Bitstamp" {
|
if exchange != "Bitstamp" {
|
||||||
log.Fatal("Unexpected result")
|
t.Error("Unexpected result")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = GetExchangeHighestPriceByCurrencyPair(pair.NewCurrencyPair("BTC", "AUD"), ticker.Spot)
|
_, err = GetExchangeHighestPriceByCurrencyPair(pair.NewCurrencyPair("BTC", "AUD"), ticker.Spot)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Fatal("Unexpected reuslt")
|
t.Error("Unexpected result")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,15 +365,15 @@ func TestGetExchangeLowestPriceByCurrencyPair(t *testing.T) {
|
|||||||
stats.Add("Bitstamp", p, ticker.Spot, 1337, 10000)
|
stats.Add("Bitstamp", p, ticker.Spot, 1337, 10000)
|
||||||
exchange, err := GetExchangeLowestPriceByCurrencyPair(p, ticker.Spot)
|
exchange, err := GetExchangeLowestPriceByCurrencyPair(p, ticker.Spot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if exchange != "Bitfinex" {
|
if exchange != "Bitfinex" {
|
||||||
log.Fatal("Unexpected result")
|
t.Error("Unexpected result")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = GetExchangeLowestPriceByCurrencyPair(pair.NewCurrencyPair("BTC", "AUD"), ticker.Spot)
|
_, err = GetExchangeLowestPriceByCurrencyPair(pair.NewCurrencyPair("BTC", "AUD"), ticker.Spot)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Fatal("Unexpected reuslt")
|
t.Error("Unexpected reuslt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
120
logger/logger.go
Normal file
120
logger/logger.go
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
setDefaultOutputs()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetupLogger configure logger instance with user provided settings
|
||||||
|
func SetupLogger() (err error) {
|
||||||
|
if *Logger.Enabled {
|
||||||
|
err = setupOutputs()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logLevel()
|
||||||
|
if Logger.ColourOutput {
|
||||||
|
colourOutput()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearAllLoggers()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// setDefaultOutputs() this setups defaults used by the logger
|
||||||
|
// This allows it to be used without any user configuration
|
||||||
|
func setDefaultOutputs() {
|
||||||
|
debugLogger = log.New(os.Stdout,
|
||||||
|
"[DEBUG]: ",
|
||||||
|
log.Ldate|log.Ltime)
|
||||||
|
|
||||||
|
infoLogger = log.New(os.Stdout,
|
||||||
|
"[INFO]: ",
|
||||||
|
log.Ldate|log.Ltime)
|
||||||
|
|
||||||
|
warnLogger = log.New(os.Stdout,
|
||||||
|
"[WARN]: ",
|
||||||
|
log.Ldate|log.Ltime)
|
||||||
|
|
||||||
|
errorLogger = log.New(os.Stdout,
|
||||||
|
"[ERROR]: ",
|
||||||
|
log.Ldate|log.Ltime)
|
||||||
|
|
||||||
|
fatalLogger = log.New(os.Stdout,
|
||||||
|
"[FATAL]: ",
|
||||||
|
log.Ldate|log.Ltime)
|
||||||
|
}
|
||||||
|
|
||||||
|
// colorOutput() sets the prefix of each log type to matching colour
|
||||||
|
// TODO: add windows support
|
||||||
|
func colourOutput() {
|
||||||
|
if runtime.GOOS != "windows" {
|
||||||
|
debugLogger.SetPrefix("\033[34m[DEBUG]\033[0m: ")
|
||||||
|
infoLogger.SetPrefix("\033[32m[INFO]\033[0m: ")
|
||||||
|
warnLogger.SetPrefix("\033[33m[WARN]\033[0m: ")
|
||||||
|
errorLogger.SetPrefix("\033[31m[ERROR]\033[0m: ")
|
||||||
|
fatalLogger.SetPrefix("\033[31m[FATAL]\033[0m: ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clearAllLoggers() sets all logger flags to 0 and outputs to Discard
|
||||||
|
func clearAllLoggers() {
|
||||||
|
debugLogger.SetFlags(0)
|
||||||
|
infoLogger.SetFlags(0)
|
||||||
|
warnLogger.SetFlags(0)
|
||||||
|
errorLogger.SetFlags(0)
|
||||||
|
fatalLogger.SetFlags(0)
|
||||||
|
|
||||||
|
debugLogger.SetOutput(ioutil.Discard)
|
||||||
|
infoLogger.SetOutput(ioutil.Discard)
|
||||||
|
warnLogger.SetOutput(ioutil.Discard)
|
||||||
|
errorLogger.SetOutput(ioutil.Discard)
|
||||||
|
fatalLogger.SetOutput(ioutil.Discard)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setupOutputs() sets up the io.writer to use for logging
|
||||||
|
// TODO: Fix up rotating at the moment its a quick job
|
||||||
|
func setupOutputs() (err error) {
|
||||||
|
if len(Logger.File) > 0 {
|
||||||
|
logFile := path.Join(LogPath, Logger.File)
|
||||||
|
if Logger.Rotate {
|
||||||
|
if _, err = os.Stat(logFile); !os.IsNotExist(err) {
|
||||||
|
currentTime := time.Now()
|
||||||
|
newName := currentTime.Format("2006-01-02 15-04-05")
|
||||||
|
newFile := newName + " " + Logger.File
|
||||||
|
err = os.Rename(logFile, path.Join(LogPath, newFile))
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Failed to rename old log file %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logFileHandle, err = os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logOutput = io.MultiWriter(os.Stdout, logFileHandle)
|
||||||
|
} else {
|
||||||
|
logOutput = os.Stdout
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseLogFile close the handler for any open log files
|
||||||
|
func CloseLogFile() (err error) {
|
||||||
|
if logFileHandle != nil {
|
||||||
|
err = logFileHandle.Close()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
33
logger/logger_levels.go
Normal file
33
logger/logger_levels.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func logLevel() {
|
||||||
|
clearAllLoggers()
|
||||||
|
enabledLevels := strings.Split(Logger.Level, "|")
|
||||||
|
|
||||||
|
for x := range enabledLevels {
|
||||||
|
switch level := enabledLevels[x]; level {
|
||||||
|
case "DEBUG":
|
||||||
|
debugLogger.SetOutput(logOutput)
|
||||||
|
debugLogger.SetFlags(log.Ldate | log.Ltime)
|
||||||
|
case "INFO":
|
||||||
|
infoLogger.SetOutput(logOutput)
|
||||||
|
infoLogger.SetFlags(log.Ldate | log.Ltime)
|
||||||
|
case "WARN":
|
||||||
|
warnLogger.SetOutput(logOutput)
|
||||||
|
warnLogger.SetFlags(log.Ldate | log.Ltime)
|
||||||
|
case "ERROR":
|
||||||
|
errorLogger.SetOutput(logOutput)
|
||||||
|
errorLogger.SetFlags(log.Ldate | log.Ltime)
|
||||||
|
case "FATAL":
|
||||||
|
fatalLogger.SetOutput(logOutput)
|
||||||
|
fatalLogger.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
75
logger/logger_test.go
Normal file
75
logger/logger_test.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
trueptr = func(b bool) *bool { return &b }(true)
|
||||||
|
falseptr = func(b bool) *bool { return &b }(false)
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCloseLogFile(t *testing.T) {
|
||||||
|
Logger = &Logging{
|
||||||
|
Enabled: trueptr,
|
||||||
|
Level: "DEBUG",
|
||||||
|
ColourOutput: false,
|
||||||
|
File: "",
|
||||||
|
Rotate: false,
|
||||||
|
}
|
||||||
|
SetupLogger()
|
||||||
|
err := CloseLogFile()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("CloseLogFile failed with %v", err)
|
||||||
|
}
|
||||||
|
os.Remove(path.Join(LogPath, Logger.File))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetupOutputsValidPath(t *testing.T) {
|
||||||
|
Logger.Enabled = trueptr
|
||||||
|
Logger.File = "debug.txt"
|
||||||
|
LogPath = "../testdata/"
|
||||||
|
err := setupOutputs()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("SetupOutputs failed expected nil got %v", err)
|
||||||
|
}
|
||||||
|
os.Remove(path.Join(LogPath, Logger.File))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetupOutputsInValidPath(t *testing.T) {
|
||||||
|
Logger.Enabled = trueptr
|
||||||
|
Logger.File = "debug.txt"
|
||||||
|
LogPath = "../testdataa/"
|
||||||
|
err := setupOutputs()
|
||||||
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("SetupOutputs failed expected %v got %v", os.ErrNotExist, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Remove(path.Join(LogPath, Logger.File))
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkDebugf(b *testing.B) {
|
||||||
|
Logger = &Logging{
|
||||||
|
Enabled: trueptr,
|
||||||
|
Level: "DEBUG",
|
||||||
|
ColourOutput: false,
|
||||||
|
File: "",
|
||||||
|
Rotate: false,
|
||||||
|
}
|
||||||
|
SetupLogger()
|
||||||
|
b.ResetTimer()
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
Debugf("This is a debug benchmark %d", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkDebugfLoggerDisabled(b *testing.B) {
|
||||||
|
clearAllLoggers()
|
||||||
|
b.ResetTimer()
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
Debugf("this is a debug benchmark")
|
||||||
|
}
|
||||||
|
}
|
||||||
34
logger/logger_types.go
Normal file
34
logger/logger_types.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Logging struct that holds all user configurable options for the logger
|
||||||
|
type Logging struct {
|
||||||
|
Enabled *bool `json:"enabled,omitempty"`
|
||||||
|
File string `json:"file"`
|
||||||
|
ColourOutput bool `json:"colour"`
|
||||||
|
Level string `json:"level"`
|
||||||
|
Rotate bool `json:"rotate"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
debugLogger *log.Logger
|
||||||
|
infoLogger *log.Logger
|
||||||
|
warnLogger *log.Logger
|
||||||
|
errorLogger *log.Logger
|
||||||
|
fatalLogger *log.Logger
|
||||||
|
|
||||||
|
logFileHandle *os.File
|
||||||
|
|
||||||
|
logOutput io.Writer
|
||||||
|
|
||||||
|
// LogPath location to store logs in
|
||||||
|
LogPath string
|
||||||
|
|
||||||
|
// Logger create a pointer to Logging struct for holding data
|
||||||
|
Logger = &Logging{}
|
||||||
|
)
|
||||||
80
logger/loggers.go
Normal file
80
logger/loggers.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Info handler takes any input returns unformatted output to infoLogger writer
|
||||||
|
func Info(v ...interface{}) {
|
||||||
|
infoLogger.Print(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Infof handler takes any input infoLogger returns formatted output to infoLogger writer
|
||||||
|
func Infof(data string, v ...interface{}) {
|
||||||
|
infoLogger.Printf(data, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Infoln handler takes any input infoLogger returns formatted output to infoLogger writer
|
||||||
|
func Infoln(v ...interface{}) {
|
||||||
|
infoLogger.Println(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print aliased to Standard log.Print
|
||||||
|
var Print = log.Print
|
||||||
|
|
||||||
|
// Printf aliased to Standard log.Printf
|
||||||
|
var Printf = log.Printf
|
||||||
|
|
||||||
|
// Println aliased to Standard log.Println
|
||||||
|
var Println = log.Println
|
||||||
|
|
||||||
|
// Debug handler takes any input returns unformatted output to infoLogger writer
|
||||||
|
func Debug(v ...interface{}) {
|
||||||
|
debugLogger.Print(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debugf handler takes any input infoLogger returns formatted output to infoLogger writer
|
||||||
|
func Debugf(data string, v ...interface{}) {
|
||||||
|
debugLogger.Printf(data, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debugln handler takes any input infoLogger returns formatted output to infoLogger writer
|
||||||
|
func Debugln(v ...interface{}) {
|
||||||
|
debugLogger.Println(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn handler takes any input returns unformatted output to warnLogger writer
|
||||||
|
func Warn(v ...interface{}) {
|
||||||
|
warnLogger.Print(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warnf handler takes any input returns unformatted output to warnLogger writer
|
||||||
|
func Warnf(data string, v ...interface{}) {
|
||||||
|
warnLogger.Printf(data, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error handler takes any input returns unformatted output to errorLogger writer
|
||||||
|
func Error(v ...interface{}) {
|
||||||
|
errorLogger.Print(v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf handler takes any input returns unformatted output to errorLogger writer
|
||||||
|
func Errorf(data string, v ...interface{}) {
|
||||||
|
errorLogger.Printf(data, v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal handler takes any input returns unformatted output to fatalLogger writer
|
||||||
|
func Fatal(v ...interface{}) {
|
||||||
|
// Send to Output instead of Fatal to allow us to increase the output depth by 1 to make sure the correct file is displayed
|
||||||
|
fatalLogger.Output(2, fmt.Sprint(v...))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf handler takes any input returns unformatted output to fatalLogger writer
|
||||||
|
func Fatalf(data string, v ...interface{}) {
|
||||||
|
// Send to Output instead of Fatal to allow us to increase the output depth by 1 to make sure the correct file is displayed
|
||||||
|
fatalLogger.Output(2, fmt.Sprintf(data, v...))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
73
main.go
73
main.go
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -16,7 +15,8 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/config"
|
"github.com/thrasher-/gocryptotrader/config"
|
||||||
"github.com/thrasher-/gocryptotrader/currency"
|
"github.com/thrasher-/gocryptotrader/currency"
|
||||||
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
"github.com/thrasher-/gocryptotrader/portfolio"
|
"github.com/thrasher-/gocryptotrader/portfolio"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,7 +31,6 @@ type Bot struct {
|
|||||||
dryRun bool
|
dryRun bool
|
||||||
configFile string
|
configFile string
|
||||||
dataDir string
|
dataDir string
|
||||||
logFile string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const banner = `
|
const banner = `
|
||||||
@@ -76,7 +75,7 @@ func main() {
|
|||||||
fmt.Println(BuildVersion(false))
|
fmt.Println(BuildVersion(false))
|
||||||
|
|
||||||
bot.config = &config.Cfg
|
bot.config = &config.Cfg
|
||||||
log.Printf("Loading config file %s..\n", bot.configFile)
|
log.Debugf("Loading config file %s..\n", bot.configFile)
|
||||||
err = bot.config.LoadConfig(bot.configFile)
|
err = bot.config.LoadConfig(bot.configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load config. Err: %s", err)
|
log.Fatalf("Failed to load config. Err: %s", err)
|
||||||
@@ -86,46 +85,48 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to open/create data directory: %s. Err: %s", bot.dataDir, err)
|
log.Fatalf("Failed to open/create data directory: %s. Err: %s", bot.dataDir, err)
|
||||||
}
|
}
|
||||||
log.Printf("Using data directory: %s.\n", bot.dataDir)
|
log.Debugf("Using data directory: %s.\n", bot.dataDir)
|
||||||
|
|
||||||
bot.logFile = GetLogFile(bot.dataDir)
|
err = bot.config.CheckLoggerConfig()
|
||||||
err = InitLogFile(bot.logFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to create log file writer. Err: %s", err)
|
log.Errorf("Failed to configure logger reason: %s", err)
|
||||||
} else {
|
}
|
||||||
log.Printf("Using log file: %s.\n", bot.logFile)
|
|
||||||
|
err = log.SetupLogger()
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to setup logger reason: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustGoMaxProcs()
|
AdjustGoMaxProcs()
|
||||||
log.Printf("Bot '%s' started.\n", bot.config.Name)
|
log.Debugf("Bot '%s' started.\n", bot.config.Name)
|
||||||
log.Printf("Bot dry run mode: %v.\n", common.IsEnabled(bot.dryRun))
|
log.Debugf("Bot dry run mode: %v.\n", common.IsEnabled(bot.dryRun))
|
||||||
|
|
||||||
log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n",
|
log.Debugf("Available Exchanges: %d. Enabled Exchanges: %d.\n",
|
||||||
len(bot.config.Exchanges),
|
len(bot.config.Exchanges),
|
||||||
bot.config.CountEnabledExchanges())
|
bot.config.CountEnabledExchanges())
|
||||||
|
|
||||||
common.HTTPClient = common.NewHTTPClientWithTimeout(bot.config.GlobalHTTPTimeout)
|
common.HTTPClient = common.NewHTTPClientWithTimeout(bot.config.GlobalHTTPTimeout)
|
||||||
log.Printf("Global HTTP request timeout: %v.\n", common.HTTPClient.Timeout)
|
log.Debugf("Global HTTP request timeout: %v.\n", common.HTTPClient.Timeout)
|
||||||
|
|
||||||
SetupExchanges()
|
SetupExchanges()
|
||||||
if len(bot.exchanges) == 0 {
|
if len(bot.exchanges) == 0 {
|
||||||
log.Fatalf("No exchanges were able to be loaded. Exiting")
|
log.Fatalf("No exchanges were able to be loaded. Exiting")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Starting communication mediums..")
|
log.Debugf("Starting communication mediums..")
|
||||||
bot.comms = communications.NewComm(bot.config.GetCommunicationsConfig())
|
bot.comms = communications.NewComm(bot.config.GetCommunicationsConfig())
|
||||||
bot.comms.GetEnabledCommunicationMediums()
|
bot.comms.GetEnabledCommunicationMediums()
|
||||||
|
|
||||||
log.Printf("Fiat display currency: %s.", bot.config.Currency.FiatDisplayCurrency)
|
log.Debugf("Fiat display currency: %s.", bot.config.Currency.FiatDisplayCurrency)
|
||||||
currency.BaseCurrency = bot.config.Currency.FiatDisplayCurrency
|
currency.BaseCurrency = bot.config.Currency.FiatDisplayCurrency
|
||||||
currency.FXProviders = forexprovider.StartFXService(bot.config.GetCurrencyConfig().ForexProviders)
|
currency.FXProviders = forexprovider.StartFXService(bot.config.GetCurrencyConfig().ForexProviders)
|
||||||
log.Printf("Primary forex conversion provider: %s.\n", bot.config.GetPrimaryForexProvider())
|
log.Debugf("Primary forex conversion provider: %s.\n", bot.config.GetPrimaryForexProvider())
|
||||||
err = bot.config.RetrieveConfigCurrencyPairs(true)
|
err = bot.config.RetrieveConfigCurrencyPairs(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to retrieve config currency pairs. Error: %s", err)
|
log.Fatalf("Failed to retrieve config currency pairs. Error: %s", err)
|
||||||
}
|
}
|
||||||
log.Println("Successfully retrieved config currencies.")
|
log.Debugf("Successfully retrieved config currencies.")
|
||||||
log.Println("Fetching currency data from forex provider..")
|
log.Debugf("Fetching currency data from forex provider..")
|
||||||
err = currency.SeedCurrencyData(common.JoinStrings(currency.FiatCurrencies, ","))
|
err = currency.SeedCurrencyData(common.JoinStrings(currency.FiatCurrencies, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to fetch forex data. Error: %s", err)
|
log.Fatalf("Unable to fetch forex data. Error: %s", err)
|
||||||
@@ -137,7 +138,7 @@ func main() {
|
|||||||
|
|
||||||
if bot.config.Webserver.Enabled {
|
if bot.config.Webserver.Enabled {
|
||||||
listenAddr := bot.config.Webserver.ListenAddress
|
listenAddr := bot.config.Webserver.ListenAddress
|
||||||
log.Printf(
|
log.Debugf(
|
||||||
"HTTP Webserver support enabled. Listen URL: http://%s:%d/\n",
|
"HTTP Webserver support enabled. Listen URL: http://%s:%d/\n",
|
||||||
common.ExtractHost(listenAddr), common.ExtractPort(listenAddr),
|
common.ExtractHost(listenAddr), common.ExtractPort(listenAddr),
|
||||||
)
|
)
|
||||||
@@ -150,11 +151,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Println("HTTP Webserver started successfully.")
|
log.Debugln("HTTP Webserver started successfully.")
|
||||||
log.Println("Starting websocket handler.")
|
log.Debugln("Starting websocket handler.")
|
||||||
StartWebsocketHandler()
|
StartWebsocketHandler()
|
||||||
} else {
|
} else {
|
||||||
log.Println("HTTP RESTful Webserver support disabled.")
|
log.Debugln("HTTP RESTful Webserver support disabled.")
|
||||||
}
|
}
|
||||||
|
|
||||||
go portfolio.StartPortfolioWatcher()
|
go portfolio.StartPortfolioWatcher()
|
||||||
@@ -169,24 +170,24 @@ func main() {
|
|||||||
|
|
||||||
// AdjustGoMaxProcs adjusts the maximum processes that the CPU can handle.
|
// AdjustGoMaxProcs adjusts the maximum processes that the CPU can handle.
|
||||||
func AdjustGoMaxProcs() {
|
func AdjustGoMaxProcs() {
|
||||||
log.Println("Adjusting bot runtime performance..")
|
log.Debugln("Adjusting bot runtime performance..")
|
||||||
maxProcsEnv := os.Getenv("GOMAXPROCS")
|
maxProcsEnv := os.Getenv("GOMAXPROCS")
|
||||||
maxProcs := runtime.NumCPU()
|
maxProcs := runtime.NumCPU()
|
||||||
log.Println("Number of CPU's detected:", maxProcs)
|
log.Debugln("Number of CPU's detected:", maxProcs)
|
||||||
|
|
||||||
if maxProcsEnv != "" {
|
if maxProcsEnv != "" {
|
||||||
log.Println("GOMAXPROCS env =", maxProcsEnv)
|
log.Debugln("GOMAXPROCS env =", maxProcsEnv)
|
||||||
env, err := strconv.Atoi(maxProcsEnv)
|
env, err := strconv.Atoi(maxProcsEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to convert GOMAXPROCS to int, using", maxProcs)
|
log.Debugf("Unable to convert GOMAXPROCS to int, using %d", maxProcs)
|
||||||
} else {
|
} else {
|
||||||
maxProcs = env
|
maxProcs = env
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i := runtime.GOMAXPROCS(maxProcs); i != maxProcs {
|
if i := runtime.GOMAXPROCS(maxProcs); i != maxProcs {
|
||||||
log.Fatal("Go Max Procs were not set correctly.")
|
log.Error("Go Max Procs were not set correctly.")
|
||||||
}
|
}
|
||||||
log.Println("Set GOMAXPROCS to:", maxProcs)
|
log.Debugln("Set GOMAXPROCS to:", maxProcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleInterrupt monitors and captures the SIGTERM in a new goroutine then
|
// HandleInterrupt monitors and captures the SIGTERM in a new goroutine then
|
||||||
@@ -196,14 +197,14 @@ func HandleInterrupt() {
|
|||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
go func() {
|
go func() {
|
||||||
sig := <-c
|
sig := <-c
|
||||||
log.Printf("Captured %v, shutdown requested.", sig)
|
log.Debugf("Captured %v, shutdown requested.", sig)
|
||||||
bot.shutdown <- true
|
bot.shutdown <- true
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown correctly shuts down bot saving configuration files
|
// Shutdown correctly shuts down bot saving configuration files
|
||||||
func Shutdown() {
|
func Shutdown() {
|
||||||
log.Println("Bot shutting down..")
|
log.Debugln("Bot shutting down..")
|
||||||
|
|
||||||
if len(portfolio.Portfolio.Addresses) != 0 {
|
if len(portfolio.Portfolio.Addresses) != 0 {
|
||||||
bot.config.Portfolio = portfolio.Portfolio
|
bot.config.Portfolio = portfolio.Portfolio
|
||||||
@@ -213,16 +214,14 @@ func Shutdown() {
|
|||||||
err := bot.config.SaveConfig(bot.configFile)
|
err := bot.config.SaveConfig(bot.configFile)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to save config.")
|
log.Warn("Unable to save config.")
|
||||||
} else {
|
} else {
|
||||||
log.Println("Config file saved successfully.")
|
log.Debugln("Config file saved successfully.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Exiting.")
|
log.Debugln("Exiting.")
|
||||||
|
|
||||||
if logFileHandle != nil {
|
log.CloseLogFile()
|
||||||
logFileHandle.Close()
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package portfolio
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/thrasher-/gocryptotrader/common"
|
"github.com/thrasher-/gocryptotrader/common"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -390,7 +390,7 @@ func (p *Base) SeedPortfolio(port Base) {
|
|||||||
// StartPortfolioWatcher observes the portfolio object
|
// StartPortfolioWatcher observes the portfolio object
|
||||||
func StartPortfolioWatcher() {
|
func StartPortfolioWatcher() {
|
||||||
addrCount := len(Portfolio.Addresses)
|
addrCount := len(Portfolio.Addresses)
|
||||||
log.Printf(
|
log.Debugf(
|
||||||
"PortfolioWatcher started: Have %d entries in portfolio.\n", addrCount,
|
"PortfolioWatcher started: Have %d entries in portfolio.\n", addrCount,
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
@@ -398,7 +398,7 @@ func StartPortfolioWatcher() {
|
|||||||
for key, value := range data {
|
for key, value := range data {
|
||||||
success := Portfolio.UpdatePortfolio(value, key)
|
success := Portfolio.UpdatePortfolio(value, key)
|
||||||
if success {
|
if success {
|
||||||
log.Printf(
|
log.Debugf(
|
||||||
"PortfolioWatcher: Successfully updated address balance for %s address(es) %s\n",
|
"PortfolioWatcher: Successfully updated address balance for %s address(es) %s\n",
|
||||||
key, value,
|
key, value,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RESTLogger logs the requests internally
|
// RESTLogger logs the requests internally
|
||||||
@@ -17,7 +17,7 @@ func RESTLogger(inner http.Handler, name string) http.Handler {
|
|||||||
|
|
||||||
inner.ServeHTTP(w, r)
|
inner.ServeHTTP(w, r)
|
||||||
|
|
||||||
log.Printf(
|
log.Debugf(
|
||||||
"%s\t%s\t%s\t%s",
|
"%s\t%s\t%s\t%s",
|
||||||
r.Method,
|
r.Method,
|
||||||
r.RequestURI,
|
r.RequestURI,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@@ -10,6 +9,7 @@ import (
|
|||||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AllEnabledExchangeOrderbooks holds the enabled exchange orderbooks
|
// AllEnabledExchangeOrderbooks holds the enabled exchange orderbooks
|
||||||
@@ -50,7 +50,7 @@ func RESTfulJSONResponse(w http.ResponseWriter, r *http.Request, response interf
|
|||||||
|
|
||||||
// RESTfulError prints the REST method and error
|
// RESTfulError prints the REST method and error
|
||||||
func RESTfulError(method string, err error) {
|
func RESTfulError(method string, err error) {
|
||||||
log.Printf("RESTful %s: server failed to send JSON response. Error %s",
|
log.Errorf("RESTful %s: server failed to send JSON response. Error %s",
|
||||||
method, err)
|
method, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ func RESTGetOrderbook(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
response, err := GetSpecificOrderbook(currency, exchange, assetType)
|
response, err := GetSpecificOrderbook(currency, exchange, assetType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to fetch orderbook for %s currency: %s\n", exchange,
|
log.Errorf("Failed to fetch orderbook for %s currency: %s\n", exchange,
|
||||||
currency)
|
currency)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ func GetAllActiveOrderbooks() []EnabledExchangeOrderbooks {
|
|||||||
currencies := individualBot.GetEnabledCurrencies()
|
currencies := individualBot.GetEnabledCurrencies()
|
||||||
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get %s exchange asset types. Error: %s",
|
log.Errorf("failed to get %s exchange asset types. Error: %s",
|
||||||
exchangeName, err)
|
exchangeName, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ func GetAllActiveOrderbooks() []EnabledExchangeOrderbooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get %s %s orderbook. Error: %s",
|
log.Errorf("failed to get %s %s orderbook. Error: %s",
|
||||||
currency.Pair().String(),
|
currency.Pair().String(),
|
||||||
exchangeName,
|
exchangeName,
|
||||||
err)
|
err)
|
||||||
@@ -193,7 +193,7 @@ func RESTGetTicker(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
response, err := GetSpecificTicker(currency, exchange, assetType)
|
response, err := GetSpecificTicker(currency, exchange, assetType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to fetch ticker for %s currency: %s\n", exchange,
|
log.Errorf("Failed to fetch ticker for %s currency: %s\n", exchange,
|
||||||
currency)
|
currency)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ func GetAllActiveTickers() []EnabledExchangeCurrencies {
|
|||||||
currency := x
|
currency := x
|
||||||
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get %s exchange asset types. Error: %s",
|
log.Errorf("failed to get %s exchange asset types. Error: %s",
|
||||||
exchangeName, err)
|
exchangeName, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ func GetAllActiveTickers() []EnabledExchangeCurrencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get %s %s ticker. Error: %s",
|
log.Errorf("failed to get %s %s ticker. Error: %s",
|
||||||
currency.Pair().String(),
|
currency.Pair().String(),
|
||||||
exchangeName,
|
exchangeName,
|
||||||
err)
|
err)
|
||||||
@@ -267,12 +267,12 @@ func GetAllEnabledExchangeAccountInfo() AllEnabledExchangeAccounts {
|
|||||||
for _, individualBot := range bot.exchanges {
|
for _, individualBot := range bot.exchanges {
|
||||||
if individualBot != nil && individualBot.IsEnabled() {
|
if individualBot != nil && individualBot.IsEnabled() {
|
||||||
if !individualBot.GetAuthenticatedAPISupport() {
|
if !individualBot.GetAuthenticatedAPISupport() {
|
||||||
log.Printf("GetAllEnabledExchangeAccountInfo: Skippping %s due to disabled authenticated API support.", individualBot.GetName())
|
log.Warnf("GetAllEnabledExchangeAccountInfo: Skippping %s due to disabled authenticated API support.", individualBot.GetName())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
individualExchange, err := individualBot.GetAccountInfo()
|
individualExchange, err := individualBot.GetAccountInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error encountered retrieving exchange account info for %s. Error %s",
|
log.Errorf("Error encountered retrieving exchange account info for %s. Error %s",
|
||||||
individualBot.GetName(), err)
|
individualBot.GetName(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
77
routines.go
77
routines.go
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -15,12 +14,13 @@ import (
|
|||||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||||
|
log "github.com/thrasher-/gocryptotrader/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func printCurrencyFormat(price float64) string {
|
func printCurrencyFormat(price float64) string {
|
||||||
displaySymbol, err := symbol.GetSymbolByCurrencyName(bot.config.Currency.FiatDisplayCurrency)
|
displaySymbol, err := symbol.GetSymbolByCurrencyName(bot.config.Currency.FiatDisplayCurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get display symbol: %s", err)
|
log.Errorf("Failed to get display symbol: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s%.8f", displaySymbol, price)
|
return fmt.Sprintf("%s%.8f", displaySymbol, price)
|
||||||
@@ -30,17 +30,17 @@ func printConvertCurrencyFormat(origCurrency string, origPrice float64) string {
|
|||||||
displayCurrency := bot.config.Currency.FiatDisplayCurrency
|
displayCurrency := bot.config.Currency.FiatDisplayCurrency
|
||||||
conv, err := currency.ConvertCurrency(origPrice, origCurrency, displayCurrency)
|
conv, err := currency.ConvertCurrency(origPrice, origCurrency, displayCurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to convert currency: %s", err)
|
log.Errorf("Failed to convert currency: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
displaySymbol, err := symbol.GetSymbolByCurrencyName(displayCurrency)
|
displaySymbol, err := symbol.GetSymbolByCurrencyName(displayCurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get display symbol: %s", err)
|
log.Errorf("Failed to get display symbol: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
origSymbol, err := symbol.GetSymbolByCurrencyName(origCurrency)
|
origSymbol, err := symbol.GetSymbolByCurrencyName(origCurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get original currency symbol: %s", err)
|
log.Errorf("Failed to get original currency symbol: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s%.2f %s (%s%.2f %s)",
|
return fmt.Sprintf("%s%.2f %s (%s%.2f %s)",
|
||||||
@@ -55,7 +55,7 @@ func printConvertCurrencyFormat(origCurrency string, origPrice float64) string {
|
|||||||
|
|
||||||
func printTickerSummary(result ticker.Price, p pair.CurrencyPair, assetType, exchangeName string, err error) {
|
func printTickerSummary(result ticker.Price, p pair.CurrencyPair, assetType, exchangeName string, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get %s %s ticker. Error: %s",
|
log.Errorf("Failed to get %s %s ticker. Error: %s",
|
||||||
p.Pair().String(),
|
p.Pair().String(),
|
||||||
exchangeName,
|
exchangeName,
|
||||||
err)
|
err)
|
||||||
@@ -65,7 +65,7 @@ func printTickerSummary(result ticker.Price, p pair.CurrencyPair, assetType, exc
|
|||||||
stats.Add(exchangeName, p, assetType, result.Last, result.Volume)
|
stats.Add(exchangeName, p, assetType, result.Last, result.Volume)
|
||||||
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.String() != bot.config.Currency.FiatDisplayCurrency {
|
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.String() != bot.config.Currency.FiatDisplayCurrency {
|
||||||
origCurrency := p.SecondCurrency.Upper().String()
|
origCurrency := p.SecondCurrency.Upper().String()
|
||||||
log.Printf("%s %s %s: TICKER: Last %s Ask %s Bid %s High %s Low %s Volume %.8f",
|
log.Infof("%s %s %s: TICKER: Last %s Ask %s Bid %s High %s Low %s Volume %.8f",
|
||||||
exchangeName,
|
exchangeName,
|
||||||
exchange.FormatCurrency(p).String(),
|
exchange.FormatCurrency(p).String(),
|
||||||
assetType,
|
assetType,
|
||||||
@@ -77,7 +77,7 @@ func printTickerSummary(result ticker.Price, p pair.CurrencyPair, assetType, exc
|
|||||||
result.Volume)
|
result.Volume)
|
||||||
} else {
|
} else {
|
||||||
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.Upper().String() == bot.config.Currency.FiatDisplayCurrency {
|
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.Upper().String() == bot.config.Currency.FiatDisplayCurrency {
|
||||||
log.Printf("%s %s %s: TICKER: Last %s Ask %s Bid %s High %s Low %s Volume %.8f",
|
log.Infof("%s %s %s: TICKER: Last %s Ask %s Bid %s High %s Low %s Volume %.8f",
|
||||||
exchangeName,
|
exchangeName,
|
||||||
exchange.FormatCurrency(p).String(),
|
exchange.FormatCurrency(p).String(),
|
||||||
assetType,
|
assetType,
|
||||||
@@ -88,7 +88,7 @@ func printTickerSummary(result ticker.Price, p pair.CurrencyPair, assetType, exc
|
|||||||
printCurrencyFormat(result.Low),
|
printCurrencyFormat(result.Low),
|
||||||
result.Volume)
|
result.Volume)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%s %s %s: TICKER: Last %.8f Ask %.8f Bid %.8f High %.8f Low %.8f Volume %.8f",
|
log.Infof("%s %s %s: TICKER: Last %.8f Ask %.8f Bid %.8f High %.8f Low %.8f Volume %.8f",
|
||||||
exchangeName,
|
exchangeName,
|
||||||
exchange.FormatCurrency(p).String(),
|
exchange.FormatCurrency(p).String(),
|
||||||
assetType,
|
assetType,
|
||||||
@@ -104,7 +104,7 @@ func printTickerSummary(result ticker.Price, p pair.CurrencyPair, assetType, exc
|
|||||||
|
|
||||||
func printOrderbookSummary(result orderbook.Base, p pair.CurrencyPair, assetType, exchangeName string, err error) {
|
func printOrderbookSummary(result orderbook.Base, p pair.CurrencyPair, assetType, exchangeName string, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get %s %s orderbook. Error: %s",
|
log.Errorf("Failed to get %s %s orderbook. Error: %s",
|
||||||
p.Pair().String(),
|
p.Pair().String(),
|
||||||
exchangeName,
|
exchangeName,
|
||||||
err)
|
err)
|
||||||
@@ -116,7 +116,7 @@ func printOrderbookSummary(result orderbook.Base, p pair.CurrencyPair, assetType
|
|||||||
|
|
||||||
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.String() != bot.config.Currency.FiatDisplayCurrency {
|
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.String() != bot.config.Currency.FiatDisplayCurrency {
|
||||||
origCurrency := p.SecondCurrency.Upper().String()
|
origCurrency := p.SecondCurrency.Upper().String()
|
||||||
log.Printf("%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %s Asks len: %d Amount: %f %s. Total value: %s",
|
log.Infof("%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %s Asks len: %d Amount: %f %s. Total value: %s",
|
||||||
exchangeName,
|
exchangeName,
|
||||||
exchange.FormatCurrency(p).String(),
|
exchange.FormatCurrency(p).String(),
|
||||||
assetType,
|
assetType,
|
||||||
@@ -131,7 +131,7 @@ func printOrderbookSummary(result orderbook.Base, p pair.CurrencyPair, assetType
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.Upper().String() == bot.config.Currency.FiatDisplayCurrency {
|
if currency.IsFiatCurrency(p.SecondCurrency.String()) && p.SecondCurrency.Upper().String() == bot.config.Currency.FiatDisplayCurrency {
|
||||||
log.Printf("%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %s Asks len: %d Amount: %f %s. Total value: %s",
|
log.Infof("%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %s Asks len: %d Amount: %f %s. Total value: %s",
|
||||||
exchangeName,
|
exchangeName,
|
||||||
exchange.FormatCurrency(p).String(),
|
exchange.FormatCurrency(p).String(),
|
||||||
assetType,
|
assetType,
|
||||||
@@ -145,7 +145,7 @@ func printOrderbookSummary(result orderbook.Base, p pair.CurrencyPair, assetType
|
|||||||
printCurrencyFormat(asksValue),
|
printCurrencyFormat(asksValue),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %f Asks len: %d Amount: %f %s. Total value: %f",
|
log.Infof("%s %s %s: ORDERBOOK: Bids len: %d Amount: %f %s. Total value: %f Asks len: %d Amount: %f %s. Total value: %f",
|
||||||
exchangeName,
|
exchangeName,
|
||||||
exchange.FormatCurrency(p).String(),
|
exchange.FormatCurrency(p).String(),
|
||||||
assetType,
|
assetType,
|
||||||
@@ -171,15 +171,15 @@ func relayWebsocketEvent(result interface{}, event, assetType, exchangeName stri
|
|||||||
}
|
}
|
||||||
err := BroadcastWebsocketMessage(evt)
|
err := BroadcastWebsocketMessage(evt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(fmt.Errorf("Failed to broadcast websocket event. Error: %s",
|
log.Errorf("Failed to broadcast websocket event. Error: %s",
|
||||||
err))
|
err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TickerUpdaterRoutine fetches and updates the ticker for all enabled
|
// TickerUpdaterRoutine fetches and updates the ticker for all enabled
|
||||||
// currency pairs and exchanges
|
// currency pairs and exchanges
|
||||||
func TickerUpdaterRoutine() {
|
func TickerUpdaterRoutine() {
|
||||||
log.Println("Starting ticker updater routine.")
|
log.Debugf("Starting ticker updater routine.")
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for {
|
for {
|
||||||
wg.Add(len(bot.exchanges))
|
wg.Add(len(bot.exchanges))
|
||||||
@@ -194,7 +194,7 @@ func TickerUpdaterRoutine() {
|
|||||||
supportsBatching := bot.exchanges[x].SupportsRESTTickerBatchUpdates()
|
supportsBatching := bot.exchanges[x].SupportsRESTTickerBatchUpdates()
|
||||||
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get %s exchange asset types. Error: %s",
|
log.Debugf("failed to get %s exchange asset types. Error: %s",
|
||||||
exchangeName, err)
|
exchangeName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -228,7 +228,7 @@ func TickerUpdaterRoutine() {
|
|||||||
}(x, &wg)
|
}(x, &wg)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
log.Println("All enabled currency tickers fetched.")
|
log.Debugln("All enabled currency tickers fetched.")
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ func TickerUpdaterRoutine() {
|
|||||||
// OrderbookUpdaterRoutine fetches and updates the orderbooks for all enabled
|
// OrderbookUpdaterRoutine fetches and updates the orderbooks for all enabled
|
||||||
// currency pairs and exchanges
|
// currency pairs and exchanges
|
||||||
func OrderbookUpdaterRoutine() {
|
func OrderbookUpdaterRoutine() {
|
||||||
log.Println("Starting orderbook updater routine.")
|
log.Debugln("Starting orderbook updater routine.")
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for {
|
for {
|
||||||
wg.Add(len(bot.exchanges))
|
wg.Add(len(bot.exchanges))
|
||||||
@@ -251,7 +251,7 @@ func OrderbookUpdaterRoutine() {
|
|||||||
enabledCurrencies := bot.exchanges[x].GetEnabledCurrencies()
|
enabledCurrencies := bot.exchanges[x].GetEnabledCurrencies()
|
||||||
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
assetTypes, err := exchange.GetExchangeAssetTypes(exchangeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get %s exchange asset types. Error: %s",
|
log.Errorf("failed to get %s exchange asset types. Error: %s",
|
||||||
exchangeName, err)
|
exchangeName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -275,19 +275,19 @@ func OrderbookUpdaterRoutine() {
|
|||||||
}(x, &wg)
|
}(x, &wg)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
log.Println("All enabled currency orderbooks fetched.")
|
log.Debugln("All enabled currency orderbooks fetched.")
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebsocketRoutine Initial routine management system for websocket
|
// WebsocketRoutine Initial routine management system for websocket
|
||||||
func WebsocketRoutine(verbose bool) {
|
func WebsocketRoutine(verbose bool) {
|
||||||
log.Println("Connecting exchange websocket services...")
|
log.Debugln("Connecting exchange websocket services...")
|
||||||
|
|
||||||
for i := range bot.exchanges {
|
for i := range bot.exchanges {
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("Establishing websocket connection for %s",
|
log.Debugf("Establishing websocket connection for %s",
|
||||||
bot.exchanges[i].GetName())
|
bot.exchanges[i].GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,9 +303,9 @@ func WebsocketRoutine(verbose bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.Error() {
|
switch err.Error() {
|
||||||
case exchange.WebsocketNotEnabled:
|
case exchange.WebsocketNotEnabled:
|
||||||
// Store in memory if enabled in future
|
log.Warnf("%s - websocket disabled", bot.exchanges[i].GetName())
|
||||||
default:
|
default:
|
||||||
log.Println(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(i)
|
}(i)
|
||||||
@@ -320,7 +320,7 @@ var wg sync.WaitGroup
|
|||||||
func Websocketshutdown(ws *exchange.Websocket) error {
|
func Websocketshutdown(ws *exchange.Websocket) error {
|
||||||
err := ws.Shutdown() // shutdown routines on the exchange
|
err := ws.Shutdown() // shutdown routines on the exchange
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("routines.go error - failed to shutodwn %s", err)
|
log.Errorf("routines.go error - failed to shutodwn %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
timer := time.NewTimer(5 * time.Second)
|
timer := time.NewTimer(5 * time.Second)
|
||||||
@@ -354,12 +354,12 @@ func streamDiversion(ws *exchange.Websocket, verbose bool) {
|
|||||||
|
|
||||||
case <-ws.Connected:
|
case <-ws.Connected:
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("exchange %s websocket feed connected", ws.GetName())
|
log.Debugf("exchange %s websocket feed connected", ws.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-ws.Disconnected:
|
case <-ws.Disconnected:
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("exchange %s websocket feed disconnected, switching to REST functionality",
|
log.Debugf("exchange %s websocket feed disconnected, switching to REST functionality",
|
||||||
ws.GetName())
|
ws.GetName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -385,12 +385,12 @@ func WebsocketDataHandler(ws *exchange.Websocket, verbose bool) {
|
|||||||
switch data.(string) {
|
switch data.(string) {
|
||||||
case exchange.WebsocketNotEnabled:
|
case exchange.WebsocketNotEnabled:
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("routines.go warning - exchange %s weboscket not enabled",
|
log.Warnf("routines.go warning - exchange %s weboscket not enabled",
|
||||||
ws.GetName())
|
ws.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.Println(data.(string))
|
log.Infof(data.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
case error:
|
case error:
|
||||||
@@ -399,33 +399,33 @@ func WebsocketDataHandler(ws *exchange.Websocket, verbose bool) {
|
|||||||
go WebsocketReconnect(ws, verbose)
|
go WebsocketReconnect(ws, verbose)
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
log.Fatalf("routines.go exchange %s websocket error - %s", ws.GetName(), data)
|
log.Errorf("routines.go exchange %s websocket error - %s", ws.GetName(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
case exchange.TradeData:
|
case exchange.TradeData:
|
||||||
// Trade Data
|
// Trade Data
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Println("Websocket trades Updated: ", data.(exchange.TradeData))
|
log.Infoln("Websocket trades Updated: ", data.(exchange.TradeData))
|
||||||
}
|
}
|
||||||
|
|
||||||
case exchange.TickerData:
|
case exchange.TickerData:
|
||||||
// Ticker data
|
// Ticker data
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Println("Websocket Ticker Updated: ", data.(exchange.TickerData))
|
log.Infoln("Websocket Ticker Updated: ", data.(exchange.TickerData))
|
||||||
}
|
}
|
||||||
case exchange.KlineData:
|
case exchange.KlineData:
|
||||||
// Kline data
|
// Kline data
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Println("Websocket Kline Updated: ", data.(exchange.KlineData))
|
log.Infoln("Websocket Kline Updated: ", data.(exchange.KlineData))
|
||||||
}
|
}
|
||||||
case exchange.WebsocketOrderbookUpdate:
|
case exchange.WebsocketOrderbookUpdate:
|
||||||
// Orderbook data
|
// Orderbook data
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Println("Websocket Orderbook Updated:", data.(exchange.WebsocketOrderbookUpdate))
|
log.Infoln("Websocket Orderbook Updated:", data.(exchange.WebsocketOrderbookUpdate))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Println("Websocket Unknown type: ", data)
|
log.Warnf("Websocket Unknown type: %s", data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -435,12 +435,13 @@ func WebsocketDataHandler(ws *exchange.Websocket, verbose bool) {
|
|||||||
// WebsocketReconnect tries to reconnect to a websocket stream
|
// WebsocketReconnect tries to reconnect to a websocket stream
|
||||||
func WebsocketReconnect(ws *exchange.Websocket, verbose bool) {
|
func WebsocketReconnect(ws *exchange.Websocket, verbose bool) {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("Websocket reconnection requested for %s", ws.GetName())
|
log.Debugf("Websocket reconnection requested for %s", ws.GetName())
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ws.Shutdown()
|
err := ws.Shutdown()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Error(err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user