Skip to content

HTX-Trading-ToolKit/HTX-human-elite-copy-trading-bot

Repository files navigation

HTX Human Elite Copy Trading Bot

A production-grade TypeScript bot that mirrors HTX (Huobi) human elite lead traders on USDT-margined linear swap futures. It watches configured elite traders, detects position changes in real time, and copies trades using Smart Copy (proportional to leader fund usage), Fixed Ratio, or Elite Sentiment strategies — with full risk controls and paper trading.

Features

  • Human Elite Copy Trading — Follow multiple HTX lead traders and mirror their futures positions automatically
  • Smart Copy Mode — HTX Copy Trading 4.0–style proportional sizing based on leader AUM vs. exposure ratio
  • Fixed Ratio Mode — Copy a fixed percentage of leader contract volume
  • Elite Sentiment Mode — Trade using HTX public elite trader sentiment indices (swap_elite_account_ratio, swap_elite_position_ratio)
  • Paper Trading — Full simulation engine with mock elite traders for risk-free testing
  • Live Trading — Direct HTX USDT linear swap API integration with HMAC-SHA256 signing
  • Risk Management — Stop loss, take profit, max position size, max daily loss, max open positions
  • State Persistence — Resume leader snapshots and trade counts across restarts
  • Graceful Shutdown — Persists state on SIGINT/SIGTERM
  • Structured Logging — Pino-based logging with configurable levels
  • Type-Safe Config — Zod schema validation for all environment variables

How Copy Trading Works

Elite Lead Trader                Copy Engine                    Your Account
─────────────────               ─────────────                  ──────────────
Opens BTC-USDT LONG    ──▶   Detect position change    ──▶   Mirror LONG
  20 contracts @ 5x           Calculate smart volume          (proportional)
Adjusts to 30 contracts ──▶  Delta = +10 contracts    ──▶   Add to position
Closes position        ──▶   Detect close event       ──▶   Close yours

Smart Copy calculates your order size so your exposure ratio matches the leader's fund usage — the same principle as HTX Smart Copy mode.

Elite Sentiment uses HTX's public top-trader sentiment API when you prefer aggregate elite bias over following a specific trader.

Project Structure

HTX-human-elite-copy-trading-bot/
├── src/
│   ├── cli/              # CLI entry (start, validate, leaders, sentiment, dry-run)
│   ├── config/           # Zod-validated environment configuration
│   ├── core/             # Copy engine — leader diffing and trade execution
│   ├── exchange/         # HTX API client, paper simulator, leader feed
│   ├── risk/             # Stop loss, take profit, position limits
│   ├── services/         # Bot orchestration and state persistence
│   ├── strategies/       # Smart copy, fixed ratio, elite sentiment logic
│   ├── types/            # Shared TypeScript interfaces
│   └── utils/            # Logger, retry, formatting helpers
├── tests/                # Unit and integration tests (Vitest)
├── .env.example          # Environment variable template
├── package.json
└── tsconfig.json

Quick Start

Prerequisites

  • Node.js 18 or higher
  • npm 9 or higher
  • HTX account with API key enabled for futures (for live trading)

Setup

cd HTX-human-elite-copy-trading-bot
npm install
cp .env.example .env

Edit .env with your configuration:

HTX_API_KEY=your_api_key_here
HTX_API_SECRET=your_api_secret_here
CONTRACT_CODE=BTC-USDT
LEAD_TRADER_IDS=elite_alpha,elite_beta
COPY_MODE=smart
LEVERAGE=5
PAPER_TRADING=true

Validate Configuration

npm run dev -- validate

List Elite Lead Traders

npm run dev -- leaders

Check Elite Trader Sentiment

npm run dev -- sentiment

Dry Run (Single Poll Cycle)

npm run dev -- dry-run

Start the Bot (Paper Trading)

npm run dev -- start

Start the Bot (Live Trading)

Set PAPER_TRADING=false in .env, then:

npm run build
npm start -- start

Configuration Reference

Variable Description Default
HTX_API_KEY HTX API access key
HTX_API_SECRET HTX API secret key
CONTRACT_CODE USDT linear swap pair (e.g. BTC-USDT) BTC-USDT
LEAD_TRADER_IDS Comma-separated elite trader IDs
COPY_MODE smart, fixed, or elite_sentiment smart
COPY_RATIO Fixed copy ratio (when COPY_MODE=fixed) 0.1
MAX_EQUITY_PER_TRADE Max equity fraction per copied trade 0.05
LEVERAGE Leverage for copied positions 5
ACCOUNT_BALANCE_USDT Paper trading starting balance 10000
MAX_POSITION_USDT Max notional per position 5000
STOP_LOSS_PERCENT Auto-close at this loss % 5
TAKE_PROFIT_PERCENT Auto-close at this profit % 15
MAX_DAILY_LOSS_USDT Halt copying after daily loss 500
MAX_OPEN_POSITIONS Max simultaneous positions 3
ELITE_SENTIMENT_PERIOD Sentiment candle period 60min
ELITE_LONG_THRESHOLD Go long above this buy ratio 0.55
ELITE_SHORT_THRESHOLD Go short below this buy ratio 0.45
PAPER_TRADING true for simulation true
POLL_INTERVAL_MS Leader poll interval (ms) 10000
USE_TESTNET Use HTX testnet endpoint false
LOG_LEVEL trace / debug / info / warn / error info

CLI Commands

Command Description
start Start the copy trading bot
validate Validate .env configuration
leaders List configured elite lead traders
sentiment Show HTX elite trader sentiment
dry-run Run one poll cycle and show stats

Copy Mode Selection Guide

Goal Recommended Mode Settings
Mirror specific elite traders smart Set LEAD_TRADER_IDS, tune MAX_EQUITY_PER_TRADE
Simple proportional copy fixed Set COPY_RATIO=0.1 (10% of leader volume)
Follow aggregate elite bias elite_sentiment Tune ELITE_LONG_THRESHOLD / ELITE_SHORT_THRESHOLD

Development

# Run tests
npm test

# Type checking
npm run typecheck

# Lint
npm run lint

# Development mode
npm run dev -- start

Risk Disclaimer

Cryptocurrency futures trading involves substantial risk of loss, including the possibility of losing more than your initial investment through leverage. Copy trading does not guarantee the same results as elite lead traders. This bot is provided as-is with no guarantees of profitability. Always test thoroughly in paper trading mode before deploying real funds. Never invest more than you can afford to lose.

License

MIT


💬 Technical Support

👉 Telegram: @tradingtermin

Need help with setup, configuration, or troubleshooting?

Contact @tradingtermin on Telegram for:

🔧 Installation and configuration help
📊 Copy strategy tuning and elite trader selection
🐛 Bug reports and feature requests
🚀 Live trading setup guidance

@tradingtermin · t.me/tradingtermin

About

HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot HTX Human Elite Copy Trading Bot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors