Skip to content

Repository files navigation

Predator Crypto

Python 3.10+ Docker License: MIT

Automated institutional-grade cryptocurrency DCA (Dollar-Cost Averaging) and mean-reversion trading bot built in Python for Alpaca Markets. Implements technical entry signals based on Bollinger Band volatility squeezes and RSI indicators, paired with dynamic equity-based position sizing, multi-level safety orders, and strict risk circuit breakers.


How It Works

Predator Crypto operates as an autonomous, 24/7 trading engine designed to exploit mean-reversion bounces during market dips while strictly protecting capital.

WebSocket Price Tick (Alpaca)
       │
       ▼
 ┌──────────────────────┐
 │ Has Open DCA Cycle?  │
 └──────────┬───────────┘
            │
      ┌─────┴─────────────────────────────────┐
      │ YES                                   │ NO
      ▼                                       ▼
┌─────────────────────────────┐   ┌─────────────────────────────┐
│ Evaluate DCA Cycle (V6):    │   │ Evaluate Entry Signals:     │
│ • Price >= +1.5% TP         │   │ • 15-min Candle Close       │
│ • Trailing Exit (0.3% dip)  │   │ • Close < Lower BB (14/1.5) │
│ • Next Safety Order Dip:    │   │ • RSI (14) < 45             │
│   Level 1: -2.5% (1.5x)    │   │ • Cooldown: 30 min / pair   │
│   Level 2: -6.0% (2.25x)   │   │ • Active Pairs < MAX_PAIRS  │
│   Level 3: -12.0% (3.375x) │   │ • Kill-Switch Check         │
│ • Hard Stop: -10.0%         │   └──────────────┬──────────────┘
│ • Timeout: 72 Hours         │                  │
└─────────────┬───────────────┘                  ▼
              │                   ┌─────────────────────────────┐
              ▼                   │ Dynamic Position Sizing:    │
┌─────────────────────────────┐   │ • Base Order: 10% of Equity │
│ Order Execution (IOC):      │   │ • Max Exposure Cap: 60%     │
│ • Immediate Or Cancel       │   └──────────────┬──────────────┘
│ • Zero Frozen Buying Power  │                  │
│ • State Synced to SQLite    │◄─────────────────┘
└─────────────────────────────┘

1. High-Probability Entry Signals

The signal engine evaluates 15-minute bars in real time using two complementary indicators:

  • Bollinger Band Squeeze: Price breaks outside the lower band (14 periods, 1.5 standard deviations), identifying extreme price displacement.
  • RSI Oversold Filter: The 14-period RSI must read below 45, confirming that selling momentum is exhausted before entering.

2. Dynamic Equity-Based Position Sizing

Order sizes are never hardcoded. Each base order dynamically allocates 10% of total live account equity at the time of execution, compounding automatically as the account grows. Global portfolio risk is capped at a strict 60% maximum exposure limit across all open positions.

3. Logarithmic DCA Safety Grid

If the market drops after the initial entry, Predator Crypto executes disciplined safety orders to move the average entry price aggressively toward the bounce zone:

  • Safety Level 1: -2.5% dip from average entry (1.5× base order volume)
  • Safety Level 2: -6.0% dip from average entry (2.25× base order volume)
  • Safety Level 3: -12.0% dip from average entry (3.375× base order volume)

4. Fast-Turnaround Take Profit & Trailing Exit

  • Take Profit Target: Automatically exits the entire accumulated position when profit reaches +1.5% over the blended average entry price.
  • Trailing Stop: Activates once the position exceeds +1.5% and locks in profit if the price retraces by 0.3% from its peak, capturing extra upside during strong green candles.

5. Immediate Or Cancel (IOC) Execution

All market orders are dispatched using Alpaca's TimeInForce.IOC (Immediate Or Cancel). Unlike bots that leave passive limit orders hanging in the order book, Predator Crypto never freezes account buying power on illiquid or fractional crypto orders.

6. Background Janitor & Self-Healing State Recovery

  • State Recovery on Startup: If the bot restarts or reboots, it inspects live open positions in Alpaca, binds them to their SQLite trade history, and adopts Alpaca's authoritative avg_entry_price as the source of truth so ongoing trades exit smoothly at their true Take Profit levels.
  • Order Janitor: A background thread runs every 5 minutes to audit and clear any stale or orphaned order states.

7. Multi-Layer Risk Circuit Breakers

  • Daily Drawdown Kill-Switch: Halts all new trading if total account equity drops by 5% in a single day.
  • Hard Stop Loss: Emergency liquidation at -10% position drawdown.
  • Cycle Timeout: Positions open longer than 72 hours without resolution are closed to liberate capital.

Project Structure

Predator-Crypto/
├── main.py                         # Application entrypoint & main loop
├── check_status.py                 # Live account equity and position diagnostics
├── Dockerfile                      # Production container image
├── docker-compose.yml              # Container orchestration configuration
├── requirements.txt                # Python dependencies
├── .env.example                    # Environment variable configuration template
├── config/
│   └── settings.py                 # Core configuration and risk parameters
└── core/
    ├── feed_alpaca.py              # Alpaca WebSocket market data stream
    ├── institutional_signals.py    # Bollinger Squeeze & RSI signal evaluation
    ├── dca_engine.py               # DCA position and safety order tracking
    ├── api_bridge.py               # REST execution wrapper & background janitor
    ├── risk_manager.py             # Dynamic equity position sizing
    ├── kill_switch.py              # Equity drawdown protection
    ├── trade_memory.py             # Local SQLite database logger
    ├── auth_alpaca.py              # Alpaca API authentication factory
    ├── notifier.py                 # Telegram notification integration
    ├── sentiment_scraper.py        # Market sentiment scoring
    ├── telemetry.py                # Optional Supabase telemetry
    └── reinforcement_learning.py   # RL-based parameter optimizer

Watchlist

Predator Crypto actively monitors and trades cryptocurrency pairs configured via the CRYPTO_WATCHLIST environment variable. The default watchlist includes:

  • BTC/USD (Bitcoin)
  • ETH/USD (Ethereum)
  • SOL/USD (Solana)
  • AVAX/USD (Avalanche)
  • DOGE/USD (Dogecoin)

To customize, set CRYPTO_WATCHLIST=BTC/USD,ETH/USD,SOL/USD in your .env file.


Quick Start

Option A: Local Python Environment

1. Clone the repository

git clone https://github.com/Robertedilan/The_Predator.Crypto.git
cd The_Predator.Crypto

2. Install dependencies

pip install -r requirements.txt

3. Configure environment variables

Copy .env.example to .env and fill in your Alpaca API credentials:

cp .env.example .env
ALPACA_API_KEY=your_alpaca_key
ALPACA_SECRET_KEY=your_alpaca_secret
ALPACA_PAPER=true
BASE_ORDER_PCT=0.10
MAX_EXPOSURE_PCT=0.60
CRYPTO_WATCHLIST=BTC/USD,ETH/USD,SOL/USD,AVAX/USD,DOGE/USD

4. Run the bot

python main.py

Option B: Docker Container

Run Predator Crypto inside a container for isolated, background deployment:

# Build and run with Docker Compose
docker compose up -d

# View live logs
docker compose logs -f

# Stop the container
docker compose down

Diagnostic Tool

Check live account equity, cash balance, and open position PnL at any time:

python check_status.py

Support

If this project is helpful to you, consider supporting via the Sponsor button at the top of this page. ☕


License

Distributed under the MIT License.


Disclaimer

This software is provided for educational and experimental purposes. Cryptocurrency trading involves substantial risk of financial loss. Always test thoroughly in paper trading before operating with live funds.

About

Autonomous Institutional DCA & Crypto Sniper Trading Engine in Python (Bollinger + RSI)

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages