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+withext-json - Composer
- A valid Drishti API key
Installation
composer require manasija/drishti-sdkPackage: manasija/drishti-sdk on Packagist.
Quick start
<?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
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
$job = $client->postBatchJobsFile(
fileName: 'batch.jsonl',
fileContent: file_get_contents('batch.jsonl'),
displayName: 'Quarterly run',
);Helper surface
API wrappers
Workflow helpers
| Function | Reference |
|---|---|
waitForBatchJobCompletion | Polls getBatchJobsJobId until a terminal job status is reached. |
submitBatchJobAndWait | Calls postBatchJobsFile, then waits for completion. |
Transport helpers
| Function | Reference |
|---|---|
request | Any API route; pass a method, path, and optional query, JSON body, or path params. |
get | Convenience wrapper over request for GET routes. |
post | Convenience wrapper over request for POST routes. |
put | Convenience wrapper over request for PUT routes. |
patch | Convenience wrapper over request for PATCH routes. |
delete | Convenience wrapper over request for DELETE routes. |
websocket | /docs/guides/websockets |