const res = await fetch('https://app.trdrs.co/api/calendar/stream', {
headers: { Authorization: `Bearer ${process.env.TRDRS_API_KEY}` },
})
const decoder = new TextDecoder()
for await (const chunk of res.body!) {
// Each SSE frame: "event: <name>\ndata: <json>\n\n". Snapshot first, then live events.
process.stdout.write(decoder.decode(chunk as Uint8Array))
}curl -N 'https://app.trdrs.co/api/calendar/stream' \
-H "Authorization: Bearer $TRDRS_API_KEY"import requests
url = "https://app.trdrs.co/api/calendar/stream"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.trdrs.co/api/calendar/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://app.trdrs.co/api/calendar/stream"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://app.trdrs.co/api/calendar/stream")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.trdrs.co/api/calendar/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body<string>{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}Stream calendar updates
Streams a notice as server-sent events (text/event-stream) whenever the economic calendar changes. When one arrives, fetch your /api/calendar window again rather than reading the change from the notice.
Required key: Trading API key. A Connect app’s backend can also send it with the app’s API key, and a venue’s backend with its Venue key, which carries trader:read or trader:trade, each naming one of its own traders in x-trdrs-trader: it then runs on that trader’s own accounts.
const res = await fetch('https://app.trdrs.co/api/calendar/stream', {
headers: { Authorization: `Bearer ${process.env.TRDRS_API_KEY}` },
})
const decoder = new TextDecoder()
for await (const chunk of res.body!) {
// Each SSE frame: "event: <name>\ndata: <json>\n\n". Snapshot first, then live events.
process.stdout.write(decoder.decode(chunk as Uint8Array))
}curl -N 'https://app.trdrs.co/api/calendar/stream' \
-H "Authorization: Bearer $TRDRS_API_KEY"import requests
url = "https://app.trdrs.co/api/calendar/stream"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.trdrs.co/api/calendar/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://app.trdrs.co/api/calendar/stream"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://app.trdrs.co/api/calendar/stream")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.trdrs.co/api/calendar/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body<string>{
"error": "invalid_instrument"
}{
"error": "invalid_instrument"
}Authorizations
The Trading API key (trdrs_sk_…), for market data, orders and account state on the accounts its owner holds. Use it server-to-server, and keep it on your server. Its scope is named trading in the API.
Response
An open event stream with one event, calendar_update, whose payload names what changed. Headlines come on /api/news/stream. A dropped connection carries no event, and EventSource reconnects on its own.
The stream may end with a reconnect event, { code, afterMs }: the engine serving it is restarting for a release, or the trader it serves moved to another engine, and the stream closes right after the event. code is engine_draining. Open the stream again after afterMs milliseconds, which is never more than 1,000: another engine serves it, and it opens as any connection does. It is not an error, so keep what you show until the new stream's first events arrive. The event sets the stream's retry: to afterMs too, so an EventSource that reconnects on its own follows it.
The response is of type string.