Browse documentation
Java SDK
The official Java SDK for the Drishti API provides a thread-safe HTTP client with a method for every endpoint, a managed websocket session that reconnects on its own, and batch job helpers. Its only runtime dependency is Jackson; HTTP and websockets use the JDK's java.net.http.
Requirements
- Java 17 or later. Check with
java -version. - A Drishti API key in the
DRISHTI_API_KEYenvironment variable. See the Quickstart to create one.
Installation
<dependency>
<groupId>io.github.techmanasija</groupId>
<artifactId>drishti-sdk</artifactId>
<version>1.0.0</version>
</dependency>The single JAR bundles Jackson. Use it for scripts and quick tests: java -cp drishti-sdk-1.0.0-all.jar YourProgram.java.
Quick start
Save this as Announcements.java:
import com.fasterxml.jackson.databind.JsonNode;
import in.manasija.drishti.DrishtiClient;
import in.manasija.drishti.params.AnnouncementsParams;
public class Announcements {
public static void main(String[] args) {
DrishtiClient client = DrishtiClient.fromEnvironment(); // reads DRISHTI_API_KEY
JsonNode result = client.getAnnouncements(new AnnouncementsParams()
.symbols("RELIANCE")
.limit(3)
.detailed(false));
for (JsonNode item : result.path("data")) {
System.out.println(item.path("date").asText() + " | "
+ item.path("category").asText() + " | "
+ item.path("summary").asText());
}
}
}Run it with the single JAR:
java -cp drishti-sdk-1.0.0-all.jar Announcements.javaIt prints the three latest RELIANCE announcements, one per line, as date | category | summary.
How the client works:
- JSON responses come back as Jackson
JsonNodetrees with the field names from the API reference. - CSV, JSONL, and HTML responses come back as
String, and PDF citations asbyte[]. - Filters are fluent objects from
in.manasija.drishti.params. Anything you leave unset is not sent. DrishtiClientis immutable and thread-safe. Create one and share it.
Errors
All SDK exceptions are unchecked and extend DrishtiException:
import in.manasija.drishti.exception.DrishtiApiException;
import in.manasija.drishti.exception.DrishtiNetworkException;
try {
client.getAccount();
} catch (DrishtiApiException e) { // HTTP error status, after retries
e.getStatusCode(); // e.g. 401
e.getErrorCode(); // e.g. "unauthorized"
e.getDetail(); // e.g. "Invalid API key"
} catch (DrishtiNetworkException e) { // no response, after retries
e.getCause(); // the IOException
}A blank API key throws IllegalArgumentException before any request is sent.
The client retries 408, 409, 425, 429, 500, 502, 503, and 504 responses, and network errors, up to 2 times with exponential backoff. It follows redirects up to five hops, and never sends your API key to another host, such as the file storage behind PDF citations. See Errors and rate limits for what each status means.
Configuration
DrishtiClient client = DrishtiClient.builder()
.apiKey(System.getenv("DRISHTI_API_KEY"))
.maxRetries(3)
.initialRetryDelay(Duration.ofMillis(250))
.timeout(Duration.ofSeconds(30))
.build();To use your own HTTP stack (a proxy, a custom SSL context, or a test double), implement HttpTransport and pass it with .transport(...).
WebSocket session
DrishtiWebSocketSession connects, sends your subscriptions, and dispatches events to handlers. It reconnects with backoff, resubscribes after every reconnect, and treats a silent connection as dropped after 90 seconds. Live streams need a paid plan.
DrishtiWebSocketSession ws = client.websocket()
.onSubscribed(ack -> System.out.println("subscribed " + ack.product() + " on tier " + ack.tier()))
.onAnnouncements(a -> System.out.println(a.path("symbol").asText() + ": " + a.path("summary").asText()))
.onError(e -> System.err.println(e.message() + " [" + e.code() + "]"));
ws.subscribe("announcements", List.of("RELIANCE", "TCS"));
ws.run(); // blocks; call ws.stop() from a handler or another thread to end itIn a web app or service, run the session in the background instead, and close it on shutdown:
ws.start(); // runs on a daemon thread named drishti-websocket
// ...
ws.close(); // stops the session and waits for the threadHandlers run on the session thread, one event at a time. Keep them fast and hand heavy work to an executor. An exception thrown in a handler is logged and does not drop the connection.
Batch jobs
Build the JSONL input, submit it, and wait for the results. Each line is one portfolio summary request with a custom_id.
String jsonl = Params.buildBatchInputJsonl(List.of(
Map.of("custom_id", "client-001", "symbols", List.of("TCS"), "mode", "news_context"),
Map.of("custom_id", "client-002", "symbols", List.of("RELIANCE"), "mode", "news_context")));
JsonNode job = client.submitBatchJobAndWait(
new BatchJobRequest("watchlist.jsonl", jsonl).displayName("Nightly run"),
Duration.ofSeconds(5), Duration.ofMinutes(30));
for (ObjectNode result : client.getBatchJobsJobIdResultsParsed(job.path("id").asText())) {
System.out.println(result.path("custom_id").asText() + " " + result.path("status").asText());
}See Batch jobs for the input format and limits.
Helper surface
Method names match the JavaScript and PHP SDKs. Filters go in the endpoint's params object, for example getNews(new NewsParams().symbols("TCS").limit(10)).
API wrappers
Workflow helpers
| Method | Reference |
|---|---|
waitForBatchJobCompletion | Polls getBatchJobsJobId until a terminal job status is reached. |
submitBatchJobAndWait | Calls postBatchJobsFile, then waits for completion. |
Transport helpers
| Method | Reference |
|---|---|
request | Any API route: method, path, query, path params, JSON body, and headers. Returns a DrishtiResponse. |
requestV1 | Any /v1/... route; adds the /v1 prefix when it is missing. |
get, post, put, patch, delete | Shortcuts over request. |
websocket, websocketBuilder | WebSocket streams |
Source and API reference (Javadoc) live in the drishti-sdk repository.