Skip to content

Prices

niveshpy prices

Wrapper group for price-related commands.

Usage:

niveshpy prices [options] <command>

Options:

  -h, --help  Show this message and exit.

Subcommands

  • list: List latest price for all securities.
  • sync: Sync prices from installed providers.
  • update: Update price for a specific security.

niveshpy prices list

List latest price for all securities.

By default, lists last available price for all securities in the portfolio.

Optionally provide text to filter securities by key or name. The can also be used to provide specific dates for which prices are needed.

Run niveshpy prices sync to fetch latest prices from installed providers.

See https://yashovardhan99.github.io/niveshpy/cli/prices for example usage.

Usage:

niveshpy prices list [options] [<queries>]

Options:

  -l, --limit INTEGER  Maximum number of securities to list.  [default: 30]
  --offset INTEGER     Number of securities to skip before starting to list.
                       Use with --limit for pagination.  [default: 0]
  --json
  --csv
  -h, --help           Show this message and exit.

niveshpy prices sync

Sync prices from installed providers.

By default, syncs prices for all securities in the portfolio.

Optionally provide text to filter securities or specific dates to sync prices for.

See https://yashovardhan99.github.io/niveshpy/cli/prices for example usage.

Usage:

niveshpy prices sync [options] [<queries>]

Options:

  --force              Force update even if prices are up-to-date.
  --provider PROVIDER  Specify a particular price provider to use.
  -h, --help           Show this message and exit.

niveshpy prices update

Update price for a specific security.

Requires the security , , and as arguments.

See https://yashovardhan99.github.io/niveshpy/cli/prices for example usage and notes.

Usage:

niveshpy prices update [options] [<security_key>] [<date>] [<ohlc>]

Options:

  -h, --help  Show this message and exit.

Usage notes and examples

List prices

Example

niveshpy prices list # (1)
niveshpy prices list UTI DSP # (2)
niveshpy prices list 'date:2023-01-01..2023-01-31' # (3)
niveshpy prices list UTI 'date:2023-01-01' # (4)
  1. Show the latest prices for all available securities
  2. Show the latest prices for all securities matching the regex "UTI" or "DSP"
  3. Show all prices from 2023-01-01 to 2023-01-31.
  4. Show price of all securities matching "UTI" for date 2023-01-01

Update prices

Note

  1. If 1 value is provided for <ohlc>, it is treated as the closing price. Other prices are set to the same value.
  2. If 2 values are provided, they are treated as opening and closing prices. High and Low are automatically set.
  3. If 4 values are provided, they are treated as opening, high, low, and closing prices respectively.
  4. Any other number of values will raise an error.

Example

niveshpy prices update # (1)
niveshpy prices update AAPL 2023-01-15 150.25 # (2)
  1. Update prices interactively.
  2. Set closing price of security with key "AAPL" on 2023-01-15 to 150.25.

Sync prices

Example

niveshpy prices sync # (1)
niveshpy prices sync UTI DSP # (2)
niveshpy prices sync 'date:2023-01' # (3)
niveshpy prices sync 'UTI Nifty' 'date:2025' --force --provider amfi # (4)
  1. Sync prices for all securities with default providers
  2. Sync prices for securites matching regex "UTI" and "DSP".
  3. Sync prices for all securities from 2023-01-01 to 2023-01-31.
  4. Sync prices for securities matching regex "UTI Nifty" from 2025-01-01 to 2025-12-31 using the provider "amfi". Due to --force, it will forcefully re-fetch all prices even if the prices were already available in the database.

Price Providers

NiveshPy comes bundled with a few useful providers. However, you can use your own custom provider as well.

Bundled Providers

Provider Name Description Command
AMFI Provide mutual fund prices from AMFI. niveshpy prices sync --provider amfi

Custom Providers

To learn how to create your own custom provider, check our guide

Model Reference

Price data models.

Price

Bases: PriceBase

Database model for price data.

Attributes:

Name Type Description
security_key str

Foreign key to the associated security.

security Security

Related security object.

date date

Date of the price data.

open Decimal

Opening price.

high Decimal

Highest price.

low Decimal

Lowest price.

close Decimal

Closing price.

properties dict[str, Any]

Additional properties of the price data.

created datetime

Timestamp when the price data was created.

PriceBase

Bases: SQLModel

Base model for price data.

Attributes:

Name Type Description
security_key str

Foreign key to the associated security.

date date

Date of the price data.

open Decimal

Opening price.

high Decimal

Highest price.

low Decimal

Lowest price.

close Decimal

Closing price.

properties dict[str, Any]

Additional properties of the price data. Defaults to an empty dictionary.

__init_subclass__

__init_subclass__(**kwargs)

Ensure subclasses inherit schema extra metadata.

Source code in niveshpy/models/price.py
66
67
68
def __init_subclass__(cls, **kwargs):
    """Ensure subclasses inherit schema extra metadata."""
    return super().__init_subclass__(**kwargs)

PriceCreate

Bases: PriceBase

Model for creating price data.

Attributes:

Name Type Description
security_key str

Foreign key to the associated security.

date date

Date of the price data.

open Decimal

Opening price.

high Decimal

Highest price.

low Decimal

Lowest price.

close Decimal

Closing price.

properties dict[str, Any]

Additional properties of the price data. Defaults to an empty dictionary.

PriceDisplay

Bases: PricePublic

Model for displaying price data with related info.

Attributes:

Name Type Description
security str

Formatted security information.

date date

Date of the price data.

open Decimal

Opening price.

high Decimal

Highest price.

low Decimal

Lowest price.

close Decimal

Closing price.

properties dict[str, Any]

Additional properties of the price data.

created datetime

Timestamp when the price data was created.

format_security

format_security(value: str | Security) -> str

Format the security field for display.

Source code in niveshpy/models/price.py
166
167
168
169
170
171
@field_validator("security", mode="before", json_schema_input_type=str | Security)
def format_security(cls, value: str | Security) -> str:
    """Format the security field for display."""
    if isinstance(value, Security):
        return f"{value.name} ({value.key})"
    return value

PricePublic

Bases: PriceBase

Public model for price data exposure.

Attributes:

Name Type Description
security_key str

Foreign key to the associated security.

date date

Date of the price data.

open Decimal

Opening price.

high Decimal

Highest price.

low Decimal

Lowest price.

close Decimal

Closing price.

properties dict[str, Any]

Additional properties of the price data.

created datetime

Timestamp when the price data was created.

PricePublicWithRelations

Bases: PricePublic

Public model for price data with related security.

Attributes:

Name Type Description
security_key str

Foreign key to the associated security.

security Security

Related security object.

date date

Date of the price data.

open Decimal

Opening price.

high Decimal

Highest price.

low Decimal

Lowest price.

close Decimal

Closing price.

properties dict[str, Any]

Additional properties of the price data.

created datetime

Timestamp when the price data was created.