Skip to content
/ RP4B Public

Strawberry Trading: Paper trading infrastructure developed in C++ to automatically run on the Raspberry PI

License

Notifications You must be signed in to change notification settings

cteufel13/RP4B

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Strawberry Trading

A C++ options trading platform designed for paper trading and strategy development. This modular system provides real-time data processing, options chain analysis, and automated trading capabilities through the Alpaca API.

πŸ—οΈ Architecture

The project is organized into several modular components:

strawberry-trading/
β”œβ”€β”€ api/              # HTTP client and API integration
β”œβ”€β”€ apps/            # Applications (paper_trader)
β”œβ”€β”€ core/            # Core trading logic and data structures
β”œβ”€β”€ logging/         # Thread-safe logging system
β”œβ”€β”€ scheduler/       # Task scheduling and timing
└── strategies/      # Trading strategies implementation

Components

  • API Module: HTTP client for Alpaca API integration with support for options data, market data, and order management
  • Core Module: Options chain processing, Greeks calculations, and fundamental trading data structures
  • Logging Module: Thread-safe singleton logger with file output and multiple log levels
  • Scheduler Module: Task scheduling and timing utilities for trading operations
  • Strategies Module: Trading strategy implementations and backtesting framework

πŸ”§ Dependencies

Required

  • CMake 4.0.3+
  • C++20 compatible compiler
  • libcurl - HTTP client library
  • nlohmann/json 3.12.0+ - JSON parsing and serialization

Installation (Ubuntu/Debian)

sudo apt update
sudo apt install cmake build-essential libcurl4-openssl-dev

Installation (macOS)

brew install cmake curl nlohmann-json

πŸš€ Building

Clone and Build

git clone <repository-url>
cd strawberry-trading
mkdir build && cd build
cmake ..
make -j$(nproc)

Build Output

Executables are generated in build/bin/:

  • paper_trader - Main paper trading application

πŸ“Š Features

Options Trading

  • Real-time options chain processing
  • Greeks calculations (Delta, Gamma, Vega, Theta, Rho)
  • Implied volatility analysis
  • Strike price and expiration filtering

Market Data

  • Real-time and historical stock/options bars
  • Latest quote data
  • Configurable timeframes
  • Market data snapshots

Order Management

  • Market and limit orders
  • Multiple order types (stop, stop-limit, trailing-stop)
  • Time-in-force options (DAY, GTC, IOC, FOK)
  • Order status tracking

Risk Management

  • Portfolio position tracking
  • Real-time P&L calculations
  • Risk metric monitoring

πŸ”‘ Configuration

API Keys

Set your Alpaca API credentials as environment variables (.zshrc, .bashrc):

export ALPACA_API_KEY="your_api_key"
export ALPACA_SECRET_KEY="your_secret_key"

Logging

Configure logging in your application:

#include <logger_alias.hpp>

int main() {
    logger.set_log_file("trading.log");
    logger.info("Starting trading application");
    // Your trading logic here
}

πŸ“ˆ Usage Example

Basic Options Chain Analysis

#include <common/optionchain.hpp>
#include <logger_alias.hpp>

// Process options chain data from Alpaca
std::string chainData = api.getOptionChain("AAPL");
OptionChain chain(chainData);

// Extract Greeks
auto deltas = chain.get_deltas();
auto gammas = chain.get_gammas();

// Find specific option
Date expiry = Date::from_string("2024-01-19");
Option option = chain.find_Option("AAPL", expiry, 'C', 150.0);

logger.info("Found option: " + option.name);

Paper Trading Application

cd build/bin
./paper_trader

πŸ§ͺ Development

Project Structure

  • Headers: Located in include/ directories within each module
  • Source: Located in src/ directories within each module
  • CMake: Each module has its own CMakeLists.txt

Adding New Strategies

  1. Create strategy class in strategies/src/
  2. Add corresponding header in strategies/include/
  3. Implement required strategy interface methods
  4. Register strategy in main application

Testing

Build and run the paper trader application to test functionality:

make paper_trader
./bin/paper_trader

πŸ“‹ API Coverage

Market Data

  • Stock bars (historical/real-time)
  • Option bars (historical/real-time)
  • Latest quotes
  • Option chain snapshots
  • Greeks and implied volatility

Trading

  • Order placement (market/limit)
  • Order status tracking
  • Portfolio positions
  • Multi-leg option strategies
  • Bracket orders

Account

  • Account information
  • Balance tracking
  • Trade history

πŸ”’ Security

  • API keys should never be committed to version control
  • Use environment variables or secure configuration files
  • Enable paper trading mode for development and testing

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For questions and support:

  • Open an issue on GitHub
  • Check the documentation in the code comments
  • Review the example applications in apps/

About

Strawberry Trading: Paper trading infrastructure developed in C++ to automatically run on the Raspberry PI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published