添加A股链接测试
This commit is contained in:
@@ -66,7 +66,7 @@ class ChanBI():
|
||||
self.end_klc = klc
|
||||
self.set_is_sure(True, sure_klc.end_time)
|
||||
self.end_time = klc.end_time
|
||||
#print(self.start_time, klc.start_time, klc.fx, "This bi is ended")
|
||||
print(self.start_time, klc.fx, "This bi is ended", len(self.klc_list), klc.index - self.start_klc.index)
|
||||
def set_is_sure(self, is_sure, time):
|
||||
self.is_sure = is_sure
|
||||
self.sure_time = time
|
||||
@@ -90,6 +90,7 @@ class ChanBI():
|
||||
break
|
||||
if not added:
|
||||
self.klc_list.append(klc)
|
||||
#print(self.start_time, klc.start_time)
|
||||
self.cal_macdhist()
|
||||
self.cal_macd_div()
|
||||
def append_klc_list(self, klc_list):
|
||||
|
||||
@@ -123,12 +123,12 @@ class TF_DF():
|
||||
return klu_state_list
|
||||
def check_fx(self, klc):
|
||||
if klc.pre and klc.next:
|
||||
if klc.high > klc.pre.high and klc.high > klc.next.high and klc.low > klc.pre.low and klc.low > klc.next.low and klc.signal > 0:
|
||||
if klc.high > klc.pre.high and klc.high > klc.next.high and klc.low > klc.pre.low and klc.low > klc.next.low:
|
||||
#if (klc.close > klc.ema52 or klc.next.close > klc.next.ema52) and klc.macd > 0:
|
||||
klc.set_fx(Chan_FX_TYPE.TOP)
|
||||
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "TOP")
|
||||
return Chan_FX_TYPE.TOP
|
||||
elif klc.low < klc.pre.low and klc.low < klc.next.low and klc.high < klc.pre.high and klc.high < klc.next.high and klc.signal < 0:
|
||||
elif klc.low < klc.pre.low and klc.low < klc.next.low and klc.high < klc.pre.high and klc.high < klc.next.high:
|
||||
#if (klc.close < klc.ema52 or klc.next.close < klc.next.ema52) and klc.macd < 0:
|
||||
klc.set_fx(Chan_FX_TYPE.BOTTOM)
|
||||
#print(klc.start_time, klc.end_time,klc.next.start_time, klc.next.end_time, klc.macd, klc.state, klc.fx, "BOTTOM")
|
||||
@@ -834,6 +834,8 @@ class TF_DF():
|
||||
fx = Chan_FX_TYPE.UNKNOWN
|
||||
# Do nothing
|
||||
if fx == Chan_FX_TYPE.UNKNOWN:
|
||||
if len(bi_list) > 0:
|
||||
bi_list[-1].add_klc(klc)
|
||||
continue
|
||||
if len(bi_list) > 0 and klc.end_klu:
|
||||
last_bi = bi_list[-1]
|
||||
|
||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
# 将项目根目录加入 sys.path,确保可以直接导入业务代码
|
||||
ROOT_DIR = Path(__file__).resolve().parents[4]
|
||||
if str(ROOT_DIR) not in sys.path:
|
||||
sys.path.append(str(ROOT_DIR))
|
||||
|
||||
from user_data.Chan.web.cn_stock_data import ChinaStockData
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
def test_cn_stock_data_fetch():
|
||||
"""简单的联通性测试,确认能否通过 akshare 拉取A股K线数据。"""
|
||||
data_client = ChinaStockData()
|
||||
|
||||
try:
|
||||
df = data_client.get_kl_data(symbol="600519", timeframe="1d", limit=20)
|
||||
except Exception as exc: # pragma: no cover - 旨在提示网络/依赖问题
|
||||
pytest.skip(f"无法调用数据接口,可能是网络或依赖问题:{exc}")
|
||||
|
||||
if df is None or df.empty:
|
||||
pytest.skip("未获取到任何数据,可能是网络异常或接口限制。")
|
||||
|
||||
expected_cols = {"date", "open", "high", "low", "close", "volume"}
|
||||
missing_cols = expected_cols - set(df.columns)
|
||||
assert not missing_cols, f"返回数据缺少列: {missing_cols}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user