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

# 搜索

> 搜索市場和事件

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

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

搜索端點允許搜索市場、事件和用戶。

## 端點

```
GET https://gamma-api.polymarket.com/search
```

## 請求參數

| 參數      | 類型     | 描述                           |
| ------- | ------ | ---------------------------- |
| `q`     | string | 搜索關鍵詞                        |
| `type`  | string | 搜索類型（markets, events, users） |
| `limit` | number | 返回數量                         |

## 請求示例

### 搜索市場

```python theme={null}
import requests

query = "Trump"
response = requests.get(
    'https://gamma-api.polymarket.com/search',
    params={
        'q': query,
        'type': 'markets',
        'limit': 10
    }
)

results = response.json()
for market in results['markets']:
    print(f"市場: {market['question']}")
    print(f"相關度: {market['score']}")
```

### 搜索事件

```python theme={null}
response = requests.get(
    'https://gamma-api.polymarket.com/search',
    params={
        'q': 'election',
        'type': 'events'
    }
)
```

## 響應示例

```json theme={null}
{
  "markets": [
    {
      "id": "123",
      "question": "川普會贏得 2024 年大選嗎？",
      "score": 0.95,
      "volume": "1000000.00"
    }
  ],
  "events": [
    {
      "id": "456",
      "title": "2024 年美國總統大選",
      "score": 0.90
    }
  ],
  "total_count": 15
}
```

## 高級搜索

### 模糊搜索

```python theme={null}
# 搜索包含關鍵詞的市場
results = requests.get(
    'https://gamma-api.polymarket.com/search',
    params={
        'q': 'bitcoin price',
        'type': 'markets'
    }
).json()
```

### 按相關度排序

搜索結果默認按相關度（score）排序，score 越高越相關。

## TypeScript 示例

```typescript theme={null}
interface SearchResult {
  markets: Market[];
  events: Event[];
  total_count: number;
}

async function searchMarkets(query: string): Promise<SearchResult> {
  const response = await fetch(
    `https://gamma-api.polymarket.com/search?q=${encodeURIComponent(query)}&type=markets`
  );
  return await response.json();
}

// 使用
const results = await searchMarkets('election 2024');
console.log(`找到 ${results.total_count} 個結果`);
```
