forked from tiagosiebler/ftx-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.ts
53 lines (44 loc) · 1.16 KB
/
rest.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
import { RestClient } from "../src/rest-client";
/*
Demonstrations on basic REST API calls
*/
(async () => {
// Optional, but required for private endpoints
const key = 'apiKeyHere';
const secret = 'apiSecretHere';
const client = new RestClient(key, secret);
// Try some public API calls
try {
console.log('getBalances: ', await client.getBalances());
console.log('getSubaccountBalances: ', await client.getSubaccountBalances('sub1'));
console.log('getMarkets: ', await client.getMarket('ABNB-0326'));
} catch (e) {
console.error('public get method failed: ', e);
}
// Try some authenticated API calls
const market = 'BTC/USD';
try {
console.log('buysome: ', await client.placeOrder({
market,
side: 'buy',
type: 'market',
size: 0.001,
price: null
}));
} catch (e) {
console.error('buy failed: ', e);
}
try {
console.log('sellsome: ', await client.placeOrder({
market,
side: 'sell',
type: 'market',
size: 0.001,
price: null
}));
} catch (e) {
console.error('sell failed: ', e);
}
// Nothing left - close the process
process.exit();
})();