This project is a REST API that scrapes historical exchange data from Yahoo Finance for specified currency pairs and periods, and stores it in an in-memory SQLite database. The data is periodically updated using a CRON job.
- Scrape historical exchange data from Yahoo Finance.
- Store scraped data in an SQLite database.
- Periodically update data using CRON jobs.
- REST API endpoints to query the stored data.
- Swagger documentation for API endpoints.
- Custom Logger System: Log messages from any location within the application and read logs directly from the CLI.
- Node.js
- npm (Node Package Manager)
- Clone the repository:
git clone https://github.com/starvader13/Forex-Historical-Data-REST-API.git
cd Forex-Historical-Data-REST-API
- Install Dependecies:
npm install
npm run setup
- Start Server:
npm run build
npm start
- The server will start running on
http://localhost:3000
.
This project includes a custom logging system that allows you to log messages from any location within the application. The logging system provides an easy way to track the status of various operations and debug issues.
To log a message, use the logger
function. Here's an example of how to setup a logger:
logger({
status: false,
origin: "database/insertDatabase",
logMessage: `Failed To Finalize Statement. Error: ${err.message}`,
timestamp: new Date().toISOString()
});
You can read and print the logs directly to the CLI by running the following command:
npm run log
Scrape historical exchange data and store it in the database.
Query Parameters:
from
(string, required): The base currency code (e.g., GBP, AED).to
(string, required): The target currency code (e.g., INR).period
(string, required): The timeframe for the historical data (e.g., 1W, 1M, 3M, 6M, 1Y).
Example URL: http://localhost:3000/api/forex-data?from=GBP&to=INR&period=1W
Responses:
200 OK
: Data scraped and stored successfully.400 Bad Request
: Invalid input parameters.500 Internal Server Error
: Failed to scrape data.
The application also utilizes CRON jobs to periodically update the data:
-
Daily Job:
- Updates data for the last week (
1W
period). - Runs every day at IST 02:20 PM.
- Updates data for the last week (
-
Weekly Job:
- Updates data for the last month (
1M
period). - Runs every Saturday at IST 02:20 PM
- Updates data for the last month (
-
Monthly Job:
- Updates data for the last 3 months (
3M
), 6 months (6M
), and 9 months (9M
). - Runs every month on 1st at IST 02:20 PM
- Updates data for the last 3 months (
-
Yearly Job:
- Updates data for the last year (
1Y
). - Runs on January 1st at IST 02:20 PM
- Updates data for the last year (
Swagger documentation is available at http://localhost:3000/api/docs
.
The SQLite database is configured in src/config/db.ts
.
The CRON jobs are configured in src/cronjob
.
This project is licensed under the MIT License.