upstox-python-sdk


Nameupstox-python-sdk JSON
Version 2.4.0 PyPI version JSON
download
home_pagehttps://github.com/upstox/upstox-python
SummaryUpstox Developer API
upload_time2024-03-04 14:21:38
maintainer
docs_urlNone
author
requires_python
licenseMIT
keywords upstox developer api
VCS
bugtrack_url
requirements certifi six python_dateutil setuptools urllib3
Travis-CI
coveralls test coverage No coveralls.
            # Upstox Python SDK for API v2

[![PyPI](https://img.shields.io/pypi/v/upstox-python-sdk?label=upstox-python-sdk)](https://pypi.python.org/pypi/upstox-python-sdk)

## Introduction

The official Python client for communicating with the <a href="https://upstox.com/uplink/">Upstox API</a>.

Upstox API is a set of rest APIs that provide data required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (using Websocket), and more, with the easy to understand API collection. 

- API version: v2
- Package version: 2.4.0
- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen

This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project.

## Documentation.

<a href="https://upstox.com/developer/api-documentation">Upstox API Documentation</a>

## Requirements.

Python 2.7 and 3.4+

## Installation & Usage
### pip install

If the python package is hosted on Github, you can install directly from Github

```sh
pip install upstox-python-sdk
```
(you may need to run `pip` with root permission: `sudo pip install upstox-python-sdk`)

Then import the package:
```python
import upstox_client 
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).

```sh
python setup.py install --user
```
(or `sudo python setup.py install` to install the package for all users)

Then import the package:
```python
import upstox_client
```

## Examples

[Sample Implementations](examples/) can be found within `/examples` folder.

- [Websocket Market data](examples/websocket/market_data/)
- [Websocket Order updates](examples/websocket/order_updates/)

## Documentation for API Endpoints

All URIs are relative to *https://api-v2.upstox.com*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*ChargeApi* | [**get_brokerage**](docs/ChargeApi.md#get_brokerage) | **GET** /charges/brokerage | Brokerage details
*HistoryApi* | [**get_historical_candle_data**](docs/HistoryApi.md#get_historical_candle_data) | **GET** /historical-candle/{instrumentKey}/{interval}/{to_date} | Historical candle data
*HistoryApi* | [**get_historical_candle_data1**](docs/HistoryApi.md#get_historical_candle_data1) | **GET** /historical-candle/{instrumentKey}/{interval}/{to_date}/{from_date} | Historical candle data
*HistoryApi* | [**get_intra_day_candle_data**](docs/HistoryApi.md#get_intra_day_candle_data) | **GET** /historical-candle/intraday/{instrumentKey}/{interval} | Intra day candle data
*LoginApi* | [**authorize**](docs/LoginApi.md#authorize) | **GET** /login/authorization/dialog | Authorize API
*LoginApi* | [**logout**](docs/LoginApi.md#logout) | **DELETE** /logout | Logout
*LoginApi* | [**token**](docs/LoginApi.md#token) | **POST** /login/authorization/token | Get token API
*MarketQuoteApi* | [**get_full_market_quote**](docs/MarketQuoteApi.md#get_full_market_quote) | **GET** /market-quote/quotes | Market quotes and instruments - Full market quotes
*MarketQuoteApi* | [**get_market_quote_ohlc**](docs/MarketQuoteApi.md#get_market_quote_ohlc) | **GET** /market-quote/ohlc | Market quotes and instruments - OHLC quotes
*MarketQuoteApi* | [**ltp**](docs/MarketQuoteApi.md#ltp) | **GET** /market-quote/ltp | Market quotes and instruments - LTP quotes.
*OrderApi* | [**cancel_order**](docs/OrderApi.md#cancel_order) | **DELETE** /order/cancel | Cancel order
*OrderApi* | [**get_order_book**](docs/OrderApi.md#get_order_book) | **GET** /order/retrieve-all | Get order book
*OrderApi* | [**get_order_details**](docs/OrderApi.md#get_order_details) | **GET** /order/history | Get order details
*OrderApi* | [**get_trade_history**](docs/OrderApi.md#get_trade_history) | **GET** /order/trades/get-trades-for-day | Get trades
*OrderApi* | [**get_trades_by_order**](docs/OrderApi.md#get_trades_by_order) | **GET** /order/trades | Get trades for order
*OrderApi* | [**modify_order**](docs/OrderApi.md#modify_order) | **PUT** /order/modify | Modify order
*OrderApi* | [**place_order**](docs/OrderApi.md#place_order) | **POST** /order/place | Place order
*PortfolioApi* | [**convert_positions**](docs/PortfolioApi.md#convert_positions) | **PUT** /portfolio/convert-position | Convert Positions
*PortfolioApi* | [**get_holdings**](docs/PortfolioApi.md#get_holdings) | **GET** /portfolio/long-term-holdings | Get Holdings
*PortfolioApi* | [**get_positions**](docs/PortfolioApi.md#get_positions) | **GET** /portfolio/short-term-positions | Get Positions
*TradeProfitAndLossApi* | [**get_profit_and_loss_charges**](docs/TradeProfitAndLossApi.md#get_profit_and_loss_charges) | **GET** /trade/profit-loss/charges | Get profit and loss on trades
*TradeProfitAndLossApi* | [**get_trade_wise_profit_and_loss_data**](docs/TradeProfitAndLossApi.md#get_trade_wise_profit_and_loss_data) | **GET** /trade/profit-loss/data | Get Trade-wise Profit and Loss Report Data
*TradeProfitAndLossApi* | [**get_trade_wise_profit_and_loss_meta_data**](docs/TradeProfitAndLossApi.md#get_trade_wise_profit_and_loss_meta_data) | **GET** /trade/profit-loss/metadata | Get profit and loss meta data on trades
*UserApi* | [**get_profile**](docs/UserApi.md#get_profile) | **GET** /user/profile | Get profile
*UserApi* | [**get_user_fund_margin**](docs/UserApi.md#get_user_fund_margin) | **GET** /user/get-funds-and-margin | Get User Fund And Margin
*WebsocketApi* | [**get_market_data_feed**](docs/WebsocketApi.md#get_market_data_feed) | **GET** /feed/market-data-feed | Market Data Feed
*WebsocketApi* | [**get_market_data_feed_authorize**](docs/WebsocketApi.md#get_market_data_feed_authorize) | **GET** /feed/market-data-feed/authorize | Market Data Feed Authorize
*WebsocketApi* | [**get_portfolio_stream_feed**](docs/WebsocketApi.md#get_portfolio_stream_feed) | **GET** /feed/portfolio-stream-feed | Portfolio Stream Feed
*WebsocketApi* | [**get_portfolio_stream_feed_authorize**](docs/WebsocketApi.md#get_portfolio_stream_feed_authorize) | **GET** /feed/portfolio-stream-feed/authorize | Portfolio Stream Feed Authorize

## Documentation for Feeder Functions

Connecting to the WebSocket for market and portfolio updates is streamlined through two primary Feeder functions:

1. **MarketDataStreamer**: Offers real-time market updates, providing a seamless way to receive instantaneous information on various market instruments.
2. **PortfolioDataStreamer**: Delivers updates related to the user's orders, enhancing the ability to track order status and portfolio changes effectively.

Both functions are designed to simplify the process of subscribing to essential data streams, ensuring users have quick and easy access to the information they need.

### Detailed Explanation of Feeder Interface

### MarketDataStreamer

The `MarketDataStreamer` interface is designed for effortless connection to the market WebSocket, enabling users to receive instantaneous updates on various instruments. The following example demonstrates how to quickly set up and start receiving market updates for selected instrument keys:

```python
import upstox_client

def on_message(message):
    print(message)


def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration), ["NSE_INDEX|Nifty 50", "NSE_INDEX|Bank Nifty"], "full")

    streamer.on("message", on_message)

    streamer.connect()


if __name__ == "__main__":
    main()
```

In this example, you first authenticate using an access token, then instantiate MarketDataStreamer with specific instrument keys and a subscription mode. Upon connecting, the streamer listens for market updates, which are logged to the console as they arrive.

Feel free to adjust the access token placeholder and any other specifics to better fit your actual implementation or usage scenario.

### Exploring the MarketDataStreamer Functionality

#### Modes
- **ltpc**: ltpc provides information solely about the most recent trade, encompassing details such as the last trade price, time of the last trade, quantity traded, and the closing price from the previous day.
- **full**: The full option offers comprehensive information, including the latest trade prices, D5 depth, 1-minute, 30-minute, and daily candlestick data, along with some additional details.

#### Functions
1. **constructor MarketDataStreamer(apiClient, instrumentKeys, mode)**: Initializes the streamer with optional instrument keys and mode (`full` or `ltpc`).
2. **connect()**: Establishes the WebSocket connection.
3. **subscribe(instrumentKeys, mode)**: Subscribes to updates for given instrument keys in the specified mode. Both parameters are mandatory.
4. **unsubscribe(instrumentKeys)**: Stops updates for the specified instrument keys.
5. **changeMode(instrumentKeys, mode)**: Switches the mode for already subscribed instrument keys.
6. **disconnect()**: Ends the active WebSocket connection.
7. **auto_reconnect(enable, interval, retryCount)**: Customizes auto-reconnect functionality. Parameters include a flag to enable/disable it, the interval(in seconds) between attempts, and the maximum number of retries.

#### Events
- **open**: Emitted upon successful connection establishment.
- **close**: Indicates the WebSocket connection has been closed.
- **message**: Delivers market updates.
- **error**: Signals an error has occurred.
- **reconnecting**: Announced when a reconnect attempt is initiated.
- **autoReconnectStopped**: Informs when auto-reconnect efforts have ceased after exhausting the retry count.

The following documentation includes examples to illustrate the usage of these functions and events, providing a practical understanding of how to interact with the MarketDataStreamer effectively.

<br/>

1. Subscribing to Market Data on Connection Open with MarketDataStreamer

```python
import upstox_client

def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration))

    def on_open():
        streamer.subscribe(
            ["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "full")

    def on_message(message):
        print(message)

    streamer.on("open", on_open)
    streamer.on("message", on_message)

    streamer.connect()

if __name__ == "__main__":
    main()
```

<br/>

2. Subscribing to Instruments with Delays

```python
import upstox_client
import time


def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration))

    def on_open():
        streamer.subscribe(
            ["NSE_EQ|INE020B01018"], "full")

    # Handle incoming market data messages\
    def on_message(message):
        print(message)

    streamer.on("open", on_open)
    streamer.on("message", on_message)

    streamer.connect()

    time.sleep(5)
    streamer.subscribe(
        ["NSE_EQ|INE467B01029"], "full")


if __name__ == "__main__":
    main()

```

<br/>

3. Subscribing and Unsubscribing to Instruments

```python
import upstox_client
import time


def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration))

    def on_open():
        print("Connected. Subscribing to instrument keys.")
        streamer.subscribe(
            ["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "full")

    # Handle incoming market data messages\
    def on_message(message):
        print(message)

    streamer.on("open", on_open)
    streamer.on("message", on_message)

    streamer.connect()

    time.sleep(5)
    print("Unsubscribing from instrument keys.")
    streamer.unsubscribe(["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"])


if __name__ == "__main__":
    main()
```

<br/>

4. Subscribe, Change Mode and Unsubscribe

```python
import upstox_client
import time

def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration))

    def on_open():
        print("Connected. Subscribing to instrument keys.")
        streamer.subscribe(
            ["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "full")

    # Handle incoming market data messages\
    def on_message(message):
        print(message)

    streamer.on("open", on_open)
    streamer.on("message", on_message)

    streamer.connect()

    time.sleep(5)
    print("Changing subscription mode to ltpc...")
    streamer.change_mode(
        ["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"], "ltpc")

    time.sleep(5)
    print("Unsubscribing from instrument keys.")
    streamer.unsubscribe(["NSE_EQ|INE020B01018", "NSE_EQ|INE467B01029"])


if __name__ == "__main__":
    main()
```

<br/>

5. Disable Auto-Reconnect

```python
import upstox_client
import time


def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration))

    def on_reconnection_halt(message):
        print(message)

    streamer.on("autoReconnectStopped", on_reconnection_halt)

    # Disable auto-reconnect feature
    streamer.auto_reconnect(False)

    streamer.connect()


if __name__ == "__main__":
    main()
```

<br/>

6. Modify Auto-Reconnect parameters

```python
import upstox_client


def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.MarketDataStreamer(
        upstox_client.ApiClient(configuration))

    # Modify auto-reconnect parameters: enable it, set interval to 10 seconds, and retry count to 3
    streamer.auto_reconnect(True, 10, 3)

    streamer.connect()


if __name__ == "__main__":
    main()
```

<br/>

### PortfolioDataStreamer

Connecting to the Portfolio WebSocket for real-time order updates is straightforward with the PortfolioDataStreamer function. Below is a concise guide to get you started on receiving updates:

```python
import upstox_client

def on_message(message):
    print(message)


def main():
    configuration = upstox_client.Configuration()
    access_token = <ACCESS_TOKEN>
    configuration.access_token = access_token

    streamer = upstox_client.PortfolioDataStreamer(
        upstox_client.ApiClient(configuration))

    streamer.on("message", on_message)

    streamer.connect()


if __name__ == "__main__":
    main()
```

This example demonstrates initializing the PortfolioDataStreamer, connecting it to the WebSocket, and setting up an event listener to receive and print order updates. Replace <ACCESS_TOKEN> with your valid access token to authenticate the session.

### Exploring the PortfolioDataStreamer Functionality

#### Functions
1. **constructor PortfolioDataStreamer()**: Initializes the streamer.
2. **connect()**: Establishes the WebSocket connection.
6. **disconnect()**: Ends the active WebSocket connection.
7. **auto_reconnect(enable, interval, retryCount)**: Customizes auto-reconnect functionality. Parameters include a flag to enable/disable it, the interval(in seconds) between attempts, and the maximum number of retries.

#### Events
- **open**: Emitted upon successful connection establishment.
- **close**: Indicates the WebSocket connection has been closed.
- **message**: Delivers market updates.
- **error**: Signals an error has occurred.
- **reconnecting**: Announced when a reconnect attempt is initiated.
- **autoReconnectStopped**: Informs when auto-reconnect efforts have ceased after exhausting the retry count.

## Documentation For Models

 - [ApiGatewayErrorResponse](docs/ApiGatewayErrorResponse.md)
 - [BrokerageData](docs/BrokerageData.md)
 - [BrokerageTaxes](docs/BrokerageTaxes.md)
 - [BrokerageWrapperData](docs/BrokerageWrapperData.md)
 - [CancelOrderData](docs/CancelOrderData.md)
 - [CancelOrderResponse](docs/CancelOrderResponse.md)
 - [ConvertPositionData](docs/ConvertPositionData.md)
 - [ConvertPositionRequest](docs/ConvertPositionRequest.md)
 - [ConvertPositionResponse](docs/ConvertPositionResponse.md)
 - [Depth](docs/Depth.md)
 - [DepthMap](docs/DepthMap.md)
 - [DpPlan](docs/DpPlan.md)
 - [GetBrokerageResponse](docs/GetBrokerageResponse.md)
 - [GetFullMarketQuoteResponse](docs/GetFullMarketQuoteResponse.md)
 - [GetHistoricalCandleResponse](docs/GetHistoricalCandleResponse.md)
 - [GetHoldingsResponse](docs/GetHoldingsResponse.md)
 - [GetIntraDayCandleResponse](docs/GetIntraDayCandleResponse.md)
 - [GetMarketQuoteLastTradedPriceResponse](docs/GetMarketQuoteLastTradedPriceResponse.md)
 - [GetMarketQuoteOHLCResponse](docs/GetMarketQuoteOHLCResponse.md)
 - [GetOrderBookResponse](docs/GetOrderBookResponse.md)
 - [GetOrderResponse](docs/GetOrderResponse.md)
 - [GetPositionResponse](docs/GetPositionResponse.md)
 - [GetProfileResponse](docs/GetProfileResponse.md)
 - [GetProfitAndLossChargesResponse](docs/GetProfitAndLossChargesResponse.md)
 - [GetTradeResponse](docs/GetTradeResponse.md)
 - [GetTradeWiseProfitAndLossDataResponse](docs/GetTradeWiseProfitAndLossDataResponse.md)
 - [GetTradeWiseProfitAndLossMetaDataResponse](docs/GetTradeWiseProfitAndLossMetaDataResponse.md)
 - [GetUserFundMarginResponse](docs/GetUserFundMarginResponse.md)
 - [HistoricalCandleData](docs/HistoricalCandleData.md)
 - [HoldingsData](docs/HoldingsData.md)
 - [IntraDayCandleData](docs/IntraDayCandleData.md)
 - [LogoutResponse](docs/LogoutResponse.md)
 - [MarketQuoteOHLC](docs/MarketQuoteOHLC.md)
 - [MarketQuoteSymbol](docs/MarketQuoteSymbol.md)
 - [MarketQuoteSymbolLtp](docs/MarketQuoteSymbolLtp.md)
 - [ModifyOrderData](docs/ModifyOrderData.md)
 - [ModifyOrderRequest](docs/ModifyOrderRequest.md)
 - [ModifyOrderResponse](docs/ModifyOrderResponse.md)
 - [OAuthClientException](docs/OAuthClientException.md)
 - [OAuthClientExceptionCause](docs/OAuthClientExceptionCause.md)
 - [OAuthClientExceptionCauseStackTrace](docs/OAuthClientExceptionCauseStackTrace.md)
 - [OAuthClientExceptionCauseSuppressed](docs/OAuthClientExceptionCauseSuppressed.md)
 - [Ohlc](docs/Ohlc.md)
 - [OrderBookData](docs/OrderBookData.md)
 - [OrderData](docs/OrderData.md)
 - [OtherTaxes](docs/OtherTaxes.md)
 - [PlaceOrderData](docs/PlaceOrderData.md)
 - [PlaceOrderRequest](docs/PlaceOrderRequest.md)
 - [PlaceOrderResponse](docs/PlaceOrderResponse.md)
 - [PositionData](docs/PositionData.md)
 - [Problem](docs/Problem.md)
 - [ProfileData](docs/ProfileData.md)
 - [ProfitAndLossChargesData](docs/ProfitAndLossChargesData.md)
 - [ProfitAndLossChargesTaxes](docs/ProfitAndLossChargesTaxes.md)
 - [ProfitAndLossChargesWrapperData](docs/ProfitAndLossChargesWrapperData.md)
 - [ProfitAndLossMetaData](docs/ProfitAndLossMetaData.md)
 - [ProfitAndLossMetaDataWrapper](docs/ProfitAndLossMetaDataWrapper.md)
 - [ProfitAndLossOtherChargesTaxes](docs/ProfitAndLossOtherChargesTaxes.md)
 - [TokenRequest](docs/TokenRequest.md)
 - [TokenResponse](docs/TokenResponse.md)
 - [TradeData](docs/TradeData.md)
 - [TradeWiseMetaData](docs/TradeWiseMetaData.md)
 - [TradeWiseProfitAndLossData](docs/TradeWiseProfitAndLossData.md)
 - [UserFundMarginData](docs/UserFundMarginData.md)
 - [WebsocketAuthRedirectResponse](docs/WebsocketAuthRedirectResponse.md)
 - [WebsocketAuthRedirectResponseData](docs/WebsocketAuthRedirectResponseData.md)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/upstox/upstox-python",
    "name": "upstox-python-sdk",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Upstox Developer API",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/0d/99/6ef82291b9fffd3ac52cbcc134f8d4f587216acc9251103d37db3c8fb974/upstox-python-sdk-2.4.0.tar.gz",
    "platform": null,
    "description": "# Upstox Python SDK for API v2\n\n[![PyPI](https://img.shields.io/pypi/v/upstox-python-sdk?label=upstox-python-sdk)](https://pypi.python.org/pypi/upstox-python-sdk)\n\n## Introduction\n\nThe official Python client for communicating with the <a href=\"https://upstox.com/uplink/\">Upstox API</a>.\n\nUpstox API is a set of rest APIs that provide data required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (using Websocket), and more, with the easy to understand API collection. \n\n- API version: v2\n- Package version: 2.4.0\n- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen\n\nThis Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project.\n\n## Documentation.\n\n<a href=\"https://upstox.com/developer/api-documentation\">Upstox API Documentation</a>\n\n## Requirements.\n\nPython 2.7 and 3.4+\n\n## Installation & Usage\n### pip install\n\nIf the python package is hosted on Github, you can install directly from Github\n\n```sh\npip install upstox-python-sdk\n```\n(you may need to run `pip` with root permission: `sudo pip install upstox-python-sdk`)\n\nThen import the package:\n```python\nimport upstox_client \n```\n\n### Setuptools\n\nInstall via [Setuptools](http://pypi.python.org/pypi/setuptools).\n\n```sh\npython setup.py install --user\n```\n(or `sudo python setup.py install` to install the package for all users)\n\nThen import the package:\n```python\nimport upstox_client\n```\n\n## Examples\n\n[Sample Implementations](examples/) can be found within `/examples` folder.\n\n- [Websocket Market data](examples/websocket/market_data/)\n- [Websocket Order updates](examples/websocket/order_updates/)\n\n## Documentation for API Endpoints\n\nAll URIs are relative to *https://api-v2.upstox.com*\n\nClass | Method | HTTP request | Description\n------------ | ------------- | ------------- | -------------\n*ChargeApi* | [**get_brokerage**](docs/ChargeApi.md#get_brokerage) | **GET** /charges/brokerage | Brokerage details\n*HistoryApi* | [**get_historical_candle_data**](docs/HistoryApi.md#get_historical_candle_data) | **GET** /historical-candle/{instrumentKey}/{interval}/{to_date} | Historical candle data\n*HistoryApi* | [**get_historical_candle_data1**](docs/HistoryApi.md#get_historical_candle_data1) | **GET** /historical-candle/{instrumentKey}/{interval}/{to_date}/{from_date} | Historical candle data\n*HistoryApi* | [**get_intra_day_candle_data**](docs/HistoryApi.md#get_intra_day_candle_data) | **GET** /historical-candle/intraday/{instrumentKey}/{interval} | Intra day candle data\n*LoginApi* | [**authorize**](docs/LoginApi.md#authorize) | **GET** /login/authorization/dialog | Authorize API\n*LoginApi* | [**logout**](docs/LoginApi.md#logout) | **DELETE** /logout | Logout\n*LoginApi* | [**token**](docs/LoginApi.md#token) | **POST** /login/authorization/token | Get token API\n*MarketQuoteApi* | [**get_full_market_quote**](docs/MarketQuoteApi.md#get_full_market_quote) | **GET** /market-quote/quotes | Market quotes and instruments - Full market quotes\n*MarketQuoteApi* | [**get_market_quote_ohlc**](docs/MarketQuoteApi.md#get_market_quote_ohlc) | **GET** /market-quote/ohlc | Market quotes and instruments - OHLC quotes\n*MarketQuoteApi* | [**ltp**](docs/MarketQuoteApi.md#ltp) | **GET** /market-quote/ltp | Market quotes and instruments - LTP quotes.\n*OrderApi* | [**cancel_order**](docs/OrderApi.md#cancel_order) | **DELETE** /order/cancel | Cancel order\n*OrderApi* | [**get_order_book**](docs/OrderApi.md#get_order_book) | **GET** /order/retrieve-all | Get order book\n*OrderApi* | [**get_order_details**](docs/OrderApi.md#get_order_details) | **GET** /order/history | Get order details\n*OrderApi* | [**get_trade_history**](docs/OrderApi.md#get_trade_history) | **GET** /order/trades/get-trades-for-day | Get trades\n*OrderApi* | [**get_trades_by_order**](docs/OrderApi.md#get_trades_by_order) | **GET** /order/trades | Get trades for order\n*OrderApi* | [**modify_order**](docs/OrderApi.md#modify_order) | **PUT** /order/modify | Modify order\n*OrderApi* | [**place_order**](docs/OrderApi.md#place_order) | **POST** /order/place | Place order\n*PortfolioApi* | [**convert_positions**](docs/PortfolioApi.md#convert_positions) | **PUT** /portfolio/convert-position | Convert Positions\n*PortfolioApi* | [**get_holdings**](docs/PortfolioApi.md#get_holdings) | **GET** /portfolio/long-term-holdings | Get Holdings\n*PortfolioApi* | [**get_positions**](docs/PortfolioApi.md#get_positions) | **GET** /portfolio/short-term-positions | Get Positions\n*TradeProfitAndLossApi* | [**get_profit_and_loss_charges**](docs/TradeProfitAndLossApi.md#get_profit_and_loss_charges) | **GET** /trade/profit-loss/charges | Get profit and loss on trades\n*TradeProfitAndLossApi* | [**get_trade_wise_profit_and_loss_data**](docs/TradeProfitAndLossApi.md#get_trade_wise_profit_and_loss_data) | **GET** /trade/profit-loss/data | Get Trade-wise Profit and Loss Report Data\n*TradeProfitAndLossApi* | [**get_trade_wise_profit_and_loss_meta_data**](docs/TradeProfitAndLossApi.md#get_trade_wise_profit_and_loss_meta_data) | **GET** /trade/profit-loss/metadata | Get profit and loss meta data on trades\n*UserApi* | [**get_profile**](docs/UserApi.md#get_profile) | **GET** /user/profile | Get profile\n*UserApi* | [**get_user_fund_margin**](docs/UserApi.md#get_user_fund_margin) | **GET** /user/get-funds-and-margin | Get User Fund And Margin\n*WebsocketApi* | [**get_market_data_feed**](docs/WebsocketApi.md#get_market_data_feed) | **GET** /feed/market-data-feed | Market Data Feed\n*WebsocketApi* | [**get_market_data_feed_authorize**](docs/WebsocketApi.md#get_market_data_feed_authorize) | **GET** /feed/market-data-feed/authorize | Market Data Feed Authorize\n*WebsocketApi* | [**get_portfolio_stream_feed**](docs/WebsocketApi.md#get_portfolio_stream_feed) | **GET** /feed/portfolio-stream-feed | Portfolio Stream Feed\n*WebsocketApi* | [**get_portfolio_stream_feed_authorize**](docs/WebsocketApi.md#get_portfolio_stream_feed_authorize) | **GET** /feed/portfolio-stream-feed/authorize | Portfolio Stream Feed Authorize\n\n## Documentation for Feeder Functions\n\nConnecting to the WebSocket for market and portfolio updates is streamlined through two primary Feeder functions:\n\n1. **MarketDataStreamer**: Offers real-time market updates, providing a seamless way to receive instantaneous information on various market instruments.\n2. **PortfolioDataStreamer**: Delivers updates related to the user's orders, enhancing the ability to track order status and portfolio changes effectively.\n\nBoth functions are designed to simplify the process of subscribing to essential data streams, ensuring users have quick and easy access to the information they need.\n\n### Detailed Explanation of Feeder Interface\n\n### MarketDataStreamer\n\nThe `MarketDataStreamer` interface is designed for effortless connection to the market WebSocket, enabling users to receive instantaneous updates on various instruments. The following example demonstrates how to quickly set up and start receiving market updates for selected instrument keys:\n\n```python\nimport upstox_client\n\ndef on_message(message):\n    print(message)\n\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration), [\"NSE_INDEX|Nifty 50\", \"NSE_INDEX|Bank Nifty\"], \"full\")\n\n    streamer.on(\"message\", on_message)\n\n    streamer.connect()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\nIn this example, you first authenticate using an access token, then instantiate MarketDataStreamer with specific instrument keys and a subscription mode. Upon connecting, the streamer listens for market updates, which are logged to the console as they arrive.\n\nFeel free to adjust the access token placeholder and any other specifics to better fit your actual implementation or usage scenario.\n\n### Exploring the MarketDataStreamer Functionality\n\n#### Modes\n- **ltpc**: ltpc provides information solely about the most recent trade, encompassing details such as the last trade price, time of the last trade, quantity traded, and the closing price from the previous day.\n- **full**: The full option offers comprehensive information, including the latest trade prices, D5 depth, 1-minute, 30-minute, and daily candlestick data, along with some additional details.\n\n#### Functions\n1. **constructor MarketDataStreamer(apiClient, instrumentKeys, mode)**: Initializes the streamer with optional instrument keys and mode (`full` or `ltpc`).\n2. **connect()**: Establishes the WebSocket connection.\n3. **subscribe(instrumentKeys, mode)**: Subscribes to updates for given instrument keys in the specified mode. Both parameters are mandatory.\n4. **unsubscribe(instrumentKeys)**: Stops updates for the specified instrument keys.\n5. **changeMode(instrumentKeys, mode)**: Switches the mode for already subscribed instrument keys.\n6. **disconnect()**: Ends the active WebSocket connection.\n7. **auto_reconnect(enable, interval, retryCount)**: Customizes auto-reconnect functionality. Parameters include a flag to enable/disable it, the interval(in seconds) between attempts, and the maximum number of retries.\n\n#### Events\n- **open**: Emitted upon successful connection establishment.\n- **close**: Indicates the WebSocket connection has been closed.\n- **message**: Delivers market updates.\n- **error**: Signals an error has occurred.\n- **reconnecting**: Announced when a reconnect attempt is initiated.\n- **autoReconnectStopped**: Informs when auto-reconnect efforts have ceased after exhausting the retry count.\n\nThe following documentation includes examples to illustrate the usage of these functions and events, providing a practical understanding of how to interact with the MarketDataStreamer effectively.\n\n<br/>\n\n1. Subscribing to Market Data on Connection Open with MarketDataStreamer\n\n```python\nimport upstox_client\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    def on_open():\n        streamer.subscribe(\n            [\"NSE_EQ|INE020B01018\", \"NSE_EQ|INE467B01029\"], \"full\")\n\n    def on_message(message):\n        print(message)\n\n    streamer.on(\"open\", on_open)\n    streamer.on(\"message\", on_message)\n\n    streamer.connect()\n\nif __name__ == \"__main__\":\n    main()\n```\n\n<br/>\n\n2. Subscribing to Instruments with Delays\n\n```python\nimport upstox_client\nimport time\n\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    def on_open():\n        streamer.subscribe(\n            [\"NSE_EQ|INE020B01018\"], \"full\")\n\n    # Handle incoming market data messages\\\n    def on_message(message):\n        print(message)\n\n    streamer.on(\"open\", on_open)\n    streamer.on(\"message\", on_message)\n\n    streamer.connect()\n\n    time.sleep(5)\n    streamer.subscribe(\n        [\"NSE_EQ|INE467B01029\"], \"full\")\n\n\nif __name__ == \"__main__\":\n    main()\n\n```\n\n<br/>\n\n3. Subscribing and Unsubscribing to Instruments\n\n```python\nimport upstox_client\nimport time\n\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    def on_open():\n        print(\"Connected. Subscribing to instrument keys.\")\n        streamer.subscribe(\n            [\"NSE_EQ|INE020B01018\", \"NSE_EQ|INE467B01029\"], \"full\")\n\n    # Handle incoming market data messages\\\n    def on_message(message):\n        print(message)\n\n    streamer.on(\"open\", on_open)\n    streamer.on(\"message\", on_message)\n\n    streamer.connect()\n\n    time.sleep(5)\n    print(\"Unsubscribing from instrument keys.\")\n    streamer.unsubscribe([\"NSE_EQ|INE020B01018\", \"NSE_EQ|INE467B01029\"])\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n<br/>\n\n4. Subscribe, Change Mode and Unsubscribe\n\n```python\nimport upstox_client\nimport time\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    def on_open():\n        print(\"Connected. Subscribing to instrument keys.\")\n        streamer.subscribe(\n            [\"NSE_EQ|INE020B01018\", \"NSE_EQ|INE467B01029\"], \"full\")\n\n    # Handle incoming market data messages\\\n    def on_message(message):\n        print(message)\n\n    streamer.on(\"open\", on_open)\n    streamer.on(\"message\", on_message)\n\n    streamer.connect()\n\n    time.sleep(5)\n    print(\"Changing subscription mode to ltpc...\")\n    streamer.change_mode(\n        [\"NSE_EQ|INE020B01018\", \"NSE_EQ|INE467B01029\"], \"ltpc\")\n\n    time.sleep(5)\n    print(\"Unsubscribing from instrument keys.\")\n    streamer.unsubscribe([\"NSE_EQ|INE020B01018\", \"NSE_EQ|INE467B01029\"])\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n<br/>\n\n5. Disable Auto-Reconnect\n\n```python\nimport upstox_client\nimport time\n\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    def on_reconnection_halt(message):\n        print(message)\n\n    streamer.on(\"autoReconnectStopped\", on_reconnection_halt)\n\n    # Disable auto-reconnect feature\n    streamer.auto_reconnect(False)\n\n    streamer.connect()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n<br/>\n\n6. Modify Auto-Reconnect parameters\n\n```python\nimport upstox_client\n\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.MarketDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    # Modify auto-reconnect parameters: enable it, set interval to 10 seconds, and retry count to 3\n    streamer.auto_reconnect(True, 10, 3)\n\n    streamer.connect()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\n<br/>\n\n### PortfolioDataStreamer\n\nConnecting to the Portfolio WebSocket for real-time order updates is straightforward with the PortfolioDataStreamer function. Below is a concise guide to get you started on receiving updates:\n\n```python\nimport upstox_client\n\ndef on_message(message):\n    print(message)\n\n\ndef main():\n    configuration = upstox_client.Configuration()\n    access_token = <ACCESS_TOKEN>\n    configuration.access_token = access_token\n\n    streamer = upstox_client.PortfolioDataStreamer(\n        upstox_client.ApiClient(configuration))\n\n    streamer.on(\"message\", on_message)\n\n    streamer.connect()\n\n\nif __name__ == \"__main__\":\n    main()\n```\n\nThis example demonstrates initializing the PortfolioDataStreamer, connecting it to the WebSocket, and setting up an event listener to receive and print order updates. Replace <ACCESS_TOKEN> with your valid access token to authenticate the session.\n\n### Exploring the PortfolioDataStreamer Functionality\n\n#### Functions\n1. **constructor PortfolioDataStreamer()**: Initializes the streamer.\n2. **connect()**: Establishes the WebSocket connection.\n6. **disconnect()**: Ends the active WebSocket connection.\n7. **auto_reconnect(enable, interval, retryCount)**: Customizes auto-reconnect functionality. Parameters include a flag to enable/disable it, the interval(in seconds) between attempts, and the maximum number of retries.\n\n#### Events\n- **open**: Emitted upon successful connection establishment.\n- **close**: Indicates the WebSocket connection has been closed.\n- **message**: Delivers market updates.\n- **error**: Signals an error has occurred.\n- **reconnecting**: Announced when a reconnect attempt is initiated.\n- **autoReconnectStopped**: Informs when auto-reconnect efforts have ceased after exhausting the retry count.\n\n## Documentation For Models\n\n - [ApiGatewayErrorResponse](docs/ApiGatewayErrorResponse.md)\n - [BrokerageData](docs/BrokerageData.md)\n - [BrokerageTaxes](docs/BrokerageTaxes.md)\n - [BrokerageWrapperData](docs/BrokerageWrapperData.md)\n - [CancelOrderData](docs/CancelOrderData.md)\n - [CancelOrderResponse](docs/CancelOrderResponse.md)\n - [ConvertPositionData](docs/ConvertPositionData.md)\n - [ConvertPositionRequest](docs/ConvertPositionRequest.md)\n - [ConvertPositionResponse](docs/ConvertPositionResponse.md)\n - [Depth](docs/Depth.md)\n - [DepthMap](docs/DepthMap.md)\n - [DpPlan](docs/DpPlan.md)\n - [GetBrokerageResponse](docs/GetBrokerageResponse.md)\n - [GetFullMarketQuoteResponse](docs/GetFullMarketQuoteResponse.md)\n - [GetHistoricalCandleResponse](docs/GetHistoricalCandleResponse.md)\n - [GetHoldingsResponse](docs/GetHoldingsResponse.md)\n - [GetIntraDayCandleResponse](docs/GetIntraDayCandleResponse.md)\n - [GetMarketQuoteLastTradedPriceResponse](docs/GetMarketQuoteLastTradedPriceResponse.md)\n - [GetMarketQuoteOHLCResponse](docs/GetMarketQuoteOHLCResponse.md)\n - [GetOrderBookResponse](docs/GetOrderBookResponse.md)\n - [GetOrderResponse](docs/GetOrderResponse.md)\n - [GetPositionResponse](docs/GetPositionResponse.md)\n - [GetProfileResponse](docs/GetProfileResponse.md)\n - [GetProfitAndLossChargesResponse](docs/GetProfitAndLossChargesResponse.md)\n - [GetTradeResponse](docs/GetTradeResponse.md)\n - [GetTradeWiseProfitAndLossDataResponse](docs/GetTradeWiseProfitAndLossDataResponse.md)\n - [GetTradeWiseProfitAndLossMetaDataResponse](docs/GetTradeWiseProfitAndLossMetaDataResponse.md)\n - [GetUserFundMarginResponse](docs/GetUserFundMarginResponse.md)\n - [HistoricalCandleData](docs/HistoricalCandleData.md)\n - [HoldingsData](docs/HoldingsData.md)\n - [IntraDayCandleData](docs/IntraDayCandleData.md)\n - [LogoutResponse](docs/LogoutResponse.md)\n - [MarketQuoteOHLC](docs/MarketQuoteOHLC.md)\n - [MarketQuoteSymbol](docs/MarketQuoteSymbol.md)\n - [MarketQuoteSymbolLtp](docs/MarketQuoteSymbolLtp.md)\n - [ModifyOrderData](docs/ModifyOrderData.md)\n - [ModifyOrderRequest](docs/ModifyOrderRequest.md)\n - [ModifyOrderResponse](docs/ModifyOrderResponse.md)\n - [OAuthClientException](docs/OAuthClientException.md)\n - [OAuthClientExceptionCause](docs/OAuthClientExceptionCause.md)\n - [OAuthClientExceptionCauseStackTrace](docs/OAuthClientExceptionCauseStackTrace.md)\n - [OAuthClientExceptionCauseSuppressed](docs/OAuthClientExceptionCauseSuppressed.md)\n - [Ohlc](docs/Ohlc.md)\n - [OrderBookData](docs/OrderBookData.md)\n - [OrderData](docs/OrderData.md)\n - [OtherTaxes](docs/OtherTaxes.md)\n - [PlaceOrderData](docs/PlaceOrderData.md)\n - [PlaceOrderRequest](docs/PlaceOrderRequest.md)\n - [PlaceOrderResponse](docs/PlaceOrderResponse.md)\n - [PositionData](docs/PositionData.md)\n - [Problem](docs/Problem.md)\n - [ProfileData](docs/ProfileData.md)\n - [ProfitAndLossChargesData](docs/ProfitAndLossChargesData.md)\n - [ProfitAndLossChargesTaxes](docs/ProfitAndLossChargesTaxes.md)\n - [ProfitAndLossChargesWrapperData](docs/ProfitAndLossChargesWrapperData.md)\n - [ProfitAndLossMetaData](docs/ProfitAndLossMetaData.md)\n - [ProfitAndLossMetaDataWrapper](docs/ProfitAndLossMetaDataWrapper.md)\n - [ProfitAndLossOtherChargesTaxes](docs/ProfitAndLossOtherChargesTaxes.md)\n - [TokenRequest](docs/TokenRequest.md)\n - [TokenResponse](docs/TokenResponse.md)\n - [TradeData](docs/TradeData.md)\n - [TradeWiseMetaData](docs/TradeWiseMetaData.md)\n - [TradeWiseProfitAndLossData](docs/TradeWiseProfitAndLossData.md)\n - [UserFundMarginData](docs/UserFundMarginData.md)\n - [WebsocketAuthRedirectResponse](docs/WebsocketAuthRedirectResponse.md)\n - [WebsocketAuthRedirectResponseData](docs/WebsocketAuthRedirectResponseData.md)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Upstox Developer API",
    "version": "2.4.0",
    "project_urls": {
        "Homepage": "https://github.com/upstox/upstox-python"
    },
    "split_keywords": [
        "upstox",
        "developer",
        "api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0d996ef82291b9fffd3ac52cbcc134f8d4f587216acc9251103d37db3c8fb974",
                "md5": "50d538765937d26f707409b9b12c92dc",
                "sha256": "7c4a52c33400eceedd5809a8fcf0edbace39eda08fed81bc9bb55c277620874b"
            },
            "downloads": -1,
            "filename": "upstox-python-sdk-2.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "50d538765937d26f707409b9b12c92dc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 88065,
            "upload_time": "2024-03-04T14:21:38",
            "upload_time_iso_8601": "2024-03-04T14:21:38.099411Z",
            "url": "https://files.pythonhosted.org/packages/0d/99/6ef82291b9fffd3ac52cbcc134f8d4f587216acc9251103d37db3c8fb974/upstox-python-sdk-2.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-04 14:21:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "upstox",
    "github_project": "upstox-python",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "certifi",
            "specs": [
                [
                    ">=",
                    "14.05.14"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    ">=",
                    "1.10"
                ]
            ]
        },
        {
            "name": "python_dateutil",
            "specs": [
                [
                    ">=",
                    "2.5.3"
                ]
            ]
        },
        {
            "name": "setuptools",
            "specs": [
                [
                    ">=",
                    "21.0.0"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    ">=",
                    "1.15.1"
                ]
            ]
        }
    ],
    "tox": true,
    "lcname": "upstox-python-sdk"
}
        
Elapsed time: 0.21058s