-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08-account.ts
More file actions
45 lines (38 loc) · 1.39 KB
/
Copy path08-account.ts
File metadata and controls
45 lines (38 loc) · 1.39 KB
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
/**
* 08 — Account: user info, preferences, subaccounts, rate-limit quota
*
* Authenticated. Run: npx tsx examples/08-account.ts
*/
import { DeltaClient } from '../src/index.js';
async function main() {
const client = new DeltaClient({
testnet: true,
apiKey: process.env.DELTA_API_KEY,
apiSecret: process.env.DELTA_API_SECRET,
});
try {
// GET /v2/profile
const user = await client.account.getUser();
console.log(`User #${user.id} ${user.email} KYC=${user.is_kyc_done}`);
// Preferences (UI prefs blob — schema is open-ended)
const prefs = await client.account.getPreferences();
console.log(`Preferences keys: ${Object.keys(prefs).length}`);
// Update a preference (uncomment to apply)
// await client.account.updatePreferences({ ...prefs, last_seen_pair: 'BTCUSD' });
// Subaccounts
const subs = await client.account.listSubaccounts();
console.log(`Subaccounts: ${subs.length}`);
for (const s of subs) {
console.log(` #${s.id} "${s.name}" parent=${s.user_id}`);
}
// Live rate-limit quota — useful before a burst of writes
const quota = await client.account.getRateLimitQuota();
console.log(
`Rate limit: ${quota.rate_limit_used}/${quota.rate_limit} ` +
`resets at ${new Date(quota.rate_limit_reset * 1000).toISOString()}`,
);
} finally {
client.destroy();
}
}
main().catch(console.error);