[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"tool-lefnire--tforce_btc_trader":3,"similar-lefnire--tforce_btc_trader":101},{"id":4,"github_repo":5,"name":6,"description_en":7,"description_zh":8,"ai_summary_zh":8,"readme_en":9,"readme_zh":10,"quickstart_zh":11,"use_case_zh":12,"hero_image_url":13,"owner_login":14,"owner_name":15,"owner_avatar_url":16,"owner_bio":17,"owner_company":18,"owner_location":19,"owner_email":20,"owner_twitter":21,"owner_website":22,"owner_url":23,"languages":24,"stars":44,"forks":45,"last_commit_at":46,"license":47,"difficulty_score":48,"env_os":49,"env_gpu":50,"env_ram":51,"env_deps":52,"category_tags":63,"github_topics":21,"view_count":66,"oss_zip_url":21,"oss_zip_packed_at":21,"status":67,"created_at":68,"updated_at":69,"faqs":70,"releases":100},8255,"lefnire\u002Ftforce_btc_trader","tforce_btc_trader","TensorForce Bitcoin Trading Bot","tforce_btc_trader 是一个基于 TensorForce 框架开发的比特币自动交易机器人，旨在利用深度强化学习技术，根据历史价格数据自动执行买入、卖出或持有操作。它主要解决了在波动剧烈的加密货币市场中，如何构建能够自适应市场变化并优化交易策略的难题，为量化交易提供了智能化的解决方案。\n\n这款工具特别适合具备 Python 基础的开发者、人工智能研究人员以及对算法交易感兴趣的学习者使用。作者明确指出，由于金融市场的复杂性，该项目目前的测试尚未完全收敛，因此不建议直接用于实盘获利，而是作为学习深度强化学习在时间序列预测中应用的绝佳教育起点和开发模板。\n\n其技术亮点在于集成了 TA-Lib 进行技术指标分析，并使用 PostgreSQL 管理历史数据与超参数实验记录。项目核心包含一个基于贝叶斯优化的超参数搜索模块，能够自动寻找神经网络结构（如 LSTM 或 CNN）的最佳配置组合。此外，它还配套了详细的机器学习教程播客，帮助用户深入理解从模型构建到调优的全过程。需要注意的是，运行该工具对硬件有一定要求，建议使用配备 GPU 的设备以获得理想的训练效率。","# TensorForce Bitcoin Trading Bot\n\n## Update 2018-08-14\nTag v0.1 has the code which follows this README. Tag v0.2 is a major overhaul after lessons learned in a finance job, and much of this README won't match the new code. I can't get tests to converge in either case, so something is fundamentally missing from this project - ie, don't count on making money (use as a starting-point \u002F education instead). I'm stepping away for a while and won't be very active here, but I'm not completely abandoning.\n\n---\n\n\n[![Join the chat at https:\u002F\u002Fgitter.im\u002Flefnire\u002Ftforce_btc_trader](https:\u002F\u002Fbadges.gitter.im\u002Flefnire\u002Ftforce_btc_trader.svg)](https:\u002F\u002Fgitter.im\u002Flefnire\u002Ftforce_btc_trader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nA [TensorForce](https:\u002F\u002Fgithub.com\u002Freinforceio\u002Ftensorforce)-based Bitcoin trading bot (algo-trader). Uses deep reinforcement learning to automatically buy\u002Fsell\u002Fhold BTC based on price history.\n\nThis project goes with Episode 26+ of [Machine Learning Guide](http:\u002F\u002Focdevel.com\u002Fpodcasts\u002Fmachine-learning). Those episodes are tutorial for this project; including an intro to Deep RL, hyperparameter decisions, etc.\n\n### 1. Setup\n- Python 3.6+ (I use template strings a lot)\n- Install & setup Postgres\n  - Create two databases: `btc_history` and `hyper_runs`. You can call these whatever you want, and just use one db instead of two if you prefer (see Data section).\n  - `cp config.example.json config.json`, pop ^ into `config.json`\n- Install [TA-Lib](https:\u002F\u002Fgithub.com\u002Fmrjbq7\u002Fta-lib) manually.\n- `pip install -r requirements.txt`\n  - If issues, try installing these deps manually.\n- Install TensorForce from git repo (constantly changing, we chase HEAD)\n  - `git clone https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftensorforce.git`\n  - `cd tensorforce && pip install -e .`\n\nNote: you'll wanna run this on a GPU rig with some RAM. I'm using a 1080ti and 16GB RAM; 8GB+ is often in used. You _can_ use a standard PC, no GPU (CPU-only); in that case `pip install -I tensorflow==1.5.0rc1` (instead of `tensorflow-gpu`). The only downside is performance; CPU is _way_ slower than GPU for ConvNet computations. Worth evaluating this repo on a CPU before you decide \"yeah, it's worth the upgrade.\"\n\n### 2. Populate Data\n- Download [mczielinski\u002Fbitcoin-historical-data](https:\u002F\u002Fwww.kaggle.com\u002Fmczielinski\u002Fbitcoin-historical-data)\n- Extract to `data\u002Fbitcoin-historical-data`\n- `python -c 'from data.data import setup_runs_table;setup_runs_table()'`\n  - if you get `ModuleNotFoundError: No module named 'data.data'`, prefix commands with `PYTHONPATH=. python ...`\n  - If you have trouble with that, just copy\u002Fpaste the SQL from that file, execute against your `hyper_runs` DB from above.\n\n### 3. Hypersearch\nThe crux of practical reinforcement learning is finding the right hyper-parameter combo (things like neural-network width\u002Fdepth, L1 \u002F L2 \u002F Dropout numbers, etc). Some papers have listed optimal default hypers. Eg, the Proximate Policy Optimization (PPO) [paper](https:\u002F\u002Fblog.openai.com\u002Fopenai-baselines-ppo\u002F) has a set of good defaults. But in my experience, they don't work well for our purposes (time-series \u002F trading). I'll keep my own \"best defaults\" updated in this project, but YMMV and you'll very likely need to try different hyper combos yourself. The file `hypersearch.py` will search hypers forever, ever honing in on better and better combos (using Bayesian Optimization (BO), see `gp.py`). See Hypersearch section below for more details.\n\n`python hypersearch.py`\n\nOptional flags:\n- `--guess \u003Cint>`: sometimes you don't want BO, which is pretty willy-nilly at first, to do the searching. Instead you want to try a hunch or two of your own first. See instructions in `utils.py#guess_overrides`.\n- `--net-type \u003Clstm|conv2d>`: see discussion below (LSTM v CNN)\n- `--boost`: you can optionally use gradient boosting when searching for the best hyper combo, instead of BO. BO is more exploratory and thorough, gradient boosting is more \"find the best solution _now_\". I tend to use `--boost` after say 100 runs are in the database, since BO may still be dilly-dallying till 200-300 and daylight's burning. Boost will suck in the early runs.\n- `--autoencode`: many of you might hit some GPU RAM constraints (hypersearch crashes due to maxed memory). If so, use this flag. It dimensionality-reduces the price-history timesteps so more can fit into RAM. It does so destructively - think of lossy image compression - but might be required for your case. See [#6](https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F6#issuecomment-364179764) for info on what leads to mem-maxing.\n- `--n-steps \u003Cint>`, `--n-tests \u003Cint>`: vary how long to train and how often to report. `n-steps` is number of timesteps to train (in 10k; ie `--n-steps 100` means 1M). `n-tests` is how many times to split that and report back to you \u002F save an entry for viz.\n\n### 4. Run\nOnce you've found a good hyper combo from above (this could take days or weeks!), it's time to run your results.\n\n`python run.py --name \u003Cstr>`\n\n- `--name \u003Cstr>` (required): name of the folder to save your run (during training) or load from (during `--live\u002F--test-live`.\n- `--id \u003Cint>`: the id of some winning hyper-combo you want to run with. Without this, it'll run from the hard-coded hyper defaults.\n- `--early-stop \u003Cint>`: sometimes your models can overfit. In particular, PPO can give you great performance for a long time and then crash-and-burn. That kind of behavior will be obvious in your visualization (below), so you can tell your run to stop after x consecutive positive episodes (depends on the agent - some find an optimum and roll for 3 positive episodes, some 8, just eyeball your graph).\n- `--live`: whooa boy, time to put your agent on GDAX and make real trades! I'm gonna let you figure out how to plug it in on your own, 'cause that's danger territory. I ain't responsible for shit. In fact, let's make that real - disclaimer at the end of README.\n- `--test-live`: same as `live`, but without making the real trades. This will start monitoring a live-updated database (from config.json), same as `live`, but instead of making the actual trade, it pretends it did and reports back how much you would have made\u002Flost. Dry-run. You'll definitely want to run this once or twice before running `--live`.\n\nFirst, run `python run.py [--id 10] --name test`. This will train your model using run 10 (from `hypersearch.py`) and save to `saves\u002Ftest`. Without `--id` it will use the hard-coded deafults. You can hit `Ctrl-C` _once_ during training to kill training (in case you see a sweet-spot and don't want to overfit).\nSecond, run `python run.py [--id 10] --name test --[test-]live` to run in live\u002Ftest-live mode. If you used `--id` before, use it again here so that loading the model matches it to its net architecture.\n\n## 5. Visualize\nTensorForce comes pre-built with reward visualization on a TensorBoard. Check out their Github, you'll see. I needed much more customization than that for viz, so we're not using TensorBoard. I created a mini Flask server (2 routes) and a D3 React dashboard where you can slice & dice hyper combos, visualize progression, etc. If you click on a single run, it'll display a graph of the buy\u002Fsell signals that agent took in a time-slice (test-set) so you can eyeball whether he's being smart.\n\n- Server: `cd visualize;FLASK_APP=server.py flask run`\n- Client:\n  - `cd visualize\u002Fclient`\n  - `npm install;npm install -g webpack-dev-server`\n  - `npm start` => localhost:8080\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flefnire_tforce_btc_trader_readme_5abebac5aa0e.png)\n\n---\n\n## About\n\nThis project is a [TensorForce](https:\u002F\u002Fgithub.com\u002Freinforceio\u002Ftensorforce)-based Bitcoin trading bot (algo-trader). It uses deep reinforcement learning to automatically buy\u002Fsell\u002Fhold BTC based on what it learns about BTC price history. Most blogs \u002F tutorials \u002F boilerplate BTC trading-bots you'll find out there use supervised machine learning, likely an LTSM. That's well and good - supervised learning learns what makes a time-series tick so it can predict the next-step future. But that's where it stops. It says \"the price will go up next\", but it doesn't tell you what to do. Well that's simple, buy, right? Ah, buy low, sell high - it's not that simple. Thousands of lines of code go into trading rules, \"if this then that\" style. Reinforcement learning takes supervised to the next level - it _embeds_ supervised within its architecture, and then decides what to do. It's beautiful stuff! Check out:\n\n- [Sutton & Barto](http:\u002F\u002Famzn.to\u002F2EWvnVf): de-facto textbook on RL basics\n- [CS 294](http:\u002F\u002Frll.berkeley.edu\u002Fdeeprlcourse\u002F): the modern deep-learning spin on ^.\n- [Machine Learning for Trading](https:\u002F\u002Fwww.udacity.com\u002Fcourse\u002Fmachine-learning-for-trading--ud501): teaches you algo-trading, stock stuff, and applied RL.\n\nThis project goes with Episode 26+ of [Machine Learning Guide](http:\u002F\u002Focdevel.com\u002Fpodcasts\u002Fmachine-learning). Those episodes are tutorial for this project; including an intro to Deep RL, hyperparameter decisions, etc.\n\n\n### Data\nFor this project I recommend using the Kaggle dataset described in Setup. It's a really solid dataset, best I've found! I'm personally using a friend's live-ticker DB. Unfortunately you can't. It's his personal thing, he may one day open it up as a paid API or something, we'll see. There's also some files in `data\u002Fpopulate` which use the CryptoWat.ch API. Great API _going forward_, but doesn't have the history you'll need to train on. If any y'all find anything better than the Kaggle set, LMK.\n\nSo here's how this project splits up databases (see `config.json`). We start with a `history` DB, which has all the historical BTC prices for multiple exchanges. Import it, train on it. Then we have an optionally separate `runs` database, which saves the results of each of your `hypersearch.py` runs. This data is used by our BO or Boost algo to search for better hyper combos. You can have `runs` table in your `history` database if you want, one-and-the-same. I have them separate because I want the `history` DB on localhost for performance reason (it's a major perf difference, you'll see), and `runs` as a public hosted DB, which allows me to collect runs from separate AWS p3.8xlarge running instances.\n\nThen, when you're ready for live mode, you'll want a `live` database which is real-time, constantly collecting exchange ticker data. `--live` will handle keeping up with that database. Again, these can all 3 be the same database if you want, I'm just doing it my way for performance.\n\n### LSTM v CNN\nYou'll notice the `--net-type \u003Clstm|conv2d>` flag in `hypersearch.py` and `run.py`. This will select between an LSTM Recurrent Neural Networks (RNNs) or Convolutional Neural Networks (CNN). I have them broken out of the hypersearch since they're so different, they kinda deserve their own `runs` DB each - but if someone can consolidate them into the hypersearch framework, please do. You may be thinking, \"BTC prices is time-series, time-series is LSTM... why CNN?\" It strangely turns out that LSTM doesn't do so hot here. In my own experience, in colleagues' experience, and in 2-3 papers I've read ([here's one](https:\u002F\u002Farxiv.org\u002Fpdf\u002F1706.10059.pdf)) - we're all coming to the same conclusion. We're not sure why... the running theory is vanishing\u002Fexploding gradient. LSTMs work well in NLP which has some maximum 50-word sentences or so. LSTMs mitigated vanilla RNN's vanishing\u002Fexploding gradient for such sentences, true - but BTC history is infinite (on-going). Maybe LSTM can only go so far with time-series. Another possibility is that Deep Reinforcement Learning is most commonly researched, published, and open-sourced using CNNs. This because RL is super video-game centric, self-driving cars, all the vision stuff. So maybe the math behind these models lends better to CNNs? Who knows. The point is - experiment with both. Report back on Github your own findings.\n\nSo how does CNN even make sense for time-series? Well we construct an \"image\" of a time-slice, where the x-axis is time (obviously), the y-axis (height) is nothing... it's [1]. The z-axis (channels) is features (OHLCV, VWAP, bid\u002Fask, etc). This is kinda like our agent literally looking at an image of price actions, like we do when day-trading, but a bit more robot-friendly \u002F less human-friendly.\n\n[Update March 04 2018]: I'm having better success recently w\u002F LSTMs and have made that the default. A change in TensorForce perhaps?\n\n### Reinforcement Models\n\nTensorForce has all sorts of models you can play with. This project currently only supports Proximate Policy Optimization (PPO), but I encourage y'all to add in other models (esp VPG, TRPO, DDPG, ACKTR, etc) and submit PRs. ACKTR is the current state-of-the-art Policy Gradient model, but not yet available in TensorForce. PPO is the second-most-state-of-the-art, so we're using that. TRPO is 3rd, VPG is old. DDPG I haven't put much thought into.\n\nThose are the Policy Gradient models. Then there's the Q-Learning approaches (DQNs, etc). We're not using those because they only support discrete actions, not continuous actions. Our agent has one discrete action (buy|sell|hold), and one continuous action (how much?). Without that \"how much\" continuous flexibility, building an algo-trader would be... well, not so cool. You could do something like (discrete action = (buy-$200, sell-$200, hold)), but I dunno man... continuous is slicker.\n\n### Hypersearch\n\nYou're likely familiar with _grid search_ and _random search_ when searching for optimial hyperparameters for machine learning models. Grid search searches literally every possible combo - exhaustive, but takes infinity years (especially w\u002F the number of hypers we work with in this project). Random search throws a dart at random hyper combos over and over, and you just kill it eventually and take the best. Super naive - it works ok for other ML setups, but in RL hypers are the make-or-break; more than model selection. Seriously, I've found L1 \u002F L2 \u002F Dropout selection more consequential than PPO vs DQN, LSTM vs CNN, etc.\n\nThat's why we're using Bayesian Optimization (BO). Or sometimes you'll hear Gaussian Processes (GP), the thing you're optimizing with BO. See `gp.py`. BO starts off like random search, since it doesn't have anything to work with; and over time it hones in on the best hyper combo using Bayesian inference. Super meta - use ML to find the best hypers for your ML - but makes sense. Wait, why not use RL to find the best hypers? We could (and I tried), but deep RL takes 10s of thousands of runs before it starts converging; and each run takes some 8hrs. BO converges much quicker. I've also implemented my own flavor of hypersearch via Gradient Boosting (if you use `--boost` during training); more for my own experimentation.\n\nWe're using `gp.py`, which comes from [thuijskens\u002Fbayesian-optimization](https:\u002F\u002Fgithub.com\u002Fthuijskens\u002Fbayesian-optimization). It uses scikit-learn's in-built GP functions. I also considered dedicated BO modules, like GPyOpt. I found `gp.py` easier to work with, but haven't compared it's relative performance, nor its optimal hypers (yes, BO has its own hypers... it's turtles all the way down. But luckily I hear you can pretty safely use BO's defaults). If anyone wants to explore any of that territory, please indeed!\n\n### License: AGPLv3.0\n\nGPL bit so we share our findings. Community effort, right? Boats and tides. Affero bit so we can all run our own trading instances w\u002F personal configs \u002F mods. Heck, any of us could run this as a service \u002F hedge fund. I'm pretty keen on this license, having used it in a prior [internet company](https:\u002F\u002Fhabitica.com) I'd founded; but if someone feels strongly about a different license, please open an issue & LMK - open to suggestions. See LICENSE.\n\n### Disclaimer\n\nBy using this code you accept all responsibility for money lost because of this code.\n\nFYI, I haven't made a dime. Doubtful the project as-is will fly. It could benefit from add-ons, like some NLP fundamentals functionality. But it's a start!\n","# TensorForce 比特币交易机器人\n\n## 更新 2018-08-14\n标签 v0.1 包含与本 README 文件一致的代码。标签 v0.2 是在金融工作中吸取教训后进行的重大重构，因此本 README 的大部分内容将不再适用于新代码。无论哪种情况，我都无法让测试收敛，这表明该项目存在根本性的缺失——也就是说，请不要指望通过它赚钱（建议将其作为起点或学习工具）。我将暂时退出该项目，并且在此处不会太活跃，但我并未完全放弃。\n\n---\n\n\n[![加入 https:\u002F\u002Fgitter.im\u002Flefnire\u002Ftforce_btc_trader 的聊天](https:\u002F\u002Fbadges.gitter.im\u002Flefnire\u002Ftforce_btc_trader.svg)](https:\u002F\u002Fgitter.im\u002Flefnire\u002Ftforce_btc_trader?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n一个基于 [TensorForce](https:\u002F\u002Fgithub.com\u002Freinforceio\u002Ftensorforce) 的比特币交易机器人（算法交易者）。利用深度强化学习，根据价格历史自动进行 BTC 的买入、卖出或持有操作。\n\n该项目与 [机器学习指南](http:\u002F\u002Focdevel.com\u002Fpodcasts\u002Fmachine-learning) 第 26 集及后续内容配套使用。这些集数是针对该项目的教程，包括深度强化学习简介、超参数选择等内容。\n\n### 1. 设置\n- Python 3.6+（我大量使用了 f-string）\n- 安装并配置 PostgreSQL\n  - 创建两个数据库：`btc_history` 和 `hyper_runs`。你可以为它们命名任意名称，如果愿意也可以只使用一个数据库（参见“数据”部分）。\n  - 执行 `cp config.example.json config.json`，并将上述信息填入 `config.json` 中。\n- 手动安装 [TA-Lib](https:\u002F\u002Fgithub.com\u002Fmrjbq7\u002Fta-lib)。\n- 运行 `pip install -r requirements.txt`\n  - 如果遇到问题，可以尝试手动安装这些依赖项。\n- 从 Git 仓库安装 TensorForce（不断更新，我们跟踪最新版本）\n  - `git clone https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftensorforce.git`\n  - `cd tensorforce && pip install -e .`\n\n注意：建议在配备一定内存的 GPU 设备上运行此项目。我使用的是 1080ti 显卡和 16GB 内存；通常会占用 8GB 以上的内存。你也可以在没有 GPU 的普通 PC 上运行（仅 CPU），此时需要执行 `pip install -I tensorflow==1.5.0rc1`（而不是 `tensorflow-gpu`）。唯一的缺点是性能：对于卷积神经网络计算而言，CPU 的速度远低于 GPU。在决定是否升级硬件之前，不妨先在 CPU 上评估一下这个项目。\n\n### 2. 填充数据\n- 下载 [mczielinski\u002Fbitcoin-historical-data](https:\u002F\u002Fwww.kaggle.com\u002Fmczielinski\u002Fbitcoin-historical-data)\n- 解压到 `data\u002Fbitcoin-historical-data`\n- 运行 `python -c 'from data.data import setup_runs_table;setup_runs_table()'`\n  - 如果出现 `ModuleNotFoundError: No module named 'data.data'` 错误，请在命令前添加 `PYTHONPATH=. python ...`。\n  - 如果仍然有问题，可以直接复制该文件中的 SQL 语句，并在前面创建的 `hyper_runs` 数据库中执行。\n\n### 3. 超参数搜索\n实际强化学习的核心在于找到合适的超参数组合（例如神经网络的宽度和深度、L1\u002FL2 正则化系数、Dropout 率等）。一些论文已经列出了最优的默认超参数。例如，近端策略优化（PPO）的论文 [OpenAI Baselines PPO](https:\u002F\u002Fblog.openai.com\u002Fopenai-baselines-ppo\u002F) 提供了一组不错的默认值。但根据我的经验，这些默认值并不适合我们的场景（时间序列\u002F交易）。我会在这个项目中持续更新我个人认为的最佳默认值，不过结果因人而异，你很可能需要自己尝试不同的超参数组合。文件 `hypersearch.py` 将会无限期地搜索超参数，不断优化出更好的组合（使用贝叶斯优化 BO，详见 `gp.py`）。更多细节请参阅下方的“超参数搜索”部分。\n\n`python hypersearch.py`\n\n可选参数：\n- `--guess \u003Cint>`：有时你可能不希望一开始由随机性较强的贝叶斯优化来搜索超参数，而是想先尝试一两个自己的猜测。具体说明请参见 `utils.py#guess_overrides`。\n- `--net-type \u003Clstm|conv2d>`：请参阅下方关于 LSTM 与 CNN 的讨论。\n- `--boost`：在寻找最佳超参数组合时，你可以选择梯度提升而非贝叶斯优化。贝叶斯优化更具探索性和全面性，而梯度提升则更倾向于“立即找到最佳方案”。我通常会在数据库中积累了约 100 次试验结果后使用 `--boost`，因为贝叶斯优化可能还需要 200 到 300 次试验才能达到理想效果，而时间却很紧迫。梯度提升可以快速捕捉到早期的优秀结果。\n- `--autoencode`：许多用户可能会遇到 GPU 内存不足的问题（超参数搜索因内存耗尽而崩溃）。如果出现这种情况，请使用此标志。它会对价格历史的时间步长进行降维处理，以便更多数据能够容纳在内存中。这种降维是破坏性的——类似于有损图像压缩——但在某些情况下可能是必要的。有关导致内存耗尽的原因，请参阅 [#6](https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F6#issuecomment-364179764)。\n- `--n-steps \u003Cint>`、`--n-tests \u003Cint>`：调整训练时长以及报告频率。`n-steps` 表示训练的时间步长数量（以 1 万为单位；例如 `--n-steps 100` 表示 100 万步）。`n-tests` 表示将训练过程分成多少个阶段进行报告，并保存用于可视化的内容。\n\n### 4. 运行\n当你从上述步骤中找到了一组合适的超参数组合后（这可能需要几天甚至几周的时间），就可以开始运行你的模型了。\n\n`python run.py --name \u003Cstr>`\n\n- `--name \u003Cstr>`（必填）：保存训练结果或加载已保存结果的文件夹名称（用于 `--live\u002F--test-live` 模式）。\n- `--id \u003Cint>`：指定要运行的获胜超参数组合的 ID。如果不指定，则会使用硬编码的默认超参数。\n- `--early-stop \u003Cint>`：有时模型可能会过拟合。特别是 PPO，在一段时间内表现优异，随后可能会突然崩盘。这种行为会在可视化图表中清晰地体现出来，因此你可以设置在连续出现 x 次正收益后停止运行（具体次数取决于智能体的表现——有些智能体在达到最佳状态后只会持续 3 次正收益，而有些则能持续 8 次，你可以根据图表自行判断）。\n- `--live`：现在是时候将你的智能体部署到 GDAX 平台并进行真实交易了！如何接入平台的具体细节需要你自己解决，因为这属于高风险操作，我对此不承担任何责任。事实上，让我们明确这一点——请参阅 README 最后的免责声明。\n- `--test-live`：与 `--live` 类似，但不会真正执行交易。它会监控来自 `config.json` 的实时更新数据库，就像 `--live` 一样，只是不会实际成交，而是模拟交易结果，并报告你原本可能获得或损失的金额。这是一种试运行的方式。在正式启用 `--live` 之前，强烈建议你至少运行一两次 `--test-live`。\n\n首先，运行 `python run.py [--id 10] --name test`。这将使用 `hypersearch.py` 中的第 10 组超参数训练模型，并保存到 `saves\u002Ftest` 目录下。如果没有指定 `--id`，则会使用硬编码的默认超参数。在训练过程中，你可以按 `Ctrl-C` 一次来终止训练（如果你发现某个超参数组合已经达到最佳效果，不想继续过拟合的话）。\n其次，运行 `python run.py [--id 10] --name test --[test-]live` 来以实时\u002F测试实时模式运行。如果你之前指定了 `--id`，这里也需要再次指定，以确保加载的模型与其对应的网络架构相匹配。\n\n## 5. 可视化\nTensorForce 内置了在 TensorBoard 上进行奖励可视化的功能。你可以去他们的 GitHub 仓库看看就知道了。不过我需要的可视化定制程度远超这个，所以我们没有使用 TensorBoard。我搭建了一个小型的 Flask 服务器（两个路由）和一个基于 D3 的 React 仪表板，你可以在其中自由组合超参数、查看训练进度等。点击某一次运行记录，就会显示该智能体在某个时间片（测试集）内发出的买入\u002F卖出信号图，这样你就能直观地判断它是否做出了合理的决策。\n\n- 服务器：`cd visualize;FLASK_APP=server.py flask run`\n- 客户端：\n  - `cd visualize\u002Fclient`\n  - `npm install;npm install -g webpack-dev-server`\n  - `npm start` => localhost:8080\n\n![](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flefnire_tforce_btc_trader_readme_5abebac5aa0e.png)\n\n---\n\n## 关于\n本项目是一个基于 TensorForce 的比特币交易机器人（算法交易者）。它利用深度强化学习，根据对 BTC 价格历史的学习结果，自动执行买入、卖出或持有操作。市面上大多数关于 BTC 交易机器人的博客、教程或代码模板都采用监督学习，通常是 LSTM 模型。这种做法确实不错——监督学习能够捕捉时间序列的规律，从而预测下一步走势。然而，它仅止于此：它会告诉你“接下来价格会上涨”，却不会指导你该如何操作。听起来很简单——买进不就行了？但事实并非如此。“低买高卖”并不是一件容易的事。实际交易中往往涉及成千上万行的规则逻辑，比如“如果……那么……”。而强化学习则将监督学习提升到了一个新的层次：它不仅将监督学习嵌入到自身的架构中，还会进一步决定具体的操作策略。这真是非常精妙的设计！推荐参考以下资源：\n\n- [Sutton & Barto](http:\u002F\u002Famzn.to\u002F2EWvnVf)：强化学习领域的经典教材。\n- [CS 294](http:\u002F\u002Frll.berkeley.edu\u002Fdeeprlcourse\u002F)：现代深度学习视角下的强化学习课程。\n- [Machine Learning for Trading](https:\u002F\u002Fwww.udacity.com\u002Fcourse\u002Fmachine-learning-for-trading--ud501)：教授算法交易、股票相关知识以及强化学习的实际应用。\n\n本项目与《机器学习指南》第 26 集及后续内容相配合。这些集数为本项目提供了详细的教程，包括深度强化学习的入门知识、超参数调优等内容。\n\n\n### 数据\n对于该项目，我推荐使用“设置”部分提到的 Kaggle 数据集。这是一个非常可靠的数据集，是我目前找到的最佳选择！我个人则使用一位朋友提供的实时行情数据库。不过很遗憾，你无法直接访问他的数据，因为这是他个人维护的资源，未来可能会以付费 API 的形式对外开放，我们拭目以待。此外，在 `data\u002Fpopulate` 目录下还有一些文件，它们使用 CryptoWat.ch 的 API 获取数据。这个 API 在未来很有用，但它缺乏足够的历史数据来支持模型训练。如果你发现了比 Kaggle 数据集更好的替代方案，请随时告诉我。\n\n本项目的数据库划分如下（参见 `config.json` 文件）。首先是一个 `history` 数据库，存储了多个交易所的历史 BTC 价格数据。你需要导入这些数据并以此进行训练。其次是一个可选的 `runs` 数据库，用于保存每次运行 `hypersearch.py` 的结果。这部分数据会被我们的 BO 或 Boost 算法用来搜索更优的超参数组合。当然，你也可以将 `runs` 表直接放在 `history` 数据库中，两者合二为一。我之所以分开管理，是因为我希望将 `history` 数据库部署在本地以提升性能（实际效果非常明显），而将 `runs` 数据库托管在云端，这样我可以从不同的 AWS p3.8xlarge 实例中收集运行结果。\n\n最后，当你准备进入实盘交易模式时，就需要一个实时更新的 `live` 数据库，持续采集交易所的行情数据。`--live` 参数会负责保持该数据库的同步更新。同样地，这三个数据库也可以合并为一个，我只是出于性能考虑选择了这样的架构。\n\n### LSTM vs CNN\n你会注意到 `hypersearch.py` 和 `run.py` 中有一个 `--net-type \u003Clstm|conv2d>` 的命令行参数。它用于选择使用 LSTM 循环神经网络还是卷积神经网络。我将这两种网络类型单独列出，是因为它们差异较大，各自适合不同的应用场景，甚至可以分别使用独立的 `runs` 数据库。不过，如果有谁能将它们整合到统一的超参数搜索框架中，请务必提出 Pull Request。你可能会疑惑：“BTC 价格是时间序列数据，时间序列通常用 LSTM 处理，为什么还要用 CNN 呢？”令人意外的是，LSTM 在这里的表现并不理想。无论是我的经验、同事的经验，还是我读过的两三篇论文（例如这篇 [arxiv.org\u002Fpdf\u002F1706.10059.pdf]），大家得出的结论都是一致的。至于原因尚不明确，目前比较流行的说法是梯度消失或爆炸问题。LSTM 在 NLP 领域表现良好，因为那里的句子长度通常不超过 50 个词左右。LSTM 正是为了解决普通 RNN 在处理这类短序列时可能遇到的梯度消失或爆炸问题而设计的。然而，BTC 的价格历史却是无限延续的，也许 LSTM 对于如此长的时间序列已经力不从心了。另一种可能性是，深度强化学习的研究、发表和开源实现大多基于 CNN，因为强化学习最初主要应用于视频游戏、自动驾驶等视觉相关的场景。因此，CNN 的数学框架或许更适合强化学习模型。当然，这只是推测，具体情况还需要通过实验来验证。建议大家同时尝试这两种模型，并将自己的发现反馈到 GitHub 上。\n\n那么，CNN 究竟如何适用于时间序列数据呢？其实我们可以将时间片段构造成一张“图像”：横轴代表时间，纵轴（高度）没有任何意义，直接设为 1；而 z 轴（通道）则表示各种特征，如开盘价、收盘价、最高价、最低价、成交量加权平均价、买卖盘等。这样一来，我们的智能体就仿佛在观察价格走势的图像，就像我们在日内交易时所做的那样，只不过这种方式更加符合机器的处理方式，相对人类而言则稍显复杂。\n\n[更新：2018 年 3 月 4 日] 近期我在 LSTM 方面取得了更好的效果，因此已将其设为默认选项。这会不会是 TensorForce 更新带来的变化呢？\n\n### 强化学习模型\nTensorForce 提供了多种可供选择的强化学习模型。目前本项目仅支持近端策略优化（PPO），但我鼓励大家继续添加其他模型（尤其是 VPG、TRPO、DDPG、ACKTR 等），并提交 Pull Request。ACKTR 是当前最先进的策略梯度模型，但尚未在 TensorForce 中实现。PPO 则是第二先进的模型，所以我们暂时选用它。TRPO 排名第三，VPG 已经较为老旧，而 DDPG 我还没有深入研究过。\n\n除了策略梯度类模型之外，还有 Q 学习类方法（如 DQN 等）。不过我们并未采用这些方法，因为它们只支持离散动作，而不支持连续动作。我们的智能体既有离散动作（买入、卖出、持有），也有连续动作（交易量大小）。如果没有“交易量大小”这一连续灵活性，构建一个真正的算法交易系统就显得不够完善。虽然理论上可以通过设定固定的交易金额（如买入 200 美元、卖出 200 美元等）来模拟离散动作，但显然不如连续动作来得灵活高效。\n\n### 超参数搜索\n\n在为机器学习模型寻找最优超参数时，你可能已经熟悉“网格搜索”和“随机搜索”。网格搜索会遍历所有可能的组合——虽然全面，但耗时极长（尤其是在我们这个项目中涉及的超参数数量较多的情况下）。而随机搜索则是随机尝试不同的超参数组合，最终选择表现最好的那组。这种方法非常简单粗暴，在其他机器学习场景下尚可接受，但在强化学习领域，超参数的选择往往决定成败，其重要性甚至超过模型本身的选择。说实话，我曾发现，L1 正则化、L2 正则化以及 Dropout 的设置，比选择 PPO 还是 DQN、LSTM 还是 CNN 等因素的影响还要大。\n\n因此，我们采用了贝叶斯优化（BO）。有时你也可能会听到“高斯过程”（GP），因为贝叶斯优化正是基于高斯过程来进行优化的。相关实现请参见 `gp.py` 文件。贝叶斯优化起初类似于随机搜索，因为它一开始并没有任何先验信息；随着时间推移，它会利用贝叶斯推断逐步聚焦到最佳的超参数组合上。这种做法颇具元学习的意味——用机器学习来寻找最适合机器学习的超参数——但逻辑上也说得通。那么，为什么不直接用强化学习来寻找最优超参数呢？理论上是可以的（我也确实尝试过），然而深度强化学习通常需要数万次迭代才能开始收敛，而每次运行又需要大约 8 小时。相比之下，贝叶斯优化收敛得快得多。此外，我还通过梯度提升实现了自己的一套超参数搜索方法（训练时使用 `--boost` 参数），这主要是为了个人实验之用。\n\n我们目前使用的 `gp.py` 源自 [thuijskens\u002Fbayesian-optimization](https:\u002F\u002Fgithub.com\u002Fthuijskens\u002Fbayesian-optimization) 项目，它直接调用了 scikit-learn 内置的高斯过程功能。我也曾考虑过专门的贝叶斯优化库，比如 GPyOpt。不过，我发现 `gp.py` 更易于使用，只是尚未对其性能与最优超参数进行过系统比较（没错，贝叶斯优化本身也有自己的超参数……真是层层嵌套啊！不过好在据说直接使用默认值通常也能取得不错的效果）。如果有朋友对这些方面感兴趣，欢迎进一步探索！\n\n### 许可证：AGPLv3.0\n\n采用 GPL 协议是为了促进研究成果的共享，毕竟这是社区共同的努力嘛。就像乘船顺流而下一样，顺势而为。加上 Affero 条款，则是为了让大家能够基于各自的配置或修改，独立运行属于自己的交易实例。事实上，我们任何人都可以将这套系统作为一项服务或对冲基金来运营。我对这种许可证非常认同，此前在我创办的一家互联网公司 Habitica 中也曾使用过类似的许可协议。当然，如果你更倾向于其他许可证，请随时提交议题并告知我们，我们非常乐意听取建议。详情请参阅 LICENSE 文件。\n\n### 免责声明\n\n使用本代码即表示你同意自行承担因该代码而导致的所有资金损失责任。\n\n顺便一提，截至目前我本人并未从中获利。而且以当前的形式来看，这个项目短期内恐怕难以取得成功。如果能加入一些附加功能，比如基础的自然语言处理能力，或许会更有价值。不过，至少这是一个不错的起点！","# tforce_btc_trader 快速上手指南\n\ntforce_btc_trader 是一个基于 TensorForce 的比特币交易机器人，利用深度强化学习（Deep RL）根据历史价格自动执行买入、卖出或持有操作。本项目适合作为学习深度强化学习在金融时间序列中应用的起点。\n\n> **注意**：作者明确表示该项目的测试尚未收敛，**切勿直接用于真实资金交易**。请仅将其作为教育和技术探索工具。\n\n## 环境准备\n\n### 系统要求\n- **操作系统**：Linux \u002F macOS \u002F Windows (推荐 Linux)\n- **Python 版本**：3.6+ (项目大量使用模板字符串)\n- **硬件建议**：\n  - **推荐**：配备 GPU 的机器（如 NVIDIA 1080ti），内存 16GB+（训练过程常占用 8GB+ 显存\u002F内存）。\n  - **最低**：普通 PC（仅 CPU），但 ConvNet 计算速度会显著慢于 GPU。若仅使用 CPU，需安装 `tensorflow==1.5.0rc1` 而非 `tensorflow-gpu`。\n\n### 前置依赖\n1. **PostgreSQL 数据库**\n   - 安装并启动 PostgreSQL 服务。\n   - 创建两个数据库（也可合并为一个）：\n     ```sql\n     CREATE DATABASE btc_history;\n     CREATE DATABASE hyper_runs;\n     ```\n2. **TA-Lib 技术指标库**\n   - 需手动安装底层 C 库及 Python 包装器。\n   - **Ubuntu\u002FDebian**:\n     ```bash\n     wget http:\u002F\u002Fprdownloads.sourceforge.net\u002Fta-lib\u002Fta-lib-0.4.0-src.tar.gz\n     tar -xzf ta-lib-0.4.0-src.tar.gz\n     cd ta-lib\u002F\n     .\u002Fconfigure --prefix=\u002Fusr\n     make\n     sudo make install\n     ```\n   - 随后通过 pip 安装 Python 接口：`pip install TA-Lib` (或在后续步骤统一安装)。\n\n## 安装步骤\n\n1. **克隆项目并配置**\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader.git\n   cd tforce_btc_trader\n   cp config.example.json config.json\n   # 编辑 config.json，填入你的数据库连接信息\n   ```\n\n2. **安装 Python 依赖**\n   ```bash\n   pip install -r requirements.txt\n   ```\n   *注：若安装失败，请尝试手动安装报错的依赖包。*\n\n3. **安装 TensorForce (开发版)**\n   由于原版 TensorForce 更新频繁，本项目使用特定的 fork 版本：\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftensorforce.git\n   cd tensorforce\n   pip install -e .\n   cd ..\n   ```\n\n4. **准备数据**\n   - 下载 Kaggle 数据集：[mczielinski\u002Fbitcoin-historical-data](https:\u002F\u002Fwww.kaggle.com\u002Fmczielinski\u002Fbitcoin-historical-data)。\n   - 解压并将文件夹重命名为 `data\u002Fbitcoin-historical-data`。\n   - 初始化数据库表结构：\n     ```bash\n     # 若遇到 ModuleNotFoundError，请添加 PYTHONPATH=. 前缀\n     PYTHONPATH=. python -c 'from data.data import setup_runs_table;setup_runs_table()'\n     ```\n     *如果上述命令失败，可直接复制 `data\u002Fdata.py` 中的 SQL 语句并在你的 `hyper_runs` 数据库中执行。*\n\n## 基本使用\n\n本项目的核心流程分为：**超参数搜索 (Hypersearch)** -> **模型训练与运行 (Run)** -> **可视化 (Visualize)**。\n\n### 1. 超参数搜索 (寻找最佳模型配置)\n强化学习的效果高度依赖超参数（如网络层数、Dropout 率等）。使用贝叶斯优化自动搜索最佳组合：\n\n```bash\npython hypersearch.py\n```\n\n**常用可选参数：**\n- `--net-type \u003Clstm|conv2d>`: 选择神经网络类型（LSTM 或 CNN）。实验表明 CNN 在此场景下表现往往优于 LSTM。\n- `--boost`: 当数据库已有约 100 次运行记录后，使用梯度提升算法加速寻找最优解（比默认的贝叶斯优化更快收敛）。\n- `--autoencode`: 若遇到显存\u002F内存溢出，启用此标志进行降维处理（有损压缩）。\n- `--n-steps \u003Cint>`: 设置训练步数（单位为 1 万，例如 `100` 代表 100 万步）。\n\n*此过程可能耗时数天至数周，旨在找到胜率最高的配置 ID。*\n\n### 2. 运行模型 (训练与回测)\n找到理想的超参数组合后（假设 ID 为 10），进行正式训练和回测：\n\n**第一步：训练模型**\n```bash\npython run.py --id 10 --name test_run\n```\n- `--id`: 指定从 `hypersearch` 中发现的最佳配置 ID。若不填则使用默认硬编码参数。\n- `--name`: 指定保存模型的文件夹名称。\n- *提示*：训练中可按 `Ctrl-C` 一次以提前停止，防止过拟合。\n\n**第二步：模拟实盘回测 (Dry Run)**\n在真正实盘前，务必先进行“模拟实盘”测试：\n```bash\npython run.py --id 10 --name test_run --test-live\n```\n- 该模式会读取实时更新的数据库，模拟交易行为并报告盈亏，但**不会**实际下单。\n\n**第三步：实盘交易 (高风险，慎用)**\n```bash\npython run.py --id 10 --name test_run --live\n```\n- **警告**：此模式将连接交易所（如 GDAX\u002FCoinbase Pro）进行真实资金交易。作者不对任何资金损失负责。请务必先充分测试 `--test-live`。\n\n### 3. 可视化结果\n项目提供基于 Flask + D3 + React 的自定义仪表盘，用于分析超参数效果和交易信号。\n\n**启动后端服务：**\n```bash\ncd visualize\nFLASK_APP=server.py flask run\n```\n\n**启动前端界面：**\n```bash\ncd visualize\u002Fclient\nnpm install\nnpm install -g webpack-dev-server\nnpm start\n```\n访问 `http:\u002F\u002Flocalhost:8080` 即可查看图表。你可以点击具体的运行记录，查看代理在特定时间片段的买卖信号决策图。","一位量化交易开发者试图构建基于深度强化学习的比特币自动交易系统，以从历史价格波动中挖掘获利策略。\n\n### 没有 tforce_btc_trader 时\n- **算法整合困难**：开发者需手动搭建 TensorFlow 环境与强化学习框架的对接，耗费大量时间处理版本兼容与数据管道问题。\n- **调参盲目低效**：面对神经网络层数、学习率等海量超参数，缺乏自动化搜索机制，只能依靠经验盲目试错，难以找到最优组合。\n- **硬件门槛模糊**：不清楚模型训练对 GPU 显存的具体需求，常在普通 CPU 上浪费时间等待缓慢的卷积网络计算，验证周期极长。\n- **策略收敛无望**：由于缺乏成熟的基准代码和贝叶斯优化支持，编写的交易机器人长期无法在回测中实现策略收敛，甚至无法跑通基础测试。\n\n### 使用 tforce_btc_trader 后\n- **开箱即用架构**：直接复用基于 TensorForce 的成熟架构，快速完成 Postgres 数据库配置与 TA-Lib 技术指标集成，立即进入核心逻辑开发。\n- **智能超参搜索**：利用内置的 `hypersearch.py` 脚本结合贝叶斯优化算法，自动遍历并锁定适合时间序列交易的最佳超参数组合，大幅减少人工干预。\n- **明确硬件指引**：依据项目提供的 GPU（如 1080ti）与内存配置建议，合理部署训练环境，显著加速深度神经网络的迭代效率。\n- **教育式避坑指南**：参考作者关于“策略难收敛”的诚实预警与播客教程，将项目定位为学习起点而非直接印钞机，理性调整预期并专注于算法原理掌握。\n\ntforce_btc_trader 的核心价值在于为开发者提供了一个经过实战反思的深度强化学习交易基线，将原本高不可攀的算法实验转化为可执行的教育与研发起点。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Flefnire_tforce_btc_trader_5abebac5.png","lefnire","Tyler Renelle","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Flefnire_6627eacf.jpg","Creator of Gnothi, Machine Learning Guide, & Habitica","OCDevel LLC","Portland, OR","tylerrenelle@gmail.com",null,"https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Flefnire\u002F","https:\u002F\u002Fgithub.com\u002Flefnire",[25,29,33,37,41],{"name":26,"color":27,"percentage":28},"Jupyter Notebook","#DA5B0B",46,{"name":30,"color":31,"percentage":32},"Python","#3572A5",42.5,{"name":34,"color":35,"percentage":36},"JavaScript","#f1e05a",11.1,{"name":38,"color":39,"percentage":40},"HTML","#e34c26",0.2,{"name":42,"color":43,"percentage":40},"CSS","#663399",835,237,"2026-04-07T13:21:42","AGPL-3.0",4,"未说明","非必需，但强烈推荐。作者使用 NVIDIA 1080ti，需支持 TensorFlow GPU 版本。若仅使用 CPU 需安装特定版本 tensorflow==1.5.0rc1，但性能会显著下降。","推荐 16GB+（运行时常用 8GB+），最低未明确说明但暗示需较大内存以防崩溃",{"notes":53,"python":54,"dependencies":55},"1. 需手动安装 TA-Lib 库。2. 数据库需配置 PostgreSQL，并创建 'btc_history' 和 'hyper_runs' 两个数据库（可合并）。3. TensorForce 需从 GitHub 源码安装而非 pip。4. 项目警告测试难以收敛，不建议直接用于实盘赚钱，仅作学习起点。5. 若显存不足可使用 '--autoencode' 标志进行降维处理。6. 可视化部分需单独启动 Flask 服务器和 npm 前端服务。","3.6+",[56,57,58,59,60,61,62],"TensorForce (git HEAD 版本)","tensorflow-gpu 或 tensorflow==1.5.0rc1","TA-Lib","PostgreSQL","Flask","D3 \u002F React (用于可视化)","scikit-learn (隐含于贝叶斯优化\u002F梯度提升)",[64,65],"Agent","开发框架",2,"ready","2026-03-27T02:49:30.150509","2026-04-17T09:53:25.716823",[71,76,81,86,91,96],{"id":72,"question_zh":73,"answer_zh":74,"source_url":75},36959,"运行 kaggle.py 时出现 \"ModuleNotFoundError: No module named 'data'\" 错误怎么办？","这是因为 Python 无法找到 'data' 模块。需要在运行脚本前设置 PYTHONPATH 环境变量，将当前目录包含在搜索路径中。请使用以下命令运行：\nPYTHONPATH=. python data\u002Fpopulate\u002Fkaggle.py","https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F8",{"id":77,"question_zh":78,"answer_zh":79,"source_url":80},36960,"运行 hypersearch.py 时出现 \"AttributeError: 'NoneType' object has no attribute 'run'\" 错误如何解决？","该错误通常是由于 TensorForce 库的版本不兼容导致的。当前的 master 分支可能已发生较大变化。建议指定 requirement.txt 中 TensorForce 的具体提交版本（例如 f1c49de3），或者尝试更新 TensorForce 到与项目兼容的版本。","https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F18",{"id":82,"question_zh":83,"answer_zh":84,"source_url":85},36961,"可视化步骤报错 \"Cannot find module 'webpack'\" 怎么处理？","这是缺少 webpack 模块导致的。可以尝试全局安装 webpack，或者在项目目录下安装。解决方案如下：\n1. 全局安装：npm install --global webpack\n2. 或者使用 yarn 添加依赖：yarn add webpack-dev-server@^2.11.1","https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F24",{"id":87,"question_zh":88,"answer_zh":89,"source_url":90},36962,"使用 memory 分支训练时 GPU 内存占用异常或出现 Allocator 内存不足警告怎么办？","TensorForce 的 memory 分支在处理批次数据时使用 episode-batches 而非 step-batches，这会显著增加内存负载。如果遇到 GPU 内存溢出（OOM）警告或性能波动，请拉取最新的 memory 分支代码。注意，该分支暂时禁用了单个 runner 的 session_config（GPU 分割功能），这反而可能有助于缓解内存最大化问题。避免手动进行 GPU 分割配置。","https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F6",{"id":92,"question_zh":93,"answer_zh":94,"source_url":95},36963,"修复 \"No module named 'data'\" 错误后，又出现 \"'data' is not a package\" 错误是什么原因？","这通常是因为目录结构中没有正确的 __init__.py 文件，导致 Python 不将 'data' 识别为包。该问题已在 PR #14 中修复。请确保拉取了包含修复的最新代码，并检查 data 目录下是否存在 __init__.py 文件。","https:\u002F\u002Fgithub.com\u002Flefnire\u002Ftforce_btc_trader\u002Fissues\u002F13",{"id":97,"question_zh":98,"answer_zh":99,"source_url":80},36964,"遇到 \"connection is closed\" 错误随后引发 AttributeError 该如何处理？","这个问题通常与 TensorForce 的版本有关。维护者指出，通过更新 TensorForce 库可以解决连接关闭的问题，无需修改任何代码。请尝试升级 TensorForce 到最新版本或项目中指定的兼容版本。",[],[102,113,121,130,140,148],{"id":103,"name":104,"github_repo":105,"description_zh":106,"stars":107,"difficulty_score":108,"last_commit_at":109,"category_tags":110,"status":67},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[64,65,111,112],"图像","数据工具",{"id":114,"name":115,"github_repo":116,"description_zh":117,"stars":118,"difficulty_score":108,"last_commit_at":119,"category_tags":120,"status":67},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[65,111,64],{"id":122,"name":123,"github_repo":124,"description_zh":125,"stars":126,"difficulty_score":66,"last_commit_at":127,"category_tags":128,"status":67},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",158594,"2026-04-16T23:34:05",[65,64,129],"语言模型",{"id":131,"name":132,"github_repo":133,"description_zh":134,"stars":135,"difficulty_score":136,"last_commit_at":137,"category_tags":138,"status":67},8272,"opencode","anomalyco\u002Fopencode","OpenCode 是一款开源的 AI 编程助手（Coding Agent），旨在像一位智能搭档一样融入您的开发流程。它不仅仅是一个代码补全插件，而是一个能够理解项目上下文、自主规划任务并执行复杂编码操作的智能体。无论是生成全新功能、重构现有代码，还是排查难以定位的 Bug，OpenCode 都能通过自然语言交互高效完成，显著减少开发者在重复性劳动和上下文切换上的时间消耗。\n\n这款工具专为软件开发者、工程师及技术研究人员设计，特别适合希望利用大模型能力来提升编码效率、加速原型开发或处理遗留代码维护的专业人群。其核心亮点在于完全开源的架构，这意味着用户可以审查代码逻辑、自定义行为策略，甚至私有化部署以保障数据安全，彻底打破了传统闭源 AI 助手的“黑盒”限制。\n\n在技术体验上，OpenCode 提供了灵活的终端界面（Terminal UI）和正在测试中的桌面应用程序，支持 macOS、Windows 及 Linux 全平台。它兼容多种包管理工具，安装便捷，并能无缝集成到现有的开发环境中。无论您是追求极致控制权的资深极客，还是渴望提升产出的独立开发者，OpenCode 都提供了一个透明、可信",144296,1,"2026-04-16T14:50:03",[64,139],"插件",{"id":141,"name":142,"github_repo":143,"description_zh":144,"stars":145,"difficulty_score":66,"last_commit_at":146,"category_tags":147,"status":67},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[65,111,64],{"id":149,"name":150,"github_repo":151,"description_zh":152,"stars":153,"difficulty_score":66,"last_commit_at":154,"category_tags":155,"status":67},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[139,64,111,65]]