### Install Groww Python SDK Source: https://groww.in/trade-api/docs/python-sdk/index Installs the Groww API Python SDK using pip. This is the first step to integrate Groww's trading functionalities into your Python applications. ```shell pip install growwapi ``` -------------------------------- ### Install pyotp Library Source: https://groww.in/trade-api/docs/python-sdk/index Installs the pyotp library, which is required for the TOTP authentication flow when using the Groww API. This library helps generate time-based one-time passwords. ```shell pip install pyotp ``` -------------------------------- ### Subscribe and Get Live Index Data (Python) Source: https://groww.in/trade-api/docs/python-sdk/feed This example shows how to subscribe to, retrieve, and unsubscribe from live index values. It allows for asynchronous data reception via a callback function or synchronous polling. Key requirements include the `GrowwFeed` and `GrowwAPI` classes, a valid API authentication token, and the necessary exchange tokens for the indices. The system supports subscriptions for up to 1000 instruments concurrently. ```Python from growwapi import GrowwFeed, GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) feed = GrowwFeed(groww) def on_data_received(meta): # callback function which gets triggered when data is received print("Data received") print(feed.get_index_value()) # Example for subscribing to index data (replace with actual index instrument details) # Assuming you have an instrument_list for indices similar to the equity/derivative example # index_instruments_list = [{"exchange": "NSE", "segment": "INDEX", "exchange_token": ""}] # Example structure # feed.subscribe_index_value(index_instruments_list, on_data_received=on_data_received) # feed.consume() # For asynchronous consumption # Or for synchronous polling: # feed.subscribe_index_value(index_instruments_list) # print(feed.get_index_value()) # feed.unsubscribe_index_value(index_instruments_list) ``` -------------------------------- ### Groww Trade API Order Response Example Source: https://groww.in/trade-api/docs/python-sdk/orders An example JSON payload representing the response received after an order operation, such as placing or retrieving order status. It includes details like order ID, trading symbol, status, quantities, and timestamps. ```APIDOC Response Example: { "groww_order_id": "GMK39038RDT490CCVRO", "trading_symbol": "WIPRO", "order_status": "OPEN", "remark": "Order placed successfully", "quantity": 100, "price": 250, "trigger_price": 245, "filled_quantity": 100, "remaining_quantity": 10, "average_fill_price": 250, "deliverable_quantity": 10, "amo_status": "PENDING", "validity": "DAY", "exchange": "NSE", "order_type": "MARKET", "transaction_type": "BUY", "segment": "CASH", "product": "CNC", "created_at": "2019-08-24T14:15:22Z", "exchange_time": "2019-08-24T14:15:22Z", "trade_date": "2019-08-24T14:15:22Z", "order_reference_id": "Ab-654321234-1628190" } ``` -------------------------------- ### Upgrade Groww Python SDK Source: https://groww.in/trade-api/docs/python-sdk/index Upgrades the installed Groww API Python SDK to the latest version using pip. Ensures you have the most recent features and bug fixes. ```shell pip install --upgrade growwapi ``` -------------------------------- ### Initialize Groww API and Get Order List Source: https://groww.in/trade-api/docs/python-sdk/orders Demonstrates how to initialize the Groww API client with an authentication token and retrieve a list of all orders. It also shows how to filter orders by segment. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) # Get order list for all segments order_list_response = groww.get_order_list( page = 0, page_size = 100 ) # Get order list for CASH segment cash_order_list_response = groww.get_order_list( segment=groww.SEGMENT_CASH, page = 0, page_size = 100 ) print(order_list_response) ``` -------------------------------- ### Market Depth Subscription and Consumption Source: https://groww.in/trade-api/docs/python-sdk/feed Shows how to subscribe to market depth data for equities and derivatives, either asynchronously via a callback or by polling synchronously. It includes setup, subscription, data retrieval, and unsubscription. ```python from growwapi import GrowwFeed, GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) feed = GrowwFeed(groww) def on_data_received(meta): # callback function which gets triggered when data is received print("Data received") print(feed.get_market_depth()) # you can fetch exchange_token from instruments.csv file instruments_list = [{"exchange": "NSE", "segment": "CASH", "exchange_token": "2885"}, {"exchange": "NSE", "segment": "FNO", "exchange_token": "35241"}] feed.subscribe_market_depth(instruments_list, on_data_received=on_data_received) # This is a blocking call. Nothing after this will run. feed.consume() # OR # you can also fetch data synchronously feed.subscribe_market_depth() # market depth can also be continuously polled using this method for i in range(10): print(feed.get_market_depth()) feed.unsubscribe_market_depth(instruments_list) ``` -------------------------------- ### Example Metadata Usage Source: https://groww.in/trade-api/docs/python-sdk/feed Illustrates how to access and utilize metadata passed to a callback function when data is received from the Groww Feed. Metadata helps in identifying and categorizing the feed data. ```python def on_data_received(meta): print("Metadata received:") print(meta) # .... process data based on metadata ... ``` -------------------------------- ### Get Order Details Source: https://groww.in/trade-api/docs/python-sdk/orders Shows how to retrieve detailed information for a specific order using its Groww order ID and segment. Requires API initialization. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) order_detail_response = groww.get_order_detail( groww_order_id="GMK39038RDT490CCVRO", segment=groww.SEGMENT_CASH, ) print(order_detail_response) ``` -------------------------------- ### Groww API: Get Order List Endpoint Source: https://groww.in/trade-api/docs/python-sdk/orders API documentation for retrieving a list of orders. Supports filtering by segment and pagination. Response includes detailed order information. ```APIDOC GET /orders # Request Parameters # segment: string (Optional) - Segment of the instrument (e.g., CASH, FNO). # page: int (Optional) - Page number for paginated results. # page_size: int (Optional) - Number of orders to fetch per page (default 25, max 25). # Response Schema # { # "order_list": [ # { # "groww_order_id": "string", # "trading_symbol": "string", # "order_status": "string", # "remark": "string", # "quantity": int, # "price": int, # "trigger_price": int, # "filled_quantity": int, # "remaining_quantity": int, # "average_fill_price": int, # "deliverable_quantity": int, # "amo_status": "string", # "validity": "string", # "exchange": "string", # "order_type": "string", # "transaction_type": "string", # "segment": "string", # "product": "string", # "created_at": "string(date-time)", # "exchange_time": "string(date-time)", # "trade_date": "string(date-time)", # "order_reference_id": "string" # } # ] # } # Example Response: # { # "order_list": [ # { # "groww_order_id": "GMK39038RDT490CCVRO", # "trading_symbol": "WIPRO", # "order_status": "OPEN", # "remark": "Order placed successfully", # "quantity": 100, # "price": 250, # "trigger_price": 245, # "filled_quantity": 100, # "remaining_quantity": 10, # "average_fill_price": 250, # "deliverable_quantity": 10, # "amo_status": "PENDING", # "validity": "DAY", # "exchange": "NSE", # "order_type": "MARKET", # "transaction_type": "BUY", # "segment": "CASH", # "product": "CNC", # "created_at": "2019-08-24T14:15:22Z", # "exchange_time": "2019-08-24T14:15:22Z", # "trade_date": "2019-08-24T14:15:22Z", # "order_reference_id": "Ab-654321234-1628190" # } # ] # } ``` -------------------------------- ### Get All Instruments Source: https://groww.in/trade-api/docs/python-sdk/instruments Fetches a comprehensive list of all available financial instruments supported by the Groww API. The data is returned as a pandas DataFrame for easy manipulation and analysis. Requires API authentication. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) instruments_df = groww.get_all_instruments() print(instruments_df.head()) ``` -------------------------------- ### Get Order List Python SDK Usage Source: https://groww.in/trade-api/docs/python-sdk/orders Fetches a list of all orders placed during the day, including open, pending, or executed orders. Supports pagination with a maximum page size of 100. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) # Example: Get order list for the current day # You can optionally specify parameters like 'from_date', 'to_date', 'status', 'page_size', etc. order_list_response = groww.get_order_list() print(order_list_response) # Example with pagination and status filter # order_list_response_paginated = groww.get_order_list(page_size=50, status="FILLED") # print(order_list_response_paginated) ``` -------------------------------- ### Groww API - Get LTP and OHLC Endpoints Source: https://groww.in/trade-api/docs/python-sdk/live-data API documentation for fetching Last Traded Price (LTP) and Open, High, Low, Close (OHLC) data. These endpoints allow retrieval of market data for financial instruments, supporting single or multiple instruments per request. ```APIDOC ## Get LTP Retrieves the Last Traded Price (LTP) for a list of given instruments. ### Request Schema | Name | Type | Description | | --- | --- | --- | | segment `*` | string | Segment of the instrument such as CASH, FNO etc. (Refer to [Segment](/trade-api/docs/python-sdk/annexures#segment)) | | exchange_trading_symbols `*` | Tuple[str] | String of trading symbols with their respective exchanges | `*` required parameters ### Response Payload All prices in rupees. ```json { "NSE_RELIANCE": 2500.5, "NSE_NIFTY": 22962.10 } ``` ### Response Schema | Name | Type | Description | | --- | --- | --- | | ltp | float | Last traded price | --- ## Get OHLC Retrieves the OHLC details for a list of given instruments quickly. Use the segment value FNO for derivatives and CASH for stocks and index. Up to 50 instruments are supported for each function call. ### Request Schema | Name | Type | Description | | --- | --- | --- | | segment `*` | string | Segment of the instrument such as CASH, FNO etc. (Refer to [Segment](/trade-api/docs/python-sdk/annexures#segment)) | | exchange_trading_symbols `*` | Tuple[str] | String of trading symbols with their respective exchanges | `*` required parameters ### Response Payload All prices in rupees. ```json { "NSE_NIFTY": { "open": 22516.45, "high": 22613.3, "low": 22526.4, "close": 22547.55 }, "NSE_RELIANCE": { "open": 1212.8, "high": 1215.0, "low": 1201.0, "close": 1204.0 } } ``` ### Response Schema | Name | Type | Description | | --- | --- | --- | | open | float | Opening price | | high | float | Highest price | | low | float | Lowest price | | close | float | Closing price | ``` -------------------------------- ### Subscribe and Get Live Equity/Derivative Data (Python) Source: https://groww.in/trade-api/docs/python-sdk/feed This snippet demonstrates how to subscribe to, retrieve, and unsubscribe from live Last Traded Price (LTP) data for equities and derivatives. It supports both asynchronous callbacks for real-time updates and synchronous polling for fetching the latest data. Dependencies include the `GrowwFeed` and `GrowwAPI` classes, an API authentication token, and exchange tokens obtained from the instruments CSV file. A maximum of 1000 instruments can be subscribed to simultaneously. ```Python from growwapi import GrowwFeed, GrowwAPI import time # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) feed = GrowwFeed(groww) def on_data_received(meta): # callback function which gets triggered when data is received print("Data received") print(feed.get_ltp()) # you can fetch exchange_token from instruments.csv file instruments_list = [{"exchange": "NSE", "segment": "CASH", "exchange_token": "2885"}, {"exchange": "NSE", "segment": "FNO", "exchange_token": "35241"}] # Asynchronous subscription with callback feed.subscribe_ltp(instruments_list, on_data_received=on_data_received) # This is a blocking call. Nothing after this will run. # feed.consume() # OR # Synchronous subscription feed.subscribe_ltp(instruments_list) # Live data can also be continuously polled using this method print("Polling live data...") for i in range(3): time.sleep(3) print(feed.get_ltp()) feed.unsubscribe_ltp(instruments_list) print("Unsubscribed from LTP.") ``` -------------------------------- ### Groww API: Get Quote for Instrument (Python) Source: https://groww.in/trade-api/docs/python-sdk/live-data Fetches a real-time quote for a single instrument using the `get_quote` method. Requires exchange, segment, and trading symbol. Returns detailed quote information including prices, OHLC, and open interest. ```Python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) quote_response = groww.get_quote( exchange=groww.EXCHANGE_NSE, segment=groww.SEGMENT_CASH, trading_symbol="NIFTY" ) print(quote_response) ``` ```APIDOC GrowwAPI.get_quote: Fetch Real-time Instrument Quote Description: Fetches a real-time quote for an individual instrument. Parameters: - exchange (string, required): Stock exchange (e.g., EXCHANGE_NSE). - segment (string, required): Segment of the instrument (e.g., SEGMENT_CASH, FNO). - trading_symbol (string, required): Trading Symbol of the instrument as defined by the exchange. Response Payload Example: { "average_price": 150.25, "bid_quantity": 1000, "bid_price": 150, "day_change": -0.5, "day_change_perc": -0.33, "upper_circuit_limit": 151, "lower_circuit_limit": 148.5, "ohlc": { "open": 149.50, "high": 150.50, "low": 148.50, "close": 149.50 }, "depth": { "buy": [ {"price": 100.5, "quantity": 1000} ], "sell": [ {"price": 100.5, "quantity": 1000} ] }, "high_trade_range": 150.5, "implied_volatility": 0.25, "last_trade_quantity": 500, "last_trade_time": 1633072800000, "low_trade_range": 148.25, "last_price": 149.5, "market_cap": 5000000000, "offer_price": 150.5, "offer_quantity": 2000, "oi_day_change": 100, "oi_day_change_percentage": 0.5, "open_interest": 2000, "previous_open_interest": 1900, "total_buy_quantity": 5000, "total_sell_quantity": 4000, "volume": 10000, "week_52_high": 160, "week_52_low": 140 } Response Schema: average_price (float): Average price of the instrument bid_quantity (int): Quantity of the bid bid_price (float): Price of the bid day_change (float): Day change in price day_change_perc (float): Day change percentage upper_circuit_limit (float): High price range lower_circuit_limit (float): Low price range open (float): Opening price high (float): Highest price low (float): Lowest price close (float): Closing price price (float): Price of the book entry quantity (int): Quantity of the book entry high_trade_range (float): High trade range implied_volatility (float): Implied volatility last_trade_quantity (int): Last trade quantity last_trade_time (int): Last trade time in epoch milliseconds low_trade_range (float): Low trade range last_price (float): Last traded price market_cap (float): Market capitalization offer_price (float): Offer price offer_quantity (int): Quantity of the offer oi_day_change (float): Open interest day change oi_day_change_percentage (float): Open interest day change percentage open_interest (float): Open interest previous_open_interest (float): Previous open interest total_buy_quantity (float): Total buy quantity total_sell_quantity (float): Total sell quantity volume (int): Volume of trades week_52_high (float): 52-week high price week_52_low (float): 52-week low price ``` -------------------------------- ### Get Position for Symbol using Groww API Python SDK Source: https://groww.in/trade-api/docs/python-sdk/portfolio Demonstrates how to initialize the GrowwAPI client and call the `get_position_for_trading_symbol` method to retrieve position details for a specific trading symbol and segment. Requires authentication token and valid trading symbol/segment. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) trading_symbol_position_response = groww.get_position_for_trading_symbol(trading_symbol="RELIANCE", segment=groww.SEGMENT_CASH) print(trading_symbol_position_response) ``` -------------------------------- ### Get Available User Margin using Groww API Python SDK Source: https://groww.in/trade-api/docs/python-sdk/margin Demonstrates how to retrieve available margin details for a Groww user using the Python SDK. It requires an API authentication token and initializes the GrowwAPI client. The output provides a detailed breakdown of various margin components like clear cash, collateral, and segment-specific margins. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) available_margin_details_response = groww.get_available_margin_details() print(available_margin_details_response) ``` -------------------------------- ### Get Positions for User - Groww API Python SDK Source: https://groww.in/trade-api/docs/python-sdk/portfolio Retrieves all positions associated with the user's account, supporting filtering by segment (e.g., CASH, FNO). The response provides details on trading symbol, segment, quantities, prices, and exchange information. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) user_positions_response = groww.get_positions_for_user() # returns positions of both CASH and FNO segment. cash_positions_response = groww.get_positions_for_user(segment=groww.SEGMENT_CASH) # returns positions of CASH segment. print(user_positions_response) ``` -------------------------------- ### Order Update Response Structure Source: https://groww.in/trade-api/docs/python-sdk/feed Provides an example of the JSON structure for an order update. It includes details such as quantity, price, filled quantity, average fill price, Groww order ID, exchange order ID, order status, duration, exchange, segment, product, and contract ID. ```json { "qty": 75, "price": "130", "filledQty": 75, "avgFillPrice": "110", "growwOrderId": "GMKFO250214150557M2HR6EJF2HSE", "exchangeOrderId": "1400000179694433", "orderStatus": "EXECUTED", "duration": "DAY", "exchange": "NSE", "segment": "FNO", "product": "NRML", "contractId": "NIFTY2522025400CE" } ``` -------------------------------- ### Initialize and Place Order with Groww API Source: https://groww.in/trade-api/docs/python-sdk/index Demonstrates how to initialize the GrowwAPI client using an authentication token and then place a limit order for a stock. It shows common parameters like trading symbol, quantity, validity, exchange, segment, product, order type, transaction type, and optional price and reference ID. ```python # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) place_order_response = groww.place_order( trading_symbol="WIPRO", quantity=1, validity=groww.VALIDITY_DAY, exchange=groww.EXCHANGE_NSE, segment=groww.SEGMENT_CASH, product=groww.PRODUCT_CNC, order_type=groww.ORDER_TYPE_LIMIT, transaction_type=groww.TRANSACTION_TYPE_BUY, price=250, # Optional: Price of the stock (for Limit orders) trigger_price=245, # Optional: Trigger price (if applicable) order_reference_id="Ab-654321234-1628190" # Optional: User provided 8 to 20 length alphanumeric reference ID to track the order ) print(place_order_response) ``` -------------------------------- ### Initialize GrowwAPI with Access Token Source: https://groww.in/trade-api/docs/python-sdk/index Demonstrates how to initialize the GrowwAPI client using a generated access token. This token is typically valid for a day and obtained from the Groww user profile for authentication. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_generated_access_token" # Initialize Groww API growwapi = GrowwAPI(API_AUTH_TOKEN) ``` -------------------------------- ### Place Order: Groww API Python SDK Source: https://groww.in/trade-api/docs/python-sdk/orders Demonstrates how to place a new order using the Groww API Python SDK. It requires authentication and specifies order details like symbol, quantity, price, and validity. The method returns a Groww order ID and its initial status upon successful placement. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) place_order_response = groww.place_order( trading_symbol="WIPRO", quantity=1, validity=groww.VALIDITY_DAY, exchange=groww.EXCHANGE_NSE, segment=groww.SEGMENT_CASH, product=groww.PRODUCT_CNC, order_type=groww.ORDER_TYPE_LIMIT, transaction_type=groww.TRANSACTION_TYPE_BUY, price=250, # Optional: Price of the stock (for Limit orders) trigger_price=245, # Optional: Trigger price (if applicable) order_reference_id="Ab-654321234-1628190" # Optional: User provided 8 to 20 length alphanumeric reference ID to track the order ) print(place_order_response) ``` -------------------------------- ### Groww API: Get Order Detail Endpoint Source: https://groww.in/trade-api/docs/python-sdk/orders API documentation for retrieving detailed information about a specific order. Requires the Groww order ID and segment. ```APIDOC GET /orders/{groww_order_id} # Request Parameters # groww_order_id: string (Required) - Order id generated by Groww. # segment: string (Required) - Segment of the instrument (e.g., CASH, FNO). # Response Schema (Example for a single order): # { # "groww_order_id": "string", # "trading_symbol": "string", # "order_status": "string", # "remark": "string", # "quantity": int, # "price": int, # "trigger_price": int, # "filled_quantity": int, # "remaining_quantity": int, # "average_fill_price": int, # "deliverable_quantity": int, # "amo_status": "string", # "validity": "string", # "exchange": "string", # "order_type": "string", # "transaction_type": "string", # "segment": "string", # "product": "string", # "created_at": "string(date-time)", # "exchange_time": "string(date-time)", # "trade_date": "string(date-time)", # "order_reference_id": "string" # } ``` -------------------------------- ### Live Index Data Subscription and Consumption Source: https://groww.in/trade-api/docs/python-sdk/feed Demonstrates how to subscribe to live index data using a callback function for asynchronous updates or poll data synchronously. It covers setting up the feed, subscribing with instrument lists, consuming data, and unsubscribing. ```python from growwapi import GrowwFeed, GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) feed = GrowwFeed(groww) def on_data_received(meta): # callback function which gets triggered when data is received print("Data received") print(feed.get_index_value()) # you can fetch exchange_token from instruments.csv file instruments_list = [{"exchange": "NSE", "segment": "CASH", "exchange_token": "NIFTY"}, {"exchange": "BSE", "segment": "CASH", "exchange_token": "1"}] feed.subscribe_index_value(instruments_list, on_data_received=on_data_received) # This is a blocking call. Nothing after this will run. feed.consume() # OR # you can also fetch data synchronously feed.subscribe_index_value(instruments_list) # live data can also be continuously polled using this method for i in range(10): print(feed.get_index_value()) feed.unsubscribe_index_value(instruments_list) ``` -------------------------------- ### Get Instrument by Exchange Token Source: https://groww.in/trade-api/docs/python-sdk/instruments Retrieves instrument data by providing the exchange token. This method is useful for identifying instruments when the exchange token is known. Requires API authentication. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) get_instrument_by_exchange_token_response = groww.get_instrument_by_exchange_token( exchange_token="2885" ) print(get_instrument_by_exchange_token_response) ``` -------------------------------- ### Fetch Instrument Details using Groww API Python SDK Source: https://groww.in/trade-api/docs/python-sdk/instruments Demonstrates how to use the Groww API Python SDK to retrieve specific instrument details. It shows the initialization of the GrowwAPI client and the call to the get_instrument_by_groww_symbol method. ```Python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) get_instrument_by_groww_symbol_response = groww.get_instrument_by_groww_symbol( groww_symbol="NSE-RELIANCE" ) print(get_instrument_by_groww_symbol_response) ``` -------------------------------- ### Get Instrument by Trading Symbol Source: https://groww.in/trade-api/docs/python-sdk/instruments Fetches detailed information for a specific financial instrument using its trading symbol and the associated exchange. This function requires valid Groww API authentication. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) get_instrument_by_trading_symbol_response = groww.get_instrument_by_exchange_and_trading_symbol( exchange = groww.EXCHANGE_NSE, trading_symbol="RELIANCE" ) print(get_instrument_by_trading_symbol_response) ``` -------------------------------- ### Initialize GrowwAPI with TOTP Flow Source: https://groww.in/trade-api/docs/python-sdk/index Shows how to initialize the GrowwAPI client using API Key and Secret with Time-based One-Time Password (TOTP) authentication. This method uses your API key and secret to generate a dynamic token for secure access. ```python from growwapi import GrowwAPI import pyotp api_key = "YOUR_API_KEY" totp_gen = pyotp.TOTP('YOUR_API_SECRET') totp = totp_gen.now() access_token = GrowwAPI.get_access_token(api_key, totp) # Use access_token to initiate GrowwAPi growwapi = GrowwAPI(access_token) ``` -------------------------------- ### Get Order Status API Source: https://groww.in/trade-api/docs/python-sdk/orders Retrieves the status of a specific order using its Groww Order ID. Requires the order ID and segment as input. Returns detailed status information for the order. ```APIDOC Method: get_order_status Description: Retrieves the status of an order using its Groww Order ID. Parameters: - groww_order_id (string, required): Order ID generated by Groww. - segment (string, required): Segment of the instrument (e.g., CASH, FNO). Returns: - groww_order_id (string): Groww's unique order identifier. - order_status (string): Current status of the order (e.g., OPEN, FILLED, REJECTED). - remark (string): A remark or message related to the order status. - filled_quantity (int): The quantity of the order that has been executed. - order_reference_id (string): User-provided reference ID for tracking. Example Usage: ```python from growwapi import GrowwAPI API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) order_status_response = groww.get_order_status( groww_order_id="GMK39038RDT490CCVRO", segment=groww.SEGMENT_CASH, ) print(order_status_response) ``` Request Schema: groww_order_id: string (required) segment: string (required) Response Schema: groww_order_id: string order_status: string remark: string filled_quantity: int order_reference_id: string ``` -------------------------------- ### Subscribe to Equity Order Updates (Python) Source: https://groww.in/trade-api/docs/python-sdk/feed Demonstrates how to subscribe to, receive, and poll for equity order updates using the Groww API SDK. It covers both callback-based event handling and synchronous data fetching methods for equity trades. ```python from growwapi import GrowwFeed, GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) feed = GrowwFeed(groww) def on_data_received(meta): if(meta.feed_type == "order_update" and meta.segment == groww.SEGMENT_CASH): print(feed.get_equity_order_update()) feed.subscribe_equity_order_updates(on_data_received=on_data_received) # This is a blocking call. Nothing after this will run. feed.consume() # OR # you can also fetch data synchronously feed.subscribe_equity_order_updates() # order update can also be continuously polled using this method for i in range(10): print(feed.get_equity_order_update()) feed.unsubscribe_equity_order_updates() ``` -------------------------------- ### Get Order Status by Reference ID API Source: https://groww.in/trade-api/docs/python-sdk/orders Retrieves the status of an order using a user-provided reference ID. Requires the reference ID and segment as input. Returns detailed status information for the order. ```APIDOC Method: get_order_status_by_reference Description: Retrieves the status of an order using a user-provided reference ID. Parameters: - order_reference_id (string, required): User-provided reference ID for tracking. - segment (string, required): Segment of the instrument (e.g., CASH, FNO). Returns: - groww_order_id (string): Groww's unique order identifier. - order_status (string): Current status of the order (e.g., OPEN, FILLED, REJECTED). - remark (string): A remark or message related to the order status. - filled_quantity (int): The quantity of the order that has been executed. - order_reference_id (string): User-provided reference ID for tracking. Example Usage: ```python from growwapi import GrowwAPI API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) order_status_by_ref_response = groww.get_order_status_by_reference( order_reference_id="Ab-654321234-1628190", segment=groww.SEGMENT_CASH, ) print(order_status_by_ref_response) ``` Request Schema: order_reference_id: string (required) segment: string (required) Response Schema: groww_order_id: string order_status: string remark: string filled_quantity: int order_reference_id: string ``` -------------------------------- ### Get Trades for Order using Groww API Python SDK Source: https://groww.in/trade-api/docs/python-sdk/orders Retrieve details of trades executed for a specific order using the `get_trade_list_for_order` method. Supports pagination with `page` and `page_size` parameters. Maximum `page_size` is 50. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) trade_list_response = groww.get_trade_list_for_order( groww_order_id="GMK39038RDT490CCVRO", segment=groww.SEGMENT_CASH, page=0, # Optional: Page number for paginated results page_size=50 # Optional: Number of trades to fetch per page (default is 50) ) print(trade_list_response) ``` ```APIDOC Get Trades for Order Method: `get_trade_list_for_order(groww_order_id: str, segment: str, page: int = 0, page_size: int = 50)` - **Description**: Retrieves a list of trades executed for a given order. - **Parameters**: - `groww_order_id` (string, required): The unique order ID generated by Groww. - `segment` (string, required): The segment of the instrument, e.g., "CASH", "FNO". - `page` (integer, optional): The page number for paginated results. Defaults to 0. - `page_size` (integer, optional): The number of trades to fetch per page. Maximum is 50. Defaults to 50. - **Returns**: - A dictionary containing a `trade_list` array, where each element represents an executed trade. - **Example Response Schema**: ```json { "trade_list": [ { "price": 250, "isin": "INE075A01022", "quantity": 1, "groww_order_id": "GMK39038RDT490CCVRO", "groww_trade_id": "", "exchange_trade_id": "202402120123456789", "exchange_order_id": "1100000057528630", "trade_status": "EXECUTED", "trading_symbol": "WIPRO", "remark": "Order placed successfully", "exchange": "NSE", "segment": "CASH", "product": "CNC", "transaction_type": "BUY", "created_at": "2019-08-24T14:15:22Z", "trade_date_time": "2019-08-24T14:15:22Z", "settlement_number": "2024052" } ] } ``` - **Notes**: - All prices are in rupees. - The `page` and `page_size` parameters are used for fetching trade details in multiple pages if there are many trades associated with the order. ``` -------------------------------- ### Live Index Data - Response Fields Source: https://groww.in/trade-api/docs/python-sdk/feed Details the structure and types of the data returned for live index values. ```APIDOC Live Index Data - Response Fields: Returns: tsInMillis (int): Epoch time in milliseconds. value (float): The current value of the index. ``` -------------------------------- ### Subscribe to FNO Order Updates (Python) Source: https://groww.in/trade-api/docs/python-sdk/feed Demonstrates how to subscribe to, receive, and poll for FNO (derivatives) order updates using the Groww API SDK. It shows both callback-based event handling and synchronous data fetching methods. ```python from growwapi import GrowwFeed, GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" groww = GrowwAPI(API_AUTH_TOKEN) feed = GrowwFeed(groww) def on_data_received(meta): if(meta.feed_type == "order_update" and meta.segment == groww.SEGMENT_FNO): print(feed.get_fno_order_update()) feed.subscribe_fno_order_updates(on_data_received=on_data_received) # This is a blocking call. Nothing after this will run. feed.consume() # OR # you can also fetch data synchronously feed.subscribe_fno_order_updates() # order update can also be continuously polled using this method for i in range(10): print(feed.get_fno_order_update()) feed.unsubscribe_fno_order_updates() ``` -------------------------------- ### Get LTP Data Source: https://groww.in/trade-api/docs/python-sdk/live-data Retrieves the Last Traded Price (LTP) for specified instruments. Supports fetching LTP for multiple instruments simultaneously by passing a tuple of exchange trading symbols. Requires segment and exchange trading symbols as input. ```python from growwapi import GrowwAPI # Groww API Credentials (Replace with your actual credentials) API_AUTH_TOKEN = "your_token" # Initialize Groww API groww = GrowwAPI(API_AUTH_TOKEN) # Get LTP for a single instrument ltp_response = groww.get_ltp( segment=groww.SEGMENT_CASH, exchange_trading_symbols="NSE_NIFTY" ) print(ltp_response) # Get LTP for multiple instruments multiple_ltp_response = groww.get_ltp( segment=groww.SEGMENT_CASH, exchange_trading_symbols=("NSE_NIFTY", "NSE_RELIANCE") ) print(multiple_ltp_response) ``` -------------------------------- ### Groww Trade API Order Operations Overview Source: https://groww.in/trade-api/docs/python-sdk/orders Provides an overview of key order management operations available through the Groww Trade API. This includes actions like placing, modifying, and canceling orders, as well as retrieving order status and history. ```APIDOC Order Management Operations: - Place Order - Modify Order - Cancel Order - Get Trades for Order - Get Order Status - Get Order Status by Reference ID - Get Order List - Get Order Details ``` -------------------------------- ### Groww API - Get Position for Symbol Details Source: https://groww.in/trade-api/docs/python-sdk/portfolio Provides the API endpoint details for retrieving position information for a specific trading symbol. It includes the request parameters, their types and requirements, and a comprehensive response schema detailing the structure of the returned position data. ```APIDOC ## Get Position for Symbol Retrieve detailed position information for a specific symbol using this `get_position_for_trading_symbol`. ### Request Schema | Name | Type | Description | | --- | --- | --- | | trading_symbol `*` | string | Trading symbol of the instrument. | | segment `*` | string | [Segment](/trade-api/docs/python-sdk/annexures#segment) of the instrument such as CASH, FNO etc. | `*`required parameter ### Response Payload All prices in rupees ```json { "positions": [ { "trading_symbol": "RELIANCE", "segment": "CASH", "credit_quantity": 10, "credit_price": 12500, "debit_quantity": 5, "debit_price": 12000, "carry_forward_credit_quantity": 8, "carry_forward_credit_price": 12300, "carry_forward_debit_quantity": 3, "carry_forward_debit_price": 11800, "exchange": "NSE", "symbol_isin": "INE123A01016", "quantity": 15, "product": "CNC", "net_carry_forward_quantity": 10, "net_price": 12400, "net_carry_forward_price": 12200 } ] } ``` #### Response Schema | Name | Type | Description | | --- | --- | --- | | trading_symbol | string | Trading symbol of the instrument. | | segment | string | [Segment](/trade-api/docs/python-sdk/annexures#segment) of the instrument such as CASH, FNO etc. | | credit_quantity | int | Quantity of credited instruments | | credit_price | int | Average price in rupees of credited instruments | | debit_quantity | int | Quantity of debited instruments | | debit_price | int | Average price in rupees of debited instruments | | carry_forward_credit_quantity | int | Quantity of carry forward credited instruments | | carry_forward_credit_price | int | Average price in rupees of carry forward credited instruments | | carry_forward_debit_quantity | int | Quantity of carry forward debited instruments | | carry_forward_debit_price | int | Average price in rupees of carry forward debited instruments | | exchange | string | [Stock exchange](/trade-api/docs/python-sdk/annexures#exchange) | | symbol_isin | string | ISIN (International Securities Identification number) of the symbol | | quantity | int | Net quantity of instruments | | product | string | [Product type](/trade-api/docs/python-sdk/annexures#product) | | net_carry_forward_quantity | int | Net carry forward quantity of instruments | | net_price | int | Net average price in rupees of instruments | | net_carry_forward_price | int | Net average price in rupees of carry forward instruments | ```