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
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
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
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)
- Show the latest prices for all available securities
- Show the latest prices for all securities matching the regex "UTI" or "DSP"
- Show all prices from 2023-01-01 to 2023-01-31.
- Show price of all securities matching "UTI" for date 2023-01-01
Update prices¶
Note
- If 1 value is provided for
<ohlc>, it is treated as the closing price. Other prices are set to the same value. - If 2 values are provided, they are treated as opening and closing prices. High and Low are automatically set.
- If 4 values are provided, they are treated as opening, high, low, and closing prices respectively.
- Any other number of values will raise an error.
Example
niveshpy prices update # (1)
niveshpy prices update AAPL 2023-01-15 150.25 # (2)
- Update prices interactively.
- 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)
- Sync prices for all securities with default providers
- Sync prices for securites matching regex "UTI" and "DSP".
- Sync prices for all securities from 2023-01-01 to 2023-01-31.
- 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 | |
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 | |
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. |