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

@@ -291,7 +291,7 @@ func (d *Deribit) GetHistoricalVolatility(ctx context.Context, ccy currency.Code
}
params := url.Values{}
params.Set("currency", ccy.String())
var data [][2]interface{}
var data [][2]any
err := d.SendHTTPRequest(ctx, exchange.RestFutures, nonMatchingEPL,
common.EncodeURLValues(getHistoricalVolatility, params), &data)
if err != nil {
@@ -719,15 +719,15 @@ func (d *Deribit) GetPublicTicker(ctx context.Context, instrument string) (*Tick
}
// SendHTTPRequest sends an unauthenticated HTTP request
func (d *Deribit) SendHTTPRequest(ctx context.Context, ep exchange.URL, epl request.EndpointLimit, path string, result interface{}) error {
func (d *Deribit) SendHTTPRequest(ctx context.Context, ep exchange.URL, epl request.EndpointLimit, path string, result any) error {
endpoint, err := d.API.Endpoints.GetURL(ep)
if err != nil {
return err
}
data := &struct {
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Data interface{} `json:"result"`
JSONRPC string `json:"jsonrpc"`
ID int64 `json:"id"`
Data any `json:"result"`
}{
Data: result,
}
@@ -1328,7 +1328,7 @@ func (d *Deribit) RemoveAPIKey(ctx context.Context, id int64) error {
}
params := url.Values{}
params.Set("id", strconv.FormatInt(id, 10))
var resp interface{}
var resp any
err := d.SendHTTPAuthRequest(ctx, exchange.RestFutures, nonMatchingEPL, http.MethodGet, removeAPIKey, params, &resp)
if err != nil {
return err
@@ -1396,7 +1396,7 @@ func (d *Deribit) SetEmailForSubAccount(ctx context.Context, sid int64, email st
params := url.Values{}
params.Set("sid", strconv.FormatInt(sid, 10))
params.Set("email", email)
var resp interface{}
var resp any
err := d.SendHTTPAuthRequest(ctx, exchange.RestFutures, nonMatchingEPL, http.MethodGet,
setEmailForSubAccount, params, &resp)
if err != nil {
@@ -2264,7 +2264,7 @@ func (d *Deribit) GetSettlementHistoryByCurency(ctx context.Context, ccy currenc
}
// SendHTTPAuthRequest sends an authenticated request to deribit api
func (d *Deribit) SendHTTPAuthRequest(ctx context.Context, ep exchange.URL, epl request.EndpointLimit, method, path string, params url.Values, result interface{}) error {
func (d *Deribit) SendHTTPAuthRequest(ctx context.Context, ep exchange.URL, epl request.EndpointLimit, method, path string, params url.Values, result any) error {
endpoint, err := d.API.Endpoints.GetURL(ep)
if err != nil {
return err

View File

@@ -44,7 +44,6 @@ var (
errWebsocketConnectionNotAuthenticated = errors.New("websocket connection is not authenticated")
errResolutionNotSet = errors.New("resolution not set")
errInvalidDestinationID = errors.New("invalid destination id")
errUnsupportedChannel = errors.New("channels not supported")
errUnacceptableAPIKey = errors.New("unacceptable api key name")
errInvalidUsername = errors.New("new username has to be specified")
errSubAccountNameChangeFailed = errors.New("subaccount name change failed")
@@ -845,19 +844,19 @@ type TransactionsData struct {
// wsInput defines a request obj for the JSON-RPC login and gets a websocket
// response
type wsInput struct {
JSONRPCVersion string `json:"jsonrpc,omitempty"`
ID int64 `json:"id,omitempty"`
Method string `json:"method"`
Params map[string]interface{} `json:"params,omitempty"`
JSONRPCVersion string `json:"jsonrpc,omitempty"`
ID int64 `json:"id,omitempty"`
Method string `json:"method"`
Params map[string]any `json:"params,omitempty"`
}
// WsRequest defines a request obj for the JSON-RPC endpoints and gets a websocket
// response
type WsRequest struct {
JSONRPCVersion string `json:"jsonrpc,omitempty"`
ID int64 `json:"id,omitempty"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
JSONRPCVersion string `json:"jsonrpc,omitempty"`
ID int64 `json:"id,omitempty"`
Method string `json:"method"`
Params any `json:"params,omitempty"`
}
// WsSubscriptionInput defines a request obj for the JSON-RPC and gets a websocket
@@ -870,22 +869,22 @@ type WsSubscriptionInput struct {
}
type wsResponse struct {
JSONRPCVersion string `json:"jsonrpc,omitempty"`
ID int64 `json:"id,omitempty"`
Result interface{} `json:"result,omitempty"`
JSONRPCVersion string `json:"jsonrpc,omitempty"`
ID int64 `json:"id,omitempty"`
Result any `json:"result,omitempty"`
Error struct {
Message string `json:"message,omitempty"`
Code int64 `json:"code,omitempty"`
Data interface{} `json:"data"`
} `json:"error,omitempty"`
Message string `json:"message,omitempty"`
Code int64 `json:"code,omitempty"`
Data any `json:"data"`
} `json:"error"`
}
type wsLoginResponse struct {
JSONRPCVersion string `json:"jsonrpc"`
ID int64 `json:"id"`
Method string `json:"method"`
Result map[string]interface{} `json:"result"`
Error *UnmarshalError `json:"error"`
JSONRPCVersion string `json:"jsonrpc"`
ID int64 `json:"id"`
Method string `json:"method"`
Result map[string]any `json:"result"`
Error *UnmarshalError `json:"error"`
}
type wsSubscriptionResponse struct {
@@ -934,25 +933,25 @@ type BlockTradeParam struct {
// BlockTradeData represents a user's block trade data.
type BlockTradeData struct {
TradeSeq int64 `json:"trade_seq"`
TradeID string `json:"trade_id"`
Timestamp types.Time `json:"timestamp"`
TickDirection int64 `json:"tick_direction"`
State string `json:"state"`
SelfTrade bool `json:"self_trade"`
Price float64 `json:"price"`
OrderType string `json:"order_type"`
OrderID string `json:"order_id"`
MatchingID interface{} `json:"matching_id"`
Liquidity string `json:"liquidity"`
OptionmpliedVolatility float64 `json:"iv,omitempty"`
InstrumentName string `json:"instrument_name"`
IndexPrice float64 `json:"index_price"`
FeeCurrency string `json:"fee_currency"`
Fee float64 `json:"fee"`
Direction string `json:"direction"`
BlockTradeID string `json:"block_trade_id"`
Amount float64 `json:"amount"`
TradeSeq int64 `json:"trade_seq"`
TradeID string `json:"trade_id"`
Timestamp types.Time `json:"timestamp"`
TickDirection int64 `json:"tick_direction"`
State string `json:"state"`
SelfTrade bool `json:"self_trade"`
Price float64 `json:"price"`
OrderType string `json:"order_type"`
OrderID string `json:"order_id"`
MatchingID any `json:"matching_id"`
Liquidity string `json:"liquidity"`
OptionmpliedVolatility float64 `json:"iv,omitempty"`
InstrumentName string `json:"instrument_name"`
IndexPrice float64 `json:"index_price"`
FeeCurrency string `json:"fee_currency"`
Fee float64 `json:"fee"`
Direction string `json:"direction"`
BlockTradeID string `json:"block_trade_id"`
Amount float64 `json:"amount"`
}
// Announcement represents public announcements.
@@ -987,9 +986,9 @@ type PortfolioMargin struct {
Pls []float64 `json:"pls"`
PcoOpt float64 `json:"pco_opt"`
PcoFtu float64 `json:"pco_ftu"`
OptSummary []interface{} `json:"opt_summary"`
OptSummary []any `json:"opt_summary"`
OptPls []float64 `json:"opt_pls"`
OptEntries []interface{} `json:"opt_entries"`
OptEntries []any `json:"opt_entries"`
MarginPos float64 `json:"margin_pos"`
Margin float64 `json:"margin"`
FtuSummary []struct {
@@ -1114,8 +1113,8 @@ type BlockTradeMoveResponse struct {
type WsResponse struct {
ID int64 `json:"id,omitempty"`
Params struct {
Data interface{} `json:"data"`
Channel string `json:"channel"`
Data any `json:"data"`
Channel string `json:"channel"`
// Used in heartbead and test_request messages.
Type string `json:"type"`
@@ -1124,7 +1123,7 @@ type WsResponse struct {
JSONRPCVersion string `json:"jsonrpc"`
// for status "ok" and "version" push data messages
Result interface{} `json:"result"`
Result any `json:"result"`
}
// VersionInformation represents websocket version information
@@ -1134,12 +1133,12 @@ type VersionInformation struct {
// wsOrderbook represents orderbook push data for a book websocket subscription.
type wsOrderbook struct {
Type string `json:"type"`
Timestamp types.Time `json:"timestamp"`
InstrumentName string `json:"instrument_name"`
ChangeID int64 `json:"change_id"`
Bids [][]interface{} `json:"bids"`
Asks [][]interface{} `json:"asks"`
Type string `json:"type"`
Timestamp types.Time `json:"timestamp"`
InstrumentName string `json:"instrument_name"`
ChangeID int64 `json:"change_id"`
Bids [][]any `json:"bids"`
Asks [][]any `json:"asks"`
}
// wsCandlestickData represents publicly available market data used to generate a TradingView candle chart.
@@ -1310,11 +1309,11 @@ type wsQuoteTickerInformation struct {
// wsRequestForQuote represents a notifications about RFQs for instruments in given currency.
type wsRequestForQuote struct {
State bool `json:"state"`
Side interface{} `json:"side"`
LastRFQTimestamp types.Time `json:"last_rfq_tstamp"`
InstrumentName string `json:"instrument_name"`
Amount interface{} `json:"amount"`
State bool `json:"state"`
Side any `json:"side"`
LastRFQTimestamp types.Time `json:"last_rfq_tstamp"`
InstrumentName string `json:"instrument_name"`
Amount any `json:"amount"`
}
// wsTrade represents trades for an instrument.
@@ -1344,27 +1343,27 @@ type wsAccessLog struct {
// wsChanges represents user's updates related to order, trades, etc. in an instrument.
type wsChanges struct {
Trades []struct {
TradeSeq float64 `json:"trade_seq"`
TradeID string `json:"trade_id"`
Timestamp types.Time `json:"timestamp"`
TickDirection float64 `json:"tick_direction"`
State string `json:"state"`
SelfTrade bool `json:"self_trade"`
ReduceOnly bool `json:"reduce_only"`
ProfitLoss float64 `json:"profit_loss"`
Price float64 `json:"price"`
PostOnly bool `json:"post_only"`
OrderType string `json:"order_type"`
OrderID string `json:"order_id"`
MatchingID interface{} `json:"matching_id"`
MarkPrice float64 `json:"mark_price"`
Liquidity string `json:"liquidity"`
InstrumentName string `json:"instrument_name"`
IndexPrice float64 `json:"index_price"`
FeeCurrency string `json:"fee_currency"`
Fee float64 `json:"fee"`
Direction string `json:"direction"`
Amount float64 `json:"amount"`
TradeSeq float64 `json:"trade_seq"`
TradeID string `json:"trade_id"`
Timestamp types.Time `json:"timestamp"`
TickDirection float64 `json:"tick_direction"`
State string `json:"state"`
SelfTrade bool `json:"self_trade"`
ReduceOnly bool `json:"reduce_only"`
ProfitLoss float64 `json:"profit_loss"`
Price float64 `json:"price"`
PostOnly bool `json:"post_only"`
OrderType string `json:"order_type"`
OrderID string `json:"order_id"`
MatchingID any `json:"matching_id"`
MarkPrice float64 `json:"mark_price"`
Liquidity string `json:"liquidity"`
InstrumentName string `json:"instrument_name"`
IndexPrice float64 `json:"index_price"`
FeeCurrency string `json:"fee_currency"`
Fee float64 `json:"fee"`
Direction string `json:"direction"`
Amount float64 `json:"amount"`
} `json:"trades"`
Positions []WebsocketPosition `json:"positions"`
Orders []struct {

View File

@@ -105,8 +105,6 @@ var defaultSubscriptions = subscription.List{
}
var (
indexENUMS = []string{"ada_usd", "algo_usd", "avax_usd", "bch_usd", "bnb_usd", "btc_usd", "doge_usd", "dot_usd", "eth_usd", "link_usd", "ltc_usd", "luna_usd", "matic_usd", "near_usd", "shib_usd", "sol_usd", "trx_usd", "uni_usd", "usdc_usd", "xrp_usd", "ada_usdc", "bch_usdc", "algo_usdc", "avax_usdc", "btc_usdc", "doge_usdc", "dot_usdc", "bch_usdc", "bnb_usdc", "eth_usdc", "link_usdc", "ltc_usdc", "luna_usdc", "matic_usdc", "near_usdc", "shib_usdc", "sol_usdc", "trx_usdc", "uni_usdc", "xrp_usdc", "btcdvol_usdc", "ethdvol_usdc"}
pingMessage = WsSubscriptionInput{
ID: 2,
JSONRPCVersion: rpcVersion,
@@ -117,7 +115,7 @@ var (
ID: 1,
JSONRPCVersion: rpcVersion,
Method: "public/set_heartbeat",
Params: map[string]interface{}{
Params: map[string]any{
"interval": 15,
},
}
@@ -168,7 +166,7 @@ func (d *Deribit) wsLogin(ctx context.Context) error {
JSONRPCVersion: rpcVersion,
Method: "public/auth",
ID: d.Websocket.Conn.GenerateMessageID(false),
Params: map[string]interface{}{
Params: map[string]any{
"grant_type": "client_signature",
"client_id": creds.Key,
"timestamp": strTS,
@@ -592,7 +590,7 @@ func (d *Deribit) processTicker(respRaw []byte, channels []string) error {
return nil
}
func (d *Deribit) processData(respRaw []byte, result interface{}) error {
func (d *Deribit) processData(respRaw []byte, result any) error {
var response WsResponse
response.Params.Data = result
err := json.Unmarshal(respRaw, &response)

View File

@@ -160,7 +160,7 @@ func (d *Deribit) WSRetrieveHistoricalVolatility(ccy currency.Code) ([]Historica
}{
Currency: ccy,
}
var data [][2]interface{}
var data [][2]any
err := d.SendWSRequest(nonMatchingEPL, getHistoricalVolatility, input, &data, false)
if err != nil {
return nil, err
@@ -1889,7 +1889,7 @@ func (d *Deribit) WSSetMMPConfig(ccy currency.Code, interval kline.Interval, fro
if ccy.IsEmpty() {
return currency.ErrCurrencyCodeEmpty
}
params := make(map[string]interface{})
params := make(map[string]any)
params["currency"] = ccy
intervalString, err := d.GetResolutionFromInterval(interval)
if err != nil {
@@ -2015,7 +2015,7 @@ func (d *Deribit) WSCreateCombo(args []ComboParam) (*ComboDetail, error) {
}
}
var resp *ComboDetail
return resp, d.SendWSRequest(nonMatchingEPL, createCombos, map[string]interface{}{"trades": args}, &resp, true)
return resp, d.SendWSRequest(nonMatchingEPL, createCombos, map[string]any{"trades": args}, &resp, true)
}
// WsLogout gracefully close websocket connection, when COD (Cancel On Disconnect) is enabled orders are not cancelled
@@ -2355,7 +2355,7 @@ func (d *Deribit) WsSimulateBlockTrade(role string, trades []BlockTradeParam) (b
// SendWSRequest sends a request through the websocket connection.
// both authenticated and public endpoints are allowed.
func (d *Deribit) SendWSRequest(epl request.EndpointLimit, method string, params, response interface{}, authenticated bool) error {
func (d *Deribit) SendWSRequest(epl request.EndpointLimit, method string, params, response any, authenticated bool) error {
if authenticated && !d.Websocket.CanUseAuthenticatedEndpoints() {
return errWebsocketConnectionNotAuthenticated
}
@@ -2418,10 +2418,8 @@ func (d *Deribit) sendWsPayload(ep request.EndpointLimit, input *WsRequest, resp
case 10040:
after := 100 * time.Millisecond // because all the request rate will be reset after 1 sec interval
backoff := request.DefaultBackoff()(attempt)
delay := backoff
if after > backoff {
delay = after
}
delay := max(after, backoff)
if dl, ok := ctx.Deadline(); ok && dl.Before(time.Now().Add(delay)) {
return errors.New("deadline would be exceeded by retry")
}