Skip to content

amgno/financebro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FinanceBro - Stock Analysis & Portfolio Bot

A Telegram bot built on Cloudflare Workers for automated financial analysis and portfolio management. Uses artificial intelligence (Anthropic Claude) to generate investment reports and interpret trading commands, integrating real-time market data from Financial Modeling Prep (FMP).

Architecture

The project is developed in Node.js and deployed on the Cloudflare ecosystem:

  • Cloudflare Workers: Serverless handling of Telegram webhook requests.
  • Durable Objects: Persistent state management (SQLite), background queues (Alarms), and user data consistency.
  • External Integrations:
    • Telegram Bot API: Main user interface.
    • Anthropic API (Claude 3.5 Sonnet): Financial analysis engine and natural language parsing.
    • Financial Modeling Prep (FMP) API: Data source for real-time quotes, price history, and company profiles.

Features

1. AI Financial Analysis

The /analyze [TICKER] command initiates a multi-step analysis process:

  1. The Worker delegates the task to the Durable Object via the Alarm system to handle long-running executions.
  2. The AI collects market data (price, changes, market cap, P/E) and historical data (30-day OHLC) via Tool Use.
  3. A structured report is generated including:
    • Fundamental analysis (Business model, financial health).
    • Technical analysis (Trend, support/resistance levels).
    • Weighted score (Technical 35%, Fundamentals 30%, Sector 20%, Sentiment 15%).
    • Operational recommendation (BUY/PASS/WATCHLIST) with execution strategy and risk management.

2. Portfolio Management and Trading

The system tracks positions and calculates P&L in real-time.

  • Order Entry: Supports structured commands (/buy AAPL 150 10) and natural language (I bought 10 Apple shares at 150 dollars). The AI performs parsing if pattern matching fails.
  • Portfolio Tracker: The /portfolio command returns a table with open positions, calculating profit/loss based on current market prices retrieved from FMP.
  • Budgeting: The /setbudget command sets available capital, influencing the AI's position sizing suggestions.

3. Security and Rate Limiting

  • Authentication: Optional support for access password (BOT_PASSWORD) to restrict bot usage.
  • Rate Limiting: SQLite-based system within the Durable Object to limit daily AI analyses per user.

Configuration

The project requires the following environment variables (configurable in wrangler.toml or Cloudflare dashboard):

Variable Description
TELEGRAM_BOT_TOKEN Token obtained from @BotFather
ANTHROPIC_API_KEY API key for accessing Claude models
FMP_API_KEY Financial Modeling Prep API key
BOT_PASSWORD (Optional) Password to protect bot access

Development and Deployment

Prerequisites

  • Node.js
  • Cloudflare account

Install Dependencies

npm install

Deploy

Deployment to Cloudflare Workers is done via Wrangler:

npx wrangler deploy

Code Structure

  • src/index.js: Main router and webhook handling.
  • src/user-storage.js: Durable Object implementation. Manages SQLite, background queues, and persistent business logic.
  • src/ai.js: Interface with Anthropic API. Handles prompt engineering, response streaming, and tool execution.
  • src/fmp.js: HTTP client for Financial Modeling Prep APIs.
  • src/telegram.js: Utilities for message formatting and Telegram API calls.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published