Portfolio
Stream Folio
Stream real-time portfolio updates via Server-Sent Events
GET
/
accounts
/
{account_id}
/
folio
/
stream
Stream Folio
curl --request GET \
--url https://api.example.com/accounts/{account_id}/folio/streamimport requests
url = "https://api.example.com/accounts/{account_id}/folio/stream"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/accounts/{account_id}/folio/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/accounts/{account_id}/folio/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$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://api.example.com/accounts/{account_id}/folio/stream"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/accounts/{account_id}/folio/stream")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/accounts/{account_id}/folio/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_bodyStream Folio
Opens a Server-Sent Events (SSE) stream that sends the sub-account’s full portfolio on connect, then streams incremental updates as positions change.Request
GET /accounts/:account_id/folio/stream
Path parameters
| Parameter | Type | Description |
|---|---|---|
account_id | string | The sub-account ID |
Response
The response is atext/event-stream with two event types.
snapshot event
Sent immediately on connect. Contains the full folio as a JSON array of [key, value] pairs:
event: snapshot
data: [["balances/token/base/USDC/0xaded...78ef","100e6"],["prices/token/WETH","3391.3"],...]
update event
Sent whenever folio data changes. Contains only the changed key/value pairs:
event: update
data: [["balances/token/base/USDC/0xaded...78ef","150e6"],["prices/token/WETH","3400.1"]]
Keepalive
A comment line is sent every 30 seconds to keep the connection alive:: keepalive
Examples
curl -N https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/folio/stream \
-H "Authorization: Bearer $LEGEND_QUERY_KEY" \
-H "Accept: text/event-stream"
const response = await fetch(
"https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/folio/stream",
{
headers: {
Authorization: `Bearer ${LEGEND_QUERY_KEY}`,
Accept: "text/event-stream",
},
}
);
const reader = response.body!.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split("\n");
buffer = lines.pop()!;
let eventType = "";
for (const line of lines) {
if (line.startsWith("event: ")) {
eventType = line.slice(7);
} else if (line.startsWith("data: ")) {
const pairs: [string, string][] = JSON.parse(line.slice(6));
console.log(`${eventType}: ${pairs.length} pairs`);
}
}
}
import httpx
import json
url = "https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/folio/stream"
headers = {
"Authorization": f"Bearer {LEGEND_QUERY_KEY}",
"Accept": "text/event-stream",
}
with httpx.stream("GET", url, headers=headers) as response:
event_type = ""
for line in response.iter_lines():
if line.startswith("event: "):
event_type = line[7:]
elif line.startswith("data: "):
pairs = json.loads(line[6:])
print(f"{event_type}: {len(pairs)} pairs")
// Stream folio updates via SSE
let url = format!("/accounts/{}/folio/stream", account_id);
// Use reqwest with EventSource or the stream_folio helper
The stream sends all folio data as flat key/value pairs. See the Folio concepts page for the full key/value reference and value encoding details.
Errors
| Status | Code | Description |
|---|---|---|
| 404 | account_not_found | Account doesn’t exist |
⌘I
Stream Folio
curl --request GET \
--url https://api.example.com/accounts/{account_id}/folio/streamimport requests
url = "https://api.example.com/accounts/{account_id}/folio/stream"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/accounts/{account_id}/folio/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/accounts/{account_id}/folio/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$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://api.example.com/accounts/{account_id}/folio/stream"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/accounts/{account_id}/folio/stream")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/accounts/{account_id}/folio/stream")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body