-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
spot-client.ts
183 lines (158 loc) · 4.1 KB
/
spot-client.ts
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
171
172
173
174
175
176
177
178
179
180
181
182
183
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
APIResponse,
KlineInterval,
NewSpotOrder,
OrderSide,
OrderTypeSpot,
SpotBalances,
SpotLastPrice,
SpotOrderQueryById,
SpotSymbolInfo,
} from './types';
import BaseRestClient from './util/BaseRestClient';
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
/**
* REST API client for Spot APIs (v1)
*
* @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
* will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
* Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
*/
export class SpotClient extends BaseRestClient {
getClientType() {
return REST_CLIENT_TYPE_ENUM.spot;
}
fetchServerTime(): Promise<number> {
return this.getServerTime();
}
async getServerTime(): Promise<number> {
const res = await this.get('/spot/v1/time');
return res.result.serverTime;
}
/**
*
* Market Data Endpoints
*
**/
getSymbols(): Promise<APIResponse<SpotSymbolInfo[]>> {
return this.get('/spot/v1/symbols');
}
getOrderBook(symbol: string, limit?: number): Promise<APIResponse<any>> {
return this.get('/spot/quote/v1/depth', {
symbol,
limit,
});
}
getMergedOrderBook(
symbol: string,
scale?: number,
limit?: number,
): Promise<APIResponse<any>> {
return this.get('/spot/quote/v1/depth/merged', {
symbol,
scale,
limit,
});
}
getTrades(symbol: string, limit?: number): Promise<APIResponse<any[]>> {
return this.get('/spot/quote/v1/trades', {
symbol,
limit,
});
}
getCandles(
symbol: string,
interval: KlineInterval,
limit?: number,
startTime?: number,
endTime?: number,
): Promise<APIResponse<any[]>> {
return this.get('/spot/quote/v1/kline', {
symbol,
interval,
limit,
startTime,
endTime,
});
}
get24hrTicker(symbol?: string): Promise<APIResponse<any>> {
return this.get('/spot/quote/v1/ticker/24hr', { symbol });
}
getLastTradedPrice(): Promise<APIResponse<SpotLastPrice[]>>;
getLastTradedPrice(symbol: string): Promise<APIResponse<SpotLastPrice>>;
getLastTradedPrice(
symbol?: string,
): Promise<APIResponse<SpotLastPrice | SpotLastPrice[]>> {
return this.get('/spot/quote/v1/ticker/price', { symbol });
}
getBestBidAskPrice(symbol?: string): Promise<APIResponse<any>> {
return this.get('/spot/quote/v1/ticker/book_ticker', { symbol });
}
/**
* Account Data Endpoints
*/
submitOrder(params: NewSpotOrder): Promise<APIResponse<any>> {
return this.postPrivate('/spot/v1/order', params);
}
getOrder(params: SpotOrderQueryById): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/order', params);
}
cancelOrder(params: SpotOrderQueryById): Promise<APIResponse<any>> {
return this.deletePrivate('/spot/v1/order', params);
}
cancelOrderBatch(params: {
symbol: string;
side?: OrderSide;
orderTypes: OrderTypeSpot[];
}): Promise<APIResponse<any>> {
const orderTypes = params.orderTypes
? params.orderTypes.join(',')
: undefined;
return this.deletePrivate('/spot/order/batch-cancel', {
...params,
orderTypes,
});
}
getOpenOrders(
symbol?: string,
orderId?: string,
limit?: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/open-orders', {
symbol,
orderId,
limit,
});
}
getPastOrders(
symbol?: string,
orderId?: string,
limit?: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/history-orders', {
symbol,
orderId,
limit,
});
}
getMyTrades(
symbol?: string,
limit?: number,
fromId?: number,
toId?: number,
): Promise<APIResponse<any>> {
return this.getPrivate('/spot/v1/myTrades', {
symbol,
limit,
fromId,
toId,
});
}
/**
* Wallet Data Endpoints
*/
getBalances(): Promise<APIResponse<SpotBalances>> {
return this.getPrivate('/spot/v1/account');
}
}