# Estimate TRX

## Get an estimate of TRX

#### <mark style="color:orange;">`POST`</mark>  `https://api.tronsave.io/v2/estimate-buy-resource` <a href="#api-method" id="api-method"></a>

Rate limi&#x74;***: 15** requests per **1** second*

#### Request params <a href="#request-params" id="request-params"></a>

<table><thead><tr><th width="206.33333333333331">Field</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>resourceAmount<mark style="color:red;">*</mark></td><td>Number</td><td>The number of resources.</td></tr><tr><td>unitPrice</td><td>String, Number</td><td><p><strong>"FAST", "MEDIUM", "SLOW", or number</strong>:</p><p><br>-"FAST": If the market is ready to fill = 100%,  FAST = MEDIUM. If the market is ready to fill &#x3C; 100%,  FAST = MEDIUM + 10. If market ready to fill = 0%,  FAST = SLOW + 20.</p><p></p><p>-"MEDIUM":  The lowest price for the maximum market fill for this order. If market is ready to fill = 0%,  MEDIUM = SLOW + 10.</p><p></p><p>-"SLOW": The lowest price that can be set for this order.</p><p></p><p>-If the price is a number, the price unit is equal to SUN</p></td></tr><tr><td>durationSec</td><td>Number</td><td>The duration of the bought resource, time unit, is in seconds. Default 3d</td></tr><tr><td>requester</td><td>String</td><td>The address of requester.</td></tr><tr><td>receiver</td><td>String</td><td>The address of receiver resource.</td></tr><tr><td>resourceType</td><td>String</td><td>"ENERGY" or "BANDWIDTH", default: "ENERGY"</td></tr><tr><td>options</td><td>Object</td><td>optional</td></tr><tr><td>options.allowPartialFill</td><td>Boolean</td><td>Allow the order to be filled partially or not</td></tr><tr><td>options.minResourceDelegateRequiredAmount</td><td>Number</td><td>The minimum resource amount delegated by a single provider.</td></tr></tbody></table>

#### Request params example <a href="#request-params-example" id="request-params-example"></a>

```json
{
    "resourceType": "ENERGY",
    "receiver": "TFwUFWr3QV376677Z8VWXxGUAMF123456",
    "durationSec": 259200,
    "resourceAmount": 32000,
    "unitPrice": "MEDIUM",
    "options": {
        "allowPartialFill": true,
        "minResourceDelegateRequiredAmount": 32000
    }
}
```

#### Responses <a href="#responses" id="responses"></a>

```json
{
    "error": false,
    "message": "Success",
    "data": {
        "unitPrice": 64,
        "durationSec": 259200,
        "estimateTrx": 6144000,
        "availableResource": 32000
    }
}
```

***Example code***

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

```javascript
const GetEstimate = async (requestAddress, receiverAddress, resourceAmount, durationSec) => {
    const url = TRONSAVE_API_URL + "/v2/estimate-buy-resource";
    const body = {
        resourceAmount,
        unitPrice: "MEDIUM",
        resourceType: RESOURCE_TYPE,
        durationSec,
        requester: requestAddress,
        receiver: receiverAddress,
        options: {
            allowPartialFill: true,
        },
    };
    const data = await fetch(url, {
        method: "POST",
        headers: {
            "content-type": "application/json",
        },
        body: JSON.stringify(body),
    });
    const response = await data.json();
    /**
     * Example response 
   {
        "error": false,
        "message": 'Success',
        "data": {
            "unitPrice": 50,
            "durationSec": 259200,
            "estimateTrx": 7680000,
            "availableResource": 32000
        }
    }
     */
    return response;
};
```

{% endtab %}

{% tab title="PHP" %}

```php
function getEstimate(): array {
    $url = TRONSAVE_API_URL . "/v2/estimate-buy-resource";
    $body = [
        'resourceAmount' => BUY_AMOUNT,
        'unitPrice' => "MEDIUM",
        'resourceType' => RESOURCE_TYPE,
        'durationSec' => DURATION_SEC,
        'requester' => REQUEST_ADDRESS,
        'receiver' => RECEIVER_ADDRESS,
        'options' => [
            'allowPartialFill' => true,
        ]
    ];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json'
    ]);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}
```

{% endtab %}

{% tab title="Python" %}

```python
def get_estimate() -> Dict[str, Any]:
    """Get estimate for buying resource"""
    url = f"{TRONSAVE_API_URL}/v2/estimate-buy-resource"
    body = {
        'resourceAmount': BUY_AMOUNT,
        'unitPrice': "MEDIUM",
        'resourceType': RESOURCE_TYPE,
        'durationSec': DURATION_SEC,
        'requester': REQUEST_ADDRESS,
        'receiver': RECEIVER_ADDRESS,
        'options': {
            'allowPartialFill': True,
        }
    }
    
    response = requests.post(url, json=body)
    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/developer/buy-resources-v2/use-signed-transaction/estimate-trx.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.
