> ## Documentation Index
> Fetch the complete documentation index at: https://polymarketcn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Data API 雜項端點

> 其他有用的 Data API 端點

<Callout type="success">
  還沒有帳號？[點擊這裡註冊 Polymarket](https://polymarket.com/?r=2026VIP) 並完成入金，才能用錢包私鑰為訂單籤名、實際成交。
</Callout>

<Warning>
  **法律合規提醒**：在使用 Polymarket 服務或 API 前，請確認您所在地區的法律規定。Polymarket 目前不支援比利時、法國、新加坡、泰國、中國大陸等地區，政策可能隨時變化。
</Warning>

Data API 提供了一些額外的端點用於獲取各種數據。

## 市場統計

### 端點

```
GET https://data-api.polymarket.com/stats
```

### 響應示例

```json theme={null}
{
  "total_markets": 5000,
  "active_markets": 1200,
  "total_volume": "500000000.00",
  "total_traders": 50000,
  "24h_volume": "5000000.00"
}
```

### Python 示例

```python theme={null}
import requests

response = requests.get('https://data-api.polymarket.com/stats')
stats = response.json()

print(f"總市場數: {stats['total_markets']}")
print(f"總交易量: ${stats['total_volume']}")
print(f"24小時交易量: ${stats['24h_volume']}")
```

## 趨勢市場

### 端點

```
GET https://data-api.polymarket.com/trending
```

### 請求參數

| 參數          | 類型     | 描述                 |
| ----------- | ------ | ------------------ |
| `timeframe` | string | 時間範圍（24h, 7d, 30d） |
| `limit`     | number | 返回數量               |

### 示例

```python theme={null}
response = requests.get(
    'https://data-api.polymarket.com/trending',
    params={
        'timeframe': '24h',
        'limit': 10
    }
)

trending = response.json()
for market in trending:
    print(f"市場: {market['question']}")
    print(f"24h 交易量: ${market['volume_24h']}")
```

## 價格歷史

### 端點

```
GET https://data-api.polymarket.com/prices/{token_id}
```

### 請求參數

| 參數           | 類型     | 描述           |
| ------------ | ------ | ------------ |
| `start_time` | number | 開始時間戳        |
| `end_time`   | number | 結束時間戳        |
| `interval`   | string | 時間間隔（1h, 1d） |

### 示例

```python theme={null}
import time

token_id = "0xabc123..."
start_time = int(time.time()) - 7 * 24 * 3600  # 7天前
end_time = int(time.time())

response = requests.get(
    f'https://data-api.polymarket.com/prices/{token_id}',
    params={
        'start_time': start_time,
        'end_time': end_time,
        'interval': '1h'
    }
)

prices = response.json()
for price_point in prices:
    print(f"時間: {price_point['timestamp']}")
    print(f"價格: {price_point['price']}")
```

## 排行榜

### 端點

```
GET https://data-api.polymarket.com/leaderboard
```

### 請求參數

| 參數          | 類型     | 描述                           |
| ----------- | ------ | ---------------------------- |
| `metric`    | string | 排序指標（volume, pnl, win\_rate） |
| `timeframe` | string | 時間範圍（all, 30d, 7d）           |
| `limit`     | number | 返回數量                         |

### 示例

```python theme={null}
response = requests.get(
    'https://data-api.polymarket.com/leaderboard',
    params={
        'metric': 'pnl',
        'timeframe': '30d',
        'limit': 100
    }
)

leaderboard = response.json()
for rank, user in enumerate(leaderboard, 1):
    print(f"#{rank} {user['username']}")
    print(f"  盈虧: ${user['pnl']}")
    print(f"  交易量: ${user['volume']}")
```

## 市場分析

### 端點

```
GET https://data-api.polymarket.com/analysis/{market_id}
```

### 響應示例

```json theme={null}
{
  "market_id": "123",
  "question": "...",
  "metrics": {
    "avg_position_size": "100.00",
    "unique_traders": 500,
    "maker_taker_ratio": "0.6",
    "bid_ask_spread": "0.02"
  },
  "price_stats": {
    "high_24h": "0.65",
    "low_24h": "0.55",
    "volatility": "0.15"
  }
}
```

## 事件通知

### 端點

```
GET https://data-api.polymarket.com/notifications
```

需要認證。返回用戶相關的通知：

* 市場結算通知
* 持倉變化提醒
* 價格警報

### 示例

```python theme={null}
headers = {'Authorization': 'Bearer YOUR_TOKEN'}

response = requests.get(
    'https://data-api.polymarket.com/notifications',
    headers=headers
)

notifications = response.json()
for notif in notifications:
    print(f"類型: {notif['type']}")
    print(f"消息: {notif['message']}")
    print(f"時間: {notif['timestamp']}")
```

## 導出數據

### 端點

```
GET https://data-api.polymarket.com/export
```

導出用戶的交易歷史（CSV 格式）。

### 示例

```python theme={null}
response = requests.get(
    'https://data-api.polymarket.com/export',
    headers={'Authorization': 'Bearer YOUR_TOKEN'},
    params={
        'format': 'csv',
        'start_date': '2024-01-01',
        'end_date': '2024-12-31'
    }
)

# 保存 CSV
with open('trades.csv', 'w') as f:
    f.write(response.text)
```

## 下一步

<CardGroup cols={2}>
  <Card title="Core API" icon="database" href="/api-tutorial/data-api/core">
    核心數據端點
  </Card>

  <Card title="Builders API" icon="users" href="/api-tutorial/data-api/builders">
    構建者數據
  </Card>

  <Card title="Gamma API" icon="chart-line" href="/api-tutorial/gamma-structure/overview">
    Gamma 市場數據
  </Card>

  <Card title="CLOB API" icon="code" href="/api-tutorial/clob/introduction">
    交易 API
  </Card>
</CardGroup>
