xtraderClient/docs/api/priceHistory.md
2026-03-15 21:08:51 +08:00

70 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# priceHistory.ts
**路径**`src/api/priceHistory.ts`
## 功能用途
价格历史公开接口,用于 TradeDetail 页面的 Yes/No 折线图。对接 **GET /pmPriceHistory/getPmPriceHistoryPublic**(无需鉴权)。
## 核心能力
- `getPmPriceHistoryPublic`:按市场 ID 分页获取价格历史
- `priceHistoryToChartData`:将接口返回的 `list` 转为 ECharts 使用的 `[timestamp_ms, value_0_100][]`
## GET /pmPriceHistory/getPmPriceHistoryPublic
### 请求参数Query
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| market | string | 是 | 传 YES 对应的 clobTokenId即当前市场 clobTokenIds[0] |
| page | number | 否 | 页码,默认 1 |
| pageSize | number | 否 | 每页条数,默认 500 |
| 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`)。
### PmPriceHistoryItemlist 单项)
| 字段 | 类型 | 说明 |
|------|------|------|
| ID | number | 主键 |
| market | string | 市场标识 |
| price | number | 价格01 小数或 0100由 priceHistoryToChartData 统一为 0100 |
| time | number | Unix 秒时间戳 |
| interval | string | 数据间隔 |
| fidelity | number | 数据精度 |
| createdAt | string | 创建时间 |
| updatedAt | string | 更新时间 |
## 使用方式
```typescript
import {
getPmPriceHistoryPublic,
priceHistoryToChartData,
type PmPriceHistoryItem,
} from '@/api/priceHistory'
const res = await getPmPriceHistoryPublic({
market: marketId,
page: 1,
pageSize: 500,
})
const chartData = priceHistoryToChartData(res.data?.list ?? [])
```
## 扩展方式
- 按时间范围1H/6H/1D 等)传 `interval``createdAtRange` 需与后端约定取值
- 若后端返回的 `price` 固定为 0100`priceHistoryToChartData` 已兼容≤1 时乘 100