Appearance
池子统计接口文档(直方图)
接口信息
| 项目 | 说明 |
|---|---|
| 接口路径 | /api/v1/dex/histogram |
| 请求方法 | POST |
| 代理路径 | /serverproxy/api/v1/dex/histogram |
| 后端服务 | https://api.dev.topo.club |
| 认证方式 | Authorization: ApiKey <key> |
接口返回指定时间范围内的交易量或 TVL 统计直方图数据,用于首页折线图、池子统计展示等场景。
请求参数
Request Body 参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| network_id | string | 是 | 网络标识,前端自动注入。topo--164 或 aptos--2 |
| data_type | string | 是 | 统计类型:vol(交易量)或 tvl(总锁仓量) |
| date_type | string | 是 | 时间粒度:hour(小时)、day(天)、week(周)、month(月) |
| begin_timestamp | number | 否 | 起始时间戳(秒),不传则由后端自动推算 |
请求示例
bash
POST /serverproxy/api/v1/dex/histogram
Content-Type: application/json
Authorization: ApiKey <key>
{
"network_id": "topo--164",
"data_type": "tvl",
"date_type": "day",
"begin_timestamp": 1740000000
}响应数据结构
json
{
"code": 0,
"message": "Success",
"data": {
"data_type": "tvl",
"network_id": "topo--164",
"date_type": "day",
"begin_timestamp": 1740000000,
"buckets": [
{
"timestamp": 1740000000,
"value": "5200000.00",
"pool_count": 128
},
{
"timestamp": 1740086400,
"value": "5350000.00",
"pool_count": 130
}
],
"total": "5350000.00",
"count": 30
},
"timestamp": 1745380000
}响应字段说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| data_type | string | 统计类型(vol 或 tvl) |
| network_id | string | 网络标识 |
| date_type | string | 时间粒度 |
| begin_timestamp | number | 起始时间戳(秒) |
| buckets | array | 时间桶数组 |
| buckets[].timestamp | number | 桶起始时间(秒) |
| buckets[].value | string | 该桶统计值(美元,字符串格式) |
| buckets[].pool_count | number | 该桶内有效池子数量(仅 TVL 有) |
| total | string | 最新统计总值 |
| count | number | 返回的桶数量 |
前端调用示例
typescript
import { fetchDexHistogram } from '@/lib/request/api'
// TVL 日线统计(最近 30 天)
const result = await fetchDexHistogram({
data_type: 'tvl',
date_type: 'day',
begin_timestamp: Math.floor(Date.now() / 1000) - 30 * 86400,
})
// 交易量周线统计
const volResult = await fetchDexHistogram({
data_type: 'vol',
date_type: 'week',
})对应 Hook:apps/web/hooks/use-histogram.ts
注意事项
network_id由前端request()自动注入到 POST body,无需手动传入buckets[].value为字符串格式数字,前端展示时需格式化date_type = 'hour'时建议结合begin_timestamp控制范围,避免数据量过大