Skip to content

marwaaann/Fintech-Data-API-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fintech-Data-API

This project is a daily pipeline that:

  • Fetches transactions from Plaid,
  • Stores them in a PostgreSQL database,
  • Aggregates daily financial data,
  • Sends the data to a Gemini LLM for analysis,
  • Stores the LLM’s recommendations.

Function Explanations

1. get_db_connection()

Connects to the PostgreSQL database using the DATABASE_URL environment variable.

2. get_or_create_access_token()

Retrieves a Plaid access token from the database or creates a new one (sandbox only) and stores it.

3. fetch_plaid_transactions(access_token, cursor=None)

Fetches new, modified, and removed transactions from Plaid using the access token and an optional cursor for incremental sync.

4. insert_transactions_to_db(transactions, item_id)

Inserts new transactions into the plaid_transactions table, skipping duplicates.

5. get_last_cursor_from_db(item_id)

Retrieves the last used Plaid sync cursor for incremental transaction fetching.

6. update_last_cursor_in_db(item_id, cursor)

Updates the last used Plaid sync cursor in the database.

7. get_daily_financial_summary_for_llm(report_date)

Aggregates daily transaction data (income, spending, top categories, etc.) for a given date, formatted for LLM input.

8. get_llm_insights(data_for_llm, report_date)

Sends the aggregated data to the Gemini LLM and parses its JSON response for summary and recommendations.

9. store_llm_recommendations(report_date, summary, rec1, rec2, rec3, llm_raw_response)

Stores the LLM’s summary and recommendations in the daily_recommendations table.

10. run_pipeline()

Orchestrates the entire process: fetches transactions, updates the database, aggregates data, gets LLM insights, and stores results.


How to Run

1. Prerequisites

  • Python 3.8+
  • PostgreSQL database
  • Plaid developer account (for API keys)
  • Google Gemini API key

2. Install Dependencies

pip install -r requirements.txt

3. Set Up Environment Variables

Create a .env file in the project root with:

PLAID_CLIENT_ID=your_plaid_client_id
PLAID_SECRET=your_plaid_secret
PLAID_ENV=sandbox
DATABASE_URL=postgresql://user:password@host:port/dbname
GEMINI_API_KEY=your_gemini_api_key
LLM_MODEL=gemini-1.5-pro-latest

4. Set Up the Database

Run the schema SQL to create tables:

psql $DATABASE_URL -f schema.sql

5. Run the Pipeline

python main.py

Notes

  • The pipeline is designed for daily runs (e.g., via cron or a scheduled job).
  • Only sandbox Plaid environment is supported for token creation in this demo.
  • LLM recommendations are stored for each day in the database.

---# Fintech-Data-API-

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages