@ganaka/sdk 1.4.0 → 1.5.0

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/dist/index.mjs CHANGED
@@ -4344,6 +4344,27 @@ const p = object({
4344
4344
  })
4345
4345
  })
4346
4346
  }, P = {
4347
+ query: object({
4348
+ end_datetime: n,
4349
+ timezone: o.optional()
4350
+ }),
4351
+ response: t.extend({
4352
+ data: object({
4353
+ niftyTimeline: array(
4354
+ object({
4355
+ id: string(),
4356
+ timestamp: string(),
4357
+ // Format: YYYY-MM-DDTHH:mm:ss (UTC)
4358
+ quoteData: a,
4359
+ createdAt: string(),
4360
+ // Format: YYYY-MM-DDTHH:mm:ss (UTC)
4361
+ updatedAt: string()
4362
+ // Format: YYYY-MM-DDTHH:mm:ss (UTC)
4363
+ })
4364
+ )
4365
+ })
4366
+ })
4367
+ }, q = {
4347
4368
  query: object({
4348
4369
  datetime: n.optional(),
4349
4370
  timezone: o.optional()
@@ -4351,10 +4372,11 @@ const p = object({
4351
4372
  response: t.extend({
4352
4373
  data: a.nullable()
4353
4374
  })
4354
- }, je = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4375
+ }, he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4355
4376
  __proto__: null,
4356
4377
  getGrowwHistoricalCandles: v,
4357
- getGrowwNiftyQuote: P,
4378
+ getGrowwNiftyQuote: q,
4379
+ getGrowwNiftyQuoteTimeline: P,
4358
4380
  getGrowwQuote: f,
4359
4381
  getGrowwQuoteTimeline: x,
4360
4382
  getGrowwToken: T,
@@ -4372,11 +4394,11 @@ const p = object({
4372
4394
  response: t.extend({
4373
4395
  data: array(g).nullable()
4374
4396
  })
4375
- }, he = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4397
+ }, Se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4376
4398
  __proto__: null,
4377
4399
  getLists: O,
4378
4400
  listSchema: g
4379
- }, Symbol.toStringTag, { value: "Module" })), q = {
4401
+ }, Symbol.toStringTag, { value: "Module" })), w = {
4380
4402
  query: object({
4381
4403
  type: _enum(["top-gainers", "volume-shockers"]),
4382
4404
  start_datetime: n,
@@ -4400,9 +4422,9 @@ const p = object({
4400
4422
  )
4401
4423
  })
4402
4424
  })
4403
- }, Se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4425
+ }, ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4404
4426
  __proto__: null,
4405
- getShortlistPersistence: q
4427
+ getShortlistPersistence: w
4406
4428
  }, Symbol.toStringTag, { value: "Module" })), z = {
4407
4429
  query: object({}),
4408
4430
  response: t.extend({
@@ -4417,10 +4439,10 @@ const p = object({
4417
4439
  )
4418
4440
  })
4419
4441
  })
4420
- }, w = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4442
+ }, D = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4421
4443
  __proto__: null,
4422
4444
  getAvailableDatetimes: z
4423
- }, Symbol.toStringTag, { value: "Module" })), D = {
4445
+ }, Symbol.toStringTag, { value: "Module" })), C = {
4424
4446
  query: object({
4425
4447
  symbol: string(),
4426
4448
  date: i,
@@ -4442,10 +4464,10 @@ const p = object({
4442
4464
  interval_in_minutes: number$1()
4443
4465
  })
4444
4466
  })
4445
- }, C = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4467
+ }, M = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4446
4468
  __proto__: null,
4447
- getCandles: D
4448
- }, Symbol.toStringTag, { value: "Module" })), M = {
4469
+ getCandles: C
4470
+ }, Symbol.toStringTag, { value: "Module" })), A = {
4449
4471
  query: object({
4450
4472
  date: i,
4451
4473
  type: _enum(t$1)
@@ -4467,8 +4489,8 @@ const p = object({
4467
4489
  })
4468
4490
  }, R = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4469
4491
  __proto__: null,
4470
- getDailyPersistentCompanies: M
4471
- }, Symbol.toStringTag, { value: "Module" })), A = {
4492
+ getDailyPersistentCompanies: A
4493
+ }, Symbol.toStringTag, { value: "Module" })), k = {
4472
4494
  query: object({
4473
4495
  date: i,
4474
4496
  type: _enum(t$1)
@@ -4480,23 +4502,23 @@ const p = object({
4480
4502
  uniqueCount: number$1()
4481
4503
  })
4482
4504
  })
4483
- }, k = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4505
+ }, E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4484
4506
  __proto__: null,
4485
- getDailyUniqueCompanies: A
4486
- }, Symbol.toStringTag, { value: "Module" })), E = object({
4507
+ getDailyUniqueCompanies: k
4508
+ }, Symbol.toStringTag, { value: "Module" })), I = object({
4487
4509
  id: uuid(),
4488
4510
  username: string()
4489
- }), I = {
4511
+ }), N = {
4490
4512
  body: object({
4491
4513
  developerToken: string().nonempty("Developer token is required")
4492
4514
  }),
4493
4515
  response: t.extend({
4494
- data: E
4516
+ data: I
4495
4517
  })
4496
- }, L = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4518
+ }, G = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4497
4519
  __proto__: null,
4498
- signIn: I
4499
- }, Symbol.toStringTag, { value: "Module" })), N = {
4520
+ signIn: N
4521
+ }, Symbol.toStringTag, { value: "Module" })), L = {
4500
4522
  query: object({
4501
4523
  symbol: string(),
4502
4524
  date: i
@@ -4518,9 +4540,9 @@ const p = object({
4518
4540
  )
4519
4541
  })
4520
4542
  })
4521
- }, G = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4543
+ }, Q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4522
4544
  __proto__: null,
4523
- getQuoteTimeline: N
4545
+ getQuoteTimeline: L
4524
4546
  }, Symbol.toStringTag, { value: "Module" })), U = object({
4525
4547
  id: uuid(),
4526
4548
  start_datetime: string(),
@@ -4529,15 +4551,15 @@ const p = object({
4529
4551
  orderCount: number$1(),
4530
4552
  name: string().nullable().optional(),
4531
4553
  tags: array(string()).optional()
4532
- }), Q = record(
4554
+ }), Y = record(
4533
4555
  string(),
4534
4556
  // date string (YYYY-MM-DD)
4535
4557
  array(U)
4536
- ), Y = {
4558
+ ), H = {
4537
4559
  response: t.extend({
4538
- data: Q
4560
+ data: Y
4539
4561
  })
4540
- }, H = object({
4562
+ }, $ = object({
4541
4563
  id: uuid(),
4542
4564
  nseSymbol: string(),
4543
4565
  entryPrice: number(),
@@ -4556,7 +4578,7 @@ const p = object({
4556
4578
  stopLossHit: boolean().optional(),
4557
4579
  stopLossTimestamp: string().optional(),
4558
4580
  timeToStopLossMinutes: number$1().optional()
4559
- }), $ = {
4581
+ }), F = {
4560
4582
  params: object({
4561
4583
  runId: uuid()
4562
4584
  }),
@@ -4564,46 +4586,46 @@ const p = object({
4564
4586
  targetGainPercentage: number().optional()
4565
4587
  }),
4566
4588
  response: t.extend({
4567
- data: array(H)
4589
+ data: array($)
4568
4590
  })
4569
- }, F = object({
4591
+ }, B = object({
4570
4592
  start_datetime: n,
4571
4593
  end_datetime: n,
4572
4594
  timezone: o.optional(),
4573
4595
  name: string().optional(),
4574
4596
  tags: array(string().min(1).max(50)).optional()
4575
- }), B = object({
4597
+ }), K = object({
4576
4598
  id: uuid(),
4577
4599
  start_datetime: n,
4578
4600
  end_datetime: n,
4579
4601
  completed: boolean(),
4580
4602
  name: string().nullable().optional(),
4581
4603
  tags: array(string()).optional()
4582
- }), K = {
4583
- body: F,
4604
+ }), Z = {
4605
+ body: B,
4584
4606
  response: t.extend({
4585
- data: B
4607
+ data: K
4586
4608
  })
4587
- }, Z = object({
4609
+ }, V = object({
4588
4610
  completed: boolean().optional(),
4589
4611
  name: string().nullable().optional(),
4590
4612
  tags: array(string().min(1).max(50)).optional()
4591
- }), V = object({
4613
+ }), J = object({
4592
4614
  id: uuid(),
4593
4615
  start_datetime: string(),
4594
4616
  end_datetime: string(),
4595
4617
  completed: boolean(),
4596
4618
  name: string().nullable().optional(),
4597
4619
  tags: array(string()).optional()
4598
- }), J = {
4620
+ }), W = {
4599
4621
  params: object({
4600
4622
  runId: uuid()
4601
4623
  }),
4602
- body: Z,
4624
+ body: V,
4603
4625
  response: t.extend({
4604
- data: V
4626
+ data: J
4605
4627
  })
4606
- }, W = {
4628
+ }, X = {
4607
4629
  params: object({
4608
4630
  runId: uuid()
4609
4631
  }),
@@ -4612,14 +4634,14 @@ const p = object({
4612
4634
  id: uuid()
4613
4635
  })
4614
4636
  })
4615
- }, X = object({
4637
+ }, ee = object({
4616
4638
  nseSymbol: string(),
4617
4639
  entryPrice: number(),
4618
4640
  stopLossPrice: number(),
4619
4641
  takeProfitPrice: number(),
4620
4642
  datetime: n,
4621
4643
  timezone: o.optional()
4622
- }), ee = object({
4644
+ }), te = object({
4623
4645
  id: uuid(),
4624
4646
  nseSymbol: string(),
4625
4647
  entryPrice: number(),
@@ -4627,28 +4649,28 @@ const p = object({
4627
4649
  takeProfitPrice: number(),
4628
4650
  datetime: string(),
4629
4651
  runId: uuid()
4630
- }), te = {
4652
+ }), ne = {
4631
4653
  params: object({
4632
4654
  runId: uuid()
4633
4655
  }),
4634
- body: X,
4656
+ body: ee,
4635
4657
  response: t.extend({
4636
- data: ee
4658
+ data: te
4637
4659
  })
4638
- }, ne = {
4660
+ }, oe = {
4639
4661
  response: t.extend({
4640
4662
  data: array(string())
4641
4663
  })
4642
- }, oe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4664
+ }, ae = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4643
4665
  __proto__: null,
4644
- createOrder: te,
4645
- createRun: K,
4646
- deleteRun: W,
4647
- getRunOrders: $,
4648
- getRunTags: ne,
4649
- getRuns: Y,
4650
- updateRun: J
4651
- }, Symbol.toStringTag, { value: "Module" })), ae = {
4666
+ createOrder: ne,
4667
+ createRun: Z,
4668
+ deleteRun: X,
4669
+ getRunOrders: F,
4670
+ getRunTags: oe,
4671
+ getRuns: H,
4672
+ updateRun: W
4673
+ }, Symbol.toStringTag, { value: "Module" })), re = {
4652
4674
  query: object({
4653
4675
  datetime: n,
4654
4676
  timezone: o.optional(),
@@ -4665,19 +4687,19 @@ const p = object({
4665
4687
  }).nullable()
4666
4688
  })
4667
4689
  })
4668
- }, re = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4690
+ }, se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4669
4691
  __proto__: null,
4670
- getShortlists: ae
4671
- }, Symbol.toStringTag, { value: "Module" })), ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4692
+ getShortlists: re
4693
+ }, Symbol.toStringTag, { value: "Module" })), fe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4672
4694
  __proto__: null,
4673
- v1_dashboard_auth_schemas: L,
4674
- v1_dashboard_available_datetimes_schemas: w,
4675
- v1_dashboard_candles_schemas: C,
4695
+ v1_dashboard_auth_schemas: G,
4696
+ v1_dashboard_available_datetimes_schemas: D,
4697
+ v1_dashboard_candles_schemas: M,
4676
4698
  v1_dashboard_daily_persistent_companies_schemas: R,
4677
- v1_dashboard_daily_unique_companies_schemas: k,
4678
- v1_dashboard_quote_timeline_schemas: G,
4679
- v1_dashboard_runs_schemas: oe,
4680
- v1_dashboard_shortlists_schemas: re
4699
+ v1_dashboard_daily_unique_companies_schemas: E,
4700
+ v1_dashboard_quote_timeline_schemas: Q,
4701
+ v1_dashboard_runs_schemas: ae,
4702
+ v1_dashboard_shortlists_schemas: se
4681
4703
  }, Symbol.toStringTag, { value: "Module" }));
4682
4704
  ({
4683
4705
  response: t.extend({
@@ -7966,7 +7988,7 @@ const fetchCandles = ({
7966
7988
  );
7967
7989
  }
7968
7990
  try {
7969
- const validatedParams = je.getGrowwHistoricalCandles.query.parse(params);
7991
+ const validatedParams = he.getGrowwHistoricalCandles.query.parse(params);
7970
7992
  const headers = {
7971
7993
  Authorization: `Bearer ${developerToken}`
7972
7994
  };
@@ -7979,7 +8001,7 @@ const fetchCandles = ({
7979
8001
  if (currentTimezone) {
7980
8002
  headers["X-Current-Timezone"] = currentTimezone;
7981
8003
  }
7982
- const response = await axios.get(`${apiDomain}/v1/developer/groww/historical-candles`, {
8004
+ const response = await axios.get(`${apiDomain}/v1/developer/historical-candles`, {
7983
8005
  params: validatedParams,
7984
8006
  headers
7985
8007
  });
@@ -8010,7 +8032,7 @@ const fetchQuote = ({
8010
8032
  );
8011
8033
  }
8012
8034
  try {
8013
- const validatedParams = je.getGrowwQuote.query.parse(params);
8035
+ const validatedParams = he.getGrowwQuote.query.parse(params);
8014
8036
  const headers = {
8015
8037
  Authorization: `Bearer ${developerToken}`
8016
8038
  };
@@ -8023,7 +8045,7 @@ const fetchQuote = ({
8023
8045
  if (currentTimezone) {
8024
8046
  headers["X-Current-Timezone"] = currentTimezone;
8025
8047
  }
8026
- const response = await axios.get(`${apiDomain}/v1/developer/groww/quote`, {
8048
+ const response = await axios.get(`${apiDomain}/v1/developer/quote`, {
8027
8049
  params: validatedParams,
8028
8050
  headers
8029
8051
  });
@@ -8045,14 +8067,14 @@ const fetchQuoteTimeline = ({
8045
8067
  runId,
8046
8068
  currentTimestamp,
8047
8069
  currentTimezone = "Asia/Kolkata"
8048
- }) => async (symbol, date2) => {
8070
+ }) => async (symbol, end_datetime) => {
8049
8071
  if (!developerToken) {
8050
8072
  throw new Error("Developer token not found. Please set DEVELOPER_KEY environment variable.");
8051
8073
  }
8052
8074
  try {
8053
- const validatedParams = je.getGrowwQuoteTimeline.query.parse({
8075
+ const validatedParams = he.getGrowwQuoteTimeline.query.parse({
8054
8076
  symbol,
8055
- date: date2
8077
+ end_datetime
8056
8078
  });
8057
8079
  const headers = {
8058
8080
  Authorization: `Bearer ${developerToken}`
@@ -8066,7 +8088,7 @@ const fetchQuoteTimeline = ({
8066
8088
  if (currentTimezone) {
8067
8089
  headers["X-Current-Timezone"] = currentTimezone;
8068
8090
  }
8069
- const response = await axios.get(`${apiDomain}/v1/developer/groww/quote-timeline`, {
8091
+ const response = await axios.get(`${apiDomain}/v1/developer/quote-timeline`, {
8070
8092
  params: validatedParams,
8071
8093
  headers
8072
8094
  });
@@ -8097,7 +8119,7 @@ const fetchShortlist = ({
8097
8119
  );
8098
8120
  }
8099
8121
  try {
8100
- const validatedParams = he.getLists.query.parse(queryParams);
8122
+ const validatedParams = Se.getLists.query.parse(queryParams);
8101
8123
  const headers = {
8102
8124
  Authorization: `Bearer ${developerToken}`
8103
8125
  };
@@ -8141,7 +8163,7 @@ const fetchShortlistPersistence = ({
8141
8163
  );
8142
8164
  }
8143
8165
  try {
8144
- const validatedParams = Se.getShortlistPersistence.query.parse(queryParams);
8166
+ const validatedParams = ve.getShortlistPersistence.query.parse(queryParams);
8145
8167
  const headers = {
8146
8168
  Authorization: `Bearer ${developerToken}`
8147
8169
  };
@@ -8185,7 +8207,7 @@ const fetchNiftyQuote = ({
8185
8207
  throw new Error("Developer token not found. Please set DEVELOPER_KEY environment variable.");
8186
8208
  }
8187
8209
  try {
8188
- const validatedParams = je.getGrowwNiftyQuote.query.parse(params);
8210
+ const validatedParams = he.getGrowwNiftyQuote.query.parse(params);
8189
8211
  const headers = {
8190
8212
  Authorization: `Bearer ${developerToken}`
8191
8213
  };
@@ -8198,7 +8220,7 @@ const fetchNiftyQuote = ({
8198
8220
  if (currentTimezone) {
8199
8221
  headers["X-Current-Timezone"] = currentTimezone;
8200
8222
  }
8201
- const response = await axios.get(`${apiDomain}/v1/developer/groww/nifty`, {
8223
+ const response = await axios.get(`${apiDomain}/v1/developer/nifty`, {
8202
8224
  params: validatedParams,
8203
8225
  headers
8204
8226
  });
@@ -8214,6 +8236,50 @@ const fetchNiftyQuote = ({
8214
8236
  throw error;
8215
8237
  }
8216
8238
  };
8239
+ dayjs.extend(utc);
8240
+ dayjs.extend(timezone);
8241
+ const fetchNiftyQuoteTimeline = ({
8242
+ developerToken,
8243
+ apiDomain,
8244
+ runId,
8245
+ currentTimestamp,
8246
+ currentTimezone = "Asia/Kolkata"
8247
+ }) => async (end_datetime) => {
8248
+ if (!developerToken) {
8249
+ throw new Error("Developer token not found. Please set DEVELOPER_KEY environment variable.");
8250
+ }
8251
+ try {
8252
+ const validatedParams = he.getGrowwNiftyQuoteTimeline.query.parse({
8253
+ end_datetime
8254
+ });
8255
+ const headers = {
8256
+ Authorization: `Bearer ${developerToken}`
8257
+ };
8258
+ if (runId) {
8259
+ headers["X-Run-Id"] = runId;
8260
+ }
8261
+ if (currentTimestamp) {
8262
+ headers["X-Current-Timestamp"] = currentTimestamp;
8263
+ }
8264
+ if (currentTimezone) {
8265
+ headers["X-Current-Timezone"] = currentTimezone;
8266
+ }
8267
+ const response = await axios.get(`${apiDomain}/v1/developer/nifty-timeline`, {
8268
+ params: validatedParams,
8269
+ headers
8270
+ });
8271
+ return response.data.data.niftyTimeline;
8272
+ } catch (error) {
8273
+ if (axios.isAxiosError(error)) {
8274
+ logger.error(`Error fetching NIFTY timeline: ${error.message}`);
8275
+ throw new Error(
8276
+ `Failed to fetch NIFTY timeline: ${error.response?.data?.message || error.message}`
8277
+ );
8278
+ }
8279
+ logger.error(`Unexpected error fetching NIFTY timeline: ${error}`);
8280
+ throw error;
8281
+ }
8282
+ };
8217
8283
  function isRetryableError(error) {
8218
8284
  if (axios.isAxiosError(error)) {
8219
8285
  const axiosError = error;
@@ -8292,7 +8358,7 @@ const placeOrder = ({ runId, apiClient }) => async (data) => {
8292
8358
  try {
8293
8359
  await retryWithBackoff(
8294
8360
  async () => {
8295
- const validatedData = ve.v1_dashboard_runs_schemas.createOrder.body.parse(data);
8361
+ const validatedData = fe.v1_dashboard_runs_schemas.createOrder.body.parse(data);
8296
8362
  await apiClient.post(`/v1/dashboard/runs/${runId}/orders`, validatedData);
8297
8363
  logger.debug(`Order persisted for ${data.nseSymbol} in runId: ${runId}`);
8298
8364
  },
@@ -8624,6 +8690,13 @@ async function ganaka({
8624
8690
  currentTimestamp,
8625
8691
  currentTimezone: "Asia/Kolkata"
8626
8692
  }),
8693
+ fetchNiftyQuoteTimeline: fetchNiftyQuoteTimeline({
8694
+ developerToken,
8695
+ apiDomain,
8696
+ runId,
8697
+ currentTimestamp,
8698
+ currentTimezone: "Asia/Kolkata"
8699
+ }),
8627
8700
  fetchQuoteTimeline: fetchQuoteTimeline({
8628
8701
  developerToken,
8629
8702
  apiDomain,