Skip to content

igormoondev/Aster-dex-trading-bot-package

Repository files navigation

aster-dex-trading-bots

Modular, well-structured Node.js package for automated trading on Aster DEX. Written in TypeScript, with support for multiple bot strategies, REST + WebSocket integration, configurable risk, and paper trading.

Features

  • Modular strategy classes: TrendFollowing, MarketMaking, LiquidationHunter, VolumeGeneration, CopyTrading, Telegram
  • Full Aster DEX integration: REST (Spot & Futures) and WebSocket for real-time data
  • Secure credentials: API keys via environment variables only
  • Config-driven: YAML/JSON config with Zod validation
  • Structured logging: Pino with configurable levels
  • Error handling & retries: Rate-limit backoff and configurable retries
  • Paper trading: Simulate orders without real funds
  • CLI: Run any strategy with a single command

Requirements

  • Node.js v18+
  • npm or yarn

Installation

git clone <repo-url>
cd aster-dex-trading-bots
npm install
npm run build

Configuration

1. Environment variables

Copy .env.example to .env and set your Aster DEX API credentials:

cp .env.example .env

Spot (HMAC):

Futures (EIP-712 / Pro API):

  • ASTER_API_KEY, ASTER_API_SECRET
  • ASTER_USER – main wallet address
  • ASTER_SIGNER – API wallet address
  • ASTER_SIGNER_PRIVATE_KEY – API wallet private key

Never commit .env or expose private keys.

2. Config file

Use a YAML or JSON file to select the bot type and strategy parameters. Example configs are in configs/.

Example: trend-following (paper trading)

botType: trend_following
product: spot
symbols:
  - BTCUSDT
  - ETHUSDT
risk:
  maxPositionSize: "0.001"
  maxDrawdownPercent: 20
  maxOpenOrders: 5
paperTrading: true
logLevel: info
strategy:
  emaFastPeriod: 12
  emaSlowPeriod: 26
  rsiPeriod: 14
  rsiOversold: 30
  rsiOverbought: 70
  entryThreshold: 0.5
  exitThreshold: 0.5
  stopLossPercent: 2
  takeProfitPercent: 4

Running the bot

CLI (recommended):

# After npm run build
node dist/cli.js start --config ./configs/trend-following.yaml

# Or with npx / npm link
aster-bot start --config ./configs/trend-following.yaml

Development (tsx):

npm run cli -- start --config ./configs/trend-following.yaml

Paper trading: Set paperTrading: true in the config. No real orders are sent; actions are only logged.

Graceful shutdown: Send SIGINT (Ctrl+C) or SIGTERM to stop the bot and close WebSocket connections.

Bot strategies

Strategy Description
TrendFollowingBot EMA + RSI + SMA; configurable entry/exit, stop-loss, take-profit. Fetches klines and places trades when conditions are met.
MarketMakingBot Dual-sided limit orders around mid; inventory skew and spread adjustment; order refresh.
LiquidationHunterBot Subscribes to liquidation stream via WebSocket; places trades with VWAP-style protection; supports paper trading.
VolumeGenerationBot Grid of limit orders near market with small take-profit; configurable grid step and max orders.
CopyTradingBot Mirrors a target trader/strategy (e.g. competition AI); copy ratio and max position; extend fetchTargetPositions() for your API.
TelegramBot Wraps another bot; Telegram commands for status, PnL, optional one-click trading; requires node-telegram-bot-api.

Project structure

aster-dex-trading-bots/
├── src/
│   ├── api/           # REST client, WebSocket client, auth (HMAC, EIP-712)
│   ├── bots/          # BaseBot + all strategy implementations
│   ├── config/        # Schema (Zod), loader (YAML/JSON)
│   ├── strategies/    # Indicators (EMA, SMA, RSI), risk helpers
│   ├── utils/         # Logger, retry, decimal, errors
│   ├── types/         # API and config types
│   ├── cli.ts         # CLI entry (aster-bot start --config)
│   └── index.ts       # Package exports
├── configs/           # Example YAML configs per bot type
├── tests/
│   └── unit/          # Jest tests (config, indicators, auth)
├── .env.example
├── package.json
├── tsconfig.json
└── README.md

API usage

You can use the clients and bots programmatically:

import { loadConfig } from 'aster-dex-trading-bots';
import { AsterRestClient } from 'aster-dex-trading-bots';
import { createBot } from 'aster-dex-trading-bots';

const config = loadConfig({ path: './configs/trend-following.yaml' });
const rest = new AsterRestClient({
  product: config.product,
  credentials: {
    apiKey: process.env.ASTER_API_KEY!,
    apiSecret: process.env.ASTER_API_SECRET!,
  },
});
const bot = createBot({ config, rest });
await bot.start();

Testing

npm test

Unit tests cover config loading, indicators (SMA, EMA, RSI), and HMAC auth. Use a testnet config and testnet credentials for any integration tests.

Rate limits

Aster DEX applies per-IP rate limits. The client respects 429 and Retry-After; repeated violations can lead to temporary IP bans. Prefer WebSocket streams where possible to reduce REST load.

Disclaimer

This software is for educational and research purposes. Trading cryptocurrencies and derivatives involves substantial risk of loss. Past performance does not guarantee future results. Use paper trading first. The authors are not responsible for any financial losses. Always comply with your jurisdiction’s laws and Aster DEX terms of service.

License

MIT

About

Modular, well-structured Node.js package for automated trading on Aster DEX. Written in TypeScript, with support for multiple bot strategies, REST + WebSocket integration, configurable risk, and paper trading.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors