mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +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:
@@ -1,15 +1,15 @@
|
||||
package btcc
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"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/ticker"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,6 @@ package btcc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -15,6 +14,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -132,48 +132,37 @@ func (b *BTCC) WsHandleData() {
|
||||
case msgTypeHeartBeat:
|
||||
|
||||
case msgTypeGetActiveContracts:
|
||||
log.Println("Active Contracts")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Active Contracts: %s", resp.Raw)
|
||||
|
||||
case msgTypeQuote:
|
||||
log.Println("Quotes")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Quotes: %s", resp.Raw)
|
||||
|
||||
case msgTypeLogin:
|
||||
log.Println("Login")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Login: %s", resp.Raw)
|
||||
|
||||
case msgTypeAccountInfo:
|
||||
log.Println("Account info")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Account info: %s", resp.Raw)
|
||||
|
||||
case msgTypeExecReport:
|
||||
log.Println("Exec Report")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Exec Report: %s", resp.Raw)
|
||||
|
||||
case msgTypePlaceOrder:
|
||||
log.Println("Place order")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Place order: %s", resp.Raw)
|
||||
|
||||
case msgTypeCancelAllOrders:
|
||||
log.Println("Cancel All orders")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Cancel All orders: %s", resp.Raw)
|
||||
|
||||
case msgTypeCancelOrder:
|
||||
log.Println("Cancel order")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Cancel order: %s", resp.Raw)
|
||||
|
||||
case msgTypeCancelReplaceOrder:
|
||||
log.Println("Replace order")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Replace order: %s", resp.Raw)
|
||||
|
||||
case msgTypeGetAccountInfo:
|
||||
log.Println("Account info")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Account info: %s", resp.Raw)
|
||||
|
||||
case msgTypeRetrieveOrder:
|
||||
log.Println("Retrieve order")
|
||||
log.Fatal(string(resp.Raw))
|
||||
log.Debugf("Retrieve order: %s", resp.Raw)
|
||||
|
||||
case msgTypeGetTrades:
|
||||
var trades WsTrades
|
||||
|
||||
@@ -2,7 +2,6 @@ package btcc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
@@ -11,6 +10,7 @@ import (
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
// Start starts the BTCC go routine
|
||||
@@ -25,18 +25,18 @@ func (b *BTCC) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the BTCC wrapper
|
||||
func (b *BTCC) Run() {
|
||||
if b.Verbose {
|
||||
log.Printf("%s Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
log.Printf("%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 Websocket: %s.", b.GetName(), common.IsEnabled(b.Websocket.IsEnabled()))
|
||||
log.Debugf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
|
||||
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") {
|
||||
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"}
|
||||
cfg := config.GetConfig()
|
||||
exchCfg, err := cfg.GetExchangeConfig(b.Name)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -47,17 +47,17 @@ func (b *BTCC) Run() {
|
||||
|
||||
err = b.UpdateCurrencies(pairs, false, true)
|
||||
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)
|
||||
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)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user