Files
gocryptotrader/cmd/exchange_template/rest.tmpl
Samuael A. fc0f262c42 exchanges: Limit mock test JSON data size by truncating slices and maps (#1968)
* set limiter to first level mock data list and updated unit tests

* address nested slices length limit

* minor fix recording file and update unit tests

* minor updates on unit tests

* re-record mock files and minor fix on the unit tests ti adapt the mock data change

* improve http recording limit value and fix issues with mock data in binance

* added MockDataSliceLimit in request items and resolve minor unit test issues

* resolve missed conflict

* rename mock variables, resolve unit test issues, and other updates

* minor fix to CheckJSON and update unit tests

* minor unit test fix

* further optimization on mock CheckJSON method, unit tests, and re-record poloniex

* common and recording unit tests fix

* minor linter issues fix

* unit tests format fix

* fix miscellaneous error

* unit tests fix and minor docs update

* re-record and reduce mock file size

* indentation fix

* minor assertion test fix

* reverted log.Printf line in live testing

* rename variables

* update NewVCRServer unit test

* replace string comparison with *net.OpError check

* restructur net error test

* exchanges/mock: Remove redundant error assertion message in TestNewVCRServer

---------

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
2025-08-26 10:27:07 +10:00

47 lines
1.5 KiB
Cheetah

{{define "rest"}}
package {{.Name}}
import (
"context"
"net/http"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
)
// Exchange implements exchange.IBotExchange and contains additional specific API methods for interacting with {{.CapitalName}}
type Exchange struct {
exchange.Base
}
const (
apiURL = ""
apiVersion = ""
)
// SendHTTPRequest sends an unauthenticated HTTP request
func (e *Exchange) SendHTTPRequest(ctx context.Context, path string, result any) error {
// This is used to generate the *http.Request, used in conjunction with the
// generate functionality below.
item := &request.Item{
Method: http.MethodGet,
Path: path,
Result: result,
Verbose: e.Verbose,
HTTPDebugging: e.HTTPDebugging,
HTTPRecording: e.HTTPRecording,
}
// Request function that closes over the above request.Item values, which
// executes on every attempt after rate limiting.
generate := func() (*request.Item, error) { return item, nil }
endpoint := request.Unset // Used in conjunction with the rate limiting
// system defined in the exchange package to slow down outbound requests
// depending on each individual endpoint.
return e.SendPayload(ctx, endpoint, generate, request.UnauthenticatedRequest)
}
// Start implementing public and private exchange API funcs below
// Private endpoints can be implemented in a separate file with a _private.go suffix for ease of access and simplicity.
{{end}}