menu

Code Examples

For more information please read our API Documentation.

Python

Install the tradingeconomics package using pip:
pip3 install tradingeconomics
Open the python command line, and type:
import tradingeconomics as te
Connect with your API Key:
te.login('client_key')
Ready to get data:
te.getIndicatorData(country='united states', indicators='gdp')
Javascript

Install NodeJS. In Windows Command Prompt or Linux bash type:
npm install tradingeconomics
To start using the Trading Economics Node package:
const te = require('tradingeconomics');
Connect with your API Key:
te.login('client_key');
Ready to get data:
data = te.getIndicatorData(country = ['china', 'portugal']).then(function(data) {
    console.log(data)
});
C#

using System;
using System.IO;
using System.Net;

namespace Examples.System.Net
{
    public class Indicators
    {
        public static void Main()
        {
            // replace guest:guest with your key
            WebRequest request = WebRequest.Create(
                "https://api.tradingeconomics.com/indicators?c=guest:guest");
            WebResponse response = request.GetResponse(); 
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);    

            using (Stream dataStream = response.GetResponseStream())
            { 
                StreamReader reader = new StreamReader(dataStream);
                String responseFromServer = reader.ReadToEnd();
                Console.WriteLine(responseFromServer);
            }     
            response.Close();
        }
    }        
}
Java

public static void getIndicatorsByCountry() throws IOException
{
    //put country name here
    String params = "united states"; 
    params = params.replaceAll("\\s","%20"); 
    //set the path
    String path = "/country" + "/" + params;   
    System.out.println("Get a list of indicators by country");
    constructUrl (path);
}
PHP

$url = 'https://api.tradingeconomics.com/indicators';
$headers = array(
    "Accept: application/xml",
    "Authorization: Client guest:guest"
);
$handle = curl_init(); 
    curl_setopt($handle, CURLOPT_URL, $url);
    curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

    $data = curl_exec($handle);
curl_close($handle);
//parse your data to satisfy your needs....
//showing result
echo($data);
R

Install the devtools package. You can do this from CRAN. Invoke R and then type:
install.packages("devtools")
Load the devtools and stringr packages:
library(devtools)
library(stringr)
Install the tradingeconomics package:
install_github("tradingeconomics/tradingeconomics/R/tradingeconomics")
To start using the Trading Economics R package, type in command window:
library(tradingeconomics)
Connect with your API Key:
login('client_key')
Ready to get data:
getIndicatorData(country = c('united states','china'), indicator = c('gdp','inflation rate'), outType = 'df')