{"id":31322907,"url":"https://github.com/0xfnzero/trading-bot-ts","last_synced_at":"2026-05-18T03:05:43.161Z","repository":{"id":316483815,"uuid":"1063574358","full_name":"0xfnzero/trading-bot-ts","owner":"0xfnzero","description":"Solana PumpSwap automated trading bot with consecutive buy pattern detection.   Auto-executes follow trades with 15% take-profit and 10% stop-loss management.","archived":false,"fork":false,"pushed_at":"2025-09-24T20:54:36.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-24T22:33:13.298Z","etag":null,"topics":["automated-trading","defi","follow-trading","pumpswap","solana","stop-loss","take-profit","trading-bot","typescript"],"latest_commit_sha":null,"homepage":"https://fnzero.dev/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xfnzero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-24T20:20:49.000Z","updated_at":"2025-09-24T20:59:52.000Z","dependencies_parsed_at":"2025-09-26T00:32:42.312Z","dependency_job_id":null,"html_url":"https://github.com/0xfnzero/trading-bot-ts","commit_stats":null,"previous_names":["0xfnzero/trading-bot-ts"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/0xfnzero/trading-bot-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfnzero%2Ftrading-bot-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfnzero%2Ftrading-bot-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfnzero%2Ftrading-bot-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfnzero%2Ftrading-bot-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xfnzero","download_url":"https://codeload.github.com/0xfnzero/trading-bot-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xfnzero%2Ftrading-bot-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automated-trading","defi","follow-trading","pumpswap","solana","stop-loss","take-profit","trading-bot","typescript"],"created_at":"2025-09-25T19:28:56.004Z","updated_at":"2026-05-18T03:05:43.149Z","avatar_url":"https://github.com/0xfnzero.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solana DEX 连续买入跟单机器人\n\n专业的 Solana PumpSwap 交易机器人，基于连续买入模式识别和跟单策略。当检测到某个代币连续大额买入时，自动跟单买入并进行止盈止损管理。\n\n## ✨ 核心特性\n\n- **🎯 智能跟单**: 检测连续买入模式，自动跟单交易\n- **📊 实时监控**: 毫秒级延迟监听链上 PumpSwap 交易事件\n- **💰 自动止盈止损**: 15% 止盈，10% 止损，全自动执行\n- **🛡️ 风险管理**: 多重风险控制，保护资金安全\n- **⚙️ 灵活配置**: 所有参数可通过环境变量自定义\n- **📈 实时统计**: 持仓跟踪、盈亏统计、性能分析\n\n## 🚀 快速开始\n\n### 环境要求\n\n- Node.js 16.0+\n- NPM 7.0+\n- Solana 交易代理服务正在运行\n\n### 安装依赖\n\n```bash\n# 克隆项目后进入目录\ncd trading-bot-ts\n\n# 安装依赖\nnpm install\n```\n\n### 配置策略参数\n\n```bash\n# 复制配置模板\ncp .env.example .env\n\n# 编辑配置文件\nnano .env  # 或使用其他编辑器\n```\n\n### 核心配置说明\n\n#### 🔗 服务连接\n```env\nHTTP_API_URL=http://localhost:3000     # 交易代理 HTTP API\nWS_URL=ws://127.0.0.1:9001            # WebSocket 数据流\nREQUEST_TIMEOUT=30000                  # 请求超时 (毫秒)\n```\n\n#### 📈 交易策略\n```env\nCONSECUTIVE_BUYS=3                     # 连续买入次数检测\nTOTAL_AMOUNT_THRESHOLD=5.0             # 总金额阈值 (SOL)\nTIME_WINDOW_MINUTES=5                  # 时间窗口 (分钟)\nBUY_AMOUNT_SOL=0.01                   # 跟单买入金额 (SOL)\n```\n\n#### 💰 止盈止损\n```env\nTAKE_PROFIT_PERCENT=15.0              # 止盈百分比\nSTOP_LOSS_PERCENT=-10.0               # 止损百分比\nCHECK_INTERVAL_SECONDS=10             # 检查间隔 (秒)\n```\n\n#### 🛡️ 风险控制\n```env\nMAX_POSITIONS=5                        # 最大同时持仓数\nCOOLDOWN_MINUTES=5                     # 代币冷却时间 (分钟)\nSLIPPAGE_BPS=500                      # 滑点保护 (5%)\n```\n\n## 🎯 运行机器人\n\n### 启动交易机器人\n\n```bash\n# 开发模式 (实时日志)\nnpm run bot\n\n# 生产模式 (编译后运行)\nnpm run bot:prod\n\n# 构建项目\nnpm run build\n\n# 仅监听事件 (不执行交易)\nnpm run subscribe\n```\n\n### 启动输出示例\n\n```\n🚀 启动交易机器人...\n✅ 服务器状态: healthy\n🚀 交易机器人已连接到数据流\n📡 正在监听链上交易事件...\n📊 当前状态: 0 个持仓, 总投资 0 SOL\n\n📊 分析买入事件: A1B2C3D4... Amount: 2.5000 SOL\n📊 分析买入事件: A1B2C3D4... Amount: 1.8000 SOL\n📊 分析买入事件: A1B2C3D4... Amount: 3.2000 SOL\n\n🎯 检测到连续买入模式!\n   代币: A1B2C3D4E5F6G7H8...\n   连续买入: 3次\n   总金额: 7.5000 SOL\n🚀 执行跟单买入!\n   我们买入: 0.01 SOL\n✅ 买入成功: 5YoP8xT2M...\n📊 当前状态: 1 个持仓, 总投资 0.01 SOL\n\n📈 A1B2C3D4... PnL: +12.50%\n🎯 触发止盈: 16.20% \u003e= 15.00%\n✅ 止盈成功: 3KpL9vN8Q...\n   盈亏: +16.20% (+0.00162 SOL)\n```\n\n## 💡 使用方式\n\n### 🤖 自动交易模式 (推荐)\n\n```typescript\nimport { TradingBot } from 'trading-proxy-client';\n\nconst bot = new TradingBot();\nawait bot.start();\n\n// 机器人自动执行：\n// ✅ 监听 PumpSwap 买入事件\n// ✅ 检测连续买入模式\n// ✅ 自动跟单买入\n// ✅ 实时止盈止损管理\n// ✅ 风险控制和仓位管理\n```\n\n### 📊 仅数据监控\n\n```typescript\nimport { EventSubscriber } from 'trading-proxy-client';\n\nconst subscriber = new EventSubscriber();\n\nsubscriber.on('pumpswap', (event, latency) =\u003e {\n  const action = event.is_buy ? '🟢 BUY' : '🔴 SELL';\n  console.log(`${action} ${event.mint} ${latency?.latency_ms}ms`);\n});\n\nsubscriber.connect();\n```\n\n### 🔧 手动交易\n\n```typescript\nimport { TradingProxyClient } from 'trading-proxy-client';\n\nconst client = new TradingProxyClient();\n\n// 健康检查\nconst health = await client.health();\n\n// 手动买入\nconst result = await client.buy(dexParams, {\n  mint: 'token_address',\n  amount_sol: 0.01,\n  slippage_bps: 500\n});\n```\n\n## 🧠 策略详解\n\n### 连续买入跟单策略\n\n机器人采用智能的连续买入模式识别策略，通过检测短时间内的大额买入行为来发现潜在的交易机会。\n\n#### 📊 工作原理\n\n```\n时间轴: 00:00 ────────────► 00:05 ────────────► 00:10\n\n代币 ABC:\n├─ 00:01  🟢 买入 2.5 SOL  (用户A)\n├─ 00:02  🟢 买入 1.8 SOL  (用户B)\n├─ 00:03  🟢 买入 3.2 SOL  (用户C)\n└─ 00:04  🎯 触发跟单！总计 7.5 SOL \u003e 5.0 SOL 阈值\n```\n\n#### 🎯 触发条件 (全部满足)\n\n1. **连续买入检测**: 在时间窗口内检测到连续买入\n2. **金额阈值**: 累计买入金额达到设定阈值\n3. **时间限制**: 所有买入发生在指定时间窗口内\n4. **风险检查**: 通过持仓限制、冷却时间等风险控制\n\n#### ⚡ 执行流程\n\n```mermaid\ngraph TD\n    A[监听PumpSwap买入事件] --\u003e B[记录买入数据]\n    B --\u003e C{是否达到连续买入次数?}\n    C --\u003e|否| A\n    C --\u003e|是| D{总金额是否超过阈值?}\n    D --\u003e|否| A\n    D --\u003e|是| E[风险检查]\n    E --\u003e F{通过风险检查?}\n    F --\u003e|否| A\n    F --\u003e|是| G[执行跟单买入]\n    G --\u003e H[开始持仓管理]\n    H --\u003e I[监控止盈止损]\n    I --\u003e J{触发止盈/止损?}\n    J --\u003e|否| I\n    J --\u003e|是| K[自动卖出]\n```\n\n#### 💰 止盈止损机制\n\n- **实时监控**: 每10秒检查一次持仓收益\n- **止盈触发**: 达到15%收益时自动卖出\n- **止损保护**: 亏损达到10%时自动止损\n- **精确计算**: 基于买入价格实时计算收益率\n\n#### 🛡️ 多重风险控制\n\n1. **持仓限制**: 最多同时持有5个代币仓位\n2. **冷却机制**: 同一代币5分钟内只能买入一次\n3. **滑点保护**: 交易时设置5%滑点保护\n4. **金额控制**: 固定小额买入，控制单笔风险\n5. **时间窗口**: 限制在短时间窗口内的买入行为\n\n## 📈 性能特性\n\n### ⚡ 低延迟优势\n\n- **毫秒级响应**: WebSocket实时数据流，延迟\u003c100ms\n- **高效处理**: 异步事件处理，不阻塞主线程\n- **智能缓存**: 价格历史缓存，快速计算收益\n\n### 🔄 自动化管理\n\n- **无人值守**: 7x24小时自动运行\n- **自动清理**: 定期清理过期数据，保持性能\n- **异常恢复**: 网络断线自动重连，容错性强\n\n### 📊 实时统计\n\n```typescript\n// 获取实时统计\nconst stats = bot.getStats();\nconsole.log(`\n持仓数量: ${stats.totalPositions}\n总投资: ${stats.totalInvested} SOL\n总盈亏: ${stats.totalPnL} SOL\n平均收益: ${stats.avgPnL.toFixed(2)}%\n`);\n```\n\n## ⚠️ 注意事项\n\n### 💡 使用建议\n\n1. **测试先行**: 建议先在小金额下测试策略效果\n2. **参数调优**: 根据市场情况调整连续买入阈值\n3. **风险意识**: 设置合理的持仓上限和买入金额\n4. **网络稳定**: 确保网络连接稳定，避免错过交易机会\n\n### 🚨 风险提示\n\n- 加密货币交易具有高风险，可能导致本金损失\n- 机器人交易无法保证盈利，请理性投资\n- 建议设置合理的资金上限，控制整体风险\n- 定期监控机器人运行状态，及时处理异常\n\n### 🔧 故障排除\n\n#### 常见问题\n\n**Q: 机器人无法连接到服务器**\n```bash\n# 检查服务器状态\ncurl http://localhost:3000/health\n\n# 检查WebSocket连接\nwscat -c ws://127.0.0.1:9001\n```\n\n**Q: 交易执行失败**\n- 检查钱包余额是否充足\n- 验证滑点设置是否合理\n- 确认代理服务正常运行\n\n**Q: 未检测到买入机会**\n- 降低 `TOTAL_AMOUNT_THRESHOLD` 阈值\n- 增加 `TIME_WINDOW_MINUTES` 时间窗口\n- 检查 WebSocket 连接是否正常\n\n## 📚 API 文档\n\n### TradingBot 类\n\n```typescript\nclass TradingBot {\n  constructor()                        // 创建机器人实例\n  async start(): Promise\u003cvoid\u003e         // 启动机器人\n  stop(): void                        // 停止机器人\n  getPositions(): Map\u003cstring, Position\u003e // 获取当前持仓\n  getStats(): Stats                   // 获取统计信息\n}\n```\n\n### 事件监听\n\n```typescript\nbot.on('buy-success', (data) =\u003e {\n  // 买入成功事件\n});\n\nbot.on('sell-success', (data) =\u003e {\n  // 卖出成功事件\n});\n\nbot.on('error', (error) =\u003e {\n  // 错误事件处理\n});\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xfnzero%2Ftrading-bot-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xfnzero%2Ftrading-bot-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xfnzero%2Ftrading-bot-ts/lists"}