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

@@ -202,7 +202,7 @@ func (f *FTX) GetMarket(ctx context.Context, marketName string) (MarketData, err
}
// GetOrderbook gets orderbook for a given market with a given depth (default depth 20)
func (f *FTX) GetOrderbook(ctx context.Context, marketName string, depth int64) (OrderbookData, error) {
func (f *FTX) GetOrderbook(ctx context.Context, marketName string, depth int64) (*OrderbookData, error) {
result := struct {
Data TempOBData `json:"result"`
}{}
@@ -216,22 +216,24 @@ func (f *FTX) GetOrderbook(ctx context.Context, marketName string, depth int64)
var resp OrderbookData
err := f.SendHTTPRequest(ctx, exchange.RestSpot, fmt.Sprintf(getOrderbook, marketName, strDepth), &result)
if err != nil {
return resp, err
return nil, err
}
resp.MarketName = marketName
resp.Asks = make([]OData, len(result.Data.Asks))
for x := range result.Data.Asks {
resp.Asks = append(resp.Asks, OData{
resp.Asks[x] = OData{
Price: result.Data.Asks[x][0],
Size: result.Data.Asks[x][1],
})
}
}
resp.Bids = make([]OData, len(result.Data.Bids))
for y := range result.Data.Bids {
resp.Bids = append(resp.Bids, OData{
resp.Bids[y] = OData{
Price: result.Data.Bids[y][0],
Size: result.Data.Bids[y][1],
})
}
}
return resp, nil
return &resp, nil
}
// GetTrades gets trades based on the conditions specified
@@ -1506,7 +1508,7 @@ func (f *FTX) FetchExchangeLimits(ctx context.Context) ([]order.MinMaxLevel, err
return nil, err
}
var limits []order.MinMaxLevel
limits := make([]order.MinMaxLevel, 0, len(data))
for x := range data {
if !data[x].Enabled {
continue

View File

@@ -3,7 +3,6 @@ package ftx
import (
"context"
"errors"
"fmt"
"log"
"math"
"os"
@@ -1000,7 +999,7 @@ func TestGetPublicOptionsTrades(t *testing.T) {
}
tmNow := time.Now()
result, err = f.GetPublicOptionsTrades(context.Background(),
tmNow.AddDate(0, -1, 0), tmNow, "5")
tmNow.AddDate(-1, 0, 0), tmNow, "5")
if err != nil {
t.Error(err)
}
@@ -2036,19 +2035,19 @@ func TestCalculatePNL(t *testing.T) {
if err != nil {
t.Error(err)
}
var orders []order.Detail
orders := make([]order.Detail, len(positions))
for i := range positions {
orders = append(orders, order.Detail{
orders[i] = order.Detail{
Side: positions[i].Side,
Pair: pair,
ID: fmt.Sprintf("%v", positions[i].ID),
ID: positions[i].ID,
Price: positions[i].Price,
Amount: positions[i].Amount,
AssetType: asset.Futures,
Exchange: f.Name,
Fee: positions[i].Fee,
Date: positions[i].Date,
})
}
}
exch := f.Name

View File

@@ -480,24 +480,25 @@ func (f *FTX) WsProcessUpdateOB(data *WsOrderbookData, p currency.Pair, a asset.
update := buffer.Update{
Asset: a,
Pair: p,
Bids: make([]orderbook.Item, len(data.Bids)),
Asks: make([]orderbook.Item, len(data.Asks)),
UpdateTime: timestampFromFloat64(data.Time),
}
var err error
for x := range data.Bids {
update.Bids = append(update.Bids, orderbook.Item{
update.Bids[x] = orderbook.Item{
Price: data.Bids[x][0],
Amount: data.Bids[x][1],
})
}
}
for x := range data.Asks {
update.Asks = append(update.Asks, orderbook.Item{
update.Asks[x] = orderbook.Item{
Price: data.Asks[x][0],
Amount: data.Asks[x][1],
})
}
}
err = f.Websocket.Orderbook.Update(&update)
err := f.Websocket.Orderbook.Update(&update)
if err != nil {
return err
}
@@ -544,18 +545,19 @@ func (f *FTX) WsProcessPartialOB(data *WsOrderbookData, p currency.Pair, a asset
a,
p)
}
var bids, asks []orderbook.Item
bids := make(orderbook.Items, len(data.Bids))
asks := make(orderbook.Items, len(data.Asks))
for x := range data.Bids {
bids = append(bids, orderbook.Item{
bids[x] = orderbook.Item{
Price: data.Bids[x][0],
Amount: data.Bids[x][1],
})
}
}
for x := range data.Asks {
asks = append(asks, orderbook.Item{
asks[x] = orderbook.Item{
Price: data.Asks[x][0],
Amount: data.Asks[x][1],
})
}
}
newOrderBook := orderbook.Base{

View File

@@ -140,8 +140,11 @@ func TestFTX_wsHandleData_Details(t *testing.T) {
"createdAt": "2021-08-08T10:35:02.649437+00:00"
}
}`
if status := parseRaw(t, inputFilled).(*order.Detail).Status; status != order.Filled {
t.Errorf("have %s, want %s", status, order.Filled)
orderDetail, ok := parseRaw(t, inputFilled).(*order.Detail)
if !ok {
t.Error("unable to type asset order detail")
} else if orderDetail.Status != order.Filled {
t.Errorf("have %s, want %s", orderDetail.Status, order.Filled)
}
const inputCancelled = `{
@@ -166,8 +169,12 @@ func TestFTX_wsHandleData_Details(t *testing.T) {
"createdAt": "2021-08-08T10:35:02.649437+00:00"
}
}`
if status := parseRaw(t, inputCancelled).(*order.Detail).Status; status != order.Cancelled {
t.Errorf("have %s, want %s", status, order.Cancelled)
orderDetail, ok = parseRaw(t, inputCancelled).(*order.Detail)
if !ok {
t.Error("unable to type asset order detail")
} else if orderDetail.Status != order.Cancelled {
t.Errorf("have %s, want %s", orderDetail.Status, order.Cancelled)
}
}

View File

@@ -431,6 +431,7 @@ func (f *FTX) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType as
return book, err
}
book.Bids = make(orderbook.Items, 0, len(tempResp.Bids))
for x := range tempResp.Bids {
// Bear tokens have illiquid books and contain negative place holders.
if tempResp.Bids[x].Size < 0 && strings.Contains(p.String(), "BEAR") {
@@ -438,8 +439,10 @@ func (f *FTX) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType as
}
book.Bids = append(book.Bids, orderbook.Item{
Amount: tempResp.Bids[x].Size,
Price: tempResp.Bids[x].Price})
Price: tempResp.Bids[x].Price,
})
}
book.Asks = make(orderbook.Items, 0, len(tempResp.Asks))
for y := range tempResp.Asks {
// Bear tokens have illiquid books and contain negative place holders.
if tempResp.Asks[y].Size < 0 && strings.Contains(p.String(), "BEAR") {
@@ -447,7 +450,8 @@ func (f *FTX) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType as
}
book.Asks = append(book.Asks, orderbook.Item{
Amount: tempResp.Asks[y].Size,
Price: tempResp.Asks[y].Price})
Price: tempResp.Asks[y].Price,
})
}
err = book.Process()
if err != nil {
@@ -522,44 +526,44 @@ func (f *FTX) FetchAccountInfo(ctx context.Context, assetType asset.Item) (accou
// GetFundingHistory returns funding history, deposits and
// withdrawals
func (f *FTX) GetFundingHistory(ctx context.Context) ([]exchange.FundHistory, error) {
var resp []exchange.FundHistory
depositData, err := f.FetchDepositHistory(ctx)
if err != nil {
return resp, err
}
for x := range depositData {
var tempData exchange.FundHistory
tempData.Fee = depositData[x].Fee
tempData.Timestamp = depositData[x].Time
tempData.ExchangeName = f.Name
tempData.CryptoToAddress = depositData[x].Address.Address
tempData.CryptoTxID = depositData[x].TxID
tempData.CryptoChain = depositData[x].Address.Method
tempData.Status = depositData[x].Status
tempData.Amount = depositData[x].Size
tempData.Currency = depositData[x].Coin
tempData.TransferID = strconv.FormatInt(depositData[x].ID, 10)
resp = append(resp, tempData)
return nil, err
}
withdrawalData, err := f.FetchWithdrawalHistory(ctx)
if err != nil {
return resp, err
return nil, err
}
fundingData := make([]exchange.FundHistory, 0, len(depositData)+len(withdrawalData))
for x := range depositData {
fundingData = append(fundingData, exchange.FundHistory{
Fee: depositData[x].Fee,
Timestamp: depositData[x].Time,
ExchangeName: f.Name,
CryptoToAddress: depositData[x].Address.Address,
CryptoTxID: depositData[x].TxID,
CryptoChain: depositData[x].Address.Method,
Status: depositData[x].Status,
Amount: depositData[x].Size,
Currency: depositData[x].Coin,
TransferID: strconv.FormatInt(depositData[x].ID, 10),
})
}
for y := range withdrawalData {
var tempData exchange.FundHistory
tempData.Fee = withdrawalData[y].Fee
tempData.Timestamp = withdrawalData[y].Time
tempData.ExchangeName = f.Name
tempData.CryptoToAddress = withdrawalData[y].Address
tempData.CryptoTxID = withdrawalData[y].TXID
tempData.CryptoChain = withdrawalData[y].Method
tempData.Status = withdrawalData[y].Status
tempData.Amount = withdrawalData[y].Size
tempData.Currency = withdrawalData[y].Coin
tempData.TransferID = strconv.FormatInt(withdrawalData[y].ID, 10)
resp = append(resp, tempData)
fundingData = append(fundingData, exchange.FundHistory{
Fee: withdrawalData[y].Fee,
Timestamp: withdrawalData[y].Time,
ExchangeName: f.Name,
CryptoToAddress: withdrawalData[y].Address,
CryptoTxID: withdrawalData[y].TXID,
CryptoChain: withdrawalData[y].Method,
Status: withdrawalData[y].Status,
Amount: withdrawalData[y].Size,
Currency: withdrawalData[y].Coin,
TransferID: strconv.FormatInt(withdrawalData[y].ID, 10),
})
}
return resp, nil
return fundingData, nil
}
// GetWithdrawalsHistory returns previous withdrawals data
@@ -1659,18 +1663,15 @@ func (f *FTX) GetFuturesPositions(ctx context.Context, a asset.Item, cp currency
if err != nil {
return nil, err
}
sort.Slice(fills, func(i, j int) bool {
return fills[i].Time.Before(fills[j].Time)
})
var resp []order.Detail
var side order.Side
resp := make([]order.Detail, len(fills))
for i := range fills {
price := fills[i].Price
side, err = order.StringToOrderSide(fills[i].Side)
side, err := order.StringToOrderSide(fills[i].Side)
if err != nil {
return nil, err
}
resp = append(resp, order.Detail{
resp[i] = order.Detail{
Side: side,
Pair: cp,
ID: strconv.FormatInt(fills[i].ID, 10),
@@ -1680,8 +1681,12 @@ func (f *FTX) GetFuturesPositions(ctx context.Context, a asset.Item, cp currency
Exchange: f.Name,
Fee: fills[i].Fee,
Date: fills[i].Time,
})
}
}
sort.Slice(resp, func(i, j int) bool {
return resp[i].Date.Before(resp[j].Date)
})
return resp, nil
}