Documentation

KiteConnect
in package

Kite Connect API client for PHP -- [kite.trade](https://kite.trade) | [Download from Github](https://github.com/zerodhatech/phpkiteconnect) Zerodha Technology (c) 2018. Version 3.0.2b License -------git Kite Connect PHP library is licensed under the MIT License.

The library

Kite Connect is a set of REST-like APIs that expose many capabilities required to build a complete investment and trading platform. Execute orders in real time, manage user portfolio, stream live market data (WebSockets), and more, with the simple HTTP API collection. This module provides an easy to use abstraction over the HTTP APIs. The HTTP calls have been converted to methods and their JSON responses are returned as native PHP structures, for example, dicts, lists, bools etc. See the Kite Connect API documentation for the complete list of APIs, supported parameters and values, and response formats. A typical web application

In a typical web application where a new instance of views, controllers etc. are created per incoming HTTP request, you will need to initialise a new instance of Kite client per request as well. This is because each individual instance represents a single user that's authenticated, unlike an admin API where you may use one instance to manage many users. Hence, in your web application, typically:

  • You will initialise an instance of the Kite client
  • Redirect the user to the login_url()
  • At the redirect url endpoint, obtain the request_token from the query parameters
  • Initialise a new instance of Kite client, use request_access_token() to obtain the access_token along with authenticated user data
  • Store this response in a session and use the stored access_token and initialise instances of Kite client for subsequent API calls. Exceptions

Kite Connect client saves you the hassle of detecting API errors by looking at HTTP codes or JSON error responses. Instead, it raises aptly named exceptions that you can catch.

Table of Contents

GTT_STATUS_ACTIVE  = "active"
GTT_STATUS_CANCELLED  = "cancelled"
GTT_STATUS_DELETED  = "deleted"
GTT_STATUS_DISABLED  = "disabled"
GTT_STATUS_EXPIRED  = "expired"
GTT_STATUS_REJECTED  = "rejected"
GTT_STATUS_TRIGGERED  = "triggered"
GTT_TYPE_OCO  = "two-leg"
GTT_TYPE_SINGLE  = "single"
MARGIN_COMMODITY  = "commodity"
MARGIN_EQUITY  = "equity"
ORDER_TYPE_LIMIT  = "LIMIT"
ORDER_TYPE_MARKET  = "MARKET"
ORDER_TYPE_SL  = "SL"
ORDER_TYPE_SLM  = "SL-M"
POSITION_TYPE_DAY  = "day"
POSITION_TYPE_OVERNIGHT  = "overnight"
PRODUCT_BO  = "BO"
PRODUCT_CNC  = "CNC"
PRODUCT_CO  = "CO"
PRODUCT_MIS  = "MIS"
PRODUCT_NRML  = "NRML"
STATUS_CANCELLED  = "CANCELLED"
STATUS_COMPLETE  = "COMPLETE"
STATUS_REJECTED  = "REJECTED"
TRANSACTION_TYPE_BUY  = "BUY"
TRANSACTION_TYPE_SELL  = "SELL"
VALIDITY_DAY  = "DAY"
VALIDITY_IOC  = "IOC"
VALIDITY_TTL  = "TTL"
VARIETY_AMO  = "amo"
VARIETY_BO  = "bo"
VARIETY_CO  = "co"
VARIETY_ICEBERG  = "iceberg"
VARIETY_REGULAR  = "regular"
VERSION  = "3.2.0"
$accessToken  : mixed
$apiKey  : mixed
$baseUrl  : string
$dateFields  : array<string|int, mixed>
$debug  : mixed
$loginUrl  : string
$routes  : array<string|int, mixed>
$sessionHook  : Closure
$timeout  : int
__construct()  : void
Initialise a new Kite Connect client instance.
cancelMFOrder()  : string
Cancel an mutual fund order.
cancelMFSIP()  : string
Cancel an mutual fund order.
cancelOrder()  : mixed
Cancel an open order.
convertPosition()  : bool
Modify an open position's product type.
deleteGTT()  : mixed
Delete an GTT order
exitOrder()  : mixed
Exit a BO or CO.
generateSession()  : mixed
Do the token exchange with the `request_token` obtained after the login flow, and retrieve the `access_token` required for all subsequent requests. The response contains not just the `access_token`, but metadata for the user who has authenticated.
getGTT()  : mixed
Get detail of individual GTT order.
getGTTs()  : array<string|int, mixed>
Get the list of all orders placed for the day.
getHistoricalData()  : array<string|int, mixed>
Retrieve historical data (candles) for an instrument.
getHoldings()  : array<string|int, mixed>
Retrieve the list of holdings
getInstruments()  : array<string|int, mixed>
Retrieve the list of market instruments available to trade.
getLoginURL()  : string
Get the remote login url to which a user should be redirected to initiate the login flow.
getLTP()  : mixed
Retrieve LTP for list of instruments.
getMargins()  : mixed
Get account balance and cash margin details for a particular segment.
getMFHoldings()  : array<string|int, mixed>
Get the list of MF holdings.
getMFInstruments()  : array<string|int, mixed>
Get list of mutual fund instruments.
getMFOrders()  : mixed
Get the list of MF orders / order info for individual order.
getMFSIPS()  : mixed
Get the list of mutual fund SIP's or individual SIP info.
getOHLC()  : mixed
Retrieve OHLC for list of instruments.
getOrderHistory()  : array<string|int, mixed>
Get history of the individual order.
getOrders()  : array<string|int, mixed>
Get the list of all orders placed for the day.
getOrderTrades()  : array<string|int, mixed>
Retrieve the list of trades executed for a particular order.
getPositions()  : mixed
Retrieve the list of positions
getProfile()  : mixed
Get user profile.
getQuote()  : array<string|int, mixed>
Retrieve quote and market depth for list of instruments.
getTrades()  : array<string|int, mixed>
Retrieve the list of trades executed.
getTriggerRange()  : array<string|int, mixed>
Retrieve the buy/sell trigger range for Cover Orders.
invalidateAccessToken()  : mixed
Kill the session by invalidating the access token.
invalidateRefreshToken()  : mixed
Invalidate refresh token.
modifyGTT()  : mixed
Modify GTT. Check [GTT documentation](https://kite.trade/docs/connect/v3/gtt/#modify-order) for details.
modifyMFSIP()  : string
Place an mutual fund order.
modifyOrder()  : mixed
Modify an open order.
orderMargins()  : array<string|int, mixed>
Fetch order margin
placeGTT()  : mixed
Place a GTT. Check [GTT documentation](https://kite.trade/docs/connect/v3/gtt/#placing-orders) for details.
placeMFOrder()  : string
Place an mutual fund order.
placeMFSIP()  : string
Place an mutual fund order.
placeOrder()  : mixed|null
Place an order.
renewAccessToken()  : array<string|int, mixed>
Renew access token by active refresh token.
setAccessToken()  : void
Set the `access_token` received after a successful authentication.
setSessionExpiryHook()  : void
Set a callback hook for session (TokenError -- timeout, expiry etc.) errors.
delete()  : mixed
Alias for sending a GET request.
formatResponse()  : mixed
Format response array, For example datetime string to DateTime object
formatResponseArray()  : array<string|int, mixed>
Format array of responses
get()  : mixed
Alias for sending a GET request.
getGTTPayload()  : array<string|int, mixed>
guzzle()  : array<string|int, mixed>
Make an HTTP request using the PHP Guzzle http client.
parseInstrumentsToCSV()  : array<string|int, mixed>
Parse a CSV dump into an array of objects.
parseMFInstrumentsToCSV()  : array<string|int, mixed>
Parse a CSV dump into an array of objects.
post()  : mixed
Alias for sending a GET request.
put()  : mixed
Alias for sending a PUT request.
request()  : mixed
Make an HTTP request.
throwSuitableException()  : void
Throw Exception based on response

Constants

GTT_STATUS_ACTIVE

public mixed GTT_STATUS_ACTIVE = "active"

GTT_STATUS_CANCELLED

public mixed GTT_STATUS_CANCELLED = "cancelled"

GTT_STATUS_DELETED

public mixed GTT_STATUS_DELETED = "deleted"

GTT_STATUS_DISABLED

public mixed GTT_STATUS_DISABLED = "disabled"

GTT_STATUS_EXPIRED

public mixed GTT_STATUS_EXPIRED = "expired"

GTT_STATUS_REJECTED

public mixed GTT_STATUS_REJECTED = "rejected"

GTT_STATUS_TRIGGERED

public mixed GTT_STATUS_TRIGGERED = "triggered"

GTT_TYPE_SINGLE

public mixed GTT_TYPE_SINGLE = "single"

MARGIN_COMMODITY

public mixed MARGIN_COMMODITY = "commodity"

MARGIN_EQUITY

public mixed MARGIN_EQUITY = "equity"

ORDER_TYPE_LIMIT

public mixed ORDER_TYPE_LIMIT = "LIMIT"

ORDER_TYPE_MARKET

public mixed ORDER_TYPE_MARKET = "MARKET"

POSITION_TYPE_DAY

public mixed POSITION_TYPE_DAY = "day"

POSITION_TYPE_OVERNIGHT

public mixed POSITION_TYPE_OVERNIGHT = "overnight"

STATUS_CANCELLED

public mixed STATUS_CANCELLED = "CANCELLED"

STATUS_COMPLETE

public mixed STATUS_COMPLETE = "COMPLETE"

STATUS_REJECTED

public mixed STATUS_REJECTED = "REJECTED"

TRANSACTION_TYPE_BUY

public mixed TRANSACTION_TYPE_BUY = "BUY"

TRANSACTION_TYPE_SELL

public mixed TRANSACTION_TYPE_SELL = "SELL"

VARIETY_ICEBERG

public mixed VARIETY_ICEBERG = "iceberg"

VARIETY_REGULAR

public mixed VARIETY_REGULAR = "regular"

Properties

$baseUrl

private string $baseUrl = "https://api.kite.trade"

$dateFields

private static array<string|int, mixed> $dateFields = ["order_timestamp", "exchange_timestamp", "created", "last_instalment", "fill_timestamp", "timestamp", "last_trade_time"]

$loginUrl

private string $loginUrl = "https://kite.trade/connect/login"

$routes

private array<string|int, mixed> $routes = [ "api.token" => "/session/token", "api.token.invalidate" => "/session/token", "api.token.renew" => "/session/refresh_token", "user.profile" => "/user/profile", "user.margins" => "/user/margins", "user.margins.segment" => "/user/margins/{segment}", "orders" => "/orders", "trades" => "/trades", "order.info" => "/orders/{order_id}", "order.place" => "/orders/{variety}", "order.modify" => "/orders/{variety}/{order_id}", "order.cancel" => "/orders/{variety}/{order_id}", "order.trades" => "/orders/{order_id}/trades", "order.margins" => "/margins/orders", "portfolio.positions" => "/portfolio/positions", "portfolio.holdings" => "/portfolio/holdings", "portfolio.positions.convert" => "/portfolio/positions", # MF api endpoints "mf.orders" => "/mf/orders", "mf.order.info" => "/mf/orders/{order_id}", "mf.order.place" => "/mf/orders", "mf.order.cancel" => "/mf/orders/{order_id}", "mf.sips" => "/mf/sips", "mf.sip.info" => "/mf/sips/{sip_id}", "mf.sip.place" => "/mf/sips", "mf.sip.modify" => "/mf/sips/{sip_id}", "mf.sip.cancel" => "/mf/sips/{sip_id}", "mf.holdings" => "/mf/holdings", "mf.instruments" => "/mf/instruments", "market.instruments.all" => "/instruments", "market.instruments" => "/instruments/{exchange}", "market.margins" => "/margins/{segment}", "market.historical" => "/instruments/historical/{instrument_token}/{interval}", "market.trigger_range" => "/instruments/trigger_range/{transaction_type}", "market.quote" => "/quote", "market.quote.ohlc" => "/quote/ohlc", "market.quote.ltp" => "/quote/ltp", "gtt.triggers" => "/gtt/triggers", "gtt.trigger_info" => "/gtt/triggers/{trigger_id}", "gtt.place" => "/gtt/triggers", "gtt.modify" => "/gtt/triggers/{trigger_id}", "gtt.delete" => "/gtt/triggers/{trigger_id}", ]

Methods

__construct()

Initialise a new Kite Connect client instance.

public __construct(string $apiKey[, string|null $accessToken = null ][, string|null $root = null ][, bool $debug = false ][, int $timeout = 7 ][, Client $guzzleClient = null ]) : void
Parameters
$apiKey : string

The Kite Connect API key issued to you.

$accessToken : string|null = null

The token obtained after the login flow in exchange for the request_token. Pre-login, this will default to None, but once you have obtained it, you should persist it in a database or session to pass to the Kite Connect class initialisation for subsequent requests

$root : string|null = null

The Kite Connect API end point root. Unless you explicitly want to send API requests to a non-default endpoint, this should be left as null.

$debug : bool = false

If set to True, requests and responses will be echoed.

$timeout : int = 7

The the time (seconds) for which the API client will wait for a request to complete before it fails.

$guzzleClient : Client = null
Return values
void

cancelOrder()

Cancel an open order.

public cancelOrder(string $variety, string $orderId[, array<string|int, mixed>|null $params = null ]) : mixed
Parameters
$variety : string

"variety" Order variety (ex. bo, co, amo, regular).

$orderId : string

"order_id" Order id.

$params : array<string|int, mixed>|null = null

Order cancel parameters $params string "parent_order_id" (Optional) Parent order id if its a multi legged order.

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

convertPosition()

Modify an open position's product type.

public convertPosition(array<string|int, mixed> $params) : bool
Parameters
$params : array<string|int, mixed>

Parameters describing the open position to be modified. $param string "exchange" Exchange in which instrument is listed (NSE, BSE, NFO, BFO, CDS, MCX). $param string "tradingsymbol" Tradingsymbol of the instrument (ex. RELIANCE, INFY). $param string "transaction_type" Transaction type (BUY or SELL). $param string "position_type" Position type (overnight, day). $param string "quantity" Position quantity $param string "old_product" Current product code (NRML, MIS, CNC). $param string "new_product" New Product code (NRML, MIS, CNC).

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
bool

exitOrder()

Exit a BO or CO.

public exitOrder(string $variety, string $orderId, array<string|int, mixed> $params) : mixed
Parameters
$variety : string

"variety" Order variety (ex. bo, co, amo, regular).

$orderId : string

"order_id" Order id.

$params : array<string|int, mixed>

Order cancel parameters $params string "parent_order_id" (Optional) Parent order id if its a multi legged order.

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

generateSession()

Do the token exchange with the `request_token` obtained after the login flow, and retrieve the `access_token` required for all subsequent requests. The response contains not just the `access_token`, but metadata for the user who has authenticated.

public generateSession(string $requestToken, string $apiSecret) : mixed
Parameters
$requestToken : string

Token obtained from the GET params after a successful login redirect

$apiSecret : string

The API secret issued with the API key.

Tags
throws
Exception
Return values
mixed

getHistoricalData()

Retrieve historical data (candles) for an instrument.

public getHistoricalData(string $instrument_token, string $interval, string|DateTime $from, string|DateTime $to[, bool $continuous = false ][, bool $oi = false ]) : array<string|int, mixed>

Although the actual response JSON from the API does not have field names such has 'open', 'high' etc., this functin call structures the data into an array of objects with field names. For example:

stdClass Object
   (
       [date] => 2016-05-02T09:15:00+0530
       [open] => 1442
       [high] => 1446.45
       [low] => 1416.15
       [close] => 1420.55
       [volume] => 205976
   )
Parameters
$instrument_token : string

"instrument_token" Instrument identifier (retrieved from the instruments()) call.

$interval : string

"interval" candle interval (minute, day, 5 minute etc.)

$from : string|DateTime

"from" From date (String in format of 'yyyy-mm-dd HH:MM:SS' or Date object).

$to : string|DateTime

"to" To date (String in format of 'yyyy-mm-dd HH:MM:SS' or Date object).

$continuous : bool = false

"continuous" is a bool flag to get continuous data for futures and options instruments. Defaults to false.

$oi : bool = false
Tags
throws
Exception
Return values
array<string|int, mixed>

getInstruments()

Retrieve the list of market instruments available to trade.

public getInstruments([string|null $exchange = null ]) : array<string|int, mixed>

Note that the results could be large, several hundred KBs in size, with tens of thousands of entries in the array. The actual response from the API is in the CSV format, but this function parses the CSV into an array of Objects where an individual object looks like:

Class Object
   (
       [instrument_token] => 128031748
       [exchange_token] => 500124
       [tradingsymbol] => DRREDDY*
       [name] => DR.REDDYS LABORATORIES
       [last_price] => 0
       [expiry] =>
       [strike] => 0
       [tick_size] => 0.05
       [lot_size] => 1
       [instrument_type] => EQ
       [segment] => BSE
       [exchange] => BSE
   )
Parameters
$exchange : string|null = null

(Optional) Exchange.

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
array<string|int, mixed>

getLoginURL()

Get the remote login url to which a user should be redirected to initiate the login flow.

public getLoginURL() : string
Return values
string

getOrderHistory()

Get history of the individual order.

public getOrderHistory(string $orderId) : array<string|int, mixed>
Parameters
$orderId : string

ID of the order (optional) whose trades are to be retrieved. If no order_id is specified, all trades for the day are returned.

Tags
throws
DataException
throws
Exception
Return values
array<string|int, mixed>

getOrders()

Get the list of all orders placed for the day.

public getOrders() : array<string|int, mixed>
Tags
throws
DataException
throws
Exception
Return values
array<string|int, mixed>

getOrderTrades()

Retrieve the list of trades executed for a particular order.

public getOrderTrades(string $orderId) : array<string|int, mixed>

An order can be executed in tranches based on market conditions. These trades are individually recorded under an order.

Parameters
$orderId : string

ID of the order (optional) whose trades are to be retrieved. If no order_id is specified, all trades for the day are returned.

Tags
throws
DataException
throws
Exception
Return values
array<string|int, mixed>

getQuote()

Retrieve quote and market depth for list of instruments.

public getQuote(array<string|int, mixed> $instruments) : array<string|int, mixed>
Parameters
$instruments : array<string|int, mixed>

instruments is a list of instruments, Instrument are in the format of tradingsymbol:exchange. For example NSE:INFY

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
array<string|int, mixed>

getTrades()

Retrieve the list of trades executed.

public getTrades() : array<string|int, mixed>
Tags
throws
DataException
throws
Exception
Return values
array<string|int, mixed>

modifyGTT()

Modify GTT. Check [GTT documentation](https://kite.trade/docs/connect/v3/gtt/#modify-order) for details.

public modifyGTT(int $triggerId, array<string|int, mixed> $params) : mixed
$params = [ // GTT type, its either `$kite::GTT_TYPE_OCO` or `$kite::GTT_TYPE_SINGLE`. "trigger_type" => $kite::GTT_TYPE_OCO, // Tradingsymbol of the instrument (ex. RELIANCE, INFY). "tradingsymbol" => "SBIN", // Exchange in which instrument is listed (NSE, BSE, NFO, BFO, CDS, MCX). "exchange" => "NSE", // List of trigger values, number of items depends on trigger type. "trigger_values" => array(300, 400), // Price at which trigger is created. This is usually the last price of the instrument. "last_price" => 318, // List of orders. Check [order params](https://kite.trade/docs/connect/v3/orders/#regular-order-parameters) for all available params. "orders" => array([ "transaction_type" => $kite::TRANSACTION_TYPE_SELL, "quantity" => 1, "product" => $kite::PRODUCT_CNC, "order_type" => $kite::ORDER_TYPE_LIMIT, "price" => 300 ], [ "transaction_type" => $kite::TRANSACTION_TYPE_SELL, "quantity" => 1, "product" => $kite::PRODUCT_CNC, "order_type" => $kite::ORDER_TYPE_LIMIT, "price" => 400 ]) ]
Parameters
$triggerId : int

GTT Trigger ID

$params : array<string|int, mixed>

GTT Params. Check above for required fields.

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

modifyMFSIP()

Place an mutual fund order.

public modifyMFSIP(string $sip_id, array<string|int, mixed> $params) : string
Parameters
$sip_id : string

Mutual fund SIP ID.

$params : array<string|int, mixed>

Mutual fund SIP modify parameters $param float "amount" Amount worth of units to purchase. Not applicable on SELLs $param int|null "instalments" (Optional) Number of instalments to trigger. If set to -1, instalments are triggered at fixed intervals until the SIP is cancelled $param string|null "frequency" (Optional) Order frequency. weekly, monthly, or quarterly. $param int|null "instalment_day" (Optional) If frequency is monthly, the day of the month (1, 5, 10, 15, 20, 25) to trigger the order on. $param string|null "status" (Optional) Pause or unpause an SIP (active or paused).

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
string

modifyOrder()

Modify an open order.

public modifyOrder(string $variety, string $orderId, array<string|int, mixed> $params) : mixed
Parameters
$variety : string

"variety" Order variety (ex. bo, co, amo, regular).

$orderId : string

"order_id" Order id.

$params : array<string|int, mixed>

Order modify parameters. $params string "parent_order_id" (Optional) Parent order id if its a multi legged order. $params string "order_type" (Optional) Order type (SL, SL-M, MARKET) $params int "quantity" (Optional) Order quantity $params int|null "disclosed_quantity" (Optional) Disclosed quantity $params float|null "price" (Optional) Order Price $params float|null "trigger_price" (Optional) Trigger price $params string|null "validity" (Optional) Order validity (DAY, IOC).

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

orderMargins()

Fetch order margin

public orderMargins(array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>

Order params to fetch margin detail $params string "exchange" Name of the exchange(eg. NSE, BSE, NFO, CDS, MCX) $params string "tradingsymbol" Trading symbol of the instrument $params string "transaction_type" eg. BUY, SELL $params string "variety" Order variety (regular, amo, bo, co etc.) $params string "product" Margin product to use for the order $params string "order_type" Order type (MARKET, LIMIT etc.) $params int "quantity" Quantity of the order $params float|null "price" Price at which the order is going to be placed (LIMIT orders) $params float|null "trigger_price" Trigger price (for SL, SL-M, CO orders)

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
array<string|int, mixed>

placeGTT()

Place a GTT. Check [GTT documentation](https://kite.trade/docs/connect/v3/gtt/#placing-orders) for details.

public placeGTT(array<string|int, mixed> $params) : mixed
$params = [ // GTT type, its either `$kite::GTT_TYPE_OCO` or `$kite::GTT_TYPE_SINGLE`. "trigger_type" => $kite::GTT_TYPE_OCO, // Tradingsymbol of the instrument (ex. RELIANCE, INFY). "tradingsymbol" => "SBIN", // Exchange in which instrument is listed (NSE, BSE, NFO, BFO, CDS, MCX). "exchange" => "NSE", // List of trigger values, number of items depends on trigger type. "trigger_values" => array(300, 400), // Price at which trigger is created. This is usually the last price of the instrument. "last_price" => 318, // List of orders. Check [order params](https://kite.trade/docs/connect/v3/orders/#regular-order-parameters) for all available params. "orders" => array([ "transaction_type" => $kite::TRANSACTION_TYPE_SELL, "quantity" => 1, "product" => $kite::PRODUCT_CNC, "order_type" => $kite::ORDER_TYPE_LIMIT, "price" => 300 ], [ "transaction_type" => $kite::TRANSACTION_TYPE_SELL, "quantity" => 1, "product" => $kite::PRODUCT_CNC, "order_type" => $kite::ORDER_TYPE_LIMIT, "price" => 400 ]) ]
Parameters
$params : array<string|int, mixed>

GTT Params. Check above for required fields.

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

placeMFOrder()

Place an mutual fund order.

public placeMFOrder(array<string|int, mixed> $params) : string
Parameters
$params : array<string|int, mixed>

Order parameters $param string "tradingsymbol" Tradingsymbol (ISIN) of the fund. $param string "transaction_type" Transaction type (BUY or SELL). $param int|null "quantity" Quantity to SELL. Not applicable on BUYs. $param float|null "amount" (Optional) Amount worth of units to purchase. Not applicable on SELLs $param string|null "tag" (Optional) An optional tag to apply to an order to identify it (alphanumeric, max 8 chars)

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
string

placeMFSIP()

Place an mutual fund order.

public placeMFSIP(array<string|int, mixed> $params) : string
Parameters
$params : array<string|int, mixed>

Mutual fund SIP parameters $param string "tradingsymbol" Tradingsymbol (ISIN) of the fund. $param float "amount" Amount worth of units to purchase. Not applicable on SELLs $param int "instalments" Number of instalments to trigger. If set to -1, instalments are triggered at fixed intervals until the SIP is cancelled $param string "frequency" Order frequency. weekly, monthly, or quarterly. $param float|null "initial_amount" (Optional) Amount worth of units to purchase before the SIP starts. $param int|null "instalment_day" (Optional) If frequency is monthly, the day of the month (1, 5, 10, 15, 20, 25) to trigger the order on. $param string|null "tag" An optional (Optional) tag to apply to an order to identify it (alphanumeric, max 8 chars)

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
string

placeOrder()

Place an order.

public placeOrder(string $variety, array<string|int, mixed> $params) : mixed|null
Parameters
$variety : string

"variety" Order variety (ex. bo, co, amo, regular).

$params : array<string|int, mixed>

Order parameters $params string "exchange" Exchange in which instrument is listed (NSE, BSE, NFO, BFO, CDS, MCX). $params string "tradingsymbol" Tradingsymbol of the instrument (ex. RELIANCE, INFY). $params string "transaction_type" Transaction type (BUY or SELL). $params string "product" Product code (NRML, MIS, CNC). $params string "order_type" Order type (SL, SL-M, LIMIT, MARKET). $params int "quantity" Order quantity $params int|null "disclosed_quantity" (Optional) Disclosed quantity $params float|null "price" (Optional) Order Price $params float|null "trigger_price" (Optional) Trigger price $params float|null "squareoff" (Mandatory only for bracker orders) Square off value $params float|null "stoploss" (Mandatory only for bracker orders) Stoploss value $params float|null "trailing_stoploss" (Optional) Trailing stoploss value (only for bracket orders) $params int|null "validity_ttl" Order validity in minutes for TTL validity orders $params int|null "iceberg_legs" Total number of legs for iceberg order variety $params int|null "iceberg_quantity" Split quantity for each iceberg leg order $params float|null "tag" (Optional) Order tag $params string|null "validity" (Optional) Order validity (DAY, IOC).

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed|null

renewAccessToken()

Renew access token by active refresh token.

public renewAccessToken(string $refreshToken, string $apiSecret) : array<string|int, mixed>

Renewed access token is implicitly set.

Parameters
$refreshToken : string

Token obtained from previous successful login.

$apiSecret : string

The API secret issued with the API key.

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
array<string|int, mixed>

setAccessToken()

Set the `access_token` received after a successful authentication.

public setAccessToken(string $accessToken) : void
Parameters
$accessToken : string

The access_token received after a successful authentication token exchange.

Return values
void

setSessionExpiryHook()

Set a callback hook for session (TokenError -- timeout, expiry etc.) errors.

public setSessionExpiryHook(Closure $method) : void

An access_token (login session) can become invalid for a number of reasons, but it doesn't make sense for the client to try and catch it during every API call.

A callback method that handles session errors can be set here and when the client encounters a token error at any point, it'll be called. This callback, for instance, can log the user out of the UI, clear session cookies, or initiate a fresh login.

Parameters
$method : Closure

The callback function that should be called in case of a TokenError error.

Return values
void

delete()

Alias for sending a GET request.

private delete(string $route[, array<string|int, mixed>|null $params = [] ][, string $headerContent = '' ]) : mixed
Parameters
$route : string

Route name mapped in self::$routes.

$params : array<string|int, mixed>|null = []

Request parameters.

$headerContent : string = ''
Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

Array or object (deserialised JSON).

formatResponse()

Format response array, For example datetime string to DateTime object

private formatResponse(mixed $data) : mixed
Parameters
$data : mixed
Tags
throws
Exception
Return values
mixed

formatResponseArray()

Format array of responses

private formatResponseArray(mixed $data) : array<string|int, mixed>
Parameters
$data : mixed
Tags
throws
Exception
Return values
array<string|int, mixed>

get()

Alias for sending a GET request.

private get(string $route[, array<string|int, mixed>|null $params = [] ][, string $headerContent = '' ]) : mixed
Parameters
$route : string

Route name mapped in self::$routes.

$params : array<string|int, mixed>|null = []

Request parameters.

$headerContent : string = ''
Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

Array or object (deserialised JSON).

getGTTPayload()

private getGTTPayload(mixed $params) : array<string|int, mixed>
Parameters
$params : mixed
Tags
throws
DataException
Return values
array<string|int, mixed>

guzzle()

Make an HTTP request using the PHP Guzzle http client.

private guzzle(string $url, string $method, array<string|int, mixed>|null $headers[, array<string|int, mixed>|null $params = null ][, mixed $guzzleClient = null ]) : array<string|int, mixed>
Parameters
$url : string

The full URL to retrieve

$method : string

The HTTP method to send (GET, POST, PUT, DELETE).

$headers : array<string|int, mixed>|null

Array of HTTP request headers to send.

$params : array<string|int, mixed>|null = null

Array of key=>value request parameters.

$guzzleClient : mixed = null
Return values
array<string|int, mixed>

Returns an array with response "headers" and "body".

parseInstrumentsToCSV()

Parse a CSV dump into an array of objects.

private parseInstrumentsToCSV(string $csv) : array<string|int, mixed>
Parameters
$csv : string

Complete CSV dump.

Tags
throws
Exception
Return values
array<string|int, mixed>

parseMFInstrumentsToCSV()

Parse a CSV dump into an array of objects.

private parseMFInstrumentsToCSV(string $csv) : array<string|int, mixed>
Parameters
$csv : string

Complete CSV dump.

Tags
throws
Exception
Return values
array<string|int, mixed>

post()

Alias for sending a GET request.

private post(string $route[, array<string|int, mixed>|null $params = [] ][, string $headerContent = '' ]) : mixed
Parameters
$route : string

Route name mapped in self::$routes.

$params : array<string|int, mixed>|null = []

Request parameters.

$headerContent : string = ''
Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

Array or object (deserialised JSON).

put()

Alias for sending a PUT request.

private put(string $route[, array<string|int, mixed>|null $params = [] ][, string $headerContent = '' ]) : mixed
Parameters
$route : string

Route name mapped in self::$routes.

$params : array<string|int, mixed>|null = []

Request parameters.

$headerContent : string = ''
Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

Array or object (deserialised JSON).

request()

Make an HTTP request.

private request(string $route, string $method, array<string|int, mixed>|null $params, string $headerContent) : mixed
Parameters
$route : string

Route name mapped in self::$routes.

$method : string

The HTTP method to send (GET, POST, PUT, DELETE).

$params : array<string|int, mixed>|null

Request parameters.

$headerContent : string

Header content

Tags
throws
DataException
throws
GeneralException
throws
InputException
throws
NetworkException
throws
OrderException
throws
PermissionException
throws
TokenException
Return values
mixed

Array or object (deserialised JSON).

Search results