firstock 1.0.1 → 1.0.5
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 +151 -1
- package/dist/Classes/Firstock.js +57 -3
- package/dist/test.js +48 -19
- package/dist/websockets/websocket_functions.js +668 -0
- package/dist/websockets/websockets.js +213 -0
- package/package.json +5 -2
- package/websockets/test_websockets.js +187 -0
- package/config.json +0 -3
package/Readme.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
|
|
1
2
|
# The Firstock Developer API Nodejs client -
|
|
2
3
|
|
|
3
4
|
To communicate with the Firstock Developer API using Nodejs, you can use the official Nodejs client library provided by Firstock.
|
|
4
5
|
Licensed under the MIT License.
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
[Version - 1.0.
|
|
8
|
+
[Version - 1.0.5](https://www.npmjs.com/package/firstock)
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
## Documentation
|
|
@@ -276,6 +277,149 @@ firstock.timePriceSeries({
|
|
|
276
277
|
});
|
|
277
278
|
```
|
|
278
279
|
|
|
280
|
+
```javascript
|
|
281
|
+
WebSockets
|
|
282
|
+
|
|
283
|
+
Order Update Feed
|
|
284
|
+
|
|
285
|
+
const { Firstock, FirstockWebSocket } = require('./websockets');
|
|
286
|
+
|
|
287
|
+
// Define callback method
|
|
288
|
+
function orderBookData(data) {
|
|
289
|
+
console.log(data);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const userId = 'YOUR_USER_ID';
|
|
293
|
+
|
|
294
|
+
const model = new FirstockWebSocket({
|
|
295
|
+
order_data: orderBookData
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
async function main() {
|
|
299
|
+
const [conn, err] = await Firstock.initializeWebsockets(userId, model);
|
|
300
|
+
console.log("Error:", err);
|
|
301
|
+
|
|
302
|
+
await new Promise(resolve => setTimeout(resolve, 25000));
|
|
303
|
+
|
|
304
|
+
// Close WebSocket connection
|
|
305
|
+
const closeErr = await Firstock.closeWebsocket(conn);
|
|
306
|
+
console.log("Close Error:", closeErr);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
main();
|
|
310
|
+
|
|
311
|
+
Position Update Feed
|
|
312
|
+
|
|
313
|
+
const { Firstock, FirstockWebSocket } = require('./websockets');
|
|
314
|
+
|
|
315
|
+
// Define callback method
|
|
316
|
+
function positionBookData(data) {
|
|
317
|
+
console.log(data);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const userId = 'YOUR_USER_ID';
|
|
321
|
+
|
|
322
|
+
const model = new FirstockWebSocket({
|
|
323
|
+
position_data: positionBookData
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
async function main() {
|
|
327
|
+
const [conn, err] = await Firstock.initializeWebsockets(userId, model);
|
|
328
|
+
console.log("Error:", err);
|
|
329
|
+
|
|
330
|
+
await new Promise(resolve => setTimeout(resolve, 25000));
|
|
331
|
+
|
|
332
|
+
// Close WebSocket connection
|
|
333
|
+
const closeErr = await Firstock.closeWebsocket(conn);
|
|
334
|
+
console.log("Close Error:", closeErr);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
main();
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
Subscribe Feed
|
|
341
|
+
|
|
342
|
+
const { Firstock, FirstockWebSocket } = require('./websockets');
|
|
343
|
+
|
|
344
|
+
// Define callback method
|
|
345
|
+
function subscribeFeedData(data) {
|
|
346
|
+
console.log(data);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const userId = 'YOUR_USER_ID';
|
|
350
|
+
|
|
351
|
+
const model = new FirstockWebSocket({
|
|
352
|
+
subscribe_feed_data: subscribeFeedData,
|
|
353
|
+
tokens: ["NSE:26000"]
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
async function main() {
|
|
357
|
+
const [conn, err] = await Firstock.initializeWebsockets(userId, model);
|
|
358
|
+
console.log("Error:", err);
|
|
359
|
+
|
|
360
|
+
if (conn) {
|
|
361
|
+
const subscribeErr = await Firstock.subscribe(conn, ["BSE:1"]);
|
|
362
|
+
console.log("Subscribe Error:", subscribeErr);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
await new Promise(resolve => setTimeout(resolve, 25000));
|
|
366
|
+
|
|
367
|
+
// Unsubscribe
|
|
368
|
+
const unsubErr = await Firstock.unsubscribe(conn, ["NSE:26000", "BSE:1"]);
|
|
369
|
+
console.log("Unsubscribe Error:", unsubErr);
|
|
370
|
+
|
|
371
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
372
|
+
|
|
373
|
+
// Close WebSocket connection
|
|
374
|
+
const closeErr = await Firstock.closeWebsocket(conn);
|
|
375
|
+
console.log("Close Error:", closeErr);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
main();
|
|
379
|
+
|
|
380
|
+
Subscribe Option Greeks Feed
|
|
381
|
+
|
|
382
|
+
const { Firstock, FirstockWebSocket } = require('./websockets');
|
|
383
|
+
|
|
384
|
+
// Define callback method
|
|
385
|
+
function subscribeOptionGreeksData(data) {
|
|
386
|
+
console.log(data);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const userId = 'YOUR_USER_ID';
|
|
390
|
+
|
|
391
|
+
const model = new FirstockWebSocket({
|
|
392
|
+
subscribe_option_greeks_data: subscribeOptionGreeksData,
|
|
393
|
+
option_greeks_tokens: ["NFO:44297"]
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
async function main() {
|
|
397
|
+
const [conn, err] = await Firstock.initializeWebsockets(userId, model);
|
|
398
|
+
console.log("Error:", err);
|
|
399
|
+
|
|
400
|
+
if (conn) {
|
|
401
|
+
const subscribeErr = await Firstock.subscribeOptionGreeks(conn, ["NFO:44298"]);
|
|
402
|
+
console.log("Subscribe Error:", subscribeErr);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
await new Promise(resolve => setTimeout(resolve, 25000));
|
|
406
|
+
|
|
407
|
+
// Unsubscribe
|
|
408
|
+
const unsubErr = await Firstock.unsubscribeOptionGreeks(conn, ["NFO:44297", "NFO:44298"]);
|
|
409
|
+
console.log("Unsubscribe Error:", unsubErr);
|
|
410
|
+
|
|
411
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
412
|
+
|
|
413
|
+
// Close WebSocket connection
|
|
414
|
+
const closeErr = await Firstock.closeWebsocket(conn);
|
|
415
|
+
console.log("Close Error:", closeErr);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
main();
|
|
419
|
+
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
|
|
279
423
|
Refer to the [Firstock Connect Documentation](https://connect.thefirstock.com/) for the complete list of supported methods.
|
|
280
424
|
|
|
281
425
|
|
|
@@ -283,3 +427,9 @@ Refer to the [Firstock Connect Documentation](https://connect.thefirstock.com/)
|
|
|
283
427
|
## Changelog
|
|
284
428
|
|
|
285
429
|
Check release notes.
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
package/dist/Classes/Firstock.js
CHANGED
|
@@ -933,8 +933,8 @@ class Firstock extends AFirstock_1.default {
|
|
|
933
933
|
callBack(err, null);
|
|
934
934
|
}
|
|
935
935
|
else if (jKey) {
|
|
936
|
-
|
|
937
|
-
|
|
936
|
+
// Prepare the request payload
|
|
937
|
+
const requestPayload = {
|
|
938
938
|
userId,
|
|
939
939
|
jKey,
|
|
940
940
|
exchange: params.exchange,
|
|
@@ -942,7 +942,13 @@ class Firstock extends AFirstock_1.default {
|
|
|
942
942
|
quantity: params.quantity,
|
|
943
943
|
product: params.product,
|
|
944
944
|
previousProduct: params.previousProduct,
|
|
945
|
-
}
|
|
945
|
+
};
|
|
946
|
+
// Add msgFlag to payload if provided
|
|
947
|
+
if (params.msgFlag) {
|
|
948
|
+
requestPayload.msgFlag = params.msgFlag;
|
|
949
|
+
}
|
|
950
|
+
axiosInterceptor
|
|
951
|
+
.post(`productConversion`, requestPayload)
|
|
946
952
|
.then((response) => {
|
|
947
953
|
const { data } = response;
|
|
948
954
|
callBack(null, data);
|
|
@@ -1767,5 +1773,53 @@ class Firstock extends AFirstock_1.default {
|
|
|
1767
1773
|
}
|
|
1768
1774
|
});
|
|
1769
1775
|
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Retrieves holdings details for a user from the Firstock API.
|
|
1778
|
+
*
|
|
1779
|
+
* This method sends a request to the Firstock holdingsDetails endpoint using the provided
|
|
1780
|
+
* user ID and session token (jKey) retrieved from config.json. The response contains the user's holdings information.
|
|
1781
|
+
*
|
|
1782
|
+
* @param {Object} params - Holdings parameters.
|
|
1783
|
+
* @param {string} params.userId - Firstock user ID (e.g., SU2707).
|
|
1784
|
+
* @param {function} callBack - Callback with `(error, result)`:
|
|
1785
|
+
* - `error`: Error object if the request fails.
|
|
1786
|
+
* - `result`: Parsed response containing holdings information if successful.
|
|
1787
|
+
*/
|
|
1788
|
+
getHoldingsDetails({ userId }, callBack) {
|
|
1789
|
+
(0, commonFunction_1.readData)((err, data) => {
|
|
1790
|
+
if (err) {
|
|
1791
|
+
const errorMessage = err instanceof Error ? err.message : err;
|
|
1792
|
+
callBack(new Error((0, commonFunction_1.errorMessageMapping)({ message: errorMessage })), null);
|
|
1793
|
+
}
|
|
1794
|
+
else if (data) {
|
|
1795
|
+
(0, commonFunction_1.checkifUserLoggedIn)({ userId, jsonData: data }, (err, jKey) => {
|
|
1796
|
+
if (err) {
|
|
1797
|
+
callBack(new Error(err), null);
|
|
1798
|
+
}
|
|
1799
|
+
else if (jKey) {
|
|
1800
|
+
axiosInterceptor
|
|
1801
|
+
.post("holdingsDetails", {
|
|
1802
|
+
userId,
|
|
1803
|
+
jKey
|
|
1804
|
+
})
|
|
1805
|
+
.then((response) => {
|
|
1806
|
+
const { data } = response;
|
|
1807
|
+
this.userId = userId;
|
|
1808
|
+
callBack(null, data);
|
|
1809
|
+
})
|
|
1810
|
+
.catch((error) => {
|
|
1811
|
+
callBack((0, commonFunction_1.handleError)(error), null);
|
|
1812
|
+
});
|
|
1813
|
+
}
|
|
1814
|
+
else {
|
|
1815
|
+
callBack(new Error("No jKey found for userId in config.json"), null);
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
else {
|
|
1820
|
+
callBack(new Error("No config data found"), null);
|
|
1821
|
+
}
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1770
1824
|
}
|
|
1771
1825
|
exports.Firstock = Firstock;
|
package/dist/test.js
CHANGED
|
@@ -7,26 +7,30 @@ const index_1 = __importDefault(require("./index"));
|
|
|
7
7
|
const firstock = new index_1.default();
|
|
8
8
|
let orderNumber = "";
|
|
9
9
|
const userDetails = {
|
|
10
|
-
userId: "",
|
|
11
|
-
password: "",
|
|
12
|
-
TOTP: "",
|
|
13
|
-
vendorCode: "",
|
|
14
|
-
apiKey: "",
|
|
10
|
+
userId: "NP2997",
|
|
11
|
+
password: "Skanda@2025",
|
|
12
|
+
TOTP: "1997",
|
|
13
|
+
vendorCode: "NP2997_API",
|
|
14
|
+
apiKey: "e55eb28e18ee1337fc0b2705f9b82465",
|
|
15
15
|
};
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
// const userDetails = {
|
|
17
|
+
// userId: "",
|
|
18
|
+
// password: "",
|
|
19
|
+
// TOTP: "",
|
|
20
|
+
// vendorCode: "",
|
|
21
|
+
// apiKey: "",
|
|
22
|
+
// };
|
|
23
|
+
// // Login and user Details start
|
|
24
|
+
firstock.login({
|
|
25
|
+
userId: userDetails.userId,
|
|
26
|
+
password: userDetails.password,
|
|
27
|
+
TOTP: userDetails.TOTP,
|
|
28
|
+
vendorCode: userDetails.vendorCode,
|
|
29
|
+
apiKey: userDetails.apiKey,
|
|
30
|
+
}, (err, result) => {
|
|
31
|
+
console.log("Error: ", err);
|
|
32
|
+
console.log("Result: ", result);
|
|
33
|
+
});
|
|
30
34
|
// // Order and report start
|
|
31
35
|
// firstock.placeOrder(
|
|
32
36
|
// {
|
|
@@ -155,6 +159,21 @@ const userDetails = {
|
|
|
155
159
|
// console.log("productConversion Result: ", result);
|
|
156
160
|
// }
|
|
157
161
|
// );
|
|
162
|
+
// firstock.productConversion(
|
|
163
|
+
// {
|
|
164
|
+
// userId: userDetails.userId,
|
|
165
|
+
// exchange: "NFO",
|
|
166
|
+
// tradingSymbol: "NIFTY",
|
|
167
|
+
// quantity: "250",
|
|
168
|
+
// product: "C",
|
|
169
|
+
// previousProduct: "I",
|
|
170
|
+
// msgFlag: "1" // Buy and Day
|
|
171
|
+
// },
|
|
172
|
+
// (err: Error | string | null, result: any) => {
|
|
173
|
+
// console.log("productConversion (Buy & Day) Error: ", err);
|
|
174
|
+
// console.log("productConversion (Buy & Day) Result: ", result);
|
|
175
|
+
// }
|
|
176
|
+
// );
|
|
158
177
|
// Holdings
|
|
159
178
|
// firstock.holdings(
|
|
160
179
|
// { userId: userDetails.userId},//, product: "C"
|
|
@@ -335,6 +354,16 @@ const userDetails = {
|
|
|
335
354
|
// console.log("brokerageCalculator Result: ", result)
|
|
336
355
|
// }
|
|
337
356
|
// )
|
|
357
|
+
// Get Holdings Details
|
|
358
|
+
// firstock.getHoldingsDetails(
|
|
359
|
+
// {
|
|
360
|
+
// userId: userDetails.userId
|
|
361
|
+
// },
|
|
362
|
+
// (err: Error | null, result: any) => {
|
|
363
|
+
// console.log("Error: ", err);
|
|
364
|
+
// console.log("Result: ", result);
|
|
365
|
+
// }
|
|
366
|
+
// );
|
|
338
367
|
// Logout
|
|
339
368
|
// firstock.logout(
|
|
340
369
|
// { userId: userDetails.userId },
|