# Get Internal Account Order History

To use this feature, you must have the API key. Read [here](/developer/get-api-key.md) to view how to get our API key

## Get order history by API key

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

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

Get many orders sorted by creation time. Default: return 10 newest orders

#### Query Parameters

<table><thead><tr><th width="200">Name</th><th width="156">Type</th><th>Description</th></tr></thead><tbody><tr><td>page</td><td>Integer</td><td>start from 0. Default:0</td></tr><tr><td>pageSize</td><td>Integer</td><td>default: 10</td></tr><tr><td>status</td><td>String</td><td>"Active" or "Completed", default get all</td></tr></tbody></table>

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

```json
{
    "error": false,
    "message": "Success",
    "data": {
        "id":  string, // id of order
        "requester": string, // the address represents the order owner
        "receiver": string, // the address of the resource that is received 
        "resourceAmount": number, // the amount of resource
        "resourceType": string, // the resource type is "ENERGY" or "BANDWIDTH"
        "remainAmount": number, // the remaining amount can be matched by the system,
        "price": number, // price unit is equal to SUN
        "durationSec": number, // rent duration, duration unit is equal to seconds
        "status": string, // the order status, either Active or Completed
        "orderType": string, // type of order is "NORMAL" or "EXTEND"
        "allowPartialFill": boolean, //Allow the order to be filled partially or not
        "payoutAmount": number, // Total payout of this order
        "fulfilledPercent": number, //The percent that shows filling processing. 0-100
        "delegates": [ //All matched delegates for this order
            {
                "delegator": string, // The address that delegates the resource for the target address
                "amount": number, //The amount of resource was delegated
                "txid": number // The transaction ID in on-chain
             }[]
       } 
    }[],
        "total": number
}
```

{% endtab %}
{% endtabs %}

*Example*&#x20;

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

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

{% endtab %}

{% tab title="Success Response" %}

```json
{
    "error": false,
    "message": "Success",
    "data": {
        "data": [
            {
                "id": "6819c7578729a45600f740d3",
                "requester": "TFwUFWr3QV376677Z8VWXxGUAMFSSSSSS",
                "receiver": "TFwUFWr3QV376677Z8VWXxGUAMFSSSSSS",
                "resourceAmount": 32000,
                "resourceType": "ENERGY",
                "remainAmount": 0,
                "orderType": "NORMAL",
                "price": 90,
                "durationSec": 300,
                "allowPartialFill": false,
                "payoutAmount": 2880000,
                "fulfilledPercent": 100,
                "delegates": [
                    {
                        "delegator": "THnnMCe67VMDXoivepiA7ZQSB8888888",
                        "amount": 32000,
                        "txid": "transaction_id_1"
                    }
                ]
            },
            {
                "id": "68198bcd8729a45600f740cf",
                "requester": "TFwUFWr3QV376677Z8VWXxGUAMFSSSSSS",
                "receiver": "TFwUFWr3QV376677Z8VWXxGUAMFSSSSSS",
                "resourceAmount": 1234,
                "resourceType": "BANDWIDTH",
                "remainAmount": 0,
                "orderType": "NORMAL",
                "price": 600,
                "durationSec": 900,
                "allowPartialFill": false,
                "payoutAmount": 740400,
                "fulfilledPercent": 100,
                "delegates": [
                    {
                        "delegator": "TMhiksDwSVjuxdXLwdNQEJpuFCLG77777",
                        "amount": 1234,
                        "txid": "transaction_id_2"
                    }
                ]
            }
        ],
        "total": 2
    }
}
```

{% endtab %}
{% endtabs %}

*Example Code*

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

```javascript
const GetOrderHistory = async (apiKey) => {
    const url = `${TRONSAVE_API_URL}/v2/orders`
    const data = await fetch(url, {
        headers: {
            'apikey': apiKey
        }
    })
    const response = await data.json()
     /**
     * Example response 
        {
            "error": false,
            "message": "Success",
            "data": 
            {
                "total": 2,
                "data": [
                    {
                        "id": "6809b08a14b1cb7c5d195d66",
                        "requester": "TTgMEAhuzPchDAL4pnm2tCNmqXp13AxzAd",
                        "receiver": "TFwUFWr3QV376677Z8VWXxGUAMFSrq1MbM",
                        "resourceAmount": 40000,
                        "resourceType": "ENERGY",
                        "remainAmount": 0,
                        "orderType": "NORMAL",
                        "price": 81.5,
                        "durationSec": 900,
                        "allowPartialFill": false,
                        "payoutAmount": 3260000,
                        "fulfilledPercent": 100,
                        "delegates": [
                            {
                                "delegator": "THnnMCe67VMDXoivepiA7ZQSB8jbgKDodf",
                                "amount": 40000,
                                "txid": "19be98d0183b29575d74999a93154b09b3c7d05051cdbd52c667cd9f0b3cc9b0"
                            }
                        ]
                    },
                    {
                        "id": "6809aaf2e2e17d3c588b467a",
                        "requester": "TTgMEAhuzPchDAL4pnm2tCNmqXp13AxzAd",
                        "receiver": "TFwUFWr3QV376677Z8VWXxGUAMFSrq1MbM",
                        "resourceAmount": 40000,
                        "resourceType": "ENERGY",
                        "remainAmount": 0,
                        "orderType": "NORMAL",
                        "price": 81.5,
                        "durationSec": 900,
                        "allowPartialFill": false,
                        "payoutAmount": 3260000,
                        "fulfilledPercent": 100,
                        "delegates": [
                            {
                                "delegator": "THnnMCe67VMDXoivepiA7ZQSB8jbgKDodf",
                                "amount": 40000,
                                "txid": "447e3fb28ad7580554642d08b9a6b220bc86f667b47edad47f16802594b6b1e3"
                            }
                        ]
                    },
                ]
            }
        }
     */
    return response
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

/**
 * Get order history from the TRONSAVE API
 * 
 * @param string $apiKey API key for authentication
 * @return array{
 *     error: bool,
 *     message: string,
 *     data: array{
 *         total: int,
 *         data: array<array{
 *             id: string,
 *             requester: string,
 *             receiver: string,
 *             resourceAmount: int,
 *             resourceType: string,
 *             remainAmount: int,
 *             orderType: string,
 *             price: float,
 *             durationSec: int,
 *             allowPartialFill: bool,
 *             payoutAmount: int,
 *             fulfilledPercent: int,
 *             delegates: array<array{
 *                 delegator: string,
 *                 amount: int,
 *                 txid: string
 *             }>
 *         }>
 *     }
 * }
 * @throws Exception If API request fails
 */
function getOrderHistory(string $apiKey): array
{
    $url = TRONSAVE_API_URL . "/v2/orders";
    
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'apikey: ' . $apiKey
        ]
    ]);

    $response = curl_exec($ch);
    
    if (curl_errno($ch)) {
        throw new Exception('Curl error: ' . curl_error($ch));
    }
    
    curl_close($ch);
    
    $result = json_decode($response, true);
    
    if (json_last_error() !== JSON_ERROR_NONE) {
        throw new Exception('JSON decode error: ' . json_last_error_msg());
    }
    
    return $result;
}

// Example usage:
try {
    $apiKey = 'your-api-key';
    $orderHistory = getOrderHistory($apiKey);
    
    // Print total orders
    echo "Total orders: " . $orderHistory['data']['total'] . "\n";
    
    // Print each order detail
    foreach ($orderHistory['data']['data'] as $order) {
        echo "Order ID: " . $order['id'] . "\n";
        echo "Resource Amount: " . $order['resourceAmount'] . "\n";
        echo "Resource Type: " . $order['resourceType'] . "\n";
        echo "Price: " . $order['price'] . "\n";
        echo "Fulfilled: " . $order['fulfilledPercent'] . "%\n";
        echo "-------------------\n";
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
```

{% endtab %}

{% tab title="Python" %}

```python
def get_order_history(api_key: str) -> dict:
    """Get order history from the TRONSAVE API"""
    url = "https://api.tronsave.io/v2/orders"
    response = requests.get(url, headers={'apikey': api_key})
    return response.json()

# Example usage
api_key = 'your-api-key'
result = get_order_history(api_key)

# Print results
if not result.get('error'):
    for order in result['data']['data']:
        print(f"Order ID: {order['id']}")
        print(f"Amount: {order['resourceAmount']}")
        print(f"Price: {order['price']}")
        print(f"Fulfilled: {order['fulfilledPercent']}%")
        print("-------------------")
```

{% 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-api-key/get-internal-account-order-history.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.
