xtraderClient/docs/api/cryptoChart.md

36 lines
1.4 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.

# cryptoChart.ts
**路径**`src/api/cryptoChart.ts`
## 功能用途
加密货币价格走势图 API使用 **Binance REST + WebSocket** 实现细粒度1 分钟)实时走势。当事件类型为加密货币时,详情页可切换显示 YES/NO 分时走势图与加密货币实时价格走势图。
## 核心能力
- `isCryptoEvent`:判断事件是否为加密货币类型(通过 tags/series slug、ticker
- `inferCryptoSymbol`从事件信息推断币种符号btc、eth 等)
- `fetchCryptoChart`:从 Binance 获取 1 分钟 K 线历史(优先),不支持时回退 CoinGecko
- `subscribeCryptoRealtime`:订阅 Binance K 线 WebSocket约每 250ms 推送,实现走势图实时更新
## 币种映射
`COINGECKO_COIN_IDS` 支持btc、eth、sol、bnb、xrp、doge、ada、avax、matic、dot、link、uni、atom、ltc、near、apt、arb、op、inj、sui、pepe、wif、shib 等。
## 使用方式
```typescript
import { isCryptoEvent, inferCryptoSymbol, fetchCryptoChart } from '@/api/cryptoChart'
if (isCryptoEvent(eventDetail)) {
const symbol = inferCryptoSymbol(eventDetail) ?? 'btc'
const res = await fetchCryptoChart({ symbol, range: '1D' })
const points = res.data ?? []
}
```
## 扩展方式
- 新增币种:在 `COINGECKO_COIN_IDS` 中追加映射
- 更换数据源:修改 `fetchCryptoChart` 内部实现,或通过后端代理 CoinGecko 以规避 CORS