# Comtrade Historical Data

> Use the following API endpoints to obtain COMTRADE historical data.

Source: https://docs.tradingeconomics.com/comtrade/historical/

The historical endpoint contains a time series with an indicator identifier, the reference date and the observed value. It allows one to check the evolution of key indicators over time.

**PYTHON**
*Using Requests:*
```python
import requests
your_api_key = 'your_api_key'
url = f'https://api.tradingeconomics.com/comtrade/historical/PRTESP24031,NORZWEXX991?c={your_api_key}'
data = requests.get(url).json()
print(data)
```

*Or using our package:*
```python
import tradingeconomics as te
te.login('your_api_key')
te.getCmtHistorical(symbol = 'PRTESP24031')
```

*With multi symbols:*
```python
te.getCmtHistorical(symbol = 'PRTESP24031, NORZWEXX991')
```

**JS**
*Using Requests:*
```js
const axios = require('axios');
(async () => {
    const your_api_key = 'your_api_key'
    const response = await axios.get(`https://api.tradingeconomics.com/comtrade/historical/PRTESP24031,NORZWEXX991?c=${your_api_key}`)
    console.log(response.data)
})()
```
*Or using our package:*
```javascript
const te = require('tradingeconomics');
te.login('your_api_key');
data = te.getComtrade(symbol = 'PRTESP24031').then(function(data){
    console.log(data)     
});
```

*With multi symbols:*
```javascript
data = te.getComtrade(symbol = 'PRTESP24031, NORZWEXX991').then(function(data){
    console.log(data)     
});
```

**C#**
*Using Requests:*
```c#
using (var httpClient = new HttpClient())
{
    using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/comtrade/historical/PRTESP24031,NORZWEXX991?c=your_api_key"))
    {
        request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1");
        var response = await httpClient.SendAsync(request);
        if (response.IsSuccessStatusCode)
        {
            var content = await response.Content.ReadAsStringAsync(); 
            Console.WriteLine(content);
        }
    }
}
```
*With multi symbols:*
```c#
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/comtrade/historical/PRTESP24031,NORZWEXX991?c=your_api_key"))
```

The response data format can be configured by appending the **&f=** parameter to the URL request.

**JSON**

```text
https://api.tradingeconomics.com/comtrade/historical/{symbols}?c={your_api_key}&f=json
```

```json
[
  {
    "symbol": "PRTESP24031",
    "date": "1997-12-31T00:00:00",
    "value": 707.0
  },
  {
    "symbol": "PRTESP24031",
    "date": "1998-12-31T00:00:00",
    "value": 7020.0
  },
  {
    "symbol": "PRTESP24031",
    "date": "2000-12-31T00:00:00",
    "value": 54310.0
  }
]
```

**CSV**

```text
https://api.tradingeconomics.com/comtrade/historical/{symbols}?c={your_api_key}&f=csv
```

```bash
symbol,date,value
PRTESP24031,12/31/1997 12:00:00 AM,707
PRTESP24031,12/31/1998 12:00:00 AM,7020
PRTESP24031,12/31/2000 12:00:00 AM,54310
```

**HTML**

```text
https://api.tradingeconomics.com/comtrade/historical/{symbols}?c={your_api_key}
```

| symbol | date | value
|--------|------|-------|
| PRTESP24031 | 12/31/1997 12:00:00 AM | 707 |
| PRTESP24031 | 12/31/1998 12:00:00 AM | 7020 |
| PRTESP24031 | 12/31/2000 12:00:00 AM | 54310 |

## Response fields

| Field  | Type   | Description                             | Example               |
|--------| -------|---------------------------------------- |-----------------------|
| Symbol | string |	Unique symbol used by Trading Economics | "NORZWEXX991"         |
| Date   | string |	Year of the updated series              | "1995-12-31T00:00:00" |
| Value  | string |	Trade value                             | 3161.0                |

