RedisWeightsClient
- class czsc.traders.RedisWeightsClient(strategy_name, redis_url=None, connection_pool=None, send_heartbeat=True, **kwargs)[source]
Bases:
object
策略持仓权重收发客户端
Attributes Summary
获取策略的最近一次心跳时间
获取策略元数据
Methods Summary
clear_all
([with_human])删除该策略所有记录
get_all_weights
([sdt, edt])获取所有权重数据
get_hist_weights
(symbol, sdt, edt)获取单个品种的持仓权重历史数据
get_keys
(pattern)获取 redis 中指定 pattern 的 keys
get_last_times
([symbols])获取所有品种上策略最近一次发布信号的时间
get_last_weights
([symbols, ignore_zero, lua])获取最近的持仓权重
获取策略交易的品种列表
publish
(symbol, dt, weight[, price, ref, ...])发布单个策略持仓权重
publish_dataframe
(df[, overwrite, batch_size])批量发布多个策略信号
register_lua_publish
(client)set_metadata
(base_freq, description, author, ...)设置策略元数据
update_last
(**kwargs)设置策略最近一次更新时间,以及更新参数【可选】
Attributes Documentation
- heartbeat_time
获取策略的最近一次心跳时间
- metadata
获取策略元数据
- version = 'V240303'
Methods Documentation
- get_all_weights(sdt=None, edt=None, **kwargs) DataFrame [source]
获取所有权重数据
- Parameters:
sdt – str, 开始时间, eg: 20210924 10:19:00
edt – str, 结束时间, eg: 20220924 10:19:00
- Returns:
pd.DataFrame
- get_hist_weights(symbol, sdt, edt) DataFrame [source]
获取单个品种的持仓权重历史数据
- Parameters:
symbol – str, 品种代码
sdt – str, 开始时间, eg: 20210924 10:19:00
edt – str, 结束时间, eg: 20220924 10:19:00
- Returns:
pd.DataFrame
- get_last_times(symbols=None)[source]
获取所有品种上策略最近一次发布信号的时间
- Parameters:
symbols – list, 品种列表, 默认为None, 即获取所有品种
- Returns:
dict, {symbol: datetime},如{‘SFIF9001’: datetime(2021, 9, 24, 15, 19, 0)}
- get_last_weights(symbols=None, ignore_zero=True, lua=True)[source]
获取最近的持仓权重
- Parameters:
symbols – list, 品种列表
ignore_zero – boolean, 是否忽略权重为0的品种
lua – boolean, 是否使用 lua 脚本获取,默认为True 如果要全量获取,推荐使用 lua 脚本,速度更快;如果要获取指定 symbols,不推荐使用 lua 脚本。
- Returns:
pd.DataFrame
- publish(symbol, dt, weight, price=0, ref=None, overwrite=False)[source]
发布单个策略持仓权重
- Parameters:
symbol – str, eg; SFIF9001
dt – py_datetime or pandas Timestamp
weight – float, 信号值
price – float, 产生信号时的价格
ref – dict, 自定义数据
overwrite – boolean, 是否覆盖已有记录
- Returns:
成功发布信号的条数