mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 07:26:48 +00:00
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:
@@ -10,6 +10,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -301,19 +302,16 @@ func checkExistingExchanges(exchName string) bool {
|
||||
|
||||
// checkMissingExchanges checks if any supported exchanges are missing api checker functionality
|
||||
func checkMissingExchanges() []string {
|
||||
tempArray := make([]string, len(usageData.Exchanges))
|
||||
for x := range usageData.Exchanges {
|
||||
tempArray[x] = usageData.Exchanges[x].Name
|
||||
exchanges := make([]string, len(usageData.Exchanges))
|
||||
for i, exch := range usageData.Exchanges {
|
||||
exchanges[i] = exch.Name
|
||||
}
|
||||
supportedExchs := exchange.Exchanges
|
||||
for z := 0; z < len(supportedExchs); {
|
||||
if common.StringSliceContainsInsensitive(tempArray, supportedExchs[z]) {
|
||||
supportedExchs = append(supportedExchs[:z], supportedExchs[z+1:]...)
|
||||
continue
|
||||
}
|
||||
z++
|
||||
}
|
||||
return supportedExchs
|
||||
|
||||
supportedExchs := slices.Clone(exchange.Exchanges)
|
||||
|
||||
return slices.DeleteFunc(supportedExchs, func(exchName string) bool {
|
||||
return common.StringSliceContainsInsensitive(exchanges, exchName)
|
||||
})
|
||||
}
|
||||
|
||||
// readFileData reads the file data from the given json file
|
||||
@@ -461,8 +459,6 @@ func checkChangeLog(htmlData *HTMLScrapingData) (string, error) {
|
||||
dataStrings, err = htmlScrapeBitfinex(htmlData)
|
||||
case pathBitmex:
|
||||
dataStrings, err = htmlScrapeBitmex(htmlData)
|
||||
case pathANX:
|
||||
dataStrings, err = htmlScrapeANX(htmlData)
|
||||
case pathPoloniex:
|
||||
dataStrings, err = htmlScrapePoloniex(htmlData)
|
||||
case pathBTCMarkets:
|
||||
@@ -513,7 +509,7 @@ func checkChangeLog(htmlData *HTMLScrapingData) (string, error) {
|
||||
}
|
||||
|
||||
// addExch appends exchange data to updates.json for future api checks
|
||||
func addExch(exchName, checkType string, data interface{}, isUpdate bool) error {
|
||||
func addExch(exchName, checkType string, data any, isUpdate bool) error {
|
||||
var file []byte
|
||||
if !isUpdate {
|
||||
if checkExistingExchanges(exchName) {
|
||||
@@ -554,7 +550,7 @@ func addExch(exchName, checkType string, data interface{}, isUpdate bool) error
|
||||
}
|
||||
|
||||
// fillData fills exchange data based on the given checkType
|
||||
func fillData(exchName, checkType string, data interface{}) (ExchangeInfo, error) {
|
||||
func fillData(exchName, checkType string, data any) (ExchangeInfo, error) {
|
||||
switch checkType {
|
||||
case github:
|
||||
tempData, ok := data.(GithubData)
|
||||
@@ -743,27 +739,13 @@ func htmlScrapeHitBTC(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aBody := string(a)
|
||||
|
||||
r, err := regexp.Compile(htmlData.RegExp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
str := r.FindAllString(aBody, -1)
|
||||
var resp []string
|
||||
for x := range str {
|
||||
tempStr := strings.Replace(str[x], "section-v-", "", 1)
|
||||
var repeat bool
|
||||
for y := range resp {
|
||||
if tempStr == resp[y] {
|
||||
repeat = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !repeat {
|
||||
resp = append(resp, tempStr)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
|
||||
return r.FindAllString(string(a), -1), nil
|
||||
}
|
||||
|
||||
// htmlScrapeBTCMarkets gets the check string for BTCMarkets exchange
|
||||
@@ -844,41 +826,6 @@ loop:
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// htmlScrapeANX gets the check string for BTCMarkets exchange
|
||||
func htmlScrapeANX(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
|
||||
a, err := io.ReadAll(temp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aBody := string(a)
|
||||
r, err := regexp.Compile(htmlData.RegExp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
str := r.FindAllString(aBody, -1)
|
||||
var resp []string
|
||||
for x := range str {
|
||||
tempStr := strings.Replace(str[x], "section-v-", "", 1)
|
||||
var repeat bool
|
||||
for y := range resp {
|
||||
if tempStr == resp[y] {
|
||||
repeat = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !repeat {
|
||||
resp = append(resp, tempStr)
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// htmlScrapeExmo gets the check string for Exmo Exchange
|
||||
func htmlScrapeExmo(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
header := map[string]string{
|
||||
@@ -1098,7 +1045,7 @@ func trelloCreateNewCheck(newCheckName string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var resp interface{}
|
||||
var resp any
|
||||
params := url.Values{}
|
||||
params.Set("name", newName)
|
||||
return sendAuthReq(http.MethodPost,
|
||||
@@ -1180,7 +1127,7 @@ func nameStateChanges(currentName, currentState string) (string, error) {
|
||||
|
||||
// trelloUpdateCheckItem updates a check item for trello
|
||||
func trelloUpdateCheckItem(checkItemID, name, state string) error {
|
||||
var resp interface{}
|
||||
var resp any
|
||||
params := url.Values{}
|
||||
newName, err := nameStateChanges(name, state)
|
||||
if err != nil {
|
||||
@@ -1217,7 +1164,7 @@ func updateFile(name string) error {
|
||||
}
|
||||
|
||||
// SendGetReq sends get req
|
||||
func sendGetReq(path string, result interface{}) error {
|
||||
func sendGetReq(path string, result any) error {
|
||||
var requester *request.Requester
|
||||
var err error
|
||||
if strings.Contains(path, "github") {
|
||||
@@ -1244,7 +1191,7 @@ func sendGetReq(path string, result interface{}) error {
|
||||
}
|
||||
|
||||
// sendAuthReq sends auth req
|
||||
func sendAuthReq(method, path string, result interface{}) error {
|
||||
func sendAuthReq(method, path string, result any) error {
|
||||
requester, err := request.New("Apichecker",
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(request.NewBasicRateLimit(time.Second*10, 100, 1)))
|
||||
@@ -1292,7 +1239,7 @@ func trelloCreateNewList() error {
|
||||
if trelloBoardID == "" {
|
||||
return errors.New("trelloBoardID not set, cannot create a new list")
|
||||
}
|
||||
var resp interface{}
|
||||
var resp any
|
||||
listName := createList
|
||||
if configData.CreateListName != "" {
|
||||
listName = configData.CreateListName
|
||||
@@ -1327,7 +1274,7 @@ func trelloDeleteCheckItem(checkitemID string) error {
|
||||
if checkitemID == "" {
|
||||
return errors.New("checkitemID cannot be empty")
|
||||
}
|
||||
var resp interface{}
|
||||
var resp any
|
||||
return sendAuthReq(http.MethodDelete,
|
||||
fmt.Sprintf(pathDeleteCheckitems, trelloChecklistID, checkitemID, apiKey, apiToken),
|
||||
&resp)
|
||||
@@ -1344,7 +1291,7 @@ func trelloCreateNewCard() error {
|
||||
if trelloListID == "" {
|
||||
return errors.New("trelloListID not set, cannot create a new checklist")
|
||||
}
|
||||
var resp interface{}
|
||||
var resp any
|
||||
cardName := createCard
|
||||
if configData.CreateCardName != "" {
|
||||
cardName = configData.CreateCardName
|
||||
@@ -1385,7 +1332,7 @@ func trelloCreateNewChecklist() error {
|
||||
if !areAPIKeysSet() || (trelloCardID == "") {
|
||||
return errors.New("apikeys or trelloCardID not set, cannot create a new checklist")
|
||||
}
|
||||
var resp interface{}
|
||||
var resp any
|
||||
checklistName := createChecklist
|
||||
if configData.CreateChecklistName != "" {
|
||||
checklistName = configData.CreateChecklistName
|
||||
@@ -1540,22 +1487,14 @@ func htmlScrapeBitfinex(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
str := r.FindAllString(string(a), -1)
|
||||
var resp []string
|
||||
for x := range str {
|
||||
tempStr := strings.Replace(str[x], "section-v-", "", 1)
|
||||
var repeat bool
|
||||
for y := range resp {
|
||||
if tempStr == resp[y] {
|
||||
repeat = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !repeat {
|
||||
resp = append(resp, tempStr)
|
||||
}
|
||||
matches := r.FindAllString(string(a), -1)
|
||||
results := make([]string, 0, len(matches))
|
||||
for _, match := range matches {
|
||||
s := strings.Replace(match, "section-v-", "", 1)
|
||||
results = append(results, s)
|
||||
}
|
||||
return resp, nil
|
||||
slices.Sort(results)
|
||||
return slices.Clip(slices.Compact(results)), nil
|
||||
}
|
||||
|
||||
// htmlScrapeBinance gets checkstring for binance exchange
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
gctfile "github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
@@ -221,15 +222,10 @@ func TestHTMLScrapeCoinbasepro(t *testing.T) {
|
||||
|
||||
func TestHTMLScrapeBitfinex(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := HTMLScrapingData{
|
||||
DateFormat: "2006-01-02",
|
||||
RegExp: `section-v-(2\d{3}-\d{1,2}-\d{1,2})`,
|
||||
Path: "https://docs.bitfinex.com/docs/changelog",
|
||||
}
|
||||
_, err := htmlScrapeBitfinex(&data)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
data := HTMLScrapingData{DateFormat: "2006-01-02", RegExp: `section-v-(2\d{3}-\d{1,2}-\d{1,2})`, Path: "https://docs.bitfinex.com/docs/changelog"}
|
||||
r, err := htmlScrapeBitfinex(&data)
|
||||
require.NoError(t, err, "htmlScrapeBitfinex must not error")
|
||||
require.NotEmpty(t, r, "htmlScrapeBitfinex must return a non empty result")
|
||||
}
|
||||
|
||||
func TestHTMLScrapeBitmex(t *testing.T) {
|
||||
@@ -251,13 +247,10 @@ func TestHTMLScrapeBitmex(t *testing.T) {
|
||||
|
||||
func TestHTMLScrapeHitBTC(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := HTMLScrapingData{
|
||||
RegExp: `newest version \d{1}.\d{1}`,
|
||||
Path: "https://api.hitbtc.com/",
|
||||
}
|
||||
if _, err := htmlScrapeHitBTC(&data); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
data := HTMLScrapingData{RegExp: `newest version \d{1}.\d{1}`, Path: "https://api.hitbtc.com/"}
|
||||
r, err := htmlScrapeHitBTC(&data)
|
||||
require.NoError(t, err, "htmlScrapeHitBTC must not error")
|
||||
require.NotEmpty(t, r, "htmlScrapeHitBTC must return a non empty result")
|
||||
}
|
||||
|
||||
func TestHTMLScrapeBTSE(t *testing.T) {
|
||||
@@ -296,17 +289,6 @@ func TestHTMLScrapeBitflyer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTMLScrapeANX(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := HTMLScrapingData{
|
||||
RegExp: `ANX Exchange API v\d{1}`,
|
||||
Path: "https://anxv3.docs.apiary.io/#reference/quickstart-catalog",
|
||||
}
|
||||
if _, err := htmlScrapeANX(&data); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTMLPoloniex(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := HTMLScrapingData{
|
||||
|
||||
Reference in New Issue
Block a user