-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathrest_api.go
More file actions
78 lines (64 loc) · 2.57 KB
/
rest_api.go
File metadata and controls
78 lines (64 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Binance Algo REST API
OpenAPI Specification for the Binance Algo REST API
*/
package binancealgorestapi
import (
"context"
"net/url"
"runtime"
"github.com/binance/binance-connector-go/common/v2/common"
)
// RestAPIClient manages communication with the Binance Algo REST API v1.4.0
type RestAPIClient struct {
cfg *common.ConfigurationRestAPI
// API Services
FutureAlgoAPI *FutureAlgoAPIService
SpotAlgoAPI *SpotAlgoAPIService
}
type Service struct {
client *RestAPIClient
}
// NewRestAPIClient creates a new Binance Binance Algo REST API REST API client
//
// @param cfg *common.ConfigurationRestAPI - The configuration for the REST API client
// @return *RestAPIClient - The newly created REST API client
func NewRestAPIClient(cfg *common.ConfigurationRestAPI) *RestAPIClient {
customHeaders := common.GetCustomHeaders(cfg)
if customHeaders == nil {
customHeaders = make(map[string]string)
}
customHeaders["User-Agent"] = "binance-algo/1.4.0 (Go/" + runtime.Version() + "; " + runtime.GOOS + "; " + runtime.GOARCH + ")"
cfg.CustomHeaders = customHeaders
c := &RestAPIClient{cfg: cfg}
// API Services
c.FutureAlgoAPI = &FutureAlgoAPIService{client: c}
c.SpotAlgoAPI = &SpotAlgoAPIService{client: c}
return c
}
// SendRequest sends an API request and returns the API response
//
// # T is a generic type parameter representing the expected response type
//
// @param ctx context.Context - The context for the request
// @param path string - The API endpoint path
// @param method string - The HTTP method (GET, POST, etc.)
// @param queryParams url.Values - The query parameters for the request
// @param bodyParams interface{} - The body parameters for the request
// @param config *common.ConfigurationRestAPI - The configuration for the REST API client
// @return *common.RestApiResponse[T] - The API response containing the typed data
// @return error - An error if the request fails
func SendRequest[T any](ctx context.Context, path string, method string, queryParams url.Values, bodyParams interface{}, config *common.ConfigurationRestAPI, signed bool) (*common.RestApiResponse[T], error) {
resp, err := common.SendRequest[T](ctx, path, method, queryParams, bodyParams, config, signed)
if err != nil {
return resp, err
}
return resp, err
}
// GetConfig returns the configuration of the REST API client
//
// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior
// @return *common.ConfigurationRestAPI - The configuration of the REST API client
func (c *RestAPIClient) GetConfig() *common.ConfigurationRestAPI {
return c.cfg
}