mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +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:
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -12,9 +11,10 @@ import (
|
||||
"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 (
|
||||
@@ -168,7 +168,6 @@ func (p *Poloniex) GetOrderbook(currencyPair string, depth int) (OrderbookAll, e
|
||||
return oba, err
|
||||
}
|
||||
if len(resp.Error) != 0 {
|
||||
log.Println(resp.Error)
|
||||
return oba, fmt.Errorf("Poloniex GetOrderbook() error: %s", resp.Error)
|
||||
}
|
||||
ob := Orderbook{}
|
||||
|
||||
@@ -3,7 +3,6 @@ package poloniex
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -12,8 +11,9 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"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 (
|
||||
@@ -132,7 +132,7 @@ func (p *Poloniex) WsHandleData() {
|
||||
var check []interface{}
|
||||
err := common.JSONDecode(resp.Raw, &check)
|
||||
if err != nil {
|
||||
log.Fatal("poloniex_websocket.go - ", err)
|
||||
log.Errorf("poloniex websocket decode error - %s", err)
|
||||
}
|
||||
|
||||
switch len(check) {
|
||||
@@ -176,7 +176,7 @@ func (p *Poloniex) WsHandleData() {
|
||||
err := p.WsProcessOrderbookUpdate(datalevel2,
|
||||
CurrencyPairID[int64(check[0].(float64))])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
p.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||
@@ -189,12 +189,12 @@ func (p *Poloniex) WsHandleData() {
|
||||
datalevel3 := datalevel2[1].(map[string]interface{})
|
||||
currencyPair, ok := datalevel3["currencyPair"].(string)
|
||||
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{})
|
||||
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)
|
||||
|
||||
@@ -2,15 +2,15 @@ package poloniex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"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/ticker"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
// Start starts the Poloniex go routine
|
||||
@@ -25,24 +25,24 @@ func (p *Poloniex) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Poloniex wrapper
|
||||
func (p *Poloniex) Run() {
|
||||
if p.Verbose {
|
||||
log.Printf("%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.Printf("%s %d currencies enabled: %s.\n", p.GetName(), len(p.EnabledPairs), p.EnabledPairs)
|
||||
log.Debugf("%s Websocket: %s (url: %s).\n", p.GetName(), common.IsEnabled(p.Websocket.IsEnabled()), poloniexWebsocketAddress)
|
||||
log.Debugf("%s polling delay: %ds.\n", p.GetName(), p.RESTPollingDelay)
|
||||
log.Debugf("%s %d currencies enabled: %s.\n", p.GetName(), len(p.EnabledPairs), p.EnabledPairs)
|
||||
}
|
||||
|
||||
exchangeCurrencies, err := p.GetExchangeCurrencies()
|
||||
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 {
|
||||
forceUpdate := false
|
||||
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())
|
||||
forceUpdate = true
|
||||
}
|
||||
err = p.UpdateCurrencies(exchangeCurrencies, false, forceUpdate)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user