119 lines
3.5 KiB
Python
119 lines
3.5 KiB
Python
from Chan import CChan
|
|
from ChanConfig import CChanConfig
|
|
from Common.CEnum import AUTYPE, DATA_SRC, KL_TYPE
|
|
from Plot.AnimatePlotDriver import CAnimateDriver
|
|
from Plot.PlotDriver import CPlotDriver
|
|
|
|
"""
|
|
def try_open(self, chan: CChan, lv) -> Optional[CCustomBSP]:
|
|
data = chan[lv]
|
|
if lv != len(chan.lv_list)-1 and data.bi_list: # 当前级别不是最低级别,且至少有一笔
|
|
if qjt_bsp := self.cal_qjt_bsp(data, chan[lv + 1]): # 计算区间套
|
|
return qjt_bsp
|
|
|
|
def cal_qjt_bsp(self, data: CKLine_List, sub_lv_data: CKLine_List) -> Optional[CCustomBSP]:
|
|
last_klu = data[-1][-1]
|
|
last_bsp_lst = data.bs_point_lst.getLastestBspList()
|
|
if len(last_bsp_lst) == 0:
|
|
return None
|
|
last_bsp = last_bsp_lst[0]
|
|
if last_bsp.klu.idx != last_klu.idx: # 当前K线是父级别的买卖点
|
|
return None
|
|
for sub_bsp in sub_lv_data.cbsp_strategy: # 对于次级别的买卖点
|
|
if sub_bsp.klu.sup_kl.idx == last_klu.idx and sub_bsp.type2str().find("1") >= 0: # 且是一类买卖点
|
|
return CCustomBSP(
|
|
bsp=last_bsp,
|
|
klu=last_klu,
|
|
bs_type=last_bsp.qjt_type(), # 返回区间套买卖点
|
|
is_buy=last_bsp.is_buy,
|
|
target_klc=sub_bsp.target_klc[-1].sup_kl.klc,
|
|
price=sub_bsp.open_price,
|
|
)
|
|
return None
|
|
"""
|
|
|
|
if __name__ == "__main__":
|
|
code = "BTC/USDT:USDT"
|
|
begin_time = "2025-6-1"
|
|
end_time = "2025-6-8"
|
|
data_src = DATA_SRC.CCXT
|
|
lv_list = [KL_TYPE.K_60M]
|
|
|
|
config = CChanConfig({
|
|
"bi_strict": True,
|
|
"trigger_step": False,
|
|
"skip_step": 0,
|
|
"divergence_rate": float("inf"),
|
|
"bsp2_follow_1": False,
|
|
"bsp3_follow_1": False,
|
|
"min_zs_cnt": 0,
|
|
"bs1_peak": False,
|
|
"macd_algo": "peak",
|
|
"bs_type": '1,2,3a,1p,2s,3b',
|
|
"print_warning": True,
|
|
"zs_algo": "normal",
|
|
})
|
|
|
|
plot_config = {
|
|
"plot_kline": True,
|
|
"plot_kline_combine": True,
|
|
"plot_bi": True,
|
|
"plot_seg": True,
|
|
"plot_eigen": True,
|
|
"plot_zs": True,
|
|
"plot_macd": True,
|
|
"plot_mean": False,
|
|
"plot_channel": False,
|
|
"plot_bsp": True,
|
|
"plot_extrainfo": False,
|
|
"plot_demark": False,
|
|
"plot_marker": False,
|
|
"plot_rsi": False,
|
|
"plot_kdj": False,
|
|
}
|
|
|
|
plot_para = {
|
|
"seg": {
|
|
"plot_trendline": True,
|
|
},
|
|
"bi": {
|
|
"show_num": True,
|
|
"disp_end": True,
|
|
},
|
|
"figure": {
|
|
"x_range": 1000,
|
|
},
|
|
"marker": {
|
|
# "markers": { # text, position, color
|
|
# '2023/06/01': ('marker here', 'up', 'red'),
|
|
# '2023/06/08': ('marker here', 'down')
|
|
# },
|
|
}
|
|
}
|
|
chan = CChan(
|
|
code=code,
|
|
begin_time=begin_time,
|
|
end_time=end_time,
|
|
data_src=data_src,
|
|
lv_list=lv_list,
|
|
config=config,
|
|
autype=AUTYPE.QFQ,
|
|
)
|
|
|
|
if not config.trigger_step:
|
|
plot_driver = CPlotDriver(
|
|
chan,
|
|
plot_config=plot_config,
|
|
plot_para=plot_para,
|
|
)
|
|
# plot_driver.figure.show()
|
|
plot_driver.save2img("./test.png")
|
|
else:
|
|
CAnimateDriver(
|
|
chan,
|
|
plot_config=plot_config,
|
|
plot_para=plot_para,
|
|
)
|
|
bsp_list = chan.get_bsp()
|
|
for bsp in bsp_list:
|
|
print(bsp.klu.time, bsp.type2str(), bsp.is_buy) |