A perpetual contracts trading bot for Aster Perp Dex, featuring built-in trend-following (SMA30) and market-making strategies. Powered by real-time WebSocket data, a reactive CLI dashboard (Ink), and automatic recovery from disconnects.
📡 Live Market Data — WebSocket streaming with REST fallbacks + auto resync
📈 Trend Following — SMA30 crossovers, auto stop-loss & trailing-stop, P&L tracking
⚖️ Market Making — Adaptive bid/ask chasing, order inspection, and risk stops
🧩 Modular Design — Gateways, engines, and UI are pluggable for easy extension
Bun ≥ 1.2
Node.js (optional, for npm users) Aster API key/secret with futures trading enabled
Create an .env
file (or export environment variables) with at least:
ASTER_API_KEY=your_key
ASTER_API_SECRET=your_secret
TRADE_SYMBOL=BTCUSDT # optional, defaults to BTCUSDT
TRADE_AMOUNT=0.001 # position size used by both strategies
LOSS_LIMIT=0.03 # per-trade USD loss cap
TRAILING_PROFIT=0.2 # trailing activation profit in USDT
TRAILING_CALLBACK_RATE=0.2 # trailing callback in percent, e.g. 0.2 => 0.2%
PROFIT_LOCK_TRIGGER_USD=0.1 # profit threshold to start moving base stop (USDT)
PROFIT_LOCK_OFFSET_USD=0.05 # base stop offset from entry after trigger (USDT)
PRICE_TICK=0.1 # price tick size; set per symbol
QTY_STEP=0.001 # quantity step size; set per symbol
Additional maker-specific settings (MAKER_*
) are in src/config.ts
and can be overridden via environment variables:
# Maker-specific (units in USDT unless noted)
MAKER_LOSS_LIMIT=0.03 # override maker risk stop; defaults to LOSS_LIMIT
MAKER_PRICE_CHASE=0.3 # chase threshold
MAKER_BID_OFFSET=0 # bid offset from top bid (USDT)
MAKER_ASK_OFFSET=0 # ask offset from top ask (USDT)
MAKER_REFRESH_INTERVAL_MS=1500 # maker refresh cadence (ms)
MAKER_MAX_CLOSE_SLIPPAGE_PCT=0.05 # allowed deviation vs mark when closing
MAKER_PRICE_TICK=0.1 # maker tick size; defaults to PRICE_TICK
bun run index.ts # or: bun run dev / bun run start
Select a strategy using arrow keys. Press Esc
to return to the menu. The dashboard displays live order books, holdings, pending orders, and recent events. All state is synchronized with exchange data and automatically restored on restart.
bun run test # bun x vitest run
bun run test:watch # stay in watch mode
Current tests cover order coordinator utilities and strategy helpers. Add unit tests alongside new modules as you extend the system.
src/config.ts
– shared runtime configurationsrc/core/
– trend & maker engines plus order coordinationsrc/exchanges/
– Aster REST/WS gateway and adapterssrc/ui/
– Ink components and strategy dashboardssrc/utils/
– math helpers and strategy utilitiestests/
– Vitest test suites for critical modules
🔁 Reconnect loops → Check access to wss://fstream.asterdex.com/ws and REST
PRs and issues are welcome! When adding strategies or new exchanges:
- Follow modular patterns in src/core
- Add matching tests in tests/