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

@@ -83,11 +83,23 @@ func (g *Gateio) GetMarketInfo(ctx context.Context) (MarketInfoResponse, error)
if !ok {
return result, errors.New("unable to type assert pairv")
}
decimalPlaces, ok := pairv["decimal_places"].(float64)
if !ok {
return result, errors.New("unable to type assert decimal_places")
}
minAmount, ok := pairv["min_amount"].(float64)
if !ok {
return result, errors.New("unable to type assert min_amount")
}
fee, ok := pairv["fee"].(float64)
if !ok {
return result, errors.New("unable to type assert fee")
}
result.Pairs = append(result.Pairs, MarketInfoPairsResponse{
Symbol: itemk,
DecimalPlaces: pairv["decimal_places"].(float64),
MinAmount: pairv["min_amount"].(float64),
Fee: pairv["fee"].(float64),
DecimalPlaces: decimalPlaces,
MinAmount: minAmount,
Fee: fee,
})
}
}
@@ -138,64 +150,59 @@ func (g *Gateio) GetTrades(ctx context.Context, symbol string) (TradeHistory, er
}
// GetOrderbook returns the orderbook data for a suppled symbol
func (g *Gateio) GetOrderbook(ctx context.Context, symbol string) (Orderbook, error) {
func (g *Gateio) GetOrderbook(ctx context.Context, symbol string) (*Orderbook, error) {
urlPath := fmt.Sprintf("/%s/%s/%s", gateioAPIVersion, gateioOrderbook, symbol)
var resp OrderbookResponse
err := g.SendHTTPRequest(ctx, exchange.RestSpotSupplementary, urlPath, &resp)
if err != nil {
return Orderbook{}, err
return nil, err
}
if resp.Result != "true" {
return Orderbook{}, errors.New("result was not true")
}
var ob Orderbook
if len(resp.Asks) == 0 {
return ob, errors.New("asks are empty")
switch {
case resp.Result != "true":
return nil, errors.New("result was not true")
case len(resp.Asks) == 0:
return nil, errors.New("asks are empty")
case len(resp.Bids) == 0:
return nil, errors.New("bids are empty")
}
// Asks are in reverse order
for x := len(resp.Asks) - 1; x != 0; x-- {
data := resp.Asks[x]
ob := Orderbook{
Result: resp.Result,
Elapsed: resp.Elapsed,
Bids: make([]OrderbookItem, len(resp.Bids)),
Asks: make([]OrderbookItem, 0, len(resp.Asks)),
}
price, err := strconv.ParseFloat(data[0], 64)
for x := len(resp.Asks) - 1; x != 0; x-- {
price, err := strconv.ParseFloat(resp.Asks[x][0], 64)
if err != nil {
continue
return nil, err
}
amount, err := strconv.ParseFloat(data[1], 64)
amount, err := strconv.ParseFloat(resp.Asks[x][1], 64)
if err != nil {
continue
return nil, err
}
ob.Asks = append(ob.Asks, OrderbookItem{Price: price, Amount: amount})
}
if len(resp.Bids) == 0 {
return ob, errors.New("bids are empty")
}
for x := range resp.Bids {
data := resp.Bids[x]
price, err := strconv.ParseFloat(data[0], 64)
price, err := strconv.ParseFloat(resp.Bids[x][0], 64)
if err != nil {
continue
return nil, err
}
amount, err := strconv.ParseFloat(data[1], 64)
amount, err := strconv.ParseFloat(resp.Bids[x][1], 64)
if err != nil {
continue
return nil, err
}
ob.Bids = append(ob.Bids, OrderbookItem{Price: price, Amount: amount})
ob.Bids[x] = OrderbookItem{Price: price, Amount: amount}
}
ob.Result = resp.Result
ob.Elapsed = resp.Elapsed
return ob, nil
return &ob, nil
}
// GetSpotKline returns kline data for the most recent time period

View File

@@ -313,6 +313,22 @@ func (g *Gateio) wsHandleData(respRaw []byte) error {
if err != nil {
return err
}
orderID, ok := invalidJSON["id"].(float64)
if !ok {
return errors.New("unable to type assert order id")
}
ctime, ok := invalidJSON["ctime"].(float64)
if !ok {
return errors.New("unable to type assert ctime")
}
mtime, ok := invalidJSON["mtime"].(float64)
if !ok {
return errors.New("unable to type assert mtime")
}
g.Websocket.DataHandler <- &order.Detail{
Price: price,
Amount: amount,
@@ -320,13 +336,13 @@ func (g *Gateio) wsHandleData(respRaw []byte) error {
RemainingAmount: left,
Fee: fee,
Exchange: g.Name,
ID: strconv.FormatFloat(invalidJSON["id"].(float64), 'f', -1, 64),
ID: strconv.FormatFloat(orderID, 'f', -1, 64),
Type: oType,
Side: oSide,
Status: oStatus,
AssetType: a,
Date: convert.TimeFromUnixTimestampDecimal(invalidJSON["ctime"].(float64)),
LastUpdated: convert.TimeFromUnixTimestampDecimal(invalidJSON["mtime"].(float64)),
Date: convert.TimeFromUnixTimestampDecimal(ctime),
LastUpdated: convert.TimeFromUnixTimestampDecimal(mtime),
Pair: p,
}
case strings.Contains(result.Method, "depth"):
@@ -349,7 +365,7 @@ func (g *Gateio) wsHandleData(respRaw []byte) error {
return err
}
var asks, bids []orderbook.Item
asks := make([]orderbook.Item, len(data.Asks))
var amount, price float64
for i := range data.Asks {
amount, err = strconv.ParseFloat(data.Asks[i][1], 64)
@@ -360,9 +376,10 @@ func (g *Gateio) wsHandleData(respRaw []byte) error {
if err != nil {
return err
}
asks = append(asks, orderbook.Item{Amount: amount, Price: price})
asks[i] = orderbook.Item{Amount: amount, Price: price}
}
bids := make([]orderbook.Item, len(data.Bids))
for i := range data.Bids {
amount, err = strconv.ParseFloat(data.Bids[i][1], 64)
if err != nil {
@@ -372,7 +389,7 @@ func (g *Gateio) wsHandleData(respRaw []byte) error {
if err != nil {
return err
}
bids = append(bids, orderbook.Item{Amount: amount, Price: price})
bids[i] = orderbook.Item{Amount: amount, Price: price}
}
var p currency.Pair
@@ -616,7 +633,7 @@ func (g *Gateio) Unsubscribe(channelsToUnsubscribe []stream.ChannelSubscription)
// & LTC_USDT this function will unsubscribe both. This function will be
// kept unlinked to the websocket subsystem and a full connection flush will
// occur when currency items are disabled.
var channelsThusFar []string
channelsThusFar := make([]string, 0, len(channelsToUnsubscribe))
for i := range channelsToUnsubscribe {
if common.StringDataCompare(channelsThusFar,
channelsToUnsubscribe[i].Channel) {

View File

@@ -319,18 +319,20 @@ func (g *Gateio) 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,
})
}
}
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 {
@@ -463,14 +465,14 @@ func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, assetType
if err != nil {
return nil, err
}
var resp []trade.Data
resp := make([]trade.Data, len(tradeData.Data))
for i := range tradeData.Data {
var side order.Side
side, err = order.StringToOrderSide(tradeData.Data[i].Type)
if err != nil {
return nil, err
}
resp = append(resp, trade.Data{
resp[i] = trade.Data{
Exchange: g.Name,
TID: tradeData.Data[i].TradeID,
CurrencyPair: p,
@@ -479,7 +481,7 @@ func (g *Gateio) GetRecentTrades(ctx context.Context, p currency.Pair, assetType
Price: tradeData.Data[i].Rate,
Amount: tradeData.Data[i].Amount,
Timestamp: time.Unix(tradeData.Data[i].Timestamp, 0),
})
}
}
err = g.AddTradesToBuffer(resp...)
@@ -829,7 +831,7 @@ func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
return nil, err
}
var orders []order.Detail
orders := make([]order.Detail, len(trades))
for i := range trades {
var pair currency.Pair
pair, err = currency.NewPairDelimiter(trades[i].Pair, format.Delimiter)
@@ -850,7 +852,7 @@ func (g *Gateio) GetOrderHistory(ctx context.Context, req *order.GetOrdersReques
Pair: pair,
}
detail.InferCostsAndTimes()
orders = append(orders, detail)
orders[i] = detail
}
order.FilterOrdersByTimeRange(&orders, req.StartTime, req.EndTime)
@@ -919,9 +921,9 @@ func (g *Gateio) GetAvailableTransferChains(ctx context.Context, cryptocurrency
return nil, err
}
var availableChains []string
availableChains := make([]string, len(chains.MultichainAddresses))
for x := range chains.MultichainAddresses {
availableChains = append(availableChains, chains.MultichainAddresses[x].Chain)
availableChains[x] = chains.MultichainAddresses[x].Chain
}
return availableChains, nil
}