mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Split up common.go, file path fixes and much more
This commit is contained in:
@@ -3,9 +3,9 @@ package events
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/communications"
|
||||
"github.com/thrasher-/gocryptotrader/communications/base"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
@@ -134,8 +134,8 @@ func GetEventCounter() (total, executed int) {
|
||||
|
||||
// ExecuteAction will execute the action pending on the chain
|
||||
func (e *Event) ExecuteAction() bool {
|
||||
if common.StringContains(e.Action, ",") {
|
||||
action := common.SplitStrings(e.Action, ",")
|
||||
if strings.Contains(e.Action, ",") {
|
||||
action := strings.Split(e.Action, ",")
|
||||
if action[0] == ActionSMSNotify {
|
||||
message := fmt.Sprintf("Event triggered: %s", e.String())
|
||||
if action[1] == "ALL" {
|
||||
@@ -251,9 +251,9 @@ func (e *Event) CheckCondition() bool {
|
||||
|
||||
// IsValidEvent checks the actions to be taken and returns an error if incorrect
|
||||
func IsValidEvent(exchange, item string, condition ConditionParams, action string) error {
|
||||
exchange = common.StringToUpper(exchange)
|
||||
item = common.StringToUpper(item)
|
||||
action = common.StringToUpper(action)
|
||||
exchange = strings.ToUpper(exchange)
|
||||
item = strings.ToUpper(item)
|
||||
action = strings.ToUpper(action)
|
||||
|
||||
if !IsValidExchange(exchange) {
|
||||
return errExchangeDisabled
|
||||
@@ -279,8 +279,8 @@ func IsValidEvent(exchange, item string, condition ConditionParams, action strin
|
||||
}
|
||||
}
|
||||
|
||||
if common.StringContains(action, ",") {
|
||||
a := common.SplitStrings(action, ",")
|
||||
if strings.Contains(action, ",") {
|
||||
a := strings.Split(action, ",")
|
||||
|
||||
if a[0] != ActionSMSNotify {
|
||||
return errInvalidAction
|
||||
@@ -326,10 +326,10 @@ func EventManger() {
|
||||
|
||||
// IsValidExchange validates the exchange
|
||||
func IsValidExchange(exchangeName string) bool {
|
||||
exchangeName = common.StringToLower(exchangeName)
|
||||
exchangeName = strings.ToLower(exchangeName)
|
||||
cfg := config.GetConfig()
|
||||
for x := range cfg.Exchanges {
|
||||
if common.StringToLower(cfg.Exchanges[x].Name) == exchangeName && cfg.Exchanges[x].Enabled {
|
||||
if strings.ToLower(cfg.Exchanges[x].Name) == exchangeName && cfg.Exchanges[x].Enabled {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func IsValidCondition(condition string) bool {
|
||||
|
||||
// IsValidAction validates passed in action
|
||||
func IsValidAction(action string) bool {
|
||||
action = common.StringToUpper(action)
|
||||
action = strings.ToUpper(action)
|
||||
switch action {
|
||||
case ActionSMSNotify, ActionConsolePrint, ActionTest:
|
||||
return true
|
||||
@@ -357,7 +357,7 @@ func IsValidAction(action string) bool {
|
||||
|
||||
// IsValidItem validates passed in Item
|
||||
func IsValidItem(item string) bool {
|
||||
item = common.StringToUpper(item)
|
||||
item = strings.ToUpper(item)
|
||||
switch item {
|
||||
case ItemPrice, ItemOrderbook:
|
||||
return true
|
||||
|
||||
@@ -121,7 +121,7 @@ func UnloadExchange(name string) error {
|
||||
|
||||
// LoadExchange loads an exchange by name
|
||||
func LoadExchange(name string, useWG bool, wg *sync.WaitGroup) error {
|
||||
nameLower := common.StringToLower(name)
|
||||
nameLower := strings.ToLower(name)
|
||||
var exch exchange.IBotExchange
|
||||
|
||||
if len(Bot.Exchanges) > 0 {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
_ "net/http/pprof" // blank import required for pprof
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -64,7 +65,7 @@ func newRouter(isREST bool) *mux.Router {
|
||||
if common.ExtractPort(listenAddr) == 80 {
|
||||
listenAddr = common.ExtractHost(listenAddr)
|
||||
} else {
|
||||
listenAddr = common.JoinStrings([]string{common.ExtractHost(listenAddr),
|
||||
listenAddr = strings.Join([]string{common.ExtractHost(listenAddr),
|
||||
strconv.Itoa(common.ExtractPort(listenAddr))}, ":")
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package engine
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -398,7 +399,7 @@ func WebsocketDataHandler(ws *exchange.Websocket) {
|
||||
|
||||
case error:
|
||||
switch {
|
||||
case common.StringContains(d.Error(), "close 1006"):
|
||||
case strings.Contains(d.Error(), "close 1006"):
|
||||
go ws.WebsocketReset()
|
||||
continue
|
||||
default:
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
grpcauth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
|
||||
@@ -41,17 +42,17 @@ func authenticateClient(ctx context.Context) (context.Context, error) {
|
||||
return ctx, fmt.Errorf("authorization header missing")
|
||||
}
|
||||
|
||||
if !common.StringContains(authStr[0], "Basic") {
|
||||
if !strings.Contains(authStr[0], "Basic") {
|
||||
return ctx, fmt.Errorf("basic not found in authorization header")
|
||||
}
|
||||
|
||||
decoded, err := crypto.Base64Decode(common.SplitStrings(authStr[0], " ")[1])
|
||||
decoded, err := crypto.Base64Decode(strings.Split(authStr[0], " ")[1])
|
||||
if err != nil {
|
||||
return ctx, fmt.Errorf("unable to base64 decode authorization header")
|
||||
}
|
||||
|
||||
username := common.SplitStrings(string(decoded), ":")[0]
|
||||
password := common.SplitStrings(string(decoded), ":")[1]
|
||||
username := strings.Split(string(decoded), ":")[0]
|
||||
password := strings.Split(string(decoded), ":")[1]
|
||||
|
||||
if username != Bot.Config.RemoteControl.Username || password != Bot.Config.RemoteControl.Password {
|
||||
return ctx, fmt.Errorf("username/password mismatch")
|
||||
@@ -159,7 +160,7 @@ func (s *RPCServer) GetInfo(ctx context.Context, r *gctrpc.GetInfoRequest) (*gct
|
||||
// GetExchanges returns a list of exchanges
|
||||
// Param is whether or not you wish to list enabled exchanges
|
||||
func (s *RPCServer) GetExchanges(ctx context.Context, r *gctrpc.GetExchangesRequest) (*gctrpc.GetExchangesResponse, error) {
|
||||
exchanges := common.JoinStrings(GetExchanges(r.Enabled), ",")
|
||||
exchanges := strings.Join(GetExchanges(r.Enabled), ",")
|
||||
return &gctrpc.GetExchangesResponse{Exchanges: exchanges}, nil
|
||||
}
|
||||
|
||||
@@ -190,13 +191,13 @@ func (s *RPCServer) GetExchangeInfo(ctx context.Context, r *gctrpc.GenericExchan
|
||||
HttpTimeout: exchCfg.HTTPTimeout.String(),
|
||||
HttpUseragent: exchCfg.HTTPUserAgent,
|
||||
HttpProxy: exchCfg.ProxyAddress,
|
||||
BaseCurrencies: common.JoinStrings(exchCfg.BaseCurrencies.Strings(), ","),
|
||||
BaseCurrencies: strings.Join(exchCfg.BaseCurrencies.Strings(), ","),
|
||||
SupportedAssets: exchCfg.CurrencyPairs.AssetTypes.JoinToString(","),
|
||||
|
||||
// TO-DO fix pairs
|
||||
//EnabledPairs: common.JoinStrings(
|
||||
//EnabledPairs: strings.Join(
|
||||
// exchCfg.CurrencyPairs.Pairs.GetPairs().Enabled.Strings(), ","),
|
||||
//AvailablePairs: common.JoinStrings(
|
||||
//AvailablePairs: strings.Join(
|
||||
// exchCfg.CurrencyPairs.Spot.Available.Strings(), ","),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package engine
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
@@ -122,7 +123,7 @@ func (c *WebsocketClient) read() {
|
||||
break
|
||||
}
|
||||
|
||||
req := common.StringToLower(evt.Event)
|
||||
req := strings.ToLower(evt.Event)
|
||||
log.Debugf("websocket: request received: %s", req)
|
||||
|
||||
result, ok := wsHandlers[req]
|
||||
|
||||
Reference in New Issue
Block a user