# Phase 0. Get Archive Historical Data

## Introduction

This phase will download historical data in 5 min. intervals for each equity stored as a sub-directory with the name of the ticker symbol:
  
### main directory for repository is:  /var/www/html/lex-opt_repository/
   sub-directories are:

  #### \_curr-Equities/ (current equities) 
      - i.e., those that are common and/or open
      - the active equities each have a file in this sub-directory,
      - e.g. for the Apple equity: /var/www/html/lex-opt_repository/\_curr-Equities/AAPL.json
  
  #### \_watchList-Equities/ (equities of interest) 
      - each equity has a file in this sub-directory,
      - e.g. for the Apple equity: /var/www/html/lex-opt_repository/\_watchList-Equities/AAPL.json
  
  #### \_hist-Equities/ (historical data for equities)
      - each equity (in both the \_curr-Equities/ & the \_watchList-Equities/ directories) has a file in this sub-directory,
      - e.g. for the Apple equity: /var/www/html/lex-opt_repository/\_hist-Equities/AAPL.json
      - data stored is in 5-min intervals
      - values are: index: unixDateTime array: [high, low, price]

 #### \_movingAvr/
      - SMA will be calculated for each data download. 
      - caculations for exponential and Fibonacci to be done late
      - each equity (in both the \_curr-Equities/ & the \_watchList-Equities/ directories) has a file in this sub-directory,
      - e.g. for the Apple equity: /var/www/html/lex-opt_repository/\_movingAvr/AAPL.json

 #### files:
      - \_curr-Options  :=> file listing the open options
      - \_futureStrike-Dates :=> coming strike dates for options 
      - \_portfolios
      - \_watchList-Options   :=> options of immediate watching interest  


Before beginning on the next 2 steps check the index.html file in the /lex-opt_4.00/ for completeness, applicability and functionality

Next, check the file docReady.js in the directory /lex-opt_4.00/js/ -  it should execute phase_0 functions before anything else such as loading the DOM etc. as these functions load necessary data from external sites. 

Phase_0 consists of 2 functions:

1. A function that will cycle through the current equity names in the global array "var currEquities" (initialized in docReady.js)   
  
  - there are 3 input parameters: 
    a. equity ticker symbol array
        - create a loop to cycle through these ticker symbols
    b. the year to fetch the data
    c. the month to start (count down from this value to 1)

2. A function that will access the data from alphaVantage
  - function is named: alphaVantage() in the file alphaVantage.js in directory /lex-opt_4.00/js/
  - input attributes (from step 1. above)
    a. a ticker symbol, e.g. AAPL
    b. a year, e.g. 2025
    c.  a month, 5
      - ticker symbol
  - see existing function alphaVantage() in folder /var/www/html/lex-op_4.00/JS/alphaVantage.js and make suggestions for improvements
  - the data returned should be stored in the repository (see var repository decleared in function domReady() in file domReady.js)
  - the name of the file for storage will be the ticker symbol with the extension .json, e.g. APPL.json. ACN.json
  - the data should be appended to the existing json data in the file  






 