Stream Large Queries
The SDK automatically splits large market-data queries into multiple HTTP requests. Use velo.stream() to process their rows incrementally instead of waiting for every request to finish and keeping the entire result in memory.
| Call | Behavior |
|---|---|
velo.query(request) | Collects every row and resolves to a Data object |
velo.stream(request) | Returns an async generator that yields one decoded row at a time |
Both take the same request, so switching between them changes one line.
Stream rows
A request sends nothing until it is executed. No HTTP request is made until the iterator returned by velo.stream() is advanced.
const velo = new Velo({ apiKey: process.env.VELO_API_KEY! });
const end = Date.now();
const begin = end - 30 * 24 * 60 * 60 * 1_000;
const request = futures
.price(["close"])
.volume(["total"])
.for({
exchanges: ["binance-futures", "bybit"],
coins: ["BTC", "ETH"],
})
.over({
between: [begin, end],
resolution: "1m",
});
for await (const row of velo.stream(request)) {
console.log(row);
}A typed request object streams the same way:
for await (const row of velo.stream({
kind: "futures.rows",
params: {
exchanges: ["binance-futures", "bybit"],
coins: ["BTC", "ETH"],
columns: ["close_price", "dollar_volume"],
begin,
end,
resolution: "1m",
},
})) {
console.log(row);
}Ending the loop early with break or return aborts any request still in flight.
Rebuild a Data object
Streaming is useful when rows can be processed and discarded. If you later need the SDK's .rows(), .series(), .columns(), or .candles() views, accumulate the rows and pass them to Data.from().
const rows = [];
for await (const row of velo.stream(request)) {
rows.push(row);
}
const data = Data.from(rows);
console.log(data.rows());
console.log(data.series());
console.log(data.columns());Accumulating every row uses similar memory to velo.query(). See Data Shapes for the available views.