# Financials Earnings Calendar Streaming

> Use the Trading Economics API streaming to obtain live financial data.

Source: https://docs.tradingeconomics.com/financials/streaming/

The Trading Economics API streaming endpoint can be used to receive live earnings calendar 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 our streaming channel.

## Get live earnings

**PYTHON**
```python
import tradingeconomics as te
import json
te.login('you_private_key')

def on_message(ws, message):
    print(json.loads(message))

te.subscribe('earnings')
te.run(on_message)
```

**JS**
Clone the repository
```javascript
git clone https://github.com/tradingeconomics/tradingeconomics-js
```

Access the folder
```javascript
cd tradingeconomics-js/Examples/stream-nodejs/
```

Install dependencies
```javascript
npm install
```

In app.js file, set-up your client **key** and **secret**. Then subscribe to earnings calendar.
```javascript
Client = new te_client({
    url: 'wss://stream.tradingeconomics.com/',
    key: 'API_CLIENT_KEY', // <--
    secret: 'API_CLIENT_SECRET' // <--
    //reconnect: true
});

Client.subscribe('earnings')
```

**C#**
```c#
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"": """ + "earnings" + @""" }"));
            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**
```bash
{"event":"Aena Earnings","country":"Spain","category":"Earnings","actual":"2.33","previous":"2.68","date":"2023-12-31T00:00:00.000Z","fiscalTag":"FY2023Q4                 ","fiscalReference":"Q4","calendarReference":"2023-12-31T00:00:00.000Z","importance":2,"teforecast":"2.42","consensus":"2.42","currency":"EUR","symbol":"AENA:SM","topic":"earnings"}'
```

## Response fields

| Field             | Type   | Description                                                                  | Example                    |
| ------------------|--------|------------------------------------------------------------------------------|----------------------------|
| event             | string | Name of the earnings event                                                   | "Aena Earnings"           |
| country           | string | Country of the company                                                       | "Spain"                   |
| category          | string | Type of release (e.g., Earnings, Revenue)                                    | "Earnings"                |
| actual            | string | Reported value for the current period                                        | "2.33"                    |
| previous          | string | Value from the prior period (revised if applicable)                          | "2.68"                    |
| date              | string | Release date and time in UTC                                                 | "2023-12-31T00:00:00.000Z"|
| FiscalTag         | string | Fiscal year and quarter identifier                                           | "FY2023Q4"                |
| FiscalReference   | string | Fiscal period in short format                                                | "Q4"                      |
| CalendarReference | string | Calendar quarter end date in UTC                                             | "2023-12-31T00:00:00.000Z"|
| importance        | number | Indicator of importance: 1 = low, 2 = medium, 3 = high                       | 2                         |
| teforecast        | string | Trading Economics proprietary projection                                     | "2.42"                    |
| consensus         | string | Consensus forecast from analysts                                             | "2.42"                    |
| currency          | string | Currency of reported values                                                  | "EUR"                     |
| symbol            | string | Unique Trading Economics symbol                                              | "AENA:SM"                 |
| topic             | string | Subscribed topic identifier                                                  | "earnings"                |

