77 lines
2.9 KiB
Markdown
77 lines
2.9 KiB
Markdown
# priceHistory.ts
|
||
|
||
**路径**:`src/api/priceHistory.ts`
|
||
|
||
## 功能用途
|
||
|
||
价格历史公开接口,用于 TradeDetail 页面的 Yes/No 折线图。对接 **GET /pmPriceHistory/getPmPriceHistoryPublic**(无需鉴权)。
|
||
|
||
## 核心能力
|
||
|
||
- `getPmPriceHistoryPublic`:按市场 ID 分页获取价格历史
|
||
- `getTimeRangeSeconds`:根据分时范围计算 `startTs`、`endTs`(Unix 秒);`endTs` 始终为当前时间;1H/6H/1D/1W/1M 的 `startTs` 为当前时间往前对应时长;ALL 的 `startTs` 为事件开始时间、`endTs` 为当前时间
|
||
- `priceHistoryToChartData`:将接口返回的 `list` 转为 ECharts 使用的 `[timestamp_ms, value_0_100][]`
|
||
|
||
## GET /pmPriceHistory/getPmPriceHistoryPublic
|
||
|
||
### 请求参数(Query)
|
||
|
||
| 参数 | 类型 | 必填 | 说明 |
|
||
|------|------|------|------|
|
||
| market | string | 是 | 传 YES 对应的 clobTokenId(即当前市场 clobTokenIds[0]) |
|
||
| page | number | 否 | 页码,默认 1 |
|
||
| pageSize | number | 否 | 每页条数,默认 500 |
|
||
| startTs | number | 否 | 时间范围起始(Unix 秒) |
|
||
| endTs | number | 否 | 时间范围结束(Unix 秒) |
|
||
| interval | string | 否 | 数据间隔 |
|
||
| time | number | 否 | 时间筛选 |
|
||
| createdAtRange | string[] | 否 | 创建时间范围 |
|
||
| fidelity | number | 否 | 数据精度 |
|
||
| keyword | string | 否 | 关键字 |
|
||
| order | string | 否 | 排序 |
|
||
| sort | string | 否 | 排序字段 |
|
||
| price | number | 否 | 价格筛选 |
|
||
|
||
### 响应
|
||
|
||
`{ code, data, msg }`,`data` 为 `PageResult<PmPriceHistoryItem>`(`list`、`page`、`pageSize`、`total`)。
|
||
|
||
### PmPriceHistoryItem(list 单项)
|
||
|
||
| 字段 | 类型 | 说明 |
|
||
|------|------|------|
|
||
| ID | number | 主键 |
|
||
| market | string | 市场标识 |
|
||
| price | number | 价格(0–1 小数或 0–100,由 priceHistoryToChartData 统一为 0–100) |
|
||
| time | number | Unix 秒时间戳 |
|
||
| interval | string | 数据间隔 |
|
||
| fidelity | number | 数据精度 |
|
||
| createdAt | string | 创建时间 |
|
||
| updatedAt | string | 更新时间 |
|
||
|
||
## 使用方式
|
||
|
||
```typescript
|
||
import {
|
||
getPmPriceHistoryPublic,
|
||
priceHistoryToChartData,
|
||
getTimeRangeSeconds,
|
||
type PmPriceHistoryItem,
|
||
} from '@/api/priceHistory'
|
||
|
||
const timeRange = getTimeRangeSeconds('1D') // { startTs, endTs }
|
||
// ALL 时传 eventDates:getTimeRangeSeconds('ALL', { startDate: ev.startDate, endDate: ev.endDate })
|
||
const res = await getPmPriceHistoryPublic({
|
||
market: marketId,
|
||
page: 1,
|
||
pageSize: 500,
|
||
...(timeRange && { startTs: timeRange.startTs, endTs: timeRange.endTs }),
|
||
})
|
||
const chartData = priceHistoryToChartData(res.data?.list ?? [])
|
||
```
|
||
|
||
## 扩展方式
|
||
|
||
- 时间戳规则:`endTs` 始终为当前时间;1H/6H/1D/1W/1M 的 `startTs` 为当前时间往前对应时长;ALL 的 `startTs` 为事件 `startDate`,`endTs` 为当前时间
|
||
- 若后端返回的 `price` 固定为 0–100,`priceHistoryToChartData` 已兼容(≤1 时乘 100)
|