The Trading Economics API streaming endpoint can be used to receive live market data utilizing a persistent web socket connection. Streaming data from the API consists of making an authorization request and leaving the socket open to continually receive data. You can authorize using your API client credentials (key/secret). Then you will be able to subscribe to 1 or more of our streaming channels.

Get live market

Subscribe to markets streaming data.

import tradingeconomics as te
import json

def on_message(ws, message):

te.subscribe( ['EURUSD:CUR', 'AAPL:US', 'CL1:COM'] )

Clone the repository

git clone

Access the folder

cd tradingeconomics-js/Examples/stream-nodejs/

Install dependencies

npm install

In userKey.js file, set-up your client key and secret. Then subscribe to markets.

Client = new te_client({
    url: 'wss://',
    key: 'API_CLIENT_KEY', // <--
    secret: 'API_CLIENT_SECRET' // <--
    //reconnect: true

Client.subscribe(['EURUSD:CUR', 'AAPL:US', 'CL1:COM'])

Only a single market topic EURUSD:CUR can be subscribed using guest:guest. For other markets topic, a “key:secret” is required.

using System.Net.WebSockets;
using System.Text;

    using (var cws = new ClientWebSocket())
        await cws.ConnectAsync(new Uri($"wss://'your_private_key'"), CancellationToken.None);

        if (cws.State == WebSocketState.Open)
            var buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(@"{""topic"": ""subscribe"", ""to"": """ + "market_symbol" + @""" }"));
            await cws.SendAsync(buffer, WebSocketMessageType.Binary, true, CancellationToken.None);

        await Task.Delay(1024);

        while (cws.State == WebSocketState.Open)
            var buffer = new ArraySegment<byte>(new byte[1024]);
            var result = await cws.ReceiveAsync(buffer, CancellationToken.None);
            if (result.MessageType == WebSocketMessageType.Close)
                await cws.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);

            Console.WriteLine($"Receiving: {Encoding.UTF8.GetString(buffer.Array, 0, result.Count).Trim()}");
catch (Exception e)
    Console.WriteLine($"Error with message: {e.Message}");

Response fields

pchnumberPercentage change0.13
nchnumberNet change0.0013
pricenumberLatest market price1.1057
dttimestampTimestamp of last market price (epoch)1681474172576
statestringMarket state (open/close)‘open’
typestringType of market (currency/indexes/commodity)‘currency’
dhighnumberDaily high1.1075
dlownumberDaily low1.1042
onumberDay open1.0912
prevnumberPrevious value1.1044
topicstringTopic subscribed‘EURUSD:CUR’