Download the PHP package upstox/upstox-php-sdk without Composer
On this page you can find all versions of the php package upstox/upstox-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package upstox-php-sdk
Upstox PHP SDK for API v2
Introduction
The official PHP client for communicating with the Upstox API.
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
- Build package: io.swagger.codegen.v3.generators.php.PhpClientCodegen
This PHP package is automatically generated by the Swagger Codegen project:
Documentation.
Requirements
PHP 7.4 and later
Installation & Usage
Composer
Run composer require upstox/upstox-php-sdk
to install the SDK from Packagist.
Github
Composer Installation
Download the latest release and run composer install
Manual Installation
Download the files and include autoload.php
:
Tests
To run the unit tests:
Examples
Sample Implementations can be found within /examples
folder.
- Websocket Market data
- Websocket Order updates
Documentation for API Endpoints
All URIs are relative to https://api.upstox.com/v2/
Class | Method | HTTP request | Description |
---|---|---|---|
ChargeApi | getBrokerage | GET /v2/charges/brokerage | Brokerage details |
ChargeApi | postMargin | POST /v2/charges/margin | Calculate Margin |
HistoryApi | getHistoricalCandleData | GET /v2/historical-candle/{instrumentKey}/{interval}/{to_date} | Historical candle data |
HistoryApi | getHistoricalCandleData1 | GET /v2/historical-candle/{instrumentKey}/{interval}/{to_date}/{from_date} | Historical candle data |
HistoryApi | getIntraDayCandleData | GET /v2/historical-candle/intraday/{instrumentKey}/{interval} | Intra day candle data |
LoginApi | authorize | GET /v2/login/authorization/dialog | Authorize API |
LoginApi | logout | DELETE /v2/logout | Logout |
LoginApi | token | POST /v2/login/authorization/token | Get token API |
MarketHolidaysAndTimingsApi | getExchangeTimings | GET /v2/market/timings/{date} | Get Exchange Timings on particular date |
MarketHolidaysAndTimingsApi | getHoliday | GET /v2/market/holidays/{date} | Get Holiday on particular date |
MarketHolidaysAndTimingsApi | getHolidays | GET /v2/market/holidays | Get Holiday list of current year |
MarketHolidaysAndTimingsApi | getMarketStatus | GET /v2/market/status/{exchange} | Get Market status for particular exchange |
MarketQuoteApi | getFullMarketQuote | GET /v2/market-quote/quotes | Market quotes and instruments - Full market quotes |
MarketQuoteApi | getMarketQuoteOHLC | GET /v2/market-quote/ohlc | Market quotes and instruments - OHLC quotes |
MarketQuoteApi | ltp | GET /v2/market-quote/ltp | Market quotes and instruments - LTP quotes. |
OptionsApi | getOptionContracts | GET /v2/option/contract | Get option contracts |
OptionsApi | getPutCallOptionChain | GET /v2/option/chain | Get option chain |
OrderApi | cancelMultiOrder | DELETE /v2/order/multi/cancel | Cancel multi order |
OrderApi | cancelOrder | DELETE /v2/order/cancel | Cancel order |
OrderApi | exitPositions | POST /v2/order/positions/exit | Exit all positions |
OrderApi | getOrderBook | GET /v2/order/retrieve-all | Get order book |
OrderApi | getOrderDetails | GET /v2/order/history | Get order history |
OrderApi | getOrderStatus | GET /v2/order/details | Get order details |
OrderApi | getTradeHistory | GET /v2/order/trades/get-trades-for-day | Get trades |
OrderApi | getTradesByOrder | GET /v2/order/trades | Get trades for order |
OrderApi | modifyOrder | PUT /v2/order/modify | Modify order |
OrderApi | placeMultiOrder | POST /v2/order/multi/place | Place multi order |
OrderApi | placeOrder | POST /v2/order/place | Place order |
PortfolioApi | convertPositions | PUT /v2/portfolio/convert-position | Convert Positions |
PortfolioApi | getHoldings | GET /v2/portfolio/long-term-holdings | Get Holdings |
PortfolioApi | getPositions | GET /v2/portfolio/short-term-positions | Get Positions |
PostTradeApi | getTradesByDateRange | GET /v2/charges/historical-trades | Get historical trades |
TradeProfitAndLossApi | getProfitAndLossCharges | GET /v2/trade/profit-loss/charges | Get profit and loss on trades |
TradeProfitAndLossApi | getTradeWiseProfitAndLossData | GET /v2/trade/profit-loss/data | Get Trade-wise Profit and Loss Report Data |
TradeProfitAndLossApi | getTradeWiseProfitAndLossMetaData | GET /v2/trade/profit-loss/metadata | Get profit and loss meta data on trades |
UserApi | getProfile | GET /v2/user/profile | Get profile |
UserApi | getUserFundMargin | GET /v2/user/get-funds-and-margin | Get User Fund And Margin |
WebsocketApi | getMarketDataFeed | GET /v2/feed/market-data-feed | Market Data Feed |
WebsocketApi | getMarketDataFeedAuthorize | GET /v2/feed/market-data-feed/authorize | Market Data Feed Authorize |
WebsocketApi | getPortfolioStreamFeed | GET /v2/feed/portfolio-stream-feed | Portfolio Stream Feed |
WebsocketApi | getPortfolioStreamFeedAuthorize | GET /v2/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:
- MarketDataStreamer: Offers real-time market updates, providing a seamless way to receive instantaneous information on various market instruments.
- 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:
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
- constructor MarketDataStreamer(apiClient, instrumentKeys, mode): Initializes the streamer with optional instrument keys and mode (
full
orltpc
). - connect(): Establishes the WebSocket connection.
- subscribe(instrumentKeys, mode): Subscribes to updates for given instrument keys in the specified mode. Both parameters are mandatory.
- unsubscribe(instrumentKeys): Stops updates for the specified instrument keys.
- changeMode(instrumentKeys, mode): Switches the mode for already subscribed instrument keys.
- disconnect(): Ends the active WebSocket connection.
- autoReconnect(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.
- Subscribing to Market Data on Connection Open with MarketDataStreamer
- Subscribing to Instruments with Delays
- Subscribing and Unsubscribing to Instruments
- Subscribe, Change Mode and Unsubscribe
- Disable Auto-Reconnect
- Modify Auto-Reconnect parameters
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:
Position and holding updates can be enabled by setting the corresponding flag to true
in the constructor of the PortfolioDataStreamer
class.
This example demonstrates initializing the PortfolioDataStreamer, connecting it to the WebSocket, and setting up an event listener to receive and print order updates. Replace
Exploring the PortfolioDataStreamer Functionality
Functions
- constructor PortfolioDataStreamer(): Initializes the streamer.
- connect(): Establishes the WebSocket connection.
- disconnect(): Ends the active WebSocket connection.
- autoReconnect(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
- AnalyticsData
- ApiGatewayErrorResponse
- BatchExecutionSummary
- BrokerageData
- BrokerageTaxes
- BrokerageWrapperData
- CancelOrExitMultiOrderData
- CancelOrExitMultiOrderResponse
- CancelOrExitOrderErrorData
- CancelOrderData
- CancelOrderResponse
- ConvertPositionData
- ConvertPositionRequest
- ConvertPositionResponse
- Depth
- DepthMap
- DpPlan
- ExchangeTimingData
- GetBrokerageResponse
- GetExchangeTimingResponse
- GetFullMarketQuoteResponse
- GetHistoricalCandleResponse
- GetHoldingsResponse
- GetHolidayResponse
- GetIntraDayCandleResponse
- GetMarketQuoteLastTradedPriceResponse
- GetMarketQuoteOHLCResponse
- GetMarketStatusResponse
- GetOptionChainResponse
- GetOptionContractResponse
- GetOrderBookResponse
- GetOrderDetailsResponse
- GetOrderResponse
- GetPositionResponse
- GetProfileResponse
- GetProfitAndLossChargesResponse
- GetTradeResponse
- GetTradeWiseProfitAndLossDataResponse
- GetTradeWiseProfitAndLossMetaDataResponse
- GetUserFundMarginResponse
- HistoricalCandleData
- HoldingsData
- HolidayData
- Instrument
- InstrumentData
- IntraDayCandleData
- LogoutResponse
- Margin
- MarginData
- MarginRequest
- MarketData
- MarketQuoteOHLC
- MarketQuoteSymbol
- MarketQuoteSymbolLtp
- MarketStatusData
- ModifyOrderData
- ModifyOrderRequest
- ModifyOrderResponse
- MultiOrderData
- MultiOrderError
- MultiOrderRequest
- MultiOrderResponse
- MultiOrderSummary
- OAuthClientException
- OAuthClientExceptionCause
- OAuthClientExceptionCauseStackTrace
- OAuthClientExceptionCauseSuppressed
- Ohlc
- OptionStrikeData
- OrderBookData
- OrderData
- OtherTaxes
- PlaceOrderData
- PlaceOrderRequest
- PlaceOrderResponse
- PositionData
- PostMarginResponse
- Problem
- ProfileData
- ProfitAndLossChargesData
- ProfitAndLossChargesTaxes
- ProfitAndLossChargesWrapperData
- ProfitAndLossMetaData
- ProfitAndLossMetaDataWrapper
- ProfitAndLossOtherChargesTaxes
- PutCallOptionChainData
- TokenRequest
- TokenResponse
- TradeData
- TradeHistoryResponse
- TradeHistoryResponseMetaData
- TradeHistoryResponsePageData
- TradeHistoryResponseTradeData
- TradeWiseMetaData
- TradeWiseProfitAndLossData
- UserFundMarginData
- WebsocketAuthRedirectResponse
- WebsocketAuthRedirectResponseData
All versions of upstox-php-sdk with dependencies
ext-curl Version *
ext-json Version *
ext-mbstring Version *
guzzlehttp/guzzle Version ^7.3
guzzlehttp/psr7 Version ^1.7 || ^2.0
amphp/amp Version ^3.0
amphp/websocket-client Version ^2.0
ramsey/uuid Version ^4.7
google/protobuf Version ^3.25