Live quotes, order books and cumulative volume from Openfeed, kept up to date for you. The Python port of @barchart/desktop-sdk-js, which is the reference implementation: its reference and design describe what this package does.
Early release. The API follows the TypeScript SDK.
Python 3.11 or later:
pip install barchart-desktop-sdk
# or
uv add barchart-desktop-sdkfrom barchart_desktop_sdk import Credentials, DesktopSdk, Listener, QuoteEvent, SubscriptionError def on_quote(event: QuoteEvent) -> None: print(event.symbol, event.formatted.session.last) def on_error(error: SubscriptionError) -> None: print(error) with DesktopSdk() as sdk: sdk.login(Credentials(url="ws://localhost:9000", username="your-username", password="your-password")) subscription = sdk.subscribe_quote("ES*0", Listener(on_event=on_quote, on_error=on_error)) ...
ws://localhost:9000 is the Barchart Desktop API, which takes Barchart Desktop's credentials. An Openfeed gateway works the same way, with its own URL.
Always pass on_error: nothing else tells you when the server refuses a subscription, such as one you don't have permission for.
Not every Openfeed server sends volume at price: on one that doesn't, the subscription goes active, but no events come and get_cumulative_volume stays None.
A failed lookup raises: raw.lookup_instruments gives an InstrumentLookupError when the server refuses it or finds nothing.
More in examples/. Every class, method and field has a docstring: your editor shows it on hover, help(DesktopSdk.subscribe_quote) prints it, and the installed package has them all as Markdown in barchart_desktop_sdk/docs/api/. The TypeScript SDK's reference describes the same methods and the delivery guarantees, under the names below.
The same names as the TypeScript SDK, in Python's style: session.lastSize is session.last_size, sdk.subscribeQuote is sdk.subscribe_quote. Records are frozen dataclasses, levels are tuples, times are UTC datetimes (to the microsecond) and trade dates are dates. The logger is a standard logging.Logger, by default logging.getLogger("barchart_desktop_sdk").
Every method is safe to call from any thread, listeners included.
- Listeners run one at a time, in order, on the SDK's delivery thread, and never inside the call that registered them, so you always hold the handle first.
- State is applied as messages arrive, on another thread, so
get_quoteand the other getters are current even while a slow listener holds up the events behind it. Events wait in a queue with no limit: a listener that can't keep up should usecoalesce_interval_ms. - A listener mustn't wait on a future the SDK settles, such as
sdk.when_connected().result(), since settling it needs the thread the listener is running on.add_done_callbackis fine. - After
close()returns, its listener isn't running and won't be called again. Called from another thread while the listener is running,close()waits for it to finish; called from inside a listener, it doesn't wait. The same goes for the functions theon_…methods return, and calls already queued for a closed or removed listener are dropped. So don't close from a thread that a listener waits on, such as one holding a lock the listener takes.
The SDK's threads are daemon threads, so one you forget to dispose() doesn't keep the process alive.
In asyncio, await the futures the SDK returns (when_connected, raw.request_snapshot, raw.lookup_instruments) by wrapping them: await asyncio.wrap_future(sdk.when_connected()).
uv manages the Python version, the environment and the lockfile; CONTRIBUTING.md has the rest.
uv sync # the environment, with the dev tools sh scripts/check.sh # everything CI runs: lint, format, types, tests, API docs, build
It depends on openfeed 1.5.0 or later, from PyPI. uv.lock pins the version the checks use; uv lock --upgrade-package openfeed moves it.