Skip to content

Market Data and Python

jayjay181818 edited this page Nov 17, 2026 · 3 revisions

Market Data and Python

Stockbar fetches prices and history through a bundled Python script, run by Stockbar's own Python environment. This page covers the providers, their order, API keys, the Python setup and how refreshing behaves.

Trading 212 and Folync data do not use Python. Everything else does.

Providers

Provider Gives Needs
Yahoo Finance (yfinance) Quotes, history and candles. The primary provider. Nothing
Financial Modeling Prep (FMP) Fallback quotes and history. The Settings hint says it is used for US stocks and that the free plan allows US historical data. An API key
Twelve Data Fallback quotes and history. The Settings hint says it is used for LSE and international listings. An API key

Exchange rates are separate. They come from exchangerate-api.com, or from Folync if you have switched that route on.

Priority and fallback

There are two different orders:

  • Live quotes use a fixed order: yfinance first, then Twelve Data, then FMP. A provider that answers with a usable quote stops the chain. The fixed order is not configurable.
  • Historical data follows your Fetch Priority. The default is Yahoo Finance (yfinance), Financial Modeling Prep, Twelve Data. Change it in Settings → Connections → Fetch Priority: choose Edit Order, drag the sources into the order you want, and choose Done. Stockbar tries each source in that order until one answers. Any known source missing from your list is added at the end.

The order is saved in a settings file readable only by your account, ~/Library/Application Support/com.stockbar/.stockbar_config.json.

API keys

You only need keys for the fallback providers, and only if you want them.

  1. Open Settings → Connections → API Keys.
  2. Paste the key for Financial Modeling Prep or Twelve Data. The eye button shows or hides it.
  3. Choose Save & Test. Stockbar saves the key to your Keychain, then tests it. A green tick means it was verified; a red cross means it was not.
  4. Remove deletes a stored key from the Keychain after you confirm. Stockbar then stops using that source until you enter a key again.

Keys are kept in the Keychain. Stockbar hands them to the Python helper through its environment for each run, and logs redact them. A key an earlier version left in the settings file is moved to the Keychain the first time it is needed. Only whether the last test passed is remembered, never the key itself. An FMP 403 usually means a key or plan limit.

Stockbar's Python environment

By default Stockbar uses its own environment at ~/Library/Application Support/Stockbar/python-env. There is no system-Python fallback: Apple's /usr/bin/python3 (3.9) cannot run the pinned packages and is not used.

Setting it up

  • First launch: an alert offers Set Up Automatically. See Installation.
  • Any time: Settings → Advanced → Python shows the Interpreter (and its version) and Stockbar's Python environment, with a Set Up button, which becomes Rebuild once it exists. Rebuilding is safe while Stockbar is running: the new environment is built beside the old one and switched in a single step.
  • From a checkout: bash script/setup_python_env.sh.

Setup installs a current Python (the environment is Python 3.13; 3.10 is the minimum) and the pinned packages. It uses uv, or a Python 3.10 or later from Homebrew or python.org, when one is installed; otherwise it downloads a pinned uv release, checks its SHA-256 and keeps it in Stockbar's own folder. Packages are installed from a lock file with exact versions and checksums.

The pins in 3.8.0: yfinance 1.8.0, pandas below 4 (until pandas 4 is released and can be tested), requests 2.34.2 and urllib3 2.8.0.

The launch-time check

On first launch, and again after an update changes the pinned versions, Stockbar checks the interpreter it uses. If the environment is missing, or packages are missing or out of date, an alert appears:

  • Set Up Stockbar's Python, when the environment does not exist yet.
  • Python Dependencies Required, when it exists but a package is missing or its version differs.

Both offer Set Up Automatically. For an interpreter you chose yourself, the alert also offers Copy Command and Open Terminal.

Using your own interpreter

You can point Stockbar at another Python 3.10 or later with the pythonInterpreterPath default. With Homebrew's Python you may need a virtual environment, because pip refuses to install into an externally managed environment:

python3.13 -m venv ~/stockbar-venv
~/stockbar-venv/bin/python3 -m pip install -r /Applications/Stockbar.app/Contents/Resources/requirements.txt
defaults write com.stockbar pythonInterpreterPath "$HOME/stockbar-venv/bin/python3"

Relaunch Stockbar afterwards. Settings → Advanced → Python then says the interpreter is set by pythonInterpreterPath.

The Python helper

Prices are fetched by a Python helper: up to two long-lived worker processes that run the bundled scripts, so each request skips Python's start-up and package imports. If both workers are busy or a worker fails, the request runs as its own process. An idle worker holds about 70 MB.

Quit Python Helper When Idle (Settings → Advanced → Memory) controls how long an idle helper is kept. It is on by default as of 3.8.0.

Setting The idle helper quits after Cost
On (default) About 90 seconds Each refresh starts it again, at about a third of a second of processor time, and delays that refresh's first price by about as long.
Off 15 minutes The 70 MB or more stays in memory between refreshes.

Details:

  • Idle workers are checked every quarter of the timeout, so a worker can live up to a quarter longer than the timeout.
  • While markets are open, refreshing every minute keeps the helper running either way.
  • While the London and US markets are closed their prices are fetched only every 30 minutes, so a helper with nothing else to fetch quits in between whether the switch is on or off.
  • If you turned the switch off in a testing build, it stays off.
  • How much memory this saves on a real portfolio has been expected, not measured; the project's benchmark never starts the helper. See Performance and Benchmarks.

How refreshing works

  • Main Refresh Interval (Settings → Refresh) is 5 minutes by default; the choices are 1 minute, 5 minutes, 15 minutes, 30 minutes and 1 hour.
  • Refresh Now and the sidebar button (⌘R) ask for an update immediately. A price younger than about 90% of the interval is reused, so a very recent price may not be fetched again.
  • Quotes are applied together at the end of each refresh (3.8.0), so the window redraws once per refresh and not once per symbol.
  • Stockbar also refreshes when the Mac wakes (3.5.0).
  • One slow symbol no longer discards a whole batch, and failed refreshes are shown (3.5.0).
  • Failing symbols are retried at increasing intervals, then paused (see below).
  • Exchange rates come from exchangerate-api.com at launch and then about once an hour, never automatically more often than every five minutes (from Folync instead, every minute, if its Exchange rates switch is on). A failed fetch is retried after five minutes, and the last-updated time is not reset by a failure.
  • Chart Data Collection (Settings → Refresh, default 5 minutes) decides how often chart history and portfolio snapshots are recorded. A repeated unchanged price is recorded about once an hour.
  • Prices are cached in ~/Library/Caches/stockbar-cache/quote_cache.json, bounded to match your refresh interval.

When a symbol keeps failing

A failing symbol is retried after 1, 2, 5 and then 10 minutes. After five consecutive failures it is paused for one hour, so providers are not hammered and rate limits are not triggered. A paused symbol's popover shows Updates paused and Retry Now.

If a provider itself fails, Stockbar backs off that provider for the same short steps (1, 2, 5, 10 minutes) rather than stopping every quote.

How errors appear

A value that is not available yet is shown as "—", never as a price or as zero. If the Python environment is missing, Stockbar says so and points to Set Up. If no market data arrives at all, check Settings → Advanced → Python: "Not set up" means Stockbar's own Python needs Set Up.

More help: Troubleshooting.

Clone this wiki locally