Automated staking system for Bittensor subnets that analyzes subnet metrics, calculates optimal staking targets, and executes staking transactions based on configurable strategies.
- Comprehensive Analysis: Detailed metrics calculation for subnet analysis
- Strategy-Based Decisions: YAML-configurable strategies (conservative, aggressive, custom)
- Safe Execution: Dry-run mode, confirmation prompts, and transaction safety checks
- Historical Caching: Optional SQLite cache for tracking subnet metrics over time
- User-Friendly CLI: Rich terminal interface with clear output and progress indicators
# Create virtual environment
python -m venv venv
source ./venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt && python cli.py# Analyze subnet 0 and show top 10 targets
python cli.py analyze --netuid 0 --top-n 10
# Use a strategy for scoring
python cli.py analyze --netuid 0 --strategy strategies/conservative.yaml# Simulate staking without executing transactions
python cli.py stake --netuid 0 --strategy strategies/conservative.yaml --dry-run# Execute staking with confirmation prompt
python cli.py stake --netuid 0 --strategy strategies/conservative.yaml
# Skip confirmation (use with caution!)
python cli.py stake --netuid 0 --strategy strategies/conservative.yaml --yes# View current staking status
python cli.py status --netuid 0bittensor-auto-staker/
├── core/
│ ├── analyzer.py # Subnet metrics calculation and analysis
│ ├── strategist.py # Makes staking decisions based on strategy
│ └── executor.py # Signs & sends staking transactions safely
├── data/
│ └── historical/ # SQLite cache for subnet metrics (optional)
├── strategies/
│ ├── conservative.yaml # Conservative strategy (high trust, lower risk)
│ └── aggressive.yaml # Aggressive strategy (high emission, higher risk)
├── cli.py # User-friendly CLI interface
├── requirements.txt
├── README.md
└── tests/
Strategies are defined in YAML files. See strategies/conservative.yaml and strategies/aggressive.yaml for examples.
-
weights: Scoring weights for different metrics
emission: Weight for emission-based scoringtrust: Weight for trust-based scoringvalidator_bonus: Bonus score for validators
-
filters: Criteria to exclude neurons
min_stake: Minimum existing stake to considermax_stake: Maximum stake thresholdexclude_immune: Exclude immune neuronsexclude_duplicate_ip: Exclude duplicate IP addressesmin_trust: Minimum trust scoremin_emission: Minimum emission threshold
-
allocation: How to distribute stakes
max_targets: Maximum number of targetsmin_stake_per_target: Minimum TAO per targetmax_stake_per_target: Maximum TAO per targetallocation_method:equal,proportional, ortop_n
-
rebalancing: When to rebalance
rebalance_threshold: Drift threshold for rebalancingrebalance_interval_blocks: Minimum blocks between rebalances
Create a new YAML file in the strategies/ directory:
name: my_custom_strategy
description: "My custom staking strategy"
weights:
emission: 1.5
trust: 1.0
validator_bonus: 0.3
filters:
min_stake: 50.0
max_stake: 5000.0
exclude_immune: false
exclude_duplicate_ip: true
min_trust: 0.2
min_emission: 0.01
max_targets: 8
min_stake_per_target: 20.0
max_stake_per_target: 1000.0
allocation_method: proportional
rebalance_threshold: 0.15
rebalance_interval_blocks: 1500
max_total_stake_ratio: 0.85
require_confirmation: trueAnalyze subnet metrics without executing any staking.
python cli.py analyze [OPTIONS]Options:
--netuid: Subnet UID (default: 0)--strategy: Strategy file path (optional, for scoring)--top-n: Number of top targets to display (default: 10)--skip-registration: Skip registration block queries (faster)
Execute staking based on strategy configuration.
python cli.py stake [OPTIONS]Options:
--netuid: Subnet UID (default: 0)--strategy: Strategy YAML file path (required)--dry-run: Simulate without executing transactions--yes: Skip confirmation prompt (use with caution!)--wait: Wait for transaction inclusion (default: True)--skip-registration: Skip registration block queries (faster)
Show current staking status and summary.
python cli.py status [OPTIONS]Options:
--netuid: Subnet UID (default: 0)
Quick platform check: connectivity, chain, TAO price, and subnet hyperparameters. Uses a lite metagraph sync, so it finishes in seconds.
python cli.py check platform [--netuid 0]Options:
--netuid: Subnet UID for hyperparameters (default: 0)
Example output: chain endpoint, current block, TAO price, plus tempo, immunity_period, neurons, and validators for the chosen subnet.
- Dry Run Mode: Test strategies without executing transactions
- Confirmation Prompts: Require explicit confirmation before transactions
- Balance Checks: Verify sufficient balance before transactions
- Transaction Limits: Configurable min/max amounts
- Strategy Validation: Validate strategy configuration before execution
# Analyze with conservative strategy
python cli.py analyze --netuid 0 --strategy strategies/conservative.yaml
# Dry run
python cli.py stake --netuid 0 --strategy strategies/conservative.yaml --dry-run
# Execute
python cli.py stake --netuid 0 --strategy strategies/conservative.yaml# Analyze with aggressive strategy
python cli.py analyze --netuid 1 --strategy strategies/aggressive.yaml --top-n 20
# Execute (aggressive strategy has require_confirmation: false, so use --yes carefully)
python cli.py stake --netuid 1 --strategy strategies/aggressive.yaml --yes# Use custom network endpoint
python cli.py analyze --netuid 0 --subtensor.network finney --strategy strategies/conservative.yamlHistorical metrics are optionally cached in SQLite for analysis:
- Location:
data/historical/metrics.db - Automatically created on first use
- Can be cleared with cache management (future feature)
python -m pytest tests/black .pre-commit install
pre-commit run --all-files- This tool executes real transactions on the Bittensor blockchain. Always test with
--dry-runfirst. - Start with small amounts to verify behavior before large transactions.
- Review strategy configurations carefully before execution.
- Monitor your positions regularly and adjust strategies as needed.
- No guarantees - subnet performance can change, and decisions are based on historical data.
- Use at your own risk - the authors are not responsible for any losses.
Contributions are welcome! Please:
- Use pre-commit hooks (black, etc.)
- Add tests for new features
- Update documentation
- Submit a PR with clear description
See LICENSE file.
The core analysis functionality is implemented in core/analyzer.py.