GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — desktop-sdk/python at main · barchart/desktop-sdk

Expand file tree

/

python

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

python

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
examples
examples
 
 
scripts
scripts
 
 
src/barchart_desktop_sdk
src/barchart_desktop_sdk
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CLAUDE.md
CLAUDE.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
llms.txt
llms.txt
 
 
pyproject.toml
pyproject.toml
 
 
uv.lock
uv.lock
 
 
uv.toml
uv.toml
 
 

README.md

Outline

Barchart Desktop SDK for Python

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.

Installing

Python 3.11 or later:

pip install barchart-desktop-sdk
# or
uv add barchart-desktop-sdk

Quick start

from 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.

Names

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").

Threads

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_quote and 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 use coalesce_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_callback is 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 the on_… 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()).

Development

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.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.