-
Notifications
You must be signed in to change notification settings - Fork 57
/
backpack_client.d.ts
379 lines (378 loc) · 10.7 KB
/
backpack_client.d.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import WebSocket from 'ws';
/**
* BackpackClient connects to the Backpack API
* @param {string} privateKey base64 encoded
* @param {string} publicKey base64 encoded
*/
export declare class BackpackClient {
config: any;
constructor(privateKey: string, publicKey: string);
/**
* This method makes a public or private API request.
* @param {String} method 方法名 The API method (public or private)
* @param {Object} params Arguments to pass to the api call
* @param {Number} retrysLeft
* @return {Object} The response object 重试请求的次数
*/
private api;
/**
* This method makes a public API request.
* @param {String} instruction The API method (public or private)
* @param {Object} params Arguments to pass to the api call
* @return {Object} The response object
*/
private publicMethod;
/**
* This method makes a private API request.
* @param {String} instruction The API method (public or private)
* @param {Object} params Arguments to pass to the api call
* @return {Object} The response object
*/
private privateMethod;
/**
* https://docs.backpack.exchange/#tag/Capital/operation/get_balances
*/
Balance(): Promise<BalanceResponse>;
/**
* https://docs.backpack.exchange/#tag/Capital/operation/get_deposits
*/
OrderHistory(params?: OrderHistoryRequest): Promise<OrderHistoryResponse>;
/**
* https://docs.backpack.exchange/#tag/History/operation/get_fills
*/
FillHistory(params?: FillHistoryRequest): Promise<FillHistoryResponse>;
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_assets
*/
Assets(): Promise<AssetsResponse>;
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_markets
*/
Markets(): Promise<MarketsResponse>;
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_ticker
*/
Ticker(params: TickerRequest): Promise<TickerResponse>;
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_depth
*/
Depth(params: DepthRequest): Promise<DepthResponse>;
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_klines
*/
KLines(params: KLinesRequest): Promise<KLinesResponse>;
/**
* https://docs.backpack.exchange/#tag/Order/operation/get_order
*/
GetOrder(params: GetOrderRequest): Promise<GetOrderResponse>;
/**
* https://docs.backpack.exchange/#tag/Order/operation/execute_order
*/
ExecuteOrder(params: ExecuteOrderRequest): Promise<ExecuteOrderResponse>;
/**
* https://docs.backpack.exchange/#tag/Order/operation/cancel_order
*/
CancelOrder(params: CancelOrderRequest): Promise<CancelOrderResponse>;
/**
* https://docs.backpack.exchange/#tag/Order/operation/get_open_orders
*/
GetOpenOrders(params?: GetOpenOrdersRequest): Promise<GetOpenOrdersResponse>;
/**
* https://docs.backpack.exchange/#tag/Order/operation/cancel_open_orders
*/
CancelOpenOrders(params: CancelOpenOrdersRequest): Promise<CancelOpenOrdersResponse>;
/**
* https://docs.backpack.exchange/#tag/System/operation/get_status
*/
Status(): Promise<StatusResponse>;
/**
* https://docs.backpack.exchange/#tag/System/operation/ping
*/
Ping(): Promise<PingResponse>;
/**
* https://docs.backpack.exchange/#tag/System/operation/get_time
*/
Time(): Promise<TimeResponse>;
/**
* https://docs.backpack.exchange/#tag/Trades/operation/get_recent_trades
*/
RecentTrades(params: RecentTradesRequest): Promise<RecentTradesResponse>;
/**
* https://docs.backpack.exchange/#tag/Trades/operation/get_historical_trades
*/
HistoricalTrades(params: HistoricalTradesRequest): Promise<HistoricalTradesResponse>;
/**
* https://docs.backpack.exchange/#tag/Streams/Private
* @return {Object} Websocket Websocket connecting to order update stream
*/
subscribeOrderUpdate(): WebSocket;
}
export type Blockchain = "Solana" | "Ethereum" | "Polygon" | "Bitcoin";
export type SelfTradePrevention = "RejectTaker" | "RejectMaker" | "RejectBoth" | "Allow";
export type TimeInForce = "GTC" | "IOC" | "FOK";
export type OrderStatus = "Cancelled" | "Expired" | "Filled" | "New" | "PartiallyFilled" | "Triggered";
export type LimitOrder = {
orderType: "limit";
id: string;
clientId?: number;
symbol: string;
side: "Bid" | "Ask";
quantity: number;
executedQuantity: number;
quoteQuantity: number;
executedQuoteQuantity: number;
triggerPrice?: number;
timeInForce: TimeInForce;
selfTradePrevention: SelfTradePrevention;
status: OrderStatus;
createdAt: number;
};
export type MarketOrder = {
orderType: "market";
id: string;
clientId?: number;
symbol: string;
side: "Bid" | "Ask";
quantity?: number;
executedQuantity: number;
quoteQuantity?: number;
executedQuoteQuantity: number;
triggerPrice?: number;
timeInForce: TimeInForce;
selfTradePrevention: SelfTradePrevention;
status: OrderStatus;
createdAt: number;
};
export type BalanceResponse = {
[property: string]: {
available: number;
locked: number;
staked: number;
};
};
export type DepositsRequest = {
limit?: number;
offset?: number;
};
export type DepositsResponse = {
id: number;
toAddress?: string;
fromAddress?: string;
confirmationBlockNumber?: number;
providerId?: string;
source: "administrator" | "solana" | "ethereum" | "bitcoin" | "nuvei" | "banxa" | "ioFinnet";
status: "pending" | "cancelled" | "confirmed" | "expired" | "initiated" | "received" | "refunded";
symbol: string;
quantity: number;
transactionHash?: string;
createdAt: string;
}[];
export type DepositAddressRequest = {
blockchain: Blockchain;
};
export type DepositAddressResponse = {
address: string;
};
export type WithdrawRequest = {
address: string;
blockchain: Blockchain;
clientId?: string;
quantity: number;
symbol: string;
twoFactorToken: string;
};
export type OrderHistoryRequest = {
limit?: number;
offset?: number;
};
export type OrderHistoryResponse = {
id: number;
orderType: "Market" | "Limit";
symbol: string;
side: "Bid" | "Ask";
price: number;
triggerPrice: number;
quantity: number;
quoteQuantity: number;
timeInForce: TimeInForce;
selfTradePrevention: SelfTradePrevention;
postOnly: boolean;
status: OrderStatus;
}[];
export type FillHistoryRequest = {
orderId?: string;
symbol?: string;
limit?: number;
offset?: number;
};
export type FillHistoryResponse = {
id: number;
tradeId: number;
orderId: number;
symbol: string;
side: "Bid" | "Ask";
price: number;
quantity: number;
fee: number;
feeSymbol: string;
isMaker: boolean;
timestamp: string;
}[];
export type WithdrawalsRequest = {
limit?: number;
offset?: number;
};
export type WithdrawalsResponse = {
id: number;
blockchain: Blockchain;
clientId?: string;
identifier?: string;
quantity: number;
fee: number;
symbol: string;
status: "pending" | "confirmed" | "verifying" | "void";
toAddress: string;
transactionHash?: string;
createdAt: string;
}[];
export type AssetsResponse = {
symbol: string;
tokens: {
blockchain: Blockchain;
depositEnabled: boolean;
minimumDeposit: number;
withdrawEnabled: boolean;
minimumWithdrawal: number;
maximumWithdrawal: number;
withdrawalFee: number;
}[];
}[];
export type MarketsResponse = {
symbol: string;
baseSymbol: string;
quoteSymbol: string;
filters: {
price: {
minPrice: number;
maxPrice?: number;
tickSize: number;
};
quantity: {
minQuantity: number;
maxQuantity?: number;
stepSize: number;
};
leverage?: {
minLeverage: number;
maxLeverage: number;
stepSize: number;
};
};
}[];
export type TickerRequest = {
symbol: string;
};
export type TickerResponse = {
symbol: string;
firstPrice: number;
lastPrice: number;
priceChange: number;
priceChangePercent: number;
high: number;
low: number;
volume: number;
trades: number;
};
export type DepthRequest = {
symbol: string;
};
export type DepthResponse = {
asks: [number, number][];
bids: [number, number][];
lastUpdated: number;
};
export type KLinesRequest = {
symbol: string;
interval: "1m" | "3m" | "5m" | "15m" | "30m" | "1h" | "2h" | "4h" | "6h" | "8h" | "12h" | "1d" | "3d" | "1month";
startTime?: number;
endTime?: number;
};
export type KLinesResponse = {
start: string;
open?: string;
high?: string;
low?: string;
close?: string;
end?: string;
volume?: string;
trades?: string;
};
export type GetOrderRequest = {
clientId?: number;
orderId?: string;
symbol: string;
};
export type GetOrderResponse = LimitOrder | MarketOrder;
export type ExecuteOrderRequest = {
clientId?: number;
orderType: "Limit" | "Market";
postOnly?: boolean;
price?: number;
quantity?: number;
quoteQuantity?: number;
selfTradePrevention?: SelfTradePrevention;
side: "Bid" | "Ask";
symbol: string;
timeInForce?: TimeInForce;
triggerPrice?: number;
};
export type ExecuteOrderResponse = LimitOrder | MarketOrder | {
id: string;
};
export type CancelOrderRequest = {
clientId?: number;
orderId?: string;
symbol: string;
};
export type CancelOrderResponse = LimitOrder | MarketOrder | {
id: string;
};
export type GetOpenOrdersRequest = {
symbol?: string;
};
export type GetOpenOrdersResponse = (LimitOrder | MarketOrder)[];
export type CancelOpenOrdersRequest = {
symbol: string;
};
export type CancelOpenOrdersResponse = (LimitOrder | MarketOrder)[];
export type StatusResponse = {
status: "Ok" | "Maintenance";
message?: string;
};
export type PingResponse = "pong";
export type TimeResponse = number;
export type RecentTradesRequest = {
symbol: string;
limit?: number;
};
export type RecentTradesResponse = {
id: number;
price: number;
quantity: number;
quoteQuantity: number;
timestamp: number;
isBuyerMaker: boolean;
}[];
export type HistoricalTradesRequest = {
symbol: string;
limit?: number;
offset?: number;
};
export type HistoricalTradesResponse = {
id: number;
price: number;
quantity: number;
quoteQuantity: number;
timestamp: number;
isBuyerMaker: boolean;
}[];