You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
# 数据获取适配器基类
|
|
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
from typing import Dict, Optional, List
|
|
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseDataAdapter(ABC):
|
|
|
|
|
|
"""数据获取适配器基类
|
|
|
|
|
|
|
|
|
|
|
|
所有数据获取适配器都需要实现这个接口,确保统一的方法调用方式。
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def connect(self) -> bool:
|
|
|
|
|
|
"""连接API
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
bool: 连接是否成功
|
|
|
|
|
|
"""
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def disconnect(self):
|
|
|
|
|
|
"""断开连接"""
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def get_kline_data(self, symbol: str, duration: str, count: int = 200) -> Optional[pd.DataFrame]:
|
|
|
|
|
|
"""获取K线数据
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
symbol: 合约代码
|
|
|
|
|
|
duration: 时间周期,如 '1m', '5m', '15m', '1h', '1d'
|
|
|
|
|
|
count: 数据数量
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
K线数据DataFrame,如果无法获取真实数据则返回None
|
|
|
|
|
|
"""
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def get_tick_data(self, symbol: str, count: int = 1000) -> Optional[pd.DataFrame]:
|
|
|
|
|
|
"""获取Tick数据
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
symbol: 合约代码
|
|
|
|
|
|
count: 数据数量
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
Tick数据DataFrame,如果无法获取真实数据则返回None
|
|
|
|
|
|
"""
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def get_contract_info(self, symbol: str) -> Optional[Dict]:
|
|
|
|
|
|
"""获取合约信息
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
symbol: 合约代码
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
合约信息字典,如果无法获取真实数据则返回None
|
|
|
|
|
|
"""
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def get_market_data(self, symbols: List[str]) -> Dict[str, Dict]:
|
|
|
|
|
|
"""批量获取市场数据
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
symbols: 合约代码列表
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
市场数据字典,键为合约代码,值为市场数据
|
|
|
|
|
|
"""
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
|
|
def get_all_symbols(self) -> List[str]:
|
|
|
|
|
|
"""获取所有品种列表
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
所有品种的合约代码列表
|
|
|
|
|
|
"""
|
|
|
|
|
|
pass
|