forked from binance/binance-connector-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest-api.ts
More file actions
170 lines (158 loc) · 6.54 KB
/
rest-api.ts
File metadata and controls
170 lines (158 loc) · 6.54 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* Binance Alpha REST API
*
* OpenAPI Specification for the Binance Alpha REST API
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { ConfigurationRestAPI, RestApiResponse, sendRequest } from '@binance/common';
import { MarketDataApi } from './modules/market-data-api';
import type {
AggregatedTradesRequest,
KlinesRequest,
TickerRequest,
} from './modules/market-data-api';
import type {
AggregatedTradesResponse,
GetExchangeInfoResponse,
KlinesResponse,
TickerResponse,
TokenListResponse,
} from './types';
export class RestAPI {
private configuration: ConfigurationRestAPI;
private marketDataApi: MarketDataApi;
constructor(configuration: ConfigurationRestAPI) {
this.configuration = configuration;
this.marketDataApi = new MarketDataApi(configuration);
}
/**
* Generic function to send a request.
* @param endpoint - The API endpoint to call.
* @param method - HTTP method to use (GET, POST, DELETE, etc.).
* @param queryParams - Query parameters for the request.
* @param bodyParams - Body parameters for the request.
*
* @returns A promise resolving to the response data object.
*/
sendRequest<T>(
endpoint: string,
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH',
queryParams: Record<string, unknown> = {},
bodyParams: Record<string, unknown> = {}
): Promise<RestApiResponse<T>> {
return sendRequest<T>(
this.configuration,
endpoint,
method,
queryParams,
bodyParams,
undefined
);
}
/**
* Generic function to send a signed request.
* @param endpoint - The API endpoint to call.
* @param method - HTTP method to use (GET, POST, DELETE, etc.).
* @param queryParams - Query parameters for the request.
* @param bodyParams - Body parameters for the request.
*
* @returns A promise resolving to the response data object.
*/
sendSignedRequest<T>(
endpoint: string,
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH',
queryParams: Record<string, unknown> = {},
bodyParams: Record<string, unknown> = {}
): Promise<RestApiResponse<T>> {
return sendRequest<T>(
this.configuration,
endpoint,
method,
queryParams,
bodyParams,
undefined,
{ isSigned: true }
);
}
/**
* Retrieves compressed, aggregated historical trades for a specific symbol. Useful for recent trade history.
*
* Weight: 0
*
* @summary Aggregated Trades
* @param {AggregatedTradesRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<AggregatedTradesResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/alpha/market-data/rest-api/Aggregated-Trades Binance API Documentation}
*/
aggregatedTrades(
requestParameters: AggregatedTradesRequest
): Promise<RestApiResponse<AggregatedTradesResponse>> {
return this.marketDataApi.aggregatedTrades(requestParameters);
}
/**
* Fetches general exchange information, such as supported symbols, rate limits, and server time.
*
* Weight: 0
*
* @summary Get Exchange Info
*
* @returns {Promise<RestApiResponse<GetExchangeInfoResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/alpha/market-data/rest-api/Get-Exchange-Info Binance API Documentation}
*/
getExchangeInfo(): Promise<RestApiResponse<GetExchangeInfoResponse>> {
return this.marketDataApi.getExchangeInfo();
}
/**
* Fetches Kline/candlestick bars for a symbol, which include open/high/low/close prices and volume over intervals. Useful for charting and analysis.
*
* Weight: 0
*
* @summary Klines (Candlestick Data)
* @param {KlinesRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<KlinesResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/alpha/market-data/rest-api/Klines Binance API Documentation}
*/
klines(requestParameters: KlinesRequest): Promise<RestApiResponse<KlinesResponse>> {
return this.marketDataApi.klines(requestParameters);
}
/**
* Gets the 24-hour rolling window price change statistics for a symbol, including volume and price changes.
*
* Weight: 0
*
* @summary Ticker (24hr Price Statistics)
* @param {TickerRequest} requestParameters Request parameters.
*
* @returns {Promise<RestApiResponse<TickerResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/alpha/market-data/rest-api/24hr-ticker-price-change Binance API Documentation}
*/
ticker(requestParameters: TickerRequest): Promise<RestApiResponse<TickerResponse>> {
return this.marketDataApi.ticker(requestParameters);
}
/**
* Retrieves a list of all available ALPHA tokens, including their IDs and symbols. Use this to find the token ID for constructing symbols in other endpoints.
*
* Weight: 0
*
* @summary Token List
*
* @returns {Promise<RestApiResponse<TokenListResponse>>}
* @throws {RequiredError | ConnectorClientError | UnauthorizedError | ForbiddenError | TooManyRequestsError | RateLimitBanError | ServerError | NotFoundError | NetworkError | BadRequestError}
* @see {@link https://developers.binance.com/docs/alpha/market-data/rest-api/Token-List Binance API Documentation}
*/
tokenList(): Promise<RestApiResponse<TokenListResponse>> {
return this.marketDataApi.tokenList();
}
}