Documentation
¶
Index ¶
- Constants
- Variables
- func IsTerminalStatus(status string) bool
- func ParseInstruments(r io.Reader) ([]models.Instrument, error)
- func ParsePostback(body []byte) (*models.PostbackPayload, error)
- func ParsePostbackRequest(r *http.Request) (*models.PostbackPayload, error)
- func RESTClientFor(cfg ProxyConfig) (*http.Client, error)
- type APIError
- type Client
- func (c *Client) AccessToken() string
- func (c *Client) CalculateMargin(ctx context.Context, req models.KnowYourMarginReq) (*models.KnowYourMarginResponse, error)
- func (c *Client) CalculateMultiMargin(ctx context.Context, req models.MultiScripMarginCalcRequest) (*models.MultiScripMarginCalcResponse, error)
- func (c *Client) CancelAlertOrder(ctx context.Context, alertID string) (*models.AlertOrderResponse, error)
- func (c *Client) CancelForeverOrder(ctx context.Context, orderID string) (*models.GttOrderStatusResponse, error)
- func (c *Client) CancelOrder(ctx context.Context, orderID string) (*models.OrderStatusResponse, error)
- func (c *Client) CancelSuperOrder(ctx context.Context, orderID string, orderLeg string) (*models.OrderStatusResponse, error)
- func (c *Client) ClientID() string
- func (c *Client) ConvertPosition(ctx context.Context, req models.PositionConversionRequest) error
- func (c *Client) ExitAllPositions(ctx context.Context) (*models.UserIPResponse, error)
- func (c *Client) ExitOrder(ctx context.Context, orderID string) (*models.OrderStatusResponse, error)
- func (c *Client) GenerateBulkEDISForm(ctx context.Context, req models.EdisBulkFormRequest) (*models.EdisFormResponse, error)
- func (c *Client) GenerateEDISForm(ctx context.Context, req models.EdisFormRequest) (*models.EdisFormResponse, error)
- func (c *Client) GenerateTPIN(ctx context.Context) (*models.TPINResponse, error)
- func (c *Client) GetAlertOrderByID(ctx context.Context, alertID string) (*models.GetAlertResponse, error)
- func (c *Client) GetAlertOrders(ctx context.Context) ([]models.GetAlertResponse, error)
- func (c *Client) GetCompanyInfo(ctx context.Context, req models.FundamentalMetricsRequest) (*models.FundamentalMetricsResponse, error)
- func (c *Client) GetForeverOrders(ctx context.Context) ([]models.ForeverOrderResponse, error)
- func (c *Client) GetFundLimits(ctx context.Context) (*models.FundLimitResponse, error)
- func (c *Client) GetHistoricalCharts(ctx context.Context, req models.HistoricalChartsRequest) (*models.ChartsResponse, error)
- func (c *Client) GetHoldings(ctx context.Context) ([]models.Holding, error)
- func (c *Client) GetIP(ctx context.Context) (*models.GetIPDetailsResponse, error)
- func (c *Client) GetInstruments(ctx context.Context) ([]models.Instrument, error)
- func (c *Client) GetIntradayCharts(ctx context.Context, req models.IntradayChartsRequest) (*models.ChartsResponse, error)
- func (c *Client) GetKillSwitchStatus(ctx context.Context) (*models.KillSwitchResponse, error)
- func (c *Client) GetLedger(ctx context.Context, fromDate, toDate string) ([]models.BoLedgerEntry, error)
- func (c *Client) GetLoginURL(partnerID string) string
- func (c *Client) GetMarketMovers(ctx context.Context, req models.TopInstrumentsRequest) (*models.TopInstrumentsResponse, error)
- func (c *Client) GetNewsHeadlines(ctx context.Context, req models.NewsHeadlineRequest) (*models.NewsHeadlineResponse, error)
- func (c *Client) GetOrderByCorrelationID(ctx context.Context, correlationID string) (*models.OrderResponse, error)
- func (c *Client) GetOrderByID(ctx context.Context, orderID string) (*models.OrderResponse, error)
- func (c *Client) GetOrderHistory(ctx context.Context, orderID string) (*models.OrderResponse, error)
- func (c *Client) GetOrderTrades(ctx context.Context, orderID string) ([]models.TradeResponse, error)
- func (c *Client) GetOrders(ctx context.Context) ([]models.OrderResponse, error)
- func (c *Client) GetPnLExit(ctx context.Context) (*models.ExitPnlResponse, error)
- func (c *Client) GetPositions(ctx context.Context) ([]models.Position, error)
- func (c *Client) GetRollingOptionCharts(ctx context.Context, req models.OptionChartRequest) (*models.OptionChartResponse, error)
- func (c *Client) GetSuperOrders(ctx context.Context) ([]models.SuperOrderResponse, error)
- func (c *Client) GetTechnicalData(ctx context.Context, req models.TechnicalMetricsRequest) (*models.TechnicalMetricsResponse, error)
- func (c *Client) GetTradeHistory(ctx context.Context, fromDate, toDate string, page int) ([]models.TradeResponse, error)
- func (c *Client) GetTrades(ctx context.Context) ([]models.TradeResponse, error)
- func (c *Client) GetTradesByOrderID(ctx context.Context, orderID string) ([]models.TradeResponse, error)
- func (c *Client) GetUserProfile(ctx context.Context) (*models.UserProfile, error)
- func (c *Client) InquireEDISQuantity(ctx context.Context, isin string) (*models.EdisQtyStatusResponse, error)
- func (c *Client) ModifyAlertOrder(ctx context.Context, alertID string, req models.AlertModifyRequest) (*models.AlertOrderResponse, error)
- func (c *Client) ModifyForeverOrder(ctx context.Context, orderID string, req models.GttModifyRequest) (*models.GttOrderStatusResponse, error)
- func (c *Client) ModifyIP(ctx context.Context, req models.UserIPRequest) (*models.UserIPResponse, error)
- func (c *Client) ModifyOrder(ctx context.Context, orderID string, req models.OrderModifyRequest) (*models.OrderStatusResponse, error)
- func (c *Client) ModifySuperOrder(ctx context.Context, orderID string, req models.SuperModifyRequest) (*models.OrderStatusResponse, error)
- func (c *Client) PlaceAlertOrder(ctx context.Context, req models.AlertOrderRequest) (*models.AlertOrderResponse, error)
- func (c *Client) PlaceForeverOrder(ctx context.Context, req models.GTTOrderModel) (*models.GttOrderStatusResponse, error)
- func (c *Client) PlaceMultiOrder(ctx context.Context, req models.MultiOrderRequest) (*models.MultiOrderResponse, error)
- func (c *Client) PlaceOrder(ctx context.Context, req models.OrderRequest) (*models.OrderStatusResponse, error)
- func (c *Client) PlaceSuperOrder(ctx context.Context, req models.SuperOrderRequest) (*models.OrderStatusResponse, error)
- func (c *Client) RenewAccessToken(ctx context.Context, tokenOverride ...string) (*models.RenewTokenResponse, error)
- func (c *Client) RenewToken(ctx context.Context, tokenOverride ...string) (*models.RenewTokenResponse, error)
- func (c *Client) SetAccessToken(token string)
- func (c *Client) SetClientID(clientID string)
- func (c *Client) SetIP(ctx context.Context, req models.UserIPRequest) (*models.UserIPResponse, error)
- func (c *Client) SetKillSwitch(ctx context.Context, status string) (*models.KillSwitchResponse, error)
- func (c *Client) SetPnLExit(ctx context.Context, req models.PnlBasedExitRequest) (*models.PnlExitResponse, error)
- func (c *Client) SliceOrder(ctx context.Context, req models.OrderRequest) ([]models.OrderStatusResponse, error)
- func (c *Client) StopPnLExit(ctx context.Context) (*models.UserIPResponse, error)
- type HTTPClient
- type Option
- type ProxyConfig
Constants ¶
const ( DefaultBaseURI = "https://api.dhan.co/v2" DefaultFeedURI = "wss://api-feed.dhan.co" )
Default API Gateway URLs
const ( // Authentication URIRenewToken = "/RenewToken" // IP Whitelisting URIGetIP = "/ip/getIP" URISetIP = "/ip/setIP" URIModifyIP = "/ip/modifyIP" // Trader Controls URIKillSwitch = "/killswitch" URIPnLExit = "/pnlExit" // EDIS URIEDISTpin = "/edis/tpin" URIEDISForm = "/edis/form" URIEDISBulkForm = "/edis/bulkform" URIEDISInquire = "/edis/inquire" // /edis/inquire/{isin} // Orders URIOrders = "/orders" URIOrdersSlicing = "/orders/slicing" URIOrdersExternal = "/orders/external" // /orders/external/{correlation-id} // Super Orders (Bracket Orders) URISuperOrders = "/super/orders" // Forever Orders (GTT) URIForeverOrders = "/forever/orders" // Conditional & Multi Orders (Alerts) URIAlertOrders = "/alerts/orders" URIMultiAlertOrders = "/alerts/multi/orders" // Trades URITrades = "/trades" // Portfolio URIHoldings = "/holdings" URIPositions = "/positions" URIPositionsConvert = "/positions/convert" // Funds & Margin URIFundLimit = "/fundlimit" URIMarginCalculator = "/margincalculator" URIMarginCalculatorMulti = "/margincalculator/multi" // Statements URILedger = "/ledger" // Charts & Market Analytics URIChartsHistorical = "/charts/historical" URIChartsIntraday = "/charts/intraday" URIChartsRollingOption = "/charts/rollingoption" URIDataCompanyInfo = "/data/companyinfo" URIDataMarketMovers = "/data/marketmovers" URIDataNewsHeadline = "/data/newsheadline" URIDataTechnical = "/data/technical" )
API Endpoint Paths
const DefaultScripMasterURL = "https://images.dhan.co/api-data/api-scrip-master.csv"
DefaultScripMasterURL is the public URL for Dhan's daily security master CSV dump
Variables ¶
var ( ErrAuthExpired = errors.New("authentication expired or invalid") ErrInsufficientFunds = errors.New("insufficient funds in trading account") ErrOrderNotModifiable = errors.New("order is closed or cannot be modified") ErrInvalidInput = errors.New("invalid request parameters") ErrRateLimited = errors.New("rate limit exceeded") ErrOrderRejected = errors.New("order rejected by broker RMS or exchange") ErrNotFound = errors.New("resource not found") ErrPermissionDenied = errors.New("permission denied for exchange or product") )
Standard Sentinel Domain Errors
Functions ¶
func IsTerminalStatus ¶
IsTerminalStatus checks if the given Dhan orderStatus string represents a final state
func ParseInstruments ¶
func ParseInstruments(r io.Reader) ([]models.Instrument, error)
ParseInstruments parses a CSV stream of Dhan security master records row-by-row
func ParsePostback ¶
func ParsePostback(body []byte) (*models.PostbackPayload, error)
ParsePostback unmarshals raw JSON bytes received from Dhan webhook into models.PostbackPayload
func ParsePostbackRequest ¶
func ParsePostbackRequest(r *http.Request) (*models.PostbackPayload, error)
ParsePostbackRequest extracts and decodes models.PostbackPayload from incoming HTTP request
func RESTClientFor ¶ added in v0.1.3
func RESTClientFor(cfg ProxyConfig) (*http.Client, error)
RESTClientFor builds an *http.Client configured with dedicated proxy settings and connection pooling.
Types ¶
type APIError ¶
type APIError struct {
HTTPStatus int
ErrorCode string
ErrorType string
Message string
RawBody []byte
Err error
}
APIError represents structured error from DhanHQ gateway
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the primary interface for communicating with DhanHQ REST API
func (*Client) AccessToken ¶
AccessToken returns the configured Access Token thread-safely
func (*Client) CalculateMargin ¶
func (c *Client) CalculateMargin(ctx context.Context, req models.KnowYourMarginReq) (*models.KnowYourMarginResponse, error)
CalculateMargin computes pre-trade margin requirement for a single order
func (*Client) CalculateMultiMargin ¶
func (c *Client) CalculateMultiMargin(ctx context.Context, req models.MultiScripMarginCalcRequest) (*models.MultiScripMarginCalcResponse, error)
CalculateMultiMargin computes basket margin and hedging benefits across multiple legs
func (*Client) CancelAlertOrder ¶
func (c *Client) CancelAlertOrder(ctx context.Context, alertID string) (*models.AlertOrderResponse, error)
CancelAlertOrder removes a conditional alert
func (*Client) CancelForeverOrder ¶
func (c *Client) CancelForeverOrder(ctx context.Context, orderID string) (*models.GttOrderStatusResponse, error)
CancelForeverOrder cancels an open GTT order
func (*Client) CancelOrder ¶
func (c *Client) CancelOrder(ctx context.Context, orderID string) (*models.OrderStatusResponse, error)
CancelOrder cancels a pending order
func (*Client) CancelSuperOrder ¶
func (c *Client) CancelSuperOrder(ctx context.Context, orderID string, orderLeg string) (*models.OrderStatusResponse, error)
CancelSuperOrder cancels an individual super order leg or entire bracket order
func (*Client) ConvertPosition ¶
ConvertPosition switches position product type
func (*Client) ExitAllPositions ¶
ExitAllPositions squares off all open intraday and derivative positions
func (*Client) ExitOrder ¶
func (c *Client) ExitOrder(ctx context.Context, orderID string) (*models.OrderStatusResponse, error)
ExitOrder cancels an open or pending order (parity alias for CancelOrder)
func (*Client) GenerateBulkEDISForm ¶
func (c *Client) GenerateBulkEDISForm(ctx context.Context, req models.EdisBulkFormRequest) (*models.EdisFormResponse, error)
GenerateBulkEDISForm generates HTML form payload for CDSL T-PIN authorization of multiple scrips
func (*Client) GenerateEDISForm ¶
func (c *Client) GenerateEDISForm(ctx context.Context, req models.EdisFormRequest) (*models.EdisFormResponse, error)
GenerateEDISForm generates HTML form payload for CDSL T-PIN authorization of a single scrip
func (*Client) GenerateTPIN ¶
GenerateTPIN requests CDSL to send a new T-PIN to the client's registered mobile/email
func (*Client) GetAlertOrderByID ¶
func (c *Client) GetAlertOrderByID(ctx context.Context, alertID string) (*models.GetAlertResponse, error)
GetAlertOrderByID fetches conditional alert details by alert ID
func (*Client) GetAlertOrders ¶
GetAlertOrders lists all configured conditional alerts
func (*Client) GetCompanyInfo ¶
func (c *Client) GetCompanyInfo(ctx context.Context, req models.FundamentalMetricsRequest) (*models.FundamentalMetricsResponse, error)
GetCompanyInfo fetches corporate and fundamental details for an equity scrip
func (*Client) GetForeverOrders ¶
GetForeverOrders retrieves all active and historical GTT orders
func (*Client) GetFundLimits ¶
GetFundLimits fetches available trading balances and collateral limits
func (*Client) GetHistoricalCharts ¶
func (c *Client) GetHistoricalCharts(ctx context.Context, req models.HistoricalChartsRequest) (*models.ChartsResponse, error)
GetHistoricalCharts queries daily historical OHLC candle data
func (*Client) GetHoldings ¶
GetHoldings retrieves long-term Demat holdings
func (*Client) GetInstruments ¶
GetInstruments streams and parses the official DhanHQ daily security master CSV
func (*Client) GetIntradayCharts ¶
func (c *Client) GetIntradayCharts(ctx context.Context, req models.IntradayChartsRequest) (*models.ChartsResponse, error)
GetIntradayCharts queries minute-level historical OHLC candle data
func (*Client) GetKillSwitchStatus ¶
GetKillSwitchStatus checks whether the account trading kill switch is active
func (*Client) GetLedger ¶
func (c *Client) GetLedger(ctx context.Context, fromDate, toDate string) ([]models.BoLedgerEntry, error)
GetLedger retrieves statement of ledger financial transactions
func (*Client) GetLoginURL ¶
GetLoginURL generates the DhanHQ consent login URL for partner authentication
func (*Client) GetMarketMovers ¶
func (c *Client) GetMarketMovers(ctx context.Context, req models.TopInstrumentsRequest) (*models.TopInstrumentsResponse, error)
GetMarketMovers fetches top gaining and losing instruments
func (*Client) GetNewsHeadlines ¶
func (c *Client) GetNewsHeadlines(ctx context.Context, req models.NewsHeadlineRequest) (*models.NewsHeadlineResponse, error)
GetNewsHeadlines fetches financial news headlines
func (*Client) GetOrderByCorrelationID ¶
func (c *Client) GetOrderByCorrelationID(ctx context.Context, correlationID string) (*models.OrderResponse, error)
GetOrderByCorrelationID retrieves order by client external correlation ID
func (*Client) GetOrderByID ¶
GetOrderByID retrieves specific order details by internal Dhan order ID
func (*Client) GetOrderHistory ¶
func (c *Client) GetOrderHistory(ctx context.Context, orderID string) (*models.OrderResponse, error)
GetOrderHistory retrieves audit history for a specific order (parity alias for GetOrderByID)
func (*Client) GetOrderTrades ¶
func (c *Client) GetOrderTrades(ctx context.Context, orderID string) ([]models.TradeResponse, error)
GetOrderTrades retrieves all trades executed for a given order (parity alias for GetTradesByOrderID)
func (*Client) GetPnLExit ¶
GetPnLExit fetches current P&L based exit configurations
func (*Client) GetPositions ¶
GetPositions retrieves open and closed positions for the trading day
func (*Client) GetRollingOptionCharts ¶
func (c *Client) GetRollingOptionCharts(ctx context.Context, req models.OptionChartRequest) (*models.OptionChartResponse, error)
GetRollingOptionCharts queries historical candles for expired options
func (*Client) GetSuperOrders ¶
GetSuperOrders retrieves all super/bracket orders placed today
func (*Client) GetTechnicalData ¶
func (c *Client) GetTechnicalData(ctx context.Context, req models.TechnicalMetricsRequest) (*models.TechnicalMetricsResponse, error)
GetTechnicalData fetches calculated technical indicators
func (*Client) GetTradeHistory ¶
func (c *Client) GetTradeHistory(ctx context.Context, fromDate, toDate string, page int) ([]models.TradeResponse, error)
GetTradeHistory retrieves historical trade executions within a specified date window
func (*Client) GetTradesByOrderID ¶
func (c *Client) GetTradesByOrderID(ctx context.Context, orderID string) ([]models.TradeResponse, error)
GetTradesByOrderID retrieves all trade fills associated with a specific order
func (*Client) GetUserProfile ¶
GetUserProfile retrieves current user profile and whitelisted IP details
func (*Client) InquireEDISQuantity ¶
func (c *Client) InquireEDISQuantity(ctx context.Context, isin string) (*models.EdisQtyStatusResponse, error)
InquireEDISQuantity checks current EDIS authorization status and approved quantity for an ISIN
func (*Client) ModifyAlertOrder ¶
func (c *Client) ModifyAlertOrder(ctx context.Context, alertID string, req models.AlertModifyRequest) (*models.AlertOrderResponse, error)
ModifyAlertOrder modifies conditional alert thresholds
func (*Client) ModifyForeverOrder ¶
func (c *Client) ModifyForeverOrder(ctx context.Context, orderID string, req models.GttModifyRequest) (*models.GttOrderStatusResponse, error)
ModifyForeverOrder updates price or trigger parameters of an open GTT order
func (*Client) ModifyIP ¶
func (c *Client) ModifyIP(ctx context.Context, req models.UserIPRequest) (*models.UserIPResponse, error)
ModifyIP updates an existing static IP
func (*Client) ModifyOrder ¶
func (c *Client) ModifyOrder(ctx context.Context, orderID string, req models.OrderModifyRequest) (*models.OrderStatusResponse, error)
ModifyOrder modifies price, trigger price, or quantity of a pending order
func (*Client) ModifySuperOrder ¶
func (c *Client) ModifySuperOrder(ctx context.Context, orderID string, req models.SuperModifyRequest) (*models.OrderStatusResponse, error)
ModifySuperOrder modifies target, stop loss, or entry price of a super order
func (*Client) PlaceAlertOrder ¶
func (c *Client) PlaceAlertOrder(ctx context.Context, req models.AlertOrderRequest) (*models.AlertOrderResponse, error)
PlaceAlertOrder creates conditional trigger alert
func (*Client) PlaceForeverOrder ¶
func (c *Client) PlaceForeverOrder(ctx context.Context, req models.GTTOrderModel) (*models.GttOrderStatusResponse, error)
PlaceForeverOrder creates a GTT (Good-Til-Triggered) conditional order
func (*Client) PlaceMultiOrder ¶
func (c *Client) PlaceMultiOrder(ctx context.Context, req models.MultiOrderRequest) (*models.MultiOrderResponse, error)
PlaceMultiOrder dispatches a batch of orders simultaneously
func (*Client) PlaceOrder ¶
func (c *Client) PlaceOrder(ctx context.Context, req models.OrderRequest) (*models.OrderStatusResponse, error)
PlaceOrder places a regular, AMO, or intraday order on DhanHQ
func (*Client) PlaceSuperOrder ¶
func (c *Client) PlaceSuperOrder(ctx context.Context, req models.SuperOrderRequest) (*models.OrderStatusResponse, error)
PlaceSuperOrder places a bracket order with automated target and stop loss legs
func (*Client) RenewAccessToken ¶ added in v0.1.1
func (c *Client) RenewAccessToken(ctx context.Context, tokenOverride ...string) (*models.RenewTokenResponse, error)
RenewAccessToken is a parity alias for RenewToken.
func (*Client) RenewToken ¶ added in v0.1.1
func (c *Client) RenewToken(ctx context.Context, tokenOverride ...string) (*models.RenewTokenResponse, error)
RenewToken refreshes an active access token for an additional 24 hours. If tokenOverride is passed, that token will be renewed; otherwise, c.AccessToken() is used. On success, the client's internal accessToken is automatically updated thread-safely.
func (*Client) SetAccessToken ¶ added in v0.1.1
SetAccessToken updates the configured access token thread-safely
func (*Client) SetClientID ¶ added in v0.1.1
SetClientID updates the configured Dhan Client ID thread-safely
func (*Client) SetIP ¶
func (c *Client) SetIP(ctx context.Context, req models.UserIPRequest) (*models.UserIPResponse, error)
SetIP registers a new static IP (PRIMARY or SECONDARY)
func (*Client) SetKillSwitch ¶
func (c *Client) SetKillSwitch(ctx context.Context, status string) (*models.KillSwitchResponse, error)
SetKillSwitch activates or deactivates the trading kill switch ("ACTIVATE" or "DEACTIVATE")
func (*Client) SetPnLExit ¶
func (c *Client) SetPnLExit(ctx context.Context, req models.PnlBasedExitRequest) (*models.PnlExitResponse, error)
SetPnLExit configures automated P&L thresholds to exit open positions
func (*Client) SliceOrder ¶
func (c *Client) SliceOrder(ctx context.Context, req models.OrderRequest) ([]models.OrderStatusResponse, error)
SliceOrder auto-splits large quantity orders across exchange freeze limits
func (*Client) StopPnLExit ¶
StopPnLExit cancels active P&L monitoring and square-off rule
type HTTPClient ¶
HTTPClient interface abstracts the underlying HTTP transport seam
type Option ¶
type Option func(*Client)
Option represents a functional configuration option for Client
func WithAccessToken ¶
WithAccessToken sets or overrides the access token
func WithBaseURI ¶
WithBaseURI overrides the default DhanHQ REST API base URL
func WithClientID ¶
WithClientID sets or overrides the client ID
func WithHTTPClient ¶
func WithHTTPClient(client HTTPClient) Option
WithHTTPClient provides a custom HTTP client (useful for fakes, proxy rotators, rate limiters)
func WithProxy ¶ added in v0.1.2
func WithProxy(cfg ProxyConfig) Option
WithProxy configures an authenticated HTTP/HTTPS forward proxy on the client using ProxyConfig.
func WithProxyURL ¶ added in v0.1.2
WithProxyURL configures a forward proxy on the client from a raw URL string. Example: "https://user:pass@dc46-mum-01.algoip.in:443"
type ProxyConfig ¶ added in v0.1.2
type ProxyConfig struct {
Scheme string // "http" or "https" (default "https")
Host string // e.g. "dc46-mum-01.algoip.in" or "103.21.54.1"
Port int // e.g. 443 (default 443 for https, 80 for http)
ClientID string // proxy username / client ID
ClientSecret string // proxy password / client secret
}
ProxyConfig holds forward proxy credentials and endpoint for static IP routing.