Skip to content

query_instruments


function backtide.storage.query_instruments(instrument_type=None, provider=None, exchange=None, limit=None)

Return stored instrument metadata, optionally filtered.

When called with no arguments, returns all instruments. When instrument_type, provider, and/or exchange are given, only matching rows are returned.

Parameters

instrument_type : str | InstrumentType | list[str | InstrumentType] | None, default=None

Filter by instrument type. Accepts a single value or a list.

provider : str | Provider | list[str | Provider] | None, default=None
Filter by data provider. Accepts a single value or a list.

exchange : str | Exchange | list[str | Exchange] | None, default=None
Filter by exchange. Accepts a single exchange or a list.

limit : int | None, default=None
Maximum number of instruments to return. None means no limit.

Returns

list[Instrument]

Matching instruments from the database.


See Also

fetch_instruments

Get instruments given their symbols.

query_bars

Return stored OHLCV bars as a dataframe.


Example

>>> from backtide.storage import query_instruments

>>> all_instruments = query_instruments(limit=5)
>>> print(all_instruments)

[Instrument(symbol="AAPL", name="Apple Inc.", base=None, quote="USD", instrument_type="stocks", exchange="XNAS", provider=Yahoo), Instrument(symbol="MSFT", name="Microsoft Corporation", base=None, quote="USD", instrument_type="stocks", exchange="XNAS", provider=Yahoo), Instrument(symbol="SPY", name="State Street SPDR S&P 500 ETF T", base=None, quote="USD", instrument_type="etf", exchange="ARCX", provider=Yahoo)]

>>> stocks = query_instruments("stocks", "yahoo", limit=5)
>>> print(stocks)

[Instrument(symbol="AAPL", name="Apple Inc.", base=None, quote="USD", instrument_type="stocks", exchange="XNAS", provider=Yahoo), Instrument(symbol="MSFT", name="Microsoft Corporation", base=None, quote="USD", instrument_type="stocks", exchange="XNAS", provider=Yahoo)]

>>> xnas = query_instruments("stocks", exchange="XNAS", limit=5)
>>> print(xnas)

[Instrument(symbol="AAPL", name="Apple Inc.", base=None, quote="USD", instrument_type="stocks", exchange="XNAS", provider=Yahoo), Instrument(symbol="MSFT", name="Microsoft Corporation", base=None, quote="USD", instrument_type="stocks", exchange="XNAS", provider=Yahoo)]