From 291e404a4a672388a3e737ab1b5522d50d37d69d Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Thu, 31 Jan 2019 14:53:24 +1100 Subject: [PATCH] Makefile: add new recipes and linter features (#244) * Makefile: add new recipes and linter features * expand linter coverage and fix issues * Update makefile * address PR nitterinos --- .travis.yml | 2 +- Makefile | 48 +++++- common/common.go | 4 +- communications/slack/slack.go | 4 +- communications/slack/slack_test.go | 3 +- config/config.go | 8 +- currency/currency.go | 6 +- currency/currency_test.go | 5 +- .../currencyconverterapi.go | 6 +- currency/symbol/symbol.go | 2 +- currency/translation/translation.go | 5 +- exchanges/alphapoint/alphapoint_test.go | 6 +- exchanges/anx/anx.go | 8 +- exchanges/anx/anx_test.go | 4 +- exchanges/binance/binance.go | 14 +- exchanges/binance/binance_test.go | 4 +- exchanges/binance/binance_websocket.go | 32 ++-- exchanges/bitfinex/bitfinex.go | 6 +- exchanges/bitfinex/bitfinex_websocket.go | 5 +- exchanges/bitfinex/bitfinex_wrapper.go | 10 +- exchanges/bitflyer/bitflyer.go | 6 +- exchanges/bitflyer/bitflyer_test.go | 12 +- exchanges/bithumb/bithumb_test.go | 2 +- exchanges/bithumb/bithumb_wrapper.go | 5 +- exchanges/bitmex/bitmex_parameters.go | 140 ++++-------------- exchanges/bitmex/bitmex_test.go | 4 +- exchanges/bitmex/bitmex_websocket.go | 10 +- exchanges/bitmex/bitmex_wrapper.go | 4 +- exchanges/bittrex/bittrex_test.go | 4 +- exchanges/btcc/btcc.go | 5 +- exchanges/btcc/btcc_test.go | 12 +- exchanges/btcc/btcc_websocket.go | 13 +- exchanges/btcmarkets/btcmarkets.go | 9 +- exchanges/btcmarkets/btcmarkets_test.go | 2 +- exchanges/coinbasepro/coinbasepro.go | 10 +- exchanges/coinut/coinut.go | 7 +- exchanges/coinut/coinut_test.go | 6 +- exchanges/coinut/coinut_wrapper.go | 12 +- exchanges/exchange.go | 5 +- exchanges/exchange_test.go | 6 +- exchanges/exchange_websocket.go | 15 +- exchanges/exchange_websocket_test.go | 2 +- exchanges/exmo/exmo.go | 4 +- exchanges/exmo/exmo_test.go | 4 +- exchanges/gateio/gateio_test.go | 4 +- exchanges/gateio/gateio_websocket.go | 4 +- exchanges/gemini/gemini.go | 6 +- exchanges/gemini/gemini_test.go | 4 +- exchanges/hitbtc/hitbtc.go | 9 +- exchanges/hitbtc/hitbtc_test.go | 4 +- exchanges/huobi/huobi.go | 2 +- exchanges/huobi/huobi_test.go | 4 +- exchanges/huobihadax/huobihadax_test.go | 4 +- exchanges/itbit/itbit.go | 13 +- exchanges/itbit/itbit_test.go | 6 +- exchanges/kraken/kraken_test.go | 2 +- exchanges/lakebtc/lakebtc.go | 4 +- exchanges/lakebtc/lakebtc_test.go | 4 +- exchanges/lakebtc/lakebtc_types.go | 2 +- exchanges/liqui/liqui_test.go | 4 +- exchanges/liqui/liqui_wrapper.go | 2 +- exchanges/localbitcoins/localbitcoins_test.go | 4 +- .../localbitcoins/localbitcoins_wrapper.go | 2 +- exchanges/okcoin/okcoin.go | 4 +- exchanges/okcoin/okcoin_test.go | 4 +- exchanges/okex/okex.go | 2 +- exchanges/okex/okex_test.go | 4 +- exchanges/okex/okex_wrapper.go | 4 +- exchanges/poloniex/poloniex_test.go | 4 +- exchanges/poloniex/poloniex_websocket.go | 7 +- exchanges/wex/wex_test.go | 4 +- exchanges/yobit/yobit.go | 4 +- exchanges/yobit/yobit_test.go | 4 +- exchanges/zb/zb_test.go | 4 +- exchanges/zb/zb_websocket_types.go | 2 +- exchanges/zb/zb_wrapper.go | 4 +- helpers.go | 7 +- main.go | 2 +- portfolio/portfolio.go | 11 +- restful_router.go | 9 +- restful_server.go | 18 +-- restful_server_test.go | 3 +- routines.go | 18 +-- tools/huobi_auth/main.go | 13 +- websocket.go | 2 +- 85 files changed, 306 insertions(+), 393 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5e86ee8..b836e806 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,6 @@ matrix: install: true script: - - go test -race -coverprofile=coverage.txt -covermode=atomic ./... + - make check after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index 28008a78..bc97a557 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,50 @@ +LDFLAGS = -ldflags "-w -s" +GCTPKG = github.com/thrasher-/gocryptotrader +LINTPKG = gopkg.in/alecthomas/gometalinter.v2 +LINTBIN = $(GOPATH)/bin/gometalinter.v2 +ENABLELLL = false +LINTOPTS = \ + --disable-all \ + --enable=gofmt \ + --enable=vet \ + --enable=vetshadow \ + --enable=misspell \ + --enable=golint \ + --enable=ineffassign \ + --enable=goconst \ + --enable=structcheck \ + --enable=unparam \ + --enable=gosimple \ + --enable=unconvert +ifeq ($(ENABLELLL), true) +LINTOPTS += \ + --enable=lll \ + --line-length=80 +endif +LINTOPTS += \ + --deadline=5m ./... | \ + grep -v 'ALL_CAPS\|OP_' 2>&1 | \ + tee /dev/stderr + get: - dep ensure + GO111MODULE=on go get $(GCTPKG) + +linter: + GO111MODULE=on go get $(GCTPKG) + GO111MODULE=off go get -u $(LINTPKG) + $(LINTBIN) --install + test -z "$$($(LINTBIN) $(LINTOPTS))" + +check: linter test + +test: + go test -race -coverprofile=coverage.txt -covermode=atomic ./... build: - go build . + GO111MODULE=on go build $(LDFLAGS) install: - go install \ No newline at end of file + GO111MODULE=on go install $(LDFLAGS) + +fmt: + gofmt -l -w -s $(shell find . -type f -name '*.go') \ No newline at end of file diff --git a/common/common.go b/common/common.go index 84d7d249..a8f5851e 100644 --- a/common/common.go +++ b/common/common.go @@ -60,7 +60,7 @@ const ( func initialiseHTTPClient() { // If the HTTPClient isn't set, start a new client with a default timeout of 15 seconds if HTTPClient == nil { - HTTPClient = NewHTTPClientWithTimeout(time.Duration(time.Second * 15)) + HTTPClient = NewHTTPClientWithTimeout(time.Second * 15) } } @@ -138,7 +138,7 @@ func GetHMAC(hashType int, input, key []byte) []byte { } } - hmac := hmac.New(hash, []byte(key)) + hmac := hmac.New(hash, key) hmac.Write(input) return hmac.Sum(nil) } diff --git a/communications/slack/slack.go b/communications/slack/slack.go index 47c9a130..35e90aff 100644 --- a/communications/slack/slack.go +++ b/communications/slack/slack.go @@ -217,7 +217,7 @@ func (s *Slack) WebsocketReader() { } case "hello": - s.handleHelloResponse(data) + s.handleHelloResponse() case "reconnect_url": err = s.handleReconnectResponse(resp) @@ -301,7 +301,7 @@ func (s *Slack) handleErrorResponse(data WebsocketResponse) error { return fmt.Errorf("Unknown error '%s'", data.Error.Msg) } -func (s *Slack) handleHelloResponse(data WebsocketResponse) { +func (s *Slack) handleHelloResponse() { if s.Verbose { log.Debugln("Websocket connected successfully.") } diff --git a/communications/slack/slack_test.go b/communications/slack/slack_test.go index c2fa2703..aa2381b7 100644 --- a/communications/slack/slack_test.go +++ b/communications/slack/slack_test.go @@ -311,8 +311,7 @@ func TestHandleErrorResponse(t *testing.T) { } func TestHandleHelloResponse(t *testing.T) { - var data WebsocketResponse - s.handleHelloResponse(data) + s.handleHelloResponse() } func TestHandleReconnectResponse(t *testing.T) { diff --git a/config/config.go b/config/config.go index 9451b70d..fc3eca36 100644 --- a/config/config.go +++ b/config/config.go @@ -31,7 +31,7 @@ const ( configFileEncryptionEnabled = 1 configFileEncryptionDisabled = -1 configPairsLastUpdatedWarningThreshold = 30 // 30 days - configDefaultHTTPTimeout = time.Duration(time.Second * 15) + configDefaultHTTPTimeout = time.Second * 15 configMaxAuthFailres = 3 ) @@ -326,7 +326,7 @@ func (c *Config) CheckClientBankAccounts() error { } for i := range c.BankAccounts { - if c.BankAccounts[i].Enabled == true { + if c.BankAccounts[i].Enabled { if c.BankAccounts[i].BankName == "" || c.BankAccounts[i].BankAddress == "" { return fmt.Errorf("banking details for %s is enabled but variables not set correctly", c.BankAccounts[i].BankName) @@ -764,7 +764,7 @@ func (c *Config) CheckExchangeConfigValues() error { c.Exchanges[i].BankAccounts = append(c.Exchanges[i].BankAccounts, BankAccount{}) } else { for _, bankAccount := range exch.BankAccounts { - if bankAccount.Enabled == true { + if bankAccount.Enabled { if bankAccount.BankName == "" || bankAccount.BankAddress == "" { return fmt.Errorf("banking details for %s is enabled but variables not set", exch.Name) @@ -855,7 +855,7 @@ func (c *Config) CheckCurrencyConfigValues() error { count := 0 for i := range c.Currency.ForexProviders { - if c.Currency.ForexProviders[i].Enabled == true { + if c.Currency.ForexProviders[i].Enabled { if c.Currency.ForexProviders[i].APIKey == "Key" { 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 diff --git a/currency/currency.go b/currency/currency.go index a60d3c27..c63573d6 100644 --- a/currency/currency.go +++ b/currency/currency.go @@ -169,7 +169,8 @@ func ConvertCurrency(amount float64, from, to string) (float64, error) { // check to see if we're converting from the base currency if to == baseCurr { - resultFrom, ok := FXRates[baseCurr+from] + var ok bool + resultFrom, ok = FXRates[baseCurr+from] if !ok { return 0, fmt.Errorf("Currency conversion failed. Unable to find %s in currency map [%s -> %s]", from, from, to) } @@ -178,7 +179,8 @@ func ConvertCurrency(amount float64, from, to string) (float64, error) { // Check to see if we're converting from the base currency if from == baseCurr { - resultTo, ok := FXRates[baseCurr+to] + var ok bool + resultTo, ok = FXRates[baseCurr+to] if !ok { return 0, fmt.Errorf("Currency conversion failed. Unable to find %s in currency map [%s -> %s]", to, from, to) } diff --git a/currency/currency_test.go b/currency/currency_test.go index 5bd655c9..d4478a97 100644 --- a/currency/currency_test.go +++ b/currency/currency_test.go @@ -34,7 +34,10 @@ func TestSeedCurrencyData(t *testing.T) { } func TestGetExchangeRates(t *testing.T) { - result := GetExchangeRates() + result := make(map[string]float64) + for k, v := range GetExchangeRates() { + result[k] = v + } backup := FXRates FXRates = nil diff --git a/currency/forexprovider/currencyconverterapi/currencyconverterapi.go b/currency/forexprovider/currencyconverterapi/currencyconverterapi.go index 97c5af8a..b4d0b6b9 100644 --- a/currency/forexprovider/currencyconverterapi/currencyconverterapi.go +++ b/currency/forexprovider/currencyconverterapi/currencyconverterapi.go @@ -20,6 +20,8 @@ const ( APIEndpointCurrencies = "currencies" APIEndpointCountries = "countries" APIEndpointUsage = "usage" + + defaultAPIKey = "Key" ) // CurrencyConverter stores the struct for the CurrencyConverter API @@ -93,7 +95,7 @@ func (c *CurrencyConverter) GetRates(baseCurrency, symbols string) (map[string]f // ConvertMany takes 2 or more currencies depending on if using the free // or paid API func (c *CurrencyConverter) ConvertMany(currencies []string) (map[string]float64, error) { - if len(currencies) > 2 && (c.APIKey == "" || c.APIKey == "Key") { + if len(currencies) > 2 && (c.APIKey == "" || c.APIKey == defaultAPIKey) { return nil, errors.New("currency fetching is limited to two currencies per request") } @@ -156,7 +158,7 @@ func (c *CurrencyConverter) GetCountries() (map[string]CountryItem, error) { func (c *CurrencyConverter) SendHTTPRequest(endPoint string, values url.Values, result interface{}) error { var path string - if c.APIKey == "" || c.APIKey == "Key" { + if c.APIKey == "" || c.APIKey == defaultAPIKey { path = fmt.Sprintf("%s%s/%s?", APIEndpointFreeURL, APIEndpointVersion, endPoint) } else { path = fmt.Sprintf("%s%s%s?", APIEndpointURL, APIEndpointVersion, endPoint) diff --git a/currency/symbol/symbol.go b/currency/symbol/symbol.go index 408af0c6..1ecdb8da 100644 --- a/currency/symbol/symbol.go +++ b/currency/symbol/symbol.go @@ -52,7 +52,7 @@ const ( BAT = "BAT" ETP = "ETP" HOT = "HOT" - STRAT = "STRAT" + STRAT = "STRAT" // nolint: misspell GNT = "GNT" REP = "REP" SNT = "SNT" diff --git a/currency/translation/translation.go b/currency/translation/translation.go index 65948ae2..d2c07a38 100644 --- a/currency/translation/translation.go +++ b/currency/translation/translation.go @@ -30,8 +30,5 @@ func GetTranslation(currency pair.CurrencyItem) (pair.CurrencyItem, error) { // HasTranslation returns whether or not a particular currency has a translation func HasTranslation(currency pair.CurrencyItem) bool { _, err := GetTranslation(currency) - if err != nil { - return false - } - return true + return (err == nil) } diff --git a/exchanges/alphapoint/alphapoint_test.go b/exchanges/alphapoint/alphapoint_test.go index 8f538602..9a40ef08 100644 --- a/exchanges/alphapoint/alphapoint_test.go +++ b/exchanges/alphapoint/alphapoint_test.go @@ -613,7 +613,7 @@ func TestWithdraw(t *testing.T) { _, err := a.WithdrawCryptocurrencyFunds(withdrawCryptoRequest) if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not implemented', recieved %v", err) + t.Errorf("Expected 'Not implemented', received %v", err) } } @@ -629,7 +629,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := a.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrNotYetImplemented { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrNotYetImplemented, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err) } } @@ -645,6 +645,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := a.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrNotYetImplemented { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrNotYetImplemented, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err) } } diff --git a/exchanges/anx/anx.go b/exchanges/anx/anx.go index 6ac8326e..faedbf0a 100644 --- a/exchanges/anx/anx.go +++ b/exchanges/anx/anx.go @@ -420,10 +420,8 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf request["nonce"] = a.Nonce.String()[0:13] path = fmt.Sprintf("api/%s/%s", anxAPIVersion, path) - if params != nil { - for key, value := range params { - request[key] = value - } + for key, value := range params { + request[key] = value } PayloadJSON, err := common.JSONEncode(request) @@ -438,7 +436,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf hmac := common.GetHMAC(common.HashSHA512, []byte(path+string("\x00")+string(PayloadJSON)), []byte(a.APISecret)) headers := make(map[string]string) headers["Rest-Key"] = a.APIKey - headers["Rest-Sign"] = common.Base64Encode([]byte(hmac)) + headers["Rest-Sign"] = common.Base64Encode(hmac) headers["Content-Type"] = "application/json" return a.SendPayload("POST", a.APIUrl+path, headers, bytes.NewBuffer(PayloadJSON), result, true, a.Verbose) diff --git a/exchanges/anx/anx_test.go b/exchanges/anx/anx_test.go index 5e050127..886c28b3 100644 --- a/exchanges/anx/anx_test.go +++ b/exchanges/anx/anx_test.go @@ -376,7 +376,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := a.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -392,7 +392,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := a.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/binance/binance.go b/exchanges/binance/binance.go index 3d38e7a0..a3d4c582 100644 --- a/exchanges/binance/binance.go +++ b/exchanges/binance/binance.go @@ -208,7 +208,6 @@ func (b *Binance) GetOrderBook(obd OrderBookDataRequestParams) (OrderBook, error case 1: ASK.Quantity, _ = strconv.ParseFloat(ask.(string), 64) orderbook.Asks = append(orderbook.Asks, ASK) - break } } } @@ -225,7 +224,6 @@ func (b *Binance) GetOrderBook(obd OrderBookDataRequestParams) (OrderBook, error case 1: BID.Quantity, _ = strconv.ParseFloat(bid.(string), 64) orderbook.Bids = append(orderbook.Bids, BID) - break } } } @@ -706,7 +704,7 @@ func (b *Binance) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { } fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount, multiplier) case exchange.CryptocurrencyWithdrawalFee: - fee = getCryptocurrencyWithdrawalFee(feeBuilder.FirstCurrency, feeBuilder.PurchasePrice, feeBuilder.Amount) + fee = getCryptocurrencyWithdrawalFee(feeBuilder.FirstCurrency) } if fee < 0 { fee = 0 @@ -735,7 +733,7 @@ func calculateTradingFee(purchasePrice, amount, multiplier float64) float64 { } // getCryptocurrencyWithdrawalFee returns the fee for withdrawing from the exchange -func getCryptocurrencyWithdrawalFee(currency string, purchasePrice, amount float64) float64 { +func getCryptocurrencyWithdrawalFee(currency string) float64 { return WithdrawalFees[currency] } @@ -746,13 +744,13 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string params := url.Values{} params.Set("asset", asset) - params.Set("address", string(address)) - params.Set("amount", string(amount)) + params.Set("address", address) + params.Set("amount", amount) if len(name) > 0 { - params.Set("name", string(name)) + params.Set("name", name) } if len(addressTag) > 0 { - params.Set("addressTag", string(addressTag)) + params.Set("addressTag", addressTag) } if err := b.SendAuthHTTPRequest("POST", path, params, &resp); err != nil { diff --git a/exchanges/binance/binance_test.go b/exchanges/binance/binance_test.go index ea9295f4..b3d23866 100644 --- a/exchanges/binance/binance_test.go +++ b/exchanges/binance/binance_test.go @@ -471,7 +471,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := b.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -487,7 +487,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/binance/binance_websocket.go b/exchanges/binance/binance_websocket.go index 648033c2..56dd04ae 100644 --- a/exchanges/binance/binance_websocket.go +++ b/exchanges/binance/binance_websocket.go @@ -15,6 +15,7 @@ import ( "github.com/thrasher-/gocryptotrader/currency/pair" exchange "github.com/thrasher-/gocryptotrader/exchanges" "github.com/thrasher-/gocryptotrader/exchanges/orderbook" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) const ( @@ -60,7 +61,7 @@ func (b *Binance) SeedLocalCache(p pair.CurrencyPair) error { newOrderBook.Pair = pair.NewCurrencyPairFromString(formattedPair.String()) newOrderBook.CurrencyPair = formattedPair.String() newOrderBook.LastUpdated = time.Now() - newOrderBook.AssetType = "SPOT" + newOrderBook.AssetType = ticker.Spot return b.Websocket.Orderbook.LoadSnapshot(newOrderBook, b.GetName(), false) } @@ -155,17 +156,18 @@ func (b *Binance) WSConnect() error { depth if b.Websocket.GetProxyAddress() != "" { - url, err := url.Parse(b.Websocket.GetProxyAddress()) + var u *url.URL + u, err = url.Parse(b.Websocket.GetProxyAddress()) if err != nil { return fmt.Errorf("binance_websocket.go - Unable to connect to parse proxy address. Error: %s", err) } - Dialer.Proxy = http.ProxyURL(url) + Dialer.Proxy = http.ProxyURL(u) } for _, ePair := range b.GetEnabledCurrencies() { - err := b.SeedLocalCache(ePair) + err = b.SeedLocalCache(ePair) if err != nil { return err } @@ -264,9 +266,9 @@ func (b *Binance) WsHandleData() { continue } else if strings.Contains(multiStreamData.Stream, "ticker") { - ticker := TickerStream{} + t := TickerStream{} - err := common.JSONDecode(multiStreamData.Data, &ticker) + err := common.JSONDecode(multiStreamData.Data, &t) if err != nil { b.Websocket.DataHandler <- fmt.Errorf("binance_websocket.go - Could not convert to a TickerStream structure %s", err.Error()) @@ -275,15 +277,15 @@ func (b *Binance) WsHandleData() { var wsTicker exchange.TickerData - wsTicker.Timestamp = time.Unix(0, ticker.EventTime) - wsTicker.Pair = pair.NewCurrencyPairFromString(ticker.Symbol) - wsTicker.AssetType = "SPOT" + wsTicker.Timestamp = time.Unix(0, t.EventTime) + wsTicker.Pair = pair.NewCurrencyPairFromString(t.Symbol) + wsTicker.AssetType = ticker.Spot wsTicker.Exchange = b.GetName() - wsTicker.ClosePrice, _ = strconv.ParseFloat(ticker.CurrDayClose, 64) - wsTicker.Quantity, _ = strconv.ParseFloat(ticker.TotalTradedVolume, 64) - wsTicker.OpenPrice, _ = strconv.ParseFloat(ticker.OpenPrice, 64) - wsTicker.HighPrice, _ = strconv.ParseFloat(ticker.HighPrice, 64) - wsTicker.LowPrice, _ = strconv.ParseFloat(ticker.LowPrice, 64) + wsTicker.ClosePrice, _ = strconv.ParseFloat(t.CurrDayClose, 64) + wsTicker.Quantity, _ = strconv.ParseFloat(t.TotalTradedVolume, 64) + wsTicker.OpenPrice, _ = strconv.ParseFloat(t.OpenPrice, 64) + wsTicker.HighPrice, _ = strconv.ParseFloat(t.HighPrice, 64) + wsTicker.LowPrice, _ = strconv.ParseFloat(t.LowPrice, 64) b.Websocket.DataHandler <- wsTicker continue @@ -302,7 +304,7 @@ func (b *Binance) WsHandleData() { wsKline.Timestamp = time.Unix(0, kline.EventTime) wsKline.Pair = pair.NewCurrencyPairFromString(kline.Symbol) - wsKline.AssetType = "SPOT" + wsKline.AssetType = ticker.Spot wsKline.Exchange = b.GetName() wsKline.StartTime = time.Unix(0, kline.Kline.StartTime) wsKline.CloseTime = time.Unix(0, kline.Kline.CloseTime) diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index 8384cb99..eb48bc98 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -934,10 +934,8 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[ request["request"] = fmt.Sprintf("%s%s", bitfinexAPIVersion, path) request["nonce"] = b.Nonce.String() - if params != nil { - for key, value := range params { - request[key] = value - } + for key, value := range params { + request[key] = value } PayloadJSON, err := common.JSONEncode(request) diff --git a/exchanges/bitfinex/bitfinex_websocket.go b/exchanges/bitfinex/bitfinex_websocket.go index 866a037f..abd319d5 100644 --- a/exchanges/bitfinex/bitfinex_websocket.go +++ b/exchanges/bitfinex/bitfinex_websocket.go @@ -135,7 +135,8 @@ func (b *Bitfinex) WsConnect() error { var err error if b.Websocket.GetProxyAddress() != "" { - proxy, err := url.Parse(b.Websocket.GetProxyAddress()) + var proxy *url.URL + proxy, err = url.Parse(b.Websocket.GetProxyAddress()) if err != nil { return err } @@ -171,7 +172,7 @@ func (b *Bitfinex) WsConnect() error { params["prec"] = "P0" } params["pair"] = y - err := b.WsSubscribe(x, params) + err = b.WsSubscribe(x, params) if err != nil { return err } diff --git a/exchanges/bitfinex/bitfinex_wrapper.go b/exchanges/bitfinex/bitfinex_wrapper.go index 78442b45..127afb46 100644 --- a/exchanges/bitfinex/bitfinex_wrapper.go +++ b/exchanges/bitfinex/bitfinex_wrapper.go @@ -271,12 +271,12 @@ func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest exchange.WithdrawRequest) ( var withdrawalSuccesses string var withdrawalErrors string - for _, withdrawl := range resp { - if withdrawl.Status == "error" { - withdrawalErrors += fmt.Sprintf("%v ", withdrawl.Message) + for _, withdrawal := range resp { + if withdrawal.Status == "error" { + withdrawalErrors += fmt.Sprintf("%v ", withdrawal.Message) } - if withdrawl.Status == "success" { - withdrawalSuccesses += fmt.Sprintf("%v,", withdrawl.WithdrawalID) + if withdrawal.Status == "success" { + withdrawalSuccesses += fmt.Sprintf("%v,", withdrawal.WithdrawalID) } } if len(withdrawalErrors) > 0 { diff --git a/exchanges/bitflyer/bitflyer.go b/exchanges/bitflyer/bitflyer.go index 604077d8..8bfe7233 100644 --- a/exchanges/bitflyer/bitflyer.go +++ b/exchanges/bitflyer/bitflyer.go @@ -386,7 +386,7 @@ func (b *Bitflyer) SendHTTPRequest(path string, result interface{}) error { func (b *Bitflyer) SendAuthHTTPRequest(path string, params url.Values, result interface{}) { headers := make(map[string]string) headers["ACCESS-KEY"] = b.APIKey - headers["ACCESS-TIMESTAMP"] = strconv.FormatInt(int64(time.Now().UnixNano()), 10) + headers["ACCESS-TIMESTAMP"] = strconv.FormatInt(time.Now().UnixNano(), 10) } // GetFee returns an estimate of fee based on type of transaction @@ -398,7 +398,7 @@ func (b *Bitflyer) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { case exchange.CryptocurrencyTradeFee: fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount) case exchange.InternationalBankDepositFee: - fee = getDepositFee(feeBuilder.BankTransactionType, feeBuilder.CurrencyItem, feeBuilder.Amount) + fee = getDepositFee(feeBuilder.BankTransactionType, feeBuilder.CurrencyItem) case exchange.InternationalBankWithdrawalFee: fee = getWithdrawalFee(feeBuilder.BankTransactionType, feeBuilder.CurrencyItem, feeBuilder.Amount) } @@ -415,7 +415,7 @@ func calculateTradingFee(purchasePrice float64, amount float64) float64 { return fee * amount * purchasePrice } -func getDepositFee(bankTransactionType exchange.InternationalBankTransactionType, currency string, amount float64) (fee float64) { +func getDepositFee(bankTransactionType exchange.InternationalBankTransactionType, currency string) (fee float64) { switch bankTransactionType { case exchange.WireTransfer: switch currency { diff --git a/exchanges/bitflyer/bitflyer_test.go b/exchanges/bitflyer/bitflyer_test.go index 18fca113..de5cd7c4 100644 --- a/exchanges/bitflyer/bitflyer_test.go +++ b/exchanges/bitflyer/bitflyer_test.go @@ -274,7 +274,7 @@ func TestSubmitOrder(t *testing.T) { } _, err := b.SubmitOrder(p, exchange.Buy, exchange.Market, 1, 1, "clientId") if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -299,7 +299,7 @@ func TestCancelExchangeOrder(t *testing.T) { err := b.CancelOrder(orderCancellation) // Assert if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -324,7 +324,7 @@ func TestCancelAllExchangeOrders(t *testing.T) { _, err := b.CancelAllOrders(orderCancellation) // Assert if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -344,7 +344,7 @@ func TestWithdraw(t *testing.T) { _, err := b.WithdrawCryptocurrencyFunds(withdrawCryptoRequest) if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -367,7 +367,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := b.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrNotYetImplemented { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrNotYetImplemented, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err) } } @@ -383,6 +383,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrNotYetImplemented { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrNotYetImplemented, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err) } } diff --git a/exchanges/bithumb/bithumb_test.go b/exchanges/bithumb/bithumb_test.go index e95684cc..2c52eeea 100644 --- a/exchanges/bithumb/bithumb_test.go +++ b/exchanges/bithumb/bithumb_test.go @@ -479,7 +479,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/bithumb/bithumb_wrapper.go b/exchanges/bithumb/bithumb_wrapper.go index 837d666f..7f310ac1 100644 --- a/exchanges/bithumb/bithumb_wrapper.go +++ b/exchanges/bithumb/bithumb_wrapper.go @@ -228,10 +228,7 @@ func (b *Bithumb) CancelAllOrders(orderCancellation exchange.OrderCancellation) if err != nil { return cancelAllOrdersResponse, err } - - for _, order := range orders.Data { - allOrders = append(allOrders, order) - } + allOrders = append(allOrders, orders.Data...) } for _, order := range allOrders { diff --git a/exchanges/bitmex/bitmex_parameters.go b/exchanges/bitmex/bitmex_parameters.go index e5155c66..ea40bb34 100644 --- a/exchanges/bitmex/bitmex_parameters.go +++ b/exchanges/bitmex/bitmex_parameters.go @@ -110,10 +110,7 @@ func (p APIKeyParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p APIKeyParams) IsNil() bool { - if p == (APIKeyParams{}) { - return true - } - return false + return p == (APIKeyParams{}) } // ChatGetParams contains all the parameters to send to the API endpoint @@ -148,10 +145,7 @@ func (p ChatGetParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p ChatGetParams) IsNil() bool { - if p == (ChatGetParams{}) { - return true - } - return false + return p == (ChatGetParams{}) } // ChatSendParams contains all the parameters to send to the API endpoint @@ -179,10 +173,7 @@ func (p ChatSendParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p ChatSendParams) IsNil() bool { - if p == (ChatSendParams{}) { - return true - } - return false + return p == (ChatSendParams{}) } // GenericRequestParams contains all the parameters for some general functions @@ -239,10 +230,7 @@ func (p GenericRequestParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p GenericRequestParams) IsNil() bool { - if p == (GenericRequestParams{}) { - return true - } - return false + return p == (GenericRequestParams{}) } // LeaderboardGetParams contains all the parameters to send to the API endpoint @@ -264,10 +252,7 @@ func (p LeaderboardGetParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p LeaderboardGetParams) IsNil() bool { - if p == (LeaderboardGetParams{}) { - return true - } - return false + return p == (LeaderboardGetParams{}) } // OrderNewParams contains all the parameters to send to the API endpoint @@ -359,10 +344,7 @@ func (p OrderNewParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderNewParams) IsNil() bool { - if p == (OrderNewParams{}) { - return true - } - return false + return p == (OrderNewParams{}) } // OrderAmendParams contains all the parameters to send to the API endpoint @@ -427,10 +409,7 @@ func (p OrderAmendParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderAmendParams) IsNil() bool { - if p == (OrderAmendParams{}) { - return true - } - return false + return p == (OrderAmendParams{}) } // OrderCancelParams contains all the parameters to send to the API endpoint @@ -458,10 +437,7 @@ func (p OrderCancelParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderCancelParams) IsNil() bool { - if p == (OrderCancelParams{}) { - return true - } - return false + return p == (OrderCancelParams{}) } // OrderCancelAllParams contains all the parameters to send to the API endpoint @@ -492,10 +468,7 @@ func (p OrderCancelAllParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderCancelAllParams) IsNil() bool { - if p == (OrderCancelAllParams{}) { - return true - } - return false + return p == (OrderCancelAllParams{}) } // OrderAmendBulkParams contains all the parameters to send to the API endpoint @@ -517,10 +490,7 @@ func (p OrderAmendBulkParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderAmendBulkParams) IsNil() bool { - if len(p.Orders) == 0 { - return true - } - return false + return len(p.Orders) == 0 } // OrderNewBulkParams contains all the parameters to send to the API endpoint @@ -542,10 +512,7 @@ func (p OrderNewBulkParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderNewBulkParams) IsNil() bool { - if len(p.Orders) == 0 { - return true - } - return false + return len(p.Orders) == 0 } // OrderCancelAllAfterParams contains all the parameters to send to the API @@ -568,10 +535,7 @@ func (p OrderCancelAllAfterParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderCancelAllAfterParams) IsNil() bool { - if p == (OrderCancelAllAfterParams{}) { - return true - } - return false + return p == (OrderCancelAllAfterParams{}) } // OrderClosePositionParams contains all the parameters to send to the API @@ -597,10 +561,7 @@ func (p OrderClosePositionParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderClosePositionParams) IsNil() bool { - if p == (OrderClosePositionParams{}) { - return true - } - return false + return p == (OrderClosePositionParams{}) } // OrderBookGetL2Params contains all the parameters to send to the API endpoint @@ -630,10 +591,7 @@ func (p OrderBookGetL2Params) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p OrderBookGetL2Params) IsNil() bool { - if p == (OrderBookGetL2Params{}) { - return true - } - return false + return p == (OrderBookGetL2Params{}) } // PositionGetParams contains all the parameters to send to the API endpoint @@ -662,10 +620,7 @@ func (p PositionGetParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p PositionGetParams) IsNil() bool { - if p == (PositionGetParams{}) { - return true - } - return false + return p == (PositionGetParams{}) } // PositionIsolateMarginParams contains all the parameters to send to the API @@ -691,10 +646,7 @@ func (p PositionIsolateMarginParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p PositionIsolateMarginParams) IsNil() bool { - if p == (PositionIsolateMarginParams{}) { - return true - } - return false + return p == (PositionIsolateMarginParams{}) } // PositionUpdateLeverageParams contains all the parameters to send to the API @@ -721,10 +673,7 @@ func (p PositionUpdateLeverageParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p PositionUpdateLeverageParams) IsNil() bool { - if p == (PositionUpdateLeverageParams{}) { - return true - } - return false + return p == (PositionUpdateLeverageParams{}) } // PositionUpdateRiskLimitParams contains all the parameters to send to the API @@ -750,10 +699,7 @@ func (p PositionUpdateRiskLimitParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p PositionUpdateRiskLimitParams) IsNil() bool { - if p == (PositionUpdateRiskLimitParams{}) { - return true - } - return false + return p == (PositionUpdateRiskLimitParams{}) } // PositionTransferIsolatedMarginParams contains all the parameters to send to @@ -779,10 +725,7 @@ func (p PositionTransferIsolatedMarginParams) ToURLVals(path string) (string, er // IsNil checks to see if any values has been set for the paramater func (p PositionTransferIsolatedMarginParams) IsNil() bool { - if p == (PositionTransferIsolatedMarginParams{}) { - return true - } - return false + return p == (PositionTransferIsolatedMarginParams{}) } // QuoteGetBucketedParams contains all the parameters to send to the API @@ -842,10 +785,7 @@ func (p QuoteGetBucketedParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p QuoteGetBucketedParams) IsNil() bool { - if p == (QuoteGetBucketedParams{}) { - return true - } - return false + return p == (QuoteGetBucketedParams{}) } // TradeGetBucketedParams contains all the parameters to send to the API @@ -906,10 +846,7 @@ func (p TradeGetBucketedParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p TradeGetBucketedParams) IsNil() bool { - if p == (TradeGetBucketedParams{}) { - return true - } - return false + return p == (TradeGetBucketedParams{}) } // UserUpdateParams contains all the parameters to send to the API endpoint @@ -946,10 +883,7 @@ func (p UserUpdateParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserUpdateParams) IsNil() bool { - if p == (UserUpdateParams{}) { - return true - } - return false + return p == (UserUpdateParams{}) } // UserTokenParams contains all the parameters to send to the API endpoint @@ -970,10 +904,7 @@ func (p UserTokenParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserTokenParams) IsNil() bool { - if p == (UserTokenParams{}) { - return true - } - return false + return p == (UserTokenParams{}) } // UserCheckReferralCodeParams contains all the parameters to send to the API @@ -995,10 +926,7 @@ func (p UserCheckReferralCodeParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserCheckReferralCodeParams) IsNil() bool { - if p == (UserCheckReferralCodeParams{}) { - return true - } - return false + return p == (UserCheckReferralCodeParams{}) } // UserConfirmTFAParams contains all the parameters to send to the API endpoint @@ -1024,10 +952,7 @@ func (p UserConfirmTFAParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserConfirmTFAParams) IsNil() bool { - if p == (UserConfirmTFAParams{}) { - return true - } - return false + return p == (UserConfirmTFAParams{}) } // UserCurrencyParams contains all the parameters to send to the API endpoint @@ -1048,10 +973,7 @@ func (p UserCurrencyParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserCurrencyParams) IsNil() bool { - if p == (UserCurrencyParams{}) { - return true - } - return false + return p == (UserCurrencyParams{}) } // UserPreferencesParams contains all the parameters to send to the API @@ -1076,10 +998,7 @@ func (p UserPreferencesParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserPreferencesParams) IsNil() bool { - if p == (UserPreferencesParams{}) { - return true - } - return false + return p == (UserPreferencesParams{}) } // UserRequestWithdrawalParams contains all the parameters to send to the API @@ -1116,8 +1035,5 @@ func (p UserRequestWithdrawalParams) ToURLVals(path string) (string, error) { // IsNil checks to see if any values has been set for the paramater func (p UserRequestWithdrawalParams) IsNil() bool { - if p == (UserRequestWithdrawalParams{}) { - return true - } - return false + return p == (UserRequestWithdrawalParams{}) } diff --git a/exchanges/bitmex/bitmex_test.go b/exchanges/bitmex/bitmex_test.go index 3b06c967..0efc06a6 100644 --- a/exchanges/bitmex/bitmex_test.go +++ b/exchanges/bitmex/bitmex_test.go @@ -618,7 +618,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := b.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -634,7 +634,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/bitmex/bitmex_websocket.go b/exchanges/bitmex/bitmex_websocket.go index 57ba026e..c3e63032 100644 --- a/exchanges/bitmex/bitmex_websocket.go +++ b/exchanges/bitmex/bitmex_websocket.go @@ -72,7 +72,8 @@ func (b *Bitmex) WsConnector() error { var err error if b.Websocket.GetProxyAddress() != "" { - proxy, err := url.Parse(b.Websocket.GetProxyAddress()) + var proxy *url.URL + proxy, err = url.Parse(b.Websocket.GetProxyAddress()) if err != nil { return err } @@ -169,7 +170,7 @@ func (b *Bitmex) wsHandleIncomingData() { } if common.StringContains(message, "ping") { - err := b.WebsocketConn.WriteJSON("pong") + err = b.WebsocketConn.WriteJSON("pong") if err != nil { b.Websocket.DataHandler <- err continue @@ -254,7 +255,8 @@ func (b *Bitmex) wsHandleIncomingData() { } for _, trade := range trades.Data { - timestamp, err := time.Parse(time.RFC3339, trade.Timestamp) + var timestamp time.Time + timestamp, err = time.Parse(time.RFC3339, trade.Timestamp) if err != nil { b.Websocket.DataHandler <- err continue @@ -320,7 +322,7 @@ func (b *Bitmex) processOrderbook(data []OrderBookL2, action string, currencyPai var bids, asks []orderbook.Item for _, orderbookItem := range data { - if orderbookItem.Side == "Sell" { + if orderbookItem.Side == exchange.Sell.ToString() { asks = append(asks, orderbook.Item{ Price: orderbookItem.Price, Amount: float64(orderbookItem.Size), diff --git a/exchanges/bitmex/bitmex_wrapper.go b/exchanges/bitmex/bitmex_wrapper.go index fe74be31..6888b980 100644 --- a/exchanges/bitmex/bitmex_wrapper.go +++ b/exchanges/bitmex/bitmex_wrapper.go @@ -107,12 +107,12 @@ func (b *Bitmex) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbo } for _, ob := range orderbookNew { - if ob.Side == "Sell" { + if ob.Side == exchange.Sell.ToString() { orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: float64(ob.Size), Price: ob.Price}) continue } - if ob.Side == "Buy" { + if ob.Side == exchange.Buy.ToString() { orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: float64(ob.Size), Price: ob.Price}) continue diff --git a/exchanges/bittrex/bittrex_test.go b/exchanges/bittrex/bittrex_test.go index 5c537bcd..c17ddee6 100644 --- a/exchanges/bittrex/bittrex_test.go +++ b/exchanges/bittrex/bittrex_test.go @@ -453,7 +453,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := b.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -469,7 +469,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/btcc/btcc.go b/exchanges/btcc/btcc.go index f650b66c..08f59ee4 100644 --- a/exchanges/btcc/btcc.go +++ b/exchanges/btcc/btcc.go @@ -115,8 +115,5 @@ func getCryptocurrencyWithdrawalFee(currency string) float64 { } func getInternationalBankWithdrawalFee(currency string, amount float64) float64 { - var fee float64 - - fee = WithdrawalFees[currency] * amount - return fee + return WithdrawalFees[currency] * amount } diff --git a/exchanges/btcc/btcc_test.go b/exchanges/btcc/btcc_test.go index 7285dbd2..fdb1c670 100644 --- a/exchanges/btcc/btcc_test.go +++ b/exchanges/btcc/btcc_test.go @@ -197,7 +197,7 @@ func TestSubmitOrder(t *testing.T) { } _, err := b.SubmitOrder(p, exchange.Buy, exchange.Limit, 1, 1, "clientId") if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -224,7 +224,7 @@ func TestCancelExchangeOrder(t *testing.T) { // Assert if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -251,7 +251,7 @@ func TestCancelAllExchangeOrders(t *testing.T) { // Assert if err != common.ErrNotYetImplemented { - t.Errorf("Expected 'Not Yet Implemented', recieved %v", err) + t.Errorf("Expected 'Not Yet Implemented', received %v", err) } } @@ -271,7 +271,7 @@ func TestWithdraw(t *testing.T) { _, err := b.WithdrawCryptocurrencyFunds(withdrawCryptoRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -294,7 +294,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := b.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -310,6 +310,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/btcc/btcc_websocket.go b/exchanges/btcc/btcc_websocket.go index 76f46af3..81a7badd 100644 --- a/exchanges/btcc/btcc_websocket.go +++ b/exchanges/btcc/btcc_websocket.go @@ -51,11 +51,12 @@ func (b *BTCC) WsConnect() error { var err error if b.Websocket.GetProxyAddress() != "" { - prxy, err := url.Parse(b.Websocket.GetProxyAddress()) + var proxy *url.URL + proxy, err = url.Parse(b.Websocket.GetProxyAddress()) if err != nil { return err } - dialer.Proxy = http.ProxyURL(prxy) + dialer.Proxy = http.ProxyURL(proxy) } b.Conn, _, err = dialer.Dial(b.Websocket.GetWebsocketURL(), http.Header{}) @@ -170,7 +171,7 @@ func (b *BTCC) WsHandleData() { case msgTypeGetTrades: var trades WsTrades - err := common.JSONDecode(resp.Raw, &trades) + err = common.JSONDecode(resp.Raw, &trades) if err != nil { b.Websocket.DataHandler <- err continue @@ -182,7 +183,7 @@ func (b *BTCC) WsHandleData() { // orderbook feeds var orderbook WsOrderbookSnapshot - err := common.JSONDecode(resp.Raw, &orderbook) + err = common.JSONDecode(resp.Raw, &orderbook) if err != nil { b.Websocket.DataHandler <- err continue @@ -477,8 +478,8 @@ func (b *BTCC) WsProcessOrderbookUpdate(ob WsOrderbookSnapshot) error { func (b *BTCC) WsProcessOldOrderbookSnapshot(ob WsOrderbookSnapshotOld, symbol string) error { var asks, bids []orderbook.Item - askData, _ := ob.Data["Asks"] - bidData, _ := ob.Data["Bids"] + askData := ob.Data["Asks"] + bidData := ob.Data["Bids"] for _, ask := range askData { data := ask.([]interface{}) diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index b7b07690..0e416586 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -467,11 +467,11 @@ func (b *BTCMarkets) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { if err != nil { return 0, err } - fee = calculateTradingFee(feeBuilder.FirstCurrency+feeBuilder.Delimiter+feeBuilder.SecondCurrency, tradingFee, feeBuilder.PurchasePrice, feeBuilder.Amount) + fee = calculateTradingFee(tradingFee, feeBuilder.PurchasePrice, feeBuilder.Amount) case exchange.CryptocurrencyWithdrawalFee: fee = getCryptocurrencyWithdrawalFee(feeBuilder.FirstCurrency) case exchange.InternationalBankWithdrawalFee: - fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.Amount) + fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem) } if fee < 0 { fee = 0 @@ -479,9 +479,8 @@ func (b *BTCMarkets) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { return fee, nil } -func calculateTradingFee(curr string, tradingFee TradingFee, purchasePrice, amount float64) (fee float64) { +func calculateTradingFee(tradingFee TradingFee, purchasePrice, amount float64) (fee float64) { fee = tradingFee.TradingFeeRate / 100000000 - return fee * amount * purchasePrice } @@ -489,7 +488,7 @@ func getCryptocurrencyWithdrawalFee(currency string) float64 { return WithdrawalFees[currency] } -func getInternationalBankWithdrawalFee(currency string, amount float64) float64 { +func getInternationalBankWithdrawalFee(currency string) float64 { var fee float64 if currency == symbol.AUD { diff --git a/exchanges/btcmarkets/btcmarkets_test.go b/exchanges/btcmarkets/btcmarkets_test.go index acd007cc..6b38c53b 100644 --- a/exchanges/btcmarkets/btcmarkets_test.go +++ b/exchanges/btcmarkets/btcmarkets_test.go @@ -447,7 +447,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := b.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/coinbasepro/coinbasepro.go b/exchanges/coinbasepro/coinbasepro.go index be1e581d..f8028166 100644 --- a/exchanges/coinbasepro/coinbasepro.go +++ b/exchanges/coinbasepro/coinbasepro.go @@ -818,7 +818,7 @@ func (c *CoinbasePro) SendAuthenticatedHTTPRequest(method, path string, params m message := nonce + method + "/" + path + string(payload) hmac := common.GetHMAC(common.HashSHA256, []byte(message), []byte(c.APISecret)) headers := make(map[string]string) - headers["CB-ACCESS-SIGN"] = common.Base64Encode([]byte(hmac)) + headers["CB-ACCESS-SIGN"] = common.Base64Encode(hmac) headers["CB-ACCESS-TIMESTAMP"] = nonce headers["CB-ACCESS-KEY"] = c.APIKey headers["CB-ACCESS-PASSPHRASE"] = c.ClientID @@ -838,9 +838,9 @@ func (c *CoinbasePro) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { } fee = c.calculateTradingFee(trailingVolume, feeBuilder.FirstCurrency, feeBuilder.Delimiter, feeBuilder.SecondCurrency, feeBuilder.PurchasePrice, feeBuilder.Amount, feeBuilder.IsMaker) case exchange.InternationalBankWithdrawalFee: - fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.Amount) + fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem) case exchange.InternationalBankDepositFee: - fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem, feeBuilder.Amount) + fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem) } if fee < 0 { @@ -870,7 +870,7 @@ func (c *CoinbasePro) calculateTradingFee(trailingVolume []Volume, firstCurrency return fee * amount * purchasePrice } -func getInternationalBankWithdrawalFee(currency string, amount float64) float64 { +func getInternationalBankWithdrawalFee(currency string) float64 { var fee float64 if currency == symbol.USD { @@ -882,7 +882,7 @@ func getInternationalBankWithdrawalFee(currency string, amount float64) float64 return fee } -func getInternationalBankDepositFee(currency string, amount float64) float64 { +func getInternationalBankDepositFee(currency string) float64 { var fee float64 if currency == symbol.USD { diff --git a/exchanges/coinut/coinut.go b/exchanges/coinut/coinut.go index a9a75aed..9e1e1180 100644 --- a/exchanges/coinut/coinut.go +++ b/exchanges/coinut/coinut.go @@ -253,10 +253,7 @@ func (c *COINUT) CancelOrders(orders []CancelOrders) (CancelOrdersResponse, erro } entries := []CancelOrders{} - for _, order := range orders { - entries = append(entries, order) - } - + entries = append(entries, orders...) params["entries"] = entries return result, c.SendHTTPRequest(coinutOrdersCancel, params, true, &result) @@ -365,7 +362,7 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{ headers := make(map[string]string) if authenticated { headers["X-USER"] = c.ClientID - hmac := common.GetHMAC(common.HashSHA256, []byte(payload), []byte(c.APISecret)) + hmac := common.GetHMAC(common.HashSHA256, payload, []byte(c.APISecret)) headers["X-SIGNATURE"] = common.HexEncodeToString(hmac) } headers["Content-Type"] = "application/json" diff --git a/exchanges/coinut/coinut_test.go b/exchanges/coinut/coinut_test.go index 75a41945..4a92bed7 100644 --- a/exchanges/coinut/coinut_test.go +++ b/exchanges/coinut/coinut_test.go @@ -325,7 +325,7 @@ func TestWithdraw(t *testing.T) { _, err := c.WithdrawCryptocurrencyFunds(withdrawCryptoRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected 'Not supported', recieved %v", err) + t.Errorf("Expected 'Not supported', received %v", err) } } @@ -341,7 +341,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := c.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -357,7 +357,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := c.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/coinut/coinut_wrapper.go b/exchanges/coinut/coinut_wrapper.go index faf600b6..447fd60a 100644 --- a/exchanges/coinut/coinut_wrapper.go +++ b/exchanges/coinut/coinut_wrapper.go @@ -239,15 +239,15 @@ func (c *COINUT) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, order return submitOrderResponse, errors.New("unsupported order type") } - switch APIresponse.(type) { + switch apiResp := APIresponse.(type) { case OrdersBase: - orderResult := APIresponse.(OrdersBase) + orderResult := apiResp submitOrderResponse.OrderID = fmt.Sprintf("%v", orderResult.OrderID) case OrderFilledResponse: - orderResult := APIresponse.(OrderFilledResponse) + orderResult := apiResp submitOrderResponse.OrderID = fmt.Sprintf("%v", orderResult.Order.OrderID) case OrderRejectResponse: - orderResult := APIresponse.(OrderRejectResponse) + orderResult := apiResp submitOrderResponse.OrderID = fmt.Sprintf("%v", orderResult.OrderID) err = fmt.Errorf("OrderID: %v was rejected: %v", orderResult.OrderID, orderResult.Reasons) } @@ -310,9 +310,7 @@ func (c *COINUT) CancelAllOrders(orderCancellation exchange.OrderCancellation) ( return cancelAllOrdersResponse, err } - for _, openOrder := range openOrders.Orders { - allTheOrders = append(allTheOrders, openOrder) - } + allTheOrders = append(allTheOrders, openOrders.Orders...) } } diff --git a/exchanges/exchange.go b/exchanges/exchange.go index 814b97e1..13d149ad 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -883,10 +883,7 @@ func (e *Base) GetWithdrawPermissions() uint32 { // SupportsWithdrawPermissions compares the supplied permissions with the exchange's to verify they're supported func (e *Base) SupportsWithdrawPermissions(permissions uint32) bool { exchangePermissions := e.GetWithdrawPermissions() - if permissions&exchangePermissions == permissions { - return true - } - return false + return permissions&exchangePermissions == permissions } // FormatWithdrawPermissions will return each of the exchange's compatible withdrawal methods in readable form diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index 2e824de5..8309b58a 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -25,7 +25,7 @@ func TestSupportsRESTTickerBatchUpdates(t *testing.T) { func TestHTTPClient(t *testing.T) { r := Base{Name: "asdf"} - r.SetHTTPClientTimeout(time.Duration(time.Second * 5)) + r.SetHTTPClientTimeout(time.Second * 5) if r.GetHTTPClient().Timeout != time.Second*5 { t.Fatalf("Test failed. TestHTTPClient unexpected value") @@ -33,7 +33,7 @@ func TestHTTPClient(t *testing.T) { r.Requester = nil newClient := new(http.Client) - newClient.Timeout = time.Duration(time.Second * 10) + newClient.Timeout = time.Second * 10 r.SetHTTPClient(newClient) if r.GetHTTPClient().Timeout != time.Second*10 { @@ -57,7 +57,7 @@ func TestHTTPClient(t *testing.T) { } newClient = new(http.Client) - newClient.Timeout = time.Duration(time.Second * 10) + newClient.Timeout = time.Second * 10 b.SetHTTPClient(newClient) if b.GetHTTPClient().Timeout != time.Second*10 { diff --git a/exchanges/exchange_websocket.go b/exchanges/exchange_websocket.go index 93755f31..0e31b190 100644 --- a/exchanges/exchange_websocket.go +++ b/exchanges/exchange_websocket.go @@ -561,17 +561,11 @@ func (w *WebsocketOrderbookLocal) UpdateUsingID(bidTargets, askTargets []orderbo } case "insert": - for _, target := range bidTargets { - orderbookAddress.Bids = append(orderbookAddress.Bids, target) - } - - for _, target := range askTargets { - orderbookAddress.Asks = append(orderbookAddress.Asks, target) - } + orderbookAddress.Bids = append(orderbookAddress.Bids, bidTargets...) + orderbookAddress.Asks = append(orderbookAddress.Asks, askTargets...) } orderbook.ProcessOrderbook(exchName, p, *orderbookAddress, assetType) - return nil } @@ -655,10 +649,7 @@ func (w *Websocket) GetFunctionality() uint32 { // SupportsFunctionality returns if the functionality is supported as a boolean func (w *Websocket) SupportsFunctionality(f uint32) bool { - if w.GetFunctionality()&f == f { - return true - } - return false + return w.GetFunctionality()&f == f } // FormatFunctionality will return each of the websocket connection compatible diff --git a/exchanges/exchange_websocket_test.go b/exchanges/exchange_websocket_test.go index 4d27f0f3..6ba5494c 100644 --- a/exchanges/exchange_websocket_test.go +++ b/exchanges/exchange_websocket_test.go @@ -314,7 +314,7 @@ func TestFunctionality(t *testing.T) { var w Websocket if w.FormatFunctionality() != NoWebsocketSupportText { - t.Fatalf("Test Failed - FormatFunctionality error expected %s but recieved %s", + t.Fatalf("Test Failed - FormatFunctionality error expected %s but received %s", NoWebsocketSupportText, w.FormatFunctionality()) } diff --git a/exchanges/exmo/exmo.go b/exchanges/exmo/exmo.go index 1f7b2df8..9e31b8fb 100644 --- a/exchanges/exmo/exmo.go +++ b/exchanges/exmo/exmo.go @@ -277,11 +277,11 @@ func (e *EXMO) GetCryptoDepositAddress() (map[string]string, error) { return nil, err } - switch result.(type) { + switch r := result.(type) { case map[string]interface{}: mapString := make(map[string]string) - for key, value := range result.(map[string]interface{}) { + for key, value := range r { strValue := fmt.Sprintf("%v", value) mapString[key] = strValue } diff --git a/exchanges/exmo/exmo_test.go b/exchanges/exmo/exmo_test.go index eb7b98de..76d9732b 100644 --- a/exchanges/exmo/exmo_test.go +++ b/exchanges/exmo/exmo_test.go @@ -369,7 +369,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := e.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -385,7 +385,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := e.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/gateio/gateio_test.go b/exchanges/gateio/gateio_test.go index dcb1b659..a9a503a9 100644 --- a/exchanges/gateio/gateio_test.go +++ b/exchanges/gateio/gateio_test.go @@ -402,7 +402,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := g.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -418,7 +418,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := g.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/gateio/gateio_websocket.go b/exchanges/gateio/gateio_websocket.go index 7463790a..0b1e0afd 100644 --- a/exchanges/gateio/gateio_websocket.go +++ b/exchanges/gateio/gateio_websocket.go @@ -156,7 +156,7 @@ func (g *Gateio) WsHandleData() { case common.StringContains(result.Method, "ticker"): var ticker WebsocketTicker var c string - err := common.JSONDecode(result.Params[1], &ticker) + err = common.JSONDecode(result.Params[1], &ticker) if err != nil { g.Websocket.DataHandler <- err continue @@ -183,7 +183,7 @@ func (g *Gateio) WsHandleData() { case common.StringContains(result.Method, "trades"): var trades []WebsocketTrade var c string - err := common.JSONDecode(result.Params[1], &trades) + err = common.JSONDecode(result.Params[1], &trades) if err != nil { g.Websocket.DataHandler <- err continue diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index bbea5aae..257044ae 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -496,10 +496,8 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st request["request"] = fmt.Sprintf("/v%s/%s", geminiAPIVersion, path) request["nonce"] = g.Nonce.GetValue(g.Name, false) - if params != nil { - for key, value := range params { - request[key] = value - } + for key, value := range params { + request[key] = value } PayloadJSON, err := common.JSONEncode(request) diff --git a/exchanges/gemini/gemini_test.go b/exchanges/gemini/gemini_test.go index b5c21eeb..a19da251 100644 --- a/exchanges/gemini/gemini_test.go +++ b/exchanges/gemini/gemini_test.go @@ -482,7 +482,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := Session[1].WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -499,7 +499,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := Session[1].WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/hitbtc/hitbtc.go b/exchanges/hitbtc/hitbtc.go index cd8108ae..360cba4b 100644 --- a/exchanges/hitbtc/hitbtc.go +++ b/exchanges/hitbtc/hitbtc.go @@ -314,13 +314,8 @@ func (h *HitBTC) GetOrderbook(currencyPair string, limit int) (Orderbook, error) } ob := Orderbook{} - for _, x := range resp.Asks { - ob.Asks = append(ob.Asks, x) - } - - for _, x := range resp.Bids { - ob.Bids = append(ob.Bids, x) - } + ob.Asks = append(ob.Asks, resp.Asks...) + ob.Bids = append(ob.Bids, resp.Bids...) return ob, nil } diff --git a/exchanges/hitbtc/hitbtc_test.go b/exchanges/hitbtc/hitbtc_test.go index 73224f7f..8776d265 100644 --- a/exchanges/hitbtc/hitbtc_test.go +++ b/exchanges/hitbtc/hitbtc_test.go @@ -312,7 +312,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := h.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -328,7 +328,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := h.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/huobi/huobi.go b/exchanges/huobi/huobi.go index 06b2a96e..178eccb1 100644 --- a/exchanges/huobi/huobi.go +++ b/exchanges/huobi/huobi.go @@ -863,7 +863,7 @@ func (h *HUOBI) SendAuthenticatedHTTPRequest(method, endpoint string, values url signature := common.Base64Encode(hmac) values.Set("Signature", signature) - if h.APIAuthPEMKeySupport == true { + if h.APIAuthPEMKeySupport { pemKey := strings.NewReader(h.APIAuthPEMKey) pemBytes, err := ioutil.ReadAll(pemKey) if err != nil { diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index fea31885..cc2bfe13 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -555,7 +555,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := h.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -571,7 +571,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := h.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/huobihadax/huobihadax_test.go b/exchanges/huobihadax/huobihadax_test.go index 20592138..a002c17b 100644 --- a/exchanges/huobihadax/huobihadax_test.go +++ b/exchanges/huobihadax/huobihadax_test.go @@ -539,7 +539,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := h.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -555,7 +555,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := h.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/itbit/itbit.go b/exchanges/itbit/itbit.go index 3848a0e2..ff6a52f4 100644 --- a/exchanges/itbit/itbit.go +++ b/exchanges/itbit/itbit.go @@ -363,17 +363,14 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params request := make(map[string]interface{}) url := i.APIUrl + path - if params != nil { - for key, value := range params { - request[key] = value - } + for key, value := range params { + request[key] = value } PayloadJSON := []byte("") var err error if params != nil { - PayloadJSON, err = common.JSONEncode(request) if err != nil { return err @@ -410,7 +407,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params RequestID string `json:"requestId"` }{} - err = i.SendPayload(method, url, headers, bytes.NewBuffer([]byte(PayloadJSON)), &intermediary, true, i.Verbose) + err = i.SendPayload(method, url, headers, bytes.NewBuffer(PayloadJSON), &intermediary, true, i.Verbose) if err != nil { return err } @@ -434,7 +431,7 @@ func (i *ItBit) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { case exchange.CryptocurrencyTradeFee: fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount, feeBuilder.IsMaker) case exchange.InternationalBankWithdrawalFee: - fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.Amount, feeBuilder.BankTransactionType) + fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.BankTransactionType) } if fee < 0 { @@ -454,7 +451,7 @@ func calculateTradingFee(purchasePrice, amount float64, isMaker bool) float64 { return feePercent * purchasePrice * amount } -func getInternationalBankWithdrawalFee(currency string, amount float64, bankTransactionType exchange.InternationalBankTransactionType) float64 { +func getInternationalBankWithdrawalFee(currency string, bankTransactionType exchange.InternationalBankTransactionType) float64 { var fee float64 if (bankTransactionType == exchange.Swift || bankTransactionType == exchange.WireTransfer) && currency == symbol.USD { fee = 40 diff --git a/exchanges/itbit/itbit_test.go b/exchanges/itbit/itbit_test.go index 46ef2e16..8a01e239 100644 --- a/exchanges/itbit/itbit_test.go +++ b/exchanges/itbit/itbit_test.go @@ -371,7 +371,7 @@ func TestWithdraw(t *testing.T) { _, err := i.WithdrawCryptocurrencyFunds(withdrawCryptoRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected 'Not supported', recieved %v", err) + t.Errorf("Expected 'Not supported', received %v", err) } } @@ -387,7 +387,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := i.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -403,7 +403,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := i.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/kraken/kraken_test.go b/exchanges/kraken/kraken_test.go index cc934367..fc2531ef 100644 --- a/exchanges/kraken/kraken_test.go +++ b/exchanges/kraken/kraken_test.go @@ -559,6 +559,6 @@ func TestWithdrawCancel(t *testing.T) { if areTestAPIKeysSet() && err == nil { t.Error("Test Failed - WithdrawCancel() error cannot be nil") } else if !areTestAPIKeysSet() && err == nil { - t.Errorf("Test Failed - WithdrawCancel() error - expecting an error when no keys are set but recieved nil") + t.Errorf("Test Failed - WithdrawCancel() error - expecting an error when no keys are set but received nil") } } diff --git a/exchanges/lakebtc/lakebtc.go b/exchanges/lakebtc/lakebtc.go index b4fda691..4c4056d2 100644 --- a/exchanges/lakebtc/lakebtc.go +++ b/exchanges/lakebtc/lakebtc.go @@ -273,7 +273,7 @@ func (l *LakeBTC) CancelExistingOrder(orderID int64) error { return err } - if resp.Result != true { + if !resp.Result { return errors.New("unable to cancel order") } return nil @@ -292,7 +292,7 @@ func (l *LakeBTC) CancelExistingOrders(orderIDs []string) error { return err } - if resp.Result != true { + if !resp.Result { return fmt.Errorf("unable to cancel order(s): %v", orderIDs) } return nil diff --git a/exchanges/lakebtc/lakebtc_test.go b/exchanges/lakebtc/lakebtc_test.go index bed35e93..6299ff10 100644 --- a/exchanges/lakebtc/lakebtc_test.go +++ b/exchanges/lakebtc/lakebtc_test.go @@ -375,7 +375,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := l.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -391,7 +391,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := l.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/lakebtc/lakebtc_types.go b/exchanges/lakebtc/lakebtc_types.go index dd890073..7bdda80e 100644 --- a/exchanges/lakebtc/lakebtc_types.go +++ b/exchanges/lakebtc/lakebtc_types.go @@ -48,7 +48,7 @@ type AccountInfo struct { Profile struct { Email string `json:"email"` UID string `json:"uid"` - BTCDepositAddress string `json:"btc_deposit_addres"` + BTCDepositAddress string `json:"btc_deposit_addres"` // nolint: misspell } `json:"profile"` } diff --git a/exchanges/liqui/liqui_test.go b/exchanges/liqui/liqui_test.go index 9dc2a278..ae0dc811 100644 --- a/exchanges/liqui/liqui_test.go +++ b/exchanges/liqui/liqui_test.go @@ -366,7 +366,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := l.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -382,6 +382,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := l.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/liqui/liqui_wrapper.go b/exchanges/liqui/liqui_wrapper.go index 0ad62d86..02d06302 100644 --- a/exchanges/liqui/liqui_wrapper.go +++ b/exchanges/liqui/liqui_wrapper.go @@ -156,7 +156,7 @@ func (l *Liqui) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exc // SubmitOrder submits a new order func (l *Liqui) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) { var submitOrderResponse exchange.SubmitOrderResponse - response, err := l.Trade(p.Pair().String(), fmt.Sprintf("%s", orderType), amount, price) + response, err := l.Trade(p.Pair().String(), orderType.ToString(), amount, price) if response > 0 { submitOrderResponse.OrderID = fmt.Sprintf("%v", response) diff --git a/exchanges/localbitcoins/localbitcoins_test.go b/exchanges/localbitcoins/localbitcoins_test.go index 152bfa19..748dd855 100644 --- a/exchanges/localbitcoins/localbitcoins_test.go +++ b/exchanges/localbitcoins/localbitcoins_test.go @@ -336,7 +336,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := l.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -352,7 +352,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := l.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/localbitcoins/localbitcoins_wrapper.go b/exchanges/localbitcoins/localbitcoins_wrapper.go index cc31664a..24b7cf0a 100644 --- a/exchanges/localbitcoins/localbitcoins_wrapper.go +++ b/exchanges/localbitcoins/localbitcoins_wrapper.go @@ -160,7 +160,7 @@ func (l *LocalBitcoins) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide Currency: p.SecondCurrency.String(), AccountInfo: "-", BankName: "Bank", - MSG: fmt.Sprintf("%s", side.ToString()), + MSG: side.ToString(), SMSVerficationRequired: true, TrackMaxAmount: true, RequireTrustedByAdvertiser: true, diff --git a/exchanges/okcoin/okcoin.go b/exchanges/okcoin/okcoin.go index 074e1f5d..2b7e7714 100644 --- a/exchanges/okcoin/okcoin.go +++ b/exchanges/okcoin/okcoin.go @@ -496,7 +496,7 @@ func (o *OKCoin) GetOrderInformation(orderID int64, symbol string) ([]OrderInfo, return nil, err } - if result.Result != true { + if !result.Result { return nil, errors.New("unable to retrieve order info") } @@ -526,7 +526,7 @@ func (o *OKCoin) GetOrderInfoBatch(orderID []int64, symbol string) ([]OrderInfo, return nil, err } - if result.Result != true { + if !result.Result { return nil, errors.New("unable to retrieve order info") } diff --git a/exchanges/okcoin/okcoin_test.go b/exchanges/okcoin/okcoin_test.go index 14e8f2de..73d1c5fa 100644 --- a/exchanges/okcoin/okcoin_test.go +++ b/exchanges/okcoin/okcoin_test.go @@ -286,7 +286,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := o.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -302,6 +302,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := o.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/okex/okex.go b/exchanges/okex/okex.go index 1ab68282..7c97f113 100644 --- a/exchanges/okex/okex.go +++ b/exchanges/okex/okex.go @@ -865,7 +865,7 @@ func (o *OKEX) GetSpotKline(arg KlinesRequestParams) ([]CandleStickData, error) values.Set("size", strconv.FormatInt(int64(arg.Size), 10)) } if arg.Since != 0 { - values.Set("since", strconv.FormatInt(int64(arg.Since), 10)) + values.Set("since", strconv.FormatInt(arg.Since, 10)) } path := fmt.Sprintf("%s%s%s.do?%s", o.APIUrl, apiVersion, spotKline, values.Encode()) diff --git a/exchanges/okex/okex_test.go b/exchanges/okex/okex_test.go index adf41e03..b54f58f9 100644 --- a/exchanges/okex/okex_test.go +++ b/exchanges/okex/okex_test.go @@ -551,7 +551,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := o.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -567,6 +567,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := o.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/okex/okex_wrapper.go b/exchanges/okex/okex_wrapper.go index 5bdd3af4..b29b1a31 100644 --- a/exchanges/okex/okex_wrapper.go +++ b/exchanges/okex/okex_wrapper.go @@ -264,9 +264,7 @@ func (o *OKEX) CancelAllOrders(orderCancellation exchange.OrderCancellation) (ex return cancelAllOrdersResponse, fmt.Errorf("Something went wrong for currency %s", formattedCurrency) } - for _, openOrder := range openOrders.Orders { - allOpenOrders = append(allOpenOrders, openOrder) - } + allOpenOrders = append(allOpenOrders, openOrders.Orders...) } for _, openOrder := range allOpenOrders { diff --git a/exchanges/poloniex/poloniex_test.go b/exchanges/poloniex/poloniex_test.go index 81eba6fb..dea71b89 100644 --- a/exchanges/poloniex/poloniex_test.go +++ b/exchanges/poloniex/poloniex_test.go @@ -331,7 +331,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := p.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -347,7 +347,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := p.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/poloniex/poloniex_websocket.go b/exchanges/poloniex/poloniex_websocket.go index 4c322284..7a711521 100644 --- a/exchanges/poloniex/poloniex_websocket.go +++ b/exchanges/poloniex/poloniex_websocket.go @@ -121,10 +121,7 @@ func getWSDataType(data interface{}) string { } func checkSubscriptionSuccess(data []interface{}) bool { - if data[1].(float64) != 1 { - return false - } - return true + return data[1].(float64) == 1 } // WsHandleData handles data from the websocket connection @@ -406,7 +403,7 @@ var CurrencyPairID = map[int]string{ 174: "BTC_REP", 177: "BTC_ARDR", 178: "BTC_ZEC", - 182: "BTC_STRAT", + 182: "BTC_STRAT", // nolint: misspell 184: "BTC_PASC", 185: "BTC_GNT", 187: "BTC_GNO", diff --git a/exchanges/wex/wex_test.go b/exchanges/wex/wex_test.go index 6bf48323..76300a9a 100644 --- a/exchanges/wex/wex_test.go +++ b/exchanges/wex/wex_test.go @@ -470,7 +470,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := w.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -486,6 +486,6 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := w.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/yobit/yobit.go b/exchanges/yobit/yobit.go index b493dc8c..f5269d61 100644 --- a/exchanges/yobit/yobit.go +++ b/exchanges/yobit/yobit.go @@ -366,7 +366,7 @@ func (y *Yobit) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) { case exchange.CryptocurrencyWithdrawalFee: fee = getWithdrawalFee(feeBuilder.FirstCurrency) case exchange.InternationalBankDepositFee: - fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem, feeBuilder.Amount, feeBuilder.BankTransactionType) + fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem, feeBuilder.BankTransactionType) case exchange.InternationalBankWithdrawalFee: fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.Amount, feeBuilder.BankTransactionType) } @@ -425,7 +425,7 @@ func getInternationalBankWithdrawalFee(currency string, amount float64, bankTran } // getInternationalBankDepositFee; No real fees for yobit deposits, but want to be explicit on what each payment type supports -func getInternationalBankDepositFee(currency string, amount float64, bankTransactionType exchange.InternationalBankTransactionType) float64 { +func getInternationalBankDepositFee(currency string, bankTransactionType exchange.InternationalBankTransactionType) float64 { var fee float64 switch bankTransactionType { case exchange.PerfectMoney: diff --git a/exchanges/yobit/yobit_test.go b/exchanges/yobit/yobit_test.go index ad0ad979..2838f4c7 100644 --- a/exchanges/yobit/yobit_test.go +++ b/exchanges/yobit/yobit_test.go @@ -442,7 +442,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := y.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -458,7 +458,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := y.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/zb/zb_test.go b/exchanges/zb/zb_test.go index 20e96db8..ffd5de5f 100644 --- a/exchanges/zb/zb_test.go +++ b/exchanges/zb/zb_test.go @@ -382,7 +382,7 @@ func TestWithdrawFiat(t *testing.T) { _, err := z.WithdrawFiatFunds(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } @@ -398,7 +398,7 @@ func TestWithdrawInternationalBank(t *testing.T) { _, err := z.WithdrawFiatFundsToInternationalBank(withdrawFiatRequest) if err != common.ErrFunctionNotSupported { - t.Errorf("Expected '%v', recieved: '%v'", common.ErrFunctionNotSupported, err) + t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err) } } diff --git a/exchanges/zb/zb_websocket_types.go b/exchanges/zb/zb_websocket_types.go index be406f20..5fe85e6e 100644 --- a/exchanges/zb/zb_websocket_types.go +++ b/exchanges/zb/zb_websocket_types.go @@ -2,7 +2,7 @@ package zb import "encoding/json" -// Subscription defines an intial subscription type to be sent +// Subscription defines an initial subscription type to be sent type Subscription struct { Event string `json:"event"` Channel string `json:"channel"` diff --git a/exchanges/zb/zb_wrapper.go b/exchanges/zb/zb_wrapper.go index ce52c23b..b75a8944 100644 --- a/exchanges/zb/zb_wrapper.go +++ b/exchanges/zb/zb_wrapper.go @@ -224,9 +224,7 @@ func (z *ZB) CancelAllOrders(orderCancellation exchange.OrderCancellation) (exch return cancelAllOrdersResponse, err } - for _, openOrder := range openOrders { - allOpenOrders = append(allOpenOrders, openOrder) - } + allOpenOrders = append(allOpenOrders, openOrders...) } for _, openOrder := range allOpenOrders { diff --git a/helpers.go b/helpers.go index 41fd8792..e1cf89ec 100644 --- a/helpers.go +++ b/helpers.go @@ -75,9 +75,7 @@ func IsRelatablePairs(p1, p2 pair.CurrencyPair, includeUSDT bool) bool { return true } - var relatablePairs []pair.CurrencyPair - relatablePairs = GetRelatableCurrencies(p1, true, includeUSDT) - + var relatablePairs = GetRelatableCurrencies(p1, true, includeUSDT) if currency.IsCryptoFiatPair(p1) { for x := range relatablePairs { relatablePairs = append(relatablePairs, GetRelatableFiatCurrencies(relatablePairs[x])...) @@ -197,7 +195,8 @@ func GetRelatableCurrencies(p pair.CurrencyPair, incOrig, incUSDT bool) []pair.C addPair(pair.NewCurrencyPair(first.String(), p.SecondCurrency.String())) - second, err := translation.GetTranslation(p.SecondCurrency) + var second pair.CurrencyItem + second, err = translation.GetTranslation(p.SecondCurrency) if err == nil { addPair(pair.NewCurrencyPair(first.String(), second.String())) diff --git a/main.go b/main.go index 9e362165..92e21351 100644 --- a/main.go +++ b/main.go @@ -143,7 +143,7 @@ func main() { common.ExtractHost(listenAddr), common.ExtractPort(listenAddr), ) - router := NewRouter(bot.exchanges) + router := NewRouter() go func() { err = http.ListenAndServe(listenAddr, router) if err != nil { diff --git a/portfolio/portfolio.go b/portfolio/portfolio.go index 093d830d..a41107d7 100644 --- a/portfolio/portfolio.go +++ b/portfolio/portfolio.go @@ -198,10 +198,7 @@ func (p *Base) UpdatePortfolio(addresses []string, coinType string) bool { } p.AddAddress(addresses[x], coinType, PortfolioAddressPersonal, result.ETH.Balance) } - if errors > 0 { - return false - } - return true + return errors == 0 } for x := range addresses { result, err := GetCryptoIDAddress(addresses[x], coinType) @@ -261,8 +258,8 @@ func (p *Base) GetPersonalPortfolio() map[string]float64 { // getPercentage returns the percentage of the target coin amount against the // total coin amount. func getPercentage(input map[string]float64, target string, totals map[string]float64) float64 { - subtotal, _ := input[target] - total, _ := totals[target] + subtotal := input[target] + total := totals[target] percentage := (subtotal / total) * 100 / 1 return percentage } @@ -270,7 +267,7 @@ func getPercentage(input map[string]float64, target string, totals map[string]fl // getPercentageSpecific returns the percentage a specific value of a target coin amount // against the total coin amount. func getPercentageSpecific(input float64, target string, totals map[string]float64) float64 { - total, _ := totals[target] + total := totals[target] percentage := (input / total) * 100 / 1 return percentage } diff --git a/restful_router.go b/restful_router.go index 65dc937c..c22234dc 100644 --- a/restful_router.go +++ b/restful_router.go @@ -6,7 +6,6 @@ import ( "time" "github.com/gorilla/mux" - exchange "github.com/thrasher-/gocryptotrader/exchanges" log "github.com/thrasher-/gocryptotrader/logger" ) @@ -42,7 +41,7 @@ var routes = Routes{} // NewRouter takes in the exchange interfaces and returns a new multiplexor // router -func NewRouter(exchanges []exchange.IBotExchange) *mux.Router { +func NewRouter() *mux.Router { router := mux.NewRouter().StrictSlash(true) routes = Routes{ @@ -109,15 +108,11 @@ func NewRouter(exchanges []exchange.IBotExchange) *mux.Router { } for _, route := range routes { - var handler http.Handler - handler = route.HandlerFunc - handler = RESTLogger(handler, route.Name) - router. Methods(route.Method). Path(route.Pattern). Name(route.Name). - Handler(handler) + Handler(RESTLogger(route.HandlerFunc, route.Name)) } return router } diff --git a/restful_server.go b/restful_server.go index 47535346..2a329eaa 100644 --- a/restful_server.go +++ b/restful_server.go @@ -42,7 +42,7 @@ type AllEnabledExchangeAccounts struct { } // RESTfulJSONResponse outputs a JSON response of the response interface -func RESTfulJSONResponse(w http.ResponseWriter, r *http.Request, response interface{}) error { +func RESTfulJSONResponse(w http.ResponseWriter, response interface{}) error { w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) return json.NewEncoder(w).Encode(response) @@ -57,7 +57,7 @@ func RESTfulError(method string, err error) { // RESTGetAllSettings replies to a request with an encoded JSON response about the // trading bots configuration. func RESTGetAllSettings(w http.ResponseWriter, r *http.Request) { - err := RESTfulJSONResponse(w, r, bot.config) + err := RESTfulJSONResponse(w, bot.config) if err != nil { RESTfulError(r.Method, err) } @@ -79,7 +79,7 @@ func RESTSaveAllSettings(w http.ResponseWriter, r *http.Request) { RESTfulError(r.Method, err) } - err = RESTfulJSONResponse(w, r, bot.config) + err = RESTfulJSONResponse(w, bot.config) if err != nil { RESTfulError(r.Method, err) } @@ -106,7 +106,7 @@ func RESTGetOrderbook(w http.ResponseWriter, r *http.Request) { return } - err = RESTfulJSONResponse(w, r, response) + err = RESTfulJSONResponse(w, response) if err != nil { RESTfulError(r.Method, err) } @@ -165,7 +165,7 @@ func RESTGetAllActiveOrderbooks(w http.ResponseWriter, r *http.Request) { var response AllEnabledExchangeOrderbooks response.Data = GetAllActiveOrderbooks() - err := RESTfulJSONResponse(w, r, response) + err := RESTfulJSONResponse(w, response) if err != nil { RESTfulError(r.Method, err) } @@ -174,7 +174,7 @@ func RESTGetAllActiveOrderbooks(w http.ResponseWriter, r *http.Request) { // RESTGetPortfolio returns the bot portfolio func RESTGetPortfolio(w http.ResponseWriter, r *http.Request) { result := bot.portfolio.GetPortfolioSummary() - err := RESTfulJSONResponse(w, r, result) + err := RESTfulJSONResponse(w, result) if err != nil { RESTfulError(r.Method, err) } @@ -197,7 +197,7 @@ func RESTGetTicker(w http.ResponseWriter, r *http.Request) { currency) return } - err = RESTfulJSONResponse(w, r, response) + err = RESTfulJSONResponse(w, response) if err != nil { RESTfulError(r.Method, err) } @@ -255,7 +255,7 @@ func RESTGetAllActiveTickers(w http.ResponseWriter, r *http.Request) { var response AllEnabledExchangeCurrencies response.Data = GetAllActiveTickers() - err := RESTfulJSONResponse(w, r, response) + err := RESTfulJSONResponse(w, response) if err != nil { RESTfulError(r.Method, err) } @@ -286,7 +286,7 @@ func GetAllEnabledExchangeAccountInfo() AllEnabledExchangeAccounts { // info func RESTGetAllEnabledAccountInfo(w http.ResponseWriter, r *http.Request) { response := GetAllEnabledExchangeAccountInfo() - err := RESTfulJSONResponse(w, r, response) + err := RESTfulJSONResponse(w, response) if err != nil { RESTfulError(r.Method, err) } diff --git a/restful_server_test.go b/restful_server_test.go index b20f8b2f..6811b22a 100644 --- a/restful_server_test.go +++ b/restful_server_test.go @@ -22,10 +22,9 @@ func loadConfig(t *testing.T) *config.Config { } func makeHTTPGetRequest(t *testing.T, url string, response interface{}) *http.Response { - req := httptest.NewRequest("GET", "http://localhost:9050/config/all", nil) w := httptest.NewRecorder() - err := RESTfulJSONResponse(w, req, response) + err := RESTfulJSONResponse(w, response) if err != nil { t.Error("Test failed. Failed to make response.", err) } diff --git a/routines.go b/routines.go index 8e676b3d..9b37d2ae 100644 --- a/routines.go +++ b/routines.go @@ -382,9 +382,9 @@ func WebsocketDataHandler(ws *exchange.Websocket, verbose bool) { return case data := <-ws.DataHandler: - switch data.(type) { + switch d := data.(type) { case string: - switch data.(string) { + switch d { case exchange.WebsocketNotEnabled: if verbose { log.Warnf("routines.go warning - exchange %s weboscket not enabled", @@ -392,12 +392,12 @@ func WebsocketDataHandler(ws *exchange.Websocket, verbose bool) { } default: - log.Infof(data.(string)) + log.Infof(d) } case error: switch { - case common.StringContains(data.(error).Error(), "close 1006"): + case common.StringContains(d.Error(), "close 1006"): go WebsocketReconnect(ws, verbose) continue default: @@ -407,27 +407,27 @@ func WebsocketDataHandler(ws *exchange.Websocket, verbose bool) { case exchange.TradeData: // Trade Data if verbose { - log.Infoln("Websocket trades Updated: ", data.(exchange.TradeData)) + log.Infoln("Websocket trades Updated: ", d) } case exchange.TickerData: // Ticker data if verbose { - log.Infoln("Websocket Ticker Updated: ", data.(exchange.TickerData)) + log.Infoln("Websocket Ticker Updated: ", d) } case exchange.KlineData: // Kline data if verbose { - log.Infoln("Websocket Kline Updated: ", data.(exchange.KlineData)) + log.Infoln("Websocket Kline Updated: ", d) } case exchange.WebsocketOrderbookUpdate: // Orderbook data if verbose { - log.Infoln("Websocket Orderbook Updated:", data.(exchange.WebsocketOrderbookUpdate)) + log.Infoln("Websocket Orderbook Updated:", d) } default: if verbose { - log.Warnf("Websocket Unknown type: %s", data) + log.Warnf("Websocket Unknown type: %s", d) } } } diff --git a/tools/huobi_auth/main.go b/tools/huobi_auth/main.go index b2c4bef5..4b48211a 100644 --- a/tools/huobi_auth/main.go +++ b/tools/huobi_auth/main.go @@ -43,7 +43,7 @@ func encodePEM(privKey *ecdsa.PrivateKey, pubKey bool) ([]byte, error) { } func decodePEM(PEMPrivKey, PEMPubKey []byte) (*ecdsa.PrivateKey, *ecdsa.PublicKey, error) { - block, _ := pem.Decode([]byte(PEMPrivKey)) + block, _ := pem.Decode(PEMPrivKey) if block == nil { return nil, nil, errors.New("priv block data is nil") } @@ -54,7 +54,7 @@ func decodePEM(PEMPrivKey, PEMPubKey []byte) (*ecdsa.PrivateKey, *ecdsa.PublicKe return nil, nil, err } - blockPub, _ := pem.Decode([]byte(PEMPubKey)) + blockPub, _ := pem.Decode(PEMPubKey) if block == nil { return nil, nil, errors.New("pub block data is nil") } @@ -97,7 +97,8 @@ func main() { } if genKeys { - pKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + var pKey *ecdsa.PrivateKey + pKey, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { log.Fatal(err) } @@ -115,13 +116,15 @@ func main() { } } else { - pubKeyData, err := common.ReadFile("publickey.pem") + var pubKeyData []byte + pubKeyData, err = common.ReadFile("publickey.pem") if err != nil { log.Fatal(err) } log.Println("Successfully read PEM files.") - priv, _, err := decodePEM(privKeyData, pubKeyData) + var priv *ecdsa.PrivateKey + priv, _, err = decodePEM(privKeyData, pubKeyData) if err != nil { log.Fatal(err) } diff --git a/websocket.go b/websocket.go index 6bd0f07b..9f7f2cde 100644 --- a/websocket.go +++ b/websocket.go @@ -194,7 +194,7 @@ func (c *WebsocketClient) write() { defer func() { c.Conn.Close() }() - for { + for { // nolint: gosimple select { case message, ok := <-c.Send: if !ok {