Skip to content

启动机器人

本页说明机器人的不同参数及其运行方式。

Note

如果使用过 setup.sh,在运行 freqtrade 命令前请务必激活虚拟环境(source .venv/bin/activate)。

系统时钟同步

运行机器人的系统时钟必须准确,需频繁与 NTP 服务器同步以避免与交易所通信出现问题。

机器人命令

usage: freqtrade [-h] [-V]
                 {trade,create-userdir,new-config,show-config,new-strategy,download-data,convert-data,convert-trade-data,trades-to-ohlcv,list-data,backtesting,backtesting-show,backtesting-analysis,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-markets,list-pairs,list-strategies,list-hyperoptloss,list-freqaimodels,list-timeframes,show-trades,test-pairlist,convert-db,install-ui,plot-dataframe,plot-profit,webserver,strategy-updater,lookahead-analysis,recursive-analysis}
                 ...

Free, open source crypto trading bot

positional arguments:
  {trade,create-userdir,new-config,show-config,new-strategy,download-data,convert-data,convert-trade-data,trades-to-ohlcv,list-data,backtesting,backtesting-show,backtesting-analysis,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-markets,list-pairs,list-strategies,list-hyperoptloss,list-freqaimodels,list-timeframes,show-trades,test-pairlist,convert-db,install-ui,plot-dataframe,plot-profit,webserver,strategy-updater,lookahead-analysis,recursive-analysis}
    trade               Trade module.
    create-userdir      Create user-data directory.
    new-config          Create new config
    show-config         Show resolved config
    new-strategy        Create new strategy
    download-data       Download backtesting data.
    convert-data        Convert candle (OHLCV) data from one format to
                        another.
    convert-trade-data  Convert trade data from one format to another.
    trades-to-ohlcv     Convert trade data to OHLCV data.
    list-data           List downloaded data.
    backtesting         Backtesting module.
    backtesting-show    Show past Backtest results
    backtesting-analysis
                        Backtest Analysis module.
    edge                Edge module. No longer part of Freqtrade
    hyperopt            Hyperopt module.
    hyperopt-list       List Hyperopt results
    hyperopt-show       Show details of Hyperopt results
    list-exchanges      Print available exchanges.
    list-markets        Print markets on exchange.
    list-pairs          Print pairs on exchange.
    list-strategies     Print available strategies.
    list-hyperoptloss   Print available hyperopt loss functions.
    list-freqaimodels   Print available freqAI models.
    list-timeframes     Print available timeframes for the exchange.
    show-trades         Show trades.
    test-pairlist       Test your pairlist configuration.
    convert-db          Migrate database to different system
    install-ui          Install FreqUI
    plot-dataframe      Plot candles with indicators.
    plot-profit         Generate plot showing profits.
    webserver           Webserver module.
    strategy-updater    updates outdated strategy files to the current version
    lookahead-analysis  Check for potential look ahead bias.
    recursive-analysis  Check for potential recursive formula issue.

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit

机器人交易命令

usage: freqtrade trade [-h] [-v] [--no-color] [--logfile FILE] [-V] [-c PATH]
                       [-d PATH] [--userdir PATH] [-s NAME]
                       [--strategy-path PATH] [--recursive-strategy-search]
                       [--freqaimodel NAME] [--freqaimodel-path PATH]
                       [--db-url PATH] [--sd-notify] [--dry-run]
                       [--dry-run-wallet DRY_RUN_WALLET] [--fee FLOAT]

options:
  -h, --help            show this help message and exit
  --db-url PATH         Override trades database URL, this is useful in custom
                        deployments (default: `sqlite:///tradesv3.sqlite` for
                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for
                        Dry Run).
  --sd-notify           Notify systemd service manager.
  --dry-run             Enforce dry-run for trading (removes Exchange secrets
                        and simulates trades).
  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET
                        Starting balance, used for backtesting / hyperopt and
                        dry-runs.
  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade
                        entry and exit).

Common arguments:
  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).
  --no-color            Disable colorization of hyperopt results. May be
                        useful if you are redirecting output to a file.
  --logfile FILE, --log-file FILE
                        Log to the file specified. Special values are:
                        'syslog', 'journald'. See the documentation for more
                        details.
  -V, --version         show program's version number and exit
  -c PATH, --config PATH
                        Specify configuration file (default:
                        `userdir/config.json` or `config.json` whichever
                        exists). Multiple --config options may be used. Can be
                        set to `-` to read config from stdin.
  -d PATH, --datadir PATH, --data-dir PATH
                        Path to the base directory of the exchange with
                        historical backtesting data. To see futures data, use
                        trading-mode additionally.
  --userdir PATH, --user-data-dir PATH
                        Path to userdata directory.

Strategy arguments:
  -s NAME, --strategy NAME
                        Specify strategy class name which will be used by the
                        bot.
  --strategy-path PATH  Specify additional strategy lookup path.
  --recursive-strategy-search
                        Recursively search for a strategy in the strategies
                        folder.
  --freqaimodel NAME    Specify a custom freqaimodels.
  --freqaimodel-path PATH
                        Specify additional lookup path for freqaimodels.

如何指定使用的配置文件?

机器人允许您通过 -c/--config 命令行选项选择要使用的配置文件:

freqtrade trade -c path/far/far/away/config.json

默认情况下,机器人会从当前工作目录加载 config.json 配置文件。

如何使用多个配置文件?

机器人允许您在命令行中指定多个 -c/--config 选项来使用多个配置文件。后指定的配置文件中定义的参数会覆盖先前命令行中指定的同名参数。

例如,您可以创建一个独立的配置文件,其中包含您用于交易的交易所密钥和密钥,在运行模拟模式(实际上不需要这些密钥)时指定一个带有空密钥和密钥值的默认配置文件:

freqtrade trade -c ./config.json

并在正常运行的真实交易模式下同时指定这两个配置文件:

freqtrade trade -c ./config.json -c path/to/secrets/keys.config.json

这可以帮助您通过为包含实际密钥的文件设置适当的文件权限来隐藏本地机器上的私有交易所密钥和交易所密钥,此外还能防止在项目问题或互联网上发布配置示例时意外泄露敏感的私有数据。

有关此技术的更多详细信息和示例,请参阅文档页面中的配置部分。

自定义数据存储位置

Freqtrade 允许使用 freqtrade create-userdir --userdir someDirectory 命令创建用户数据目录。该目录结构如下所示:

user_data/
├── backtest_results
├── data
├── hyperopts
├── hyperopt_results
├── plot
└── strategies

您可以在配置中添加 "user_data_dir" 设置项,使机器人始终指向该目录。或者,在每个命令中传入 --userdir 参数。如果目录不存在,机器人将无法启动,但会创建必要的子目录。

此目录应包含您的自定义策略、自定义超参数优化和超参数优化损失函数、回测历史数据(使用回测命令或下载脚本获取)以及绘图输出。

建议使用版本控制来跟踪策略的变更。

如何使用 --strategy 参数?

该参数允许您加载自定义策略类。 要测试机器人安装,可以使用 create-userdir 子命令安装的 SampleStrategy(通常位于 user_data/strategy/sample_strategy.py)。

机器人将在 user_data/strategies 目录中搜索您的策略文件。 如需使用其他目录,请阅读下一节关于 --strategy-path 的说明。

加载策略时,只需在此参数中传入类名(例如:CustomStrategy)。

示例:user_data/strategies 目录中,您有一个名为 my_awesome_strategy.py 的文件,其中包含名为 AwesomeStrategy 的策略类,加载方式如下:

freqtrade trade --strategy AwesomeStrategy

如果机器人找不到您的策略文件,将在错误信息中显示具体原因(文件未找到或代码错误)。

了解更多关于策略文件的信息,请参阅 策略自定义

如何使用 --strategy-path 参数?

此参数允许您添加额外的策略查找路径,该路径会在默认位置之前被检查(传入的路径必须是目录!):

freqtrade trade --strategy AwesomeStrategy --strategy-path /some/directory

如何安装策略?

这非常简单。将您的策略文件复制粘贴到 user_data/strategies 目录中,或使用 --strategy-path 参数。然后,机器人就可以使用它了。

如何使用 --db-url

当您在模拟交易模式下运行机器人时,默认情况下不会将交易记录存储在数据库中。如果您希望将机器人操作存储到数据库,可以使用 --db-url 参数。这也可用于在生产模式下指定自定义数据库。示例命令:

freqtrade trade -c config.json --db-url sqlite:///tradesv3.dry_run.sqlite

下一步

机器人的最优策略会随着市场趋势的变化而改变。下一步是进行策略定制