firstock 1.0.0 → 1.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Firstock Broking Private Limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Readme.md CHANGED
@@ -1,7 +1,8 @@
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
- `<br />` Licensed under the MIT License.
5
+ Licensed under the MIT License.
5
6
 
6
7
 
7
8
  [Version - 1.0.0](https://www.npmjs.com/package/firstock)
@@ -11,11 +12,6 @@ To communicate with the Firstock Developer API using Nodejs, you can use the off
11
12
 
12
13
  * Nodejs client documentation
13
14
 
14
- ## v3 - Changes
15
-
16
- * Error code response structured has been changed
17
- * Renamed
18
-
19
15
  ## Installing the client
20
16
 
21
17
  Use the package manager [npm](https://www.npmjs.com/) to install thefirstock.
@@ -288,3 +284,9 @@ Refer to the [Firstock Connect Documentation](https://connect.thefirstock.com/)
288
284
  ## Changelog
289
285
 
290
286
  Check release notes.
287
+
288
+
289
+
290
+
291
+
292
+
@@ -36,6 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Firstock = void 0;
39
40
  const axios_1 = __importDefault(require("axios"));
40
41
  const sha256 = __importStar(require("sha256"));
41
42
  const AFirstock_1 = __importDefault(require("./AFirstock"));
@@ -932,8 +933,8 @@ class Firstock extends AFirstock_1.default {
932
933
  callBack(err, null);
933
934
  }
934
935
  else if (jKey) {
935
- axiosInterceptor
936
- .post(`productConversion`, {
936
+ // Prepare the request payload
937
+ const requestPayload = {
937
938
  userId,
938
939
  jKey,
939
940
  exchange: params.exchange,
@@ -941,7 +942,13 @@ class Firstock extends AFirstock_1.default {
941
942
  quantity: params.quantity,
942
943
  product: params.product,
943
944
  previousProduct: params.previousProduct,
944
- })
945
+ };
946
+ // Add msgFlag to payload if provided
947
+ if (params.msgFlag) {
948
+ requestPayload.msgFlag = params.msgFlag;
949
+ }
950
+ axiosInterceptor
951
+ .post(`productConversion`, requestPayload)
945
952
  .then((response) => {
946
953
  const { data } = response;
947
954
  callBack(null, data);
@@ -1766,5 +1773,53 @@ class Firstock extends AFirstock_1.default {
1766
1773
  }
1767
1774
  });
1768
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
+ }
1769
1824
  }
1770
- exports.default = Firstock;
1825
+ exports.Firstock = Firstock;
package/dist/index.js CHANGED
@@ -1,7 +1,3 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const Firstock_1 = __importDefault(require("./Classes/Firstock"));
7
- exports.default = Firstock_1.default;
2
+ const Firstock_1 = require("./Classes/Firstock");
3
+ module.exports = Firstock_1.Firstock;
@@ -45,7 +45,20 @@ const readData = (callback) => {
45
45
  const path = "./config.json";
46
46
  fs.readFile(path, "utf-8", (err, jsonString) => {
47
47
  if (err) {
48
- callback(err, null);
48
+ if (err.code === "ENOENT") {
49
+ // File not found: create it with "{}"
50
+ fs.writeFile(path, "{}", "utf-8", (writeErr) => {
51
+ if (writeErr) {
52
+ callback(writeErr, null);
53
+ }
54
+ else {
55
+ callback(null, {}); // Return an empty object
56
+ }
57
+ });
58
+ }
59
+ else {
60
+ callback(err, null);
61
+ }
49
62
  }
50
63
  else {
51
64
  try {
package/dist/test.js CHANGED
@@ -3,17 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const Firstock_1 = __importDefault(require("./Classes/Firstock"));
7
- const firstock = new Firstock_1.default();
6
+ const index_1 = __importDefault(require("./index"));
7
+ const firstock = new index_1.default();
8
8
  let orderNumber = "";
9
- const userDetails = {
10
- userId: "",
11
- password: "",
12
- TOTP: "",
13
- vendorCode: "",
14
- apiKey: "",
15
- };
16
- // Login and user Details start
9
+ // const userDetails = {
10
+ // userId: "NP2997",
11
+ // password: "Skanda@202",
12
+ // TOTP: "1997",
13
+ // vendorCode: "NP2997_API",
14
+ // apiKey: "65d837ab42a4b0000fbe05f37ee575fb",
15
+ // };
16
+ // const userDetails = {
17
+ // userId: "",
18
+ // password: "",
19
+ // TOTP: "",
20
+ // vendorCode: "",
21
+ // apiKey: "",
22
+ // };
23
+ // // Login and user Details start
17
24
  // firstock.login(
18
25
  // {
19
26
  // userId: userDetails.userId,
@@ -155,6 +162,21 @@ const userDetails = {
155
162
  // console.log("productConversion Result: ", result);
156
163
  // }
157
164
  // );
165
+ // firstock.productConversion(
166
+ // {
167
+ // userId: userDetails.userId,
168
+ // exchange: "NFO",
169
+ // tradingSymbol: "NIFTY",
170
+ // quantity: "250",
171
+ // product: "C",
172
+ // previousProduct: "I",
173
+ // msgFlag: "1" // Buy and Day
174
+ // },
175
+ // (err: Error | string | null, result: any) => {
176
+ // console.log("productConversion (Buy & Day) Error: ", err);
177
+ // console.log("productConversion (Buy & Day) Result: ", result);
178
+ // }
179
+ // );
158
180
  // Holdings
159
181
  // firstock.holdings(
160
182
  // { userId: userDetails.userId},//, product: "C"
@@ -335,6 +357,16 @@ const userDetails = {
335
357
  // console.log("brokerageCalculator Result: ", result)
336
358
  // }
337
359
  // )
360
+ // Get Holdings Details
361
+ // firstock.getHoldingsDetails(
362
+ // {
363
+ // userId: userDetails.userId
364
+ // },
365
+ // (err: Error | null, result: any) => {
366
+ // console.log("Error: ", err);
367
+ // console.log("Result: ", result);
368
+ // }
369
+ // );
338
370
  // Logout
339
371
  // firstock.logout(
340
372
  // { userId: userDetails.userId },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firstock",
3
- "version": "1.0.0",
3
+ "version": "1.0.4",
4
4
  "description": "Node js package for using firstock developer apis",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -1,371 +0,0 @@
1
- interface Response {
2
- data: {
3
- [key: string]: any;
4
- };
5
- }
6
-
7
- interface LoginParams {
8
- userId: string;
9
- password: string;
10
- TOTP: string;
11
- vendorCode: string;
12
- apiKey: string;
13
- [key: string]: any;
14
- }
15
-
16
- interface ConfigData {
17
- [key: string]: {
18
- jKey: string;
19
- };
20
- }
21
-
22
- interface PlaceOrderParams {
23
- userId: string;
24
- exchange: string;
25
- tradingSymbol: string;
26
- quantity: string | number;
27
- price: string | number;
28
- product: string;
29
- transactionType: string;
30
- priceType: string;
31
- retention: string;
32
- remarks: string;
33
- triggerPrice: string;
34
- [key: string]: any;
35
- }
36
-
37
- interface CancelOrderParams {
38
- userId: string;
39
- orderNumber: string;
40
- [key: string]: any;
41
- }
42
-
43
- interface ModifyOrderParams {
44
- userId: string;
45
- orderNumber: string;
46
- price: string | number;
47
- quantity: string | number;
48
- triggerPrice: string | number;
49
- tradingSymbol: string;
50
- exchange: string;
51
- priceType: string;
52
- product: string;
53
- retention: string;
54
- [key: string]: any;
55
- }
56
-
57
- interface BasketItem {
58
- exchange: string;
59
- transactionType: string;
60
- product: string;
61
- tradingSymbol: string;
62
- quantity: string | number;
63
- priceType: string;
64
- price: string | number;
65
- [key: string]: any;
66
- }
67
-
68
- interface BasketMarginParams {
69
- userId: string;
70
- BasketList_Params: BasketItem[];
71
- [key: string]: any;
72
- }
73
-
74
- interface SingleOrderHistoryParams {
75
- userId: string;
76
- orderNumber: string;
77
- [key: string]: any;
78
- }
79
-
80
- interface UserDetailsParams {
81
- userId: string;
82
- [key: string]: any;
83
- }
84
-
85
- interface OrderMarginParams {
86
- userId: string;
87
- exchange: string;
88
- tradingSymbol: string;
89
- quantity: string | number;
90
- price: string | number;
91
- product: string;
92
- transactionType: string;
93
- priceType: string;
94
- [key: string]: any;
95
- }
96
-
97
- interface ProductConversionParams {
98
- userId: string;
99
- exchange: string;
100
- tradingSymbol: string;
101
- quantity: string | number;
102
- product: string;
103
- previousProduct: string;
104
- transactionType?: string;
105
- positionType?: string;
106
- [key: string]: any;
107
- }
108
-
109
- interface OrderBookParams {
110
- userId: string;
111
- [key: string]: any;
112
- }
113
-
114
- interface TradeBookParams {
115
- userId: string;
116
- [key: string]: any;
117
- }
118
-
119
- interface PositionsBookParams {
120
- userId: string;
121
- [key: string]: any;
122
- }
123
-
124
- interface MultiQuoteItem {
125
- exchange: string;
126
- tradingSymbol: string;
127
- [key: string]: any;
128
- }
129
-
130
- interface GetMultiQuotesParams {
131
- userId: string;
132
- data: MultiQuoteItem[];
133
- [key: string]: any;
134
- }
135
-
136
- interface GetQuoteLTPParams {
137
- userId: string;
138
- exchange: string;
139
- tradingSymbol: string;
140
- [key: string]: any;
141
- }
142
-
143
- interface GetMultiQuotesLTPParams {
144
- userId: string;
145
- data: MultiQuoteItem[];
146
- [key: string]: any;
147
- }
148
-
149
- interface SearchScriptsParams {
150
- userId: string;
151
- stext: string;
152
- [key: string]: any;
153
- }
154
-
155
- interface GetSecurityInfoParams {
156
- userId: string;
157
- exchange: string;
158
- tradingSymbol: string;
159
- [key: string]: any;
160
- }
161
-
162
- interface HoldingsParams {
163
- userId: string;
164
- product?: string;
165
- [key: string]: any;
166
- }
167
-
168
- interface LimitsParams {
169
- userId: string;
170
- [key: string]: any;
171
- }
172
-
173
- interface GetQuotesParams {
174
- userId: string;
175
- exchange: string;
176
- tradingSymbol: string;
177
- [key: string]: any;
178
- }
179
-
180
- interface GetIndexListParams {
181
- userId: string;
182
- exchange: string;
183
- [key: string]: any;
184
- }
185
-
186
- interface GetOptionChainParams {
187
- userId: string;
188
- exchange: string;
189
- symbol: string;
190
- strikePrice: string | number;
191
- count: string | number;
192
- expiry?: string;
193
- [key: string]: any;
194
- }
195
-
196
- interface TimePriceSeriesParams {
197
- userId: string;
198
- exchange: string;
199
- tradingSymbol: string;
200
- endTime: string;
201
- startTime: string;
202
- interval: string | number;
203
- [key: string]: any;
204
- }
205
-
206
- interface BrokerageCalculatorParams {
207
- userId: string;
208
- exchange: string;
209
- tradingSymbol: string;
210
- transactionType: string;
211
- Product: string;
212
- quantity: string | number;
213
- price: string | number;
214
- strike_price: string | number;
215
- inst_name: string;
216
- lot_size: string | number;
217
- [key: string]: any;
218
- }
219
-
220
- interface GetExpiryParams {
221
- userId: string;
222
- exchange: string;
223
- tradingSymbol: string;
224
- [key: string]: any;
225
- }
226
-
227
-
228
- abstract class AFirstock {
229
- constructor() {
230
- if (this.constructor === AFirstock) {
231
- throw new Error("Abstract classes can't be instantiated.");
232
- }
233
- }
234
-
235
- abstract getPosts(): Promise<any>;
236
-
237
- abstract getUsers(): any;
238
-
239
- abstract getPostByUserId(): any;
240
-
241
- abstract login(
242
- params: LoginParams,
243
- callBack: (error: Error | null, result: Response | null) => void
244
- ): void;
245
-
246
- abstract logout(
247
- params: { userId: string },
248
- callBack: (error: Error | string | null, result: Response | null) => void
249
- ): void;
250
-
251
- abstract userDetails(
252
- params: UserDetailsParams,
253
- callBack: (error: Error | string | null, result: Response | null) => void
254
- ): void;
255
-
256
- abstract placeOrder(
257
- params: PlaceOrderParams,
258
- callBack: (error: Error | string | null, result: Response | null) => void
259
- ): void;
260
-
261
- abstract orderMargin(
262
- params: OrderMarginParams,
263
- callBack: (error: Error | string | null, result: Response | null) => void
264
- ): void;
265
-
266
- abstract cancelOrder(
267
- params: CancelOrderParams,
268
- callBack: (error: Error | string | null, result: Response | null) => void
269
- ): void;
270
-
271
- abstract modifyOrder(
272
- params: ModifyOrderParams,
273
- callBack: (error: Error | string | null, result: Response | null) => void
274
- ): void;
275
-
276
- abstract singleOrderHistory(
277
- params: SingleOrderHistoryParams,
278
- callBack: (error: Error | string | null, result: Response | null) => void
279
- ): void;
280
- abstract orderBook(
281
- params: OrderBookParams,
282
- callBack: (error: Error | string | null, result: Response | null) => void
283
- ): void;
284
-
285
- abstract tradeBook(
286
- params: TradeBookParams,
287
- callBack: (error: Error | string | null, result: Response | null) => void
288
- ): void;
289
-
290
- abstract positionBook(
291
- params: PositionsBookParams,
292
- callBack: (error: Error | string | null, result: Response | null) => void
293
- ): void;
294
-
295
- abstract productConversion(
296
- params: ProductConversionParams,
297
- callBack: (error: Error | string | null, result: Response | null) => void
298
- ): void;
299
-
300
- abstract holdings(
301
- params: HoldingsParams,
302
- callBack: (error: Error | string | null, result: Response | null) => void
303
- ): void;
304
-
305
- abstract limit(
306
- params: LimitsParams,
307
- callBack: (error: Error | string | null, result: Response | null) => void
308
- ): void;
309
-
310
- abstract basketMargin(
311
- params: BasketMarginParams,
312
- callBack: (error: Error | string | null, result: Response | null) => void
313
- ): void;
314
-
315
- abstract getQuote(
316
- params: GetQuotesParams,
317
- callBack: (error: Error | string | null, result: Response | null) => void
318
- ): void;
319
-
320
- abstract getQuoteltp(
321
- params: GetQuoteLTPParams,
322
- callBack: (error: Error | string | null, result: Response | null) => void
323
- ): void;
324
-
325
- abstract getMultiQuotesltp(
326
- params: GetMultiQuotesLTPParams,
327
- callBack: (error: Error | string | null, result: Response | null) => void
328
- ): void;
329
-
330
- abstract getMultiQuotes(
331
- params: GetMultiQuotesParams,
332
- callBack: (error: Error | string | null, result: Response | null) => void
333
- ): void;
334
-
335
- abstract searchScrips(
336
- params: SearchScriptsParams,
337
- callBack: (error: Error | string | null, result: Response | null) => void
338
- ): void;
339
-
340
- abstract securityInfo(
341
- params: GetSecurityInfoParams,
342
- callBack: (error: Error | string | null, result: Response | null) => void
343
- ): void;
344
-
345
- abstract indexList(
346
- params: GetIndexListParams,
347
- callBack: (error: Error | string | null, result: Response | null) => void
348
- ): void;
349
-
350
- abstract optionChain(
351
- params: GetOptionChainParams,
352
- callBack: (error: Error | string | null, result: Response | null) => void
353
- ): void;
354
-
355
- abstract timePriceSeries(
356
- params: TimePriceSeriesParams,
357
- callBack: (error: Error | string | null, result: Response | null) => void
358
- ): void;
359
-
360
- abstract getExpiry(
361
- params: GetExpiryParams,
362
- callBack: (error: Error | string | null, result: Response | null) => void
363
- ): void;
364
-
365
- abstract brokerageCalculator(
366
- params: BrokerageCalculatorParams,
367
- callBack: (error: Error | string | null, result: Response | null) => void
368
- ): void;
369
- }
370
-
371
- export default AFirstock;