Skip to content

池子统计接口文档(直方图) ​

接口信息 ​

项目说明
接口路径/api/v1/dex/histogram
请求方法POST
代理路径/serverproxy/api/v1/dex/histogram
后端服务https://api.dev.topo.club
认证方式Authorization: ApiKey <key>

接口返回指定时间范围内的交易量或 TVL 统计直方图数据,用于首页折线图、池子统计展示等场景。

请求参数 ​

Request Body 参数 ​

参数名类型必填说明
network_idstring是网络标识,前端自动注入。topo--164 或 aptos--2
data_typestring是统计类型:vol(交易量)或 tvl(总锁仓量)
date_typestring是时间粒度:hour(小时)、day(天)、week(周)、month(月)
begin_timestampnumber否起始时间戳(秒),不传则由后端自动推算

请求示例 ​

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_typestring统计类型(vol 或 tvl)
network_idstring网络标识
date_typestring时间粒度
begin_timestampnumber起始时间戳(秒)
bucketsarray时间桶数组
buckets[].timestampnumber桶起始时间(秒)
buckets[].valuestring该桶统计值(美元,字符串格式)
buckets[].pool_countnumber该桶内有效池子数量(仅 TVL 有)
totalstring最新统计总值
countnumber返回的桶数量

前端调用示例 ​

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

注意事项 ​

  1. network_id 由前端 request() 自动注入到 POST body,无需手动传入
  2. buckets[].value 为字符串格式数字,前端展示时需格式化
  3. date_type = 'hour' 时建议结合 begin_timestamp 控制范围,避免数据量过大