mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 15:10:15 +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:
@@ -3,7 +3,6 @@ package okcoin
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -14,9 +13,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 (
|
||||
@@ -811,7 +811,7 @@ func (o *OKCoin) GetFuturesUserInfo() {
|
||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo, url.Values{}, 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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -912,7 +912,7 @@ func (o *OKCoin) GetFuturesUserInfo4Fix() {
|
||||
err := o.SendAuthenticatedHTTPRequest(okcoinFuturesUserInfo4Fix, v, 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)
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -13,7 +12,8 @@ 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"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -132,11 +132,11 @@ func (o *OKCoin) WsHandleData() {
|
||||
var init []WsResponse
|
||||
err := common.JSONDecode(resp.Raw, &init)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
if init[0].ErrorCode != "" {
|
||||
log.Fatal(o.WebsocketErrors[init[0].ErrorCode])
|
||||
log.Error(o.WebsocketErrors[init[0].ErrorCode])
|
||||
}
|
||||
|
||||
if init[0].Success {
|
||||
@@ -166,7 +166,7 @@ func (o *OKCoin) WsHandleData() {
|
||||
|
||||
err = common.JSONDecode(init[0].Data, &ticker)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Error(err)
|
||||
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func (o *OKCoin) WsHandleData() {
|
||||
|
||||
err = common.JSONDecode(init[0].Data, &orderbook)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
o.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
|
||||
@@ -201,7 +201,7 @@ func (o *OKCoin) WsHandleData() {
|
||||
|
||||
err = common.JSONDecode(init[0].Data, &klineData)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var klines []WsKlines
|
||||
@@ -237,7 +237,7 @@ func (o *OKCoin) WsHandleData() {
|
||||
var dealsData [][]interface{}
|
||||
err = common.JSONDecode(init[0].Data, &dealsData)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Error(err)
|
||||
}
|
||||
|
||||
var deals []WsDeals
|
||||
|
||||
@@ -3,15 +3,15 @@ package okcoin
|
||||
import (
|
||||
"errors"
|
||||
"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 OKCoin go routine
|
||||
@@ -26,9 +26,9 @@ func (o *OKCoin) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the OKCoin wrapper
|
||||
func (o *OKCoin) Run() {
|
||||
if o.Verbose {
|
||||
log.Printf("%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.Printf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
||||
log.Debugf("%s Websocket: %s. (url: %s).\n", o.GetName(), common.IsEnabled(o.Websocket.IsEnabled()), o.WebsocketURL)
|
||||
log.Debugf("%s polling delay: %ds.\n", o.GetName(), o.RESTPollingDelay)
|
||||
log.Debugf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
|
||||
}
|
||||
|
||||
if o.APIUrl == okcoinAPIURL {
|
||||
@@ -40,7 +40,7 @@ func (o *OKCoin) Run() {
|
||||
|
||||
prods, err := o.GetSpotInstruments()
|
||||
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 {
|
||||
var pairs []string
|
||||
for x := range prods {
|
||||
@@ -49,17 +49,17 @@ func (o *OKCoin) Run() {
|
||||
|
||||
err = o.UpdateCurrencies(pairs, false, forceUpgrade)
|
||||
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 {
|
||||
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)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user