mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 07:26:46 +00:00
build/ci: Update Go to v1.24, golangci-lint to v1.64.6 and fix issues (#1804)
* build/ci: Update Go to v1.24, golangci-lint to v1.64.5 and fix issues * Address shazbert's nitters * linter/config: Fix new linter issue and use versionSize const * Address gk's nitters and fix additional linter issue after rebase * Address glorious nits * staticcheck: Fix additional linter issues after upgrading to Go 1.24.1 and golangci-lint v1.64.6 Also addresses nits * Improve testing, assertify usage and use common.ErrParsingWSField * TestCreateNewStrategy: Replace must > should wording
This commit is contained in:
@@ -994,7 +994,7 @@ func (b *Bitfinex) GetLends(ctx context.Context, symbol string, values url.Value
|
||||
// GetCandles returns candle chart data
|
||||
// timeFrame values: '1m', '5m', '15m', '30m', '1h', '3h', '6h', '12h', '1D', '1W', '14D', '1M'
|
||||
// section values: last or hist
|
||||
func (b *Bitfinex) GetCandles(ctx context.Context, symbol, timeFrame string, start, end int64, limit uint32, historic bool) ([]Candle, error) {
|
||||
func (b *Bitfinex) GetCandles(ctx context.Context, symbol, timeFrame string, start, end int64, limit uint64, historic bool) ([]Candle, error) {
|
||||
var fundingPeriod string
|
||||
if symbol[0] == 'f' {
|
||||
fundingPeriod = ":p30"
|
||||
@@ -1019,7 +1019,7 @@ func (b *Bitfinex) GetCandles(ctx context.Context, symbol, timeFrame string, sta
|
||||
}
|
||||
|
||||
if limit > 0 {
|
||||
v.Set("limit", strconv.FormatInt(int64(limit), 10))
|
||||
v.Set("limit", strconv.FormatUint(limit, 10))
|
||||
}
|
||||
|
||||
path += "/hist"
|
||||
|
||||
@@ -34,8 +34,6 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
)
|
||||
|
||||
var errParsingWSField = errors.New("error parsing WS field")
|
||||
|
||||
const (
|
||||
authenticatedBitfinexWebsocketEndpoint = "wss://api.bitfinex.com/ws/2"
|
||||
publicBitfinexWebsocketEndpoint = "wss://api-pub.bitfinex.com/ws/2"
|
||||
@@ -105,7 +103,7 @@ var defaultSubscriptions = subscription.List{
|
||||
var comms = make(chan stream.Response)
|
||||
|
||||
type checksum struct {
|
||||
Token int
|
||||
Token uint32
|
||||
Sequence int64
|
||||
}
|
||||
|
||||
@@ -642,11 +640,11 @@ func (b *Bitfinex) handleWSChecksum(c *subscription.Subscription, d []interface{
|
||||
if c == nil {
|
||||
return fmt.Errorf("%w: Subscription param", common.ErrNilPointer)
|
||||
}
|
||||
var token int
|
||||
var token uint32
|
||||
if f, ok := d[2].(float64); !ok {
|
||||
return common.GetTypeAssertError("float64", d[2], "checksum")
|
||||
} else { //nolint:revive // using lexical variable requires else statement
|
||||
token = int(f)
|
||||
token = uint32(f)
|
||||
}
|
||||
if len(d) < 4 {
|
||||
return errNoSeqNo
|
||||
@@ -949,22 +947,22 @@ func (b *Bitfinex) handleWSAllTrades(s *subscription.Subscription, respRaw []byt
|
||||
}
|
||||
v, valueType, _, err := jsonparser.Get(respRaw, "[1]")
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w `tradesUpdate[1]`: %w", errParsingWSField, err)
|
||||
return fmt.Errorf("%w `tradesUpdate[1]`: %w", common.ErrParsingWSField, err)
|
||||
}
|
||||
var wsTrades []*wsTrade
|
||||
switch valueType {
|
||||
case jsonparser.String:
|
||||
if t, err := b.handleWSPublicTradeUpdate(respRaw); err != nil {
|
||||
return fmt.Errorf("%w `tradesUpdate[2]`: %w", errParsingWSField, err)
|
||||
} else {
|
||||
wsTrades = []*wsTrade{t}
|
||||
t, err := b.handleWSPublicTradeUpdate(respRaw)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w `tradesUpdate[2]`: %w", common.ErrParsingWSField, err)
|
||||
}
|
||||
wsTrades = []*wsTrade{t}
|
||||
case jsonparser.Array:
|
||||
if wsTrades, err = b.handleWSPublicTradesSnapshot(v); err != nil {
|
||||
return fmt.Errorf("%w `tradesSnapshot`: %w", errParsingWSField, err)
|
||||
return fmt.Errorf("%w `tradesSnapshot`: %w", common.ErrParsingWSField, err)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("%w `tradesUpdate[1]`: %w `%s`", errParsingWSField, jsonparser.UnknownValueTypeError, valueType)
|
||||
return fmt.Errorf("%w `tradesUpdate[1]`: %w `%s`", common.ErrParsingWSField, jsonparser.UnknownValueTypeError, valueType)
|
||||
}
|
||||
trades := make([]trade.Data, len(wsTrades))
|
||||
for _, w := range wsTrades {
|
||||
@@ -2084,7 +2082,7 @@ func makeRequestInterface(channelName string, data interface{}) []interface{} {
|
||||
return []interface{}{0, channelName, nil, data}
|
||||
}
|
||||
|
||||
func validateCRC32(book *orderbook.Base, token int) error {
|
||||
func validateCRC32(book *orderbook.Base, token uint32) error {
|
||||
// Order ID's need to be sub-sorted in ascending order, this needs to be
|
||||
// done on the main book to ensure that we do not cut price levels out below
|
||||
reOrderByID(book.Bids)
|
||||
@@ -2132,14 +2130,14 @@ func validateCRC32(book *orderbook.Base, token int) error {
|
||||
|
||||
checksumStr := strings.TrimSuffix(check.String(), ":")
|
||||
checksum := crc32.ChecksumIEEE([]byte(checksumStr))
|
||||
if checksum == uint32(token) {
|
||||
if checksum == token {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid checksum for %s %s: calculated [%d] does not match [%d]",
|
||||
book.Asset,
|
||||
book.Pair,
|
||||
checksum,
|
||||
uint32(token))
|
||||
token)
|
||||
}
|
||||
|
||||
// reOrderByID sub sorts orderbook items by its corresponding ID when price
|
||||
@@ -2195,11 +2193,11 @@ func subToMap(s *subscription.Subscription, a asset.Item, p currency.Pair) map[s
|
||||
for k, v := range s.Params {
|
||||
switch k {
|
||||
case CandlesPeriodKey:
|
||||
if s, ok := v.(string); !ok {
|
||||
s, ok := v.(string)
|
||||
if !ok {
|
||||
panic(common.GetTypeAssertError("string", v, "subscription.CandlesPeriodKey"))
|
||||
} else {
|
||||
fundingPeriod = ":" + s
|
||||
}
|
||||
fundingPeriod = ":" + s
|
||||
case "key", "symbol", "len":
|
||||
panic(fmt.Errorf("%w: %s", errParamNotAllowed, k)) // Ensure user's Params aren't silently overwritten
|
||||
default:
|
||||
|
||||
@@ -1077,7 +1077,7 @@ func (b *Bitfinex) GetHistoricCandles(ctx context.Context, pair currency.Pair, a
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
candles, err := b.GetCandles(ctx, cf, fInterval, req.Start.UnixMilli(), req.End.UnixMilli(), uint32(req.RequestLimit), true)
|
||||
candles, err := b.GetCandles(ctx, cf, fInterval, req.Start.UnixMilli(), req.End.UnixMilli(), req.RequestLimit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1114,7 +1114,7 @@ func (b *Bitfinex) GetHistoricCandlesExtended(ctx context.Context, pair currency
|
||||
timeSeries := make([]kline.Candle, 0, req.Size())
|
||||
for x := range req.RangeHolder.Ranges {
|
||||
var candles []Candle
|
||||
candles, err = b.GetCandles(ctx, cf, fInterval, req.RangeHolder.Ranges[x].Start.Time.UnixMilli(), req.RangeHolder.Ranges[x].End.Time.UnixMilli(), uint32(req.RequestLimit), true)
|
||||
candles, err = b.GetCandles(ctx, cf, fInterval, req.RangeHolder.Ranges[x].Start.Time.UnixMilli(), req.RangeHolder.Ranges[x].End.Time.UnixMilli(), req.RequestLimit, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user