|
| 1 | +--- |
| 2 | +name: coin-radar-update-mapping |
| 3 | +description: Updates ledger ID mappings using Ledger's Coinradar API to sync the top cryptocurrencies. Use when the user asks to update mappings from Coinradar, sync top tokens, or mentions the Coinradar API. |
| 4 | +--- |
| 5 | + |
| 6 | +# Coin Radar Update Mapping |
| 7 | + |
| 8 | +Automatically syncs cryptocurrency token ledger IDs from Ledger's Coinradar API into `assets/_record.json`. This approach fetches the top tokens by market cap and their complete ledger ID mappings. |
| 9 | + |
| 10 | +## When to Use |
| 11 | + |
| 12 | +- User asks to update mappings from Coinradar |
| 13 | +- User wants to sync the top N tokens (e.g., "top 50", "top 100") |
| 14 | +- User mentions using the Coinradar API |
| 15 | +- User wants to update multiple tokens at once based on market rank |
| 16 | + |
| 17 | +## Process |
| 18 | + |
| 19 | +### 1. Fetch Top Currencies List |
| 20 | + |
| 21 | +Use the Coinradar currencies endpoint to get the top tokens by market cap: |
| 22 | + |
| 23 | +``` |
| 24 | +https://api.coinradar.ledger.com/v1/live/currencies?limit=50&offset=0 |
| 25 | +``` |
| 26 | + |
| 27 | +**Parameters:** |
| 28 | +- `limit` - Number of tokens to fetch (start with 50, max 1000) |
| 29 | +- `offset` - Pagination offset (use 0 to start from the top) |
| 30 | + |
| 31 | +**Response structure:** |
| 32 | +```json |
| 33 | +[ |
| 34 | + { |
| 35 | + "name": "Bitcoin", |
| 36 | + "ticker": "BTC", |
| 37 | + "rank": 1, |
| 38 | + "image": "https://proxycgassets.api.live.ledger.com/coins/images/1/large/bitcoin.png", |
| 39 | + "coinradarId": "672de245673914b8252e64fae57cf88d56cb930e18f172e96498e0041970e127", |
| 40 | + "supported": true, |
| 41 | + "swap": true, |
| 42 | + "buy": true, |
| 43 | + "currencies": null |
| 44 | + } |
| 45 | +] |
| 46 | +``` |
| 47 | + |
| 48 | +**Key field:** `coinradarId` - Use this to fetch detailed ledger IDs for each token. |
| 49 | + |
| 50 | +### 2. Fetch Ledger IDs for Each Token |
| 51 | + |
| 52 | +For each `coinradarId` from step 1, call the nested currency endpoint: |
| 53 | + |
| 54 | +``` |
| 55 | +https://api.coinradar.ledger.com/v1/live/currency-nested/{coinradarId} |
| 56 | +``` |
| 57 | + |
| 58 | +**Response structure:** |
| 59 | +```json |
| 60 | +{ |
| 61 | + "name": "Tether USD", |
| 62 | + "ticker": "USDT", |
| 63 | + "rank": 3, |
| 64 | + "image": "https://proxycgassets.api.live.ledger.com/coins/images/325/large/Tether.png", |
| 65 | + "coinradarId": "b19f92c398a6f639793b7a21cb678d75c4d8383f9fa4bf2bbc5afb4e212e57c7", |
| 66 | + "currencies": [ |
| 67 | + { |
| 68 | + "name": "Tether USD", |
| 69 | + "ticker": "USDT", |
| 70 | + "network": "ethereum", |
| 71 | + "contract": "0xdac17f958d2ee523a2206206994597c13d831ec7", |
| 72 | + "ledgerId": "ethereum/erc20/usd_tether__erc20_", |
| 73 | + "supported": true |
| 74 | + }, |
| 75 | + { |
| 76 | + "name": "Tether USD", |
| 77 | + "ticker": "USDT", |
| 78 | + "network": "bsc", |
| 79 | + "contract": "0x55d398326f99059ff775485246999027b3197955", |
| 80 | + "ledgerId": "bsc/bep20/binance-peg_bsc-usd", |
| 81 | + "supported": true |
| 82 | + } |
| 83 | + ] |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### 3. Extract All Ledger IDs |
| 88 | + |
| 89 | +From the `currencies` array, extract all `ledgerId` values (ignore entries where `ledgerId` is null). |
| 90 | + |
| 91 | +**Important Rule:** All ledger IDs returned for a single `coinradarId` should use the same icon/image, with the following exceptions: |
| 92 | +- **L1 and L2 exceptions:** Base, Optimism, Arbitrum, and other Layer 1/Layer 2 networks may have their own specific icons |
| 93 | +- For most tokens, all networks share the same icon |
| 94 | +- The `image` field from the parent object provides the standard icon URL |
| 95 | + |
| 96 | +### 4. Read Current State |
| 97 | + |
| 98 | +Load `assets/_record.json` to see existing mappings. |
| 99 | + |
| 100 | +### 5. Match or Create Token Entry |
| 101 | + |
| 102 | +For each token from the API: |
| 103 | + |
| 104 | +1. Look for an existing entry in `_record.json` using the ticker (UPPERCASE) |
| 105 | +2. If found, prepare to merge ledger IDs |
| 106 | +3. If not found, prepare to create a new entry with the ticker in UPPERCASE |
| 107 | + |
| 108 | +### 6. Merge Ledger IDs |
| 109 | + |
| 110 | +For each token: |
| 111 | +- Keep all existing IDs from `_record.json` |
| 112 | +- Add new IDs from the Coinradar API |
| 113 | +- Remove duplicates |
| 114 | +- Sort alphabetically |
| 115 | + |
| 116 | +### 7. Update File |
| 117 | + |
| 118 | +Update `assets/_record.json` with the merged ledger ID lists for all processed tokens. |
| 119 | + |
| 120 | +## File Format |
| 121 | + |
| 122 | +`assets/_record.json` structure: |
| 123 | +```json |
| 124 | +{ |
| 125 | + "TOKEN_TICKER": { |
| 126 | + "ids": [ |
| 127 | + "network/standard/token_identifier", |
| 128 | + "another_network/standard/token_identifier" |
| 129 | + ] |
| 130 | + } |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +## Examples |
| 135 | + |
| 136 | +**User request:** "Update les mappings pour les top 50 tokens avec Coinradar" |
| 137 | + |
| 138 | +**Steps:** |
| 139 | +1. Fetch `https://api.coinradar.ledger.com/v1/live/currencies?limit=50&offset=0` |
| 140 | +2. For each token in the response: |
| 141 | + - Extract `coinradarId` and `ticker` |
| 142 | + - Fetch `https://api.coinradar.ledger.com/v1/live/currency-nested/{coinradarId}` |
| 143 | + - Extract all `ledgerId` values from the `currencies` array |
| 144 | +3. Load `assets/_record.json` |
| 145 | +4. For each token: |
| 146 | + - Find or create entry for the ticker (UPPERCASE) |
| 147 | + - Merge new ledger IDs with existing ones |
| 148 | + - Sort and deduplicate |
| 149 | +5. Update `assets/_record.json` with all changes |
| 150 | +6. Report summary: how many tokens processed, how many updated, how many created |
| 151 | + |
| 152 | +**User request:** "Sync BTC, ETH, and USDT from Coinradar" |
| 153 | + |
| 154 | +**Steps:** |
| 155 | +1. Fetch `https://api.coinradar.ledger.com/v1/live/currencies?limit=100&offset=0` |
| 156 | +2. Filter the response to only BTC, ETH, and USDT by ticker |
| 157 | +3. For each of these 3 tokens: |
| 158 | + - Extract `coinradarId` |
| 159 | + - Fetch nested currency data |
| 160 | + - Extract all ledger IDs |
| 161 | +4. Load `assets/_record.json` |
| 162 | +5. Merge ledger IDs for "BTC", "ETH", and "USDT" entries |
| 163 | +6. Update file |
| 164 | + |
| 165 | +## Edge Cases |
| 166 | + |
| 167 | +**Token not in Coinradar API**: Inform user that the token wasn't found in the top N tokens from Coinradar. |
| 168 | + |
| 169 | +**Token not in _record.json**: Create a new entry with the ticker in UPPERCASE. |
| 170 | + |
| 171 | +**No new IDs**: Inform user that the token already has all ledger IDs from Coinradar. |
| 172 | + |
| 173 | +**Null ledgerId**: Skip entries where `ledgerId` is null in the currencies array. |
| 174 | + |
| 175 | +**API rate limiting**: If processing many tokens, consider adding small delays between requests. |
| 176 | + |
| 177 | +**Large limit values**: Start with limit=50 for testing. Can go up to 1000 for full sync. |
| 178 | + |
| 179 | +## Important Notes |
| 180 | + |
| 181 | +- Token tickers in `_record.json` use UPPERCASE |
| 182 | +- Always preserve existing IDs from `_record.json` |
| 183 | +- Sort final list alphabetically for consistency |
| 184 | +- Maintain JSON formatting with 2-space indentation |
| 185 | +- The API endpoint is production: `api.coinradar.ledger.com` |
| 186 | +- All ledger IDs for the same `coinradarId` share the same icon (except L1/L2 exceptions) |
| 187 | +- The `image` field provides the direct URL to the token's icon |
| 188 | +- Skip any currency entries where `ledgerId` is null |
| 189 | +- Process tokens in order of their market cap rank |
| 190 | +- Consider fetching in batches (e.g., 50 at a time) for large syncs |
| 191 | + |
| 192 | +## Performance Tips |
| 193 | + |
| 194 | +- Start with small limits (50) for testing |
| 195 | +- For full sync, can use limit=1000 but will take longer |
| 196 | +- Show progress to user (e.g., "Processing token 10/50: USDC") |
| 197 | +- Batch write to `_record.json` at the end rather than per-token |
0 commit comments