Skip to content

Commit 4158566

Browse files
committed
feat(examples): add go-account-list-products script
Adds a new example script that fetches available trading pairs for a Go Account via GET /api/prime/trading/v1/accounts/{accountId}/products. Displays a formatted table of available/disabled pairs with base currency, quote currency, and margin support. Updates go-account-workflows.md with documentation, env var requirements, and usage. Ticket: CAAS-2079
1 parent 7ed99d6 commit 4158566

2 files changed

Lines changed: 137 additions & 1 deletion

File tree

examples/docs/go-account-workflows.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,26 @@ const url = coin.url(`/wallet/${walletId}/policy/rule`);
165165
const result = await bitgo.put(url).send(body).result();
166166
```
167167

168-
### 8. Sign Transaction — sign only (Step 2 of 3)
168+
### 8. Go Account List Products — view available trading pairs
169+
**File:** `examples/ts/go-account/go-account-list-products.ts`
170+
171+
Fetches all trading products (pairs) available for a prime trading account.
172+
Use this before placing an order to find valid product symbols.
173+
174+
**Best for:**
175+
- Discovering which trading pairs are enabled for your account
176+
- Validating product symbols before placing an order
177+
178+
**Example:**
179+
```typescript
180+
const url = (bitgo as any).microservicesUrl(
181+
`/api/prime/trading/v1/accounts/${accountId}/products`
182+
);
183+
const response = await (bitgo as any).get(url).result();
184+
// response.data → array of { id, baseCurrency, quoteCurrency, isTradeDisabled, ... }
185+
```
186+
187+
### 9. Sign Transaction — sign only (Step 2 of 3)
169188
**File:** `examples/ts/go-account/sign-transaction.ts`
170189

171190
Signs a pre-built payload and outputs the hex signature. Use this when the build
@@ -339,6 +358,9 @@ const usdtAddress = await wallet.createAddress({
339358
# Sign only: sign a pre-built payload (Step 2 of 3)
340359
OFC_WALLET_ID=your_wallet_id OFC_WALLET_PASSPHRASE=your_passphrase OFC_PREBUILD_PAYLOAD='{"..."}' npx tsx sign-transaction.ts
341360

361+
# List available trading pairs for a Go Account
362+
OFC_WALLET_ID=your_wallet_id npx tsx go-account-list-products.ts
363+
342364
# List whitelist policy rules on a wallet
343365
OFC_WALLET_ID=your_wallet_id npx tsx go-account-whitelist-list.ts
344366

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* Go Account — List Trading Products
3+
*
4+
* Retrieves the available trading pairs (products) for a prime trading account.
5+
* Use this to discover valid product symbols before placing a trade order.
6+
*
7+
* API: GET /api/prime/trading/v1/accounts/{ACCOUNT_ID}/products
8+
*
9+
* Required environment variables (in examples/.env):
10+
* TESTNET_ACCESS_TOKEN - your BitGo access token (must have trade_trade scope)
11+
* OFC_WALLET_ID - your Go Account wallet ID
12+
*
13+
* Copyright 2025, BitGo, Inc. All Rights Reserved.
14+
*/
15+
16+
import { BitGoAPI } from '@bitgo/sdk-api';
17+
require('dotenv').config({ path: '../../../.env' });
18+
19+
// Initialize BitGo SDK
20+
const bitgo = new BitGoAPI({
21+
accessToken: process.env.TESTNET_ACCESS_TOKEN,
22+
env: 'staging', // Change to 'production' for mainnet
23+
});
24+
25+
// ---------------------------------------------------------------------------
26+
// Configuration — update these values or set them as environment variables
27+
// ---------------------------------------------------------------------------
28+
29+
/**
30+
* Your Go Account wallet ID.
31+
* Find this in the BitGo portal or from the wallet object in your API responses.
32+
*/
33+
const accountId = process.env.OFC_WALLET_ID || 'your_wallet_id';
34+
35+
// ---------------------------------------------------------------------------
36+
37+
interface Product {
38+
id: string;
39+
name: string;
40+
baseCurrency: string;
41+
quoteCurrency: string;
42+
baseIncrement: string;
43+
quoteIncrement: string;
44+
isTradeDisabled: boolean;
45+
isMarginTradeSupported: boolean;
46+
}
47+
48+
interface ListProductsResponse {
49+
data: Product[];
50+
}
51+
52+
async function main() {
53+
console.log('=== Go Account — List Trading Products ===\n');
54+
55+
const url = (bitgo as any).microservicesUrl(
56+
`/api/prime/trading/v1/accounts/${accountId}/products`
57+
);
58+
59+
console.log(`Fetching trading products for account ${accountId}...`);
60+
const response: ListProductsResponse = await (bitgo as any).get(url).result();
61+
62+
const products: Product[] = response.data ?? [];
63+
64+
if (products.length === 0) {
65+
console.log('No trading products found for this account.');
66+
return;
67+
}
68+
69+
console.log(`✓ Found ${products.length} product(s)\n`);
70+
71+
// Display a formatted table of available products
72+
const availableProducts = products.filter((p) => !p.isTradeDisabled);
73+
const disabledProducts = products.filter((p) => p.isTradeDisabled);
74+
75+
console.log('Available trading pairs:');
76+
console.log('-'.repeat(70));
77+
console.log(
78+
`${'Product ID'.padEnd(24)} ${'Base'.padEnd(12)} ${'Quote'.padEnd(12)} ${'Margin'}`
79+
);
80+
console.log('-'.repeat(70));
81+
82+
for (const p of availableProducts) {
83+
const margin = p.isMarginTradeSupported ? 'yes' : 'no';
84+
console.log(
85+
`${p.id.padEnd(24)} ${p.baseCurrency.padEnd(12)} ${p.quoteCurrency.padEnd(12)} ${margin}`
86+
);
87+
}
88+
89+
if (disabledProducts.length > 0) {
90+
console.log(`\n${disabledProducts.length} pair(s) currently disabled for trading:`);
91+
for (const p of disabledProducts) {
92+
console.log(` ${p.id} (${p.baseCurrency}/${p.quoteCurrency})`);
93+
}
94+
}
95+
96+
console.log('\nFull response:');
97+
console.log(JSON.stringify(response, null, 2));
98+
99+
console.log('\n' + '='.repeat(60));
100+
console.log('SUMMARY');
101+
console.log('='.repeat(60));
102+
console.log(` Account ID : ${accountId}`);
103+
console.log(` Total products : ${products.length}`);
104+
console.log(` Available to trade: ${availableProducts.length}`);
105+
console.log(` Disabled : ${disabledProducts.length}`);
106+
console.log('='.repeat(60));
107+
108+
console.log('\nNext step: use a product ID above with go-account-place-order.ts');
109+
}
110+
111+
main().catch((e) => {
112+
console.error('\n❌ Error listing trading products:', e);
113+
process.exit(1);
114+
});

0 commit comments

Comments
 (0)