|
| 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