velo.stream
Returns an async generator that executes a supported query and yields decoded items in request order. Streaming avoids collecting the complete result in memory and can surface rows while a line-oriented response is still arriving.
Imports
import { Velo } from 'velo-sdk';Example
import { Velo, futures } from 'velo-sdk';
const velo = new Velo({ apiKey: process.env.VELO_API_KEY! });
const request = futures
.price(['close'])
.volume(['total'])
.for({ exchanges: ['binance-futures'], coins: ['BTC', 'ETH'] })
.over({ last: '30D', resolution: '1m' });
for await (const row of velo.stream(request)) {
console.log(row.time, row.close_price);
}No HTTP request is sent until iteration starts. Leaving the loop early aborts requests that are still in flight:
for await (const row of velo.stream(request)) {
console.log(row);
break;
}Definition
function stream<K extends StreamableKind, P extends QueryParams<K>>(
input: QueryInput<K, P>,
options?: HttpRequestOptions,
): AsyncGenerator<QueryItem<K, P>, void, undefined>;Parameters
input
- Type:
QueryInput<K, P>whereK extends StreamableKind
A direct endpoint request or completed request builder for a streamable query kind.
| Input | Yielded item |
|---|---|
| Futures, options, or spot rows | A typed market-data Row |
futures.basis() | A futures basis row |
orderbook.levels() | OrderbookRow |
options.terms() | TermPoint |
catalog.futures(), .options(), or .spot() | The corresponding product type |
marketCaps.history() | MarketCap |
news.stories() is not streamable because its response is handled as one JSON document. Use velo.query() to fetch it. Subscription requests such as news.feed() must be passed to velo.watch().
options
- Type:
HttpRequestOptions - Optional
Overrides the client's HTTP settings for every HTTP request generated by this execution.
| Property | Type | Description |
|---|---|---|
signal | AbortSignal | Aborts iteration, in-flight requests, and pending retry waits. |
timeout | number | Per-attempt timeout in milliseconds. Defaults to the client setting, initially 60_000. |
retry | Partial<RetryOptions> | Overrides retries, baseDelayMs, or maxDelayMs for this execution. |
HTTP retry defaults and retryable failures are described in velo.query().
Return Type
- Type:
AsyncGenerator<QueryItem<K, P>, void, undefined>
The yielded item type is inferred from the request kind and parameters. Market-row requests preserve the selected exchange and column types.
Large queries may be split into multiple HTTP requests. Up to four requests overlap, but decoded items are yielded in request order. Whole-document endpoints that support the streaming interface may yield their items only after an individual response has been buffered and decoded.
Each call creates a separate execution. Iterating two generators built from the same request sends the request twice, as does passing the same request to both query() and stream().
Errors
Invalid request objects and unsupported query kinds fail when stream() creates the generator. HTTP and decoding failures are thrown during iteration as VeloError subclasses after retries are exhausted. Aborting options.signal throws the signal's abort reason from the iterator.
For a longer workflow, see Stream Large Queries.