CI: Fix golangci-lint linter issues, add prealloc linter and bump version depends for Go 1.18 (#915)

* Bump CI versions

* Specifically set go version as 1.17.x bumps it to 1.18

* Another

* Adjust AppVeyor

* Part 1 of linter issues

* Part 2

* Fix various linters and improvements

* Part 3

* Finishing touches

* Tests and EqualFold

* Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests

* Fix nitterinos and bump golangci-lint timeout for AppVeyor

* Address nits, ensure all books are returned on err due to syncer regression

* Fix the wiggins

* Fix duplication

* Fix nitterinos
This commit is contained in:
Adrian Gallagher
2022-04-20 13:45:15 +10:00
committed by GitHub
parent c48e5ea90a
commit 9a4eb9de84
216 changed files with 3493 additions and 2424 deletions

View File

@@ -18,7 +18,6 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/log"
)
const (
@@ -144,51 +143,51 @@ func (b *Bitstamp) GetTicker(ctx context.Context, currency string, hourly bool)
// GetOrderbook Returns a JSON dictionary with "bids" and "asks". Each is a list
// of open orders and each order is represented as a list holding the price and
// the amount.
func (b *Bitstamp) GetOrderbook(ctx context.Context, currency string) (Orderbook, error) {
func (b *Bitstamp) GetOrderbook(ctx context.Context, currency string) (*Orderbook, error) {
type response struct {
Timestamp int64 `json:"timestamp,string"`
Bids [][]string `json:"bids"`
Asks [][]string `json:"asks"`
Timestamp int64 `json:"timestamp,string"`
Bids [][2]string `json:"bids"`
Asks [][2]string `json:"asks"`
}
resp := response{}
path := "/v" + bitstampAPIVersion + "/" + bitstampAPIOrderbook + "/" + strings.ToLower(currency) + "/"
var resp response
err := b.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp)
if err != nil {
return Orderbook{}, err
return nil, err
}
orderbook := Orderbook{}
orderbook.Timestamp = resp.Timestamp
for _, x := range resp.Bids {
price, err := strconv.ParseFloat(x[0], 64)
if err != nil {
log.Error(log.ExchangeSys, err)
continue
}
amount, err := strconv.ParseFloat(x[1], 64)
if err != nil {
log.Error(log.ExchangeSys, err)
continue
}
orderbook.Bids = append(orderbook.Bids, OrderbookBase{price, amount})
orderbook := Orderbook{
Timestamp: resp.Timestamp,
Bids: make([]OrderbookBase, len(resp.Bids)),
Asks: make([]OrderbookBase, len(resp.Asks)),
}
for _, x := range resp.Asks {
price, err := strconv.ParseFloat(x[0], 64)
for x := range resp.Bids {
price, err := strconv.ParseFloat(resp.Bids[x][0], 64)
if err != nil {
log.Error(log.ExchangeSys, err)
continue
return nil, err
}
amount, err := strconv.ParseFloat(x[1], 64)
amount, err := strconv.ParseFloat(resp.Bids[x][1], 64)
if err != nil {
log.Error(log.ExchangeSys, err)
continue
return nil, err
}
orderbook.Asks = append(orderbook.Asks, OrderbookBase{price, amount})
orderbook.Bids[x] = OrderbookBase{price, amount}
}
return orderbook, nil
for x := range resp.Asks {
price, err := strconv.ParseFloat(resp.Asks[x][0], 64)
if err != nil {
return nil, err
}
amount, err := strconv.ParseFloat(resp.Asks[x][1], 64)
if err != nil {
return nil, err
}
orderbook.Asks[x] = OrderbookBase{price, amount}
}
return &orderbook, nil
}
// GetTradingPairs returns a list of trading pairs which Bitstamp
@@ -305,7 +304,7 @@ func (b *Bitstamp) GetUserTransactions(ctx context.Context, currencyPair string)
}
}
var transactions []UserTransactions
transactions := make([]UserTransactions, len(response))
for x := range response {
tx := UserTransactions{}
tx.Date = response[x].Date
@@ -318,7 +317,7 @@ func (b *Bitstamp) GetUserTransactions(ctx context.Context, currencyPair string)
tx.BTCUSD = processNumber(response[x].BTCUSD)
tx.Fee = response[x].Fee
tx.OrderID = response[x].OrderID
transactions = append(transactions, tx)
transactions[x] = tx
}
return transactions, nil

View File

@@ -221,10 +221,10 @@ type websocketOrderBookResponse struct {
}
type websocketOrderBook struct {
Asks [][]string `json:"asks"`
Bids [][]string `json:"bids"`
Timestamp int64 `json:"timestamp,string"`
Microtimestamp string `json:"microtimestamp"`
Asks [][2]string `json:"asks"`
Bids [][2]string `json:"bids"`
Timestamp int64 `json:"timestamp,string"`
Microtimestamp string `json:"microtimestamp"`
}
// OHLCResponse holds returned candle data

View File

@@ -21,7 +21,7 @@ import (
)
const (
bitstampWSURL = "wss://ws.bitstamp.net"
bitstampWSURL = "wss://ws.bitstamp.net" // nolint // gosec false positive
)
// WsConnect connects to a websocket feed
@@ -255,33 +255,29 @@ func (b *Bitstamp) wsUpdateOrderbook(update websocketOrderBook, p currency.Pair,
if len(update.Asks) == 0 && len(update.Bids) == 0 {
return errors.New("no orderbook data")
}
var asks, bids []orderbook.Item
asks := make([]orderbook.Item, len(update.Asks))
bids := make([]orderbook.Item, len(update.Bids))
for i := range update.Asks {
target, err := strconv.ParseFloat(update.Asks[i][0], 64)
if err != nil {
b.Websocket.DataHandler <- err
continue
return err
}
amount, err := strconv.ParseFloat(update.Asks[i][1], 64)
if err != nil {
b.Websocket.DataHandler <- err
continue
return err
}
asks = append(asks, orderbook.Item{Price: target, Amount: amount})
asks[i] = orderbook.Item{Price: target, Amount: amount}
}
for i := range update.Bids {
target, err := strconv.ParseFloat(update.Bids[i][0], 64)
if err != nil {
b.Websocket.DataHandler <- err
continue
return err
}
amount, err := strconv.ParseFloat(update.Bids[i][1], 64)
if err != nil {
b.Websocket.DataHandler <- err
continue
return err
}
bids = append(bids, orderbook.Item{Price: target, Amount: amount})
bids[i] = orderbook.Item{Price: target, Amount: amount}
}
return b.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
Bids: bids,
@@ -311,17 +307,19 @@ func (b *Bitstamp) seedOrderBook(ctx context.Context) error {
}
var newOrderBook orderbook.Base
newOrderBook.Asks = make(orderbook.Items, len(orderbookSeed.Asks))
for i := range orderbookSeed.Asks {
newOrderBook.Asks = append(newOrderBook.Asks, orderbook.Item{
newOrderBook.Asks[i] = orderbook.Item{
Price: orderbookSeed.Asks[i].Price,
Amount: orderbookSeed.Asks[i].Amount,
})
}
}
newOrderBook.Bids = make(orderbook.Items, len(orderbookSeed.Bids))
for i := range orderbookSeed.Bids {
newOrderBook.Bids = append(newOrderBook.Bids, orderbook.Item{
newOrderBook.Bids[i] = orderbook.Item{
Price: orderbookSeed.Bids[i].Price,
Amount: orderbookSeed.Bids[i].Amount,
})
}
}
newOrderBook.Pair = p[x]
newOrderBook.Asset = asset.Spot

View File

@@ -285,7 +285,7 @@ func (b *Bitstamp) FetchTradablePairs(ctx context.Context, asset asset.Item) ([]
return nil, err
}
var products []string
products := make([]string, 0, len(pairs))
for x := range pairs {
if pairs[x].Trading != "Enabled" {
continue
@@ -406,18 +406,20 @@ func (b *Bitstamp) UpdateOrderbook(ctx context.Context, p currency.Pair, assetTy
return book, err
}
book.Bids = make(orderbook.Items, len(orderbookNew.Bids))
for x := range orderbookNew.Bids {
book.Bids = append(book.Bids, orderbook.Item{
book.Bids[x] = orderbook.Item{
Amount: orderbookNew.Bids[x].Amount,
Price: orderbookNew.Bids[x].Price,
})
}
}
book.Asks = make(orderbook.Items, len(orderbookNew.Asks))
for x := range orderbookNew.Asks {
book.Asks = append(book.Asks, orderbook.Item{
book.Asks[x] = orderbook.Item{
Amount: orderbookNew.Asks[x].Amount,
Price: orderbookNew.Asks[x].Price,
})
}
}
err = book.Process()
if err != nil {
@@ -436,7 +438,7 @@ func (b *Bitstamp) UpdateAccountInfo(ctx context.Context, assetType asset.Item)
return response, err
}
var currencies []account.Balance
currencies := make([]account.Balance, 0, len(accountBalance))
for k, v := range accountBalance {
currencies = append(currencies, account.Balance{
CurrencyName: currency.NewCode(k),
@@ -480,23 +482,23 @@ func (b *Bitstamp) GetWithdrawalsHistory(ctx context.Context, c currency.Code) (
// GetRecentTrades returns the most recent trades for a currency and asset
func (b *Bitstamp) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
var err error
p, err = b.FormatExchangeCurrency(p, assetType)
p, err := b.FormatExchangeCurrency(p, assetType)
if err != nil {
return nil, err
}
var tradeData []Transactions
tradeData, err = b.GetTransactions(ctx, p.String(), "")
tradeData, err := b.GetTransactions(ctx, p.String(), "")
if err != nil {
return nil, err
}
var resp []trade.Data
resp := make([]trade.Data, len(tradeData))
for i := range tradeData {
s := order.Buy
if tradeData[i].Type == 1 {
s = order.Sell
}
resp = append(resp, trade.Data{
resp[i] = trade.Data{
Exchange: b.Name,
TID: strconv.FormatInt(tradeData[i].TradeID, 10),
CurrencyPair: p,
@@ -505,7 +507,7 @@ func (b *Bitstamp) GetRecentTrades(ctx context.Context, p currency.Pair, assetTy
Price: tradeData[i].Price,
Amount: tradeData[i].Amount,
Timestamp: time.Unix(tradeData[i].Date, 0),
})
}
}
err = b.AddTradesToBuffer(resp...)
@@ -720,7 +722,7 @@ func (b *Bitstamp) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
return nil, err
}
var orders []order.Detail
orders := make([]order.Detail, len(resp))
for i := range resp {
orderSide := order.Buy
if resp[i].Type == SellOrder {
@@ -745,7 +747,7 @@ func (b *Bitstamp) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
p = req.Pairs[0]
}
orders = append(orders, order.Detail{
orders[i] = order.Detail{
Amount: resp[i].Amount,
ID: strconv.FormatInt(resp[i].ID, 10),
Price: resp[i].Price,
@@ -754,7 +756,7 @@ func (b *Bitstamp) GetActiveOrders(ctx context.Context, req *order.GetOrdersRequ
Date: tm,
Pair: p,
Exchange: b.Name,
})
}
}
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
@@ -788,7 +790,7 @@ func (b *Bitstamp) GetOrderHistory(ctx context.Context, req *order.GetOrdersRequ
return nil, err
}
var orders []order.Detail
orders := make([]order.Detail, 0, len(resp))
for i := range resp {
if resp[i].Type != MarketTrade {
continue