Skip to content

Securities

A security is an investment instrument that you have purchased or sold. This can be a mutual fund, a stock, an ETF or even physical commodities such as gold or silver.

niveshpy securities

Wrapper group for security-related commands.

Usage:

niveshpy securities [options] <command>

Options:

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

Subcommands

  • add: Add a new security.
  • delete: Delete a security based on a query.
  • list: List all securities.

niveshpy securities add

Add a new security.

To create securities interactively, run the command with no arguments. To add a single security non-interactively, provide all arguments along with --no-input.

is a unique identifier for the security, e.g., ticker symbol or ISIN. If another security with the same key exists, it will be updated.

category and type should be one of the enum values:

  • Category: EQUITY, DEBT, COMMODITY, OTHER
  • Type: STOCK, BOND, MUTUAL_FUND, ETF, OTHER

Usage:

niveshpy securities add [options] [<key>] [<name>] [<category>] [<type>]

Options:

  --no-input  Run without user input, using defaults or skipping prompts.
  -h, --help  Show this message and exit.

niveshpy securities delete

Delete a security based on a query.

If no key is provided, you will be prompted to select from existing securities. The query will be used to search for securities by key or name. If multiple securities match the provided query, you will be prompted to select one.

Associated transactions and holdings are not deleted but will no longer be visible in reports.

When running in a non-interactive mode, --force must be provided to confirm deletion. Additionally, the must match exactly one security key.

Usage:

niveshpy securities delete [options] [<queries>]

Options:

  -l, --limit INTEGER  Maximum number of limit to list.  [default: 100]
  --no-input           Run without user input, using defaults or skipping
                       prompts.
  -f, --force          Force the operation without confirmation.
  -n, --dry-run        Simulate the operation without making any changes.
  -h, --help           Show this message and exit.

niveshpy securities list

List all securities.

Optionally provide a text QUERY to filter securities by key or name.

Usage:

niveshpy securities 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.

Model Reference

Models for securities.

Security

Bases: SecurityBase

Database model for securities.

Attributes:

Name Type Description
key str

Unique key identifying the security.

name str

Name of the security.

type SecurityType

Type of the security.

category SecurityCategory

Category of the security.

properties dict[str, Any]

Additional properties of the security.

created datetime

Timestamp when the security was created.

SecurityBase

Bases: SQLModel

Base model for securities.

Attributes:

Name Type Description
key str

Unique key identifying the security.

name str

Name of the security.

type SecurityType

Type of the security.

category SecurityCategory

Category of the security.

properties dict[str, Any]

Additional properties of the security. Defaults to an empty dictionary.

__init_subclass__

__init_subclass__(**kwargs)

Ensure subclasses inherit schema extra metadata.

Source code in niveshpy/models/security.py
102
103
104
def __init_subclass__(cls, **kwargs):
    """Ensure subclasses inherit schema extra metadata."""
    return super().__init_subclass__(**kwargs)

SecurityCategory

Bases: StrEnum

Enum for security categories.

COMMODITY class-attribute instance-attribute

COMMODITY = auto()

Security category representing commodities.

DEBT class-attribute instance-attribute

DEBT = auto()

Security category representing debt.

EQUITY class-attribute instance-attribute

EQUITY = auto()

Security category representing equity.

OTHER class-attribute instance-attribute

OTHER = auto()

Security category representing other categories.

REAL_ESTATE class-attribute instance-attribute

REAL_ESTATE = auto()

Security category representing real estate.

SecurityCreate

Bases: SecurityBase

Model for creating a new security.

Attributes:

Name Type Description
key str

Unique key identifying the security.

name str

Name of the security.

type SecurityType

Type of the security.

category SecurityCategory

Category of the security.

properties dict[str, Any]

Additional properties of the security. Defaults to an empty dictionary.

SecurityType

Bases: StrEnum

Enum for security types.

BOND class-attribute instance-attribute

BOND = auto()

Security type representing bonds.

ETF class-attribute instance-attribute

ETF = auto()

Security type representing exchange-traded funds.

MUTUAL_FUND class-attribute instance-attribute

MUTUAL_FUND = auto()

Security type representing mutual funds.

OTHER class-attribute instance-attribute

OTHER = auto()

Security type representing other types of securities.

STOCK class-attribute instance-attribute

STOCK = auto()

Security type representing stocks.