efraim-lima / financial-api-scraper

A simple API that get data from stocks and use it as data for requests and user interaction.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask API Application with Scraper Integration

Hey there! Welcome to this README, where I'll walk you through our Flask API application with scraper integration. It's designed not only provide stock data but allows you to "buy" stocks via API requests.

Main Libraries Used

Here are some of the main libraries I used in project:

  • bleach πŸ’§: Helps keep the SQL clean and free from any malicious injections, sanityzing it.
  • celery πŸ•’: Powers task queue, ensuring asynchronous task execution for better scalability.
  • flask 🏠: The web framework for build the API
  • logging πŸ› οΈ: Keeps track of user activities, generating alerts and info as needed.
  • polygon-api-client πŸ“Š: Provides access to financial data from Polygon.
  • redis πŸ’»: Used for cache management and messaging queue.
  • requests πŸ“Š: Used for fetching data from web (APIs and Pages).
  • requests_html πŸ“Š: Enables HTML parsing and web scraping for data extraction.
  • zenrows πŸ“Š: An incredible tool for bypass scraping problems.

Additional Libraries

I also used other helpful libraries like appdirs, beautifulsoup4, holidays, and numpy, among others.

Functionality πŸ› οΈ

Data Collection and Storage πŸ“Š

This tool collect stock data from APIs and store it in cache as JSON format. Ater this, the scraper correlates stock tickers and fetch additional data from external sources.

Stock Purchase πŸ’°

Users can easily make stock purchases through simple POST requests to /stock/<stock_symbol>. These purchases are then stored in an SQLite database for further processing.

curl -X POST -H "Content-Type: application/json" -d '{"amount": <integer>}' http://localhost:8000/stock/<stock_symbol>

After sending a POST request, you can access the database by following these steps:

  • First, get the Docker container ID from app-test_app in docker ps:
docker ps
  • Insert it into the command below to access the container shell:
docker exec -it <container_id> /bin/bash
  • Finally, retrieve the database:
sqlite3 app/db/purchases.db

select * from history

Stock Information Retrieval πŸ“ˆ

Users can retrieve stock information via GET requests to /stock/<stock_symbol>. The retrieved data is stored temporarily in a Redis cache and scraper get performance metrics, appending it to the ticker JSON response.

curl -X GET http://localhost:8000/stock/<stock_symbol>

Frontend Interface πŸ–₯️

I am currently working on a frontend interface (stocks.html) where users can access more information and select suggested stocks. All processes are integrated with API connections.

Deployment πŸš€

Deploying our application is easy! Just fire up Docker Compose with docker-compose up -d in the /root directory.

docker-compose up -d

Personally, I prefer running these commands:

docker-compose down

echo "y" | docker system prune -f && exit

docker-compose up --build

Security Measures πŸ”’

Security is my goal! My code includes input and output sanitization to prevent any potential code or SQL injection attacks. I'm also considering adding output escaping logic for additional protection.

Notes πŸ“

While the code don't performs admirably in CLI mode, I am actively working on developing a user-friendly frontend solution. Stay tuned for updates!

Feedback and Contributions πŸ™Œ

Your feedback and contribution mean too much for me! If you have any suggestions or want to contribute, don't hesitate to reach out to me (Efraim Lima). You can contact me via email at efraim.alima@gmail.com or connect on LinkedIn.

Thanks a lot for the opportunity!

About

A simple API that get data from stocks and use it as data for requests and user interaction.


Languages

Language:Python 92.9%Language:C 3.3%Language:Cython 2.8%Language:XSLT 0.4%Language:C++ 0.3%Language:Fortran 0.1%Language:JavaScript 0.0%Language:PowerShell 0.0%Language:Roff 0.0%Language:CSS 0.0%Language:Shell 0.0%Language:Forth 0.0%Language:Meson 0.0%Language:HTML 0.0%Language:Dockerfile 0.0%