# 获取订单簿 (Order book)

要使用此功能，您必须拥有 API 密钥。请阅读[**这里**](/chinese/developer/get-api-key.md)以了解如何获取我们的 API 密钥。

## 通过 API 密钥获取订单簿

<mark style="color:blue;">`GET`</mark> `https://api.tronsave.io/v2/order-book`

速率限制 (Rate limit): 每1秒15个请求。

#### Query Params

<table><thead><tr><th width="215">Name</th><th width="121">Type</th><th>Description</th></tr></thead><tbody><tr><td>address</td><td>String</td><td>能源接收地址</td></tr><tr><td>minDelegateAmount</td><td>number</td><td>从一个提供者委托的最低能源量。</td></tr><tr><td>durationSec</td><td>number</td><td>订单持续时间（秒）</td></tr><tr><td>resourceType</td><td>string</td><td>“ENERGY”或“BANDWIDTH”，默认： “ENERGY”</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "error": false,
    "message": "Success",
    "data": [
        {
            "price": number, // 价格（单位：SUN）
            "availableResourceAmount": number, // 此价格下可用的资源数量
        },
        {}
    ]
}

```

{% endtab %}
{% endtabs %}

**例子&#x20;*****(Example)***

**Query Params**

<table><thead><tr><th width="215">Key</th><th>Val</th></tr></thead><tbody><tr><td>address</td><td>TFwUFWr3QV376677Z8VWXxGUAMFSrq11111</td></tr><tr><td>minDelegateAmount</td><td>1000</td></tr><tr><td>durationSec</td><td>86400</td></tr><tr><td>resourceType</td><td>BANDWIDTH</td></tr></tbody></table>

{% tabs %}
{% tab title="Header" %}

```javascript
{
  "apikey": <YOUR_API_KEY>
}
```

{% endtab %}

{% tab title="Success Response" %}

```json
{
    "error": false,
    "message": "Success",
    "data": [
        {
            "price": 602,
            "availableResourceAmount": 1179
        },
        {
            "price": 650,
            "availableResourceAmount": 2409
        },
        {
            "price": 700,
            "availableResourceAmount": 5395
        },
        {
            "price": 701,
            "availableResourceAmount": 6613
        }
    ]
}
```

{% endtab %}
{% endtabs %}

*Example Code*

{% tabs %}
{% tab title="Javascript" %}

```javascript
const GetOrderBook = async (apiKey, receiverAddress) => {
    const url = `${TRONSAVE_API_URL}/v2/order-book?address=${receiverAddress}`
    const data = await fetch(url, {
        headers: {
            'apikey': apiKey
        }
    })
    const response = await data.json()
    /**
     * Example response 
    {
        error: false,
        message: 'Success',
        data: [
            { price: 54, availableResourceAmount: 2403704 },
            { price: 60, availableResourceAmount: 3438832 },
            { price: 61, availableResourceAmount: 4100301 },
            { price: 90, availableResourceAmount: 7082046 },
            { price: 91, availableResourceAmount: 7911978 }
        ]
    }
     */
    return response
}
```

{% endtab %}

{% tab title="PHP" %}

```php
function getOrderBook(): array {
    $url = TRONSAVE_API_URL . "/v2/order-book?address=" . RECEIVER_ADDRESS;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'apikey: ' . API_KEY
    ]);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}
```

{% endtab %}

{% tab title="Python" %}

```python
/def get_order_book() -> Dict[str, Any]:
    """Get order book for resources"""
    url = f"{TRONSAVE_API_URL}/v2/order-book"
    headers = {'apikey': API_KEY}
    params = {'address': RECEIVER_ADDRESS}
    
    response = requests.get(url, headers=headers, params=params)
    return response.json()
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tronsave.io/chinese/developer/buy-resources-v2/use-api-key/get-order-book.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
