-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfasterHmacSign.ts
36 lines (30 loc) · 1017 Bytes
/
fasterHmacSign.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
import { createHmac } from 'crypto';
import { RestClient } from '../src';
// import from npm, after installing via npm `npm install bitmart-api`
// import { RestClient } from 'bitmart-api';
const account = {
key: process.env.API_KEY || 'apiKeyHere',
secret: process.env.API_SECRET || 'apiSecretHere',
memo: process.env.API_MEMO || 'apiMemoHere',
};
const client = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
apiMemo: account.memo,
/**
* Overkill in almost every case, but if you need any optimisation available,
* you can inject a faster sign mechanism such as node's native createHmac:
*/
customSignMessageFn: async (message, secret) => {
return createHmac('sha256', secret).update(message).digest('hex');
},
});
async function getSpotBalances() {
try {
const balances = await client.getAccountBalancesV1();
console.log('Balances: ', JSON.stringify(balances, null, 2));
} catch (e) {
console.error(`Req error: `, e);
}
}
getSpotBalances();