UNPKG

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