Skip to main content

Resolve and maintain canonical financial instrument records from ISINs, symbols, and names

Project description

Instrument Registry

Resolve and maintain canonical financial instrument records. instrument-reg maps ISINs, provider symbols, names, and other identifiers to a consistent local registry for Beancount and other financial workflows.

Why Use It

  • resolve an instrument from a flexible query like an ISIN, symbol, name, conid, or FX pair
  • keep a local instrument registry with explicit, predictable write paths
  • validate bundled and user-defined instrument data
  • fetch provider-backed details without giving up local registry precedence

Concepts

  • Canonical Name: The unique identifier used in Beancount ledgers (e.g., AAPL, CSPX).
  • ISIN: International Securities Identification Number (e.g., US0378331005). Primary identifier for many instruments.
  • FIGI: Financial Instrument Global Identifier.
  • Query: User input to resolve or add, such as an ISIN, provider symbol, name, conid, or FX pair.
  • Provider Symbol: Provider-specific market symbol (e.g., AAPL on Yahoo, CSPX.L on Yahoo).

Installation

uv tool install instrument-registry

Install optional live-data providers when you want external resolution and verification:

uv tool install 'instrument-registry[providers]'

Configuration

The registry loads data from two sources:

  1. Bundled Data: Built-in instruments (ETFs, Stocks).
  2. User Data: Custom YAML files located at INSTRUMENT_REGISTRY_PATH.

Set the environment variable to point to your custom registry:

export INSTRUMENT_REGISTRY_PATH=~/path/to/my/registry

The registry recursively scans this directory for .yaml and .yml files.

Read precedence for CLI commands is:

  • user-defined registry paths first
  • bundled registry second

Write behavior for add is strict:

  • instrument-reg add writes only when INSTRUMENT_REGISTRY_PATH is set or --registry-path is passed
  • --registry-path is a command option, so pass it after the subcommand, for example instrument-reg add --registry-path ~/registry ...
  • if neither is set, the command fails instead of guessing a write location

Network lookup caching uses the platform cache directory by default. For sandboxed development or CI runs, you can override it with INSTRUMENT_REGISTRY_CACHE_DIR:

export INSTRUMENT_REGISTRY_CACHE_DIR=.cache/instrument-registry

Usage

Resolve a Query

Resolve a query from local registries first, then external providers if needed. Queries can be ISINs, provider symbols, names, IBKR conids, or common FX pairs.

instrument-reg resolve US0378331005
# Output: Resolved: Apple Inc. -> AAPL (yahoo)

Automatic Currency Resolution

The resolver can derive common FX provider symbols when they are not already in your registry:

  • resolve EUR -> EURUSD=X
  • resolve EUR/JPY -> EURJPY=X
  • resolve USD/JPY -> JPY=X

This eliminates the need to manually define standard Forex pairs in your registry files.

With price verification (checks if price matches historical data):

instrument-reg resolve US0378331005 --date 2024-01-01 --price 185.00

Add an Instrument

Add a new instrument to your local registry.

add requires an explicit write target. Set INSTRUMENT_REGISTRY_PATH or pass --registry-path.

# Auto-fetch metadata — instrument type and asset class are inferred from the provider
instrument-reg add --registry-path ~/registry US0378331005 --fetch

# Manually specify all details (instrument-type and asset-class are required without --fetch)
INSTRUMENT_REGISTRY_PATH=~/registry instrument-reg add \
  --name AAPL \
  --isin US0378331005 \
  --symbol AAPL \
  --instrument-type Stock \
  --asset-class Stock \
  --currency USD

Linting

Validate registry files and check for duplicates.

instrument-reg lint

Verify against live market data (checks if tickers are valid):

instrument-reg lint --verify

Fetch Metadata

Fetch details using local registries first, then provider lookup when needed.

instrument-reg fetch --isin US0378331005

Command Summary

  • resolve: resolve a query from local registries first, then external providers
  • add: add or update an instrument in an explicit user registry path
  • fetch: inspect provider details using local registry precedence first
  • lint: validate registry files and optionally verify live provider data

Programmatic Usage

You can use the registry in your Python scripts:

from pydantic_market_data.models import SecurityCriteria

from instrument_registry.registry import get_registry

# Initialize registry (loads bundled data + user data from env var)
reg = get_registry()

# 1. Resolve by ISIN
instrument = reg.find_by_isin("US0378331005")
if instrument:
    print(f"Name: {instrument.name}, Currency: {instrument.currency}")

# 2. Search by identifier fields
criteria = SecurityCriteria(symbol="AAPL")
candidates = reg.find_candidates(criteria)
for c in candidates:
    print(f"Found: {c.name} ({c.isin})")

# 3. Look up by provider symbol
# Note: Provider-symbol lookup requires the provider name
instrument = reg.find_by_ticker("yahoo", "AAPL")

Data Format (YAML)

instruments:
  - name: AAPL
    isin: US0378331005
    instrument_type: Stock
    asset_class: Stock
    currency: USD
    tickers:
      yahoo: AAPL
    validation_points:
      - date: "2024-01-01"
        price: 185.64

Contributing

  • Bundled Data: Submit a PR to add common instruments to src/instrument_registry/data/instruments/.
  • Providers: Implement new data sources in src/instrument_registry/finder.py by adding a class that implements the DataProvider protocol.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

instrument_registry-0.2.9.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

instrument_registry-0.2.9-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file instrument_registry-0.2.9.tar.gz.

File metadata

  • Download URL: instrument_registry-0.2.9.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for instrument_registry-0.2.9.tar.gz
Algorithm Hash digest
SHA256 8647ccf99ca2595d38a3548674607cb2c90f6e718fa5cf318a4ac981f9937e36
MD5 240aa76bb127032d39b8fe611a67939f
BLAKE2b-256 255418e46962ecf880b1dd85c84b3e130f32b25d1b14cffec6f660bb5348ee3e

See more details on using hashes here.

File details

Details for the file instrument_registry-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: instrument_registry-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for instrument_registry-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 9a7ed28b49cb1321ee0f99a2b844c024c8158dbf6e4db3a7670df0c6e3d096d2
MD5 8d4f84bc7a39a674fbe1b9bf03559201
BLAKE2b-256 f01062c6187d6b718a3262a85897efa55807df22570e24bec0d512ff18834c06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page