ABC Test

No credit card required

This Actor is under maintenance.

This actor is under maintenance and it may unreliable.

ABC Test

ABC Test

fdg43jkg33455/abc-test

No credit card required

Test

.eslintrc

1{ 2 "extends": "@apify" 3} 4

.gitignore

1apify_storage 2node_modules

.npmignore

1# This file tells Git which files shouldn't be added to source control 2 3.idea 4node_modules 5

Dockerfile

1# Dockerfile contains instructions how to build a Docker image that will contain 2# all the code and configuration needed to run your actor. For a full 3# Dockerfile reference, see https://docs.docker.com/engine/reference/builder/ 4 5# First, specify the base Docker image. Apify provides the following base images 6# for your convenience: 7# apify/actor-node-basic (Node.js 10 on Alpine Linux, small and fast image) 8# apify/actor-node-chrome (Node.js 10 + Chrome on Debian) 9# apify/actor-node-chrome-xvfb (Node.js 10 + Chrome + Xvfb on Debian) 10# For more information, see https://apify.com/docs/actor#base-images 11# Note that you can use any other image from Docker Hub. 12FROM apify/actor-node-basic 13 14# Second, copy just package.json and package-lock.json since they are the only files 15# that affect NPM install in the next step 16COPY package*.json ./ 17 18# Install NPM packages, skip optional and development dependencies to keep the 19# image small. Avoid logging too much and print the dependency tree for debugging 20RUN npm --quiet set progress=false \ 21 && npm install --only=prod --no-optional \ 22 && echo "Installed NPM packages:" \ 23 && npm list \ 24 && echo "Node.js version:" \ 25 && node --version \ 26 && echo "NPM version:" \ 27 && npm --version 28 29# Next, copy the remaining files and directories with the source code. 30# Since we do this after NPM install, quick build will be really fast 31# for simple source file changes. 32COPY . ./ 33 34# Specify how to run the source code 35CMD npm start 36

INPUT_SCHEMA.json

1{ 2 "title": "Firestore Import input", 3 "description": "Imports dataset to Firestore DB", 4 "type": "object", 5 "schemaVersion": 1, 6 "properties": { 7 "datasetId": { 8 "title": "Dataset", 9 "type": "string", 10 "description": "Dataset ID of dataset you want to import to Firestore", 11 "editor": "textfield" 12 }, 13 "apiKey": { 14 "title": "Api key", 15 "type": "string", 16 "description": "Firestore API key", 17 "editor": "textfield" 18 }, 19 "authDomain": { 20 "title": "Auth domain", 21 "type": "string", 22 "description": "Firestore authentication domain", 23 "editor": "textfield" 24 }, 25 "projectId": { 26 "title": "Project ID", 27 "type": "string", 28 "description": "Firestore project ID", 29 "editor": "textfield" 30 }, 31 "collectionName": { 32 "title": "Collection name", 33 "type": "string", 34 "description": "Firestore collection name", 35 "editor": "textfield" 36 } 37 } 38} 39

INPUT_SCHEMA_Original.json

1{ 2 "title": "Firestore Import input", 3 "description": "Imports dataset to Firestore DB", 4 "type": "object", 5 "schemaVersion": 1, 6 "properties": { 7 "datasetId": { 8 "title": "Dataset", 9 "type": "string", 10 "description": "Dataset ID of dataset you want to import to Firestore", 11 "editor": "textfield" 12 }, 13 "apiKey": { 14 "title": "Api key", 15 "type": "string", 16 "description": "Firestore API key", 17 "editor": "textfield" 18 }, 19 "authDomain": { 20 "title": "Auth domain", 21 "type": "string", 22 "description": "Firestore authentication domain", 23 "editor": "textfield" 24 }, 25 "projectId": { 26 "title": "Project ID", 27 "type": "string", 28 "description": "Firestore project ID", 29 "editor": "textfield" 30 }, 31 "collectionName": { 32 "title": "Collection name", 33 "type": "string", 34 "description": "Firestore collection name", 35 "editor": "textfield" 36 } 37 }, 38 "required": ["datasetId", "apiKey", "authDomain", "projectId", "collectionName"] 39} 40

apify.json

1{ 2 "name": "firestore-import", 3 "version": "0.0", 4 "buildTag": "latest", 5 "env": null, 6 "template": "hello_world" 7} 8

main (backedup on 28-Apr-2023).js

1const Apify = require('apify'); 2const firebase = require('firebase'); 3 4function TestFunction(myurl,createdAtTime) 5{ 6 var myPath= "AprilTest2023/25Apr2023/"+myurl+"/"+createdAtTime; 7 return myPath; 8} 9 10 function extractPreOpenMarket(apiObject, iframeSrc) { // this function extract Nifty Total Market Sectors data from apiObject and then store it into localStorage 11 var ApiMainObject = apiObject; 12 var timeStamp = apiObject['timestamp'].split(' ')[0] 13 var Category = '' 14 15 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=FO') == true) { 16 Category = 'FnO'; 17 } 18 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=ALL') == true) { 19 Category = 'ALL'; 20 } 21 22 var tempObj = {}; 23 24 var dataArray = [] 25 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=FO') == true) { 26 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 27 var alias = apiObject['data'][d] //for short-handing 28 var Symbol = alias['metadata']['symbol'] 29 30 delete alias['metadata']['chartTodayPath'] 31 delete alias['metadata']['symbol'] 32 delete alias['metadata']['purpose'] 33 delete alias['metadata']['yearHigh'] 34 delete alias['metadata']['yearLow'] 35 36 tempObj[Symbol] = alias 37 //dataArray.push( alias ) 38 39 } //for Loop ENDS HERE 40 41 } 42 else 43 { 44 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 45 var alias = apiObject['data'][d] //for short-handing 46 var Symbol = alias['metadata']['symbol'] 47 48 delete alias['metadata']['chartTodayPath'] 49 delete alias['metadata']['symbol'] 50 delete alias['metadata']['purpose'] 51 delete alias['metadata']['yearHigh'] 52 delete alias['metadata']['yearLow'] 53 54 delete alias['metadata']['marketCap'] 55 delete alias['detail']['preOpenMarket']['lastUpdateTime'] 56 delete alias['metadata']['identifier'] 57 58 tempObj[Symbol] = alias 59 //dataArray.push( alias ) 60 61 } //for Loop ENDS HERE 62 } 63 64 65 ApiMainObject["data"] = tempObj 66 //apiObject["data"] = dataArray; 67 68 var id = "pre_open_market" +"/"+ Category; 69 70 return [ ApiMainObject, timeStamp, id ] 71 72 } // extractPreOpenMarket(apiObject, iframeSrc) ENDS HERE 73 74 function extractTradingDates(apiObject, iframeSrc){ // this function extracts previous trading date and then save it into IndexedDB 75 76 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 77 var date = new Date( apiObject[1]['marketCurrentTradingDate'] ) 78 var currentTradingDate = date.getDate() +'-'+ months[date.getMonth()] +'-'+ date.getFullYear() 79 date =new Date( apiObject[1]['marketPreviousTradingDate'] ) 80 81 var previousTradingDate = date.getDate() +'-'+ months[date.getMonth()] +'-'+ date.getFullYear() 82 83 var nextTradingDate = apiObject[1]['marketNextTradingDate'] 84 85 //var tradingDates={ "marketCurrentTradingDate":currentTradingDate, "marketPreviousTradingDate":previousTradingDate, "marketNextTradingDate":nextTradingDate } 86 var tradingDates = { "currentTradingDate":currentTradingDate, "previousTradingDate":previousTradingDate, "nextTradingDate":nextTradingDate } 87 88 var timeStamp = currentTradingDate; 89 90 var id = "trading_dates"; 91 92 return [ tradingDates, timeStamp, id ] 93 94 95 } // extractTradingDates(apiObject) function ENDS HERE 96 97 function extractSectorStockNamesData(apiObject, iframeSrc) { // coded on 31-Dec-2022. this function extracts stock names of any given sector and it puts data in database 98 //modified on 5 Jan 2023 99 100 //var iframeSrc = window.location.href 101 var ApiMainObject = {}; 102 var timeStamp = apiObject['timestamp'].split(' ')[0] 103 var indexName = '' 104 var sectorName = '' 105 var stockNamesArray = [] 106 107 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open') == true) { // if iframeSrc is for pre market sector stocks then run this block 108 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=FO') == true) { 109 sectorName = 'FnO'; 110 indexName = 'FnO'; 111 } 112 else if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=BANKNIFTY') == true) { 113 sectorName = 'NIFTY BANK'; 114 indexName = 'NIFTY_BANK'; 115 } 116 else if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=NIFTY') == true) { 117 sectorName = 'NIFTY 50'; 118 indexName = 'NIFTY_50'; 119 } 120 121 122 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 123 var Symbol = apiObject['data'][d]['metadata']['symbol'] 124 stockNamesArray.push(Symbol) 125 } 126 stockNamesArray = stockNamesArray.sort() 127 128 } 129 else { 130 131 sectorName = apiObject['name'] 132 indexName = apiObject['metadata']['indexName'].replace(/ /g,'_') 133 134 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 135 var Symbol = apiObject['data'][d]['symbol'] 136 if(Symbol.includes('NIFTY') == false) 137 { 138 stockNamesArray.push(Symbol) 139 } 140 141 } 142 stockNamesArray = stockNamesArray.sort() 143 } 144 145 ApiMainObject["sectorName"] = sectorName.replace(/&amp;/g,'&'); 146 ApiMainObject["Symbols"] = stockNamesArray; 147 148 if( stockNamesArray.length > 1 ) 149 { 150 151 //console.log(ApiMainObject) 152 //return [indexName, ApiMainObject]; 153 var id = 'sector_stockNames' + '/' + indexName; 154 return [ ApiMainObject, timeStamp, id ] 155 156 } 157 158 159 } // extractSectorStockNamesData(apiObject) ENDS HERE 160 161 function extractAllIndicesPerformace(apiObject, iframeSrc) { // this function extract All Indices Performance data from apiObject and then store it into localStorage 162 163 var ApiMainObject = apiObject; 164 165 var tempObj = {}; 166 var timeStamp = apiObject['timestamp'].split(' ')[0] 167 168 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 169 var alias = apiObject['data'][d] //for short-handing 170 var data = alias //for short-handing 171 var Symbol = alias['indexSymbol'] 172 173 var pb= Number(alias['pb']) 174 var pe= Number(alias['pe']) 175 var dy= Number(alias['dy']) 176 var advances=0 177 var declines=0 178 var unchanged=0 179 if( alias['advances'] == undefined || alias['declines'] == undefined || alias['unchanged'] == undefined ) 180 { } 181 else { 182 advances=Number( alias['advances'] ) 183 declines=Number( alias['declines'] ) 184 unchanged=Number( alias['unchanged'] ) 185 } 186 187 //console.log(alias['key'], Symbol) 188 data['advances'] = advances 189 data['declines'] = declines 190 data['unchanged'] = unchanged 191 192 data['pe'] = pe 193 data['pb'] = pb 194 data['dy'] = dy 195 196 197 198 if (alias['key'] == 'BROAD MARKET INDICES' && Symbol == 'NIFTY 50' || alias['key'] == 'BROAD MARKET INDICES' && Symbol == 'INDIA VIX') { //fetch Data of 'INDIA VIX' and 'NIFTY 50' from 'BROAD MARKET INDICES' index performance 199 //tempObj[Symbol] = [alias["last"], alias["low"], alias["high"], alias["open"], alias["percentChange"], alias["previousClose"], alias["variation"], pb, pe, advances, declines, unchanged ] 200 { 201 delete data['chart30dPath'] 202 delete data['chart365dPath'] 203 delete data['date30dAgo'] 204 delete data['date365dAgo'] 205 delete data['indexSymbol'] 206 delete data['key'] 207 delete data['oneMonthAgo'] 208 delete data['oneWeekAgo'] 209 delete data['oneYearAgo'] 210 delete data['perChange30d'] 211 delete data['perChange365d'] 212 delete data['yearHigh'] 213 delete data['yearLow'] 214 delete data['chartTodayPath'] 215 216 } 217 tempObj[Symbol] = data 218 } 219 else if (alias['key'] == 'SECTORAL INDICES') { //fetch Data of all Sectors/index from 'SECTORAL INDICES' index performance 220 //tempObj[Symbol] = [alias["last"], alias["low"], alias["high"], alias["open"], alias["percentChange"], alias["previousClose"], alias["variation"], pb, pe, advances, declines, unchanged ] 221 { 222 delete data['chart30dPath'] 223 delete data['chart365dPath'] 224 delete data['date30dAgo'] 225 delete data['date365dAgo'] 226 delete data['indexSymbol'] 227 delete data['key'] 228 delete data['oneMonthAgo'] 229 delete data['oneWeekAgo'] 230 delete data['oneYearAgo'] 231 delete data['perChange30d'] 232 delete data['perChange365d'] 233 delete data['yearHigh'] 234 delete data['yearLow'] 235 delete data['chartTodayPath'] 236 237 } 238 tempObj[Symbol] = data 239 } 240 else if ( Symbol == 'NIFTY INFRA' || Symbol == 'NIFTY ENERGY' || Symbol == 'NIFTY COMMODITIES' || Symbol == 'NIFTY INDIA CONSUMPTION' || Symbol == 'NIFTY PSE' || Symbol == 'NIFTY SERV SECTOR' ) { //fetch Data of specific index 241 //tempObj[Symbol] = [alias["last"], alias["low"], alias["high"], alias["open"], alias["percentChange"], alias["previousClose"], alias["variation"], pb, pe, advances, declines, unchanged ] 242 { 243 delete data['chart30dPath'] 244 delete data['chart365dPath'] 245 delete data['date30dAgo'] 246 delete data['date365dAgo'] 247 delete data['indexSymbol'] 248 delete data['key'] 249 delete data['oneMonthAgo'] 250 delete data['oneWeekAgo'] 251 delete data['oneYearAgo'] 252 delete data['perChange30d'] 253 delete data['perChange365d'] 254 delete data['yearHigh'] 255 delete data['yearLow'] 256 delete data['chartTodayPath'] 257 258 } 259 tempObj[Symbol] = data 260 } 261 262 263 264 } //for Loop ENDS HERE 265 266 267 268 269 delete ApiMainObject['dates']; 270 delete ApiMainObject['date30dAgo']; 271 delete ApiMainObject['date365dAgo']; 272 273 ApiMainObject['data'] = tempObj; 274 275 var id = "index_performace"; 276 277 //console.log( ApiMainObject ) 278 return [ApiMainObject, timeStamp, id] 279 280 } // extractAllIndicesPerformace(apiObject) ENDS HERE 281 282 function extractStockFuture(apiObject, iframeSrc) { // this function extract Stock Future data from apiObject and then store it into localStorage 283 284 var ApiMainObject = apiObject; 285 286 var timeStamp = apiObject['timestamp'].split(' ')[0] 287 288 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 289 //var alias = apiObject['data'][d] //for short-handing 290 delete ApiMainObject['data'][d]['meta']; 291 delete ApiMainObject['data'][d]['optionType']; 292 delete ApiMainObject['data'][d]['strikePrice']; 293 294 } //for Loop ENDS HERE 295 296 297 delete ApiMainObject['marketStatus']; 298 299 var id = "stock_futures" 300 301 return [ ApiMainObject, timeStamp, id ] 302 303 } // extractStockFuture(apiObject) ENDS HERE 304 305 function extractMostActiveUnderlying(apiObject, iframeSrc) { // this function extract Most Active Underlying/Stocks/Indices data from apiObject and then store it into localStorage 306 307 var ApiMainObject = apiObject; 308 309 var tempObj = {}; 310 var timeStamp = apiObject['timestamp'].split(' ')[0] 311 312 var id = "most_active_underlying" 313 314 return [ ApiMainObject, timeStamp, id ] 315 316 } // extractMostActiveUnderlying(apiObject) ENDS HERE 317 318 function extractMostActiveFutureContracts(apiObject, iframeSrc) { // this function extract Most Active Future Contracts data from apiObject and then store it into localStorage 319 320 var ApiMainObject = apiObject; 321 322 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 323 324 var tempObj = {}; 325 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 326 327 328 for (var d = 0; d < apiObject['value']['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 329 //var alias = apiObject['data'][d] //for short-handing 330 delete ApiMainObject['value']['data'][d]['optionType']; 331 delete ApiMainObject['value']['data'][d]['strikePrice']; 332 333 } //for Loop ENDS HERE 334 335 for (var d = 0; d < apiObject['volume']['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 336 //var alias = apiObject['data'][d] //for short-handing 337 delete ApiMainObject['volume']['data'][d]['optionType']; 338 delete ApiMainObject['volume']['data'][d]['strikePrice']; 339 340 } //for Loop ENDS HERE 341 342 delete ApiMainObject['value']['timestamp'] 343 delete ApiMainObject['volume']['timestamp'] 344 345 346 347 var id = "most_active_future_contracts" 348 349 return [ ApiMainObject, timeStamp, id ] 350 351 } // extractMostActiveFutureContracts(apiObject) ENDS HERE 352 353 function extractStockOptions(apiObject, iframeSrc) { // this function extract Stock Options data from apiObject and then store it into localStorage 354 var ApiMainObject = apiObject; 355 356 var timeStamp = apiObject['timestamp'].split(' ')[0] 357 358 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 359 //var alias = apiObject['data'][d] //for short-handing 360 delete ApiMainObject['data'][d]['meta']; 361 } //for Loop ENDS HERE 362 363 364 delete ApiMainObject['marketStatus']; 365 366 var id = "stock_options"; 367 368 return [ ApiMainObject, timeStamp, id ] 369 370 371 } // extractMostActiveFutureContracts(apiObject) ENDS HERE 372 373 function extractSpurtsInOIByUnderlyings(apiObject, iframeSrc) { // this function extracts Spurts in Open Interest by Underlyings and then save it into IndexedDB 374 375 var ApiMainObject = apiObject; 376 377 var timeStamp = apiObject['timestamp'].split(' ')[0] 378 var dataArray = [] 379 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 380 var alias = apiObject['data'][d] //for short-handing 381 var Symbol = alias['symbol'] 382 if( Symbol != "-" ) 383 { 384 dataArray.push( alias ) 385 } 386 } //for Loop ENDS HERE 387 388 389 ApiMainObject["data"] = dataArray 390 var id = "spurts_in_open_interest_by_underlyings" 391 392 return [ ApiMainObject, timeStamp, id ] 393 394 } // extractSpurtsInOIByUnderlyings(apiObject ENDS HERE 395 396 function extractSpurtsInOIByContracts(apiObject, iframeSrc){ // this function extracts Spurts in Open Interest by Contracts and then save it into IndexedDB 397 398 var ApiMainObject = apiObject; 399 400 var tempObj = {}; 401 var timeStamp = apiObject['timestamp'].split(' ')[0] 402 403 for ( var dataArr of apiObject['data']) { 404 405 for ( var slide_rise_labels in dataArr ) 406 { 407 var alias = dataArr[ slide_rise_labels ] 408 tempObj[ slide_rise_labels ] = alias 409 } 410 } 411 412 413 ApiMainObject['data'] = tempObj 414 415 delete ApiMainObject['currTradingDate']; 416 delete ApiMainObject['prevTradingDate']; 417 418 var id = "spurts_in_open_interest_by_contracts" 419 420 return [ ApiMainObject, timeStamp, id ] 421 } // extractSpurtsInOIByContracts(apiObject) function ENDS HERE 422 423 function extractMostActiveOptionContracts(apiObject, iframeSrc) { // this function extract Most Active Option Contracts data from apiObject and then store it into localStorage 424 425 var ApiMainObject = apiObject; 426 427 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 428 429 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 430 431 delete ApiMainObject['value']['timestamp'] 432 delete ApiMainObject['volume']['timestamp'] 433 434 435 var id = "most_active_option_contracts" 436 437 return [ ApiMainObject, timeStamp, id ] 438 439 440 } // extractMostActiveOptionContracts(apiObject) ENDS HERE 441 442 function extractMostActiveContracts(apiObject, iframeSrc) { // this function extract Most Active Contracts data from apiObject and then store it into localStorage 443 444 var ApiMainObject = apiObject; 445 446 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 447 448 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 449 450 delete ApiMainObject['value']['timestamp'] 451 delete ApiMainObject['volume']['timestamp'] 452 453 454 var id = "most_active_contracts" 455 456 return [ ApiMainObject, timeStamp, id ] 457 458 } // extractMostActiveContracts(apiObject) ENDS HERE 459 460 function extractMostActiveCalls(apiObject, iframeSrc) { // this function extract Most Active Contracts data from apiObject and then store it into localStorage 461 462 var ApiMainObject = apiObject; 463 464 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 465 466 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 467 468 delete ApiMainObject['value']['timestamp'] 469 delete ApiMainObject['volume']['timestamp'] 470 471 472 var id = "most_active_calls" 473 474 return [ ApiMainObject, timeStamp, id ] 475 476 } // extractMostActiveCalls(apiObject) ENDS HERE 477 478 function extractMostActivePuts(apiObject, iframeSrc) { // this function extract Most Active Contracts data from apiObject and then store it into localStorage 479 480 var ApiMainObject = apiObject; 481 482 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 483 484 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 485 486 delete ApiMainObject['value']['timestamp'] 487 delete ApiMainObject['volume']['timestamp'] 488 489 490 var id = "most_active_puts" 491 492 return [ ApiMainObject, timeStamp, id ] 493 494 } // extractMostActivePuts(apiObject) ENDS HERE 495 496 497 function extractSecuritiesInFnO( apiObject, iframeSrc ) { // this function extract FnO's Securities and out of which it just pick only two stocks (AARTIIND, MOTHERSON) and add these two stocks in nifty_total_market's last entry 498 499 var ApiMainObject = apiObject; 500 501 var timeStamp = apiObject['timestamp'].split(' ')[0] 502 503 ApiMainObject['advances']=Number( apiObject['advance']['advances'] ) 504 ApiMainObject['declines']=Number( apiObject['advance']['declines'] ) 505 ApiMainObject['unchanged']=Number( apiObject['advance']['unchanged'] ) 506 507 var dataObj = {}; 508 509 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all FnO stocks 510 var alias = apiObject['data'][d] //for short-handing 511 var Symbol = alias['symbol'] 512 513 alias['dayHigh'] = Number( alias['dayHigh'] ) 514 alias['dayLow'] = Number( alias['dayLow'] ) 515 alias['lastPrice'] = Number( alias['lastPrice'] ) 516 alias['open'] = Number( alias['open'] ) 517 alias['previousClose'] = Number( alias['previousClose'] ) 518 519 520 delete alias['chart30dPath'] 521 delete alias['chart365dPath'] 522 delete alias['chartTodayPath'] 523 delete alias['date30dAgo'] 524 delete alias['date365dAgo'] 525 delete alias['identifier'] 526 delete alias['lastUpdateTime'] 527 delete alias['meta'] 528 delete alias['nearWKH'] 529 delete alias['nearWKL'] 530 delete alias['perChange30d'] 531 delete alias['perChange365d'] 532 delete alias['series'] 533 delete alias['symbol'] 534 delete alias['yearHigh'] 535 delete alias['yearLow'] 536 537 538 dataObj [ Symbol ] = alias 539 540 } //for Loop ENDS HERE 541 542 ApiMainObject['data'] = dataObj 543 544 delete ApiMainObject['date30dAgo'] 545 delete ApiMainObject['date365dAgo'] 546 delete ApiMainObject['marketStatus'] 547 delete ApiMainObject['metadata'] 548 delete ApiMainObject['name'] 549 delete ApiMainObject['advance'] 550 551 var id ='nifty_total_market' 552 553 return [ ApiMainObject, timeStamp, id ] 554 } // extractSecuritiesInFnO(apiObject) ENDS HERE 555 556 function extractNiftyTotalMarket(apiObject, iframeSrc) { // this function extract Nifty Total Market Sectors data from apiObject and then store it into localStorage 557 558 559 var ApiMainObject = apiObject; 560 561 var timeStamp = apiObject['timestamp'].split(' ')[0] 562 563 ApiMainObject['advances']=Number( apiObject['advance']['advances'] ) 564 ApiMainObject['declines']=Number( apiObject['advance']['declines'] ) 565 ApiMainObject['unchanged']=Number( apiObject['advance']['unchanged'] ) 566 567 var dataObj = {}; 568 569 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all FnO stocks 570 var alias = apiObject['data'][d] //for short-handing 571 var Symbol = alias['symbol'] 572 573 alias['dayHigh'] = Number( alias['dayHigh'] ) 574 alias['dayLow'] = Number( alias['dayLow'] ) 575 alias['lastPrice'] = Number( alias['lastPrice'] ) 576 alias['open'] = Number( alias['open'] ) 577 alias['previousClose'] = Number( alias['previousClose'] ) 578 579 580 delete alias['chart30dPath'] 581 delete alias['chart365dPath'] 582 delete alias['chartTodayPath'] 583 delete alias['date30dAgo'] 584 delete alias['date365dAgo'] 585 delete alias['identifier'] 586 delete alias['lastUpdateTime'] 587 delete alias['meta'] 588 delete alias['nearWKH'] 589 delete alias['nearWKL'] 590 delete alias['perChange30d'] 591 delete alias['perChange365d'] 592 delete alias['priority'] 593 delete alias['series'] 594 delete alias['symbol'] 595 delete alias['yearHigh'] 596 delete alias['yearLow'] 597 598 599 dataObj [ Symbol ] = alias 600 601 } //for Loop ENDS HERE 602 603 ApiMainObject['data'] = dataObj 604 605 delete ApiMainObject['date30dAgo'] 606 delete ApiMainObject['date365dAgo'] 607 delete ApiMainObject['marketStatus'] 608 delete ApiMainObject['metadata'] 609 delete ApiMainObject['name'] 610 delete ApiMainObject['advance'] 611 612 var id ='nifty_total_market' 613 614 return [ ApiMainObject, timeStamp, id ] 615 616 617 } // extractNiftyTotalMarket(apiObject) ENDS HERE 618 619 620 621 function extractOptionChainData(optionChainObject, iframeSrc) { 622 //this function will extract specific Data from optionChainObject. this object may be of any Index or Equity. 623 624 var optionChainDataObject = {}; 625 var returnedDataArray; 626 returnedDataArray = extractOptionChainDataByExpiry(optionChainObject) // this function stores option chain data by current expiry 627 optionChainDataObject[ returnedDataArray[1] ] = returnedDataArray[0] 628 //if (Date.parse(new Date().toISOString().slice(0, 10).replace(/-/g, '/')) == Date.parse(optionChainObject['records']['expiryDates'][0])) // if current date is equals to exipryDate then also store next expiry Data 629 { 630 var nextExpiryFilteredDataObject = { 631 "filtered": {}, 632 "records": {} 633 } 634 var nextExpiryFilteredDataArrays = [] 635 var nextExpirtDate = optionChainObject['records']['expiryDates'][1] 636 637 var CEtotOI = 0, CEtotVol = 0; 638 var PEtotOI = 0, PEtotVol = 0; 639 for (var d in optionChainObject['records']['data']) { 640 var recordData = optionChainObject['records']['data'][d] 641 if (recordData['expiryDate'] == nextExpirtDate) { 642 nextExpiryFilteredDataArrays.push(recordData) 643 if (recordData['CE'] != undefined) { 644 CEtotOI += recordData['CE']['openInterest'] 645 CEtotVol += recordData['CE']['totalTradedVolume'] 646 } 647 648 if (recordData['PE'] != undefined) { 649 PEtotOI += recordData['PE']['openInterest'] 650 PEtotVol += recordData['PE']['totalTradedVolume'] 651 } 652 653 } 654 655 } 656 nextExpiryFilteredDataObject["filtered"]["data"] = nextExpiryFilteredDataArrays 657 nextExpiryFilteredDataObject["filtered"]["CE"] = { "totOI": CEtotOI, "totVol": CEtotVol } 658 nextExpiryFilteredDataObject["filtered"]["PE"] = { "totOI": PEtotOI, "totVol": PEtotVol } 659 nextExpiryFilteredDataObject["records"]["timestamp"] = optionChainObject['records']['timestamp'] 660 661 returnedDataArray = extractOptionChainDataByExpiry(nextExpiryFilteredDataObject) // here this function is called to stores option chain data for next expiry 662 optionChainDataObject[ returnedDataArray[1] ] = returnedDataArray[0] 663 664 } //if (Date.parse(new Date().toISOString().slice(0, 10).replace(/-/g, '/')) == Date.parse(apiObject['records']['expiryDates'][0])) ENDS HERE 665 666 return [ optionChainDataObject, returnedDataArray[2], returnedDataArray[3] ] 667 668 } //extractOptionChainData(optionChainObject) Function ENDS HERE 669 670 function extractOptionChainDataByExpiry(optionChainObject) { 671 //this function will extract specific Data from optionChainObject. this object may be of any Index or Equity. 672 // 673 //console.log(optionChainObject["filtered"]["data"][0]['CE']) 674 //await getData("currentDay") 675 //await sleep(1500) 676 var highest_PUT_OI_Change = "0,0", highest_Call_OI_Change = "0,0", highest_PUT_OI = "0,0", highest_Call_OI = "0,0"; 677 678 var ApiMainObject = {}; 679 //ApiMainObject = JSON.parse(localStorage.getItem("NSE_APIs_Data")); 680 //ApiMainObject = JSON.parse(returnedIndexedDBData); 681 682 var totalOICEChange = 0, totalOIPEChange = 0; //these variables are for Addition intraday change in OI of all strike prices for CE, PE 683 var totalCE = optionChainObject["filtered"]["CE"]["totOI"] 684 var totalCEVol = optionChainObject["filtered"]["CE"]["totVol"] 685 686 var totalPE = optionChainObject["filtered"]["PE"]["totOI"] 687 var totalPEVol = optionChainObject["filtered"]["PE"]["totVol"] 688 689 var strikePriceObject, Symbol, expiryDate, timeStamp, strikePrice, spotPrice; 690 691 //Symbol = optionChainObject["filtered"]["data"][0]['CE']['underlying'] //get index or stock name from 1st strike price's data 692 //spotPrice = optionChainObject["filtered"]["data"][0]['CE']['underlyingValue'] //get spot price of index or stock name from 1st strike price's data 693 694 if (optionChainObject["filtered"]["data"][0]["CE"] != undefined) { //if there is not CE object in strikePriceObject then set arrayCE to all 0s and add 0 into totalOICEChange 695 Symbol = optionChainObject["filtered"]["data"][0]['CE']['underlying'] //get index or stock name from 1st strike price's data 696 spotPrice = optionChainObject["filtered"]["data"][0]['CE']['underlyingValue'] //get spot price of index or stock name from 1st strike price's data 697 } 698 else if (optionChainObject["filtered"]["data"][0]["PE"] != undefined) { //if there is CE object in strikePriceObject then fetch data from CE object and set arrayCE as array and add CE's changeinOpenInterest into totalOICEChange 699 Symbol = optionChainObject["filtered"]["data"][0]['PE']['underlying'] //get index or stock name from 1st strike price's data 700 spotPrice = optionChainObject["filtered"]["data"][0]['PE']['underlyingValue'] //get spot price of index or stock name from 1st strike price's data 701 } 702 703 for (var i = 0; i < optionChainObject["filtered"]['data'].length; i++) // loop fetching all strike prices 704 { 705 706 strikePriceObject = optionChainObject["filtered"]["data"][i] //get ith array's Strike price object 707 //Symbol=strikePriceObject['CE']['underlying'] 708 expiryDate = strikePriceObject['expiryDate'] 709 timeStamp = optionChainObject['records']['timestamp'].split(' ')[0] 710 strikePrice = strikePriceObject['strikePrice'] 711 //spotPrice=strikePriceObject['CE']['underlyingValue'] 712 if (strikePriceObject["CE"] == undefined) { //if there is not CE object in strikePriceObject then set arrayCE to all 0s and add 0 into totalOICEChange 713 //var arrayCE = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 714 totalOICEChange += 0 715 716 } 717 else { //if there is CE object in strikePriceObject then fetch data from CE object and set arrayCE as array and add CE's changeinOpenInterest into totalOICEChange 718 //var arrayCE = [ strikePriceObject["CE"]["openInterest"], strikePriceObject["CE"]["changeinOpenInterest"], strikePriceObject["CE"]["totalTradedVolume"], strikePriceObject["CE"]["impliedVolatility"], strikePriceObject["CE"]["lastPrice"], strikePriceObject["CE"]["change"], strikePriceObject["CE"]["totalBuyQuantity"], strikePriceObject["CE"]["totalSellQuantity"], strikePriceObject["CE"]["askPrice"], strikePriceObject["CE"]["askQty"], strikePriceObject["CE"]["bidprice"], strikePriceObject["CE"]["bidQty"], strikePriceObject["CE"]["pChange"], strikePriceObject["CE"]["pchangeinOpenInterest"] ] 719 totalOICEChange += strikePriceObject["CE"]["changeinOpenInterest"] 720 721 delete strikePriceObject['CE']['expiryDate'] 722 } 723 724 725 if (strikePriceObject["PE"] == undefined) { //if there is not PE object in strikePriceObject then set arrayPE to all 0s and add 0 into totalOIPEChange 726 //var arrayPE = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 727 totalOIPEChange += 0 728 } 729 else { //if there is PE object in strikePriceObject then fetch data from PE object and set arrayPE as array and add PE's changeinOpenInterest into totalOIPEChange 730 //var arrayPE = [ strikePriceObject["PE"]["openInterest"], strikePriceObject["PE"]["changeinOpenInterest"], strikePriceObject["PE"]["totalTradedVolume"], strikePriceObject["PE"]["impliedVolatility"], strikePriceObject["PE"]["lastPrice"], strikePriceObject["PE"]["change"], strikePriceObject["PE"]["totalBuyQuantity"], strikePriceObject["PE"]["totalSellQuantity"], strikePriceObject["PE"]["askPrice"], strikePriceObject["PE"]["askQty"], strikePriceObject["PE"]["bidprice"], strikePriceObject["PE"]["bidQty"], strikePriceObject["PE"]["pChange"], strikePriceObject["PE"]["pchangeinOpenInterest"] ] 731 totalOIPEChange += strikePriceObject["PE"]["changeinOpenInterest"] 732 733 delete strikePriceObject['PE']['expiryDate'] 734 } 735 736 737 738 delete strikePriceObject['strikePrice'] 739 delete strikePriceObject['expiryDate'] 740 741 if (ApiMainObject[strikePrice] == undefined ) //if strikePrice does not exit in ApiMainObject["option_chain_data"][Symbol][expiryDate][timeStamp] then add it with empty entry 742 { 743 ApiMainObject[strikePrice] = {}; 744 ApiMainObject[strikePrice] = strikePriceObject 745 746 747 //ApiMainObject[strikePrice]["CE"] = arrayCE 748 //ApiMainObject[strikePrice]["PE"] = arrayPE 749 } 750 751 } // for(var i=0;i<optionChainObject["filtered"]['data'].length;i++) // for loop Ends here 752 753 754 ApiMainObject["totalCEPE"] = { 755 "totalOICE" : totalCE, 756 "totalCEVol" : totalCEVol, 757 "totalOIPE" : totalPE, 758 "totalPEVol" : totalPEVol, 759 "intradayOICEChange" : totalOICEChange, 760 "intradayOIPEChange" : totalOIPEChange, 761 } 762 763 ApiMainObject["SpotPrice"] = spotPrice; 764 ApiMainObject["expiryDate"] = expiryDate; 765 766 var id = "option_chain_data" + "/"+ Symbol 767 768 //console.log( [ ApiMainObject, expiryDate, timeStamp, id ] ) 769 return [ ApiMainObject, expiryDate, timeStamp, id ] 770 771 } //extractOptionChainData(optionChainObject) Function ENDS HERE 772 773 774 function extractIntradayGraphData(apiObject, iframeSrc) { // this function extracts intraday chart data from apiObject and then store it 775 //added on 18-Feb-2023 776 777 var ApiMainObject = {}; 778 var tempObj = {}; 779 780 var options = { 781 timeZone: 'Asia/Kolkata', 782 day: '2-digit', 783 month: 'short', 784 year: 'numeric', 785 }; 786 787 788 //var timeStamp = new Date( apiObject['grapthData'][0][0] ).toLocaleString('en-IN', options); 789 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 790 791 var date = new Date( apiObject['grapthData'][0][0] ) 792 var timeStamp = date.getDate() +'-'+ months[date.getMonth()] +'-'+ date.getFullYear() 793 794 for (var d = 0; d < apiObject['grapthData'].length; d++) { // loop for accessing all stocks of 752 stocks 795 var alias = apiObject['grapthData'][d] //for short-handing 796 var DateTimeInMilliseconds = alias[0] // DateTime in milliseconds 797 var Price = alias[1] // price 798 tempObj [ DateTimeInMilliseconds ] = Price 799 } //for Loop ENDS HERE 800 801 802 ApiMainObject["name"] = apiObject['name'] 803 ApiMainObject["identifier"] = apiObject['identifier'] 804 ApiMainObject["closePrice"] = apiObject['closePrice'] 805 ApiMainObject["graphData"] = tempObj 806 807 808 var id="intraday_chart_data" + "/"+apiObject['name'] 809 810 811 return [ ApiMainObject, timeStamp, id ] 812 813 } // extractIntradayGraphData(apiObject, iframeSrc) ENDS HERE 814 815 816 817 818 async function handleData(apiObject, iframeSrc, db, createdAtTime) { // this function first handles localStorages for current NSE_APIs_Data, PreviousDay_NSE_APIs_Data. and then redirect iframe's JSON object to specified function according to iframe src 819 820 var ApiMainObject = {}; 821 var returnedDataArray ; 822 var pathToStoreData; 823 var pathOfDocument; 824 var dataObj; 825 826 var options = { 827 timeZone: 'Asia/Kolkata', 828 month: 'long', 829 year: 'numeric', 830 }; 831 832 833 if ( iframeSrc.includes("api/allMarketStatus") == true ) { 834 returnedDataArray = extractTradingDates(apiObject) 835 pathOfDocument = returnedDataArray[2] +'/marketStatus' ; 836 } 837 else if (iframeSrc.includes("#OnlyForSectorsStocks") == true) { // if current iframe's src is for fetching only stockname of sectors with #OnlyForSectorsStocks, then redirect to extractSectorStockNamesData(apiObject) function 838 returnedDataArray = extractSectorStockNamesData(apiObject, iframeSrc ) 839 pathOfDocument = returnedDataArray[2] ; 840 } 841 else if (iframeSrc.includes("api/option-chain-indices") == true || iframeSrc.includes("api/option-chain-equities") == true) { // if current iframe's src is for index or equity, then redirect to extractOptionChainData(apiObject) function 842 returnedDataArray = extractOptionChainData(apiObject, iframeSrc) 843 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime + '/' +createdAtTime; 844 } 845 else if (iframeSrc.includes("api/live-analysis-variations") == true) { // if current iframe's src is for gainers or loosers, then redirect to extractGainersLoosersData(apiObject, iframeSrc) function 846 //returnedDataArray = extractGainersLoosersData(apiObject, iframeSrc) 847 848 } 849 else if (iframeSrc.includes("api/allIndices") == true) { // if current iframe's src is for index performance, then redirect to extractAllIndicesPerformace(apiObject) function 850 returnedDataArray = extractAllIndicesPerformace(apiObject, iframeSrc) 851 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 852 } 853 else if (iframeSrc.includes("api/liveEquity-derivatives?index=stock_fut") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 854 returnedDataArray = extractStockFuture(apiObject, iframeSrc) 855 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 856 } 857 else if (iframeSrc.includes("https://www.nseindia.com/api/live-analysis-most-active-underlying") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 858 returnedDataArray = extractMostActiveUnderlying(apiObject, iframeSrc) 859 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 860 } 861 else if (iframeSrc.includes("https://www.nseindia.com/api/snapshot-derivatives-equity?index=futures") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 862 returnedDataArray = extractMostActiveFutureContracts(apiObject, iframeSrc) 863 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 864 } 865 else if (iframeSrc.includes("https://www.nseindia.com/api/liveEquity-derivatives?index=stock_opt") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 866 returnedDataArray = extractStockOptions(apiObject, iframeSrc) 867 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 868 } 869 //else if (iframeSrc.includes("https://www.nseindia.com/api/equity-stockIndices?index=NIFTY%20TOTAL%20MARKET") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 870 else if (iframeSrc.includes("https://www.nseindia.com/api/equity-stockIndices?index=NIFTY%20TOTAL%20MARKET") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 871 returnedDataArray = extractNiftyTotalMarket(apiObject, iframeSrc) 872 //returnedDataArray = extractSecuritiesInFnO( apiObject, iframeSrc ) 873 874 875 if( Object.keys(equityData).length==0 ) 876 { 877 equityData["data"] = returnedDataArray[0] 878 equityData["timeStamp"] = returnedDataArray[1] 879 equityData["id"] = returnedDataArray[2] 880 equityData["alreadySavedData"] = "NIFTY%20TOTAL%20MARKET" 881 } 882 else 883 { 884 var alias = returnedDataArray[0]["data"] 885 for( var Symbol in alias ) 886 { 887 if( equityData["data"]["data"][Symbol]==undefined ) 888 { 889 equityData["data"]["data"][Symbol] = alias[Symbol] 890 } 891 892 } 893 894 895 if( equityData["alreadySavedData"] == "SECURITIES%20IN%20F%26O" ) 896 { 897 equityData["data"]["advances"] = returnedDataArray[0]["advances"] 898 equityData["data"]["declines"] = returnedDataArray[0]["declines"] 899 equityData["data"]["unchanged"] = returnedDataArray[0]["unchanged"] 900 } 901 } 902 903 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 904 //console.log("equityData", equityData) 905 } 906 else if (iframeSrc.includes("https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 907 returnedDataArray = extractSecuritiesInFnO(apiObject, iframeSrc) 908 //returnedDataArray = extractNiftyTotalMarket(apiObject, iframeSrc) 909 910 if( Object.keys(equityData).length==0 ) 911 { 912 equityData["data"] = returnedDataArray[0] 913 equityData["timeStamp"] = returnedDataArray[1] 914 equityData["id"] = returnedDataArray[2] 915 equityData["alreadySavedData"] = "SECURITIES%20IN%20F%26O" 916 } 917 else 918 { 919 var alias = returnedDataArray[0]["data"] 920 for( var Symbol in alias ) 921 { 922 if( equityData["data"]["data"][Symbol]==undefined ) 923 { 924 equityData["data"]["data"][Symbol] = alias[Symbol] 925 } 926 927 } 928 929 } 930 931 //pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 932 pathOfDocument = returnedDataArray[2] + '/FnO/' +createdAtTime+ '/' +createdAtTime; 933 } 934 else if (iframeSrc.includes("https://www.nseindia.com/api/market-data-pre-open") == true) { // if current iframe's src is for pre open market then redirect to extractPreOpenMarket(apiObject, iframeSrc) function 935 returnedDataArray = extractPreOpenMarket(apiObject, iframeSrc) 936 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime + '/' +createdAtTime; 937 } 938 else if (iframeSrc.includes("https://www.nseindia.com/api/live-analysis-oi-spurts-underlyings") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 939 returnedDataArray = extractSpurtsInOIByUnderlyings(apiObject, iframeSrc) 940 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 941 } 942 else if (iframeSrc.includes("https://www.nseindia.com/api/live-analysis-oi-spurts-contracts") == true) { // if current iframe's src is for stock_fut , then redirect to extractStockFuture(apiObject) function 943 returnedDataArray = extractSpurtsInOIByContracts(apiObject, iframeSrc) 944 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 945 } 946 else if (iframeSrc.includes("https://www.nseindia.com/api/snapshot-derivatives-equity?index=options") == true) { // if current iframe's src is for most active options , then redirect to extractMostActiveOptionContracts(apiObject) function 947 returnedDataArray = extractMostActiveOptionContracts(apiObject, iframeSrc) 948 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 949 } 950 else if (iframeSrc.includes("https://www.nseindia.com/api/snapshot-derivatives-equity?index=contracts") == true) { // if current iframe's src is for most active contracts , then redirect to extractMostActiveContracts(apiObject) function 951 returnedDataArray = extractMostActiveContracts(apiObject, iframeSrc) 952 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 953 } 954 else if (iframeSrc.includes("https://www.nseindia.com/api/snapshot-derivatives-equity?index=calls") == true) { // if current iframe's src is for most active calls , then redirect to extractMostActiveCalls(apiObject) function 955 returnedDataArray = extractMostActiveCalls(apiObject, iframeSrc) 956 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 957 } 958 else if (iframeSrc.includes("https://www.nseindia.com/api/snapshot-derivatives-equity?index=puts") == true) { // if current iframe's src is for most active puts, then redirect to extractMostActivePuts(apiObject) function 959 returnedDataArray = extractMostActivePuts(apiObject, iframeSrc) 960 pathOfDocument = returnedDataArray[2] + '/' +createdAtTime; 961 } 962 963 else if (iframeSrc.includes("https://www.nseindia.com/api/chart-databyindex?index=") == true) { // if current iframe's src is for graph chart data, then redirect to extractIntradayGraphData(apiObject, iframeSrc) function 964 returnedDataArray = extractIntradayGraphData(apiObject, iframeSrc) // added on 18-Feb-2023 965 pathOfDocument = returnedDataArray[2] ; 966 } 967 968 //April 2023/26-Apr-2023/sector_stockNames/NIFTY_BANK/22:21:16 has 969 var monthYear = new Date( returnedDataArray[1] ).toLocaleString('en-IN', options); 970 //pathToStoreData = monthYear +'/'+ returnedDataArray[1] + '/' + returnedDataArray[2] + '/' +createdAtTime; 971 pathToStoreData = monthYear +'/'+ returnedDataArray[1] + '/' + pathOfDocument ; 972 973 dataObj={ 974 "data": JSON.stringify(returnedDataArray[0]) 975 } 976 console.log( JSON.stringify(returnedDataArray[0]).length ) 977 if (iframeSrc.includes("https://www.nseindia.com/api/equity-stockIndices?index=NIFTY%20TOTAL%20MARKET") == false ) 978 { 979 await db.doc( pathToStoreData ).set( dataObj ); 980 } 981 982 983 } //localStorageChecking_and_redirecting(apiObject,iframeSrc) function ENDS HERE 984 985var equityData = {}; 986 987 988Apify.main(async () => { 989 const input = await Apify.getInput(); 990 991 const { data } = input; 992 let islegacyPhantomJSTask = false; 993 if (data && typeof data === 'string') { 994 // It runs from legacy phantomjs crawler task finished webhook 995 const legacyInput = JSON.parse(data); 996 Object.assign(input, legacyInput); 997 islegacyPhantomJSTask = true; 998 } 999 1000 const { datasetId, apiKey, authDomain, projectId, collectionName } = input; 1001 1002 if (!datasetId) { 1003 throw new Error('DatasetId is required on input.'); 1004 } 1005 1006 firebase.initializeApp({ 1007 apiKey, 1008 authDomain, 1009 projectId, 1010 }); 1011 1012 // Initialize Cloud Firestore through Firebase 1013 const db = firebase.firestore(); 1014 console.log(`Start importing dataset ${datasetId} to firestore.`); 1015 const dataset = await Apify.openDataset(datasetId, { forceCloud: true }); 1016 const datasetInfo = await dataset.getInfo(); 1017 1018 //console.log('datasetInfo:', datasetInfo); 1019 const createdAt = new Date( datasetInfo["createdAt"] ) 1020 1021 var options = { 1022 timeZone: 'Asia/Kolkata', 1023 year: 'numeric', 1024 month: '2-digit', 1025 day: '2-digit', 1026 hour: '2-digit', 1027 minute: '2-digit', 1028 second: '2-digit' , 1029 hour12: false 1030 }; 1031 1032 //var createdAtTime = new Date( datasetInfo["createdAt"] ).toTimeString('en-IN', options).split(' ')[0] 1033 var createdAtTime = new Date( datasetInfo["createdAt"] ).toLocaleString('en-IN', options).split(' ')[1] 1034 1035 // Import dataset from actor/task 1036 const limit = 1000; 1037 let counter = 0; 1038 for (let offset = 0; offset < datasetInfo.itemCount; offset += limit) { 1039 const pagination = await dataset.getData({ 1040 simplified: islegacyPhantomJSTask, 1041 clean: !islegacyPhantomJSTask, 1042 limit, 1043 offset, 1044 }); 1045 console.log(`Get dataset items offset: ${pagination.offset}`); 1046 for (const item of pagination.items) { 1047 var fetchedURL = item["url"]; 1048 var myurl = (item["url"].replace(/[^\w\s]/gi, "")); 1049 console.log('item:', myurl ); 1050 console.log('createdAt:', createdAt ); 1051 1052 try { 1053 if( item["pageText"]!="" ) 1054 { 1055 //var myPath= "March2022/10Mar2023/"+myurl+"/"+createdAtTime; 1056 /*var myPath = TestFunction(myurl,createdAtTime); 1057 //await db.collection(collectionName).doc( myurl ).set( JSON.parse(item["pageText"]) ); // Use doc() and set() instead of add() 1058 //await db.doc( myPath ).set( JSON.parse(item["pageText"]) ); // Use doc() and set() instead of add() 1059 var dataObj={ 1060 "objectValue":(item["pageText"]) 1061 } 1062 await db.doc( myPath ).set( dataObj ); // Use doc() and set() instead of add() 1063 1064 //console.log('Added item:', item.replace(/[^\w\s]/gi, '')); 1065 */ 1066 1067 await handleData( JSON.parse(item["pageText"]), fetchedURL, db, createdAtTime); 1068 1069 counter++; 1070 } 1071 1072 } catch (err) { 1073 //console.log(`Cannot import item ${JSON.stringify(item)}: ${err.message}`); 1074 console.log(`Cannot import item ${myurl}: ${err.message} : ${err}`); 1075 } 1076 } 1077 } 1078 1079 console.log(`Imported ${counter} from dataset ${datasetId}.`); 1080 1081 console.log('Done!'); 1082});

main backedup on 09-Sep-2023.js

1const Apify = require('apify'); 2const firebase = require('firebase'); 3 4 function extractPreOpenMarket(apiObject, iframeSrc) { // this function extract Nifty Total Market Sectors data from apiObject and then store it into localStorage 5 var ApiMainObject = apiObject; 6 //var timeStamp = apiObject['timestamp'].split(' ')[0] 7 var timeStamp = apiObject['timestamp'] 8 var Category = '' 9 10 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=FO') == true) { 11 Category = 'FnO'; 12 } 13 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=ALL') == true) { 14 Category = 'ALL'; 15 } 16 17 var tempObj = {}; 18 19 var dataArray = [] 20 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=FO') == true) { 21 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 22 var alias = apiObject['data'][d] //for short-handing 23 var Symbol = alias['metadata']['symbol'] 24 25 delete alias['metadata']['chartTodayPath'] 26 delete alias['metadata']['symbol'] 27 delete alias['metadata']['purpose'] 28 delete alias['metadata']['yearHigh'] 29 delete alias['metadata']['yearLow'] 30 31 tempObj[Symbol] = alias 32 //dataArray.push( alias ) 33 34 } //for Loop ENDS HERE 35 36 } 37 else 38 { 39 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 40 var alias = apiObject['data'][d] //for short-handing 41 var Symbol = alias['metadata']['symbol'] 42 43 delete alias['metadata']['chartTodayPath'] 44 delete alias['metadata']['symbol'] 45 delete alias['metadata']['purpose'] 46 delete alias['metadata']['yearHigh'] 47 delete alias['metadata']['yearLow'] 48 49 delete alias['metadata']['marketCap'] 50 delete alias['detail']['preOpenMarket']['lastUpdateTime'] 51 delete alias['metadata']['identifier'] 52 53 tempObj[Symbol] = alias 54 //dataArray.push( alias ) 55 56 } //for Loop ENDS HERE 57 } 58 59 60 ApiMainObject["data"] = tempObj 61 //apiObject["data"] = dataArray; 62 63 var id = "pre_open_market" +"/"+ Category; 64 65 return [ ApiMainObject, timeStamp, id ] 66 67 } // extractPreOpenMarket(apiObject, iframeSrc) ENDS HERE 68 69 function extractTradingDates(apiObject, iframeSrc){ // this function extracts previous trading date and then save it into IndexedDB 70 71 var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; 72 var date = new Date( apiObject[1]['marketCurrentTradingDate'] ) 73 var dayOfMonth = String(date.getDate()); 74 if (dayOfMonth.length < 2) { 75 dayOfMonth = '0' + dayOfMonth; 76 } 77 var currentTradingDate = dayOfMonth +'-'+ months[date.getMonth()] +'-'+ date.getFullYear() 78 date =new Date( apiObject[1]['marketPreviousTradingDate'] ) 79 var dayOfMonth = String(date.getDate()); 80 if (dayOfMonth.length < 2) { 81 dayOfMonth = '0' + dayOfMonth; 82 } 83 var previousTradingDate = dayOfMonth +'-'+ months[date.getMonth()] +'-'+ date.getFullYear() 84 85 var nextTradingDate = apiObject[1]['marketNextTradingDate'] 86 87 //var tradingDates={ "marketCurrentTradingDate":currentTradingDate, "marketPreviousTradingDate":previousTradingDate, "marketNextTradingDate":nextTradingDate } 88 var tradingDates = { "currentTradingDate":currentTradingDate, "previousTradingDate":previousTradingDate, "nextTradingDate":nextTradingDate } 89 90 var timeStamp = currentTradingDate; 91 92 var id = "trading_dates"; 93 94 return [ tradingDates, timeStamp, id ] 95 96 97 } // extractTradingDates(apiObject) function ENDS HERE 98 99 function extractSectorStockNamesData(apiObject, iframeSrc) { // coded on 31-Dec-2022. this function extracts stock names of any given sector and it puts data in database 100 //modified on 5 Jan 2023 101 102 //var iframeSrc = window.location.href 103 var ApiMainObject = {}; 104 var timeStamp = apiObject['timestamp'].split(' ')[0] 105 var indexName = '' 106 var sectorName = '' 107 var stockNamesArray = [] 108 109 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open') == true) { // if iframeSrc is for pre market sector stocks then run this block 110 if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=FO') == true) { 111 sectorName = 'FnO'; 112 indexName = 'FnO'; 113 } 114 else if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=BANKNIFTY') == true) { 115 sectorName = 'NIFTY BANK'; 116 indexName = 'NIFTY_BANK'; 117 } 118 else if (iframeSrc.includes('https://www.nseindia.com/api/market-data-pre-open?key=NIFTY') == true) { 119 sectorName = 'NIFTY 50'; 120 indexName = 'NIFTY_50'; 121 } 122 123 124 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 125 var Symbol = apiObject['data'][d]['metadata']['symbol'] 126 stockNamesArray.push(Symbol) 127 } 128 stockNamesArray = stockNamesArray.sort() 129 130 } 131 else if (iframeSrc.includes('https://www.nseindia.com/api/equity-stockIndices?index=SECURITIES%20IN%20F%26O') == true) { // if iframeSrc is for FnO sector stocks then run this block 132 133 sectorName = 'FnO'; 134 indexName = 'FnO'; 135 136 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 137 var Symbol = apiObject['data'][d]['symbol'] 138 if(Symbol.includes('NIFTY') == false) 139 { 140 stockNamesArray.push(Symbol) 141 } 142 143 } 144 stockNamesArray = stockNamesArray.sort() 145 146 } 147 else { 148 149 sectorName = apiObject['name'] 150 indexName = apiObject['metadata']['indexName'].replace(/ /g,'_') 151 152 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Data Arrays 153 var Symbol = apiObject['data'][d]['symbol'] 154 if(Symbol.includes('NIFTY') == false) 155 { 156 stockNamesArray.push(Symbol) 157 } 158 159 } 160 stockNamesArray = stockNamesArray.sort() 161 } 162 163 ApiMainObject["sectorName"] = sectorName.replace(/&amp;/g,'&'); 164 ApiMainObject["Symbols"] = stockNamesArray; 165 166 if( stockNamesArray.length > 1 ) 167 { 168 169 //console.log(ApiMainObject) 170 //return [indexName, ApiMainObject]; 171 var id = 'sector_stockNames' + '/' + indexName; 172 return [ ApiMainObject, timeStamp, id ] 173 174 } 175 176 177 } // extractSectorStockNamesData(apiObject) ENDS HERE 178 179 function extractAllIndicesPerformace(apiObject, iframeSrc) { // this function extract All Indices Performance data from apiObject and then store it into localStorage 180 181 var ApiMainObject = apiObject; 182 183 var tempObj = {}; 184 var timeStamp = apiObject['timestamp'].split(' ')[0] 185 186 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 187 var alias = apiObject['data'][d] //for short-handing 188 var data = alias //for short-handing 189 var Symbol = alias['indexSymbol'] 190 191 var pb= Number(alias['pb']) 192 var pe= Number(alias['pe']) 193 var dy= Number(alias['dy']) 194 var advances=0 195 var declines=0 196 var unchanged=0 197 if( alias['advances'] == undefined || alias['declines'] == undefined || alias['unchanged'] == undefined ) 198 { } 199 else { 200 advances=Number( alias['advances'] ) 201 declines=Number( alias['declines'] ) 202 unchanged=Number( alias['unchanged'] ) 203 } 204 205 //console.log(alias['key'], Symbol) 206 data['advances'] = advances 207 data['declines'] = declines 208 data['unchanged'] = unchanged 209 210 data['pe'] = pe 211 data['pb'] = pb 212 data['dy'] = dy 213 214 215 216 //if (alias['key'] == 'BROAD MARKET INDICES' && Symbol == 'NIFTY 50' || alias['key'] == 'BROAD MARKET INDICES' && Symbol == 'INDIA VIX') { //fetch Data of 'INDIA VIX' and 'NIFTY 50' from 'BROAD MARKET INDICES' index performance 217 if ( alias['key'] == 'BROAD MARKET INDICES' ) { //fetch Data of 'INDIA VIX' and 'NIFTY 50' from 'BROAD MARKET INDICES' index performance 218 219 { 220 delete data['chart30dPath'] 221 delete data['chart365dPath'] 222 delete data['date30dAgo'] 223 delete data['date365dAgo'] 224 delete data['indexSymbol'] 225 delete data['key'] 226 delete data['oneMonthAgo'] 227 delete data['oneWeekAgo'] 228 delete data['oneYearAgo'] 229 delete data['perChange30d'] 230 delete data['perChange365d'] 231 delete data['yearHigh'] 232 delete data['yearLow'] 233 delete data['chartTodayPath'] 234 235 } 236 tempObj[Symbol] = data 237 } 238 else if (alias['key'] == 'SECTORAL INDICES') { //fetch Data of all Sectors/index from 'SECTORAL INDICES' index performance 239 //tempObj[Symbol] = [alias["last"], alias["low"], alias["high"], alias["open"], alias["percentChange"], alias["previousClose"], alias["variation"], pb, pe, advances, declines, unchanged ] 240 { 241 delete data['chart30dPath'] 242 delete data['chart365dPath'] 243 delete data['date30dAgo'] 244 delete data['date365dAgo'] 245 delete data['indexSymbol'] 246 delete data['key'] 247 delete data['oneMonthAgo'] 248 delete data['oneWeekAgo'] 249 delete data['oneYearAgo'] 250 delete data['perChange30d'] 251 delete data['perChange365d'] 252 delete data['yearHigh'] 253 delete data['yearLow'] 254 delete data['chartTodayPath'] 255 256 } 257 tempObj[Symbol] = data 258 } 259 else if ( Symbol == 'NIFTY INFRA' || Symbol == 'NIFTY ENERGY' || Symbol == 'NIFTY COMMODITIES' || Symbol == 'NIFTY INDIA CONSUMPTION' || Symbol == 'NIFTY PSE' || Symbol == 'NIFTY SERV SECTOR' ) { //fetch Data of specific index 260 //tempObj[Symbol] = [alias["last"], alias["low"], alias["high"], alias["open"], alias["percentChange"], alias["previousClose"], alias["variation"], pb, pe, advances, declines, unchanged ] 261 { 262 delete data['chart30dPath'] 263 delete data['chart365dPath'] 264 delete data['date30dAgo'] 265 delete data['date365dAgo'] 266 delete data['indexSymbol'] 267 delete data['key'] 268 delete data['oneMonthAgo'] 269 delete data['oneWeekAgo'] 270 delete data['oneYearAgo'] 271 delete data['perChange30d'] 272 delete data['perChange365d'] 273 delete data['yearHigh'] 274 delete data['yearLow'] 275 delete data['chartTodayPath'] 276 277 } 278 tempObj[Symbol] = data 279 } 280 281 282 283 } //for Loop ENDS HERE 284 285 286 287 288 delete ApiMainObject['dates']; 289 delete ApiMainObject['date30dAgo']; 290 delete ApiMainObject['date365dAgo']; 291 292 ApiMainObject['data'] = tempObj; 293 294 var id = "index_performace"; 295 296 //console.log( ApiMainObject ) 297 return [ApiMainObject, timeStamp, id] 298 299 } // extractAllIndicesPerformace(apiObject) ENDS HERE 300 301 function extractStockFuture(apiObject, iframeSrc) { // this function extract Stock Future data from apiObject and then store it into localStorage 302 303 var ApiMainObject = apiObject; 304 305 var timeStamp = apiObject['timestamp'].split(' ')[0] 306 307 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 308 //var alias = apiObject['data'][d] //for short-handing 309 delete ApiMainObject['data'][d]['meta']; 310 delete ApiMainObject['data'][d]['optionType']; 311 delete ApiMainObject['data'][d]['strikePrice']; 312 313 } //for Loop ENDS HERE 314 315 316 delete ApiMainObject['marketStatus']; 317 318 var id = "stock_futures" 319 320 return [ ApiMainObject, timeStamp, id ] 321 322 } // extractStockFuture(apiObject) ENDS HERE 323 324 function extractMostActiveUnderlying(apiObject, iframeSrc) { // this function extract Most Active Underlying/Stocks/Indices data from apiObject and then store it into localStorage 325 326 var ApiMainObject = apiObject; 327 328 var tempObj = {}; 329 var timeStamp = apiObject['timestamp'].split(' ')[0] 330 331 var id = "most_active_underlying" 332 333 return [ ApiMainObject, timeStamp, id ] 334 335 } // extractMostActiveUnderlying(apiObject) ENDS HERE 336 337 function extractMostActiveFutureContracts(apiObject, iframeSrc) { // this function extract Most Active Future Contracts data from apiObject and then store it into localStorage 338 339 var ApiMainObject = apiObject; 340 341 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 342 343 var tempObj = {}; 344 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 345 346 347 for (var d = 0; d < apiObject['value']['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 348 //var alias = apiObject['data'][d] //for short-handing 349 delete ApiMainObject['value']['data'][d]['optionType']; 350 delete ApiMainObject['value']['data'][d]['strikePrice']; 351 352 } //for Loop ENDS HERE 353 354 for (var d = 0; d < apiObject['volume']['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 355 //var alias = apiObject['data'][d] //for short-handing 356 delete ApiMainObject['volume']['data'][d]['optionType']; 357 delete ApiMainObject['volume']['data'][d]['strikePrice']; 358 359 } //for Loop ENDS HERE 360 361 delete ApiMainObject['value']['timestamp'] 362 delete ApiMainObject['volume']['timestamp'] 363 364 365 366 var id = "most_active_future_contracts" 367 368 return [ ApiMainObject, timeStamp, id ] 369 370 } // extractMostActiveFutureContracts(apiObject) ENDS HERE 371 372 function extractStockOptions(apiObject, iframeSrc) { // this function extract Stock Options data from apiObject and then store it into localStorage 373 var ApiMainObject = apiObject; 374 375 var timeStamp = apiObject['timestamp'].split(' ')[0] 376 377 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 378 //var alias = apiObject['data'][d] //for short-handing 379 delete ApiMainObject['data'][d]['meta']; 380 } //for Loop ENDS HERE 381 382 383 delete ApiMainObject['marketStatus']; 384 385 var id = "stock_options"; 386 387 return [ ApiMainObject, timeStamp, id ] 388 389 390 } // extractMostActiveFutureContracts(apiObject) ENDS HERE 391 392 function extractSpurtsInOIByUnderlyings(apiObject, iframeSrc) { // this function extracts Spurts in Open Interest by Underlyings and then save it into IndexedDB 393 394 var ApiMainObject = apiObject; 395 396 var timeStamp = apiObject['timestamp'].split(' ')[0] 397 var dataArray = [] 398 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all Indices, but here we are justing fetching few indices performances out of all 399 var alias = apiObject['data'][d] //for short-handing 400 var Symbol = alias['symbol'] 401 if( Symbol != "-" ) 402 { 403 dataArray.push( alias ) 404 } 405 } //for Loop ENDS HERE 406 407 408 ApiMainObject["data"] = dataArray 409 var id = "spurts_in_open_interest_by_underlyings" 410 411 return [ ApiMainObject, timeStamp, id ] 412 413 } // extractSpurtsInOIByUnderlyings(apiObject ENDS HERE 414 415 function extractSpurtsInOIByContracts(apiObject, iframeSrc){ // this function extracts Spurts in Open Interest by Contracts and then save it into IndexedDB 416 417 var ApiMainObject = apiObject; 418 419 var tempObj = {}; 420 var timeStamp = apiObject['timestamp'].split(' ')[0] 421 422 for ( var dataArr of apiObject['data']) { 423 424 for ( var slide_rise_labels in dataArr ) 425 { 426 var alias = dataArr[ slide_rise_labels ] 427 tempObj[ slide_rise_labels ] = alias 428 } 429 } 430 431 432 ApiMainObject['data'] = tempObj 433 434 delete ApiMainObject['currTradingDate']; 435 delete ApiMainObject['prevTradingDate']; 436 437 var id = "spurts_in_open_interest_by_contracts" 438 439 return [ ApiMainObject, timeStamp, id ] 440 } // extractSpurtsInOIByContracts(apiObject) function ENDS HERE 441 442 function extractMostActiveOptionContracts(apiObject, iframeSrc) { // this function extract Most Active Option Contracts data from apiObject and then store it into localStorage 443 444 var ApiMainObject = apiObject; 445 446 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 447 448 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 449 450 delete ApiMainObject['value']['timestamp'] 451 delete ApiMainObject['volume']['timestamp'] 452 453 454 var id = "most_active_option_contracts" 455 456 return [ ApiMainObject, timeStamp, id ] 457 458 459 } // extractMostActiveOptionContracts(apiObject) ENDS HERE 460 461 function extractMostActiveContracts(apiObject, iframeSrc) { // this function extract Most Active Contracts data from apiObject and then store it into localStorage 462 463 var ApiMainObject = apiObject; 464 465 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 466 467 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 468 469 delete ApiMainObject['value']['timestamp'] 470 delete ApiMainObject['volume']['timestamp'] 471 472 473 var id = "most_active_contracts" 474 475 return [ ApiMainObject, timeStamp, id ] 476 477 } // extractMostActiveContracts(apiObject) ENDS HERE 478 479 function extractMostActiveCalls(apiObject, iframeSrc) { // this function extract Most Active Contracts data from apiObject and then store it into localStorage 480 481 var ApiMainObject = apiObject; 482 483 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 484 485 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 486 487 delete ApiMainObject['value']['timestamp'] 488 delete ApiMainObject['volume']['timestamp'] 489 490 491 var id = "most_active_calls" 492 493 return [ ApiMainObject, timeStamp, id ] 494 495 } // extractMostActiveCalls(apiObject) ENDS HERE 496 497 function extractMostActivePuts(apiObject, iframeSrc) { // this function extract Most Active Contracts data from apiObject and then store it into localStorage 498 499 var ApiMainObject = apiObject; 500 501 ApiMainObject ["timeStamp"] = apiObject['volume']['timestamp'] 502 503 var timeStamp = apiObject['volume']['timestamp'].split(' ')[0] 504 505 delete ApiMainObject['value']['timestamp'] 506 delete ApiMainObject['volume']['timestamp'] 507 508 509 var id = "most_active_puts" 510 511 return [ ApiMainObject, timeStamp, id ] 512 513 } // extractMostActivePuts(apiObject) ENDS HERE 514 515 516 function extractSecuritiesInFnO( apiObject, iframeSrc ) { // this function extract FnO's Securities and out of which it just pick only two stocks (AARTIIND, MOTHERSON) and add these two stocks in nifty_total_market's last entry 517 518 var ApiMainObject = apiObject; 519 520 var timeStamp = apiObject['timestamp'].split(' ')[0] 521 522 ApiMainObject['advances']=Number( apiObject['advance']['advances'] ) 523 ApiMainObject['declines']=Number( apiObject['advance']['declines'] ) 524 ApiMainObject['unchanged']=Number( apiObject['advance']['unchanged'] ) 525 526 var dataObj = {}; 527 528 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all FnO stocks 529 var alias = apiObject['data'][d] //for short-handing 530 var Symbol = alias['symbol'] 531 532 alias['dayHigh'] = Number( alias['dayHigh'] ) 533 alias['dayLow'] = Number( alias['dayLow'] ) 534 alias['lastPrice'] = Number( alias['lastPrice'] ) 535 alias['open'] = Number( alias['open'] ) 536 alias['previousClose'] = Number( alias['previousClose'] ) 537 538 539 delete alias['chart30dPath'] 540 delete alias['chart365dPath'] 541 delete alias['chartTodayPath'] 542 delete alias['date30dAgo'] 543 delete alias['date365dAgo'] 544 delete alias['identifier'] 545 delete alias['lastUpdateTime'] 546 delete alias['meta'] 547 delete alias['nearWKH'] 548 delete alias['nearWKL'] 549 delete alias['perChange30d'] 550 delete alias['perChange365d'] 551 delete alias['series'] 552 delete alias['symbol'] 553 delete alias['yearHigh'] 554 delete alias['yearLow'] 555 556 557 dataObj [ Symbol ] = alias 558 559 } //for Loop ENDS HERE 560 561 ApiMainObject['data'] = dataObj 562 563 delete ApiMainObject['date30dAgo'] 564 delete ApiMainObject['date365dAgo'] 565 delete ApiMainObject['marketStatus'] 566 delete ApiMainObject['metadata'] 567 delete ApiMainObject['name'] 568 delete ApiMainObject['advance'] 569 570 //var id ='nifty_total_market' 571 var id ='equity_market' 572 573 return [ ApiMainObject, timeStamp, id ] 574 } // extractSecuritiesInFnO(apiObject) ENDS HERE 575 576 function extractNiftyTotalMarket(apiObject, iframeSrc) { // this function extract Nifty Total Market Sectors data from apiObject and then store it into localStorage 577 578 579 var ApiMainObject = apiObject; 580 581 var timeStamp = apiObject['timestamp'].split(' ')[0] 582 583 ApiMainObject['advances']=Number( apiObject['advance']['advances'] ) 584 ApiMainObject['declines']=Number( apiObject['advance']['declines'] ) 585 ApiMainObject['unchanged']=Number( apiObject['advance']['unchanged'] ) 586 587 var dataObj = {}; 588 589 for (var d = 0; d < apiObject['data'].length; d++) { // loop for accessing all FnO stocks 590 var alias = apiObject['data'][d] //for short-handing 591 var Symbol = alias['symbol'] 592 593 alias['dayHigh'] = Number( alias['dayHigh'] ) 594 alias['dayLow'] = Number( alias['dayLow'] ) 595 alias['lastPrice'] = Number( alias['lastPrice'] ) 596 alias['open'] = Number( alias['open'] ) 597 alias['previousClose'] = Number( alias['previousClose'] ) 598 599 600 delete alias['chart30dPath'] 601 delete alias['chart365dPath'] 602 delete alias['chartTodayPath'] 603 delete alias['date30dAgo'] 604 delete alias['date365dAgo'] 605 delete alias['identifier'] 606 delete alias['lastUpdateTime'] 607 delete alias['meta'] 608 delete alias['nearWKH'] 609 delete alias['nearWKL'] 610 delete alias['perChange30d'] 611 delete alias['perChange365d'] 612 delete alias['priority'] 613 delete alias['series'] 614 delete alias['symbol'] 615 delete alias['yearHigh'] 616 delete alias['yearLow'] 617 618 619 dataObj [ Symbol ] = alias 620 621 } //for Loop ENDS HERE 622 623 ApiMainObject['data'] = dataObj 624 625 delete ApiMainObject['date30dAgo'] 626 delete ApiMainObject['date365dAgo'] 627 delete ApiMainObject['marketStatus'] 628 delete ApiMainObject['metadata'] 629 delete ApiMainObject['name'] 630 delete ApiMainObject['advance'] 631 632 //var id ='nifty_total_market' 633 var id ='equity_market' 634 635 return [ ApiMainObject, timeStamp, id ] 636 637 638 } // extractNiftyTotalMarket(apiObject) ENDS HERE 639 640 641 642 function extractOptionChainData(optionChainObject, iframeSrc) { 643 //this function will extract specific Data from optionChainObject. this object may be of any Index or Equity. 644 645 var optionChainDataObject = {}; 646 var returnedDataArray; 647 returnedDataArray = extractOptionChainDataByExpiry(optionChainObject) // this function stores option chain data by current expiry 648 optionChainDataObject[ returnedDataArray[1] ] = returnedDataArray[0] 649 //if (Date.parse(new Date().toISOString().slice(0, 10).replace(/-/g, '/')) == Date.parse(optionChainObject['records']['expiryDates'][0])) // if current date is equals to exipryDate then also store next expiry Data 650 { 651 var nextExpiryFilteredDataObject = { 652 "filtered": {}, 653 "records": {} 654 } 655 var nextExpiryFilteredDataArrays = [] 656 var nextExpirtDate = optionChainObject['records']['expiryDates'][1] 657 658 var CEtotOI = 0, CEtotVol = 0; 659 var PEtotOI = 0, PEtotVol = 0; 660 for (var d in optionChainObject['records']['data']) { 661 var recordData = optionChainObject['records']['data'][d] 662 if (recordData['expiryDate'] == nextExpirtDate) { 663 nextExpiryFilteredDataArrays.push(recordData) 664 if (recordData['CE'] != undefined) { 665 CEtotOI += recordData['CE']['openInterest'] 666 CEtotVol += recordData['CE']['totalTradedVolume'] 667 } 668 669 if (recordData['PE'] != undefined) { 670 PEtotOI += recordData['PE']['openInterest'] 671 PEtotVol += recordData['PE']['totalTradedVolume'] 672 } 673 674 } 675 676 } 677 nextExpiryFilteredDataObject["filtered"]["data"] = nextExpiryFilteredDataArrays 678 nextExpiryFilteredDataObject["filtered"]["CE"] = { "totOI": CEtotOI, "totVol": CEtotVol } 679 nextExpiryFilteredDataObject["filtered"]["PE"] = { "totOI": PEtotOI, "totVol": PEtotVol } 680 nextExpiryFilteredDataObject["records"]["timestamp"] = optionChainObject['records']['timestamp'] 681 682 returnedDataArray = extractOptionChainDataByExpiry(nextExpiryFilteredDataObject) // here this function is called to stores option chain data for next expiry 683 optionChainDataObject[ returnedDataArray[1] ] = returnedDataArray[0] 684 685 } //if (Date.parse(new Date().toISOString().slice(0, 10).replace(/-/g, '/')) == Date.parse(apiObject['records']['expiryDates'][0])) ENDS HERE 686 optionChainDataObject[ "timestamp" ] = returnedDataArray[2] 687 return [ optionChainDataObject, returnedDataArray[2], returnedDataArray[3] ] 688 689 } //extractOptionChainData(optionChainObject) Function ENDS HERE 690 691 function extractOptionChainDataByExpiry(optionChainObject) { 692 //this function will extract specific Data from optionChainObject. this object may be of any Index or Equity. 693 // 694 //console.log(optionChainObject["filtered"]["data"][0]['CE']) 695 //await getData("currentDay") 696 //await sleep(1500) 697 var highest_PUT_OI_Change = "0,0", highest_Call_OI_Change = "0,0", highest_PUT_OI = "0,0", highest_Call_OI = "0,0"; 698 699 var ApiMainObject = {}; 700 //ApiMainObject = JSON.parse(localStorage.getItem("NSE_APIs_Data")); 701 //ApiMainObject = JSON.parse(returnedIndexedDBData); 702 703 var totalOICEChange = 0, totalOIPEChange = 0; //these variables are for Addition intraday change in OI of all strike prices for CE, PE 704 var totalCE = optionChainObject["filtered"]["CE"]["totOI"] 705 var totalCEVol = optionChainObject["filtered"]["CE"]["totVol"] 706 707 var totalPE = optionChainObject["filtered"]["PE"]["totOI"] 708 var totalPEVol = optionChainObject["filtered"]["PE"]["totVol"] 709 710 var strikePriceObject, Symbol, expiryDate, timeStamp, strikePrice, spotPrice; 711 712 //Symbol = optionChainObject["filtered"]["data"][0]['CE']['underlying'] //get index or stock name from 1st strike price's data 713