Skip to content

A trading bot for Aster Perp DEX with SMA30 trend-following and market-making strategies. Features real-time WebSocket data, a reactive CLI dashboard, and automatic reconnect.

Notifications You must be signed in to change notification settings

keidev-sol/Perp-Trading-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Perp Trading Bot

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.

✨ Highlights

📡 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

🛠 Requirements

Bun ≥ 1.2

Node.js (optional, for npm users) Aster API key/secret with futures trading enabled

Configuration

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

Running the CLI

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.

Testing

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.

Project Structure

  • src/config.ts – shared runtime configuration
  • src/core/ – trend & maker engines plus order coordination
  • src/exchanges/ – Aster REST/WS gateway and adapters
  • src/ui/ – Ink components and strategy dashboards
  • src/utils/ – math helpers and strategy utilities
  • tests/ – Vitest test suites for critical modules

🐞 Troubleshooting

🔁 Reconnect loops → Check access to wss://fstream.asterdex.com/ws and REST ⚠️ 429 / 5xx errors → Gateway auto-backs off; verify rate limits & API creds ⌨️ CLI input issues → Run in a real terminal (non-TTY disables shortcuts)

🤝 Contributing

PRs and issues are welcome! When adding strategies or new exchanges:

  • Follow modular patterns in src/core
  • Add matching tests in tests/

📬 Contact

Need this trading bot? 👉 Telegram | Twitter

About

A trading bot for Aster Perp DEX with SMA30 trend-following and market-making strategies. Features real-time WebSocket data, a reactive CLI dashboard, and automatic reconnect.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published