Upstox Python SDK

repository·master·Indexed 41 days ago

https://github.com/upstox/upstox-python

Official Python client for the Upstox API v2. Enables developers to build trading platforms with real-time order execution, portfolio management, live market data streaming, and access to historical candle data (V3), GTT orders, IPO management, mutual funds, and fundamental financial data.

Tokens
125.6K
Snippets
327
Records
481
Agent score
2%

What's inside Upstox

  1. Project structure of interactive_examples

    master

    The interactive_examples directory is organized into functional modules. Key components include:

    • utils.py: Shared helpers for SDK client initialization, search, quotes, and history.
    • test_runner.py: Automated test harness for all examples.
    • instrument_search/: Instrument search scripts.
    • futures_basis/: Futures and basis scripts.
    • options_strategies/: Options strategy scripts.
    • options_analytics/: Options analytics scripts.
    • arbitrage/: Arbitrage scripts.
    • historical_analysis/: Historical analysis scripts.
    • portfolio_screening/: Portfolio screening scripts.
    • market_data/: Market data scripts.
    • fundamentals/: Fundamentals scripts.
    • market_information/: Market information scripts.
    • ipo/: IPO scripts.
  2. Explore Upstox API example categories

    master

    The examples/ directory is organized by API functional areas. You can find specific Python snippets for:

    • Authentication (login/): Token retrieval, access-token requests, and logout.
    • User Management (user/): Profiles, funds, margin, IP management, and kill switch.
    • Orders (orders/): Lifecycle management (place, modify, cancel), order books, history, and trades.
    • Portfolio (portfolio/): Positions, holdings, and MTF positions.
    • Market Data (market-quote/, historical-data/): LTP, quotes, OHLC, Greeks, and candle data.
    • Options (option-chain/, expired-instruments/, strategies/): Option chains, expired contracts, and pre-built options strategies.
    • Other Services: IPOs, GTT orders, margins, charges, mutual funds, payments, news, fundamentals, and P&L reports.
  3. Explore Market Quote examples

    master

    The examples/market-quote/ directory contains various implementation patterns for retrieving market data using the Upstox Python SDK. These examples are categorized by the type of quote data requested:

    • Full Market Quotes: Retrieve comprehensive market data (available in standard and V3 versions).
    • OHLC Quotes: Retrieve Open, High, Low, and Close market data (available in standard and V3 versions).
    • LTP Quotes: Retrieve Last Traded Price (LTP) market data (available in standard and V3 versions).
    • Option Greeks: Retrieve specific Greek fields for options instruments.

    Most examples support retrieving data for a single instrument key or for multiple instrument keys simultaneously.

  4. Manage IPOs using the Upstox Python SDK

    master
    The Upstox Python SDK provides a suite of capabilities to interact with Initial Public Offerings (IPOs). Developers can use the SDK to discover available IPO listings, retrieve specific IPO details, place bids (apply for IPOs), manage orders, and cancel existing IPO orders. The functionality is organized into several key workflows: listing discovery, detail retrieval, application/bidding, and order management.
  5. User-related example code overview

    master
    The examples/user/ directory contains implementation examples for various user-centric API operations. These include retrieving profile information, checking funds and margins (including V3 endpoints), managing user IP addresses, and controlling the Kill Switch functionality.
  6. Retrieve Trade Profit and Loss reports

    master

    The Upstox Python SDK provides functionality to retrieve trade-related financial data, including metadata, profit and loss (P&L) reports, and trade charges.

    Key workflows include:

    • Get Report Meta Data: Retrieve metadata required to generate reports for specific segments (e.g., equity).
    • Get Profit Loss Report: Retrieve detailed P&L reports for specific segments like Futures and Options (F&O).
    • Get Trade Charges: Retrieve a breakdown of charges incurred during trades for both equity and F&O segments.
  7. Portfolio management examples

    master
    The examples/portfolio/ directory contains implementation patterns for managing user portfolio data using the Upstox Python SDK. Key capabilities demonstrated include retrieving active positions, managing Margin Trading Facility (MTF) positions, converting position types (intraday vs. delivery), and fetching user holdings.
  8. Manage payouts using UserApi

    master

    Payout-related operations are exposed through the UserApi class. You can use these endpoints to retrieve payout history, check available payout modes, and manage the lifecycle of a payout (initiate, modify, or cancel).

    ⚠️ Warning: The methods initiate_payout, modify_payout, and cancel_payout move real funds. It is strongly recommended to test your implementation against a sandbox or test account before deploying to production.

  9. Available Options Trading Strategy Categories

    master

    The examples are organized into four main strategy categories based on market outlook:

    • Bullish: Strategies for when you expect the market to move up (e.g., Buy Call, Bull Call Spread, Bull Butterfly).
    • Bearish: Strategies for when you expect the market to move down (e.g., Buy Put, Bear Call Spread, Bear Butterfly).
    • Neutral: Strategies for when you expect the market to move sideways or stay range-bound (e.g., Short Straddle, Short Strangle, Iron Butterfly).
    • Others: Strategies combining directional and volatility views, or pure volatility plays (e.g., Long Straddle, Long Strangle, Call Ratio Spread).
  10. Access fundamental financial data via Upstox Python SDK

    master

    The Upstox Python SDK provides endpoints to retrieve comprehensive fundamental financial data for companies. You can access various financial statements and metrics including:

    • Company Profile: General information about the company.
    • Key Ratios: Financial performance metrics and ratios.
    • Balance Sheet: Assets, liabilities, and equity data.
    • Income Statement: Revenue, expenses, and profit data.
    • Cash Flow: Inflow and outflow of cash.
    • Competitors: Peer comparison data.
    • Corporate Actions: Information on dividends, splits, etc.
    • Share Holdings: Data regarding share distribution and ownership.
  11. Understand the DepthMap model properties

    master

    The DepthMap model represents the market depth (order book) for a security. It contains two primary lists of Depth objects representing the current market bids and asks:

    • buy: A list[Depth] containing the current bids (buy orders).
    • sell: A list[Depth] containing the current asks (sell orders).

    Both properties are optional.