Get started
The Trading Economics Application Programming Interface (API) provides direct access to 300.000 economic indicators, exchange rates, stock market indexes, government bond yields, commodity prices and company financials. You can also subscribe to quotes from our markets and streaming updates from our economic calendar and earnings releases calendar. We offer two distinct solutions that serve as convenient gateways to interact with our API: one in Python and the other in Node.js. However, you can interact with our API in different programming languages and we provide samples for some in our open source github repository.
Endpoints
You can write HTTP requests in any language and use endpoints to extract the raw data. In this documentation, the examples will be in Python, Javascript and C#:
import requests
api_key = 'YOUR_API_KEY'
url = f'https://api.tradingeconomics.com/country/mexico?c={api_key}'
data = requests.get(url).json()
print(data)
The response data format can be configured by appending the &f= parameter to the URL request (supported formats: JSON, CSV, XML)
url = f'https://api.tradingeconomics.com/country/mexico?c={api_key}&f=xml'
You can use request headers to pass the API key:
import requests
response = requests.get('https://api.tradingeconomics.com/country/mexico', headers = {'Authorization': 'api_key'})
print(response.json())
const axios = require('axios');
(async () => {
const api_key = 'YOUR_API_KEY'
const response = await axios.get(`https://api.tradingeconomics.com/country/mexico?c=${api_key}`)
console.log(response.data)
})()
The response data format can be configured by appending the &f= parameter to the URL request (supported formats: JSON, CSV, XML)
const response = await axios.get(`https://api.tradingeconomics.com/country/mexico?c=${api_key}&f=xml`)
You can use request headers to pass the API key:
(async () => {
const url = 'https://api.tradingeconomics.com/country/mexico';
const headers = { 'Authorization': 'api_key' };
try {
const response = await fetch(url, { method: 'GET', headers });
const data = await response.text();
console.log(data);
} catch (error) {
console.error(error);
}
})();
To use Trading Economics API with any server based language, copy and paste an endpoint and change its parameters to what you like.
By default, Server based languages show data as string:
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?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);
}
}
}
The response data format can be configured by appending the &f= parameter to the URL request (supported formats: JSON, CSV, XML)
new HttpRequestMessage(new HttpMethod("GET"), "https://api.tradingeconomics.com/country/mexico?c=your_api_key&f=xml")
Packages
You can also use Trading Economics packages to have easy access to API. Below, we present a basic example to illustrate how to use these packages:
Pre-requirements
- Recent version of Python .
Install the tradingeconomics package using pip, a package management system used to install and manage software packages written in Python. In Windows Command Prompt or Linux bash type:
pip install tradingeconomics
Using package
import tradingeconomics as te #1
te.login('your_api_key') #2
data = te.getIndicatorData(country='mexico') #3
#1 Imports Trading Economics Python package
#2 Calls the authentication method
#3 Makes a call to the API. You can change the parameters to what you like
By default, the response will be a list of dictionaries.
You can also change the output type to Pandas dataframe:
data = te.getIndicatorData(country='mexico', output_type='df')
Pre-requirements
- Recent Node.js version.
Install the tradingeconomics package using npm, a package management system used to install and manage software packages written in JavaScript. In Windows Command Prompt or Linux bash type:
npm install tradingeconomics
Using package
const te = require('tradingeconomics'); //1
te.login('your_api_key'); //2
data = te.getIndicatorData(country = 'mexico').then(function(data){ //3
});
//1 Imports Trading Economics Node.js package
//2 Calls the authentication method
//3 Makes a call to the API. You can change the parameters to what you like
By default, Node.js package shows data as array of Javascript objects.
View on browser
Another alternative to visualize the data is using URLs. If you click at one of them, a new browser window will open with a data sample and the complete URL. To use them, just copy and paste in an internet browser or any other tool, changing the parameters to what you like.
You can visualize the response data in several formats by appending the &f= parameter to the URL request.
Country | Category | Title | LatestValueDate | LatestValue | Source | SourceURL | Unit | URL | CategoryGroup | Adjustment | Frequency | HistoricalDataSymbol | CreateDate | FirstValueDate | PreviousValue | PreviousValueDate |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Mexico | Auto Exports | Mexico Auto Exports | 6/30/2023 12:00:00 AM | 286.29 | Instituto Nacional de Estadística y Geografía (INEGI) | https://www.inegi.org.mx/ | Thousand Units | /mexico/auto-exports | Trade | NSA | Monthly | MEXICOAUTEXP | 7/23/2019 12:20:00 PM | 1/31/1988 12:00:00 AM | 279.27 | 5/31/2023 12:00:00 AM |
Mexico | Balance of Trade | Mexico Balance of Trade | 5/31/2023 12:00:00 AM | -74.00 | Instituto Nacional de Estadística y Geografía (INEGI) | https://www.inegi.org.mx/ | USD Million | /mexico/balance-of-trade | Trade | NSA | Monthly | MXTBBAL | 7/25/2014 2:01:00 PM | 1/31/1980 12:00:00 AM | -1509.00 | 4/30/2023 12:00:00 AM |
Mexico | Banks Balance Sheet | Mexico Banks Balance Sheet | 4/30/2023 12:00:00 AM | 10335903.02 | Banco de México | https://www.banxico.org.mx | MXN Million | /mexico/banks-balance-sheet | Trade | NSA | Monthly | MEXICOBANBALSHE | 9/8/2014 3:29:00 PM | 12/31/2000 12:00:00 AM | 10169075.64 | 3/31/2023 12:00:00 AM |
[{"Country":"Mexico","Category":"Auto Exports","Title":"Mexico Auto Exports","LatestValueDate":"2023-08-31T00:00:00","LatestValue":287.85,"Source":"Instituto Nacional de Estadística y Geografía (INEGI)","SourceURL":"https://www.inegi.org.mx/","Unit":"Thousand Units","URL":"/mexico/auto-exports","CategoryGroup":"Trade","Adjustment":"NSA","Frequency":"Monthly","HistoricalDataSymbol":"MEXICOAUTEXP","CreateDate":"2019-07-23T12:20:00","FirstValueDate":"1988-01-31T00:00:00","PreviousValue":275.77,"PreviousValueDate":"2023-07-31T00:00:00"},{"Country":"Mexico","Category":"Balance of Trade","Title":"Mexico Balance of Trade","LatestValueDate":"2023-08-31T00:00:00","LatestValue":-1377.09,"Source":"Instituto Nacional de Estadística y Geografía (INEGI)","SourceURL":"https://www.inegi.org.mx/","Unit":"USD Million","URL":"/mexico/balance-of-trade","CategoryGroup":"Trade","Adjustment":"NSA","Frequency":"Monthly","HistoricalDataSymbol":"MXTBBAL","CreateDate":"2014-07-25T14:01:00","FirstValueDate":"1980-01-31T00:00:00","PreviousValue":-881.20,"PreviousValueDate":"2023-07-31T00:00:00"},{"Country":"Mexico","Category":"Banks Balance Sheet","Title":"Mexico Banks Balance Sheet","LatestValueDate":"2023-08-31T00:00:00","LatestValue":10702998.84,"Source":"Banco de México","SourceURL":"http://www.banxico.org.mx","Unit":"MXN Million","URL":"/mexico/banks-balance-sheet","CategoryGroup":"Money","Adjustment":"NSA","Frequency":"Monthly","HistoricalDataSymbol":"MEXICOBANBALSHE","CreateDate":"2014-09-08T15:29:00","FirstValueDate":"2000-12-31T00:00:00","PreviousValue":10608854.67,"PreviousValueDate":"2023-07-31T00:00:00"}]
Country,Category,Title,LatestValueDate,LatestValue,Source,SourceURL,Unit,URL,CategoryGroup,Adjustment,Frequency,HistoricalDataSymbol,CreateDate,FirstValueDate,PreviousValue,PreviousValueDate
Mexico,Auto Exports,Mexico Auto Exports,8/31/2023 12:00:00 AM,287.85,Instituto Nacional de Estadística y Geografía (INEGI),https://www.inegi.org.mx/,Thousand Units,/mexico/auto-exports,Trade,NSA,Monthly,MEXICOAUTEXP,7/23/2019 12:20:00 PM,1/31/1988 12:00:00 AM,275.77,7/31/2023 12:00:00 AM
Mexico,Balance of Trade,Mexico Balance of Trade,8/31/2023 12:00:00 AM,-1377.09,Instituto Nacional de Estadística y Geografía (INEGI),https://www.inegi.org.mx/,USD Million,/mexico/balance-of-trade,Trade,NSA,Monthly,MXTBBAL,7/25/2014 2:01:00 PM,1/31/1980 12:00:00 AM,-881.20,7/31/2023 12:00:00 AM
Mexico,Banks Balance Sheet,Mexico Banks Balance Sheet,8/31/2023 12:00:00 AM,10702998.84,Banco de México,http://www.banxico.org.mx,MXN Million,/mexico/banks-balance-sheet,Money,NSA,Monthly,MEXICOBANBALSHE,9/8/2014 3:29:00 PM,12/31/2000 12:00:00 AM,10608854.67,7/31/2023 12:00:00 AM
<ArrayOfCountryIndicator xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/API.Models">
<CountryIndicator>
<Adjustment>NSA</Adjustment>
<Category>Auto Exports</Category>
<CategoryGroup>Trade</CategoryGroup>
<Country>Mexico</Country>
<CreateDate>2019-07-23T12:20:00</CreateDate>
<FirstValueDate>1988-01-31T00:00:00</FirstValueDate>
<Frequency>Monthly</Frequency>
<HistoricalDataSymbol>MEXICOAUTEXP</HistoricalDataSymbol>
<LatestValue>287.85</LatestValue>
<LatestValueDate>2023-08-31T00:00:00</LatestValueDate>
<PreviousValue>275.77</PreviousValue>
<PreviousValueDate>2023-07-31T00:00:00</PreviousValueDate>
<Source>Instituto Nacional de Estadística y Geografía (INEGI)</Source>
<SourceURL>https://www.inegi.org.mx/</SourceURL>
<Title>Mexico Auto Exports</Title>
<URL>/mexico/auto-exports</URL>
<Unit>Thousand Units</Unit>
</CountryIndicator>
<CountryIndicator>
<Adjustment>NSA</Adjustment>
<Category>Balance of Trade</Category>
<CategoryGroup>Trade</CategoryGroup>
<Country>Mexico</Country>
<CreateDate>2014-07-25T14:01:00</CreateDate>
<FirstValueDate>1980-01-31T00:00:00</FirstValueDate>
<Frequency>Monthly</Frequency>
<HistoricalDataSymbol>MXTBBAL</HistoricalDataSymbol>
<LatestValue>-1377.09</LatestValue>
<LatestValueDate>2023-08-31T00:00:00</LatestValueDate>
<PreviousValue>-881.20</PreviousValue>
<PreviousValueDate>2023-07-31T00:00:00</PreviousValueDate>
<Source>Instituto Nacional de Estadística y Geografía (INEGI)</Source>
<SourceURL>https://www.inegi.org.mx/</SourceURL>
<Title>Mexico Balance of Trade</Title>
<URL>/mexico/balance-of-trade</URL>
<Unit>USD Million</Unit>
</CountryIndicator>
<CountryIndicator>
<Adjustment>NSA</Adjustment>
<Category>Banks Balance Sheet</Category>
<CategoryGroup>Money</CategoryGroup>
<Country>Mexico</Country>
<CreateDate>2014-09-08T15:29:00</CreateDate>
<FirstValueDate>2000-12-31T00:00:00</FirstValueDate>
<Frequency>Monthly</Frequency>
<HistoricalDataSymbol>MEXICOBANBALSHE</HistoricalDataSymbol>
<LatestValue>10702998.84</LatestValue>
<LatestValueDate>2023-08-31T00:00:00</LatestValueDate>
<PreviousValue>10608854.67</PreviousValue>
<PreviousValueDate>2023-07-31T00:00:00</PreviousValueDate>
<Source>Banco de México</Source>
<SourceURL>http://www.banxico.org.mx</SourceURL>
<Title>Mexico Banks Balance Sheet</Title>
<URL>/mexico/banks-balance-sheet</URL>
<Unit>MXN Million</Unit>
</CountryIndicator>
</ArrayOfCountryIndicator>
GitHub
You can look for other examples on how to use our API in different programming languages, in our Github repository.