Files
ritmex-bot/setup.sh
T

110 lines
2.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
# One-click setup for ritmex-bot (Linux/macOS)
# - Ensures Bun is installed
# - Installs dependencies
# - Prompts for API credentials
# - Generates .env
# - Starts the bot
main() {
require_unix
ensure_bun
install_deps
prompt_env
write_env
echo
echo "✅ Setup complete. Starting ritmex-bot..."
echo
start_bot
}
require_unix() {
case "$(uname -s)" in
Linux|Darwin) ;;
*) echo "This script supports only Linux and macOS." >&2; exit 1 ;;
esac
}
ensure_bun() {
if command -v bun >/dev/null 2>&1; then
echo "✔ Bun found: $(bun --version)"
return
fi
echo " Bun not found. Installing Bun..."
if [ "$(uname -s)" = "Darwin" ] && command -v brew >/dev/null 2>&1; then
brew install bun
else
# Non-interactive install via official script
curl -fsSL https://bun.sh/install | bash
# shellcheck disable=SC1090
if [ -f "$HOME/.bun/bun" ] || [ -d "$HOME/.bun" ]; then
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
fi
fi
if ! command -v bun >/dev/null 2>&1; then
echo "❌ Failed to install Bun. Please install it manually from https://bun.sh" >&2
exit 1
fi
echo "✔ Bun installed: $(bun --version)"
}
install_deps() {
echo "Installing dependencies with Bun..."
bun install
}
prompt_env() {
echo
echo "Please enter your AsterDex API credentials."
read -r -p "ASTER_API_KEY: " ASTER_API_KEY
read -r -s -p "ASTER_API_SECRET (input hidden): " ASTER_API_SECRET
echo
read -r -p "TRADE_SYMBOL (default BTCUSDT): " TRADE_SYMBOL || true
TRADE_SYMBOL=${TRADE_SYMBOL:-BTCUSDT}
# Optional trading parameters
read -r -p "TRADE_AMOUNT (default 0.001): " TRADE_AMOUNT || true
TRADE_AMOUNT=${TRADE_AMOUNT:-0.001}
read -r -p "LOSS_LIMIT (default 0.03): " LOSS_LIMIT || true
LOSS_LIMIT=${LOSS_LIMIT:-0.03}
read -r -p "KLINE_INTERVAL (default 1m): " KLINE_INTERVAL || true
KLINE_INTERVAL=${KLINE_INTERVAL:-1m}
}
write_env() {
local env_file=".env"
echo "Writing ${env_file}..."
cat > "${env_file}" <<EOF
# Generated by setup.sh
ASTER_API_KEY=${ASTER_API_KEY}
ASTER_API_SECRET=${ASTER_API_SECRET}
TRADE_SYMBOL=${TRADE_SYMBOL}
TRADE_AMOUNT=${TRADE_AMOUNT}
LOSS_LIMIT=${LOSS_LIMIT}
KLINE_INTERVAL=${KLINE_INTERVAL}
# Optional maker params (uncomment and tune as needed)
# MAKER_LOSS_LIMIT=0.03
# MAKER_PRICE_CHASE=0.3
# MAKER_BID_OFFSET=0
# MAKER_ASK_OFFSET=0
# MAKER_REFRESH_INTERVAL_MS=1500
# MAKER_MAX_CLOSE_SLIPPAGE_PCT=0.05
# MAKER_PRICE_TICK=0.1
EOF
echo "✔ .env created at $(pwd)/${env_file}"
}
start_bot() {
# Bun auto-loads .env; no need to run dotenv explicitly
bun run start
}
main "$@"