跳转至内容

索引

运行 V2 策略

V2 策略的主要逻辑包含在Controller中,该 Controller 继承自 Directional 或 Market Making 等基类,通过协调各种智能组件如CandlesExecutors来实现策略逻辑。

对于用户而言,其主要接口是V2 脚本,这是一个定义配置参数的文件,作为用户和策略之间的桥梁。

要为脚本生成配置文件,请运行:

create --script-config [SCRIPT_FILE]

[SCRIPT_FILE]的自动补全将仅显示本地/scripts目录中可配置的脚本。

系统会提示您定义策略参数,这些参数将保存在conf/scripts目录中的 YAML 文件中。之后,您可以通过指定此配置文件来运行脚本:

start --script [SCRIPT_FILE] --conf [SCRIPT_CONFIG_FILE]

[SCRIPT_CONFIG_FILE]的自动补全将显示/conf/scripts目录中的配置文件。

方向性策略

方向性策略继承自DirectionalTrading策略基类。

在其 Controller 的get_processed_data函数中,方向性策略使用从Candles派生的技术指标来定义触发多头和空头条件的阈值,使用signal参数:

以下是当前的 V2 方向性策略:

Bollinger V1

使用布林带百分比(BBP)的简单方向性策略。BBP 衡量资产价格相对于其上下布林带的位置,该策略使用当前 BBP 构建多头/空头信号。

代码:

创建配置文件

create --script-config v2_bollinger_v1_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
stop_loss PositionExecutor 设置止损百分比(例如,0.01 表示 1%损失):
take_profit PositionExecutor 输入止盈百分比(例如,0.03 表示 3%收益):
time_limit PositionExecutor 设置三重障碍的时间限制(以秒为单位)(例如,21600 表示 6 小时):
trailing_stop_activation_price_delta PositionExecutor 输入追踪止损的触发价格差值(例如,0.008 表示 0.8%):
trailing_stop_trailing_delta PositionExecutor 设置追踪止损的追踪差值(例如,0.004 表示 0.4%):
order_amount_usd orders 输入以美元计价的订单金额(例如,15):
cooldown_time orders 指定订单下达之间的冷却时间(以秒为单位)(例如,15):
candles_exchange candles 输入获取蜡烛图数据的交易所名称(例如,binance_perpetual):
candles_interval candles 设置蜡烛图的时间间隔(例如,1m, 5m, 1h):
bb_length strategy 输入布林带长度(例如,100):
bb_std strategy 设置布林带的标准差(例如,2.0):
bb_long_threshold strategy 指定布林带的多头阈值(例如,0.3):
bb_short_threshold strategy 定义布林带的空头阈值(例如,0.7):

此外,脚本可能还会定义其他不带 prompt_on_new 标志的参数。

启动脚本

start --script v2_bollinger_v1_config.py --conf [SCRIPT_CONFIG_FILE]

状态

下方截图显示了运行 status 命令时显示的内容:

MACD-BB

一种结合了MACD和布林带的方向性策略,用于产生多/空信号。该策略使用 MACD 进行趋势识别,使用布林带进行波动率和价格水平分析。

代码:

创建配置文件

create --script-config v2_macd_bb_v1_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
stop_loss PositionExecutor 设置止损百分比(例如,0.01 表示 1% 的损失)
take_profit PositionExecutor 输入止盈百分比(例如,0.06 表示 6% 的收益)
time_limit PositionExecutor 设置三重屏障的时间限制(秒)(例如,86400 表示 24 小时)
trailing_stop_activation_price_delta PositionExecutor 输入跟踪止损的激活价格差值(例如,0.01 表示 1%)
trailing_stop_trailing_delta PositionExecutor 设置跟踪止损的跟踪差值(例如,0.004 表示 0.4%)
order_amount_usd orders 输入订单金额(美元)(例如,15)
cooldown_time orders 指定下订单之间的冷却时间(秒)(例如,15)
candles_exchange candles 输入获取蜡烛数据的交易所名称(例如,binance_perpetual)
candles_interval candles 设置蜡烛的时间间隔(例如,3m)
macd_fast strategy 设置 MACD 快线长度(例如,21)
macd_slow strategy 指定 MACD 慢线长度(例如,42)
macd_signal strategy 定义 MACD 信号线长度(例如,9)
bb_length strategy 输入布林带长度(例如,100)
bb_std strategy 设置布林带的标准差(例如,2.0)
bb_long_threshold strategy 指定布林带的做多阈值(例如,0.3)
bb_short_threshold strategy 定义布林带的做空阈值(例如,0.7)

此外,脚本可能还会定义其他不带 prompt_on_new 标志的参数。

启动脚本

start --script v2_macd_bb_v1_config.py --conf [SCRIPT_CONFIG_FILE]

状态

下方截图显示了运行 status 命令时显示的内容:

趋势跟随者

一种简单的趋势跟踪策略,使用简单移动平均线(SMA)和布林带来构建多/空信号。

代码:

创建配置文件

create --script-config v2_trend_follower_v1_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
stop_loss PositionExecutor 设置止损百分比(例如,0.01 表示 1% 的损失)
take_profit PositionExecutor 输入止盈百分比(例如,0.06 表示 6% 的收益)
time_limit PositionExecutor 设置三重屏障的时间限制(秒)(例如,86400 表示 24 小时)
trailing_stop_activation_price_delta PositionExecutor 输入跟踪止损的激活价格差值(例如,0.01 表示 1%)
trailing_stop_trailing_delta PositionExecutor 设置跟踪止损的跟踪差值(例如,0.004 表示 0.4%)
order_amount_usd orders 输入订单金额(美元)(例如,15)
cooldown_time orders 指定下订单之间的冷却时间(秒)(例如,15)
candles_exchange candles 输入获取蜡烛数据的交易所名称(例如,binance_perpetual)
candles_interval candles 设置蜡烛的时间间隔(例如,3m)
sma_fast strategy 输入 SMA 快线长度(范围 10-150,例如 20)
sma_slow strategy 设置 SMA 慢线长度(范围 50-400,例如 100)
bb_length strategy 输入布林带长度(范围 50-200,例如 100)
bb_std strategy 设置布林带的标准差(范围 2.0-3.0,例如 2.0)
bb_threshold strategy 指定布林带的阈值(范围 0.1-0.5,例如 0.2)

启动脚本

start --script v2_trend_follower_v1_config.py --conf [SCRIPT_CONFIG_FILE]

状态:

做市策略

做市策略创建并管理一组仓位执行器,这些执行器在固定中间价格附近下订单。它们继承自MarketMaking策略基类。

DmanV1

使用 DMAN v1 控制器的定制做市脚本

代码:

创建配置文件

create --script-config v2_dman_v1_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
candles_exchange candles 输入获取蜡烛数据的交易所名称(例如,binance_perpetual)
candles_interval candles 设置蜡烛的时间间隔(例如,3m)
order_amount orders 输入报价资产的基础订单金额(例如,25 USDT)
n_levels orders 指定订单级别数量(例如,5)
start_spread orders 将起始价差设置为 NATR 的倍数(例如,1.0 表示 1x NATR)
step_between_orders orders 将订单之间的步长定义为 NATR 的倍数(例如,0.8 表示 0.8x NATR)
order_refresh_time orders 输入订单的刷新时间(秒)(例如,900 表示 15 分钟)
cooldown_time orders 指定下订单之间的冷却时间(秒)(例如,5)
stop_loss PositionExecutor 设置止损百分比(例如,0.2 表示 20% 的损失)
take_profit PositionExecutor 输入止盈百分比(例如,0.06 表示 6% 的收益)
time_limit PositionExecutor 设置三重屏障的时间限制(秒)(例如,43200 表示 12 小时)
trailing_stop_activation_price_delta PositionExecutor 输入跟踪止损的激活价格差值(例如,0.0045 表示 0.45%)
trailing_stop_trailing_delta PositionExecutor 设置跟踪止损的跟踪差值(例如,0.003 表示 0.3%)
natr_length strategy 输入 NATR(标准化平均真实波幅)长度(例如,100)

启动脚本

start --script dman_v1_config.py --conf [SCRIPT_CONFIG_FILE]

状态:

DmanV2

一种简单的做市策略,使用自然平均真实波幅(NATR)动态设置价差。

代码:

创建配置文件

create --script-config v2_dman_v2_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
candles_exchange candles 输入获取蜡烛数据的交易所名称(例如,binance_perpetual)
candles_interval candles 设置蜡烛的时间间隔(例如,3m)
order_amount orders 输入报价资产的基础订单金额(例如,25 USDT)
n_levels orders 指定订单级别数量(例如,5)
start_spread orders 将起始价差设置为 NATR 的倍数(例如,1.0 表示 1x NATR)
step_between_orders orders 将订单之间的步长定义为 NATR 的倍数(例如,0.8 表示 0.8x NATR)
cooldown_time orders 指定下订单之间的冷却时间(秒)(例如,5)
order_refresh_time orders 取消或替换订单的频率(以秒为单位)
stop_loss PositionExecutor 设置止损百分比(例如,0.2 表示 20% 的损失)
take_profit PositionExecutor 输入止盈百分比(例如,0.06 表示 6% 的收益)
time_limit PositionExecutor 设置三重屏障的时间限制(秒)(例如,43200 表示 12 小时)
trailing_stop_activation_price_delta PositionExecutor 输入跟踪止损的激活价格差值(例如,0.0045 表示 0.45%)
trailing_stop_trailing_delta PositionExecutor 设置跟踪止损的跟踪差值(例如,0.003 表示 0.3%)
natr_length strategy 输入 NATR(标准化平均真实波幅)长度(例如,100)
macd_fast strategy 设置 MACD 快速线长度(例如,12)
macd_slow strategy 指定 MACD 慢速线长度(例如,26)
macd_signal strategy 定义 MACD 信号线长度(例如,9)

启动脚本

start --script dman_v2_config.py --conf [SCRIPT_CONFIG_FILE]

状态:

DmanV3

使用布林带指标进行网格执行的均值回归策略,使价差动态化并移动中间价格。

代码:

创建配置文件

create --script-config v2_dman_v3_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
candles_exchange candles 输入获取蜡烛数据的交易所名称(例如,binance_perpetual)
candles_interval candles 设置 K 线的时间间隔(例如,30m)
bollinger_band_length strategy 输入布林带的长度(例如,200)
bollinger_band_std strategy 设置布林带的标准差(例如,3.0)
order_amount orders 输入以报价资产计算的基础订单金额(例如,20 USDT)
n_levels orders 指定订单级别数量(例如,5)
start_spread orders 将首个订单的价差设置为布林带值的比率(例如,1.0)
step_between_orders orders 将订单间的步长定义为布林带值的比率(例如,0.2)
stop_loss PositionExecutor 设置止损百分比(例如,0.2 表示 20% 的损失)
take_profit PositionExecutor 输入止盈百分比(例如,0.06 表示 6% 的收益)
time_limit PositionExecutor 设置三重屏障的时间限制(以秒为单位)(例如,3 天为 259200)
trailing_stop_activation_price_delta PositionExecutor 输入跟踪止损的激活价格差值(例如,0.01 表示 1%)
trailing_stop_trailing_delta PositionExecutor 设置跟踪止损的跟踪差值(例如,0.003 表示 0.3%)

此外,脚本还可能定义其他没有prompt_on_new标志的高级参数。

启动脚本

start --script dman_v3.py --conf [SCRIPT_CONFIG_FILE]

状态:

DmanV4

利用 NATR 指标动态设置价差并移动中间价格的方向性做市策略,通过各种高级配置增强以实现更精细的控制。

代码:

创建配置文件

create --script-config v2_dman_v4_config

用户定义参数

以下是运行create命令时的用户定义参数:

参数 类型 提示
exchange trading 输入机器人将运行的交易所名称(例如,binance_perpetual)
trading_pairs trading 列出机器人将交易的交易对,用逗号分隔(例如,BTC-USDT,ETH-USDT)
leverage trading 设置交易使用的杠杆(例如,20 表示 20 倍杠杆)
candles_exchange candles 输入获取蜡烛数据的交易所名称(例如,binance_perpetual)
candles_interval candles 设置蜡烛的时间间隔(例如,3m)
bollinger_band_length candles 输入布林带的长度(例如,200)
order_amount orders 输入以报价资产计算的基础订单金额(例如,10 USDT)
amount_ratio_increase orders 设置每级后续订单金额增加的比率(例如,1.5)
n_levels orders 指定订单级别数量(例如,5)
start_spread orders 输入订单的起始价差(例如,0.03)
spread_ratio_increase orders 定义每级后续订单价差增加的比率(例如,2.0)
stop_loss PositionExecutor 设置止损百分比(例如,0.5)
global_trailing_stop_activation_price_delta PositionExecutor 输入全局追踪止损的激活价格差值(例如,0.025)
global_trailing_stop_trailing_delta PositionExecutor 设置全局追踪止损的追踪差值(例如,0.005)

此外,脚本还可能定义其他没有prompt_on_new标志的高级参数。

启动脚本

start --script dman_v4_config.py --conf [SCRIPT_CONFIG_FILE]

状态: