Browse documentation
SDKs

PHP SDK

The official PHP SDK for the Drishti API provides a synchronous HTTP client with named-argument methods, a low-level request method, and a blocking websocket client for long-running workers.

Requirements

  • PHP 8.2+ with ext-json
  • Composer
  • A valid Drishti API key

Installation

bash
composer require manasija/drishti-sdk

Package: manasija/drishti-sdk on Packagist.

Quick start

php
<?php

require 'vendor/autoload.php';

use Drishti\DrishtiClient;

$client = new DrishtiClient(apiKey: getenv('DRISHTI_API_KEY'));

$news = $client->getNews(symbols: ['RELIANCE', 'TCS'], limit: 10);
echo count($news['data']);

JSON responses are returned as associative arrays. CSV, PDF, and JSONL responses are returned as strings. Failed requests throw Drishti\Exception\DrishtiApiException with getStatusCode() and getBody().

WebSocket session

PHP web requests cannot hold a socket open, so run the websocket client as a long-running CLI worker, for example under supervisord or systemd. run() blocks, reconnects after disconnects, and resubscribes every product until you call stop().

php
<?php

require 'vendor/autoload.php';

use Drishti\DrishtiClient;

$client = new DrishtiClient(apiKey: getenv('DRISHTI_API_KEY'));

$ws = $client->websocket(
    onOpen: fn (string $reason) => print("connected
"),
);

$ws->onAnnouncements(function (array $announcement): void {
    echo $announcement['symbol'], ' ', $announcement['summary'] ?? '', PHP_EOL;
});

$ws->subscribe('announcements', symbols: ['RELIANCE']);
$ws->run();

See the websocket worker example for a complete script.

Batch jobs

php
$job = $client->postBatchJobsFile(
    fileName: 'batch.jsonl',
    fileContent: file_get_contents('batch.jsonl'),
    displayName: 'Quarterly run',
);

Helper surface

API wrappers

Workflow helpers

FunctionReference
waitForBatchJobCompletionPolls getBatchJobsJobId until a terminal job status is reached.
submitBatchJobAndWaitCalls postBatchJobsFile, then waits for completion.

Transport helpers

FunctionReference
requestAny API route; pass a method, path, and optional query, JSON body, or path params.
getConvenience wrapper over request for GET routes.
postConvenience wrapper over request for POST routes.
putConvenience wrapper over request for PUT routes.
patchConvenience wrapper over request for PATCH routes.
deleteConvenience wrapper over request for DELETE routes.
websocket/docs/guides/websockets