A complete trading system for Bittensor subnet alpha tokens with two complementary bots:
Dollar Cost Averaging bot that buys alpha when prices are favorable.
Smart selling bot that unstakes alpha when prices reach profit targets.
- Smart DCA Strategy: Buys a fixed TAO amount (e.g., 0.01 TAO) at regular intervals (e.g., every 5 minutes)
- Price-Based Filtering: Only buys when alpha price is at or below your threshold (e.g., β€0.05 TAO)
- Accumulation Focus: Builds alpha positions during favorable market conditions
- Smart Profit-Taking: Sells fixed alpha amounts (e.g., 0.1 alpha) when price reaches targets (e.g., β₯0.08 TAO)
- Position Management: Maintains minimum holdings while taking profits
- High-Price Alerts: Only sells when profitable price thresholds are met
- Single Subnet Focus: Both bots concentrate on one subnet you choose
- Enhanced Logging: Shows every trade with real-time session statistics
- Session Analytics: Tracks performance, averages, and totals for each bot
- Network Resilience: Auto-reconnects and retries on connection issues
- Session Summaries: Provides complete analytics when stopped
- Secure Password Handling: Manual entry with memory cleanup
-
Install dependencies:
cd SubnetsBot pip install -r requirements.txt -
Configure both bots:
DCA Bot - Edit
dca_config.yaml:validator: "your_validator_hotkey_ss58_here" # β REPLACE THIS target_netuid: 1 # Choose your subnet purchase_amount: 0.01 # TAO amount per purchase interval_seconds: 5 # How often to buy min_balance: 0.5 # Stop when wallet hits this balance max_price_threshold: 0.05 # Only buy if price β€ 0.05 TAO per alpha
Unstaking Bot - Edit
unstaking_config.yaml:validator: "your_validator_hotkey_ss58_here" # β SAME AS ABOVE target_netuid: 1 # Same subnet as DCA bot unstake_amount: 0.1 # Alpha amount per sale interval_seconds: 10 # How often to check for selling min_price_threshold: 0.08 # Only sell if price β₯ 0.08 TAO per alpha min_holdings_threshold: 0.5 # Never sell below this amount
-
Run the bots:
DCA Bot (in one terminal):
python dca_bot.py
Unstaking Bot (in another terminal):
python unstaking_bot.py
Both bots will prompt you to enter your wallet password securely:
π Enter wallet password: [type your password here]
Alternative (Less Secure): You can optionally set an environment variable:
export WALLET_PASSWORD="your_wallet_password" python dca_bot.py # or unstaking_bot.py
β οΈ Not recommended on shared/rented servers due to security risks.
# DCA Bot - Buy Low
max_price_threshold: 0.05 # Buy below 0.05 TAO
purchase_amount: 0.01 # Spend 0.01 TAO per purchase
# Unstaking Bot - Sell High
min_price_threshold: 0.08 # Sell above 0.08 TAO
unstake_amount: 0.1 # Sell 0.1 alpha per saleProfit Margin: 60% (0.08/0.05 = 1.6x)
This setup automatically:
- π Accumulates alpha when price β€ 0.05 TAO
- π Takes profits when price β₯ 0.08 TAO
- π Compounds gains through both price appreciation and position building
π Initializing DCA Bot...
π Enter wallet password: [hidden input]
β
Wallet 'default' loaded successfully
β
Connected to Bittensor network (Block: 1234567)
DCA Bot Configuration
π― Target Subnet: 1
π° Purchase Amount: 0.0100 TAO per trade
β° Interval: 5 minutes
π Stop Balance: 0.5000 TAO
π² Max Price: 0.050000 TAO per alpha
π Validator: 5HYjn...
π³ Starting Wallet Balance: 5.2500 TAO
πͺ Current Alpha Holdings: 0.125000 alpha
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βΈοΈ Price too high: 0.550000 TAO > 0.050000 TAO threshold
π‘ Waiting for better price. Current: 0.550000 TAO, Target: β€0.050000 TAO
β³ Waiting 5 minutes until next purchase...
π Attempting purchase: 0.0100 TAO β 0.200000 alpha @ 0.050000 TAO/alpha
π’ TRADE #1 | 2024-01-15 14:30:25
π° Bought: 0.018182 alpha for 0.0100 TAO
π Price: 0.550000 TAO per alpha
π Avg Price: 0.550000 TAO per alpha
π Total Invested: 0.010000 TAO
πͺ Total Holdings: 0.143182 alpha
π³ Wallet Balance: 5.2400 TAO
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β³ Waiting 5 minutes until next purchase...
### **Unstaking Bot Output:**
π Initializing Unstaking Bot... π Enter wallet password: [hidden input] β Wallet 'default' loaded successfully β Connected to Bittensor network (Block: 1234567)
Unstaking Bot Configuration π― Target Subnet: 1 πͺ Unstake Amount: 0.100000 alpha per trade β° Interval: 10 minutes π² Min Price: 0.080000 TAO per alpha πͺ Min Holdings: 0.500000 alpha π Validator: 5HYjn...
π³ Starting Wallet Balance: 2.1500 TAO πͺ Current Alpha Holdings: 1.425000 alpha ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βΈοΈ Price too low: 0.065000 TAO < 0.080000 TAO threshold π‘ Waiting for higher price. Current: 0.065000 TAO, Target: β₯0.080000 TAO β³ Waiting 10 minutes until next check...
π Attempting sale: 0.100000 alpha β 0.008000 TAO @ 0.080000 TAO/alpha π΄ SALE #1 | 2024-01-15 15:45:25 π° Sold: 0.100000 alpha for 0.008000 TAO π Price: 0.080000 TAO per alpha π Avg Price: 0.080000 TAO per alpha π Total Earned: 0.008000 TAO πͺ Remaining Holdings: 1.325000 alpha π³ Wallet Balance: 2.1580 TAO ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β³ Waiting 10 minutes until next check...
- Wallet balance drops below
min_balance - You press Ctrl+C
- Insufficient funds for next purchase
- You press Ctrl+C
- Network connection issues (with auto-retry)
- No alpha holdings to sell
π DCA Session Summary
βββββββββββββββββββββββ¬ββββββββββββββββββββββ
β π― Target Subnet β 1 β
β β±οΈ Session Duration β 2h 15m 30s β
β π’ Total Trades β 27 β
β π° Total TAO Investedβ 0.270000 β
β πͺ Total Alpha Boughtβ 0.491818 β
β π Average Price Paidβ 0.549130 β
β π Price Change β +2.45% β
βββββββββββββββββββββββ΄ββββββββββββββββββββββ
π Trade History
# 1 | 2024-01-15 14:30:25 | 0.018182 alpha @ 0.550000 TAO | Spent: 0.0100 TAO
# 2 | 2024-01-15 14:35:25 | 0.018519 alpha @ 0.540000 TAO | Spent: 0.0100 TAO
# 3 | 2024-01-15 14:40:25 | 0.018182 alpha @ 0.550000 TAO | Spent: 0.0100 TAO
...
### Example Unstaking Summary:
π Unstaking Session Summary βββββββββββββββββββββββ¬ββββββββββββββββββββββ β π― Target Subnet β 1 β β β±οΈ Session Duration β 4h 20m 15s β β π’ Total Sales β 8 β β πͺ Total Alpha Sold β 0.800000 β β π° Total TAO Earned β 0.068000 β β π Average Price β 0.085000 β β π Price Change β +6.25% β βββββββββββββββββββββββ΄ββββββββββββββββββββββ
π Sales History
...
Session-Only Calculations:
π **DCA Bot**: Average price and total invested based only on current session
π **Unstaking Bot**: Average sale price and total earned based only on current session
πͺ **Total Holdings**: Your complete subnet position (includes all previous activity)
target_netuid: 1 # Which subnet to buy alpha in
purchase_amount: 0.01 # TAO amount per purchase
interval_minutes: 5 # Minutes between purchases
min_balance: 0.5 # Stop when wallet balance hits this
max_price_threshold: 0.05 # Only buy if price is β€ this value (0.0 = no limit)target_netuid: 1 # Which subnet to sell alpha from (match DCA bot)
unstake_amount: 0.1 # Alpha amount per sale
interval_minutes: 10 # Minutes between price checks
min_price_threshold: 0.08 # Only sell if price is β₯ this value (0.0 = no limit)
min_holdings_threshold: 0.5 # Never sell below this alpha amountConservative Long-Term Growth:
# DCA Bot
purchase_amount: 0.01
interval_minutes: 15
max_price_threshold: 0.03 # Buy below 0.03 TAO
min_balance: 1.0
# Unstaking Bot
unstake_amount: 0.05
interval_minutes: 30
min_price_threshold: 0.07 # Sell above 0.07 TAO
min_holdings_threshold: 1.0 # Keep substantial positionAggressive High-Frequency Trading:
# DCA Bot
purchase_amount: 0.1
interval_minutes: 3
max_price_threshold: 0.08 # Buy up to 0.08 TAO
min_balance: 0.5
# Unstaking Bot
unstake_amount: 0.2
interval_minutes: 5
min_price_threshold: 0.10 # Sell above 0.10 TAO
min_holdings_threshold: 0.2Value Hunter (Wide Margins):
# DCA Bot
purchase_amount: 0.05
interval_minutes: 30
max_price_threshold: 0.025 # Only buy very cheap
min_balance: 2.0
# Unstaking Bot
unstake_amount: 0.15
interval_minutes: 15
min_price_threshold: 0.08 # Sell for good profits
min_holdings_threshold: 0.5Emergency Mode (No Filters):
# DCA Bot - Buy at any price
max_price_threshold: 0.0
# Unstaking Bot - Sell everything
min_price_threshold: 0.0
min_holdings_threshold: 0.0Bot won't start:
- Check wallet name in config
- Verify validator hotkey is correct
- Enter correct wallet password when prompted
- Ensure wallet file exists and isn't corrupted
"Subnet not found" error:
- Verify
target_netuidexists and is active - Check Bittensor network status
"Insufficient balance" immediately:
- Check your actual wallet balance
- Lower
purchase_amountormin_balance
Connection errors:
- Check internet connection
- Wait for Bittensor network issues to resolve
- Start Small: Begin with 0.01 TAO purchases and 0.05 alpha sales to test
- Research Prices: Check historical alpha prices to set smart buy/sell thresholds
- Set Profit Margins: Ensure sell threshold > buy threshold for profitability
- Monitor First: Watch the first few cycles of both bots to ensure they work
- Secure Setup: Use manual password entry, especially on shared servers
- Coordinate Bots: Use same subnet for both bots, different intervals for balance
- Position Management: Set appropriate
min_holdings_thresholdto maintain base position - Keep Reserves: Set
min_balanceto keep some TAO for fees and opportunities - Track Performance: Review session summaries to analyze your complete trading strategy
- Complete Trading System: DCA bot buys, unstaking bot sells
- Smart Automation: Both bots use time-based AND price-based strategies
- Price Coordination: Set buy threshold < sell threshold for profitability
- Position Management: Unstaking bot preserves minimum holdings
- Always test with small amounts first
- Research price history to set appropriate thresholds
- Monitor both wallet balance and alpha holdings
- Bots can run independently or together for complete automation
- π Manual password entry: Prompts for password at startup (recommended)
- π§Ή Memory cleanup: Password cleared from memory after use
β οΈ Environment variable support: Optional but less secure on shared servers- π One-time entry: Password only needed once per session, not per trade
- β Bot startup - Enter once when starting
- β After restart - Need to re-enter if bot is restarted
- β Not during trades - All purchases happen automatically after unlock
- β Not during waits - No interruption during interval periods
- π Local development: Safest option for testing
- π Dedicated servers: Better than shared hosting
β οΈ Shared servers: Use manual password entry only- π« Avoid env vars: On rented/shared infrastructure like DATA Crunch
- π Auto-reconnection: Reconnects automatically if connection drops
- π Retry Logic: 3 attempts for all network operations with smart delays
- πͺ Continuous Operation: Bot keeps running through network hiccups
- β‘ Smart Recovery: Graceful error handling without stopping the process
- π Real-time Stats: Session average price and total invested after each trade
- πͺ Live Holdings: Shows your current total alpha position in the subnet
- π Session Analytics: Running calculations based only on current session trades
- π³ Balance Tracking: Continuous wallet balance monitoring
- β Automatic stopping when balance is low
- β Graceful shutdown with Ctrl+C
- β Comprehensive trade logging with session statistics
- β Session summaries with all transaction details
- β Error handling and recovery
- β Secure password handling with memory cleanup
π‘ Pro Tip: DCA works best over longer periods. Set it up and let it run for hours or days to smooth out price volatility!