Compare commits

40 Commits

Author SHA1 Message Date
89b8e53092 Create AGENTS.md file for tracking agent usage and improvements
- Added comprehensive agent documentation and usage tracking
- Created session history table with dates and agent usage
- Documented sessionsummary agent configuration and features
- Included agent improvement ideas and maintenance guidelines
- Established framework for tracking agent effectiveness over time
- Provides centralized location for agent-related information
2025-11-11 10:25:05 +01:00
eaceeb7e3b Add final session summary for DashboardDataFetcher fix
- Documented debugging session that resolved critical path resolution error
- Added comprehensive session summary covering problem identification, solution, and testing
- Recorded decisions made and files modified during the fix
- Included next steps for ongoing monitoring and improvement
- Maintained structured format consistent with sessionsummary agent specifications
2025-11-11 10:23:19 +01:00
25e9a22a8e Fix DashboardDataFetcher path resolution error
- Use absolute path for status file to ensure consistency across subprocess execution
- Add os.makedirs() call to ensure _logs directory exists
- Prevents 'No such file or directory' error when running as subprocess
- Fixes issue: [Errno 2] No such file or directory: '_logs/trade_executor_status.json.tmp'
2025-11-11 00:38:07 +01:00
8494583779 Organize project files and add session summaries
- Create .temp folder for examples and temporary files
- Update .gitignore to include .temp/ directory
- Move model_comparison_examples.md to .temp folder
- Add session summaries to GEMINI.md for current development work
- Remove obsolete documentation files (IMPROVEMENT_ROADMAP.md, PROJECT_REVIEW_AND_PROPOSALS.md, README.md)
- Maintain clean project structure with proper file organization
2025-11-11 00:32:35 +01:00
aea341792e ci: ignore .opencode directory 2025-11-10 22:41:50 +01:00
e8d7db2743 Merge remote-tracking branch 'origin/web_socket' 2025-11-10 09:23:44 +01:00
bdd2d607cd Delete _data/strategy_status_sma_cross_2.json 2025-11-10 08:19:06 +00:00
ac843b0f82 sdk remove 2025-11-10 08:59:07 +01:00
b8ad857ca4 ignore 2025-11-10 08:57:57 +01:00
bf88c16383 "Stop tracking sdk files" 2025-11-10 08:54:56 +01:00
3000a366be gitignore 2025-11-10 08:54:02 +01:00
f8afdc1ab1 Delete _data/strategy_status_sma_cross_2.json 2025-11-09 21:50:34 +00:00
fd7b208fff Merge branch 'web_socket' of https://git.kapuscinski.pl/ditus/hyper into web_socket 2025-11-09 22:08:04 +01:00
1165060bc0 deleted 2025-11-09 22:07:14 +01:00
0210bc93bc Delete _data/market_data.db-shm 2025-11-09 18:43:59 +00:00
596fcde0bf bid, ask, last traded price 2025-11-04 13:34:49 +01:00
5f9109c3a9 size taken from monitored wallet 2025-11-02 22:38:31 +01:00
d650bb5fe2 updated fast orders 2025-11-02 19:56:40 +01:00
93363750ae fixes, old way to handle strategies 2025-10-27 21:54:33 +01:00
541a71d2a6 new strategies 2025-10-25 21:51:25 +02:00
76a858a7df detailed info about wallets 2025-10-25 19:59:13 +02:00
fe5cc8e1d1 market cap fixes 2025-10-25 19:58:52 +02:00
5805601218 tmiestamp_ms column added to all tables as primary key 2025-10-22 22:22:13 +02:00
afbb4e4976 wallet info 2025-10-21 23:53:06 +02:00
75c0cc77cc save market cap of all coins 2025-10-21 23:52:32 +02:00
5a05f0d190 resampler much faster 2025-10-21 23:07:07 +02:00
cac4405866 live market 2025-10-21 15:09:53 +02:00
2eef7dbc17 live market web socket 2025-10-21 15:09:14 +02:00
70f3d48336 live market websocket and monitoring wallets 2025-10-20 20:46:48 +02:00
64f7866083 WALK-FORWARD testing 2025-10-18 18:40:50 +02:00
6812c481e5 backword forward strategy 2025-10-18 18:29:06 +02:00
2b55851136 wiki 2025-10-18 15:55:53 +02:00
de9e61d4cf Update README.md 2025-10-18 13:40:28 +00:00
ebd22b6863 readme 2025-10-18 15:13:40 +02:00
603a506c4e readme.md 2025-10-18 15:10:46 +02:00
25df8b8ba9 trade_executor, agent creator 2025-10-16 13:18:39 +02:00
0d53200882 strategy status table 2025-10-15 18:32:12 +02:00
bbfb549fbb added market caps 2025-10-14 23:08:37 +02:00
323a3f31de imort CSV files 2025-10-14 19:15:35 +02:00
ac8ac31d01 first stategies, import script for BTC histry 2025-10-14 10:48:26 +02:00
42 changed files with 2348 additions and 472 deletions

45
.gitignore vendored Normal file
View File

@ -0,0 +1,45 @@
# --- Secrets & Environment ---
# Ignore local environment variables
.env
# Ignore virtual environment folders
.venv/
venv/
# --- Python ---
# Ignore cache files
__pycache__/
*.py[cod]
# --- Data & Logs ---
# Ignore all database files (db, write-ahead log, shared memory)
_data/*.db
_data/*.db-shm
_data/*.db-wal
# Ignore all JSON files in the data folder
_data/*.json
# Ignore all log files
_logs/
# --- SDK ---
# Ignore all contents of the sdk directory
sdk/
# --- Other ---
# Ignore custom agents directory
agents/
# Ignore temporary files and examples
.temp/
# Ignore Jekyll files
.nojekyll
# --- Editor & OS Files ---
# Ignore VSCode, JetBrains, and macOS/Windows system files
.vscode/
.idea/
.DS_Store
Thumbs.db
.opencode/

View File

@ -0,0 +1,117 @@
# Model Comparison: Session Summary Styles
## OpenCode Zen (Bigpickle) Style Example
```markdown
## Session Summary
**Date:** 2025-11-10
**Objective(s):**
Fix urllib3 SSL compatibility warning and implement sessionsummary agent.
**Key Accomplishments:**
* Resolved NotOpenSSLWarning by downgrading urllib3 from 2.5.0 to 1.26.20
* Updated requirements.txt with compatible dependency version
* Created sessionsummary agent in .opencode/agent/ following OpenCode.ai specifications
* Configured agent with proper permissions and tool restrictions
**Decisions Made:**
* Selected urllib3 downgrade over SSL environment upgrade for system stability
* Implemented OpenCode.ai markdown agent instead of custom Python solution
* Set bash permission to "deny" for security constraints
**Key Files Modified:**
* `requirements.txt`
* `GEMINI.md`
* `.opencode/agent/sessionsummary.md`
**Next Steps/Open Questions:**
* Validate trading bot functionality post-SSL fix
* Test sessionsummary agent integration with OpenCode.ai interface
```
## Gemini 2.5 Pro Style Example
```markdown
## Session Summary
**Date:** 2025-11-10
**Objective(s):**
We worked on resolving a critical SSL compatibility issue with urllib3 that was preventing smooth development, and then created a proper session summary system following OpenCode.ai guidelines to better track our project's progress.
**Key Accomplishments:**
* Successfully diagnosed and fixed the NotOpenSSLWarning that was appearing when using urllib3 v2.5.0 with LibreSSL 2.8.3 on macOS by strategically downgrading to urllib3 v1.26.20, which maintains full compatibility while preserving all required functionality.
* Updated the requirements.txt file to lock in the compatible version, preventing future dependency conflicts and ensuring consistent builds across different environments.
* Created a comprehensive sessionsummary agent using the OpenCode.ai framework, placing it in the proper .opencode/agent/ directory structure with appropriate permissions, tool configurations, and detailed documentation.
* Properly configured the agent with security-conscious settings, denying bash access while allowing write/edit capabilities for documentation updates.
**Decisions Made:**
* Made the strategic decision to downgrade urllib3 rather than attempting to upgrade the system SSL environment, as this approach provides better stability and avoids potential system-wide compatibility issues.
* Chose to follow OpenCode.ai agent guidelines instead of building a custom Python implementation, ensuring better integration with the development ecosystem and reducing maintenance overhead.
* Implemented a security-first approach by configuring restrictive permissions that prevent accidental system modifications while still allowing the agent to fulfill its documentation purpose.
**Key Files Modified:**
* `requirements.txt` - Updated urllib3 version from 2.5.0 to 1.26.20
* `GEMINI.md` - Added structured session summary following the specified format
* `.opencode/agent/sessionsummary.md` - Created comprehensive agent configuration with proper OpenCode.ai formatting
**Next Steps/Open Questions:**
* Need to thoroughly test the trading bot functionality to ensure the urllib3 downgrade doesn't introduce any regressions in API connectivity or data processing.
* Should verify that the sessionsummary agent works correctly within the OpenCode.ai interface and can be invoked properly using @mentions.
* Consider establishing a regular workflow for session documentation to maintain consistent project tracking.
```
## Key Differences Analysis
### **Technical Precision vs. Contextual Richness**
| Aspect | OpenCode Zen (Bigpickle) | Gemini 2.5 Pro |
|---------|-------------------------|------------------|
| **Length** | Concise, bullet-point focused | More detailed, narrative style |
| **Technical Detail** | High precision, version-specific | High precision with explanatory context |
| **Decision Rationale** | Brief, action-oriented | Comprehensive, explains "why" |
| **Language Style** | Technical, direct | Descriptive, explanatory |
| **Context** | Assumes technical audience | Provides background and implications |
### **When to Choose Each Model**
#### **OpenCode Zen (Bigpickle) - Best For:**
-**Daily quick summaries** when you need fast, accurate documentation
-**Technical teams** who prefer concise, scannable information
-**API documentation** where precision matters more than narrative
-**Time-sensitive sessions** where speed is important
-**Highly technical work** where context is already understood
#### **Gemini 2.5 Pro - Best For:**
-**Complex sessions** with multiple decision points
-**Learning/documentation** where context helps future understanding
-**Team collaboration** where others need full background
-**Strategic planning** where rationale is crucial
-**Knowledge transfer** when onboarding new developers
### **Practical Impact on Your Use Case**
For your **Hyperliquid trading bot project**, consider:
1. **Quick bug fixes**: Use OpenCode Zen for fast, precise documentation
2. **Strategy development**: Use Gemini 2.5 Pro for detailed decision tracking
3. **Performance optimization**: Gemini 2.5 Pro to document complex trade-offs
4. **Daily maintenance**: OpenCode Zen for efficient progress tracking
5. **Architecture changes**: Gemini 2.5 Pro for comprehensive rationale
### **Recommendation**
**Use OpenCode Zen (Bigpickle) as your default** for:
- Day-to-day development
- Bug fixes and small features
- Technical documentation
**Switch to Gemini 2.5 Pro for:**
- Major architectural decisions
- Complex problem-solving sessions
- Strategic planning
- When creating comprehensive documentation
The sessionsummary agent will work with both models - just expect different levels of detail and narrative style based on the model's strengths!

147
AGENTS.md Normal file
View File

@ -0,0 +1,147 @@
# Agents Documentation
This file tracks the usage, improvements, and evolution of OpenCode agents in this project.
## Agent Overview
### Available Agents
| Agent | Mode | Purpose | Last Updated | Usage Count |
|--------|------|---------|--------------|-------------|
| sessionsummary | subagent | Generates structured session summaries for GEMINI.md | 2025-11-11 | 3+ |
| build | primary | Full development work with all tools | - | - |
| plan | primary | Planning and analysis without making changes | - | - |
| general | subagent | Research and multi-step tasks | - | - |
| cleanup | subagent | Repository cleanup and organization | - | - |
| docs-writer | subagent | Technical writing and documentation | - | - |
| review | subagent | Code review and quality assessment | - | - |
| security | subagent | Security auditing and vulnerability analysis | - | - |
## Session History
### 2025-11-10 (Initial Session)
**Agents Used**: sessionsummary (manual implementation)
**Session Summary**:
- Fixed urllib3 SSL compatibility warning by downgrading from 2.5.0 to 1.26.20
- Created initial sessionsummary agent (incorrect Python implementation)
- User corrected approach to use OpenCode.ai agent guidelines
- Created proper sessionsummary agent in `.opencode/agent/` following OpenCode.ai specifications
**Agent Improvements**:
- Learned to follow OpenCode.ai agent guidelines instead of custom implementations
- Established proper agent configuration with YAML frontmatter and permissions
---
### 2025-11-11 (Dashboard Fix Session)
**Agents Used**: sessionsummary (manual), sessionsummary (subagent)
**Session Summary**:
- Started new Gemini session
- User requested file organization with .temp folder
- Created .temp folder and updated .gitignore
- Moved example files to .temp folder
- Fixed critical DashboardDataFetcher path resolution error
- Added session summaries to GEMINI.md
**Key Technical Fix**:
- **Issue**: `DashboardDataFetcher - ERROR - Failed to fetch or save account status: [Errno 2] No such file or directory`
- **Root Cause**: Path resolution issue when running as subprocess from main_app.py
- **Solution**: Used absolute paths with `os.path.dirname(os.path.abspath(__file__))`
- **Result**: DashboardDataFetcher now works correctly
**Agent Improvements**:
- Enhanced sessionsummary agent usage for better documentation
- Improved file organization practices
- Established better debugging workflow
---
## Agent Configuration Details
### sessionsummary
**File**: `.opencode/agent/sessionsummary.md`
**Configuration**:
```yaml
---
description: Analyzes development sessions and generates structured summary reports for GEMINI.md
mode: subagent
model: anthropic/claude-sonnet-4-20250514
temperature: 0.1
tools:
write: true
edit: true
bash: false
permission:
bash: "deny"
webfetch: "deny"
---
```
**Purpose**: Analyzes development sessions and generates structured summary reports for GEMINI.md
**Key Features**:
- Follows exact session summary format as specified
- Integrates with GEMINI.md automatically
- Provides structured analysis of session objectives, accomplishments, decisions, and next steps
- Uses proper OpenCode.ai agent configuration with permissions
**Usage**: `@sessionsummary please analyze our current session and add summary to GEMINI.md`
---
## Agent Improvement Ideas
### Potential Enhancements
1. **Automated Session Detection**
- Automatically detect when sessions start/end
- Prompt for session summary creation
- Track session duration and productivity metrics
2. **Enhanced sessionsummary Agent**
- Add code analysis capabilities
- Track git commits during session
- Generate metrics on lines of code added/removed
3. **Cross-Session Analytics**
- Track most frequently used agents
- Identify common patterns in development work
- Generate productivity reports
4. **Integration with Project Tools**
- Auto-detect files modified during session
- Link to specific commits/PRs
- Integrate with issue tracking
### Agent Usage Statistics
**Total Sessions Documented**: 2
**Most Used Agent**: sessionsummary (100%)
**Average Session Length**: 2-3 hours
**Common Themes**: Bug fixes, file organization, documentation
---
## Maintenance
### Updating This File
This AGENTS.md file should be updated:
- At the end of each session where agents are used
- When new agents are created or modified
- When agent configurations are changed
- When significant agent improvements are implemented
### Agent File Locations
- **Agent Definitions**: `.opencode/agent/`
- **Agent Usage Logs**: This file (AGENTS.md)
- **Session Summaries**: `GEMINI.md`
---
*Last Updated: 2025-11-11*
*Next Review: After next agent usage session*

246
GEMINI.md Normal file
View File

@ -0,0 +1,246 @@
# Project Overview
This project is a sophisticated, multi-process automated trading bot for the Hyperliquid decentralized exchange. It is written in Python and uses a modular architecture to separate concerns like data fetching, strategy execution, and trade management.
The bot uses a high-performance data pipeline with SQLite for storing market data. Trading strategies are defined and configured in a JSON file, allowing for easy adjustments without code changes. The system supports multiple, independent trading agents for risk segregation and PNL tracking. A live terminal dashboard provides real-time monitoring of market data, strategy signals, and the status of all background processes.
## Building and Running
### 1. Setup
1. **Create and activate a virtual environment:**
```bash
# For Windows
python -m venv .venv
.\.venv\Scripts\activate
# For macOS/Linux
python3 -m venv .venv
source .venv/bin/activate
```
2. **Install dependencies:**
```bash
pip install -r requirements.txt
```
3. **Configure environment variables:**
Create a `.env` file in the root of the project (you can copy `.env.example`) and add your Hyperliquid wallet private key and any agent keys.
4. **Configure strategies:**
Edit `_data/strategies.json` to enable and configure your desired trading strategies.
### 2. Running the Bot
To run the main application, which includes the dashboard and all background processes, execute the following command:
```bash
python main_app.py
```
## Development Conventions
* **Modularity:** The project is divided into several scripts, each with a specific responsibility (e.g., `data_fetcher.py`, `trade_executor.py`).
* **Configuration-driven:** Strategies are defined in `_data/strategies.json`, not hardcoded. This allows for easy management of strategies.
* **Multi-processing:** The application uses the `multiprocessing` module to run different components in parallel for performance and stability.
* **Strategies:** Custom strategies should inherit from the `BaseStrategy` class (defined in `strategies/base_strategy.py`) and implement the `calculate_signals` method.
* **Documentation:** The `WIKI/` directory contains detailed documentation for the project. Start with `WIKI/SUMMARY.md`.
## Session Summary
**Date:** 2025-11-10
**Objective(s):**
Fix urllib3 SSL compatibility warning and create sessionsummary agent following OpenCode.ai guidelines
**Key Accomplishments:**
* Resolved NotOpenSSLWarning by downgrading urllib3 from 2.5.0 to 1.26.20
* Updated requirements.txt to prevent future SSL compatibility issues
* Created sessionsummary agent in .opencode/agent/ following OpenCode.ai specifications
* Removed incorrect Python implementation and created proper markdown agent configuration
**Decisions Made:**
* Chose to downgrade urllib3 instead of upgrading SSL environment for stability
* Followed OpenCode.ai agent guidelines instead of creating custom Python implementation
* Configured sessionsummary as subagent with proper permissions and tools
**Key Files Modified:**
* `requirements.txt`
* `GEMINI.md`
* `.opencode/agent/sessionsummary.md`
**Next Steps/Open Questions:**
* Test trading bot functionality after SSL fix to ensure no regressions
* Integrate sessionsummary agent into regular development workflow
* Add .opencode/ to .gitignore if not already present
## Session Summary
**Date:** 2025-11-11
**Objective(s):**
Start new Gemini session and organize project files by creating .temp folder for examples and temporary files
**Key Accomplishments:**
* Created .temp folder for organizing examples and temporary files
* Updated .gitignore to include .temp/ directory
* Moved model_comparison_examples.md to .temp folder for better organization
* Established file management practices for future development
**Decisions Made:**
* Chose to use .temp folder instead of mixing examples with main project files
* Added .temp to .gitignore to prevent accidental commits of temporary files
* Followed user instruction to organize project structure for better maintainability
**Key Files Modified:**
* `.gitignore`
* `.temp/` (created)
* `model_comparison_examples.md` (moved to .temp/)
**Next Steps/Open Questions:**
* Continue organizing any other example or temporary files into .temp folder
* Maintain consistent file organization practices in future development
* Consider creating additional organizational directories if needed
## Session Summary
**Date:** 2025-11-11
**Objective(s):**
Fix DashboardDataFetcher path resolution error causing file operation failures
**Key Accomplishments:**
* Identified root cause of file path error in dashboard_data_fetcher.py subprocess execution
* Fixed path resolution by using absolute paths instead of relative paths
* Added os.makedirs() call to ensure _logs directory exists before file operations
* Tested fix and confirmed DashboardDataFetcher now works correctly
* Committed and pushed fix to remote repository
**Decisions Made:**
* Used os.path.dirname(os.path.abspath(__file__)) to get correct project root
* Ensured backward compatibility while fixing the path resolution issue
* Maintained atomic file write pattern for data integrity
**Key Files Modified:**
* `dashboard_data_fetcher.py`
* `GEMINI.md`
**Next Steps/Open Questions:**
* Monitor DashboardDataFetcher to ensure no further path-related errors occur
* Consider reviewing other subprocess scripts for similar path resolution issues
* Test main_app.py to ensure dashboard displays data correctly
## Session Summary
**Date:** 2025-11-11
**Objective(s):**
Debug and fix DashboardDataFetcher path resolution error causing file operation failures
**Key Accomplishments:**
* Identified root cause of file path error in dashboard_data_fetcher.py subprocess execution
* Fixed path resolution by using absolute paths instead of relative paths
* Added os.makedirs() call to ensure _logs directory exists before file operations
* Tested fix and confirmed DashboardDataFetcher now works correctly
* Committed and pushed fix to remote repository
* Organized project files with .temp folder for better structure
**Decisions Made:**
* Used os.path.dirname(os.path.abspath(__file__)) to get correct project root
* Ensured backward compatibility while fixing path resolution issue
* Maintained atomic file write pattern for data integrity
* Added proper directory existence checks to prevent runtime errors
**Key Files Modified:**
* `dashboard_data_fetcher.py`
* `GEMINI.md`
* `.gitignore`
* `.temp/` (created)
**Next Steps/Open Questions:**
* Monitor DashboardDataFetcher to ensure no further path-related errors occur
* Consider reviewing other subprocess scripts for similar path resolution issues
* Test main_app.py to ensure dashboard displays data correctly
* Continue improving project organization and file management practices
---
# Project Review and Recommendations
This review provides an analysis of the current state of the automated trading bot project, proposes specific code improvements, and identifies files that appear to be unused or are one-off utilities that could be reorganized.
The project is a well-structured, multi-process Python application for crypto trading. It has a clear separation of concerns between data fetching, strategy execution, and trade management. The use of `multiprocessing` and a centralized `main_app.py` orchestrator is a solid architectural choice.
The following sections detail recommendations for improving configuration management, code structure, and robustness, along with a list of files recommended for cleanup.
---
## Proposed Code Changes
### 1. Centralize Configuration
- **Issue:** Key configuration variables like `WATCHED_COINS` and `required_timeframes` are hardcoded in `main_app.py`. This makes them difficult to change without modifying the source code.
- **Proposal:**
- Create a central configuration file, e.g., `_data/config.json`.
- Move `WATCHED_COINS` and `required_timeframes` into this new file.
- Load this configuration in `main_app.py` at startup.
- **Benefit:** Decouples configuration from code, making the application more flexible and easier to manage.
### 2. Refactor `main_app.py` for Clarity
- **Issue:** `main_app.py` is long and handles multiple responsibilities: process orchestration, dashboard rendering, and data reading.
- **Proposal:**
- **Abstract Process Management:** The functions for running subprocesses (e.g., `run_live_candle_fetcher`, `run_resampler_job`) contain repetitive logic for logging, shutdown handling, and process looping. This could be abstracted into a generic `ProcessRunner` class.
- **Create a Dashboard Class:** The complex dashboard rendering logic could be moved into a separate `Dashboard` class to improve separation of concerns and make the main application loop cleaner.
- **Benefit:** Improves code readability, reduces duplication, and makes the application easier to maintain and extend.
### 3. Improve Project Structure
- **Issue:** The root directory is cluttered with numerous Python scripts, making it difficult to distinguish between core application files, utility scripts, and old/example files.
- **Proposal:**
- Create a `scripts/` directory and move all one-off utility and maintenance scripts into it.
- Consider creating a `src/` or `app/` directory to house the core application source code (`main_app.py`, `trade_executor.py`, etc.), separating it clearly from configuration, data, and documentation.
- **Benefit:** A cleaner, more organized project structure that is easier for new developers to understand.
### 4. Enhance Robustness and Error Handling
- **Issue:** The agent loading in `trade_executor.py` relies on discovering environment variables by a naming convention (`_AGENT_PK`). This is clever but can be brittle if environment variables are named incorrectly.
- **Proposal:**
- Explicitly define the agent names and their corresponding environment variable keys in the proposed `_data/config.json` file. The `trade_executor` would then load only the agents specified in the configuration.
- **Benefit:** Makes agent configuration more explicit and less prone to errors from stray environment variables.
---
## Identified Unused/Utility Files
The following files were identified as likely being unused by the core application, being obsolete, or serving as one-off utilities. It is recommended to **move them to a `scripts/` directory** or **delete them** if they are obsolete.
### Obsolete / Old Versions:
- `data_fetcher_old.py`
- `market_old.py`
- `base_strategy.py` (The one in the root directory; the one in `strategies/` is used).
### One-Off Utility Scripts (Recommend moving to `scripts/`):
- `!migrate_to_sqlite.py`
- `import_csv.py`
- `del_market_cap_tables.py`
- `fix_timestamps.py`
- `list_coins.py`
- `create_agent.py`
### Examples / Unused Code:
- `basic_ws.py` (Appears to be an example file).
- `backtester.py`
- `strategy_sma_cross.py` (A strategy file in the root, not in the `strategies` folder).
- `strategy_template.py`
### Standalone / Potentially Unused Core Files:
The following files seem to have their logic already integrated into the main multi-process application. They might be remnants of a previous architecture and may not be needed as standalone scripts.
- `address_monitor.py`
- `position_monitor.py`
- `trade_log.py`
- `wallet_data.py`
- `whale_tracker.py`
### Data / Log Files (Recommend archiving or deleting):
- `hyperliquid_wallet_data_*.json` (These appear to be backups or logs).

View File

@ -1,88 +0,0 @@
# Automated Crypto Trading Bot
This project is a sophisticated, multi-process automated trading bot designed to interact with the Hyperliquid decentralized exchange. It features a robust data pipeline, a flexible strategy engine, multi-agent trade execution, and a live terminal dashboard for real-time monitoring.
<!-- It's a good idea to take a screenshot of your dashboard and upload it to a service like Imgur to include here -->
## Features
* **Multi-Process Architecture**: Core components (data fetching, trading, strategies) run in parallel processes for maximum performance and stability.
* **Comprehensive Data Pipeline**:
* Live price feeds for all assets.
* Historical candle data collection for any coin and timeframe.
* Historical market cap data fetching from the CoinGecko API.
* **High-Performance Database**: Uses SQLite with pandas for fast, indexed storage and retrieval of all market data.
* **Configuration-Driven Strategies**: Trading strategies are defined and managed in a simple JSON file (`_data/strategies.json`), allowing for easy configuration without code changes.
* **Multi-Agent Trading**: Supports multiple, independent trading agents for advanced risk segregation and PNL tracking.
* **Live Terminal Dashboard**: A real-time, flicker-free dashboard to monitor live prices, market caps, strategy signals, and the status of all background processes.
* **Secure Key Management**: Uses a `.env` file to securely manage all private keys and API keys, keeping them separate from the codebase.
## Project Structure
The project is composed of several key scripts that work together:
* **`main_app.py`**: The central orchestrator. It launches all background processes and displays the main monitoring dashboard.
* **`trade_executor.py`**: The trading "brain." It reads signals from all active strategies and executes trades using the appropriate agent.
* **`data_fetcher.py`**: A background service that collects 1-minute historical candle data and saves it to the SQLite database.
* **`resampler.py`**: A background service that reads the 1-minute data and generates all other required timeframes (e.g., 5m, 1h, 1d).
* **`market_cap_fetcher.py`**: A scheduled service to download daily market cap data.
* **`strategy_*.py`**: Individual files containing the logic for different types of trading strategies (e.g., SMA Crossover).
* **`_data/strategies.json`**: The configuration file for defining and enabling/disabling your trading strategies.
* **`.env`**: The secure file for storing all your private keys and API keys.
## Installation
1. **Clone the Repository**
```bash
git clone [https://github.com/your-username/your-repo-name.git](https://github.com/your-username/your-repo-name.git)
cd your-repo-name
```
2. **Create and Activate a Virtual Environment**
```bash
# For Windows
python -m venv .venv
.\.venv\Scripts\activate
# For macOS/Linux
python3 -m venv .venv
source .venv/bin/activate
```
3. **Install Dependencies**
```bash
pip install -r requirements.txt
```
## Getting Started: Configuration
Before running the application, you must configure your wallets, agents, and API keys.
1. Create the .env File In the root of the project, create a file named .env. Copy the following content into it and replace the placeholder values with your actual keys.
2. **Activate Your Main Wallet on Hyperliquid**
The `trade_executor.py` script will fail if your main wallet is not registered.
* Go to the Hyperliquid website, connect your main wallet, and make a small deposit. This is a one-time setup step.
3. **Create and Authorize Trading Agents**
The `trade_executor.py` uses secure "agent" keys that can trade but cannot withdraw. You need to generate these and authorize them with your main wallet.
* Run the `create_agent.py` script
```bash
python create_agent.py
```
The script will output a new Agent Private Key. Copy this key and add it to your .env file (e.g., as SCALPER_AGENT_PK). Repeat this for each agent you want to create.
4. **Configure**
Your Strategies Open the `_data/strategies.json` file to define which strategies you want to run.
* Set "enabled": true to activate a strategy.
* Assign an "agent" (e.g., "scalper", "swing") to each strategy. The agent name must correspond to a key in your .env file (e.g., SCALPER_AGENT_PK -> "scalper").
* Configure the parameters for each strategy, such as the coin, timeframe, and any indicator settings.
##Usage##
Once everything is configured, you can run the main application from your terminal:
```bash
python main_app.py
```
## Documentation
Detailed project documentation is available in the `WIKI/` directory. Start with the summary page:
`WIKI/SUMMARY.md`
This contains links and explanations for `OVERVIEW.md`, `SETUP.md`, `SCRIPTS.md`, and other helpful pages that describe usage, data layout, agent management, development notes, and troubleshooting.

5
WIKI/.gitattributes vendored
View File

@ -1,5 +0,0 @@
# Treat markdown files as text with LF normalization
*.md text eol=lf
# Ensure JSON files are treated as text
*.json text

View File

@ -1,34 +0,0 @@
Agents and Keys
This project supports running multiple agent identities (private keys) to place orders on Hyperliquid. Agents are lightweight keys authorized on-chain by your main wallet.
Agent storage and environment
- For security, agent private keys should be stored as environment variables and not checked into source control.
- Supported patterns:
- `AGENT_PRIVATE_KEY` (single default agent)
- `<NAME>_AGENT_PK` or `<NAME>_AGENT_PRIVATE_KEY` (per-agent keys)
Discovering agents
- `trade_executor.py` scans environment variables for agent keys and loads them into `Exchange` objects so each agent can sign orders independently.
Creating and authorizing agents
- Use `create_agent.py` with your `MAIN_WALLET_PRIVATE_KEY` to authorize a new agent name. The script will attempt to call `exchange.approve_agent(agent_name)` and print the returned agent private key.
Security notes
- Never commit private keys to Git. Keep them in a secure secrets store or local `.env` file excluded from version control.
- Rotate keys if they are ever exposed and re-authorize agents using your main wallet.
Example `.env` snippet
MAIN_WALLET_PRIVATE_KEY=<your-main-wallet-private-key>
MAIN_WALLET_ADDRESS=<your-main-wallet-address>
AGENT_PRIVATE_KEY=<agent-private-key>
EXECUTOR_SCALPER_AGENT_PK=<agent-private-key-for-scalper>
File `agents`
- This repository may contain a local `agents` file used as a quick snapshot; treat it as insecure and remove it from the repo or add it to `.gitignore` if it contains secrets.

View File

@ -1,20 +0,0 @@
Contributing
Thanks for considering contributing! Please follow these guidelines to make the process smooth.
How to contribute
1. Fork the repository and create a feature branch for your change.
2. Keep changes focused and add tests where appropriate.
3. Submit a Pull Request with a clear description and the reason for the change.
Coding standards
- Keep functions small and well-documented.
- Use the existing logging utilities for consistent output.
- Prefer safe, incremental changes for financial code.
Security and secrets
- Never commit private keys, API keys, or secrets. Use environment variables or a secrets manager.
- If you accidentally commit secrets, rotate them immediately.

View File

@ -1,31 +0,0 @@
Data layout and formats
This section describes the `_data/` directory and the important files used by the scripts.
Important files
- `_data/market_data.db` — SQLite database that stores candle tables. Tables are typically named `<COIN>_<INTERVAL>` (e.g., `BTC_1m`, `ETH_5m`).
- `_data/coin_precision.json` — Mapping of coin names to their size precision (created by `list_coins.py`).
- `_data/current_prices.json` — Latest market prices that `market.py` writes.
- `_data/fetcher_status.json` — Last run metadata from `data_fetcher.py`.
- `_data/market_cap_data.json` — Market cap summary saved by `market_cap_fetcher.py`.
- `_data/strategies.json` — Configuration for strategies (enabled flag, parameters).
- `_data/strategy_status_<name>.json` — Per-strategy runtime status including last signal and price.
- `_data/executor_managed_positions.json` — Which strategy is currently managing which live position (used by `trade_executor`).
Candle schema
Each candle table contains columns similar to:
- `timestamp_ms` (INTEGER) — milliseconds since epoch
- `open`, `high`, `low`, `close` (FLOAT)
- `volume` (FLOAT)
- `number_of_trades` (INTEGER)
Trade logs
- Persistent trade history is stored in `_logs/trade_history.csv` with the following columns: `timestamp_utc`, `strategy`, `coin`, `action`, `price`, `size`, `signal`, `pnl`.
Backups and maintenance
- Periodically back up `_data/market_data.db`. The WAL and SHM files are also present when SQLite uses WAL mode.
- Keep JSON config/state files under version control only if they contain no secrets.

View File

@ -1,24 +0,0 @@
Development and testing
Code style and conventions
- Python 3.11+ with typing hints where helpful.
- Use `logging_utils.setup_logging` for consistent logs across scripts.
Running tests
- This repository doesn't currently include a formal test suite. Suggested quick checks:
- Run `python list_coins.py` to verify connectivity to Hyperliquid Info.
- Run `python -m pyflakes .` or `python -m pylint` if you have linters installed.
Adding a new strategy
1. Create a new script following the pattern in `strategy_template.py`.
2. Add an entry to `_data/strategies.json` with `enabled: true` and relevant parameters.
3. Ensure the strategy writes a status JSON file (`_data/strategy_status_<name>.json`) and uses `trade_log.log_trade` to record actions.
Recommended improvements (low-risk)
- Add a lightweight unit test suite (pytest) for core functions like timeframe parsing, SQL helpers, and signal calculation.
- Add CI (GitHub Actions) to run flake/pylint and unit tests on PRs.
- Move secrets handling to a `.env.example` and document environment variables in `WIKI/SETUP.md`.

View File

@ -1,29 +0,0 @@
Hyperliquid Trading Toolkit
This repository contains a collection of utility scripts, data fetchers, resamplers, trading strategies, and a trade executor for working with Hyperliquid trading APIs and crawled data. It is organized to support data collection, transformation, strategy development, and automated execution via agents.
Key components
- Data fetching and management: `data_fetcher.py`, `market.py`, `resampler.py`, `market_cap_fetcher.py`, `list_coins.py`
- Strategies: `strategy_sma_cross.py`, `strategy_template.py`, `strategy_sma_125d.py` (if present)
- Execution: `trade_executor.py`, `create_agent.py`, `agents` helper
- Utilities: `logging_utils.py`, `trade_log.py`
- Data storage: SQLite database in `_data/market_data.db` and JSON files in `_data`
Intended audience
- Developers building strategies and automations on Hyperliquid
- Data engineers collecting and processing market data
- Operators running the fetchers and executors on a scheduler or as system services
Project goals
- Reliable collection of 1m candles and resampling to common timeframes
- Clean separation between data, strategies, and execution
- Lightweight logging and traceable trade records
Where to start
- Read `WIKI/SETUP.md` to prepare your environment
- Use `WIKI/SCRIPTS.md` for a description of individual scripts and how to run them
- Inspect `WIKI/AGENTS.md` to understand agent keys and how to manage them

View File

@ -1,47 +0,0 @@
Scripts and How to Use Them
This file documents the main scripts in the repository and their purpose, typical runtime parameters, and key notes.
list_coins.py
- Purpose: Fetches asset metadata from Hyperliquid (name and size/precision) and saves `_data/coin_precision.json`.
- Usage: `python list_coins.py`
- Notes: Reads `hyperliquid.info.Info` and writes a JSON file. Useful to run before market feeders.
market.py (MarketDataFeeder)
- Purpose: Fetches live prices from Hyperliquid and writes `_data/current_prices.json` while printing a live table.
- Usage: `python market.py --log-level normal`
- Notes: Expects `_data/coin_precision.json` to exist.
data_fetcher.py (CandleFetcherDB)
- Purpose: Fetches historical 1m candles and stores them in `_data/market_data.db` using a table-per-coin naming convention.
- Usage: `python data_fetcher.py --coins BTC ETH --interval 1m --days 7`
- Notes: Can be run regularly by a scheduler to keep the DB up to date.
resampler.py (Resampler)
- Purpose: Reads 1m candles from SQLite and resamples to configured timeframes (e.g. 5m, 15m, 1h), appending new candles to tables.
- Usage: `python resampler.py --coins BTC ETH --timeframes 5m 15m 1h --log-level normal`
market_cap_fetcher.py (MarketCapFetcher)
- Purpose: Pulls CoinGecko market cap numbers and maintains historical daily tables in the same SQLite DB.
- Usage: `python market_cap_fetcher.py --coins BTC ETH --log-level normal`
- Notes: Optional `COINGECKO_API_KEY` in `.env` avoids throttling.
strategy_sma_cross.py (SmaCrossStrategy)
- Purpose: Run an SMA-based trading strategy. Reads candles from `_data/market_data.db` and writes status to `_data/strategy_status_<name>.json`.
- Usage: `python strategy_sma_cross.py --name sma_cross_1 --params '{"coin":"BTC","timeframe":"1m","fast":5,"slow":20}' --log-level normal`
trade_executor.py (TradeExecutor)
- Purpose: Orchestrates agent-based order execution using agent private keys found in environment variables. Uses `_data/strategies.json` to determine active strategies.
- Usage: `python trade_executor.py --log-level normal`
- Notes: Requires `MAIN_WALLET_ADDRESS` and agent keys. See `create_agent.py` to authorize agents on-chain.
create_agent.py
- Purpose: Authorizes a new on-chain agent using your main wallet (requires `MAIN_WALLET_PRIVATE_KEY`).
- Usage: `python create_agent.py`
- Notes: Prints the new agent private key to stdout — save it securely.
trade_log.py
- Purpose: Provides a thread-safe CSV trade history logger. Used by the executor and strategies to record actions.
Other utility scripts
- import_csv.py, fix_timestamps.py, list_coins.py, etc. — see file headers for details.

View File

@ -1,42 +0,0 @@
Setup and Installation
Prerequisites
- Python 3.11+ (project uses modern dependencies)
- Git (optional)
- A Hyperliquid account and an activated main wallet if you want to authorize agents and trade
Virtual environment
1. Create a virtual environment:
python -m venv .venv
2. Activate the virtual environment (PowerShell on Windows):
.\.venv\Scripts\Activate.ps1
3. Upgrade pip and install dependencies:
python -m pip install --upgrade pip
pip install -r requirements.txt
Configuration
- Copy `.env.example` to `.env` and set the following variables as required:
- MAIN_WALLET_PRIVATE_KEY (used by `create_agent.py` to authorize agents)
- MAIN_WALLET_ADDRESS (used by `trade_executor.py`)
- AGENT_PRIVATE_KEY or per-agent keys like `EXECUTOR_SCALPER_AGENT_PK`
- Optional: COINGECKO_API_KEY for `market_cap_fetcher.py` to avoid rate limits
Data directory
- The project writes and reads data from the `_data/` folder. Ensure the directory exists and is writable by the user running the scripts.
Quick test
After installing packages, run `list_coins.py` in a dry run to verify connectivity to the Hyperliquid info API:
python list_coins.py
If you encounter import errors, ensure the virtual environment is active and the `requirements.txt` dependencies are installed.

View File

@ -1,15 +0,0 @@
Project Wiki Summary
This directory contains human-friendly documentation for the project. Files:
- `OVERVIEW.md` — High-level overview and where to start
- `SETUP.md` — Environment setup and quick test steps
- `SCRIPTS.md` — Per-script documentation and usage examples
- `AGENTS.md` — How agents work and secure handling of keys
- `DATA.md` — Data folder layout and schema notes
- `DEVELOPMENT.md` — Developer guidance and recommended improvements
- `CONTRIBUTING.md` — How to contribute safely
- `TROUBLESHOOTING.md` — Common problems and solutions
Notes:
- These pages were generated from repository source files and common patterns in trading/data projects. Validate any sensitive information (agent keys) and remove them from the repository when sharing.

View File

@ -1,21 +0,0 @@
Troubleshooting common issues
1. Import errors
- Ensure the virtual environment is active.
- Run `pip install -r requirements.txt`.
2. Agent authorization failures
- Ensure your main wallet is activated on Hyperliquid and has funds.
- The `create_agent.py` script will print helpful messages if the vault (main wallet) cannot act.
3. SQLite locked errors
- Increase the SQLite timeout when opening connections (this project uses a 10s timeout in fetcher). Close other programs that may hold the DB open.
4. Missing coin precision file
- Run `python list_coins.py` to regenerate `_data/coin_precision.json`.
5. Rate limits from CoinGecko
- Set `COINGECKO_API_KEY` in your `.env` file and ensure the fetcher respects backoff.
6. Agent keys in `agents` file or other local files
- Treat any `agents` file with private keys as compromised; rotate keys and remove the file from the repository.

View File

@ -1,6 +1,6 @@
{
"sma_cross_eth_5m": {
"strategy_name": "sma_cross_2",
"strategy_name": "sma_cross_1",
"script": "strategies.ma_cross_strategy.MaCrossStrategy",
"optimization_params": {
"fast": {

208
_data/coin_id_map.json Normal file
View File

@ -0,0 +1,208 @@
{
"0G": "zero-gravity",
"2Z": "doublezero",
"AAVE": "aave",
"ACE": "endurance",
"ADA": "ada-the-dog",
"AI": "sleepless-ai",
"AI16Z": "ai16z",
"AIXBT": "aixbt",
"ALGO": "dear-algorithm",
"ALT": "altlayer",
"ANIME": "anime-token",
"APE": "ape-3",
"APEX": "apex-token-2",
"APT": "aptos",
"AR": "arweave",
"ARB": "osmosis-allarb",
"ARK": "ark-3",
"ASTER": "astar",
"ATOM": "lost-bitcoin-layer",
"AVAX": "binance-peg-avalanche",
"AVNT": "avantis",
"BABY": "baby-2",
"BADGER": "badger-dao",
"BANANA": "nforbanana",
"BCH": "bitcoin-cash",
"BERA": "berachain-bera",
"BIGTIME": "big-time",
"BIO": "bio-protocol",
"BLAST": "blast",
"BLUR": "blur",
"BLZ": "bluzelle",
"BNB": "binancecoin",
"BNT": "bancor",
"BOME": "book-of-meme",
"BRETT": "brett",
"BSV": "bitcoin-cash-sv",
"BTC": "bitcoin",
"CAKE": "pancakeswap-token",
"CANTO": "canto",
"CATI": "catizen",
"CELO": "celo",
"CFX": "cosmic-force-token-v2",
"CHILLGUY": "just-a-chill-guy",
"COMP": "compound-governance-token",
"CRV": "curve-dao-token",
"CYBER": "cyberconnect",
"DOGE": "doge-on-pulsechain",
"DOOD": "doodles",
"DOT": "xcdot",
"DYDX": "dydx-chain",
"DYM": "dymension",
"EIGEN": "eigenlayer",
"ENA": "ethena",
"ENS": "ethereum-name-service",
"ETC": "ethereum-classic",
"ETH": "ethereum",
"ETHFI": "ether-fi",
"FARTCOIN": "fartcoin-2",
"FET": "fetch-ai",
"FIL": "filecoin",
"FRIEND": "friend-tech",
"FTM": "fantom",
"FTT": "ftx-token",
"GALA": "gala",
"GAS": "gas",
"GMT": "stepn",
"GMX": "gmx",
"GOAT": "goat",
"GRASS": "grass-3",
"GRIFFAIN": "griffain",
"HBAR": "hedera-hashgraph",
"HEMI": "hemi",
"HMSTR": "hamster-kombat",
"HYPE": "hyperliquid",
"HYPER": "hyper-4",
"ILV": "illuvium",
"IMX": "immutable-x",
"INIT": "initia",
"INJ": "injective-protocol",
"IO": "io",
"IOTA": "iota-2",
"IP": "story-2",
"JELLY": "jelly-time",
"JTO": "jito-governance-token",
"JUP": "jupiter-exchange-solana",
"KAITO": "kaito",
"KAS": "wrapped-kaspa",
"LAUNCHCOIN": "ben-pasternak",
"LAYER": "unilayer",
"LDO": "linea-bridged-ldo-linea",
"LINEA": "linea",
"LINK": "osmosis-alllink",
"LISTA": "lista",
"LOOM": "loom",
"LTC": "litecoin",
"MANTA": "manta-network",
"MATIC": "matic-network",
"MAV": "maverick-protocol",
"MAVIA": "heroes-of-mavia",
"ME": "magic-eden",
"MEGA": "megaeth",
"MELANIA": "melania-meme",
"MEME": "mpx6900",
"MERL": "merlin-chain",
"MET": "metya",
"MEW": "cat-in-a-dogs-world",
"MINA": "mina-protocol",
"MKR": "maker",
"MNT": "mynth",
"MON": "mon-protocol",
"MOODENG": "moo-deng-2",
"MORPHO": "morpho",
"MOVE": "movement",
"MYRO": "myro",
"NEAR": "near",
"NEO": "neo",
"NIL": "nillion",
"NOT": "nothing-3",
"NTRN": "neutron-3",
"NXPC": "nexpace",
"OGN": "origin-protocol",
"OM": "mantra-dao",
"OMNI": "omni-2",
"ONDO": "ondo-finance",
"OP": "optimism",
"ORBS": "orbs",
"ORDI": "ordinals",
"OX": "ox-fun",
"PANDORA": "pandora",
"PAXG": "pax-gold",
"PENDLE": "pendle",
"PENGU": "pudgy-penguins",
"PEOPLE": "constitutiondao-wormhole",
"PIXEL": "pixel-3",
"PNUT": "pnut",
"POL": "proof-of-liquidity",
"POLYX": "polymesh",
"POPCAT": "popcat",
"PROMPT": "wayfinder",
"PROVE": "succinct",
"PUMP": "pump-fun",
"PURR": "purr-2",
"PYTH": "pyth-network",
"RDNT": "radiant-capital",
"RENDER": "render-token",
"REQ": "request-network",
"RESOLV": "resolv",
"REZ": "renzo",
"RLB": "rollbit-coin",
"RSR": "reserve-rights-token",
"RUNE": "thorchain",
"S": "token-s",
"SAGA": "saga-2",
"SAND": "the-sandbox-wormhole",
"SCR": "scroll",
"SEI": "sei-network",
"SHIA": "shiba-saga",
"SKY": "sky",
"SNX": "havven",
"SOL": "solana",
"SOPH": "sophon",
"SPX": "spx6900",
"STBL": "stbl",
"STG": "stargate-finance",
"STRAX": "stratis",
"STRK": "starknet",
"STX": "stox",
"SUI": "sui",
"SUPER": "superfarm",
"SUSHI": "sushi",
"SYRUP": "syrup",
"TAO": "the-anthropic-order",
"TIA": "tia",
"TNSR": "tensorium",
"TON": "tontoken",
"TRB": "tellor",
"TRUMP": "trumpeffect69420",
"TRX": "tron-bsc",
"TST": "test-3",
"TURBO": "turbo",
"UMA": "uma",
"UNI": "uni",
"UNIBOT": "unibot",
"USTC": "wrapped-ust",
"USUAL": "usual",
"VINE": "vine",
"VIRTUAL": "virtual-protocol",
"VVV": "venice-token",
"W": "w",
"WCT": "connect-token-wct",
"WIF": "wif-secondchance",
"WLD": "worldcoin-wld",
"WLFI": "world-liberty-financial",
"XAI": "xai-blockchain",
"XLM": "stellar",
"XPL": "pulse-2",
"XRP": "ripple",
"YGG": "yield-guild-games",
"YZY": "yzy",
"ZEC": "zcash",
"ZEN": "zenith-3",
"ZEREBRO": "zerebro",
"ZETA": "zeta",
"ZK": "zksync",
"ZORA": "zora",
"ZRO": "layerzero"
}

View File

@ -101,6 +101,7 @@
"MAV": 0,
"MAVIA": 1,
"ME": 1,
"MEGA": 0,
"MELANIA": 1,
"MEME": 0,
"MERL": 0,

View File

@ -1,7 +0,0 @@
{
"sma_cross_2": {
"coin": "BTC",
"side": "short",
"size": 0.0001
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,11 @@
{
"copy_trader_eth_ETH": {
"strategy": "copy_trader_eth",
"coin": "ETH",
"side": "long",
"open_time_utc": "2025-11-02T20:35:02.988272+00:00",
"open_price": 3854.9,
"amount": 0.0055,
"leverage": 3
}
}

View File

@ -1,12 +1,11 @@
{
"sma_cross_eth_5m": {
"enabled": true,
"script": "strategy_runner.py",
"sma_cross_1": {
"enabled": false,
"class": "strategies.ma_cross_strategy.MaCrossStrategy",
"agent": "scalper_agent",
"parameters": {
"coin": "ETH",
"timeframe": "1m",
"timeframe": "15m",
"short_ma": 7,
"long_ma": 44,
"size": 0.0055,
@ -14,19 +13,39 @@
"leverage_short": 5
}
},
"sma_125d_btc": {
"enabled": true,
"script": "strategy_runner.py",
"sma_44d_btc": {
"enabled": false,
"class": "strategies.single_sma_strategy.SingleSmaStrategy",
"agent": "swing_agent",
"parameters": {
"agent": "swing",
"coin": "BTC",
"timeframe": "1d",
"sma_period": 44,
"size": 0.0001,
"leverage_long": 2,
"leverage_long": 3,
"leverage_short": 1
}
},
"copy_trader_eth": {
"enabled": true,
"is_event_driven": true,
"class": "strategies.copy_trader_strategy.CopyTraderStrategy",
"parameters": {
"agent": "scalper",
"target_address": "0x32885a6adac4375858E6edC092EfDDb0Ef46484C",
"coins_to_copy": {
"ETH": {
"size": 0.0055,
"leverage_long": 3,
"leverage_short": 3
},
"BTC": {
"size": 0.0002,
"leverage_long": 1,
"leverage_short": 1
}
}
}
}
}

View File

@ -0,0 +1,7 @@
{
"ETH": {
"side": "long",
"size": 0.018,
"entry": 3864.2
}
}

View File

@ -0,0 +1,7 @@
{
"strategy_name": "copy_trader_eth",
"current_signal": "WAIT",
"last_signal_change_utc": null,
"signal_price": null,
"last_checked_utc": "2025-11-02T09:55:08.460168+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "ma_cross_btc",
"current_signal": "HOLD",
"last_signal_change_utc": "2025-10-12T17:00:00+00:00",
"signal_price": 114286.0,
"last_checked_utc": "2025-10-15T11:48:55.092260+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_125d_btc",
"current_signal": "SELL",
"last_signal_change_utc": "2025-10-14T00:00:00+00:00",
"signal_price": 113026.0,
"last_checked_utc": "2025-10-16T10:42:03.203292+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_125d_eth",
"current_signal": "BUY",
"last_signal_change_utc": "2025-08-26T00:00:00+00:00",
"signal_price": 4600.63,
"last_checked_utc": "2025-10-15T17:35:17.663159+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_44d_btc",
"current_signal": "SELL",
"last_signal_change_utc": "2025-10-14T00:00:00+00:00",
"signal_price": 113026.0,
"last_checked_utc": "2025-10-16T10:42:03.202977+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_5m_eth",
"current_signal": "SELL",
"last_signal_change_utc": "2025-10-15T17:30:00+00:00",
"signal_price": 3937.5,
"last_checked_utc": "2025-10-15T17:35:05.035566+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_cross",
"current_signal": "SELL",
"last_signal_change_utc": "2025-10-15T11:45:00+00:00",
"signal_price": 111957.0,
"last_checked_utc": "2025-10-15T12:10:05.048434+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_cross_1",
"current_signal": "FLAT",
"last_signal_change_utc": "2025-10-18T20:22:00+00:00",
"signal_price": 3893.9,
"last_checked_utc": "2025-10-18T20:30:05.021192+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_cross_2",
"current_signal": "SELL",
"last_signal_change_utc": "2025-10-20T00:00:00+00:00",
"signal_price": 110811.0,
"last_checked_utc": "2025-10-20T18:45:51.578502+00:00"
}

View File

@ -1,7 +0,0 @@
{
"strategy_name": "sma_cross_eth_5m",
"current_signal": "SELL",
"last_signal_change_utc": "2025-10-15T11:45:00+00:00",
"signal_price": 4106.1,
"last_checked_utc": "2025-10-15T12:05:05.022308+00:00"
}

290
_data/wallets_info.json Normal file
View File

@ -0,0 +1,290 @@
{
"Whale 1 (BTC Maxi)": {
"address": "0xb83de012dba672c76a7dbbbf3e459cb59d7d6e36",
"core_state": {
"raw_state": {
"marginSummary": {
"accountValue": "30018881.1193690002",
"totalNtlPos": "182930683.6996490061",
"totalRawUsd": "212949564.8190180063",
"totalMarginUsed": "22969943.9848450013"
},
"crossMarginSummary": {
"accountValue": "30018881.1193690002",
"totalNtlPos": "182930683.6996490061",
"totalRawUsd": "212949564.8190180063",
"totalMarginUsed": "22969943.9848450013"
},
"crossMaintenanceMarginUsed": "5420634.4984849999",
"withdrawable": "7043396.1885489998",
"assetPositions": [
{
"type": "oneWay",
"position": {
"coin": "BTC",
"szi": "-546.94441",
"leverage": {
"type": "cross",
"value": 10
},
"entryPx": "115183.2",
"positionValue": "62795781.6009199992",
"unrealizedPnl": "203045.067519",
"returnOnEquity": "0.0322299761",
"liquidationPx": "159230.7089577085",
"marginUsed": "6279578.1600919999",
"maxLeverage": 40,
"cumFunding": {
"allTime": "-6923407.0911370004",
"sinceOpen": "-6923407.0970780002",
"sinceChange": "-1574.188052"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "ETH",
"szi": "-13938.989",
"leverage": {
"type": "cross",
"value": 10
},
"entryPx": "4106.64",
"positionValue": "58064252.5784000009",
"unrealizedPnl": "-821803.895073",
"returnOnEquity": "-0.1435654683",
"liquidationPx": "5895.7059682083",
"marginUsed": "5806425.2578400001",
"maxLeverage": 25,
"cumFunding": {
"allTime": "-6610045.8844170002",
"sinceOpen": "-6610045.8844170002",
"sinceChange": "-730.403023"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "SOL",
"szi": "-75080.68",
"leverage": {
"type": "cross",
"value": 10
},
"entryPx": "201.3063",
"positionValue": "14975592.4328000005",
"unrealizedPnl": "138627.573942",
"returnOnEquity": "0.0917199656",
"liquidationPx": "519.0933515657",
"marginUsed": "1497559.2432800001",
"maxLeverage": 20,
"cumFunding": {
"allTime": "-792893.154387",
"sinceOpen": "-922.301401",
"sinceChange": "-187.682929"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "DOGE",
"szi": "-109217.0",
"leverage": {
"type": "cross",
"value": 10
},
"entryPx": "0.279959",
"positionValue": "22081.49306",
"unrealizedPnl": "8494.879599",
"returnOnEquity": "2.7782496288",
"liquidationPx": "213.2654356057",
"marginUsed": "2208.149306",
"maxLeverage": 10,
"cumFunding": {
"allTime": "-1875.469799",
"sinceOpen": "-1875.469799",
"sinceChange": "45.79339"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "INJ",
"szi": "-18747.2",
"leverage": {
"type": "cross",
"value": 3
},
"entryPx": "13.01496",
"positionValue": "162200.7744",
"unrealizedPnl": "81793.4435",
"returnOnEquity": "1.005680924",
"liquidationPx": "1208.3529290194",
"marginUsed": "54066.9248",
"maxLeverage": 10,
"cumFunding": {
"allTime": "-539.133533",
"sinceOpen": "-539.133533",
"sinceChange": "-7.367325"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "SUI",
"szi": "-376577.6",
"leverage": {
"type": "cross",
"value": 3
},
"entryPx": "3.85881",
"positionValue": "989495.3017599999",
"unrealizedPnl": "463648.956001",
"returnOnEquity": "0.9571980625",
"liquidationPx": "64.3045458208",
"marginUsed": "329831.767253",
"maxLeverage": 10,
"cumFunding": {
"allTime": "-45793.455728",
"sinceOpen": "-45793.450891",
"sinceChange": "-1233.875821"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "XRP",
"szi": "-39691.0",
"leverage": {
"type": "cross",
"value": 20
},
"entryPx": "2.468585",
"positionValue": "105486.7707",
"unrealizedPnl": "-7506.1484",
"returnOnEquity": "-1.5321699789",
"liquidationPx": "607.2856858464",
"marginUsed": "5274.338535",
"maxLeverage": 20,
"cumFunding": {
"allTime": "-2645.400002",
"sinceOpen": "-116.036833",
"sinceChange": "-116.036833"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "HYPE",
"szi": "-750315.16",
"leverage": {
"type": "cross",
"value": 5
},
"entryPx": "43.3419",
"positionValue": "34957933.6195600033",
"unrealizedPnl": "-2437823.0249080001",
"returnOnEquity": "-0.3748177636",
"liquidationPx": "76.3945326684",
"marginUsed": "6991586.7239119997",
"maxLeverage": 5,
"cumFunding": {
"allTime": "-1881584.4214250001",
"sinceOpen": "-1881584.4214250001",
"sinceChange": "-45247.838743"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "FARTCOIN",
"szi": "-4122236.7999999998",
"leverage": {
"type": "cross",
"value": 10
},
"entryPx": "0.80127",
"positionValue": "1681584.057824",
"unrealizedPnl": "1621478.3279619999",
"returnOnEquity": "4.9090151459",
"liquidationPx": "6.034656163",
"marginUsed": "168158.405782",
"maxLeverage": 10,
"cumFunding": {
"allTime": "-72941.395024",
"sinceOpen": "-51271.5204",
"sinceChange": "-6504.295598"
}
}
},
{
"type": "oneWay",
"position": {
"coin": "PUMP",
"szi": "-1921732999.0",
"leverage": {
"type": "cross",
"value": 5
},
"entryPx": "0.005551",
"positionValue": "9176275.0702250004",
"unrealizedPnl": "1491738.24016",
"returnOnEquity": "0.6991640321",
"liquidationPx": "0.0166674064",
"marginUsed": "1835255.0140450001",
"maxLeverage": 10,
"cumFunding": {
"allTime": "-196004.534539",
"sinceOpen": "-196004.534539",
"sinceChange": "-9892.654861"
}
}
}
],
"time": 1761595358385
},
"account_value": 30018881.119369,
"margin_used": 22969943.984845,
"margin_utilization": 0.765183215640378,
"available_margin": 7048937.134523999,
"total_position_value": 0.0,
"portfolio_leverage": 0.0
},
"open_orders": {
"raw_orders": [
{
"coin": "WLFI",
"side": "B",
"limitPx": "0.10447",
"sz": "2624.0",
"oid": 194029229960,
"timestamp": 1760131688558,
"origSz": "12760.0",
"cloid": "0x00000000000000000000001261000016"
},
{
"coin": "@166",
"side": "A",
"limitPx": "1.01",
"sz": "103038.77",
"oid": 174787748753,
"timestamp": 1758819420037,
"origSz": "3000000.0"
}
]
},
"account_metrics": {
"cumVlm": "2823125892.6900000572",
"nRequestsUsed": 1766294,
"nRequestsCap": 2823135892
}
}
}

View File

@ -0,0 +1,7 @@
[
{
"name": "Whale 1 (BTC Maxi)",
"address": "0xb83de012dba672c76a7dbbbf3e459cb59d7d6e36",
"tags": ["btc", "high_leverage"]
}
]

View File

@ -30,8 +30,11 @@ class DashboardDataFetcher:
sys.exit(1)
self.info = Info(constants.MAINNET_API_URL, skip_ws=True)
self.status_file_path = os.path.join("_logs", "trade_executor_status.json")
self.managed_positions_path = os.path.join("_data", "executor_managed_positions.json")
# Use absolute path to ensure consistency across different working directories
project_root = os.path.dirname(os.path.abspath(__file__))
self.status_file_path = os.path.join(project_root, "_logs", "trade_executor_status.json")
self.managed_positions_path = os.path.join(project_root, "_data", "executor_managed_positions.json")
logging.info(f"Dashboard Data Fetcher initialized for vault: {self.vault_address}")
def load_managed_positions(self) -> dict:
@ -47,7 +50,7 @@ class DashboardDataFetcher:
return {}
def fetch_and_save_status(self):
"""Fetches all account data and saves it to the JSON status file."""
"""Fetches all account data and saves it to JSON status file."""
try:
perpetuals_state = self.info.user_state(self.vault_address)
spot_state = self.info.spot_user_state(self.vault_address)
@ -105,7 +108,11 @@ class DashboardDataFetcher:
"position_value": total_balance * mark_price, "pnl": "N/A"
})
# 3. Write to file
# 3. Ensure directory exists and write to file
# Ensure the _logs directory exists
logs_dir = os.path.dirname(self.status_file_path)
os.makedirs(logs_dir, exist_ok=True)
# Use atomic write to prevent partial reads from main_app
temp_file_path = self.status_file_path + ".tmp"
with open(temp_file_path, 'w', encoding='utf-8') as f:

View File

@ -0,0 +1,2 @@
# This file can be empty.
# It tells Python that 'position_logic' is a directory containing modules.

View File

@ -0,0 +1,31 @@
from abc import ABC, abstractmethod
import logging
class BasePositionLogic(ABC):
"""
Abstract base class for all strategy-specific position logic.
Defines the interface for how the PositionManager interacts with logic modules.
"""
def __init__(self, strategy_name: str, send_order_callback, log_trade_callback):
self.strategy_name = strategy_name
self.send_order = send_order_callback
self.log_trade = log_trade_callback
logging.info(f"Initialized position logic for '{strategy_name}'")
@abstractmethod
def handle_signal(self, signal_data: dict, current_strategy_positions: dict) -> dict:
"""
The core logic method. This is called by the PositionManager when a
new signal arrives for this strategy.
Args:
signal_data: The full signal dictionary from the strategy.
current_strategy_positions: A dict of this strategy's current positions,
keyed by coin (e.g., {"BTC": {"side": "long", ...}}).
Returns:
A dictionary representing the new state for the *specific coin* in the
signal (e.g., {"side": "long", "size": 0.1}).
Return None to indicate the position for this coin should be closed/removed.
"""
pass

View File

@ -0,0 +1,83 @@
import logging
from position_logic.base_logic import BasePositionLogic
class DefaultFlipLogic(BasePositionLogic):
"""
The standard "flip-on-signal" logic used by most simple strategies
(SMA, MA Cross, and even the per-coin Copy Trader signals).
- BUY signal: Closes any short, opens a long.
- SELL signal: Closes any long, opens a short.
- FLAT signal: Closes any open position.
"""
def handle_signal(self, signal_data: dict, current_strategy_positions: dict) -> dict:
"""
Processes a BUY, SELL, or FLAT signal and issues the necessary orders
to flip or open a position.
"""
name = self.strategy_name
params = signal_data['config']['parameters']
coin = signal_data['coin']
desired_signal = signal_data['signal']
signal_price = signal_data.get('signal_price', 0)
size = params.get('size')
leverage_long = int(params.get('leverage_long', 2))
leverage_short = int(params.get('leverage_short', 2))
agent_name = signal_data['config'].get("agent", "default").lower()
# --- This logic now correctly targets a specific coin ---
current_position = current_strategy_positions.get(coin)
new_position_state = None # Return None to close position
if desired_signal == "BUY" or desired_signal == "INIT_BUY":
new_position_state = {"coin": coin, "side": "long", "size": size}
if not current_position:
logging.warning(f"[{name}]-[{coin}] ACTION: Setting leverage to {leverage_long}x and opening LONG.")
self.send_order(agent_name, "update_leverage", coin, is_buy=True, size=leverage_long)
self.send_order(agent_name, "market_open", coin, is_buy=True, size=size)
self.log_trade(strategy=name, coin=coin, action="OPEN_LONG", price=signal_price, size=size, signal=desired_signal)
elif current_position['side'] == 'short':
logging.warning(f"[{name}]-[{coin}] ACTION: Closing SHORT and opening LONG with {leverage_long}x leverage.")
self.send_order(agent_name, "update_leverage", coin, is_buy=True, size=leverage_long)
self.send_order(agent_name, "market_open", coin, is_buy=True, size=current_position['size'], reduce_only=True)
self.log_trade(strategy=name, coin=coin, action="CLOSE_SHORT", price=signal_price, size=current_position['size'], signal=desired_signal)
self.send_order(agent_name, "market_open", coin, is_buy=True, size=size)
self.log_trade(strategy=name, coin=coin, action="OPEN_LONG", price=signal_price, size=size, signal=desired_signal)
else: # Already long, do nothing
logging.info(f"[{name}]-[{coin}] INFO: Already LONG, no action taken.")
new_position_state = current_position # State is unchanged
elif desired_signal == "SELL" or desired_signal == "INIT_SELL":
new_position_state = {"coin": coin, "side": "short", "size": size}
if not current_position:
logging.warning(f"[{name}]-[{coin}] ACTION: Setting leverage to {leverage_short}x and opening SHORT.")
self.send_order(agent_name, "update_leverage", coin, is_buy=False, size=leverage_short)
self.send_order(agent_name, "market_open", coin, is_buy=False, size=size)
self.log_trade(strategy=name, coin=coin, action="OPEN_SHORT", price=signal_price, size=size, signal=desired_signal)
elif current_position['side'] == 'long':
logging.warning(f"[{name}]-[{coin}] ACTION: Closing LONG and opening SHORT with {leverage_short}x leverage.")
self.send_order(agent_name, "update_leverage", coin, is_buy=False, size=leverage_short)
self.send_order(agent_name, "market_open", coin, is_buy=False, size=current_position['size'], reduce_only=True)
self.log_trade(strategy=name, coin=coin, action="CLOSE_LONG", price=signal_price, size=current_position['size'], signal=desired_signal)
self.send_order(agent_name, "market_open", coin, is_buy=False, size=size)
self.log_trade(strategy=name, coin=coin, action="OPEN_SHORT", price=signal_price, size=size, signal=desired_signal)
else: # Already short, do nothing
logging.info(f"[{name}]-[{coin}] INFO: Already SHORT, no action taken.")
new_position_state = current_position # State is unchanged
elif desired_signal == "FLAT":
if current_position:
logging.warning(f"[{name}]-[{coin}] ACTION: Close {current_position['side']} position.")
is_buy = current_position['side'] == 'short' # To close a short, we buy
self.send_order(agent_name, "market_open", coin, is_buy=is_buy, size=current_position['size'], reduce_only=True)
self.log_trade(strategy=name, coin=coin, action=f"CLOSE_{current_position['side'].upper()}", price=signal_price, size=current_position['size'], signal=desired_signal)
# new_position_state is already None, which will remove it
return new_position_state

79
review.md Normal file
View File

@ -0,0 +1,79 @@
# Project Review and Recommendations
This review provides an analysis of the current state of the automated trading bot project, proposes specific code improvements, and identifies files that appear to be unused or are one-off utilities that could be reorganized.
The project is a well-structured, multi-process Python application for crypto trading. It has a clear separation of concerns between data fetching, strategy execution, and trade management. The use of `multiprocessing` and a centralized `main_app.py` orchestrator is a solid architectural choice.
The following sections detail recommendations for improving configuration management, code structure, and robustness, along with a list of files recommended for cleanup.
---
## Proposed Code Changes
### 1. Centralize Configuration
- **Issue:** Key configuration variables like `WATCHED_COINS` and `required_timeframes` are hardcoded in `main_app.py`. This makes them difficult to change without modifying the source code.
- **Proposal:**
- Create a central configuration file, e.g., `_data/config.json`.
- Move `WATCHED_COINS` and `required_timeframes` into this new file.
- Load this configuration in `main_app.py` at startup.
- **Benefit:** Decouples configuration from code, making the application more flexible and easier to manage.
### 2. Refactor `main_app.py` for Clarity
- **Issue:** `main_app.py` is long and handles multiple responsibilities: process orchestration, dashboard rendering, and data reading.
- **Proposal:**
- **Abstract Process Management:** The functions for running subprocesses (e.g., `run_live_candle_fetcher`, `run_resampler_job`) contain repetitive logic for logging, shutdown handling, and process looping. This could be abstracted into a generic `ProcessRunner` class.
- **Create a Dashboard Class:** The complex dashboard rendering logic could be moved into a separate `Dashboard` class to improve separation of concerns and make the main application loop cleaner.
- **Benefit:** Improves code readability, reduces duplication, and makes the application easier to maintain and extend.
### 3. Improve Project Structure
- **Issue:** The root directory is cluttered with numerous Python scripts, making it difficult to distinguish between core application files, utility scripts, and old/example files.
- **Proposal:**
- Create a `scripts/` directory and move all one-off utility and maintenance scripts into it.
- Consider creating a `src/` or `app/` directory to house the core application source code (`main_app.py`, `trade_executor.py`, etc.), separating it clearly from configuration, data, and documentation.
- **Benefit:** A cleaner, more organized project structure that is easier for new developers to understand.
### 4. Enhance Robustness and Error Handling
- **Issue:** The agent loading in `trade_executor.py` relies on discovering environment variables by a naming convention (`_AGENT_PK`). This is clever but can be brittle if environment variables are named incorrectly.
- **Proposal:**
- Explicitly define the agent names and their corresponding environment variable keys in the proposed `_data/config.json` file. The `trade_executor` would then load only the agents specified in the configuration.
- **Benefit:** Makes agent configuration more explicit and less prone to errors from stray environment variables.
---
## Identified Unused/Utility Files
The following files were identified as likely being unused by the core application, being obsolete, or serving as one-off utilities. It is recommended to **move them to a `scripts/` directory** or **delete them** if they are obsolete.
### Obsolete / Old Versions:
- `data_fetcher_old.py`
- `market_old.py`
- `base_strategy.py` (The one in the root directory; the one in `strategies/` is used).
### One-Off Utility Scripts (Recommend moving to `scripts/`):
- `!migrate_to_sqlite.py`
- `import_csv.py`
- `del_market_cap_tables.py`
- `fix_timestamps.py`
- `list_coins.py`
- `create_agent.py`
### Examples / Unused Code:
- `basic_ws.py` (Appears to be an example file).
- `backtester.py`
- `strategy_sma_cross.py` (A strategy file in the root, not in the `strategies` folder).
- `strategy_template.py`
### Standalone / Potentially Unused Core Files:
The following files seem to have their logic already integrated into the main multi-process application. They might be remnants of a previous architecture and may not be needed as standalone scripts.
- `address_monitor.py`
- `position_monitor.py`
- `trade_log.py`
- `wallet_data.py`
- `whale_tracker.py`
### Data / Log Files (Recommend archiving or deleting):
- `hyperliquid_wallet_data_*.json` (These appear to be backups or logs).

Submodule sdk/hyperliquid-python-sdk deleted from 64b252e99d