Skip to content

Commit

Permalink
Makefile: add new recipes and linter features (thrasher-corp#244)
Browse files Browse the repository at this point in the history
* Makefile: add new recipes and linter features

* expand linter coverage and fix issues

* Update makefile

* address PR nitterinos
  • Loading branch information
thrasher- authored Jan 31, 2019
1 parent e182248 commit 291e404
Show file tree
Hide file tree
Showing 85 changed files with 306 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
48 changes: 45 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
GO111MODULE=on go install $(LDFLAGS)

fmt:
gofmt -l -w -s $(shell find . -type f -name '*.go')
4 changes: 2 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions communications/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (s *Slack) WebsocketReader() {
}

case "hello":
s.handleHelloResponse(data)
s.handleHelloResponse()

case "reconnect_url":
err = s.handleReconnectResponse(resp)
Expand Down Expand Up @@ -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.")
}
Expand Down
3 changes: 1 addition & 2 deletions communications/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions currency/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion currency/currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
APIEndpointCurrencies = "currencies"
APIEndpointCountries = "countries"
APIEndpointUsage = "usage"

defaultAPIKey = "Key"
)

// CurrencyConverter stores the struct for the CurrencyConverter API
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion currency/symbol/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const (
BAT = "BAT"
ETP = "ETP"
HOT = "HOT"
STRAT = "STRAT"
STRAT = "STRAT" // nolint: misspell
GNT = "GNT"
REP = "REP"
SNT = "SNT"
Expand Down
5 changes: 1 addition & 4 deletions currency/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions exchanges/alphapoint/alphapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
8 changes: 3 additions & 5 deletions exchanges/anx/anx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions exchanges/anx/anx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
14 changes: 6 additions & 8 deletions exchanges/binance/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
Loading

0 comments on commit 291e404

Please sign in to comment.