[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-1435":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":15,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":15,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":16,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":17,"hasPages":17,"topics":19,"createdAt":10,"pushedAt":10,"updatedAt":40,"readmeContent":41,"aiSummary":42,"trendingCount":15,"starSnapshotCount":15,"syncStatus":43,"lastSyncTime":44,"discoverSource":45},1435,"coinbase-trading-bot","ForecastForge\u002Fcoinbase-trading-bot","ForecastForge","coinbase trading bot, coinbase bot, AI\u002Fautomated crypto trading, Coinbase Advanced Trade\u002FPro, spot and futures, grid DCA scalping arbitrage, copy and signal bots, strategy setup tutorial guide automation","https:\u002F\u002Fgithub.com\u002FForecastForge\u002Fcoinbase-trading-bot",null,"TypeScript",209,191,219,0,6.85,false,"main",[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39],"algorithmic-trading","automated-trading","bitcoin","coinbase","coinbase-advanced-trade","crypto-bot","crypto-trading","cryptocurrency","dca","defi","ethereum","fintech","grid-trading","nodejs","open-source","spot-trading","trading-automation","trading-bot","trading-strategy","typescript","2026-06-12 02:00:27","# Coinbase Advanced Trade — Systematic EMA Bot\n\n> **Run your own rules on [Coinbase Advanced Trade](https:\u002F\u002Fwww.coinbase.com\u002Fadvanced-trade).**  \n> No paywalled “black box.” No mystery logic. A **TypeScript** bot you can read end-to-end, test in **paper mode**, and extend when *you* are ready.\n\n*The open-source way to run **systematic** rules on Coinbase—**without** outsourcing your API keys to a closed dashboard you cannot audit, diff, or improve.*\n\n**Jump to:** [At a glance](#at-a-glance) · [Your journey](#your-journey-in-four-beats) · [Who this is for](#who-this-is-for) · [Quick start](#quick-start-first-time-users) · [Configuration](#configuration-reference) · [Project layout](#project-layout) · [Go live](#enabling-live-trading-read-carefully) · [Troubleshooting](#troubleshooting) · [Your next move](#your-next-move-invitation)\n\n---\n\n## The pitch — why people stick around\n\n**Most trading tools ask you to trust a logo. This one asks you to read the code.**\n\n- **Clarity you can build on** — One loop, one strategy module, and configuration that is **validated at startup** (so bad env vars fail fast, not in production).\n- **Discipline, baked in** — **Paper trading is the default.** You opt in to live orders with a single flag—on purpose.\n- **Risk you define** — Size entries with a **per-trade risk fraction** and an optional **hard cap** per order in your quote currency. The bot does not “guess” your tolerance.\n- **A strategy people actually recognize** — **EMA cross + long-term EMA filter** and **ATR** logging mirror ideas you will find in books, courses, and prop-style playbooks: trend follow when the market agrees, step aside when the cross says to exit.\n- **Serious stack** — [TypeScript 5](https:\u002F\u002Fwww.typescriptlang.org\u002F), **Node 20+**, and [coinbase-advanced-node](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fcoinbase-advanced-node) talking to the real Advanced Trade API—the same class of building blocks used by developers who treat execution as software engineering.\n\n**Ideal if you** want to **automate a rule you understand**, **learn systematic trading on real infrastructure**, or **ship a v1** you can later upgrade with your own risk engine—without starting from a fragile script you found in a forum thread.\n\n---\n\n## At a glance\n\n| You want to… | What this gives you |\n|--------------|---------------------|\n| **Get going in one session** | `npm install` → copy `.env` → `npm run dev` and you are pulling candles. |\n| **See signals before you risk capital** | **Paper mode on by default** — logs what would have traded. |\n| **Own your stack** | Full source: indicators, strategy, execution—fork it, don’t rent it. |\n| **Stay in control** | Tweak EMAs, pair, and poll interval in `.env` without touching the exchange UI every hour. |\n| **Grow from prototype to system** | Clean folders so you can add stops, websockets, or a second strategy without a rewrite. |\n\n**Under the hood (one sentence):** a production-style client that runs a **trend-following** EMA rule, applies **position sizing** from *your* settings, and only sends live **market** orders when you say so.\n\n---\n\n## Your journey in four beats\n\n1. **Connect in minutes** — Add keys to `.env`, run `npm run dev`, and you are already streaming **real** market structure into your terminal—not a demo with fake prices.\n2. **Watch the rules work in plain sight** — Every cycle logs **close, EMAs, ATR, signal, balances**. The story is in the data, not in someone else’s “AI.”\n3. **Tune like a product** — Swap pair, timeframes, and EMAs from configuration; iterate without rebuilding your *idea* from scratch every week.\n4. **Promote to live on your terms** — **Paper is default** for a reason. When the logs still make sense to you, **you** flip one flag. That’s the bar.\n\n**That’s the hook:** not “magic money,” but **a machine you understand** that can keep watching when you need to work, sleep, or think.\n\n---\n\n## Who this is for\n\n| You are… | You’ll care because… |\n|----------|----------------------|\n| **A developer** | You want **Git, TypeScript, and a real REST client** next to your trading idea—not a binary blob called “strategies.dll.” |\n| **A self-directed trader** | You want a **documented rule** and **reproducible logs** you can review when emotions have cooled. |\n| **A learner** | You want the **full path**: candles → math → *intent* → (optional) order—on the **same** exchange serious traders use. |\n| **A builder \u002F side-project founder** | You need a **credible v1** you can show: “this places orders through Coinbase; here’s the repo.” |\n| **Anyone burned by “bots” in a box** | **You** hold the code. If something is wrong, you can **find the line**—not file a support ticket and hope. |\n\n---\n\n## We’re straight with you (this builds trust, not hype)\n\n- We do **not** claim guaranteed **profits**, “passive income,” or a secret edge. **Markets change; rules break; capital is at risk.**\n- We **do** offer **full transparency**, **paper-by-default** execution, and a **serious** starting point to learn and extend—*if* you put in the work on testing and risk.\n- The goal isn’t a lottery ticket. It’s **ownership of your process** in a form you can run, measure, and improve.\n\n---\n\n## Why this project exists (technical promise)\n\n| Goal | How this project helps |\n|------|-------------------------|\n| **Clarity** | One strategy, one loop, explicit env-driven configuration (validated with [Zod](https:\u002F\u002Fzod.dev\u002F)). |\n| **Safety** | **Paper trading is the default**; real orders require you to opt in explicitly. |\n| **Control** | Risk per trade and optional per-order caps are separate from the signal logic. |\n| **Maintenance** | Typed code, [coinbase-advanced-node](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002Fcoinbase-advanced-node) for the exchange API, Node 20+. |\n\n> **Important:** Marketing copy does not change market reality. **Trading involves risk of loss. Past results do not predict future results.** This repository is **not** financial, tax, or legal advice. You are responsible for API keys, permissions, product choice, fees, and compliance with law and Coinbase terms. **Nothing here promises profit.**\n\n---\n\n## What the strategy does (in plain language)\n\nThe bot uses a **double EMA crossover** on candle closes, with a **long-term EMA** as a **trend filter**—a combination widely used in systematic trading and taught in many technical and quantitative finance resources.\n\n- **Entry (buy signal):** Shorter EMA crosses **above** longer EMA **and** price is on the “right side” of the trend EMA (configurable, default: above the 200-period EMA on your chosen candle size).\n- **Exit (sell signal):** Shorter EMA crosses **below** longer EMA (full base exit, subject to min order sizes).\n\n**ATR (Average True Range)** is calculated for each cycle and logged so you can extend the bot (e.g. dynamic stops, volatility-scaled size) without reverse-engineering the code.\n\nThis is **not** a guarantee of positive returns. **Edge** in live markets depends on product, timeframe, costs, slippage, and regime—and must be **measured** (backtest, walk-forward, paper trade) for *your* market and *your* parameters.\n\n---\n\n## High-level flow\n\n```mermaid\nflowchart LR\n  subgraph config [Config]\n    ENV[\".env\"]\n  end\n  subgraph exchange [Coinbase Advanced Trade]\n    API[\"REST API\"]\n  end\n  subgraph bot [Bot]\n    Candles[\"Fetch candles\"]\n    Indicators[\"EMA + ATR\"]\n    Rules[\"Rules engine\"]\n    Risk[\"Size & limits\"]\n    Exec[\"Market IOC orders\"]\n  end\n  ENV --> Candles\n  Candles --> Indicators\n  Indicators --> Rules\n  Rules --> Risk\n  Risk --> Exec\n  Candles --> API\n  Risk --> API\n  Exec --> API\n```\n\n---\n\n## Requirements\n\n- **Node.js 20+**\n- A **Coinbase** account with [Advanced Trade](https:\u002F\u002Fwww.coinbase.com\u002Fadvanced-trade) access\n- An **API key** with appropriate permissions (read balances, read market data, **trade** only if you disable paper mode)\n\n---\n\n## Quick start (first-time users)\n\n### 1. Install\n\n```bash\ngit clone \u003Cyour-repo-url>\ncd \"coinbase trading bot\"\nnpm install\n```\n\n### 2. Configure environment\n\n```bash\ncopy .env.example .env\n```\n\nOn macOS or Linux:\n\n```bash\ncp .env.example .env\n```\n\nEdit `.env` and add credentials (see [Authentication](#authentication) below). **Leave `PAPER_TRADING=1` until you are ready.**\n\n### 3. Build and run\n\n```bash\nnpm run build\nnpm start\n```\n\n**Development (TypeScript without a separate build):**\n\n```bash\nnpm run dev\n```\n\nYou should see timestamped log lines: closes, EMAs, ATR, signal, and balances. In paper mode, **no orders** are sent.\n\n### That “it’s alive” moment\n\nThe first time you see a full **tick** in the log—**price, EMAs, ATR, signal, balances**—you’ve turned a loose idea into a **pipeline** you can re-run any day. *That* is the feeling most people are chasing when they say they want a bot. This repo is built to get you to that moment **fast**, then help you not ruin it with rushed live size.\n\n---\n\n## Authentication\n\nThe bot supports the same two styles supported by the underlying client:\n\n| Method | Environment variables | Notes |\n|--------|----------------------|--------|\n| **CDP (recommended)** | `CDP_API_KEY_NAME`, `CDP_API_KEY_SECRET` | Modern Coinbase [Developer Platform](https:\u002F\u002Fwww.coinbase.com\u002Fdeveloper-platform) \u002F Cloud API keys. |\n| **Legacy HMAC** | `API_KEY`, `API_SECRET` | Older key format, where still supported. |\n\n**Never commit** `.env` or keys. The repository includes `.gitignore` rules for `.env`.\n\n**Permissions:** For paper trading you still need valid keys so the client can read **candles** and **balances** (same as live). Ensure your key’s scopes match what you intend (view vs trade).\n\n---\n\n## Configuration reference\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `PAPER_TRADING` | `1` (on) | `1` \u002F `true` = log only; set to `0` to send real orders. |\n| `PRODUCT_ID` | `BTC-USD` | e.g. `ETH-USD`, `SOL-USD` (use Coinbase’s product IDs). |\n| `CANDLE_GRANULARITY` | `FIVE_MINUTE` | `ONE_MINUTE`, `FIVE_MINUTE`, `FIFTEEN_MINUTE`, `THIRTY_MINUTE`, `ONE_HOUR`, `TWO_HOUR`, `SIX_HOUR`, `ONE_DAY`. |\n| `POLL_MS` | `60000` | Milliseconds between loop iterations. |\n| `EMA_FAST` | `12` | Fast EMA length (closes). |\n| `EMA_SLOW` | `26` | Slow EMA length (same window family as many MACD definitions). |\n| `EMA_TREND` | `200` | Trend EMA; long entries require price context vs this line (see code). |\n| `ATR_PERIOD` | `14` | ATR lookback; used in logs; extend the code for risk logic. |\n| `RISK_PER_TRADE` | `0.02` | Fraction of **available quote** balance used to size a **new buy** (e.g. `0.02` = 2%). |\n| `MAX_QUOTE_PER_ORDER` | *(optional)* | Hard cap in **quote** currency on each buy (e.g. `500` for 500 USD). |\n\n---\n\n## Trading behavior (what to expect)\n\n- **Buys** use **market IOC** with **`quote_size`** (spend up to the risk- and cap-limited amount).\n- **Sells** use **market IOC** with **`base_size`**, using nearly all base balance on exit (minus rounding); minimum sizes come from the **product** API.\n- The bot does **not** manage partial take-profits, stop-loss orders, or pending-order reconciliation in the current version; treat it as a **minimal v1** you can extend.\n\n### Moving toward a more “professional” outcome (no empty promises)\n\nProfitable *process* in real markets usually combines:\n\n1. **Explicit costs** — fees, spread, and (for some products) funding; compare to the average trade’s expected move.\n2. **Stability of rules** — avoid changing parameters on every red day; document what you test.\n3. **Out-of-sample checks** — walk-forward or paper **after** any parameter search.\n4. **Risk of ruin** — keep per-trade risk small relative to what you can afford to lose.\n\nThis README is written so you can align expectations with that workflow—not with hype.\n\n---\n\n## Project layout\n\n| Path | Role |\n|------|------|\n| `src\u002Findex.ts` | Loads env, starts the engine. |\n| `src\u002Fconfig.ts` | Validated environment and `PRODUCT_ID` parsing. |\n| `src\u002Fcoinbase\u002FcreateClient.ts` | Authenticated `Coinbase` client. |\n| `src\u002Fstrategy\u002FemaCrossTrendStrategy.ts` | EMA\u002FATR signal logic. |\n| `src\u002Fengine\u002FbotEngine.ts` | Polling loop, balances, order placement, logging. |\n| `src\u002Findicators\u002F` | EMA and ATR helpers. |\n| `src\u002Futils\u002FsizeFormat.ts` | Order size strings vs exchange minima. |\n\n---\n\n## Scripts\n\n| Command | Description |\n|---------|-------------|\n| `npm run build` | Compile to `dist\u002F`. |\n| `npm start` | Run compiled `dist\u002Findex.js` (use after `build`). |\n| `npm run dev` | Run TypeScript with `tsx` (no `build` required). |\n| `npm run typecheck` | Type-check only. |\n\n---\n\n## Enabling live trading (read carefully)\n\n1. Confirm **paper** logs match your intent for several sessions and products.\n2. Set **`PAPER_TRADING=0`** in `.env`.\n3. Use **only capital you can afford to lose**; start with **small** `RISK_PER_TRADE` and optional **`MAX_QUOTE_PER_ORDER`**.\n4. Monitor the first live sessions; consider running on a small VPS or home machine you control, with a locked-down key.\n\n**Stop the bot** with `Ctrl+C` in the terminal (SIGINT).\n\n---\n\n## Troubleshooting\n\n| Symptom | What to check |\n|--------|----------------|\n| `Set CDP API keys...` | Missing or misnamed env vars; use `.env` in the project root. |\n| `Unknown product` | `PRODUCT_ID` must match a live Advanced Trade product (e.g. `BTC-USD`). |\n| Orders rejected \u002F below minimum | Check Coinbase `base_min_size` \u002F `quote_min_size` for that product; increase balance or `RISK_PER_TRADE` slightly if appropriate. |\n| “Need N candles” | The strategy needs a minimum history; wait for the feed to return enough bars or use a coarser `CANDLE_GRANULARITY` if the API limit is an issue. |\n\n---\n\n## Your next move (invitation)\n\n- **Save it** — Star the repository so you can find it when you are ready to go from reading to running.\n- **Make it yours** — Fork, rename, strip what you do not need, add what you *do* (stops, another pair, a second strategy file). The license is on you and the rights holders—check the repo’s license if one is present.\n- **Show someone** — Send the link to the friend who says “I will automate that someday.” A working repo beats another bookmark on a “how to trade” article.\n- **Stay curious** — The interesting part is not the first run. It is what you **measure** and **change** next—*after* the excitement wears off and the log files stack up.\n\n---\n\n## License\n\nSee the `package.json` \u002F repository license if provided. The bot depends on **coinbase-advanced-node** and other packages under their respective licenses.\n\n---\n\n## Acknowledgment\n\nExchange connectivity is provided by the open-source **[coinbase-advanced-node](https:\u002F\u002Fgithub.com\u002FJoshJancula\u002Fcoinbase-advanced-node)** client, not by Coinbase, Inc. This project is an independent example and is not affiliated with or endorsed by Coinbase.\n\nIf you use this in production, **log retention**, **key rotation**, and **incident response** are your responsibility.\n\n---\n\n**Questions?** Open an issue in your repository, or adapt the code under `src\u002Fstrategy` for your own rules—after testing.\n","Coinbase Trading Bot 是一个基于 Coinbase Advanced Trade 平台的自动化加密货币交易机器人。它使用 TypeScript 编写，支持现货和期货交易，提供网格 DCA 套利、信号复制等功能，并且内置了 EMA 交叉策略与 ATR 日志记录等技术特点。项目代码完全开源，用户可以自主阅读、测试（包括纸面交易模式）并扩展功能。适用于希望在不将 API 密钥交给第三方的情况下，自行实现或学习系统化交易策略的个人投资者和技术爱好者。",2,"2026-05-06 17:32:46","CREATED_QUERY"]