drishti-sdk 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,45 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Drishti SDK (JavaScript / TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official JavaScript/TypeScript SDK for the Manasija Alpha API (`/v1`).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This SDK provides:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- A typed HTTP client for all endpoints of drishti api
|
|
8
|
+
- A low-level request layer for custom endpoint access
|
|
9
|
+
- A WebSocket session client for real-time streams
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Node.js `18+`
|
|
14
|
+
- A valid Alpha API key
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Install from npm:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install drishti-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
If you are developing this package locally:
|
|
8
25
|
|
|
9
26
|
```bash
|
|
10
27
|
npm install
|
|
11
28
|
npm run build
|
|
12
29
|
```
|
|
13
30
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
31
|
+
## Quick Start
|
|
17
32
|
|
|
18
|
-
```
|
|
19
|
-
import { MarketStackClient } from "
|
|
33
|
+
```ts
|
|
34
|
+
import { MarketStackClient } from "drishti-sdk";
|
|
20
35
|
|
|
21
36
|
const client = new MarketStackClient({
|
|
22
37
|
apiKey: process.env.ALPHA_API_KEY!,
|
|
23
|
-
// Optional override. Defaults to https://developers.manasija.in
|
|
24
|
-
// baseUrl: "https://developers.manasija.in",
|
|
25
38
|
});
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
40
|
+
const news = await client.getNews({
|
|
41
|
+
symbols: ["RELIANCE", "TCS"],
|
|
42
|
+
limit: 10,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
console.log(news.data.length);
|
|
33
46
|
```
|
|
34
47
|
|
|
35
|
-
All calls automatically send `X-API-Key` using the
|
|
48
|
+
All SDK calls automatically send `X-API-Key` using the key passed to `MarketStackClient`.
|
|
36
49
|
|
|
37
|
-
|
|
50
|
+
## HTTP Usage
|
|
38
51
|
|
|
39
|
-
|
|
52
|
+
### Common endpoint examples
|
|
40
53
|
|
|
41
|
-
```
|
|
42
|
-
import { MarketStackClient } from "
|
|
54
|
+
```ts
|
|
55
|
+
import { MarketStackClient } from "drishti-sdk";
|
|
56
|
+
|
|
57
|
+
const client = new MarketStackClient({ apiKey: process.env.ALPHA_API_KEY! });
|
|
58
|
+
|
|
59
|
+
// Announcements
|
|
60
|
+
const announcements = await client.getAnnouncements({
|
|
61
|
+
symbols: ["RELIANCE"],
|
|
62
|
+
detailed: true,
|
|
63
|
+
limit: 20,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Earnings detail
|
|
67
|
+
const earnings = await client.getEarningsDetail({
|
|
68
|
+
symbol: "MEDIASSIST",
|
|
69
|
+
quarter: "q4_26",
|
|
70
|
+
detailed: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Concall transcript URLs
|
|
74
|
+
const transcript = await client.getConcallsTranscript({
|
|
75
|
+
symbol: "TCS",
|
|
76
|
+
quarter: "q4_26",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Alerts feed
|
|
80
|
+
const alerts = await client.getAlerts({
|
|
81
|
+
symbols: ["INFY"],
|
|
82
|
+
important: true,
|
|
83
|
+
limit: 25,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Account usage
|
|
87
|
+
const usage = await client.getAccountUsage();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Low-level request access
|
|
91
|
+
|
|
92
|
+
Use this when you need an endpoint not yet wrapped by a helper method.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { MarketStackClient } from "drishti-sdk";
|
|
96
|
+
|
|
97
|
+
const client = new MarketStackClient({ apiKey: process.env.ALPHA_API_KEY! });
|
|
98
|
+
|
|
99
|
+
const response = await client.request("GET", "/v1/news", {
|
|
100
|
+
query: { symbols: "RELIANCE", limit: 5 },
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
You can also use shortcut methods: `get`, `post`, `put`, `patch`, `delete`.
|
|
105
|
+
|
|
106
|
+
## Error Handling
|
|
107
|
+
|
|
108
|
+
HTTP failures throw `MarketStackApiError`.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { MarketStackApiError, MarketStackClient } from "drishti-sdk";
|
|
112
|
+
|
|
113
|
+
const client = new MarketStackClient({ apiKey: process.env.ALPHA_API_KEY! });
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
await client.getAccount();
|
|
117
|
+
} catch (error) {
|
|
118
|
+
if (error instanceof MarketStackApiError) {
|
|
119
|
+
console.error(error.statusCode);
|
|
120
|
+
console.error(error.body);
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## WebSocket Usage (`/v1/ws`)
|
|
127
|
+
|
|
128
|
+
### Async iterator style
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { MarketStackClient } from "drishti-sdk";
|
|
43
132
|
|
|
44
133
|
const client = new MarketStackClient({ apiKey: process.env.ALPHA_API_KEY! });
|
|
45
134
|
const ws = client.websocket();
|
|
@@ -49,46 +138,113 @@ await ws.subscribe({ product: "announcements", symbols: ["RELIANCE"], detailed:
|
|
|
49
138
|
|
|
50
139
|
for await (const event of ws.events()) {
|
|
51
140
|
if (event.kind === "subscribed") {
|
|
52
|
-
console.log("
|
|
141
|
+
console.log("subscribed", event.product, event.tier);
|
|
53
142
|
} else if (event.kind === "data") {
|
|
54
|
-
console.log(event.channel, event.data
|
|
143
|
+
console.log(event.channel, event.data);
|
|
144
|
+
} else if (event.kind === "error") {
|
|
145
|
+
console.error(event.message);
|
|
55
146
|
}
|
|
56
147
|
}
|
|
57
|
-
|
|
58
|
-
await ws.close();
|
|
59
148
|
```
|
|
60
149
|
|
|
61
|
-
|
|
150
|
+
### Callback style with reconnect
|
|
62
151
|
|
|
63
|
-
```
|
|
64
|
-
import {
|
|
152
|
+
```ts
|
|
153
|
+
import { MarketStackClient } from "drishti-sdk";
|
|
65
154
|
|
|
66
|
-
const
|
|
67
|
-
|
|
155
|
+
const client = new MarketStackClient({ apiKey: process.env.ALPHA_API_KEY! });
|
|
156
|
+
|
|
157
|
+
const ws = client.websocket({
|
|
68
158
|
autoReconnect: true,
|
|
159
|
+
reconnectInitialDelayMs: 1000,
|
|
160
|
+
reconnectMaxDelayMs: 30000,
|
|
161
|
+
onReconnectAttempt: (attempt, delayMs, reason) => {
|
|
162
|
+
console.log("reconnect", { attempt, delayMs, reason });
|
|
163
|
+
},
|
|
164
|
+
onData: (event) => {
|
|
165
|
+
if (event.kind === "data") console.log(event.channel, event.data);
|
|
166
|
+
},
|
|
69
167
|
});
|
|
70
168
|
|
|
71
169
|
await ws.connect();
|
|
72
|
-
await ws.subscribe({ product: "
|
|
170
|
+
await ws.subscribe({ product: "alerts", symbols: ["RELIANCE"] });
|
|
73
171
|
await ws.run();
|
|
74
172
|
```
|
|
75
173
|
|
|
76
|
-
|
|
174
|
+
Direct import is also supported:
|
|
77
175
|
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
176
|
+
```ts
|
|
177
|
+
import { AlphaWebSocketSession } from "drishti-sdk";
|
|
178
|
+
```
|
|
82
179
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
180
|
+
## Batch Jobs
|
|
181
|
+
|
|
182
|
+
Upload JSONL files for batch processing:
|
|
86
183
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
184
|
+
```ts
|
|
185
|
+
import { readFile } from "node:fs/promises";
|
|
186
|
+
import { Blob } from "node:buffer";
|
|
187
|
+
import { MarketStackClient } from "drishti-sdk";
|
|
188
|
+
|
|
189
|
+
const client = new MarketStackClient({ apiKey: process.env.ALPHA_API_KEY! });
|
|
190
|
+
|
|
191
|
+
const fileBuffer = await readFile("./batch.jsonl");
|
|
192
|
+
const fileBlob = new Blob([fileBuffer], { type: "application/jsonl" });
|
|
193
|
+
|
|
194
|
+
const job = await client.postBatchJobsFile({
|
|
195
|
+
file: fileBlob,
|
|
196
|
+
filename: "batch.jsonl",
|
|
197
|
+
display_name: "Quarterly run",
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const status = await client.getBatchJobsJobId({ job_id: job.id });
|
|
94
201
|
```
|
|
202
|
+
|
|
203
|
+
## API Surface
|
|
204
|
+
|
|
205
|
+
### REST helper methods
|
|
206
|
+
|
|
207
|
+
- `getNews`
|
|
208
|
+
- `getSymbolsMetadata`
|
|
209
|
+
- `getAnnouncementsCategories`
|
|
210
|
+
- `getAnnouncements`
|
|
211
|
+
- `getAnnouncementsAttachments`
|
|
212
|
+
- `postDailySummary`
|
|
213
|
+
- `getEarnings`
|
|
214
|
+
- `getEarningsDetail`
|
|
215
|
+
- `getEarningsAttachments`
|
|
216
|
+
- `getConcalls`
|
|
217
|
+
- `getConcallsDetail`
|
|
218
|
+
- `getConcallsTranscript`
|
|
219
|
+
- `postConcallsTranscripts`
|
|
220
|
+
- `getAlerts`
|
|
221
|
+
- `getAccount`
|
|
222
|
+
- `getAccountLimits`
|
|
223
|
+
- `getAccountUsage`
|
|
224
|
+
- `getAccountLedger`
|
|
225
|
+
- `postBatchJobs`
|
|
226
|
+
- `postBatchJobsFile`
|
|
227
|
+
- `getBatchJobs`
|
|
228
|
+
- `getBatchJobsJobId`
|
|
229
|
+
- `deleteBatchJobsJobId`
|
|
230
|
+
- `getBatchJobsJobIdResults`
|
|
231
|
+
- `websocket`
|
|
232
|
+
|
|
233
|
+
### Low-level HTTP methods
|
|
234
|
+
|
|
235
|
+
- `request`
|
|
236
|
+
- `get`
|
|
237
|
+
- `post`
|
|
238
|
+
- `put`
|
|
239
|
+
- `patch`
|
|
240
|
+
- `delete`
|
|
241
|
+
|
|
242
|
+
## TypeScript Support
|
|
243
|
+
|
|
244
|
+
The package ships with `.d.ts` files and typed request/response models from:
|
|
245
|
+
|
|
246
|
+
- `types.ts` (response payloads)
|
|
247
|
+
- `params.ts` (query/body input models)
|
|
248
|
+
|
|
249
|
+
This enables strong autocomplete and type checking for both endpoint helpers and WebSocket events.
|
|
250
|
+
|