跳至内容

启动机器人

本页面解释了机器人的不同参数以及如何运行它。

注意

如果您使用了 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 参数来使用多个配置文件。在命令行中后指定的配置文件中定义的参数会覆盖先前配置文件中同名的参数。

例如,您可以创建一个单独的配置文件,其中包含您用于交易的交易所的密钥和密钥密文,在模拟模式(Dry Mode)下运行时使用一个默认配置文件(该文件中的密钥和密钥密文为空,因为模拟模式不需要这些信息):

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 参数。如果目录不存在,机器人将无法启动,但会创建所需的子目录。

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

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

如何使用 --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

下一步

机器人的最优策略会随着时间推移和市场趋势变化而改变。下一步是进行 策略自定义