Streaming
The Trading Economics API streaming endpoint can be used to receive live calendar releases 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 one or more of our streaming channels.
Get live calendar
import tradingeconomics as te
import json
te.login('your_private_key')
def on_message(ws, message):
print(json.loads(message))
te.subscribe('calendar')
te.run(on_message)
Clone the repository
git clone https://github.com/tradingeconomics/tradingeconomics-js
Access the folder
cd tradingeconomics-js/Examples/stream-nodejs/
Install dependencies
npm install
In app.js file, set-up your client key and secret. Then subscribe to calendar
Client = new te_client({
url: 'wss://stream.tradingeconomics.com/',
key: 'API_CLIENT_KEY', // <--
secret: 'API_CLIENT_SECRET' // <--
//reconnect: true
});
Client.subscribe('calendar')
using System.Net.WebSockets;
using System.Text;
try
{
using (var cws = new ClientWebSocket())
{
await cws.ConnectAsync(new Uri($"wss://stream.tradingeconomics.com/?client='your_private_key'"), CancellationToken.None);
if (cws.State == WebSocketState.Open)
{
var buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(@"{""topic"": ""subscribe"", ""to"": """ + "calendar" + @""" }"));
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}");
}
{'event': 'Consumer Inflation Expectations', 'country': 'United States', 'category': 'Inflation Expectations', 'ticker': 'UNITEDSTAINFEXP', 'actual': '3.8%', 'previous': '4.1%', 'revised': 'null', 'date': '2023-07-10T15:00:00', 'referenceDate': '2023-06-30T00:00:00', 'reference': 'Jun', 'calendarId': '324314', 'unit': '%', 'currency': 'null', 'importance': '1', 'teforecast': '3.9%', 'forecast ': 'null', 'symbol': 'UNITEDSTAINFEXP', 'source': 'null', 'topic': 'calendar'}
{'event': '3-Month Bill Auction', 'country': 'United States', 'category': '3 Month Bill Yield', 'ticker': 'UNITEDSTA3MONBILYIE', 'actual': '5.25%', 'previous': '5.23%', 'revised': 'null', 'date': '2023-07-10T15:00:00', 'referenceDate': 'None', 'reference': , 'calendarId': '313670', 'unit': '%', 'currency': 'None', 'importance': '1', 'teforecast': 'None', 'forecast ': 'None', 'symbol': 'UNITEDSTA3MONBILYIE', 'source': 'null', 'topic': 'calendar'}
{'event': '6-Month Bill Auction', 'country': 'United States', 'category': '6 Month Bill Yield', 'ticker': 'UNITEDSTA6MONBILYIE', 'actual': '5.27%', 'previous': '5.236%', 'revised': 'null', 'date': '2023-07-10T15:00:00', 'referenceDate': 'null', 'reference': , 'calendarId': '324314', 'unit': '%', 'currency': 'null', 'importance': '1', 'teforecast': 'null', 'forecast ': 'null', 'symbol': 'UNITEDSTA6MONBILYIE', 'source': 'null', 'topic': 'calendar'}
Response fields
Field | Type | Description | Example |
---|---|---|---|
event | string | Specific event name in the calendar | ‘Retail Sales MoM’ |
country | string | Country name | ‘United States’ |
category | string | Indicator category name | ‘Retail Sales MoM’ |
ticker | string | Unique ticker used by Trading Economics | ‘RSTAMOM’ |
actual | string | Latest released value | ‘-1%’ |
previous | string | Value for the previous period after the revision (if revision is applicable) | ‘-0.2%’ |
revised | string | Value reported in the previous period after revision | ‘-0.4%’ |
date | string | Release time and date in UTC | ‘2023-04-14T12:30:00’ |
referenceDate | string | The date period for which released data refers to | ‘2023-03-31T00:00:00’ |
reference | string | The period for which released data refers to | ‘Mar’ |
calendarId | string | Unique calendar ID used by Trading Economics | ‘319965’ |
unit | string | Unit of the data | ‘%’ |
currency | string | Currency of the data | “C$” |
importance | number | 1 = low, 2 = medium, 3 = high | 3 |
teforecast | string | TE own projections | ‘-0.9%’ |
forecast | string | Average forecast among a representative group of economists | ‘-0.4%’ |
symbol | string | Unique symbol used by Trading Economics | ‘RSTAMOM’ |
source | string | Source of the data | ‘Office for National Statistics’ |
topic | string | Topic subscribed | ‘calendar’ |