-
Notifications
You must be signed in to change notification settings - Fork 5
/
backpack_client.ts
843 lines (796 loc) · 22.3 KB
/
backpack_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
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
import got, { OptionsOfTextResponseBody } from "got";
import crypto from "crypto";
import qs from "qs";
import WebSocket from "ws";
const DEFAULT_TIMEOUT_MS = 5_000;
const BASE_URL = process.env.BPX_API_URL ?? "https://api.backpack.exchange/";
const instructions = {
public: new Map<string, { url: string; method: string }>([
["assets", { url: `${BASE_URL}api/v1/assets`, method: "GET" }],
["markets", { url: `${BASE_URL}api/v1/markets`, method: "GET" }],
["ticker", { url: `${BASE_URL}api/v1/ticker`, method: "GET" }],
["depth", { url: `${BASE_URL}api/v1/depth`, method: "GET" }],
["klines", { url: `${BASE_URL}api/v1/klines`, method: "GET" }],
["status", { url: `${BASE_URL}api/v1/status`, method: "GET" }],
["ping", { url: `${BASE_URL}api/v1/ping`, method: "GET" }],
["time", { url: `${BASE_URL}api/v1/time`, method: "GET" }],
["trades", { url: `${BASE_URL}api/v1/trades`, method: "GET" }],
[
"tradesHistory",
{ url: `${BASE_URL}api/v1/trades/history`, method: "GET" },
],
]),
private: new Map<string, { url: string; method: string }>([
["balanceQuery", { url: `${BASE_URL}api/v1/capital`, method: "GET" }],
[
"depositAddressQuery",
{ url: `${BASE_URL}wapi/v1/capital/deposit/address`, method: "GET" },
],
[
"depositQueryAll",
{ url: `${BASE_URL}wapi/v1/capital/deposits`, method: "GET" },
],
[
"fillHistoryQueryAll",
{ url: `${BASE_URL}wapi/v1/history/fills`, method: "GET" },
],
["orderCancel", { url: `${BASE_URL}api/v1/order`, method: "DELETE" }],
["orderCancelAll", { url: `${BASE_URL}api/v1/orders`, method: "DELETE" }],
["orderExecute", { url: `${BASE_URL}api/v1/order`, method: "POST" }],
[
"orderHistoryQueryAll",
{ url: `${BASE_URL}wapi/v1/history/orders`, method: "GET" },
],
["orderQuery", { url: `${BASE_URL}api/v1/order`, method: "GET" }],
["orderQueryAll", { url: `${BASE_URL}api/v1/orders`, method: "GET" }],
[
"withdraw",
{ url: `${BASE_URL}wapi/v1/capital/withdrawals`, method: "POST" },
],
[
"withdrawalQueryAll",
{ url: `${BASE_URL}wapi/v1/capital/withdrawals`, method: "GET" },
],
]),
};
// https://stackoverflow.com/questions/71916954/crypto-sign-function-to-sign-a-message-with-given-private-key
const toPkcs8der = (rawB64: string) => {
var rawPrivate = Buffer.from(rawB64, "base64").subarray(0, 32);
var prefixPrivateEd25519 = Buffer.from(
"302e020100300506032b657004220420",
"hex"
);
var der = Buffer.concat([prefixPrivateEd25519, rawPrivate]);
return crypto.createPrivateKey({ key: der, format: "der", type: "pkcs8" });
};
// https://stackoverflow.com/questions/68612396/sign-and-verify-jws-json-web-signature-with-ed25519-keypair
const toSpki = (rawB64: string) => {
var rawPublic = Buffer.from(rawB64, "base64");
var prefixPublicEd25519 = Buffer.from("302a300506032b6570032100", "hex");
var der = Buffer.concat([prefixPublicEd25519, rawPublic]);
return crypto.createPublicKey({ key: der, format: "der", type: "spki" });
};
/**
* This method generates a signature for Backpack according to
* https://docs.backpack.exchange/#section/Authentication/Signing-requests
* @param {Object} request params as an object
* @param {UInt8Array} privateKey
* @param {number} timestamp Unix time in ms that the request was sent
* @param {string} instruction
* @param {number} window Time window in milliseconds that the request is valid for
* @return {string} base64 encoded signature to include on request
*/
const getMessageSignature = (
request: object,
privateKey: string,
timestamp: number,
instruction: string,
window?: number
): string => {
function alphabeticalSort(a: string, b: string) {
return a.localeCompare(b);
}
const message = qs.stringify(request, { sort: alphabeticalSort });
const headerInfo = { timestamp, window: window ?? DEFAULT_TIMEOUT_MS };
const headerMessage: string = qs.stringify(headerInfo);
const messageToSign: string =
"instruction=" +
instruction +
"&" +
(message ? message + "&" : "") +
headerMessage;
const signature = crypto.sign(
null,
Buffer.from(messageToSign),
toPkcs8der(privateKey)
);
return signature.toString("base64");
};
const rawRequest = async (
instruction: string,
headers: object,
data: object
) => {
const { url, method } = instructions.private.has(instruction)
? instructions.private.get(instruction)!
: instructions.public.get(instruction)!;
let fullUrl = url;
headers["User-Agent"] = "Backpack Typescript API Client";
headers["Content-Type"] =
method == "GET"
? "application/x-www-form-urlencoded"
: "application/json; charset=utf-8";
const options = { headers };
if (method == "GET") {
Object.assign(options, { method });
fullUrl =
url + (Object.keys(data).length > 0 ? "?" + qs.stringify(data) : "");
} else if (method == "POST" || method == "DELETE") {
Object.assign(options, {
method,
body: JSON.stringify(data),
});
}
let response;
try {
response = await got(fullUrl, options as OptionsOfTextResponseBody);
} catch (err: any) {
if (err.response && err.response.body) {
console.log("Error", err.response.body);
}
throw err;
}
const contentType = response.headers["content-type"];
if (contentType?.includes("application/json")) {
const parsed = JSON.parse(response.body, function (_key, value) {
if (value instanceof Array && value.length == 0) {
return value;
}
if (isNaN(Number(value))) {
return value;
}
return Number(value);
});
if (parsed.error && parsed.error.length) {
const error = parsed.error
.filter((e: string) => e.startsWith("E"))
.map((e: string) => e.substr(1));
if (!error.length) {
throw new Error("Backpack API returned an unknown error");
}
throw new Error(
`url=${url} body=${options["body"]} err=${error.join(", ")}`
);
}
return parsed;
} else if (contentType?.includes("text/plain")) {
return response.body;
} else {
return response;
}
};
/**
* BackpackClient connects to the Backpack API
* @param {string} privateKey base64 encoded
* @param {string} publicKey base64 encoded
* @param {object} customHeaders custom headers for all requests
* @param {number} windowMs timeout window for all requests in millis
*/
export class BackpackClient {
private config: {
privateKey: string;
publicKey: string;
timeout: number;
};
private customHeaders: Record<string, string>;
constructor(
privateKey: string,
publicKey: string,
customHeaders: Record<string, string> = {},
windowMs: number = DEFAULT_TIMEOUT_MS,
) {
this.config = { privateKey, publicKey, timeout: windowMs };
this.customHeaders = customHeaders;
// Verify that the keys are a correct pair before sending any requests. Ran
// into errors before with that which were not obvious.
const pubkeyFromPrivateKey = crypto
.createPublicKey(toPkcs8der(privateKey))
.export({ format: "der", type: "spki" })
.toString("base64");
const pubkey = toSpki(publicKey)
.export({ format: "der", type: "spki" })
.toString("base64");
if (pubkeyFromPrivateKey != pubkey) {
throw new Error("Invalid keypair");
}
}
/**
* 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
* @return {Object} The response object
*/
private async api(method: string, params?: object): Promise<object> {
try {
if (instructions.public.has(method)) {
return await this.publicMethod(method, params);
} else if (instructions.private.has(method)) {
return await this.privateMethod(method, params);
}
} catch (e: any) {
console.warn(
"BPX api error",
{
method,
},
instructions.private.has(method) ? instructions.private.get(method)! :
(instructions.public.has(method) ? instructions.public.get(method)! : 'could not find method'),
e.toString(),
e.response && e.response.body ? e.response.body : ""
);
throw e;
}
throw new Error(method + " is not a valid API method.");
}
/**
* 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 async publicMethod(
instruction: string,
params: object = {},
): Promise<object> {
const response = await rawRequest(instruction, this.customHeaders, params);
return response;
}
/**
* 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 async privateMethod(
instruction: string,
params: any = {},
): Promise<object> {
const timestamp = Date.now();
const window = this.config.timeout ?? DEFAULT_TIMEOUT_MS;
const signature = getMessageSignature(
params,
this.config.privateKey,
timestamp,
instruction,
window,
);
const headers = {
"X-Timestamp": timestamp,
"X-Window": window,
"X-API-Key": this.config.publicKey,
"X-Signature": signature,
};
const response = await rawRequest(instruction, { ...headers, ...this.customHeaders}, params);
return response;
}
/**
* https://docs.backpack.exchange/#tag/Capital/operation/get_balances
*/
async Balance(): Promise<BalanceResponse> {
return this.api("balanceQuery") as unknown as BalanceResponse;
}
/**
* https://docs.backpack.exchange/#tag/Capital/operation/get_deposits
*/
async Deposits(params?: DepositsRequest): Promise<DepositsResponse> {
return this.api("depositQueryAll", params) as unknown as DepositsResponse;
}
/**
* https://docs.backpack.exchange/#tag/Capital/operation/get_deposit_address
*/
async DepositAddress(
params: DepositAddressRequest
): Promise<DepositAddressResponse> {
return this.api(
"depositAddressQuery",
params
) as unknown as DepositAddressResponse;
}
/**
* https://docs.backpack.exchange/#tag/Capital/operation/get_withdrawals
*/
async Withdrawals(params?: WithdrawalsRequest): Promise<WithdrawalsResponse> {
return this.api(
"withdrawalQueryAll",
params
) as unknown as WithdrawalsResponse;
}
/**
* https://docs.backpack.exchange/#tag/Capital/operation/request_withdrawal
*/
async Withdraw(params: WithdrawRequest): Promise<void> {
this.api("withdraw", params);
}
/**
* https://docs.backpack.exchange/#tag/History/operation/get_order_history
*/
async OrderHistory(
params?: OrderHistoryRequest
): Promise<OrderHistoryResponse> {
return this.api(
"orderHistoryQueryAll",
params
) as unknown as OrderHistoryResponse;
}
/**
* https://docs.backpack.exchange/#tag/History/operation/get_fills
*/
async FillHistory(params?: FillHistoryRequest): Promise<FillHistoryResponse> {
return this.api(
"fillHistoryQueryAll",
params
) as unknown as FillHistoryResponse;
}
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_assets
*/
async Assets(): Promise<AssetsResponse> {
return this.api("assets") as unknown as AssetsResponse;
}
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_markets
*/
async Markets(): Promise<MarketsResponse> {
return this.api("markets") as unknown as MarketsResponse;
}
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_ticker
*/
async Ticker(params: TickerRequest): Promise<TickerResponse> {
return this.api("ticker", params) as unknown as TickerResponse;
}
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_depth
*/
async Depth(params: DepthRequest): Promise<DepthResponse> {
return this.api("depth", params) as unknown as DepthResponse;
}
/**
* https://docs.backpack.exchange/#tag/Markets/operation/get_klines
*/
async KLines(params: KLinesRequest): Promise<KLinesResponse> {
return this.api("klines", params) as unknown as KLinesResponse;
}
/**
* https://docs.backpack.exchange/#tag/Order/operation/get_order
*/
async GetOrder(params: GetOrderRequest): Promise<GetOrderResponse> {
return this.api("orderQuery", params) as unknown as GetOrderResponse;
}
/**
* https://docs.backpack.exchange/#tag/Order/operation/execute_order
*/
async ExecuteOrder(
params: ExecuteOrderRequest
): Promise<ExecuteOrderResponse> {
return this.api("orderExecute", params) as unknown as ExecuteOrderResponse;
}
/**
* https://docs.backpack.exchange/#tag/Order/operation/cancel_order
*/
async CancelOrder(params: CancelOrderRequest): Promise<CancelOrderResponse> {
return this.api("orderCancel", params) as unknown as CancelOrderResponse;
}
/**
* https://docs.backpack.exchange/#tag/Order/operation/get_open_orders
*/
async GetOpenOrders(
params?: GetOpenOrdersRequest
): Promise<GetOpenOrdersResponse> {
return this.api(
"orderQueryAll",
params
) as unknown as GetOpenOrdersResponse;
}
/**
* https://docs.backpack.exchange/#tag/Order/operation/cancel_open_orders
*/
async CancelOpenOrders(
params: CancelOpenOrdersRequest
): Promise<CancelOpenOrdersResponse> {
return this.api(
"orderCancelAll",
params
) as unknown as CancelOpenOrdersResponse;
}
/**
* https://docs.backpack.exchange/#tag/System/operation/get_status
*/
async Status(): Promise<StatusResponse> {
return this.api("status") as unknown as StatusResponse;
}
/**
* https://docs.backpack.exchange/#tag/System/operation/ping
*/
async Ping(): Promise<PingResponse> {
return this.api("ping") as unknown as PingResponse;
}
/**
* https://docs.backpack.exchange/#tag/System/operation/get_time
*/
async Time(): Promise<TimeResponse> {
return this.api("time") as unknown as TimeResponse;
}
/**
* https://docs.backpack.exchange/#tag/Trades/operation/get_recent_trades
*/
async RecentTrades(
params: RecentTradesRequest
): Promise<RecentTradesResponse> {
return this.api("trades", params) as unknown as RecentTradesResponse;
}
/**
* https://docs.backpack.exchange/#tag/Trades/operation/get_historical_trades
*/
async HistoricalTrades(
params: HistoricalTradesRequest
): Promise<HistoricalTradesResponse> {
return this.api(
"tradesHistory",
params
) as unknown as HistoricalTradesResponse;
}
/**
* https://docs.backpack.exchange/#tag/Streams/Private
* @return {Object} Websocket Websocket connecting to order update stream
*/
subscribeOrderUpdate(): WebSocket {
const privateStream = new WebSocket("wss://ws.backpack.exchange");
const timestamp = Date.now();
const window = this.config.timeout ?? DEFAULT_TIMEOUT_MS;
const signature = getMessageSignature(
{},
this.config.privateKey,
timestamp,
"subscribe",
window,
);
const subscriptionData = {
method: "SUBSCRIBE",
params: ["account.orderUpdate"],
signature: [
this.config.publicKey,
signature,
timestamp.toString(),
window.toString(),
],
};
privateStream.onopen = (_) => {
console.log("Connected to BPX Websocket");
privateStream.send(JSON.stringify(subscriptionData));
};
privateStream.onerror = (error) => {
console.log(`Websocket Error ${error}`);
};
return privateStream;
}
}
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;
price: 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 = {
orderId?: string;
symbol?: string;
limit?: number;
offset?: number;
};
// Not that this is different from other order endpoints because it is missing
// some fields like createdAt
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;
from?: number;
to?: number;
};
export type FillHistoryResponse = {
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;
}[];