corexxx 1.0.20 → 1.0.24
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/dlog.js +18 -14
- package/dist/dlog.js.map +1 -1
- package/dist/yahoofin.d.ts +9 -1
- package/dist/yahoofin.js +77 -7
- package/dist/yahoofin.js.map +1 -1
- package/package.json +2 -1
- package/src/dlog.ts +17 -15
- package/src/yahoofin.ts +74 -6
package/dist/dlog.js
CHANGED
|
@@ -7,42 +7,46 @@ exports.dlog = void 0;
|
|
|
7
7
|
var dlog;
|
|
8
8
|
(function (dlog) {
|
|
9
9
|
function d(msg, msg2 = null) {
|
|
10
|
-
console.log(`[DEBUG] ${msg} ${msg2 ? msg2 : ""} `);
|
|
10
|
+
console.log(`[${new Date().toLocaleString()}][DEBUG] ${msg} ${msg2 ? msg2 : ""} `);
|
|
11
11
|
}
|
|
12
12
|
dlog.d = d;
|
|
13
13
|
function e(msg, msg2 = null) {
|
|
14
|
-
console.log(`[ERROR] ${msg} ${msg2 ? msg2 : ""} `);
|
|
14
|
+
console.log(`[${new Date().toLocaleString()}][ERROR] ${msg} ${msg2 ? msg2 : ""} `);
|
|
15
15
|
}
|
|
16
16
|
dlog.e = e;
|
|
17
17
|
function i(msg, msg2 = null) {
|
|
18
|
-
console.log(`[INFO] ${msg} ${msg2 ? msg2 : ""} `);
|
|
18
|
+
console.log(`[${new Date().toLocaleString()}][INFO] ${msg} ${msg2 ? msg2 : ""} `);
|
|
19
19
|
}
|
|
20
20
|
dlog.i = i;
|
|
21
21
|
function s(msg, msg2 = null) {
|
|
22
|
-
console.log(`[SUCCESS] ${msg} ${msg2 ? msg2 : ""} `);
|
|
22
|
+
console.log(`[${new Date().toLocaleString()}][SUCCESS] ${msg} ${msg2 ? msg2 : ""} `);
|
|
23
23
|
}
|
|
24
24
|
dlog.s = s;
|
|
25
|
-
function ex(e, ignore =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
function ex(e, ignore = true) {
|
|
26
|
+
var _a;
|
|
27
|
+
try {
|
|
28
|
+
if (ignore) {
|
|
29
|
+
console.log(`[${new Date().toLocaleString()}][EXCEPTION] ${e.message}. Please check: ${(_a = e.stack) === null || _a === void 0 ? void 0 : _a.split("\n").slice(0, 2).join("")})`);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.log(`[${new Date().toLocaleString()}][EXCEPTION] Unwanted Exception: `, e.message, e.stack);
|
|
33
|
+
console.log(e);
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
console.log(e);
|
|
35
|
+
catch (e) { }
|
|
32
36
|
}
|
|
33
37
|
dlog.ex = ex;
|
|
34
38
|
function obj(obj, msg = "DEBUG OBJECT") {
|
|
35
|
-
console.log(
|
|
39
|
+
console.log(`[${new Date().toLocaleString()}][DEBUG] =========================== ${msg} START ======================`);
|
|
36
40
|
console.log(JSON.stringify(obj || {}, null, 1));
|
|
37
|
-
console.log(
|
|
41
|
+
console.log(`[${new Date().toLocaleString()}][DEBUG] =========================== ${msg} END ======================`);
|
|
38
42
|
}
|
|
39
43
|
dlog.obj = obj;
|
|
40
44
|
function map(map) {
|
|
41
|
-
console.log("=========================== DEBUG OBJECT START ======================");
|
|
45
|
+
console.log("[${new Date().toLocaleString()}]=========================== DEBUG OBJECT START ======================");
|
|
42
46
|
for (let x in map.keys()) {
|
|
43
47
|
console.log(`${JSON.stringify(x)} ==> ${JSON.stringify(map.get(x))}`);
|
|
44
48
|
}
|
|
45
|
-
console.log("=========================== DEBUG OBJECT END ======================");
|
|
49
|
+
console.log("[${new Date().toLocaleString()}]=========================== DEBUG OBJECT END ======================");
|
|
46
50
|
}
|
|
47
51
|
dlog.map = map;
|
|
48
52
|
})(dlog = exports.dlog || (exports.dlog = {}));
|
package/dist/dlog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dlog.js","sourceRoot":"","sources":["../src/dlog.ts"],"names":[],"mappings":";;;AAAA,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AAQ,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACvE;QACD,OAAO,CAAC,GAAG,CAAC,qGAAqG,CAAC,CAAC;IACrH,CAAC;IANe,QAAG,MAMlB,CAAA;AACH,CAAC,EAnCgB,IAAI,GAAJ,YAAI,KAAJ,YAAI,QAmCpB"}
|
package/dist/yahoofin.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export declare namespace yahooFin {
|
|
2
2
|
type TStockInfo = {
|
|
3
|
+
_id: string;
|
|
3
4
|
ltp: number;
|
|
4
5
|
open: number;
|
|
5
6
|
symbol: string;
|
|
6
7
|
name: string;
|
|
7
|
-
exchange:
|
|
8
|
+
exchange: TExchange;
|
|
8
9
|
volume: number;
|
|
9
10
|
high: number;
|
|
10
11
|
low: number;
|
|
@@ -18,8 +19,13 @@ export declare namespace yahooFin {
|
|
|
18
19
|
pre_pChange?: number;
|
|
19
20
|
post_ltp?: number;
|
|
20
21
|
post_pChange?: number;
|
|
22
|
+
previousClose?: number;
|
|
21
23
|
};
|
|
24
|
+
type TExchange = "NSE" | "BSE" | "NASDAQ" | "LSE";
|
|
25
|
+
function getExchangeFromKey(id: string): TExchange;
|
|
22
26
|
function getBulkStockQuote(symbols: string[], exchange: "NSE" | "BSE" | "LSE" | "NASDAQ"): Promise<TStockInfo[]>;
|
|
27
|
+
function getSymbolFromFullKey(key: string): string;
|
|
28
|
+
function getBulkStockQuoteWithFullKey(symbols: string[]): Promise<TStockInfo[]>;
|
|
23
29
|
type TInterval = "1d" | "5m" | "15m" | "1h";
|
|
24
30
|
type THistoryData = {
|
|
25
31
|
timestamp: number[];
|
|
@@ -32,4 +38,6 @@ export declare namespace yahooFin {
|
|
|
32
38
|
};
|
|
33
39
|
function getHistoryData(symbol: string, interval: TInterval, candle_count?: number): Promise<THistoryData | undefined>;
|
|
34
40
|
function getBulkHistoryData(symbols: string[], interval: TInterval, candle_count?: number): Promise<Map<string, THistoryData> | undefined>;
|
|
41
|
+
type TSupportedNSEIndex = "NIFTY 50" | "NIFTY BANK" | "NIFTY ENERGY" | "NIFTY 200" | "NIFTY 500";
|
|
42
|
+
function fetchNSEIndexList(index: TSupportedNSEIndex): Promise<yahooFin.TStockInfo[]>;
|
|
35
43
|
}
|
package/dist/yahoofin.js
CHANGED
|
@@ -11,18 +11,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.yahooFin = void 0;
|
|
13
13
|
const axios = require("axios").default;
|
|
14
|
+
const nse_indices_1 = require("nse-indices");
|
|
14
15
|
const dlog_1 = require("./dlog");
|
|
15
16
|
var yahooFin;
|
|
16
17
|
(function (yahooFin) {
|
|
17
18
|
const extMap = { NSE: ".NS", BSE: ".BS", NASDAQ: "", LSE: ".L" };
|
|
18
|
-
|
|
19
|
+
function getExchangeFromKey(id) {
|
|
20
|
+
if (!id) {
|
|
21
|
+
return "NASDAQ";
|
|
22
|
+
}
|
|
23
|
+
if (id.endsWith(".BS"))
|
|
24
|
+
return "BSE";
|
|
25
|
+
if (id.endsWith(".NS"))
|
|
26
|
+
return "NSE";
|
|
27
|
+
if (id.endsWith(".L"))
|
|
28
|
+
return "LSE";
|
|
29
|
+
return "NASDAQ";
|
|
30
|
+
}
|
|
31
|
+
yahooFin.getExchangeFromKey = getExchangeFromKey;
|
|
19
32
|
function getBulkStockQuote(symbols, exchange) {
|
|
20
|
-
var _a, _b, _c, _d, _e;
|
|
21
33
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
|
|
34
|
+
return yield getBulkStockQuoteWithFullKey(symbols.map((x) => x + extMap[exchange]));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
yahooFin.getBulkStockQuote = getBulkStockQuote;
|
|
38
|
+
function getSymbolFromFullKey(key) {
|
|
39
|
+
if (!key) {
|
|
40
|
+
return key;
|
|
41
|
+
}
|
|
42
|
+
return key.replace(".NS", "").replace(".L", "").replace(".BS", "");
|
|
43
|
+
}
|
|
44
|
+
yahooFin.getSymbolFromFullKey = getSymbolFromFullKey;
|
|
45
|
+
// Get map
|
|
46
|
+
function getBulkStockQuoteWithFullKey(symbols) {
|
|
47
|
+
var _a, _b, _c, _d, _e, _f;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!symbols || symbols.length == 0) {
|
|
23
50
|
return [];
|
|
24
51
|
}
|
|
25
|
-
symbols = symbols.map((x) => x + extMap[exchange]);
|
|
26
52
|
let result = [];
|
|
27
53
|
try {
|
|
28
54
|
let resp = yield axios.get(`https://query1.finance.yahoo.com/v7/finance/quote?formatted=true&symbols=${symbols.join(",")}`, {
|
|
@@ -34,9 +60,10 @@ var yahooFin;
|
|
|
34
60
|
for (let d of data.quoteResponse.result) {
|
|
35
61
|
//dlog.obj(d.postMarketChangePercent);
|
|
36
62
|
result.push({
|
|
37
|
-
|
|
63
|
+
_id: d.symbol,
|
|
64
|
+
symbol: getSymbolFromFullKey(d.symbol),
|
|
38
65
|
name: d.shortName,
|
|
39
|
-
exchange:
|
|
66
|
+
exchange: getExchangeFromKey(d.symbol),
|
|
40
67
|
ltp: d.regularMarketPrice.raw,
|
|
41
68
|
open: d.regularMarketOpen.raw,
|
|
42
69
|
low: d.regularMarketDayLow.raw,
|
|
@@ -52,6 +79,7 @@ var yahooFin;
|
|
|
52
79
|
post_pChange: (_c = d.postMarketChangePercent) === null || _c === void 0 ? void 0 : _c.raw,
|
|
53
80
|
pre_ltp: (_d = d.preMarketPrice) === null || _d === void 0 ? void 0 : _d.raw,
|
|
54
81
|
pre_pChange: (_e = d.preMarketChangePercent) === null || _e === void 0 ? void 0 : _e.raw,
|
|
82
|
+
previousClose: (_f = d.regularMarketPreviousClose) === null || _f === void 0 ? void 0 : _f.raw,
|
|
55
83
|
});
|
|
56
84
|
}
|
|
57
85
|
//dlog.obj(result);
|
|
@@ -63,7 +91,7 @@ var yahooFin;
|
|
|
63
91
|
return result;
|
|
64
92
|
});
|
|
65
93
|
}
|
|
66
|
-
yahooFin.
|
|
94
|
+
yahooFin.getBulkStockQuoteWithFullKey = getBulkStockQuoteWithFullKey;
|
|
67
95
|
function getHistoryData(symbol, interval, candle_count) {
|
|
68
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
97
|
candle_count = candle_count || 14;
|
|
@@ -103,6 +131,48 @@ var yahooFin;
|
|
|
103
131
|
});
|
|
104
132
|
}
|
|
105
133
|
yahooFin.getBulkHistoryData = getBulkHistoryData;
|
|
134
|
+
function fetchNSEIndexList(index) {
|
|
135
|
+
var _a;
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
try {
|
|
138
|
+
let data = yield nse_indices_1.getIndex(index);
|
|
139
|
+
let result = [];
|
|
140
|
+
for (var x of data.data) {
|
|
141
|
+
// log.obj(x);
|
|
142
|
+
try {
|
|
143
|
+
let d = {
|
|
144
|
+
exchange: "NSE",
|
|
145
|
+
_id: x.symbol + ".NS",
|
|
146
|
+
symbol: x.symbol,
|
|
147
|
+
change: x.change,
|
|
148
|
+
pChange: x.pChange,
|
|
149
|
+
name: ((_a = x.meta) === null || _a === void 0 ? void 0 : _a.companyName) || x.symbol,
|
|
150
|
+
week52Low: x.yearLow,
|
|
151
|
+
week52High: x.yearHigh,
|
|
152
|
+
volume: x.totalTradedVolume,
|
|
153
|
+
ltp: x.lastPrice,
|
|
154
|
+
low: x.dayLow,
|
|
155
|
+
high: x.dayHigh,
|
|
156
|
+
open: x.open,
|
|
157
|
+
};
|
|
158
|
+
result.push(d);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
dlog_1.dlog.d("Not able to fetch latest stock info");
|
|
162
|
+
dlog_1.dlog.ex(e, true);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
dlog_1.dlog.s(`NSE Data fetched ${result.length} item found`);
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
dlog_1.dlog.d("Exception: Not able to fetch latest stock info may be NSE API is broken");
|
|
170
|
+
dlog_1.dlog.ex(e, true);
|
|
171
|
+
}
|
|
172
|
+
return [];
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
yahooFin.fetchNSEIndexList = fetchNSEIndexList;
|
|
106
176
|
// end of lib
|
|
107
177
|
})(yahooFin = exports.yahooFin || (exports.yahooFin = {}));
|
|
108
178
|
// test
|
package/dist/yahoofin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"yahoofin.js","sourceRoot":"","sources":["../src/yahoofin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;AACvC,iCAA8B;AAE9B,IAAiB,QAAQ,
|
|
1
|
+
{"version":3,"file":"yahoofin.js","sourceRoot":"","sources":["../src/yahoofin.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;AACvC,6CAAuC;AACvC,iCAA8B;AAE9B,IAAiB,QAAQ,CAqLxB;AArLD,WAAiB,QAAQ;IA6BvB,MAAM,MAAM,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;IAEjE,SAAgB,kBAAkB,CAAC,EAAU;QAC3C,IAAI,CAAC,EAAE,EAAE;YACP,OAAO,QAAQ,CAAC;SACjB;QACD,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,OA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3B,GAAG,EAAE,CAAC,CAAC,SAAS;4BAChB,GAAG,EAAE,CAAC,CAAC,MAAM;4BACb,IAAI,EAAE,CAAC,CAAC,OAAO;4BACf,IAAI,EAAE,CAAC,CAAC,IAAI;yBACb,CAAC;wBACF,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;qBAChB;oBAAC,OAAO,CAAC,EAAE;wBACV,WAAI,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC;wBAC9C,WAAI,CAAC,EAAE,CAAC,CAAU,EAAE,IAAI,CAAC,CAAC;qBAC3B;iBACF;gBACD,WAAI,CAAC,CAAC,CAAC,oBAAoB,MAAM,CAAC,MAAM,aAAa,CAAC,CAAC;gBACvD,OAAO,MAAM,CAAC;aACf;YAAC,OAAO,CAAC,EAAE;gBACV,WAAI,CAAC,CAAC,CAAC,yEAAyE,CAAC,CAAC;gBAClF,WAAI,CAAC,EAAE,CAAC,CAAU,EAAE,IAAI,CAAC,CAAC;aAC3B;YACD,OAAO,EAAE,CAAC;;KACX;IAnCqB,0BAAiB,oBAmCtC,CAAA;IAED,aAAa;AACf,CAAC,EArLgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAqLxB;AACD,OAAO;AACP,CAAC,GAAS,EAAE;IACV,+DAA+D;IAC/D,iBAAiB;AACnB,CAAC,CAAA,CAAC,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "corexxx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"@types/underscore": "^1.11.3",
|
|
16
16
|
"axios": "^0.21.1",
|
|
17
17
|
"moment": "^2.29.1",
|
|
18
|
+
"nse-indices": "^0.0.3",
|
|
18
19
|
"underscore": "^1.13.1",
|
|
19
20
|
"universal-cookie": "^4.0.4"
|
|
20
21
|
},
|
package/src/dlog.ts
CHANGED
|
@@ -3,35 +3,37 @@
|
|
|
3
3
|
//let _log = colorogs(true, true, __filename);
|
|
4
4
|
export namespace dlog {
|
|
5
5
|
export function d(msg: String, msg2: any = null) {
|
|
6
|
-
console.log(`[DEBUG] ${msg} ${msg2 ? msg2 : ""} `);
|
|
6
|
+
console.log(`[${new Date().toLocaleString()}][DEBUG] ${msg} ${msg2 ? msg2 : ""} `);
|
|
7
7
|
}
|
|
8
8
|
export function e(msg: String, msg2: any = null) {
|
|
9
|
-
console.log(`[ERROR] ${msg} ${msg2 ? msg2 : ""} `);
|
|
9
|
+
console.log(`[${new Date().toLocaleString()}][ERROR] ${msg} ${msg2 ? msg2 : ""} `);
|
|
10
10
|
}
|
|
11
11
|
export function i(msg: String, msg2: any = null) {
|
|
12
|
-
console.log(`[INFO] ${msg} ${msg2 ? msg2 : ""} `);
|
|
12
|
+
console.log(`[${new Date().toLocaleString()}][INFO] ${msg} ${msg2 ? msg2 : ""} `);
|
|
13
13
|
}
|
|
14
14
|
export function s(msg: String, msg2: any = null) {
|
|
15
|
-
console.log(`[SUCCESS] ${msg} ${msg2 ? msg2 : ""} `);
|
|
15
|
+
console.log(`[${new Date().toLocaleString()}][SUCCESS] ${msg} ${msg2 ? msg2 : ""} `);
|
|
16
16
|
}
|
|
17
|
-
export function ex(e: Error, ignore =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export function ex(e: Error, ignore = true) {
|
|
18
|
+
try {
|
|
19
|
+
if (ignore) {
|
|
20
|
+
console.log(`[${new Date().toLocaleString()}][EXCEPTION] ${e.message}. Please check: ${e.stack?.split("\n").slice(0, 2).join("")})`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
console.log(`[${new Date().toLocaleString()}][EXCEPTION] Unwanted Exception: `, e.message, e.stack);
|
|
24
|
+
console.log(e);
|
|
25
|
+
} catch (e) {}
|
|
24
26
|
}
|
|
25
27
|
export function obj(obj?: Object, msg: string = "DEBUG OBJECT") {
|
|
26
|
-
console.log(
|
|
28
|
+
console.log(`[${new Date().toLocaleString()}][DEBUG] =========================== ${msg} START ======================`);
|
|
27
29
|
console.log(JSON.stringify(obj || {}, null, 1));
|
|
28
|
-
console.log(
|
|
30
|
+
console.log(`[${new Date().toLocaleString()}][DEBUG] =========================== ${msg} END ======================`);
|
|
29
31
|
}
|
|
30
32
|
export function map(map: Map<string, any>) {
|
|
31
|
-
console.log("=========================== DEBUG OBJECT START ======================");
|
|
33
|
+
console.log("[${new Date().toLocaleString()}]=========================== DEBUG OBJECT START ======================");
|
|
32
34
|
for (let x in map.keys()) {
|
|
33
35
|
console.log(`${JSON.stringify(x)} ==> ${JSON.stringify(map.get(x))}`);
|
|
34
36
|
}
|
|
35
|
-
console.log("=========================== DEBUG OBJECT END ======================");
|
|
37
|
+
console.log("[${new Date().toLocaleString()}]=========================== DEBUG OBJECT END ======================");
|
|
36
38
|
}
|
|
37
39
|
}
|
package/src/yahoofin.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
const axios = require("axios").default;
|
|
2
|
+
import { getIndex } from "nse-indices";
|
|
2
3
|
import { dlog } from "./dlog";
|
|
3
4
|
|
|
4
5
|
export namespace yahooFin {
|
|
5
6
|
// define types
|
|
6
7
|
export type TStockInfo = {
|
|
8
|
+
_id: string;
|
|
7
9
|
ltp: number;
|
|
8
10
|
open: number;
|
|
9
11
|
symbol: string;
|
|
10
12
|
name: string;
|
|
11
|
-
exchange:
|
|
13
|
+
exchange: TExchange;
|
|
12
14
|
volume: number;
|
|
13
15
|
high: number;
|
|
14
16
|
low: number;
|
|
@@ -24,16 +26,39 @@ export namespace yahooFin {
|
|
|
24
26
|
pre_pChange?: number;
|
|
25
27
|
post_ltp?: number;
|
|
26
28
|
post_pChange?: number;
|
|
29
|
+
previousClose?: number;
|
|
27
30
|
};
|
|
28
31
|
|
|
32
|
+
export type TExchange = "NSE" | "BSE" | "NASDAQ" | "LSE";
|
|
33
|
+
|
|
29
34
|
const extMap = { NSE: ".NS", BSE: ".BS", NASDAQ: "", LSE: ".L" };
|
|
30
35
|
|
|
31
|
-
|
|
36
|
+
export function getExchangeFromKey(id: string): TExchange {
|
|
37
|
+
if (!id) {
|
|
38
|
+
return "NASDAQ";
|
|
39
|
+
}
|
|
40
|
+
if (id.endsWith(".BS")) return "BSE";
|
|
41
|
+
if (id.endsWith(".NS")) return "NSE";
|
|
42
|
+
if (id.endsWith(".L")) return "LSE";
|
|
43
|
+
return "NASDAQ";
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
export async function getBulkStockQuote(symbols: string[], exchange: "NSE" | "BSE" | "LSE" | "NASDAQ"): Promise<TStockInfo[]> {
|
|
33
|
-
|
|
47
|
+
return await getBulkStockQuoteWithFullKey(symbols.map((x) => x + extMap[exchange]));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getSymbolFromFullKey(key: string) {
|
|
51
|
+
if (!key) {
|
|
52
|
+
return key;
|
|
53
|
+
}
|
|
54
|
+
return key.replace(".NS", "").replace(".L", "").replace(".BS", "");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Get map
|
|
58
|
+
export async function getBulkStockQuoteWithFullKey(symbols: string[]): Promise<TStockInfo[]> {
|
|
59
|
+
if (!symbols || symbols.length == 0) {
|
|
34
60
|
return [];
|
|
35
61
|
}
|
|
36
|
-
symbols = symbols.map((x) => x + extMap[exchange]);
|
|
37
62
|
let result: TStockInfo[] = [];
|
|
38
63
|
try {
|
|
39
64
|
let resp = await axios.get(`https://query1.finance.yahoo.com/v7/finance/quote?formatted=true&symbols=${symbols.join(",")}`, {
|
|
@@ -45,9 +70,10 @@ export namespace yahooFin {
|
|
|
45
70
|
for (let d of data.quoteResponse.result) {
|
|
46
71
|
//dlog.obj(d.postMarketChangePercent);
|
|
47
72
|
result.push({
|
|
48
|
-
|
|
73
|
+
_id: d.symbol,
|
|
74
|
+
symbol: getSymbolFromFullKey(d.symbol),
|
|
49
75
|
name: d.shortName,
|
|
50
|
-
exchange:
|
|
76
|
+
exchange: getExchangeFromKey(d.symbol),
|
|
51
77
|
ltp: d.regularMarketPrice.raw,
|
|
52
78
|
open: d.regularMarketOpen.raw,
|
|
53
79
|
low: d.regularMarketDayLow.raw,
|
|
@@ -63,6 +89,7 @@ export namespace yahooFin {
|
|
|
63
89
|
post_pChange: d.postMarketChangePercent?.raw,
|
|
64
90
|
pre_ltp: d.preMarketPrice?.raw,
|
|
65
91
|
pre_pChange: d.preMarketChangePercent?.raw,
|
|
92
|
+
previousClose: d.regularMarketPreviousClose?.raw,
|
|
66
93
|
});
|
|
67
94
|
}
|
|
68
95
|
//dlog.obj(result);
|
|
@@ -114,6 +141,47 @@ export namespace yahooFin {
|
|
|
114
141
|
return result;
|
|
115
142
|
}
|
|
116
143
|
|
|
144
|
+
// API for NSE
|
|
145
|
+
|
|
146
|
+
// We should use 3p libs as it uses some cookies
|
|
147
|
+
export type TSupportedNSEIndex = "NIFTY 50" | "NIFTY BANK" | "NIFTY ENERGY" | "NIFTY 200" | "NIFTY 500";
|
|
148
|
+
export async function fetchNSEIndexList(index: TSupportedNSEIndex): Promise<yahooFin.TStockInfo[]> {
|
|
149
|
+
try {
|
|
150
|
+
let data = await getIndex(index);
|
|
151
|
+
let result: yahooFin.TStockInfo[] = [];
|
|
152
|
+
for (var x of data.data) {
|
|
153
|
+
// log.obj(x);
|
|
154
|
+
try {
|
|
155
|
+
let d: yahooFin.TStockInfo = {
|
|
156
|
+
exchange: "NSE",
|
|
157
|
+
_id: x.symbol + ".NS",
|
|
158
|
+
symbol: x.symbol,
|
|
159
|
+
change: x.change,
|
|
160
|
+
pChange: x.pChange,
|
|
161
|
+
name: x.meta?.companyName || x.symbol,
|
|
162
|
+
week52Low: x.yearLow,
|
|
163
|
+
week52High: x.yearHigh,
|
|
164
|
+
volume: x.totalTradedVolume,
|
|
165
|
+
ltp: x.lastPrice,
|
|
166
|
+
low: x.dayLow,
|
|
167
|
+
high: x.dayHigh,
|
|
168
|
+
open: x.open,
|
|
169
|
+
};
|
|
170
|
+
result.push(d);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
dlog.d("Not able to fetch latest stock info");
|
|
173
|
+
dlog.ex(e as Error, true);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
dlog.s(`NSE Data fetched ${result.length} item found`);
|
|
177
|
+
return result;
|
|
178
|
+
} catch (e) {
|
|
179
|
+
dlog.d("Exception: Not able to fetch latest stock info may be NSE API is broken");
|
|
180
|
+
dlog.ex(e as Error, true);
|
|
181
|
+
}
|
|
182
|
+
return [];
|
|
183
|
+
}
|
|
184
|
+
|
|
117
185
|
// end of lib
|
|
118
186
|
}
|
|
119
187
|
// test
|