分页与数据处理
使用交互式参考检查响应并试读一页。本指南介绍如何继续读取后续结果。
查找合作伙伴的预售
跳转到“查找合作伙伴的预售”将 partner_id 设为链上合作伙伴对象 ID,不是 API 密钥账户名或钱包地址。过滤先于排序和分页执行。若无匹配预售,返回 200、空数组及 null 游标。
下面的服务端 JavaScript 示例遍历全部进行中的预售。在后端环境设置 BLAST_PARTNER_KEY 和 BLAST_PARTNER_ID。
const key = process.env.BLAST_PARTNER_KEY;const partnerId = process.env.BLAST_PARTNER_ID;if (!key || !/^0x[0-9a-f]{64}$/.test(partnerId ?? '')) { throw new Error('Configure a partner key and canonical partner object ID.');}
const query = new URLSearchParams({ partner_id: partnerId, status: 'live', sort: 'ending', limit: '50',});const sales = new Map();const visited = new Set();
for (;;) { const response = await fetch( `https://www.blast.fun/api/v1/presales?${query}`, { headers: { 'X-Blast-Partner-Key': key }, signal: AbortSignal.timeout(15000) }, ); if (!response.ok) { // Honor Retry-After for 429/503 in your job scheduler. Do not loop here. throw new Error(`Blast HTTP ${response.status}; retry-after=${response.headers.get('retry-after')}`); } const page = await response.json(); for (const sale of page.presales) sales.set(sale.presale_id, sale); if (page.next_cursor === null) break; if (visited.has(page.next_cursor)) throw new Error('Repeated pagination cursor.'); visited.add(page.next_cursor); query.set('cursor', page.next_cursor);}
console.log([...sales.values()]);分页时保持 status、sort、partner_id、verified_team 和 audited 不变。将游标视为不透明令牌。新活动被索引后,结果可能变化;收集多页时按 ID 去重。分页不是整个数据集的冻结快照。
使用正确的游标
跳转到“使用正确的游标”| 端点 | 从响应读取 | 下次请求发送 | 停止条件 |
|---|---|---|---|
| 预售 | next_cursor |
cursor |
游标为 null |
| 发现 | section.data.nextCursor |
cursor,保持相同 view |
游标为 null 或分区为空 |
| 搜索 | 对应分组的 section.data.nextCursor |
cursor,保持相同 group 和 q |
游标为 null 或分区为空 |
| 持币人 | next_cursor |
cursor,保持相同币种和视图 |
游标为 null;不完整数据属于不可用 |
| 发行活动 | next_cursor |
cursor,保持相同发行项目和视图 |
游标为 null |
| 池 K 线 | 最早的 bucket_start |
to |
K 线数组为空 |
| 池成交记录 | 最后一行的 cursor |
before |
成交数组为空或到达归档边界 |
保留精度与单位
跳转到“保留精度与单位”以 _atoms 结尾的金额、行情储备量和行情成交量,均为以代币最小单位计的十进制字符串。整数运算用 BigInt,价格用十进制运算库。将大额余额转为 JavaScript Number 会损失精度。
- 社交价格历史: 价格为每整枚代币的美元价格,数据点是
[timestamp_ms, decimal_price_string]。 - 行情池及 K 线价格: 每个 meme 原子单位对应的 quote 原子单位。用十进制运算乘以
10^(meme_decimals − quote_decimals),转换为每整枚 meme 代币对应的 quote 代币数量。 - 基点: 10,000 表示 100%。请查字段模式,有些端点使用 JSON 整数,有些使用十进制字符串。
- 时间: 标为
_ms或Ms的时间戳使用 Unix 毫秒。时长不是时间戳。publish_time等特定字段使用 Unix 秒,模式中有说明。
空、缺失和过时并不相同
跳转到“空、缺失和过时并不相同”[] 表示读取成功但无匹配项。null 表示具体事实不可用或不适用,不要默默转换成零。省略可选字段也不同于必填字段值为 null。
发现与搜索提供 available、stale、empty 和 unavailable 分区。只有 available 和 stale 携带数据。搜索可在某一分组不可用时仍返回 200。不完整的持币人快照中事实值为 null,不代表持币人数为零。
在将数据展示为当前状态前,请检查 as_of 或 provenance。若缓存响应,应保留索引时间并遵守返回的缓存政策。重试策略见限流与错误。