stocktrader / README.md
Benjamin Consolvo
README
f3d0040
|
raw
history blame
4.41 kB
metadata
title: Stock Trader
emoji: πŸ“š
colorFrom: yellow
colorTo: purple
sdk: streamlit
sdk_version: 1.42.2
app_file: app.py
pinned: false
license: apache-2.0
short_description: Stock trading application

Stock Trader Application

Overview

Stock Trader is an interactive web application built with Streamlit that allows you to monitor stock market data, execute trades using a paper trading account through Alpaca, analyze market sentiment, and visualize stock performance. The application combines real-time market data, news sentiment analysis, and automated trading capabilities in an easy-to-use interface.

Features

  • Real-time Stock Data: Track current prices and market status
  • Manual Trading: Buy and sell stocks with customizable quantities
  • Sentiment Analysis: Analyze news sentiment for stocks using multiple sources
  • Automated Trading: Background process trades stocks based on sentiment analysis
  • Portfolio Visualization: View your holdings and portfolio value in real-time
  • Market Insights: Monitor top volume stocks with interactive charts

Installation

Prerequisites

  • Python 3.8 or higher
  • UV package manager (for dependency management)
  • API keys for:
    • Alpaca Trading API
    • News API
    • Alpha Vantage API

Setup Instructions

  1. Clone the repository
git clone https://github.com/opea-project/Enterprise-Inference/
cd examples/stocktrader
  1. Initialize the virtual environment

    uv init
    
  2. Install dependencies

    uv add -r requirements.txt
    
  3. Activate the virtual environment

    source .venv/bin/activate
    
  4. Configure your API keys in .streamlit/secrets.toml. For this application, you will need:

  • Alpaca Trading API: Sign up at Alpaca to get your API key and secret key. This app uses paper trading, so make sure to get paper trading credentials.

  • News API: Register at News API to get a free API key for accessing news articles.

  • Alpha Vantage: Get a free API key from Alpha Vantage for stock market data.

The .streamlit/secrets.toml should have the following structure:

ALPACA_API_KEY = "your_alpaca_api_key"
ALPACA_SECRET_KEY = "your_alpaca_secret_key"
NEWS_API_KEY = "your_news_api_key"
ALPHA_VANTAGE_API_KEY = "your_alpha_vantage_api_key"
  1. Launch the application
    streamlit run app.py
    

Using the Application

Manual Trading

  1. Enter a Stock Symbol: Type a valid stock ticker symbol (e.g., AAPL, MSFT) in the sidebar.

  2. Check Sentiment: Click the "Check Sentiment" button to analyze current news sentiment for the selected stock.

  3. Trade Execution:

    • Choose between "Enter Quantity" or "Enter Amount"
    • Specify the quantity of shares or dollar amount
    • Select "Buy" or "Sell" action
    • Click "Execute" to place your order. If you submit outside of market hours, it will only execute when the market next opens.
  4. Portfolio Information: View your current cash balance, buying power, equity, and portfolio value in the sidebar.

Stock Charts

The main area displays charts for top volume stocks, showing historical price movements since 2023. You can:

  • Zoom in/out of charts
  • Pan across time periods
  • Hover over data points for precise values

Automated Trading

The application includes an automated trading feature that runs in the background:

  1. Analyzes sentiment for top volume stocks
  2. Executes buy orders for stocks with positive sentiment (if there is sufficient buying power)
  3. Executes sell orders for stocks with negative sentiment (if a position is held)
  4. Holds positions for stocks with neutral sentiment

Troubleshooting

Common Issues

  • API Rate Limits: If charts or data fail to load, you may have exceeded API rate limits. Wait a few minutes and try again.
  • Invalid Stock Symbols: Ensure you're entering valid ticker symbols when trading.
  • Market Hours: Some features may behave differently when markets are closed.

API Limitations

  • News API: Limited to 100 requests per day on the free tier
  • Alpha Vantage: Limited to 5 API requests per minute and 500 requests per day on the free tier

License

This project is licensed under the Apache 2.0 License.