[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-75889":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":13,"stars7d":13,"stars30d":15,"stars90d":13,"forks30d":13,"starsTrendScore":13,"compositeScore":13,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":16,"fork":16,"defaultBranch":17,"hasWiki":18,"hasPages":16,"topics":19,"createdAt":10,"pushedAt":10,"updatedAt":39,"readmeContent":40,"aiSummary":41,"trendingCount":13,"starSnapshotCount":13,"syncStatus":42,"lastSyncTime":43,"discoverSource":44},75889,"binance-trading-bot","pro-tech-killers\u002Fbinance-trading-bot","pro-tech-killers","binance trading bot binance spot binance api trading bot crypto trading bot automated trading binance trading bot typescript ccxt algorithmic trading spot trading crypto bot binance trading bot npm nodejs quant fintech crypto trading bot automated trading binance trading bot open source binance trading bot btc eth usdt binance trading bot","https:\u002F\u002Fgithub.com\u002Fpro-tech-killers\u002Fbinance-trading-bot",null,"TypeScript",90,0,1,186,false,"main",true,[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"algorithmic-trading","automated-trading","binance","binance-api","btc","ccxt","crypto","crypto-bot","cryptocurrency","eth","fintech","nodejs","npm","open-source","quant","spot-trading","supertrend","trading-bot","typescript","2026-06-12 02:03:37","# Binance Spot Trading Bot\n\n**Keywords:** binance binance-spot binance-api binance-bot npm package binance-trading-bot ccxt trading-bot supertrend ema rsi zod typescript nodejs node-20 esm modules market-order dry-run testnet spot-trading crypto btc eth usdt algo-trading automated-trading automated-crypto quantitative paper-trading open-source long-only binance-testnet scalp swing grid-bot dca day-trading market-making signal-bot volatility ohlcv candlestick rest-api rate-limit spot-only no-futures stablecoin quote-invest\n\n**Repository (clone \u002F issues \u002F PRs):** [github.com\u002Fpro-tech-killers\u002Fbinance-trading-bot](https:\u002F\u002Fgithub.com\u002Fpro-tech-killers\u002Fbinance-trading-bot)\n\n\n**Related:** [coinbase-trading-bot](https:\u002F\u002Fgithub.com\u002Fpro-tech-killers\u002Fcoinbase-trading-bot) · [bybit-trading-bot](https:\u002F\u002Fgithub.com\u002FAI4FinanceFoundation\u002Fbybit-trading-bot) · [ai-trading-agent](https:\u002F\u002Fgithub.com\u002Fendless-sky-team\u002Fai-trading-agent)\n\n---\n\n## Table of contents\n\n1. [Disclaimer](#disclaimer)  \n2. [What this bot does](#what-this-bot-does)  \n3. [Architecture](#architecture)  \n4. [Stack](#stack)  \n5. [npm scripts](#npm-scripts)  \n6. [Strategies](#strategies)  \n7. [Execution: orders, balance, bars](#execution-orders-balance-bars)  \n8. [Configuration](#configuration)  \n9. [Keys and security](#keys-and-security)  \n10. [Install and run](#install-and-run)  \n11. [Operations and logs](#operations-and-logs)  \n12. [Troubleshooting](#troubleshooting)  \n13. [Limitations](#limitations)  \n14. [Performance and trade history](#performance-and-trade-history)  \n15. [Project layout](#project-layout)  \n16. [License](#license)  \n\n---\n\n## Disclaimer\n\n- **Not financial, legal, or tax advice.** Spot crypto trading is high risk; you can lose your full position.  \n- **Past results do not guarantee future results.** Public strategies (e.g. SuperTrend) are widely used and may be crowded.  \n- **You** own API key safety, KYC, taxes, and compliance with laws and [Binance](https:\u002F\u002Fwww.binance.com\u002F) terms.  \n- This software is provided **as is**, without warranty. **Use at your own risk.**  \n\nBefore **live** trading: run on [Binance Spot Testnet](https:\u002F\u002Ftestnet.binance.vision\u002F) and keep `DRY_RUN` until you trust the logs and behavior.\n\n---\n\n## What this bot does\n\n| Area | In scope | Not implemented |\n|------|----------|-----------------|\n| Market | **Binance Spot** (`defaultType: spot`) | Futures, options, margin, other venues |\n| Side | **Long** (buy in, sell out) | Short, hedge, pairs |\n| Orders | **Market** (CCXT helpers for quote-sized buys) | Limit, TWAP, OCO, etc. |\n| Data | `fetchOHLCV` for one `SYMBOL` \u002F `TIMEFRAME` | Order book, funding, on-chain |\n| Risk | % of free quote per **buy** | DB VaR, Kelly, drawdown halts, breakers |\n| State | In-memory `lastActedOnBarOpen` | Trade DB, full audit trail |\n| HA | One process | Multi-region, leader election |\n\nFor **live** use you still need monitoring, key hygiene, and position sizes that match your risk tolerance.\n\n---\n\n## Architecture\n\nTight **poll loop**: `loadMarkets` once, then every `POLL_SEC` fetch OHLCV, compute indicators, get `buy` \u002F `sell` \u002F `hold`, log, and optionally send orders. The **open** candle is **dropped** so signals use **closed** bars only (reduces repainting when polling faster than the timeframe).\n\n```mermaid\nflowchart LR\n  subgraph config\n    A[\".env + Zod\"]\n  end\n  subgraph loop[\"Main loop (TradingBot)\"]\n    B[\"fetchOHLCV\"] --> C[\"indicators + strategy\"]\n    C --> D[\"log line\"]\n    D --> E{\"DRY_RUN?\"}\n    E -->|yes| F[\"no exchange orders\"]\n    E -->|no| G[\"market buy \u002F sell via CCXT\"]\n  end\n  A --> B\n  G --> B\n```\n\n- **`src\u002Fconfig.ts`** — one load at startup; bad env → process exits.  \n- **`src\u002Fstrategy.ts`**, **`src\u002Findicators.ts`** — SuperTrend, EMA\u002FRSI.  \n- **`src\u002Fbot.ts`** — CCXT `binance`, `enableRateLimit: true`, testnet, balance, orders.  \n\n---\n\n## Stack\n\n| Piece | Role |\n|-------|------|\n| **Node.js ≥ 20** | Runtime |\n| **TypeScript** | ESM build to `dist\u002F` |\n| **CCXT** | Binance REST (spot) |\n| **Zod** | Env parsing |\n| **dotenv** | `.env` in dev |\n| **tsx** | `npm run dev` |\n\n---\n\n## npm scripts\n\n| Command | What it runs |\n|---------|----------------|\n| `npm run dev` | `node --import tsx src\u002Findex.ts` — TypeScript directly, no `dist\u002F` build. |\n| `npm run build` | `tsc` → emits JavaScript under `dist\u002F`. |\n| `npm start` | `node dist\u002Findex.js` — **requires** `build` first. |\n| `npm run typecheck` | `tsc --noEmit` — CI-friendly compile check. |\n\n---\n\n## Strategies\n\n### SuperTrend (`STRATEGY=supertrend`, default)\n\nATR-based trend following (typical ATR + multiplier bands, trend flips on band breaks). Signals on the **last two closed** bars: **buy** on trend **down → up**, **sell** on **up → down**. Tuning: `ST_ATR_PERIOD`, `ST_MULTIPLIER`.\n\n### EMA + RSI (`STRATEGY=ema_rsi`)\n\nFast\u002Fslow EMA cross on **close**; **buy** on bullish cross if RSI ≤ `RSI_MAX_BUY`; **sell** on bearish cross. Same closed-bar data as above.\n\n**Widely used rules ≠ guaranteed edge.**\n\n---\n\n## Execution: orders, balance, bars\n\n- **Bars:** only **completed** candles feed indicators.  \n- **De-dupe:** `lastActedOnBarOpen` blocks repeat buy\u002Fsell on the same last closed bar after an action (including dry-run). **Hold** does not set it. If **sell** is signaled but there is no free base, the bar can still be marked so the loop does not spin on warnings.  \n- **Buy:** free **quote** × `QUOTE_INVEST_PCT` → market buy (`createMarketOrderWithCost` \u002F `quoteOrderQty` \u002F fallbacks in code).  \n- **Sell:** market **all free base** (precision-rounded).  \n- **Testnet:** `BINANCE_TESTNET=true` or `1` → CCXT sandbox.  \n\nThis is a **simple** executor, not a full OMS: no built-in fill analytics or slippage model.\n\n---\n\n## Configuration\n\nCopy `.env.example` to `.env`. **Do not commit** `.env`.\n\n| Variable | Default \u002F notes |\n|----------|-----------------|\n| `BINANCE_API_KEY` | `\"\"` — required for private endpoints \u002F live. |\n| `BINANCE_SECRET` | `\"\"` |\n| `BINANCE_TESTNET` | `true` \u002F `1` → testnet. Else live REST (public OHLCV can work without keys). |\n| `DRY_RUN` | Default **on** (anything other than `false` \u002F `0` = no orders). Set `DRY_RUN=false` only when you want real or testnet **orders**. |\n| `STRATEGY` | `supertrend` or `ema_rsi` (`ema-rsi`, `emarsi`). |\n| `ST_ATR_PERIOD` | `10` |\n| `ST_MULTIPLIER` | `3` |\n| `SYMBOL` | `BTC\u002FUSDT` |\n| `TIMEFRAME` | `1h` |\n| `EMA_FAST` \u002F `EMA_SLOW` | `12` \u002F `26` — fast must be **&lt;** slow. |\n| `RSI_PERIOD` | `14` |\n| `RSI_MAX_BUY` | `70` |\n| `QUOTE_INVEST_PCT` | `0.1` (10% of free quote per buy) |\n| `POLL_SEC` | `60` |\n\nInvalid Zod config or `EMA_FAST >= EMA_SLOW` → exit on startup.\n\n---\n\n## Keys and security\n\n- **Least privilege:** dedicated API key, **no withdrawal** (if the venue allows), **IP allowlist** in production.  \n- **Secrets** via env or a secret manager — never in git.  \n- **Testnet first:** [testnet.binance.vision](https:\u002F\u002Ftestnet.binance.vision\u002F).  \n- **Host:** dedicated OS user, lock down `.env` permissions.  \n- **This repo** does not encrypt keys on disk.  \n\n---\n\n## Install and run\n\n**Requires:** Node **20+**, `npm`.\n\n```bash\nnpm install\n```\n\n```bash\n# Windows\ncopy .env.example .env\n# macOS \u002F Linux\ncp .env.example .env\n```\n\nFor first runs use `DRY_RUN=true` and `BINANCE_TESTNET=true` until behavior matches what you expect.\n\n```bash\nnpm run dev\n```\n\nProduction-style (compiled):\n\n```bash\nnpm run build\nnpm start\n```\n\nTypecheck:\n\n```bash\nnpm run typecheck\n```\n\n**Stop:** Ctrl+C or SIGTERM. There is no automatic cancel-all-orders on exit — use the exchange UI if needed.\n\n---\n\n## Operations and logs\n\n- **Logs:** timestamp (bar time), `close=…`, strategy detail, `BUY` \u002F `SELL` \u002F `HOLD`, and whether action was already taken for that bar. Tick errors are logged; the loop continues.  \n- **Monitoring:** ship logs to your stack; alert on repeated `tick error` or process death.  \n- **Network:** transient failures show as errors; the bot does not implement custom reconnection beyond CCXT.  \n- **What counts as “real” paper:** `DRY_RUN=true` (engine runs, **no** orders) or testnet with small size — **that** is your **operational** record. Anything you export from the exchange (or testnet) is your **authoritative** trade history.  \n\n---\n\n## Troubleshooting\n\n| Symptom | Likely cause | What to try |\n|--------|----------------|-------------|\n| Process exits immediately on start | Zod validation failed | Read stderr (often `EMA_FAST` \u002F `EMA_SLOW` or missing fields); compare `.env` to `.env.example`. |\n| Orders fail with auth errors | Wrong key\u002Fsecret or testnet mismatch | Match `BINANCE_TESTNET` to keys from [testnet.binance.vision](https:\u002F\u002Ftestnet.binance.vision\u002F) vs production keys. |\n| Repeated tick errors | Network, rate limits, or symbol not loaded | Check connectivity; confirm `SYMBOL` exists after `loadMarkets` (see logs); CCXT handles basic rate limiting (`enableRateLimit: true`). |\n| Signal fires but no order | `DRY_RUN` still truthy | Set `DRY_RUN=false` only when you intend real\u002Ftestnet orders. |\n| “Already acted” every tick | `lastActedOnBarOpen` dedupe | Expected until a **new** closed bar produces a new signal; not a bug. |\n\n---\n\n## Limitations\n\n- No stop-loss \u002F take-profit \u002F trailing in the strategy layer.  \n- No on-disk position DB — restarts can re-touch the last closed bar on the first tick; be aware around bar boundaries.  \n- Fees and slippage not modeled in the bot.  \n- Single symbol, single thread.  \n\n---\n\n## Performance and trade history\n\n### How to get **your** real trading history\n\nThis repository **does not** store or export fills. **Your** history comes from:\n\n1. **Binance (or testnet):** *Orders* \u002F *Trade History* \u002F account **Export** (CSV) for the date range.  \n2. **This bot’s logs:** stdout lines with `BUY`\u002F`SELL`\u002F`HOLD` — redirect to a file and pair timestamps with exchange IDs from the app or API.  \n3. **Spreadsheet or journal:** sum **realized** P&L per week or per round-trip; subtract **fees** (Binance schedule applies).  \n\n`DRY_RUN` and testnet give you a **realistic** run of the same code paths without mainnet capital — still not a substitute for legal\u002Ftax recordkeeping; use exchange exports for that.\n\n### Example performance journal (illustration only)\n\nThe tables below are **synthetic** numbers for **layout** — they are **not** from Binance, not from a linked account, and **not** produced by a built-in backtest in this repo. They show how you might **present** a weekly summary and a small blotter after you paste **your** data.\n\n**Run metadata (fill with your run)**\n\n| Field | Example value (yours will differ) |\n|-------|-------------------------------------|\n| **Label** | `BTC\u002FUSDT` · 1h · SuperTrend · testnet or live |\n| **Period** | e.g. Jan–Mar 2026 (your window) |\n| **Mode** | `DRY_RUN` \u002F `testnet` \u002F `mainnet` |\n| **Fee basis** | Your Binance spot fee tier (illustration uses a flat % only below) |\n\n#### Weekly summary (illustrative)\n\n| Week ending (UTC) | Trades (round-trips) | Avg. notional \u002F leg (USDT) | Gross P&L (USDT) | Fees (USDT) | Net P&L (USDT) | Notes |\n|-------------------|----------------------|-----------------------------:|-----------------:|------------:|----------------:|--------|\n| 2026-01-04 | 2 | 320 | -4.20 | 0.26 | -4.46 | — |\n| 2026-01-11 | 4 | 310 | +6.10 | 0.41 | +5.69 | — |\n| 2026-01-18 | 3 | 295 | +2.40 | 0.32 | +2.08 | — |\n| 2026-01-25 | 5 | 340 | -8.10 | 0.48 | -8.58 | Choppy week |\n| 2026-02-01 | 4 | 300 | +5.20 | 0.40 | +4.80 | — |\n| 2026-02-08 | 6 | 315 | +1.50 | 0.45 | +1.05 | — |\n| 2026-02-15 | 3 | 330 | -2.10 | 0.33 | -2.43 | — |\n| 2026-02-22 | 4 | 305 | +7.80 | 0.44 | +7.36 | — |\n| 2026-03-01 | 5 | 325 | -5.60 | 0.45 | -6.05 | — |\n| 2026-03-08 | 2 | 310 | +3.10 | 0.29 | +2.81 | — |\n| 2026-03-15 | 5 | 300 | -1.20 | 0.42 | -1.62 | — |\n| 2026-03-22 | 4 | 318 | +4.00 | 0.41 | +3.59 | — |\n\n**Illustrative net over the sample window (table only):** about **+4.0 USDT** — **not** a performance claim; replace with your exports.\n\n#### Round-trip blotter sample (illustrative)\n\n*Replace with your exchange order or trade IDs.*\n\n| Ref. | Side sequence | Notional (USDT, approx.) | Net after fees (USDT) | Notes |\n|------|----------------|--------------------------|------------------------|--------|\n| RT-2026-001 | Buy → sell | 300 | -1.80 | Stopped by signal |\n| RT-2026-002 | Buy → sell | 300 | +2.10 | — |\n| RT-2026-003 | Buy → sell | 320 | +0.40 | — |\n| RT-2026-004 | Buy → sell | 310 | -2.20 | — |\n| RT-2026-005 | Buy → sell | 315 | +1.60 | — |\n\n**Bottom line:** treat **exchange and tax records** as ground truth. Use this bot’s config and logs to explain *what the automation did*, and use the journal format above (or your own) to track **real** P&L over time.\n\n---\n\n## Project layout\n\n| Path | Role |\n|------|------|\n| `package.json` | Scripts, deps, Node engine. |\n| `tsconfig.json` | TypeScript, ESM, strict. |\n| `src\u002Findex.ts` | Entry: `loadConfig()`, `TradingBot`, `start()`. |\n| `src\u002Fconfig.ts` | `dotenv` + Zod. |\n| `src\u002Fbot.ts` | CCXT loop, orders. |\n| `src\u002Fstrategy.ts` | Strategy switch. |\n| `src\u002Findicators.ts` | EMA, RSI, ATR, SuperTrend. |\n| `dist\u002F` | `npm run build` output. |\n| `.env.example` | Env template. |\n\n---\n\n## License\n\nThis project is provided **as is** without warranty. Add a `LICENSE` file if you need explicit terms. Authors and contributors are **not liable** for trading losses, API issues, or incidents arising from your keys or environment.\n\nFor **production** suitability, do your own review, security review, and smallest-size live test after compliance sign-off.\n","该项目是一个基于币安现货市场的自动化交易机器人。它使用TypeScript编写，通过Binance API实现自动交易功能，支持多种技术指标如SuperTrend、EMA和RSI等进行策略配置。核心特点包括开源、易于部署（基于Node.js环境）、支持干运行模式以及在Binance测试网上的模拟交易能力。适用于希望利用算法提高交易效率或探索量化交易策略的个人投资者和技术爱好者。注意，用户需自行负责API密钥安全及遵守相关法律法规。",2,"2026-06-11 03:53:37","CREATED_QUERY"]