UNPKG

44.2 kBJavaScriptView Raw
1var __defProp = Object.defineProperty;
2var __export = (target, all) => {
3 for (var name in all)
4 __defProp(target, name, { get: all[name], enumerable: true });
5};
6
7// src/DayDetails/index.ts
8var DayDetails_exports = {};
9__export(DayDetails_exports, {
10 getOrderBook: () => getOrderBook,
11 getPriceData: () => getPriceData,
12 getPriceOverview: () => getPriceOverviewData,
13 getShareholders: () => getShareholders,
14 getSupervisionDetail: () => getSupervisionDetail,
15 getThresholds: () => getThresholds,
16 getTradersType: () => getTradersType,
17 getTrades: () => getTrades
18});
19
20// src/request.ts
21import axios from "axios";
22import deepmerge from "deepmerge";
23
24// src/utils/index.ts
25var utils_exports = {};
26__export(utils_exports, {
27 dEven2Date: () => dEven2Date,
28 dEvenValidation: () => dEvenValidation,
29 deepUpdate: () => deepUpdate,
30 even2JDate: () => even2JDate,
31 faToAr: () => faToAr,
32 fakeBrowserHeaders: () => fakeBrowserHeaders,
33 hEven2Time: () => hEven2Time,
34 hEvenValidation: () => hEvenValidation,
35 omitNulls: () => omitNulls
36});
37
38// src/utils/miscUtils.ts
39function deepUpdate(d1, d2) {
40 const ret = { ...d1 };
41 for (const [key, value] of Object.entries(d2)) {
42 if (!(key in d1)) {
43 ret[key] = value;
44 } else if (typeof value === "object") {
45 ret[key] = deepUpdate(d1[key], value);
46 } else {
47 ret[key] = value;
48 }
49 }
50 return ret;
51}
52function omitNulls(obj) {
53 const ret = obj;
54 for (const [key, value] of Object.entries(obj)) {
55 if (value === null) {
56 delete ret[key];
57 }
58 }
59 return ret;
60}
61
62// src/utils/timeUtils.ts
63function hEven2Time(heven) {
64 const hevenStr = heven.toString();
65 if (hevenStr.length === 6) {
66 return `${hevenStr.slice(0, 2).padStart(2, "0")}:${hevenStr.slice(2, 4)}:${hevenStr.slice(4)}`;
67 }
68 return `${hevenStr.slice(0, 1).padStart(2, "0")}:${hevenStr.slice(1, 3)}:${hevenStr.slice(3)}`;
69}
70function dEven2Date(deven) {
71 const devenStr = deven.toString();
72 const year = devenStr.slice(0, 4);
73 const month = devenStr.slice(4, 6);
74 const day = devenStr.slice(6).padStart(2, "0");
75 return `${year}-${month}-${day}`;
76}
77function even2JDate(dEven, hEven) {
78 return /* @__PURE__ */ new Date(`${hEven2Time(dEven)} ${dEven2Date(hEven)}`);
79}
80function hEvenValidation(hEven) {
81 const hEvenStr = hEven.toString();
82 if (hEvenStr.length === 6) {
83 const hour = parseInt(hEvenStr.slice(0, 2));
84 const minute = parseInt(hEvenStr.slice(2, 4));
85 const second = parseInt(hEvenStr.slice(4));
86 return hour >= 0 && hour <= 23 && minute >= 0 && minute <= 59 && second >= 0 && second <= 59;
87 }
88 return false;
89}
90function dEvenValidation(dEven) {
91 const dEvenStr = dEven.toString();
92 const year = parseInt(dEvenStr.slice(0, 4));
93 const month = parseInt(dEvenStr.slice(4, 6));
94 const day = parseInt(dEvenStr.slice(6));
95 return year >= 1300 && year <= 1500 && month >= 1 && month <= 12 && day >= 1 && day <= 31;
96}
97
98// src/utils/fetchUtils.ts
99function fakeBrowserHeaders() {
100 return {
101 Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
102 "Accept-Encoding": "gzip, deflate, br",
103 "Accept-Language": "en-US,en;q=0.9,fa;q=0.8",
104 "Cache-Control": "max-age=0",
105 "Sec-Ch-Ua": '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
106 "Sec-Ch-Ua-Mobile": "?0",
107 "Sec-Ch-Ua-Platform": '"Windows"',
108 "Sec-Fetch-Dest": "document",
109 "Sec-Fetch-Mode": "navigate",
110 "Sec-Fetch-Site": "none",
111 "Sec-Fetch-User": "?1",
112 "Sec-GPC": "1",
113 "Upgrade-Insecure-Requests": "1",
114 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
115 };
116}
117
118// src/utils/localeUtils.ts
119var faToAr = (value) => {
120 return value.replace(/ی/g, "\u064A").replace(/ک/g, "\u0643").replace(/۰/g, "\u0660").replace(/۱/g, "\u0661").replace(/۲/g, "\u0662").replace(/۳/g, "\u0663").replace(/۴/g, "\u0664").replace(/۵/g, "\u0665").replace(/۶/g, "\u0666").replace(/۷/g, "\u0667").replace(/۸/g, "\u0668").replace(/۹/g, "\u0669");
121};
122
123// src/request.ts
124import { trySafe } from "p-safe";
125async function request(url, options = {}) {
126 return trySafe(async () => {
127 const response = await axios.request(
128 deepmerge(
129 {
130 url,
131 method: "GET",
132 headers: {
133 ...fakeBrowserHeaders(),
134 Accept: "ext/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
135 "X-Requested-With": "XMLHttpRequest"
136 },
137 timeout: 1e4
138 },
139 options
140 )
141 );
142 return { data: response };
143 });
144}
145
146// src/DayDetails/getPriceOverview.ts
147import { trySafe as trySafe2 } from "p-safe";
148async function getPriceOverviewData(params, options = {}) {
149 return trySafe2(async () => {
150 const { insId, dEven } = params;
151 const { data: response, error } = await request(
152 `http://cdn.tsetmc.com/api/ClosingPrice/GetClosingPriceDaily/${insId}/${dEven}`,
153 options
154 );
155 if (error)
156 return { error };
157 if (!response)
158 return { error: new Error("NoData") };
159 const data = response.data["closingPriceDaily"];
160 return {
161 data: {
162 priceChange: data["priceChange"],
163 low: data["priceMin"],
164 high: data["priceMax"],
165 yesterday: data["priceYesterday"],
166 open: data["priceFirst"],
167 close: data["pClosing"],
168 last: data["pDrCotVal"],
169 count: data["zTotTran"],
170 volume: data["qTotTran5J"],
171 value: data["qTotCap"]
172 }
173 };
174 });
175}
176
177// src/DayDetails/getOrderBook.ts
178import { trySafe as trySafe3 } from "p-safe";
179async function getOrderBook(params, options = {}) {
180 return trySafe3(async () => {
181 const { insId, dEven } = params;
182 const { data: response, error } = await request(
183 `http://cdn.tsetmc.com/api/BestLimits/${insId}/${dEven}`,
184 options
185 );
186 if (error)
187 return { error };
188 if (!response)
189 return { error: new Error("NoData") };
190 const data = response.data["bestLimitsHistory"];
191 data.sort((a, b) => {
192 if (a["hEven"] === b["hEven"]) {
193 return a["number"] - b["number"];
194 }
195 return a["hEven"] - b["hEven"];
196 });
197 let prevData = { buyRows: [], sellRows: [] };
198 const hevenMap = {};
199 for (const row of data) {
200 const heven = row["hEven"];
201 const t = even2JDate(dEven, heven);
202 const buyRow = {
203 time: t,
204 count: row["zOrdMeDem"],
205 price: row["pMeDem"],
206 volume: row["qTitMeDem"]
207 };
208 const sellRow = {
209 time: t,
210 count: row["zOrdMeOf"],
211 price: row["pMeOf"],
212 volume: row["qTitMeOf"]
213 };
214 const index = row["number"] - 1;
215 if (!(heven in hevenMap)) {
216 hevenMap[heven] = { ...prevData };
217 }
218 while (hevenMap[heven].buyRows.length < index + 1) {
219 hevenMap[heven].buyRows.push(null);
220 }
221 while (hevenMap[heven].sellRows.length < index + 1) {
222 hevenMap[heven].sellRows.push(null);
223 }
224 hevenMap[heven].buyRows[index] = buyRow;
225 hevenMap[heven].sellRows[index] = sellRow;
226 prevData = hevenMap[heven];
227 }
228 return {
229 data: Object.keys(hevenMap).map((key) => ({
230 time: even2JDate(dEven, parseInt(key)),
231 ...hevenMap[key]
232 }))
233 };
234 });
235}
236
237// src/DayDetails/getPriceData.ts
238import { trySafe as trySafe4 } from "p-safe";
239async function getPriceData(params, options = {}) {
240 return trySafe4(async () => {
241 const { insId, dEven } = params;
242 const { data: response, error } = await request(
243 `http://cdn.tsetmc.com/api/ClosingPrice/GetClosingPriceHistory/${insId}/${dEven}`,
244 options
245 );
246 if (error)
247 return { error };
248 if (!response)
249 return { error: new Error("NoData") };
250 const data = response.data["closingPriceHistory"];
251 return {
252 data: data.map((row) => ({
253 time: even2JDate(dEven, row["hEven"]),
254 close: row["pClosing"],
255 last: row["pDrCotVal"],
256 value: row["qTotCap"],
257 volume: row["qTotTran5J"],
258 count: row["zTotTran"]
259 }))
260 };
261 });
262}
263
264// src/DayDetails/getTrades.ts
265import { trySafe as trySafe5 } from "p-safe";
266async function getTrades(params, options = {}) {
267 return trySafe5(async () => {
268 const { insId, dEven, summarize } = params;
269 const summarizeStr = summarize ? "true" : "false";
270 const { data: response, error } = await request(
271 `http://cdn.tsetmc.com/api/Trade/GetTradeHistory/${insId}/${dEven}/${summarizeStr}`,
272 options
273 );
274 if (error)
275 return { error };
276 if (!response)
277 return { error: new Error("NoData") };
278 const data = response.data["tradeHistory"];
279 return {
280 data: data.map((row) => ({
281 time: even2JDate(dEven, Number(row["hEven"])),
282 price: row["pTran"],
283 volume: row["qTitTran"]
284 }))
285 };
286 });
287}
288
289// src/DayDetails/getTradersType.ts
290import { trySafe as trySafe6 } from "p-safe";
291async function getTradersType(params, options = {}) {
292 return trySafe6(async () => {
293 const { insId, dEven } = params;
294 const { data: response, error } = await request(
295 `http://cdn.tsetmc.com/api/ClientType/GetClientTypeHistory/${insId}/${dEven}`,
296 options
297 );
298 if (error)
299 return { error };
300 if (!response)
301 return { error: new Error("No Data") };
302 const data = response.data["clientType"];
303 return {
304 data: {
305 legal: {
306 buy: {
307 volume: data["buy_N_Volume"],
308 value: data["buy_N_Value"],
309 count: data["buy_N_Count"]
310 },
311 sell: {
312 volume: data["sell_N_Volume"],
313 value: data["sell_N_Value"],
314 count: data["sell_N_Count"]
315 }
316 },
317 real: {
318 buy: {
319 volume: data["buy_I_Volume"],
320 value: data["buy_I_Value"],
321 count: data["buy_I_Count"]
322 },
323 sell: {
324 volume: data["sell_I_Volume"],
325 value: data["sell_I_Value"],
326 count: data["sell_I_Count"]
327 }
328 }
329 }
330 };
331 });
332}
333
334// src/DayDetails/getSupervisionDetail.ts
335import { trySafe as trySafe7 } from "p-safe";
336import deepmerge2 from "deepmerge";
337async function getSupervisionDetail(insId, options = {}) {
338 return trySafe7(async () => {
339 const { data: response, error } = await request(
340 "http://old.tsetmc.com/tsev2/data/Supervision.aspx",
341 deepmerge2(
342 {
343 params: {
344 i: insId
345 }
346 },
347 options
348 )
349 );
350 if (error) {
351 return { error };
352 }
353 if (!response || !response.data) {
354 return { error: new Error("NoData") };
355 }
356 const [status, reason, description, date] = response.data.split("#");
357 return {
358 data: {
359 status: UnderSupervision(status),
360 reason,
361 description,
362 date: new Date(date)
363 }
364 };
365 });
366}
367function UnderSupervision(status) {
368 switch (status) {
369 default:
370 case "0":
371 return "";
372 case "1":
373 return "\u0645\u0634\u0645\u0648\u0644 \u0641\u0631\u0622\u06CC\u0646\u062F \u062A\u0639\u0644\u06CC\u0642";
374 case "2":
375 return "\u0645\u0639\u0627\u0645\u0644\u0647 \u062A\u062D\u062A \u0627\u062D\u062A\u06CC\u0627\u0637";
376 case "3":
377 return "\u062A\u0639\u0644\u06CC\u0642 \u0634\u062F\u0647";
378 }
379}
380
381// src/DayDetails/getShareholders.ts
382import { trySafe as trySafe8 } from "p-safe";
383async function getShareholders(params, options = {}) {
384 return trySafe8(async () => {
385 const { insId, dEven } = params;
386 const { data: response, error } = await request(
387 `http://cdn.tsetmc.com/api/Shareholder/${insId}/${dEven}`,
388 options
389 );
390 if (error)
391 return { error };
392 if (!response)
393 return { error: new Error("NoData") };
394 const data = response.data["shareShareholder"];
395 return {
396 data: data.map((row) => ({
397 date: even2JDate(dEven, row["dEven"]),
398 shareholder: {
399 id: row["shareHolderId"].toString(),
400 name: row["shareHolderName"]
401 },
402 count: row["numberOfShares"],
403 percentage: row["perOfShares"]
404 }))
405 };
406 });
407}
408
409// src/DayDetails/getThresholds.ts
410import { trySafe as trySafe9 } from "p-safe";
411async function getThresholds(params, options = {}) {
412 return trySafe9(async () => {
413 const { insId, dEven } = params;
414 const { data: response, error } = await request(
415 `http://cdn.tsetmc.com/api/MarketData/GetStaticThreshold/${insId}/${dEven}`,
416 options
417 );
418 if (error)
419 return { error };
420 if (!response)
421 return { error: new Error("NoData") };
422 const data = response.data["staticThreshold"];
423 return {
424 data: {
425 rangeMax: Number(data[1].psGelStaMax),
426 rangeMin: Number(data[1]?.psGelStaMin)
427 }
428 };
429 });
430}
431
432// src/Group/index.ts
433var Group_exports = {};
434__export(Group_exports, {
435 getAllGroups: () => getAllGroups
436});
437
438// src/Group/getAllGroups.ts
439import { trySafe as trySafe10 } from "p-safe";
440async function getAllGroups(options = {}) {
441 return trySafe10(async () => {
442 const { data: response, error } = await request(
443 "http://cdn.tsetmc.com/api/StaticData/GetStaticData",
444 options
445 );
446 if (error)
447 return { error };
448 if (!response)
449 return { error: new Error("NoData") };
450 return {
451 data: response.data["staticData"]
452 };
453 });
454}
455var GroupType = /* @__PURE__ */ ((GroupType2) => {
456 GroupType2["PAPER"] = "PAPER";
457 GroupType2["INDUSTRY"] = "INDUSTRIAL";
458 return GroupType2;
459})(GroupType || {});
460
461// src/MarketMap/index.ts
462var MarketMap_exports = {};
463__export(MarketMap_exports, {
464 getMarketMap: () => getMarketMap
465});
466
467// src/MarketMap/getMarketMap.ts
468import { trySafe as trySafe11 } from "p-safe";
469import deepmerge3 from "deepmerge";
470async function getMarketMap(params, options = {}) {
471 return trySafe11(async () => {
472 const {
473 mapType = 1 /* MarketValue */,
474 hEven = 0,
475 market = 0,
476 sector = 0,
477 size = 1920
478 } = params;
479 if (hEven !== 0 && !hEvenValidation(hEven)) {
480 return { error: new Error("Invalid hEven") };
481 }
482 const { data: response, error } = await request(
483 "http://cdn.tsetmc.com/api/ClosingPrice/GetMarketMap",
484 deepmerge3(
485 {
486 params: {
487 market,
488 sector,
489 size,
490 typeSelected: mapType,
491 hEven
492 }
493 },
494 options
495 )
496 );
497 if (error)
498 return { error };
499 if (!response)
500 return { error: new Error("NoData") };
501 return {
502 data: response.data.map((row) => ({
503 id: row["insCode"],
504 shortName: row["lVal18AFC"],
505 longName: row["lVal30"],
506 close: row["pClosing"],
507 last: row["pDrCotVal"],
508 volume: row["qTotTran5J"],
509 value: row["qTotCap"],
510 count: row["zTotTran"],
511 groupName: row["lSecVal"],
512 color: row["color"],
513 priceChangePercent: row["priceChangePercent"],
514 percent: row["percent"]
515 }))
516 };
517 });
518}
519var MapType = /* @__PURE__ */ ((MapType2) => {
520 MapType2[MapType2["MarketValue"] = 1] = "MarketValue";
521 MapType2[MapType2["MarketVolume"] = 2] = "MarketVolume";
522 return MapType2;
523})(MapType || {});
524
525// src/MarketWatch/index.ts
526var MarketWatch_exports = {};
527__export(MarketWatch_exports, {
528 getClientTypeAll: () => getClientTypeAll,
529 getPriceData: () => getWatchPrice,
530 getWatchStats: () => getWatchStats
531});
532
533// src/MarketWatch/getClientTypeAll.ts
534import { trySafe as trySafe12 } from "p-safe";
535async function getClientTypeAll() {
536 return trySafe12(async () => {
537 const response = await fetch("http://old.tsetmc.com/tsev2/data/ClientTypeAll.aspx");
538 const text = await response.text();
539 const watchData = {};
540 const rows = text.split(";");
541 for (const row of rows) {
542 if (!row) {
543 continue;
544 }
545 const [symbolId, r_buy_c, l_buy_c, r_buy_v, l_buy_v, r_sell_c, l_sell_c, r_sell_v, l_sell_v] = row.split(",");
546 watchData[symbolId] = {
547 legal: {
548 buy: {
549 volume: parseInt(l_buy_v),
550 count: parseInt(l_buy_c)
551 },
552 sell: {
553 volume: parseInt(l_sell_v),
554 count: parseInt(l_sell_c)
555 }
556 },
557 real: {
558 buy: {
559 volume: parseInt(r_buy_v),
560 count: parseInt(r_buy_c)
561 },
562 sell: {
563 volume: parseInt(r_sell_v),
564 count: parseInt(r_sell_c)
565 }
566 }
567 };
568 }
569 return { data: watchData };
570 });
571}
572
573// src/MarketWatch/getPriceData.ts
574import { trySafe as trySafe13 } from "p-safe";
575import deepmerge4 from "deepmerge";
576async function getWatchPrice(params, options = {}) {
577 return trySafe13(async () => {
578 const { refId = 0, hEven = 0 } = params || {};
579 const { data: response, error } = await request(
580 "http://old.tsetmc.com/tsev2/data/MarketWatchPlus.aspx",
581 deepmerge4(
582 {
583 params: {
584 h: hEven,
585 r: refId
586 }
587 },
588 options
589 )
590 );
591 if (error)
592 return { error };
593 if (!response || !response.data)
594 return { error: new Error("NoData") };
595 const data = response.data;
596 const sections = data.split("@");
597 let maxHeven = 0;
598 const watchData = {};
599 const rows = sections[2].split(";");
600 for (const row of rows) {
601 if (!row)
602 continue;
603 const cols = row.split(",");
604 if (cols.length === 0 || cols.length === 10)
605 continue;
606 const symbolId = cols[0];
607 const heven = parseInt(cols[4]);
608 watchData[symbolId] = {
609 symbolId: cols[0],
610 isin: cols[1],
611 shortName: cols[2],
612 fullName: cols[3],
613 heven: parseInt(cols[4]),
614 open: parseInt(cols[5]),
615 close: parseInt(cols[6]),
616 last: parseInt(cols[7]),
617 count: parseInt(cols[8]),
618 volume: parseInt(cols[9]),
619 value: parseInt(cols[10]),
620 low: parseInt(cols[11]),
621 high: parseInt(cols[12]),
622 yesterday: parseInt(cols[13]),
623 eps: parseInt(cols[14]) || null,
624 baseVolume: parseInt(cols[15]),
625 visitCount: parseInt(cols[16]),
626 flow: parseInt(cols[17]),
627 group: parseInt(cols[18]),
628 rangeMax: parseInt(cols[19]),
629 rangeMin: parseInt(cols[20]),
630 z: parseInt(cols[21]),
631 yval: parseInt(cols[22]),
632 orderbook: {
633 buyRows: [],
634 sellRows: []
635 }
636 };
637 if (heven > maxHeven) {
638 maxHeven = heven;
639 }
640 }
641 const orderbookRows = sections[3].split(";");
642 for (const row of orderbookRows) {
643 if (!row) {
644 continue;
645 }
646 const [symbolId, rank, sCount, bCount, bPrice, sPrice, bVolume, sVolume] = row.split(",");
647 const orderbook = watchData[symbolId].orderbook || {
648 buyRows: [],
649 sellRows: []
650 };
651 orderbook.buyRows[rank] = {
652 count: parseInt(bCount),
653 price: parseInt(bPrice),
654 volume: parseInt(bVolume)
655 };
656 orderbook.sellRows[rank] = {
657 count: parseInt(sCount),
658 price: parseInt(sPrice),
659 volume: parseInt(sVolume)
660 };
661 watchData[symbolId].orderbook = orderbook;
662 }
663 const result = [];
664 for (const key in watchData) {
665 const dataRow = watchData[key];
666 if (!dataRow.symbolId) {
667 continue;
668 }
669 const orderbook = watchData[key].orderbook || {
670 buyRows: [],
671 sellRows: []
672 };
673 result.push({
674 symbolId: watchData[key].symbolId,
675 isin: watchData[key].isin,
676 shortName: watchData[key].shortName,
677 fullName: watchData[key].fullName,
678 heven: watchData[key].heven,
679 open: watchData[key].open,
680 close: watchData[key].close,
681 last: watchData[key].last,
682 count: watchData[key].count,
683 volume: watchData[key].volume,
684 value: watchData[key].value,
685 low: watchData[key].low,
686 high: watchData[key].high,
687 yesterday: watchData[key].yesterday,
688 eps: watchData[key].eps,
689 baseVolume: watchData[key].baseVolume,
690 visitCount: watchData[key].visitCount,
691 flow: watchData[key].flow,
692 group: watchData[key].group,
693 rangeMax: watchData[key].rangeMax,
694 rangeMin: watchData[key].rangeMin,
695 z: watchData[key].z,
696 yval: watchData[key].yval,
697 orderbook: {
698 buyRows: Object.values(orderbook.buyRows),
699 sellRows: Object.values(orderbook.sellRows)
700 }
701 });
702 }
703 return { data: result };
704 });
705}
706
707// src/MarketWatch/getWatchStats.ts
708import { trySafe as trySafe14 } from "p-safe";
709var STATS_TRADES_INDICES = /* @__PURE__ */ ((STATS_TRADES_INDICES2) => {
710 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_value_3_month"] = 0] = "average_value_3_month";
711 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_value_12_month"] = 1] = "average_value_12_month";
712 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_value_rank_3_month"] = 2] = "average_value_rank_3_month";
713 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_value_rank_12_month"] = 3] = "average_value_rank_12_month";
714 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_volume_3_month"] = 4] = "average_volume_3_month";
715 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_volume_12_month"] = 5] = "average_volume_12_month";
716 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_volume_rank_3_month"] = 6] = "average_volume_rank_3_month";
717 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_volume_rank_12_month"] = 7] = "average_volume_rank_12_month";
718 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_count_3_month"] = 8] = "average_count_3_month";
719 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_count_12_month"] = 9] = "average_count_12_month";
720 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_count_rank_3_month"] = 10] = "average_count_rank_3_month";
721 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_count_rank_12_month"] = 11] = "average_count_rank_12_month";
722 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_price_no_base_last_day"] = 12] = "average_price_no_base_last_day";
723 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["average_price_with_base_last_day"] = 13] = "average_price_with_base_last_day";
724 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["value_last_day"] = 14] = "value_last_day";
725 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["volume_last_day"] = 15] = "volume_last_day";
726 STATS_TRADES_INDICES2[STATS_TRADES_INDICES2["count_last_day"] = 16] = "count_last_day";
727 return STATS_TRADES_INDICES2;
728})(STATS_TRADES_INDICES || {});
729var STATS_NEGATIVE_DAYS_INDICES = /* @__PURE__ */ ((STATS_NEGATIVE_DAYS_INDICES2) => {
730 STATS_NEGATIVE_DAYS_INDICES2[STATS_NEGATIVE_DAYS_INDICES2["days_count_3_month"] = 18] = "days_count_3_month";
731 STATS_NEGATIVE_DAYS_INDICES2[STATS_NEGATIVE_DAYS_INDICES2["days_count_12_month"] = 19] = "days_count_12_month";
732 STATS_NEGATIVE_DAYS_INDICES2[STATS_NEGATIVE_DAYS_INDICES2["days_percent_3_month"] = 20] = "days_percent_3_month";
733 STATS_NEGATIVE_DAYS_INDICES2[STATS_NEGATIVE_DAYS_INDICES2["days_percent_12_month"] = 21] = "days_percent_12_month";
734 STATS_NEGATIVE_DAYS_INDICES2[STATS_NEGATIVE_DAYS_INDICES2["days_rank_3_month"] = 22] = "days_rank_3_month";
735 STATS_NEGATIVE_DAYS_INDICES2[STATS_NEGATIVE_DAYS_INDICES2["days_rank_12_month"] = 23] = "days_rank_12_month";
736 return STATS_NEGATIVE_DAYS_INDICES2;
737})(STATS_NEGATIVE_DAYS_INDICES || {});
738var STATS_NO_TRADE_DAYS_INDICES = /* @__PURE__ */ ((STATS_NO_TRADE_DAYS_INDICES2) => {
739 STATS_NO_TRADE_DAYS_INDICES2[STATS_NO_TRADE_DAYS_INDICES2["days_count_3_month"] = 24] = "days_count_3_month";
740 STATS_NO_TRADE_DAYS_INDICES2[STATS_NO_TRADE_DAYS_INDICES2["days_count_12_month"] = 25] = "days_count_12_month";
741 return STATS_NO_TRADE_DAYS_INDICES2;
742})(STATS_NO_TRADE_DAYS_INDICES || {});
743var STATS_POSITIVE_DAYS_INDICES = /* @__PURE__ */ ((STATS_POSITIVE_DAYS_INDICES2) => {
744 STATS_POSITIVE_DAYS_INDICES2[STATS_POSITIVE_DAYS_INDICES2["days_count_3_month"] = 26] = "days_count_3_month";
745 STATS_POSITIVE_DAYS_INDICES2[STATS_POSITIVE_DAYS_INDICES2["days_count_12_month"] = 27] = "days_count_12_month";
746 STATS_POSITIVE_DAYS_INDICES2[STATS_POSITIVE_DAYS_INDICES2["days_percent_3_month"] = 28] = "days_percent_3_month";
747 STATS_POSITIVE_DAYS_INDICES2[STATS_POSITIVE_DAYS_INDICES2["days_percent_12_month"] = 29] = "days_percent_12_month";
748 STATS_POSITIVE_DAYS_INDICES2[STATS_POSITIVE_DAYS_INDICES2["days_rank_3_month"] = 30] = "days_rank_3_month";
749 STATS_POSITIVE_DAYS_INDICES2[STATS_POSITIVE_DAYS_INDICES2["days_rank_12_month"] = 31] = "days_rank_12_month";
750 return STATS_POSITIVE_DAYS_INDICES2;
751})(STATS_POSITIVE_DAYS_INDICES || {});
752var STATS_WITH_TRADE_DAYS_INDICES = /* @__PURE__ */ ((STATS_WITH_TRADE_DAYS_INDICES2) => {
753 STATS_WITH_TRADE_DAYS_INDICES2[STATS_WITH_TRADE_DAYS_INDICES2["days_count_3_month"] = 32] = "days_count_3_month";
754 STATS_WITH_TRADE_DAYS_INDICES2[STATS_WITH_TRADE_DAYS_INDICES2["days_count_12_month"] = 33] = "days_count_12_month";
755 STATS_WITH_TRADE_DAYS_INDICES2[STATS_WITH_TRADE_DAYS_INDICES2["days_rank_3_month"] = 34] = "days_rank_3_month";
756 STATS_WITH_TRADE_DAYS_INDICES2[STATS_WITH_TRADE_DAYS_INDICES2["days_rank_12_month"] = 35] = "days_rank_12_month";
757 return STATS_WITH_TRADE_DAYS_INDICES2;
758})(STATS_WITH_TRADE_DAYS_INDICES || {});
759var STATS_COMPANY_VALUE_INDICES = /* @__PURE__ */ ((STATS_COMPANY_VALUE_INDICES2) => {
760 STATS_COMPANY_VALUE_INDICES2[STATS_COMPANY_VALUE_INDICES2["total_value"] = 36] = "total_value";
761 STATS_COMPANY_VALUE_INDICES2[STATS_COMPANY_VALUE_INDICES2["total_value_rank"] = 37] = "total_value_rank";
762 return STATS_COMPANY_VALUE_INDICES2;
763})(STATS_COMPANY_VALUE_INDICES || {});
764var STATS_OPEN_DAYS_INDICES = /* @__PURE__ */ ((STATS_OPEN_DAYS_INDICES2) => {
765 STATS_OPEN_DAYS_INDICES2[STATS_OPEN_DAYS_INDICES2["days_count_3_month"] = 38] = "days_count_3_month";
766 STATS_OPEN_DAYS_INDICES2[STATS_OPEN_DAYS_INDICES2["days_count_12_month"] = 39] = "days_count_12_month";
767 STATS_OPEN_DAYS_INDICES2[STATS_OPEN_DAYS_INDICES2["days_percent_3_month"] = 40] = "days_percent_3_month";
768 STATS_OPEN_DAYS_INDICES2[STATS_OPEN_DAYS_INDICES2["days_percent_12_month"] = 41] = "days_percent_12_month";
769 STATS_OPEN_DAYS_INDICES2[STATS_OPEN_DAYS_INDICES2["days_rank_3_month"] = 42] = "days_rank_3_month";
770 STATS_OPEN_DAYS_INDICES2[STATS_OPEN_DAYS_INDICES2["days_rank_12_month"] = 43] = "days_rank_12_month";
771 return STATS_OPEN_DAYS_INDICES2;
772})(STATS_OPEN_DAYS_INDICES || {});
773var STATS_CLOSED_DAYS_INDICES = /* @__PURE__ */ ((STATS_CLOSED_DAYS_INDICES2) => {
774 STATS_CLOSED_DAYS_INDICES2[STATS_CLOSED_DAYS_INDICES2["days_count_3_month"] = 38] = "days_count_3_month";
775 STATS_CLOSED_DAYS_INDICES2[STATS_CLOSED_DAYS_INDICES2["days_count_12_month"] = 39] = "days_count_12_month";
776 STATS_CLOSED_DAYS_INDICES2[STATS_CLOSED_DAYS_INDICES2["days_percent_3_month"] = 40] = "days_percent_3_month";
777 STATS_CLOSED_DAYS_INDICES2[STATS_CLOSED_DAYS_INDICES2["days_percent_12_month"] = 41] = "days_percent_12_month";
778 STATS_CLOSED_DAYS_INDICES2[STATS_CLOSED_DAYS_INDICES2["days_rank_3_month"] = 42] = "days_rank_3_month";
779 STATS_CLOSED_DAYS_INDICES2[STATS_CLOSED_DAYS_INDICES2["days_rank_12_month"] = 43] = "days_rank_12_month";
780 return STATS_CLOSED_DAYS_INDICES2;
781})(STATS_CLOSED_DAYS_INDICES || {});
782var STATS_CLIENT_TYPE_INDICES = /* @__PURE__ */ ((STATS_CLIENT_TYPE_INDICES2) => {
783 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["days_count_3_month"] = 44] = "days_count_3_month";
784 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["days_count_12_month"] = 45] = "days_count_12_month";
785 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["days_percent_3_month"] = 46] = "days_percent_3_month";
786 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["days_percent_12_month"] = 47] = "days_percent_12_month";
787 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["days_rank_3_month"] = 48] = "days_rank_3_month";
788 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["days_rank_12_month"] = 49] = "days_rank_12_month";
789 return STATS_CLIENT_TYPE_INDICES2;
790})(STATS_CLIENT_TYPE_INDICES || {});
791var STATS_CLIENT_TYPE_INDICES = /* @__PURE__ */ ((STATS_CLIENT_TYPE_INDICES2) => {
792 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_volume_3_month"] = 50] = "individual_buy_average_volume_3_month";
793 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_volume_12_month"] = 51] = "individual_buy_average_volume_12_month";
794 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_volume_rank_3_month"] = 52] = "individual_buy_average_volume_rank_3_month";
795 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_volume_rank_12_month"] = 53] = "individual_buy_average_volume_rank_12_month";
796 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_volume_3_month"] = 54] = "legal_buy_average_volume_3_month";
797 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_volume_12_month"] = 55] = "legal_buy_average_volume_12_month";
798 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_volume_rank_3_month"] = 56] = "legal_buy_average_volume_rank_3_month";
799 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_volume_rank_12_month"] = 57] = "legal_buy_average_volume_rank_12_month";
800 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_count_3_month"] = 58] = "individual_buy_average_count_3_month";
801 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_count_12_month"] = 59] = "individual_buy_average_count_12_month";
802 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_count_rank_3_month"] = 60] = "individual_buy_average_count_rank_3_month";
803 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_buy_average_count_rank_12_month"] = 61] = "individual_buy_average_count_rank_12_month";
804 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_count_3_month"] = 62] = "legal_buy_average_count_3_month";
805 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_count_12_month"] = 63] = "legal_buy_average_count_12_month";
806 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_count_rank_3_month"] = 64] = "legal_buy_average_count_rank_3_month";
807 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_buy_average_count_rank_12_month"] = 65] = "legal_buy_average_count_rank_12_month";
808 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_buy_average_count_3_month"] = 66] = "total_buy_average_count_3_month";
809 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_buy_average_count_12_month"] = 67] = "total_buy_average_count_12_month";
810 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_buy_average_count_rank_3_month"] = 68] = "total_buy_average_count_rank_3_month";
811 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_buy_average_count_rank_12_month"] = 69] = "total_buy_average_count_rank_12_month";
812 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_volume_3_month"] = 70] = "individual_sell_average_volume_3_month";
813 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_volume_12_month"] = 71] = "individual_sell_average_volume_12_month";
814 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_volume_rank_3_month"] = 72] = "individual_sell_average_volume_rank_3_month";
815 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_volume_rank_12_month"] = 73] = "individual_sell_average_volume_rank_12_month";
816 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_volume_3_month"] = 74] = "legal_sell_average_volume_3_month";
817 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_volume_12_month"] = 75] = "legal_sell_average_volume_12_month";
818 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_volume_rank_3_month"] = 76] = "legal_sell_average_volume_rank_3_month";
819 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_volume_rank_12_month"] = 77] = "legal_sell_average_volume_rank_12_month";
820 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_count_3_month"] = 78] = "individual_sell_average_count_3_month";
821 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_count_12_month"] = 79] = "individual_sell_average_count_12_month";
822 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_count_rank_3_month"] = 80] = "individual_sell_average_count_rank_3_month";
823 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["individual_sell_average_count_rank_12_month"] = 81] = "individual_sell_average_count_rank_12_month";
824 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_count_3_month"] = 82] = "legal_sell_average_count_3_month";
825 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_count_12_month"] = 83] = "legal_sell_average_count_12_month";
826 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_count_rank_3_month"] = 84] = "legal_sell_average_count_rank_3_month";
827 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["legal_sell_average_count_rank_12_month"] = 85] = "legal_sell_average_count_rank_12_month";
828 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_sell_average_count_3_month"] = 86] = "total_sell_average_count_3_month";
829 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_sell_average_count_12_month"] = 87] = "total_sell_average_count_12_month";
830 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_sell_average_count_rank_3_month"] = 88] = "total_sell_average_count_rank_3_month";
831 STATS_CLIENT_TYPE_INDICES2[STATS_CLIENT_TYPE_INDICES2["total_sell_average_count_rank_12_month"] = 89] = "total_sell_average_count_rank_12_month";
832 return STATS_CLIENT_TYPE_INDICES2;
833})(STATS_CLIENT_TYPE_INDICES || {});
834async function getWatchStatsRaw(options = {}) {
835 return trySafe14(async () => {
836 const { data: response, error } = await request(
837 "http://old.tsetmc.com/tsev2/data/InstValue.aspx?t=a",
838 options
839 );
840 if (error)
841 return { error };
842 if (!response || !response.data)
843 return { error: new Error("No data") };
844 const watchData = {};
845 const sections = response.data.split(";");
846 let symbolId = "NaN";
847 sections.forEach((section) => {
848 let row = section.split(",");
849 if (row.length === 3) {
850 symbolId = row[0];
851 watchData[symbolId] = {};
852 row = row.slice(1);
853 }
854 if (symbolId === "NaN" || !row[1]) {
855 return;
856 }
857 const dataKey = parseInt(row[0]);
858 watchData[symbolId][dataKey] = row[1].includes(".") ? parseFloat(row[1]) : parseInt(row[1]);
859 });
860 return { data: watchData };
861 });
862}
863async function getWatchStats(options = {}) {
864 return trySafe14(async () => {
865 const { data, error } = await getWatchStatsRaw(options);
866 if (error)
867 return { error };
868 if (!data)
869 return { error: new Error("No data") };
870 const watchData = {};
871 Object.keys(data).forEach((symbolId) => {
872 const symbolData = data[symbolId];
873 const symbolStats = {
874 trades: null,
875 negative_days: null,
876 no_trade_days: null,
877 positive_days: null,
878 with_trade_days: null,
879 company_value: null,
880 open_days: null,
881 closed_days: null,
882 client_type: null
883 };
884 Object.keys(symbolData).forEach((dataKey) => {
885 const numKey = parseInt(dataKey);
886 if (numKey in STATS_TRADES_INDICES) {
887 if (!symbolStats.trades)
888 symbolStats.trades = {};
889 symbolStats.trades[STATS_TRADES_INDICES[numKey]] = symbolData[numKey];
890 }
891 if (numKey in STATS_NEGATIVE_DAYS_INDICES) {
892 if (!symbolStats.negative_days)
893 symbolStats.negative_days = {};
894 symbolStats.negative_days[STATS_NEGATIVE_DAYS_INDICES[numKey]] = symbolData[numKey];
895 }
896 if (numKey in STATS_NO_TRADE_DAYS_INDICES) {
897 if (!symbolStats.no_trade_days)
898 symbolStats.no_trade_days = {};
899 symbolStats.no_trade_days[STATS_NO_TRADE_DAYS_INDICES[numKey]] = symbolData[numKey];
900 }
901 if (numKey in STATS_POSITIVE_DAYS_INDICES) {
902 if (!symbolStats.positive_days)
903 symbolStats.positive_days = {};
904 symbolStats.positive_days[STATS_POSITIVE_DAYS_INDICES[numKey]] = symbolData[numKey];
905 }
906 if (numKey in STATS_WITH_TRADE_DAYS_INDICES) {
907 if (!symbolStats.with_trade_days)
908 symbolStats.with_trade_days = {};
909 symbolStats.with_trade_days[STATS_WITH_TRADE_DAYS_INDICES[numKey]] = symbolData[numKey];
910 }
911 if (numKey in STATS_COMPANY_VALUE_INDICES) {
912 if (!symbolStats.company_value)
913 symbolStats.company_value = {};
914 symbolStats.company_value[STATS_COMPANY_VALUE_INDICES[numKey]] = symbolData[numKey];
915 }
916 if (numKey in STATS_OPEN_DAYS_INDICES) {
917 if (!symbolStats.open_days)
918 symbolStats.open_days = {};
919 symbolStats.open_days[STATS_OPEN_DAYS_INDICES[numKey]] = symbolData[numKey];
920 }
921 if (numKey in STATS_CLOSED_DAYS_INDICES) {
922 if (!symbolStats.closed_days)
923 symbolStats.closed_days = {};
924 symbolStats.closed_days[STATS_CLOSED_DAYS_INDICES[numKey]] = symbolData[numKey];
925 }
926 if (numKey in STATS_CLIENT_TYPE_INDICES) {
927 if (!symbolStats.client_type)
928 symbolStats.client_type = {};
929 symbolStats.client_type[STATS_CLIENT_TYPE_INDICES[numKey]] = symbolData[numKey];
930 }
931 });
932 watchData[symbolId] = symbolStats;
933 });
934 return { data: watchData };
935 });
936}
937
938// src/Instrument/index.ts
939var Instrument_exports = {};
940__export(Instrument_exports, {
941 getBoardMembersHistory: () => getBoardMembersHistory,
942 getDPSData: () => getDPSData,
943 getInstrumentInfo: () => getInstrumentInfo,
944 getIntraDayPriceChart: () => getIntraDayPriceChart,
945 getSupervisorMsg: () => getSupervisorMsg
946});
947
948// src/Instrument/getBoardMembersHistory.ts
949import { trySafe as trySafe15 } from "p-safe";
950import deepmerge5 from "deepmerge";
951async function getBoardMembersHistory(params, options = {}) {
952 return trySafe15(async () => {
953 const { data: response, error } = await request(
954 "http://old.tsetmc.com/tsev2/data/CodalContent.aspx",
955 deepmerge5(
956 {
957 params: {
958 s: faToAr(params.symbol),
959 r: "12"
960 }
961 },
962 options
963 )
964 );
965 if (error) {
966 return { error };
967 }
968 if (!response || !response.data) {
969 return { error: new Error("NoData") };
970 }
971 const data = String(response.data).replace(/([^\\])?'/gm, '$1"');
972 const ds = JSON.parse(data);
973 const result = [];
974 for (const item of ds) {
975 if (item[4].Root.AssemblyDate) {
976 result.push({
977 type: "BoardMembers",
978 AssemblyDate: item[4].Root.AssemblyDate,
979 SessionDate: item[4].Root.BoardMembersSessionDate,
980 BoardMembers: item[4].Root.BoardMembers.BoardMember.map((member) => ({
981 ...member,
982 Charged: member.Charged === "\u0645\u0648\u0638\u0641" || member.Charged === "True"
983 }))
984 });
985 }
986 if (item[4].Root.DirectorManager) {
987 result.push({
988 type: "DirectorManager",
989 MeetingDate: item[1],
990 SessionDate: item[2],
991 DirectorManager: {
992 Name: item[4].Root.DirectorManager.DirectorManagerName,
993 NationalCode: item[4].Root.DirectorManager.DirectorManagerNationalCode,
994 EducationDegree: item[4].Root.DirectorManager.DirectorManagerEducationDegree
995 }
996 });
997 }
998 }
999 return { data: result };
1000 });
1001}
1002
1003// src/Instrument/getDPSData.ts
1004import { trySafe as trySafe16 } from "p-safe";
1005import deepmerge6 from "deepmerge";
1006async function getDPSData(params, options = {}) {
1007 return trySafe16(async () => {
1008 const { data: response, error } = await request(
1009 "http://old.tsetmc.com/tsev2/data/DPSData.aspx",
1010 deepmerge6(
1011 {
1012 params: {
1013 s: faToAr(params.symbol)
1014 }
1015 },
1016 options
1017 )
1018 );
1019 if (error) {
1020 return { error };
1021 }
1022 if (!response || !response.data) {
1023 return { error: new Error("NoData") };
1024 }
1025 const rows = response.data.split(";");
1026 const result = [];
1027 for (const row of rows) {
1028 const [
1029 publishDate,
1030 meetingDate,
1031 fiscalYear,
1032 profitAfterTax,
1033 profitToAllocate,
1034 profitAccumulated,
1035 cashProfitPerShare
1036 ] = row.split("@");
1037 result.push({
1038 publishDate,
1039 meetingDate,
1040 fiscalYear,
1041 profitAfterTax,
1042 profitToAllocate,
1043 profitAccumulated,
1044 cashProfitPerShare
1045 });
1046 }
1047 return { data: result };
1048 });
1049}
1050
1051// src/Instrument/getInstrumentInfo.ts
1052import { trySafe as trySafe17 } from "p-safe";
1053async function getInstrumentInfo(params, options = {}) {
1054 return trySafe17(async () => {
1055 const { data: response, error } = await request(
1056 `http://cdn.tsetmc.com/api/Instrument/GetInstrumentInfo/${params.insId}`,
1057 options
1058 );
1059 if (error)
1060 return { error };
1061 if (!response)
1062 return { error: new Error("NoData") };
1063 return { data: response.data["instrumentInfo"] };
1064 });
1065}
1066
1067// src/Instrument/getSupervisorMsg.ts
1068import { trySafe as trySafe18 } from "p-safe";
1069async function getSupervisorMsg(params, options = {}) {
1070 return trySafe18(async () => {
1071 const { data: response, error } = await request(
1072 `http://cdn.tsetmc.com/api/Msg/GetMsgByInsCode/${params.insId}`,
1073 options
1074 );
1075 if (error)
1076 return { error };
1077 if (!response)
1078 return { error: new Error("NoData") };
1079 return {
1080 data: response.data["msg"].map((row) => ({
1081 id: row["tseMsgIdn"],
1082 dEven: row["dEven"],
1083 hEven: row["hEven"],
1084 title: row["tseTitle"],
1085 description: row["tseDesc"],
1086 flow: row["flow"]
1087 }))
1088 };
1089 });
1090}
1091
1092// src/Instrument/getIntraDayPriceChart.ts
1093import { trySafe as trySafe19 } from "p-safe";
1094import deepmerge7 from "deepmerge";
1095async function getIntraDayPriceChart(params, options = {}) {
1096 return trySafe19(async () => {
1097 const { data: response, error } = await request(
1098 "http://old.tsetmc.com/tsev2/chart/data/IntraDayPrice.aspx",
1099 deepmerge7(
1100 {
1101 params: {
1102 i: params.insId
1103 }
1104 },
1105 options
1106 )
1107 );
1108 if (error) {
1109 return { error };
1110 }
1111 if (!response || !response.data) {
1112 return { error: new Error("NoData") };
1113 }
1114 const ticks = response.data.split(";");
1115 if (!Array.isArray(ticks) || ticks.length === 0) {
1116 return { error: new Error("MalformedData") };
1117 }
1118 const result = [];
1119 for (const tick of ticks) {
1120 const [time, high, low, open, close, volume] = tick.split(",");
1121 const [hour, minute] = time.split(":");
1122 result.push({
1123 time: new Date(Date.UTC(2010, 1, 1, parseInt(hour), parseInt(minute))),
1124 high: parseInt(high),
1125 low: parseInt(low),
1126 open: parseInt(open),
1127 close: parseInt(close),
1128 volume: parseInt(volume)
1129 });
1130 }
1131 return { data: result };
1132 });
1133}
1134
1135// src/index.ts
1136var TseTmc = { DayDetails: DayDetails_exports, Group: Group_exports, MarketMap: MarketMap_exports, MarketWatch: MarketWatch_exports, Instrument: Instrument_exports };
1137var src_default = TseTmc;
1138export {
1139 DayDetails_exports as DayDetails,
1140 Group_exports as Group,
1141 GroupType,
1142 Instrument_exports as Instrument,
1143 MapType,
1144 MarketMap_exports as MarketMap,
1145 MarketWatch_exports as MarketWatch,
1146 TseTmc,
1147 src_default as default,
1148 utils_exports as utils
1149};