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

@@ -82,7 +82,7 @@ func (g *Gemini) GetTicker(ctx context.Context, currencyPair string) (TickerV2,
//
// params - limit_bids or limit_asks [OPTIONAL] default 50, 0 returns all Values
// Type is an integer ie "params.Set("limit_asks", 30)"
func (g *Gemini) GetOrderbook(ctx context.Context, currencyPair string, params url.Values) (Orderbook, error) {
func (g *Gemini) GetOrderbook(ctx context.Context, currencyPair string, params url.Values) (*Orderbook, error) {
path := common.EncodeURLValues(
fmt.Sprintf("/v%s/%s/%s",
geminiAPIVersion,
@@ -91,7 +91,7 @@ func (g *Gemini) GetOrderbook(ctx context.Context, currencyPair string, params u
params)
var orderbook Orderbook
return orderbook, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &orderbook)
return &orderbook, g.SendHTTPRequest(ctx, exchange.RestSpot, path, &orderbook)
}
// GetTrades return the trades that have executed since the specified timestamp.

View File

@@ -587,7 +587,11 @@ func TestWsAuth(t *testing.T) {
timer := time.NewTimer(sharedtestvalues.WebsocketResponseDefaultTimeout)
select {
case resp := <-g.Websocket.DataHandler:
if resp.(WsSubscriptionAcknowledgementResponse).Type != "subscription_ack" {
subAck, ok := resp.(WsSubscriptionAcknowledgementResponse)
if !ok {
t.Error("unable to type assert WsSubscriptionAcknowledgementResponse")
}
if subAck.Type != "subscription_ack" {
t.Error("Login failed")
}
case <-timer.C:

View File

@@ -90,7 +90,7 @@ func (g *Gemini) GenerateDefaultSubscriptions() ([]stream.ChannelSubscription, e
// Subscribe sends a websocket message to receive data from the channel
func (g *Gemini) Subscribe(channelsToSubscribe []stream.ChannelSubscription) error {
var channels []string
channels := make([]string, 0, len(channelsToSubscribe))
for x := range channelsToSubscribe {
if common.StringDataCompareInsensitive(channels, channelsToSubscribe[x].Channel) {
continue
@@ -111,12 +111,12 @@ func (g *Gemini) Subscribe(channelsToSubscribe []stream.ChannelSubscription) err
return err
}
var subs []wsSubscriptions
subs := make([]wsSubscriptions, len(channels))
for x := range channels {
subs = append(subs, wsSubscriptions{
subs[x] = wsSubscriptions{
Name: channels[x],
Symbols: strings.Split(fmtPairs, ","),
})
}
}
wsSub := wsSubscribeRequest{
@@ -134,7 +134,7 @@ func (g *Gemini) Subscribe(channelsToSubscribe []stream.ChannelSubscription) err
// Unsubscribe sends a websocket message to stop receiving data from the channel
func (g *Gemini) Unsubscribe(channelsToUnsubscribe []stream.ChannelSubscription) error {
var channels []string
channels := make([]string, 0, len(channelsToUnsubscribe))
for x := range channelsToUnsubscribe {
if common.StringDataCompareInsensitive(channels, channelsToUnsubscribe[x].Channel) {
continue
@@ -155,12 +155,12 @@ func (g *Gemini) Unsubscribe(channelsToUnsubscribe []stream.ChannelSubscription)
return err
}
var subs []wsSubscriptions
subs := make([]wsSubscriptions, len(channels))
for x := range channels {
subs = append(subs, wsSubscriptions{
subs[x] = wsSubscriptions{
Name: channels[x],
Symbols: strings.Split(fmtPairs, ","),
})
}
}
wsSub := wsSubscribeRequest{
@@ -384,7 +384,7 @@ func (g *Gemini) wsHandleData(respRaw []byte) error {
}
tradeEvent := trade.Data{
Timestamp: time.Unix(result.Timestamp/1000, 0),
Timestamp: time.UnixMilli(result.Timestamp),
CurrencyPair: pair,
AssetType: asset.Spot,
Exchange: g.Name,
@@ -442,12 +442,16 @@ func (g *Gemini) wsHandleData(respRaw []byte) error {
if len(candle.Changes[i]) != 6 {
continue
}
interval, ok := result["type"].(string)
if !ok {
return errors.New("unable to type assert interval")
}
g.Websocket.DataHandler <- stream.KlineData{
Timestamp: time.Unix(int64(candle.Changes[i][0])/1000, 0),
Timestamp: time.UnixMilli(int64(candle.Changes[i][0])),
Pair: pair,
AssetType: asset.Spot,
Exchange: g.Name,
Interval: result["type"].(string),
Interval: interval,
OpenPrice: candle.Changes[i][1],
HighPrice: candle.Changes[i][2],
LowPrice: candle.Changes[i][3],
@@ -526,7 +530,9 @@ func (g *Gemini) wsProcessUpdate(result *wsL2MarketData) error {
return err
}
var bids, asks []orderbook.Item
bids := make([]orderbook.Item, 0, len(result.Changes))
asks := make([]orderbook.Item, 0, len(result.Changes))
for x := range result.Changes {
price, err := strconv.ParseFloat(result.Changes[x][1], 64)
if err != nil {
@@ -582,7 +588,7 @@ func (g *Gemini) wsProcessUpdate(result *wsL2MarketData) error {
return nil
}
var trades []trade.Data
trades := make([]trade.Data, len(result.Trades))
for x := range result.Trades {
tSide, err := order.StringToOrderSide(result.Trades[x].Side)
if err != nil {
@@ -591,8 +597,8 @@ func (g *Gemini) wsProcessUpdate(result *wsL2MarketData) error {
Err: err,
}
}
trades = append(trades, trade.Data{
Timestamp: time.Unix(result.Trades[x].Timestamp/1000, 0),
trades[x] = trade.Data{
Timestamp: time.UnixMilli(result.Trades[x].Timestamp),
CurrencyPair: pair,
AssetType: asset.Spot,
Exchange: g.Name,
@@ -600,7 +606,7 @@ func (g *Gemini) wsProcessUpdate(result *wsL2MarketData) error {
Amount: result.Trades[x].Quantity,
Side: tSide,
TID: strconv.FormatInt(result.Trades[x].EventID, 10),
})
}
}
return trade.AddTradesToBuffer(g.Name, trades...)

View File

@@ -319,14 +319,14 @@ func (g *Gemini) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (a
return response, err
}
var currencies []account.Balance
currencies := make([]account.Balance, len(accountBalance))
for i := range accountBalance {
currencies = append(currencies, account.Balance{
currencies[i] = account.Balance{
CurrencyName: currency.NewCode(accountBalance[i].Currency),
Total: accountBalance[i].Amount,
Hold: accountBalance[i].Amount - accountBalance[i].Available,
Free: accountBalance[i].Available,
})
}
}
response.Accounts = append(response.Accounts, account.SubAccount{
@@ -431,16 +431,20 @@ func (g *Gemini) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType
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})
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})
Price: orderbookNew.Asks[x].Price,
}
}
err = book.Process()
if err != nil {
@@ -692,7 +696,7 @@ func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
return nil, err
}
var orders []order.Detail
orders := make([]order.Detail, len(resp))
for i := range resp {
var symbol currency.Pair
symbol, err = currency.NewPairFromFormattedPairs(resp[i].Symbol, availPairs, format)
@@ -709,7 +713,7 @@ func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
side := order.Side(strings.ToUpper(resp[i].Type))
orderDate := time.Unix(resp[i].Timestamp, 0)
orders = append(orders, order.Detail{
orders[i] = order.Detail{
Amount: resp[i].OriginalAmount,
RemainingAmount: resp[i].RemainingAmount,
ID: strconv.FormatInt(resp[i].OrderID, 10),
@@ -720,7 +724,7 @@ func (g *Gemini) GetActiveOrders(ctx context.Context, req *order.GetOrdersReques
Price: resp[i].Price,
Pair: symbol,
Date: orderDate,
})
}
}
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
@@ -767,7 +771,7 @@ func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
return nil, err
}
var orders []order.Detail
orders := make([]order.Detail, len(trades))
for i := range trades {
side := order.Side(strings.ToUpper(trades[i].Type))
orderDate := time.Unix(trades[i].Timestamp, 0)
@@ -789,7 +793,7 @@ func (g *Gemini) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
),
}
detail.InferCostsAndTimes()
orders = append(orders, detail)
orders[i] = detail
}
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)