How steveman1123/multistonk works
Project Type and Purpose
• The project is a full-stack automated stock trading program that uses multiple algorithms/strategies.
• It is designed to interact with the Alpaca API for trading actions. It processes configuration files to set up trading parameters and uses multiple algorithm modules (located in ./algos) as well as specialized utilities for Alpaca and Nasdaq API interactions.
File Structure
• Key files and directories:
• The top-level Python scripts (e.g., multistonk.py, dryrun.py) contain the main running loops and support functions.
• The ./algos directory holds individual algorithm modules (each implementing a set of required functions such as init, getList, goodSells, sellDn, sellUp, and sellUpDn).
• The ./configs directory stores user-modifiable settings that drive the execution and behavior of the algorithms and the trading process.
• The modules (alpacafxns.py and ndaqfxns.py) encapsulate API-specific functions, making clear separations between general stock data processing and API-dependent operations.
• Other components include stockStuff (holding API key files and historical data) and miscellaneous testing or debug scripts (e.g., debugTesting.py).
a. Main Components:
• Main Application Driver:
• multistonk.py: Orchestrates the trading program lifecycle (running until the portfolio value drops a certain percentage), reading config files, and calling respective algorithm modules.
• Algorithm Modules:
• Directory: ./algos. Each file represents a unique trading strategy. They must implement key functions to determine buying and selling decisions.
• Configuration Management:
• Directory: ./configs. Contains various config files (e.g., multi.config) which define user settings, triggering live or paper trading, algorithm-specific thresholds, etc.
• API Integration Layers:
• alpacafxns.py: Handles direct communication with Alpaca's markets API for executing trades.
• ndaqfxns.py: Responsible for functions that compute or request data from the Nasdaq API without requiring API keys.
• Stock Data and API Key Management:
• Directory: ./stockStuff holds API keys and historical trading data which the system uses to inform trading decisions.
• Utilities and Support Functions:
• Additional helper scripts (e.g., tradeData.py, getPos.py, otherfxns.py) are likely used for data handling, position tracking, and executing various helper tasks.
b. Relationships and Interactions:
• The Main Application (multistonk.py) drives the overall process, reading config files from ./configs, then sequentially or concurrently invoking different algorithm modules from ./algos.
• Each algorithm module uses its initialization and decision functions to interact with the main driver, suggesting to the driver which stocks to buy or sell.
• API function modules (alpacafxns.py and ndaqfxns.py) are called by the main application and/or algorithms to perform data retrieval and transaction execution.
• The stockStuff directory (after being relocated as instructed) provides essential data (e.g., API keys or historical stock data) needed by these API and trading modules.
• The program also includes dry-run testing utilities (e.g., dryrun.py, algoAnalysis/ scripts) to simulate trading scenarios without risk.
c. Architectural Patterns and Design Principles:
• Modularity: Each algorithm exists as its own module, making it straightforward to add, modify, or remove strategies.
• Separation of Concerns: Distinct modules deal with API integration (alpacafxns.py, ndaqfxns.py), configuration (configs/), and core trading logic (multistonk.py and related scripts).
• Extensibility: The architecture allows for new configuration files or new algorithms to be added without major refactoring.