|
|
|
|
@ -29,12 +29,13 @@ class CacheService:
|
|
|
|
|
self.stock_service = StockService(db)
|
|
|
|
|
self.future_service = FutureService(db)
|
|
|
|
|
|
|
|
|
|
def get_all_codes(self, security_type: str) -> List[str]:
|
|
|
|
|
def get_all_codes(self, security_type: str, contract_type: str = "all") -> List[str]:
|
|
|
|
|
"""
|
|
|
|
|
获取所有代码列表
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
security_type: 证券类型 (stock, future)
|
|
|
|
|
contract_type: 合约类型 (all, main) - 仅对期货有效
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
代码列表
|
|
|
|
|
@ -46,16 +47,29 @@ class CacheService:
|
|
|
|
|
if security_type == "stock":
|
|
|
|
|
return adapter.get_code_list("EXTRA_STOCK_A")
|
|
|
|
|
elif security_type == "future":
|
|
|
|
|
if contract_type == "main":
|
|
|
|
|
# 只获取主力合约
|
|
|
|
|
main_contracts = adapter.get_all_main_contracts()
|
|
|
|
|
return list(main_contracts.values())
|
|
|
|
|
else:
|
|
|
|
|
return adapter.get_code_list("EXTRA_FUTURE")
|
|
|
|
|
else:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
def get_future_varieties(self) -> List[str]:
|
|
|
|
|
"""获取期货品种列表"""
|
|
|
|
|
adapter = sdk_manager.get_default_connection()
|
|
|
|
|
if not adapter:
|
|
|
|
|
raise RuntimeError("SDK连接失败")
|
|
|
|
|
return adapter.get_future_varieties()
|
|
|
|
|
|
|
|
|
|
def detect_all_missing_data(
|
|
|
|
|
self,
|
|
|
|
|
security_type: str,
|
|
|
|
|
period_type: str,
|
|
|
|
|
start_date: date,
|
|
|
|
|
end_date: date
|
|
|
|
|
end_date: date,
|
|
|
|
|
contract_type: str = "all"
|
|
|
|
|
) -> Dict:
|
|
|
|
|
"""
|
|
|
|
|
一键检测所有数据的缺失情况
|
|
|
|
|
@ -65,12 +79,13 @@ class CacheService:
|
|
|
|
|
period_type: 周期类型 (daily, min1, etc.)
|
|
|
|
|
start_date: 开始日期
|
|
|
|
|
end_date: 结束日期
|
|
|
|
|
contract_type: 合约类型 (all, main) - 仅对期货有效
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
检测结果字典
|
|
|
|
|
"""
|
|
|
|
|
# 获取所有代码
|
|
|
|
|
code_list = self.get_all_codes(security_type)
|
|
|
|
|
code_list = self.get_all_codes(security_type, contract_type)
|
|
|
|
|
|
|
|
|
|
if not code_list:
|
|
|
|
|
raise ValueError(f"无法获取{security_type}代码列表")
|
|
|
|
|
@ -79,7 +94,7 @@ class CacheService:
|
|
|
|
|
|
|
|
|
|
# 创建检测任务
|
|
|
|
|
task = CacheTask(
|
|
|
|
|
task_name=f"一键检测所有数据 - {security_type} - {len(code_list)}个代码",
|
|
|
|
|
task_name=f"一键检测所有数据 - {security_type} - {contract_type} - {len(code_list)}个代码",
|
|
|
|
|
task_type="detect_all_missing",
|
|
|
|
|
security_type=security_type,
|
|
|
|
|
period_type=period_type,
|
|
|
|
|
@ -244,7 +259,8 @@ class CacheService:
|
|
|
|
|
security_type: str,
|
|
|
|
|
period_type: str,
|
|
|
|
|
start_date: date,
|
|
|
|
|
end_date: date
|
|
|
|
|
end_date: date,
|
|
|
|
|
contract_type: str = "all"
|
|
|
|
|
) -> CacheTask:
|
|
|
|
|
"""
|
|
|
|
|
一键缓存所有缺失数据
|
|
|
|
|
@ -254,12 +270,13 @@ class CacheService:
|
|
|
|
|
period_type: 周期类型
|
|
|
|
|
start_date: 开始日期
|
|
|
|
|
end_date: 结束日期
|
|
|
|
|
contract_type: 合约类型 (all, main) - 仅对期货有效
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
缓存任务对象
|
|
|
|
|
"""
|
|
|
|
|
# 获取所有代码
|
|
|
|
|
code_list = self.get_all_codes(security_type)
|
|
|
|
|
code_list = self.get_all_codes(security_type, contract_type)
|
|
|
|
|
|
|
|
|
|
if not code_list:
|
|
|
|
|
raise ValueError(f"无法获取{security_type}代码列表")
|
|
|
|
|
|