# GET /v1/fx

用于货币换算的当前 USD 基准汇率。

返回当前的 USD 基准汇率。当你请求 USD 以外的[货币](/zh-cn/docs/using-the-api#货币)时，最新价格按这些汇率换算。汇率约每小时更新一次。

## 访问

适用于所有套餐。

## 请求

`GET https://api.cs2.sh/v1/fx`

**curl**

```bash
curl https://api.cs2.sh/v1/fx \
  -H "Authorization: Bearer <<YOUR_API_KEY>>" \
  -H "Accept-Encoding: gzip" --compressed
```

**Python**

```python
import requests

headers = {
    "Authorization": "Bearer <<YOUR_API_KEY>>",
    "Accept-Encoding": "gzip",
}

response = requests.get(
    "https://api.cs2.sh/v1/fx",
    headers=headers,
)

response.raise_for_status()
data = response.json()
```

**Node**

```javascript
const headers = {
  "Authorization": "Bearer <<YOUR_API_KEY>>",
  "Accept-Encoding": "gzip",
};

const response = await fetch("https://api.cs2.sh/v1/fx", { headers });

if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
```

**Go**

```go
package main

import (
    "compress/gzip"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    req, _ := http.NewRequest("GET", "https://api.cs2.sh/v1/fx", nil)
    req.Header.Set("Authorization", "Bearer <<YOUR_API_KEY>>")
    req.Header.Set("Accept-Encoding", "gzip")

    resp, err := http.DefaultClient.Do(req)
    if err != nil { panic(err) }
    defer resp.Body.Close()

    if resp.StatusCode < 200 || resp.StatusCode >= 300 {
        body, _ := io.ReadAll(resp.Body)
        panic(fmt.Sprintf("HTTP %d: %s", resp.StatusCode, body))
    }

    var reader io.Reader = resp.Body
    if resp.Header.Get("Content-Encoding") == "gzip" {
        gz, err := gzip.NewReader(resp.Body)
        if err != nil { panic(err) }
        defer gz.Close()
        reader = gz
    }

    var data any
    if err := json.NewDecoder(reader).Decode(&data); err != nil { panic(err) }
    fmt.Printf("%#v\n", data)
}
```

**R**

```r
library(httr2)

resp <- request("https://api.cs2.sh/v1/fx") |>
  req_headers(
    Authorization = "Bearer <<YOUR_API_KEY>>",
    `Accept-Encoding` = "gzip"
  ) |>
  req_perform()

data <- resp_body_json(resp)
```

## 响应

```json
{
  "base": "USD",
  "updated_at": "2026-09-22T23:00:02Z",
  "collected_at": "2026-09-22T23:00:54.577Z",
  "fresh": true,
  "rates": {
    "AUD": 1.40622087,
    "CAD": 1.40543053,
    "CHF": 0.82058071,
    "CNY": 6.71350215,
    "EUR": 0.87319354,
    "GBP": 0.74932836,
    "JPY": 157.40767305,
    "NZD": 1.74524572,
    "SGD": 1.27536852,
    "USD": 1
  }
}
```

## 响应字段

[FXResponse](/zh-cn/docs/objects#fxresponse) 字段:

| 字段 | 类型 | 必需 | 描述 |
| --- | --- | --- | --- |
| `base` | `string` | 是 | 基准货币（始终为 `USD`）。 |
| `updated_at` | `string (date-time)` | 是 | 汇率提供方发布这些汇率的时间。 |
| `collected_at` | `string (date-time)` | 是 | cs2.sh 采集这些汇率的时间。 |
| `fresh` | `boolean` | 是 | 汇率超过 2 小时时为 `false`。最新价格换算在最长 24 小时内仍会继续使用这些汇率。 |
| `rates` | `Record<string, number>` | 是 | 每 1 USD 可兑换的各货币数量，以货币代码为键。 |

## 错误

`400 validation_error` 表示请求包含查询参数。`503 service_unavailable` 表示汇率不可用。共有错误见[请求错误](/zh-cn/docs/using-the-api#请求错误)。
