Perp Dex Trading Bot
About A Bun-powered trading workstation for Aster and Hyperliquid perpetual contracts that ships two production-ready agents: an SMA30 trend follower and a dual-sided market maker. The CLI is built with Ink, synchronises risk state from the exchange, and automatically recovers from restarts or disconnects.perpetual - perp dex trading bot
Install / Use
npx skills add 0xagarg/perp-dex-trading-botInstalls into whichever agent you are using.
README
Aster & HL Trading Bot
A Bun-powered trading workstation for Aster and Hyperliquid perpetual contracts that ships two production-ready agents: an SMA30 trend follower and a dual-sided market maker. The CLI is built with Ink, synchronises risk state from the exchange, and automatically recovers from restarts or disconnects.
- Aster 30% Fee Discount Referral Link
- GRVT Fee Discount Referral Link
- Hyperliquid Fee Discount Referral Link
Highlights
- Live market data & risk sync via websocket feeds with REST fallbacks, full reconciliation on restart.
- Trend engine featuring SMA30 entries, fixed stop loss, trailing stop, Bollinger bandwidth gate, and profit-lock stepping.
- Market-making loop with adaptive quote chasing, loss caps, and automatic order healing.
- Extensible architecture decoupling exchange adapters, engines, and the Ink CLI for easy venue or strategy additions.
- Multi-exchange support for AsterDex, GRVT, and Hyperliquid exchanges.
Requirements
- Bun ≥ 1.2 (
bun,bunxavailable on PATH) - macOS, Linux, or Windows via WSL (native Windows works but WSL is recommended)
- Node.js is optional unless your environment requires it for tooling
One-Line Bootstrap (macOS / Linux / WSL)
curl -fsSL https://github.com/mooncity/asterdex-hl-trading-bot/raw/refs/heads/main/setup.sh | bash
The script installs Bun, project dependencies, collects Aster API credentials, generates .env, and launches the CLI. Prepare your API Key/Secret before running.
Manual Installation
- Clone the repository
Alternatively download the ZIP from GitHub and extract it manually.git clone https://github.com/mooncitydev/asterdex-hl-trading-bot.git cd asterdex-hl-trading-bot - Install Bun
- macOS / Linux:
curl -fsSL https://bun.sh/install | bash - Windows PowerShell:
powershell -c "irm bun.sh/install.ps1 | iex"Re-open the terminal and confirmbun -vprints a version.
- macOS / Linux:
- Install dependencies
bun install - Create your environment file
Editcp .env.example .env.envwith your exchange credentials and overrides. - Launch the CLI
Use the arrow keys to pick a strategy,bun run index.tsEnterto start,Escto return to the menu, andCtrl+Cto exit.
Environment Variables
The most important settings shipped in .env.example are summarised below:
| Variable | Purpose |
| --- | --- |
| ASTER_API_KEY / ASTER_API_SECRET | Required Aster exchange credentials |
| TRADE_SYMBOL | Contract symbol, defaults to BTCUSDT |
| TRADE_AMOUNT | Order size in base asset units |
| LOSS_LIMIT | Max per-trade loss (USDT) before forced close |
| TRAILING_PROFIT / TRAILING_CALLBACK_RATE | Trailing stop trigger amount (USDT) and pullback percentage |
| PROFIT_LOCK_TRIGGER_USD / PROFIT_LOCK_OFFSET_USD | Move the base stop once unrealised PnL exceeds this trigger |
| BOLLINGER_LENGTH / BOLLINGER_STD_MULTIPLIER | Window size and std-dev multiplier for bandwidth filtering |
| MIN_BOLLINGER_BANDWIDTH | Minimum bandwidth ratio required before opening a new position |
| PRICE_TICK / QTY_STEP | Exchange precision filters for price and quantity |
| POLL_INTERVAL_MS | Trend engine polling cadence in milliseconds |
| MAX_CLOSE_SLIPPAGE_PCT | Allowed deviation vs mark price when closing |
| MAKER_* | Maker strategy knobs: chase threshold, quote offsets, refresh cadence, etc. |
Exchange Configuration
AsterDex (Default)
EXCHANGE=aster
ASTER_API_KEY=your_aster_api_key
ASTER_API_SECRET=your_aster_api_secret
GRVT
EXCHANGE=grvt
GRVT_API_KEY=your_grvt_api_key
GRVT_API_SECRET=your_grvt_wallet_secret
GRVT_SUB_ACCOUNT_ID=your_trading_account_id
Hyperliquid
EXCHANGE=hyperliquid
HYPERLIQUID_WALLET_ADDRESS=your_wallet_address
HYPERLIQUID_PRIVATE_KEY=your_private_key
To trade on other exchanges, set EXCHANGE=grvt or EXCHANGE=hyperliquid and populate the respective credentials documented in .env.example.
Common Commands
bun run index.ts # Launch the CLI
bun run start # Same as above
bun run dev # Development entry point
bun x vitest run # Execute the Vitest suite
Silent & Background Execution
Direct silent launch
Skip the Ink menu and start a strategy straight from the CLI:
bun run index.ts --strategy trend --silent # Trend engine
bun run index.ts --strategy maker --silent # Maker engine
bun run index.ts --strategy offset-maker --silent # Offset maker engine
Package scripts
Convenience aliases are exposed in package.json:
bun run start:trend:silent
bun run start:maker:silent
bun run start:offset:silent
Daemonising with pm2
Install pm2 locally (e.g. bun add -d pm2) and launch without a global install:
bunx pm2 start bun --name aster-hl-trend --cwd . --restart-delay 5000 -- run index.ts --strategy trend --silent
You can also reuse the bundled scripts:
bun run pm2:start:trend
bun run pm2:start:maker
bun run pm2:start:offset
Adjust --name, --cwd, or --restart-delay to suit your environment and run pm2 save if you want the process to auto-start after reboot.
Testing
Vitest powers the unit tests:
bun run test
bun x vitest --watch
Troubleshooting
- You need at least 50–100 USDT of capital before deploying a live strategy.
- Set leverage on the exchange beforehand (around 50x is recommended); the bot does not change it for you.
- Keep server/desktop time in sync with real-world time to avoid signature errors.
- Make sure the exchange account is in one-way position mode.
- Env not loading: ensure
.envresides in the repository root and variable names are spelled correctly. - Order rejected for precision: align
PRICE_TICK,QTY_STEP, andTRADE_SYMBOLwith the exchange filters. - Permission or auth errors: double-check exchange API scopes.
- Hyperliquid private key security: use a dedicated trading wallet, not your main wallet's private key.
Disclaimer
Algorithmic trading carries risk. Validate strategies with paper accounts or small capital first, safeguard your API keys, and only grant the minimum required permissions.
Related Skills
node-connect
385.5kDiagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
blender-python-addon
40.5kBlender Python add-on rules for operators, panels, properties, registration, testing, and API-safe scripting
flutter-development-guidelines-cursorrules-prompt-file
40.5kCursor rules for Flutter development with MVVM architecture, Riverpod state management, Material widgets, and Dart style guidelines.
commit-push-pr
140.6kCommit, push, and open a PR
