Skip to main content

Core models, interfaces and broker assembly for BrokerKit.

Project description

brokerkit-core

The framework half of BrokerKit: the models, the interfaces every broker adapter implements, and the assembly layer that resolves create_broker("zerodha", ...) to a live, authenticated broker.

This package ships no broker integrations. Install it alongside at least one adapter.

pip install brokerkit-core brokerkit-zerodha

Available adapters: brokerkit-groww, brokerkit-fyers, brokerkit-upstox, brokerkit-dhan, brokerkit-angelone, brokerkit-zerodha.

The idea

Every Indian broker ships its own SDK with its own auth flow, symbol format, units (some report prices in paise, some in rupees), error convention (some raise, some return a failure dict, some return status: false and only log it) and its own idea of what a "quote" contains. brokerkit-core defines one typed, async contract; each adapter absorbs its broker's quirks behind it.

from brokerkit import create_broker

broker = await create_broker("zerodha", api_key=..., api_secret=..., access_token=...)

instruments = await broker.instruments.fetch_instruments()
reliance = next(i for i in instruments if i.symbol == "RELIANCE")

quote = await broker.market.get_quote(reliance)
print(quote.last_price, quote.volume)

await broker.close()

Swap "zerodha" for "fyers" and nothing else changes.

The contract

Every broker exposes the same providers:

Attribute Interface Methods
broker.auth AuthProvider login, get_token
broker.instruments InstrumentProvider fetch_instruments
broker.orders OrderProvider place_order, modify, cancel, get_order, list_orders
broker.portfolio PortfolioProvider holdings, positions
broker.market MarketDataProvider get_quote, get_ltp, get_ohlc, get_option_chain
broker.historical HistoricalDataProvider get_candles
broker.streaming StreamingProvider subscribe_ltp, unsubscribe_ltp, close

Plus three interfaces that only some brokers implement, deliberately kept off the shared Broker base so no broker is forced to carry a hole: ChargesProvider, FundamentalsProvider, NewsProvider, MarketInformationProvider.

Design decisions worth knowing

  • Async-native. Every interface method is async def. Adapters wrap sync vendor SDKs with asyncio.to_thread; blocking calls never run inside an interface method.
  • Pydantic v2 models, Decimal prices. Validation at construction, JSON-serializable for API/agent layers. Enums are stdlib StrEnum.
  • Instruments are a thin adapter, not a store. fetch_instruments() downloads, normalizes and returns — the framework holds no cache, no indexes, no lookups. Storage and querying belong to your app. Calling it again re-downloads, because brokers update masters daily.
  • Instance-scoped state only. No module-level tokens, clients or caches, so one process can hold several accounts. BrokerManager composes N named brokers on top of that.
  • Adapters are plugins. Core never imports an adapter. create_broker("dhan", ...) lazily imports brokerkit_dhan, whose Broker subclass self-registers via __init_subclass__. Adding a broker touches no core code.

Models

Instrument, Order / OrderRequest, Position, Holding, Quote / Ohlc / DepthLevel, Candle, Tick, OptionChain / OptionContract / OptionGreeks, BrokerageCharges, and the fundamentals/news/market-information models.

Two cross-broker facts these encode:

  • Tick.minute_ohlc only ever populates for Upstox — it is the one broker whose feed computes a live 1-minute candle server-side. Everywhere else it stays None and you aggregate ticks yourself.
  • Instrument.isin is None for Angel One and Zerodha — their instrument masters have no ISIN column at all. ISIN is the natural cross-broker join key for equities, so join those two on exchange_token instead; it matches exactly across Groww, Fyers, Dhan and Zerodha.

Multiple accounts

from brokerkit import BrokerManager

manager = BrokerManager()
await manager.add("main", "zerodha", api_key=..., api_secret=..., access_token=...)
await manager.add("data", "fyers", client_id=..., secret_key=..., ...)

quote = await manager["data"].market.get_quote(instrument)
await manager.close_all()

License

MIT © 2026 Aditya Vishwakarma

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

brokerkit_core-1.0.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

brokerkit_core-1.0.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file brokerkit_core-1.0.0.tar.gz.

File metadata

  • Download URL: brokerkit_core-1.0.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for brokerkit_core-1.0.0.tar.gz
Algorithm Hash digest
SHA256 51e07dff36332d3b1c27555e5915c546f2e8cc3c6cf8b7662209fcbb51ba762f
MD5 af9730f9e09969542eeb25f558055419
BLAKE2b-256 a91b85026a25d4f06936f9aa6e1fbe9f62e50ff4d834f7649dc39a6932bab03c

See more details on using hashes here.

File details

Details for the file brokerkit_core-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: brokerkit_core-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for brokerkit_core-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6303ae8dfb0fcb8f1a871d83b106d2a687676138a6241cc106fbddb6dd7492d1
MD5 03a51700f7f5dbaa202aedad472a3909
BLAKE2b-256 f70922403abe5c487ad81d94f4bc2f9ca2d5812ce01891fca3692b6838bf25dc

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