modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)

* modernise: Run new gopls modernise tool against codebase

* Address shazbert's nits

* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling

* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS

* refactor: Various slice usage improvements and rename TODO

* tranches: Revert deleteByID changes due to performance decrease

Shazbert was a F1 driver in a past lifetime 🏎️

* tranches: Simply retrieve copy

Thanks to shazbert

* documentation: Sort contributors list by contributions

* tranches: Remove deadcode in deleteByID
This commit is contained in:
Adrian Gallagher
2025-03-21 09:17:10 +11:00
committed by GitHub
parent d857d704e3
commit 4651af5767
223 changed files with 1504 additions and 1752 deletions

View File

@@ -357,10 +357,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
SentParams: jsonifyInterface([]any{p, assetTypes[i]}),
Function: "UpdateTicker",
Error: msg,
Response: jsonifyInterface([]interface{}{updateTickerResponse}),
Response: jsonifyInterface([]any{updateTickerResponse}),
})
var GetCachedTickerResponse *ticker.Price
@@ -371,10 +371,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
SentParams: jsonifyInterface([]any{p, assetTypes[i]}),
Function: "GetCachedTicker",
Error: msg,
Response: jsonifyInterface([]interface{}{GetCachedTickerResponse}),
Response: jsonifyInterface([]any{GetCachedTickerResponse}),
})
var updateOrderbookResponse *orderbook.Base
@@ -385,10 +385,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
SentParams: jsonifyInterface([]any{p, assetTypes[i]}),
Function: "UpdateOrderbook",
Error: msg,
Response: jsonifyInterface([]interface{}{updateOrderbookResponse}),
Response: jsonifyInterface([]any{updateOrderbookResponse}),
})
var GetCachedOrderbookResponse *orderbook.Base
@@ -399,10 +399,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
SentParams: jsonifyInterface([]any{p, assetTypes[i]}),
Function: "GetCachedOrderbook",
Error: msg,
Response: jsonifyInterface([]interface{}{GetCachedOrderbookResponse}),
Response: jsonifyInterface([]any{GetCachedOrderbookResponse}),
})
var fetchTradablePairsResponse []currency.Pair
@@ -413,10 +413,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{assetTypes[i]}),
SentParams: jsonifyInterface([]any{assetTypes[i]}),
Function: "FetchTradablePairs",
Error: msg,
Response: jsonifyInterface([]interface{}{fetchTradablePairsResponse}),
Response: jsonifyInterface([]any{fetchTradablePairsResponse}),
})
// r6
err = e.UpdateTradablePairs(context.TODO(), false)
@@ -426,10 +426,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{false}),
SentParams: jsonifyInterface([]any{false}),
Function: "UpdateTradablePairs",
Error: msg,
Response: jsonifyInterface([]interface{}{nil}),
Response: jsonifyInterface([]any{nil}),
})
var getHistoricTradesResponse []trade.Data
@@ -440,10 +440,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i], time.Now().Add(-time.Hour), time.Now()}),
SentParams: jsonifyInterface([]any{p, assetTypes[i], time.Now().Add(-time.Hour), time.Now()}),
Function: "GetHistoricTrades",
Error: msg,
Response: jsonifyInterface([]interface{}{getHistoricTradesResponse}),
Response: jsonifyInterface([]any{getHistoricTradesResponse}),
})
var getRecentTradesResponse []trade.Data
@@ -454,10 +454,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i]}),
SentParams: jsonifyInterface([]any{p, assetTypes[i]}),
Function: "GetRecentTrades",
Error: msg,
Response: jsonifyInterface([]interface{}{getRecentTradesResponse}),
Response: jsonifyInterface([]any{getRecentTradesResponse}),
})
var getHistoricCandlesResponse *kline.Item
@@ -472,7 +472,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Function: "GetHistoricCandles",
Error: msg,
Response: getHistoricCandlesResponse,
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i], startTime, endTime, kline.OneDay}),
SentParams: jsonifyInterface([]any{p, assetTypes[i], startTime, endTime, kline.OneDay}),
})
var getHistoricCandlesExtendedResponse *kline.Item
@@ -486,7 +486,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Function: "GetHistoricCandlesExtended",
Error: msg,
Response: getHistoricCandlesExtendedResponse,
SentParams: jsonifyInterface([]interface{}{p, assetTypes[i], startTime, endTime, kline.OneDay}),
SentParams: jsonifyInterface([]any{p, assetTypes[i], startTime, endTime, kline.OneDay}),
})
var getServerTimeResponse time.Time
@@ -500,7 +500,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Function: "GetServerTime",
Error: msg,
Response: getServerTimeResponse,
SentParams: jsonifyInterface([]interface{}{assetTypes[i]}),
SentParams: jsonifyInterface([]any{assetTypes[i]}),
})
err = e.UpdateOrderExecutionLimits(context.TODO(), assetTypes[i])
@@ -511,10 +511,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{assetTypes[i]}),
SentParams: jsonifyInterface([]any{assetTypes[i]}),
Function: "UpdateOrderExecutionLimits",
Error: msg,
Response: jsonifyInterface([]interface{}{""}),
Response: jsonifyInterface([]any{""}),
})
fundingRateRequest := &fundingrate.HistoricalRatesRequest{
@@ -532,10 +532,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{fundingRateRequest}),
SentParams: jsonifyInterface([]any{fundingRateRequest}),
Function: "GetFundingRates",
Error: msg,
Response: jsonifyInterface([]interface{}{fundingRateResponse}),
Response: jsonifyInterface([]any{fundingRateResponse}),
})
var isPerpetualFutures bool
@@ -546,10 +546,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{assetTypes[i], p}),
SentParams: jsonifyInterface([]any{assetTypes[i], p}),
Function: "IsPerpetualFutureCurrency",
Error: msg,
Response: jsonifyInterface([]interface{}{isPerpetualFutures}),
Response: jsonifyInterface([]any{isPerpetualFutures}),
})
}
@@ -563,7 +563,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
Function: "GetCachedAccountInfo",
Error: msg,
Response: jsonifyInterface([]interface{}{GetCachedAccountInfoResponse}),
Response: jsonifyInterface([]any{GetCachedAccountInfoResponse}),
})
var getFundingHistoryResponse []exchange.FundingHistory
@@ -576,7 +576,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
Function: "GetAccountFundingHistory",
Error: msg,
Response: jsonifyInterface([]interface{}{getFundingHistoryResponse}),
Response: jsonifyInterface([]any{getFundingHistoryResponse}),
})
feeType := exchange.FeeBuilder{
@@ -593,10 +593,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{feeType}),
SentParams: jsonifyInterface([]any{feeType}),
Function: "GetFeeByType-Trade",
Error: msg,
Response: jsonifyInterface([]interface{}{getFeeByTypeResponse}),
Response: jsonifyInterface([]any{getFeeByTypeResponse}),
})
s := &order.Submit{
@@ -617,10 +617,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{*s}),
SentParams: jsonifyInterface([]any{*s}),
Function: "SubmitOrder",
Error: msg,
Response: jsonifyInterface([]interface{}{submitOrderResponse}),
Response: jsonifyInterface([]any{submitOrderResponse}),
})
modifyRequest := order.Modify{
@@ -639,7 +639,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{modifyRequest}),
SentParams: jsonifyInterface([]any{modifyRequest}),
Function: "ModifyOrder",
Error: msg,
Response: modifyOrderResponse,
@@ -658,10 +658,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{cancelRequest}),
SentParams: jsonifyInterface([]any{cancelRequest}),
Function: "CancelOrder",
Error: msg,
Response: jsonifyInterface([]interface{}{nil}),
Response: jsonifyInterface([]any{nil}),
})
var request []order.Cancel
@@ -680,10 +680,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{cancelRequest}),
SentParams: jsonifyInterface([]any{cancelRequest}),
Function: "CancelBatchOrders",
Error: msg,
Response: jsonifyInterface([]interface{}{CancelBatchOrdersResponse}),
Response: jsonifyInterface([]any{CancelBatchOrdersResponse}),
})
var cancellAllOrdersResponse order.CancelAllResponse
@@ -694,10 +694,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{cancelRequest}),
SentParams: jsonifyInterface([]any{cancelRequest}),
Function: "CancelAllOrders",
Error: msg,
Response: jsonifyInterface([]interface{}{cancellAllOrdersResponse}),
Response: jsonifyInterface([]any{cancellAllOrdersResponse}),
})
var r15 *order.Detail
@@ -708,10 +708,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{config.OrderSubmission.OrderID, p, assetTypes[i]}),
SentParams: jsonifyInterface([]any{config.OrderSubmission.OrderID, p, assetTypes[i]}),
Function: "GetOrderInfo",
Error: msg,
Response: jsonifyInterface([]interface{}{r15}),
Response: jsonifyInterface([]any{r15}),
})
historyRequest := order.MultiOrderRequest{
@@ -730,10 +730,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{historyRequest}),
SentParams: jsonifyInterface([]any{historyRequest}),
Function: "GetOrderHistory",
Error: msg,
Response: jsonifyInterface([]interface{}{getOrderHistoryResponse}),
Response: jsonifyInterface([]any{getOrderHistoryResponse}),
})
orderRequest := order.MultiOrderRequest{
@@ -752,10 +752,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{orderRequest}),
SentParams: jsonifyInterface([]any{orderRequest}),
Function: "GetActiveOrders",
Error: msg,
Response: jsonifyInterface([]interface{}{getActiveOrdersResponse}),
Response: jsonifyInterface([]any{getActiveOrdersResponse}),
})
var getDepositAddressResponse *deposit.Address
@@ -766,7 +766,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{p.Base, ""}),
SentParams: jsonifyInterface([]any{p.Base, ""}),
Function: "GetDepositAddress",
Error: msg,
Response: getDepositAddressResponse,
@@ -786,10 +786,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{feeType}),
SentParams: jsonifyInterface([]any{feeType}),
Function: "GetFeeByType-Crypto-Withdraw",
Error: msg,
Response: jsonifyInterface([]interface{}{GetFeeByTypeResponse}),
Response: jsonifyInterface([]any{GetFeeByTypeResponse}),
})
withdrawRequest := withdraw.Request{
@@ -811,7 +811,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{withdrawRequest}),
SentParams: jsonifyInterface([]any{withdrawRequest}),
Function: "WithdrawCryptocurrencyFunds",
Error: msg,
Response: withdrawCryptocurrencyFundsResponse,
@@ -833,10 +833,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{feeType}),
SentParams: jsonifyInterface([]any{feeType}),
Function: "GetFeeByType-FIAT-Withdraw",
Error: msg,
Response: jsonifyInterface([]interface{}{getFeeByTypeFiatResponse}),
Response: jsonifyInterface([]any{getFeeByTypeFiatResponse}),
})
withdrawRequestFiat := withdraw.Request{
@@ -876,7 +876,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{withdrawRequestFiat}),
SentParams: jsonifyInterface([]any{withdrawRequestFiat}),
Function: "WithdrawFiatFunds",
Error: msg,
Response: withdrawFiatFundsResponse,
@@ -889,7 +889,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{withdrawRequestFiat}),
SentParams: jsonifyInterface([]any{withdrawRequestFiat}),
Function: "WithdrawFiatFundsToInternationalBank",
Error: msg,
Response: withdrawFiatFundsInternationalResponse,
@@ -913,7 +913,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{marginRateHistoryRequest}),
SentParams: jsonifyInterface([]any{marginRateHistoryRequest}),
Function: "GetMarginRatesHistory",
Error: msg,
Response: marginRateHistoryResponse,
@@ -931,10 +931,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{positionSummaryRequest}),
SentParams: jsonifyInterface([]any{positionSummaryRequest}),
Function: "GetFuturesPositionSummary",
Error: msg,
Response: jsonifyInterface([]interface{}{positionSummaryResponse}),
Response: jsonifyInterface([]any{positionSummaryResponse}),
})
calculatePNLRequest := &futures.PNLCalculatorRequest{
@@ -957,10 +957,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{calculatePNLRequest}),
SentParams: jsonifyInterface([]any{calculatePNLRequest}),
Function: "CalculatePNL",
Error: msg,
Response: jsonifyInterface([]interface{}{calculatePNLResponse}),
Response: jsonifyInterface([]any{calculatePNLResponse}),
})
collateralCalculator := &futures.CollateralCalculator{
@@ -980,10 +980,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{collateralCalculator}),
SentParams: jsonifyInterface([]any{collateralCalculator}),
Function: "ScaleCollateral",
Error: msg,
Response: jsonifyInterface([]interface{}{scaleCollateralResponse}),
Response: jsonifyInterface([]any{scaleCollateralResponse}),
})
totalCollateralCalculator := &futures.TotalCollateralCalculator{
@@ -997,10 +997,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{totalCollateralCalculator}),
SentParams: jsonifyInterface([]any{totalCollateralCalculator}),
Function: "CalculateTotalCollateral",
Error: msg,
Response: jsonifyInterface([]interface{}{calculateTotalCollateralResponse}),
Response: jsonifyInterface([]any{calculateTotalCollateralResponse}),
})
var futuresPositionsResponse []futures.PositionResponse
@@ -1016,10 +1016,10 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
responseContainer.ErrorCount++
}
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
SentParams: jsonifyInterface([]interface{}{futuresPositionsRequest}),
SentParams: jsonifyInterface([]any{futuresPositionsRequest}),
Function: "GetFuturesPositionOrders",
Error: msg,
Response: jsonifyInterface([]interface{}{futuresPositionsResponse}),
Response: jsonifyInterface([]any{futuresPositionsResponse}),
})
response = append(response, responseContainer)
@@ -1027,7 +1027,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
return response
}
func jsonifyInterface(params []interface{}) json.RawMessage {
func jsonifyInterface(params []any) json.RawMessage {
response, _ := json.MarshalIndent(params, "", " ")
return response
}

View File

@@ -57,7 +57,7 @@ type ExchangeAssetPairResponses struct {
type EndpointResponse struct {
Function string `json:"function"`
Error string `json:"error"`
Response interface{} `json:"response"`
Response any `json:"response"`
SentParams json.RawMessage `json:"sentParams"`
}