2码稳定底王 - API文档
📚 目录
🔬 核心算法API
core_algorithm.py
convert_to_dual_code(number_str: str) -> str
将开奖号码转换为对码。
参数:
number_str(str): 开奖号码字符串,如 "218"
返回:
str: 对码字符串,如 "763"
示例:
from core_algorithm import convert_to_dual_code
dual_code = convert_to_dual_code("218")
print(dual_code) # "763"
get_six_and_four_codes(original_number: str) -> Tuple[Set[str], Set[str]]
根据开奖号码获取6码和4码。
参数:
original_number(str): 开奖号码字符串,如 "218"
返回:
Tuple[Set[str], Set[str]]: (six_codes, four_codes) 六码和四码的集合
示例:
from core_algorithm import get_six_and_four_codes
six_codes, four_codes = get_six_and_four_codes("218")
print(six_codes) # {'1', '2', '3', '6', '7', '8'}
print(four_codes) # {'0', '4', '5', '9'}
get_even_numbers_from_six_codes(six_codes: Set[str]) -> List[str]
从6码中提取偶数。
参数:
six_codes(Set[str]): 6码的集合
返回:
List[str]: 偶数列表(最多3个)
示例:
from core_algorithm import get_even_numbers_from_six_codes
six_codes = {'1', '2', '3', '6', '7', '8'}
evens = get_even_numbers_from_six_codes(six_codes)
print(evens) # ['2', '6', '8']
calculate_three_numbers(even_list: List[str]) -> List[str]
三个偶数两两相加,得到3个数字(排序后返回)。
参数:
even_list(List[str]): 偶数列表(3个元素)
返回:
List[str]: 3个数字的列表(已排序)
示例:
from core_algorithm import calculate_three_numbers
evens = ['2', '6', '8']
numbers = calculate_three_numbers(evens)
print(numbers) # ['0', '4', '8']
get_29_groups(original_number: str) -> List[str]
根据开奖号码获取29组稳定大底。
参数:
original_number(str): 开奖号码字符串,如 "218"
返回:
List[str]: 29组两码的列表
示例:
from core_algorithm import get_29_groups
groups = get_29_groups("218")
print(len(groups)) # 29
print(groups) # ['01', '04', '05', '06', '09', '13', ...]
check_match(lottery_number: str, groups: List[str]) -> bool
检查开奖号码的任意2码是否属于大底的任意2码。
参数:
lottery_number(str): 开奖号码字符串,如 "281"groups(List[str]): 大底列表,如 ["14", "19", "18", ...]
返回:
bool: 是否匹配
示例:
from core_algorithm import check_match
groups = ['01', '04', '05', '18', '28', ...]
is_match = check_match("281", groups)
print(is_match) # True or False
📡 数据获取API
data_fetcher.py
DataFetcher.__init__()
初始化数据获取器。
参数: 无
示例:
from data_fetcher import DataFetcher
fetcher = DataFetcher()
DataFetcher.fetch_data(lottery_type: str) -> Tuple[bool, str, List[List[str]]]
从互联网获取开奖数据。
参数:
lottery_type(str): 彩种类型,'3D' 或 'P3'
返回:
Tuple[bool, str, List[List[str]]]: (成功标志, 消息, 数据列表)- 数据格式:[[期号, 开奖号码, ...], ...]
示例:
from data_fetcher import DataFetcher
fetcher = DataFetcher()
success, message, data = fetcher.fetch_data("3D")
if success:
print(f"获取到 {len(data)} 条数据")
print(data[0]) # 最新一期数据
DataFetcher.get_latest_number(lottery_type: str) -> Tuple[bool, str, Optional[str]]
获取最新一期开奖号码。
参数:
lottery_type(str): 彩种类型,'3D' 或 'P3'
返回:
Tuple[bool, str, Optional[str]]: (成功标志, 消息, 开奖号码)
示例:
from data_fetcher import DataFetcher
fetcher = DataFetcher()
success, message, number = fetcher.get_latest_number("3D")
if success:
print(f"最新开奖号码: {number}")
else:
print(f"获取失败: {message}")
DataFetcher.get_history_data(lottery_type: str, periods: int) -> Tuple[bool, str, List[Tuple[str, str]]]
获取历史开奖数据。
参数:
lottery_type(str): 彩种类型,'3D' 或 'P3'periods(int): 期数
返回:
Tuple[bool, str, List[Tuple[str, str]]]: (成功标志, 消息, 数据列表)- 数据格式:[(期号, 开奖号码), ...]
示例:
from data_fetcher import DataFetcher
fetcher = DataFetcher()
success, message, history = fetcher.get_history_data("3D", 100)
if success:
for period, number in history:
print(f"{period}: {number}")
🛠️ 工具函数API
utils/logger.py
setup_logger(name: str = "2码稳定底王", log_level: int = logging.INFO) -> logging.Logger
设置日志系统。
参数:
name(str): 日志器名称,默认为 "2码稳定底王"log_level(int): 日志级别,默认为 logging.INFO
返回:
logging.Logger: 配置好的日志器
示例:
from utils.logger import setup_logger
logger = setup_logger("MyModule")
logger.info("这是一条日志")
get_logger(name: str = None) -> logging.Logger
获取日志器。
参数:
name(str): 日志器名称,如果为None则使用默认名称
返回:
logging.Logger: 日志器实例
示例:
from utils.logger import get_logger
logger = get_logger("MyModule")
logger.debug("调试信息")
logger.info("一般信息")
logger.warning("警告信息")
logger.error("错误信息")
utils/validators.py
validate_lottery_number(number: str) -> Tuple[bool, str]
验证开奖号码格式。
参数:
number(str): 开奖号码字符串
返回:
Tuple[bool, str]: (是否有效, 错误消息)
示例:
from utils.validators import validate_lottery_number
is_valid, error_msg = validate_lottery_number("218")
if not is_valid:
print(f"验证失败: {error_msg}")
validate_periods(periods_str: str) -> Tuple[bool, str, int]
验证回测期数。
参数:
periods_str(str): 期数字符串
返回:
Tuple[bool, str, int]: (是否有效, 错误消息, 期数)
示例:
from utils.validators import validate_periods
is_valid, error_msg, periods = validate_periods("100")
if not is_valid:
print(f"验证失败: {error_msg}")
else:
print(f"期数: {periods}")
utils/ui_helpers.py
center_window(window: tk.Toplevel, width: Optional[int] = None, height: Optional[int] = None)
窗口居中显示。
参数:
window(tk.Toplevel): 窗口对象width(Optional[int]): 窗口宽度,如果为None则使用当前宽度height(Optional[int]): 窗口高度,如果为None则使用当前高度
示例:
from utils.ui_helpers import center_window
import tkinter as tk
window = tk.Toplevel()
center_window(window, 400, 300)
create_button(parent, text: str, command, **kwargs) -> tk.Button
创建标准样式的按钮。
参数:
parent: 父容器text(str): 按钮文本command: 命令函数**kwargs: 其他参数
返回:
tk.Button: 按钮对象
示例:
from utils.ui_helpers import create_button
def on_click():
print("按钮被点击")
btn = create_button(parent, "确定", on_click)
btn.pack()
create_card_frame(parent, **kwargs) -> tk.Frame
创建卡片样式的Frame。
参数:
parent: 父容器**kwargs: 其他参数
返回:
tk.Frame: Frame对象
示例:
from utils.ui_helpers import create_card_frame
card = create_card_frame(parent)
card.pack()
⚙️ 配置API
config.py
常量说明
算法常量:
GROUPS_COUNT(int): 29组稳定2码EVEN_COUNT(int): 需要3个偶数DUAL_CODES_COUNT(int): 5组对码LOTTERY_NUMBER_LENGTH(int): 开奖号码长度
网络配置:
REQUEST_TIMEOUT(int): 请求超时时间(秒)CACHE_EXPIRY_HOURS(int): 缓存过期时间(小时)DATA_URLS(Dict[str, str]): 数据源URL字典EXPECTED_COLS(Dict[str, int]): 数据列数字典
UI配置:
WINDOW_WIDTH(int): 窗口宽度WINDOW_HEIGHT(int): 窗口高度WINDOW_TITLE(str): 窗口标题COLORS(Dict[str, str]): 颜色方案字典FONT_FAMILY(str): 字体家族FONT_SIZES(Dict[str, int]): 字体大小字典
其他配置:
TRIAL_DAYS(int): 试用期天数EXPORT_FORMATS(Dict[str, str]): 导出格式字典AD_MESSAGES(List[str]): 广告词列表COPYRIGHT_INFO(Dict): 版权信息字典
示例:
from config import COLORS, WINDOW_WIDTH, GROUPS_COUNT
# 使用颜色
primary_color = COLORS['primary']
# 使用窗口配置
window.geometry(f"{WINDOW_WIDTH}x{WINDOW_HEIGHT}")
# 使用算法常量
print(f"生成 {GROUPS_COUNT} 组2码")
🔐 注册系统API
registration/client_license_validator.py
ClientLicenseValidator.__init__(public_key_path: str = "registration/keys/public_key.pem", license_file: str = "license.json")
初始化客户端授权验证器。
参数:
public_key_path(str): 公钥文件路径license_file(str): 授权文件路径
示例:
from registration.client_license_validator import ClientLicenseValidator
validator = ClientLicenseValidator()
ClientLicenseValidator.verify_license(license_data: Dict = None) -> Tuple[bool, str]
验证授权文件。
参数:
license_data(Dict, optional): 授权数据,如果为None则从文件加载
返回:
Tuple[bool, str]: (是否有效, 消息)
示例:
from registration.client_license_validator import ClientLicenseValidator
validator = ClientLicenseValidator()
is_valid, message = validator.verify_license()
if is_valid:
print("授权有效")
else:
print(f"授权无效: {message}")
TrialManager.__init__(trial_file: str = "trial.json")
初始化试用期管理器。
参数:
trial_file(str): 试用文件路径
示例:
from registration.client_license_validator import TrialManager
trial_manager = TrialManager()
TrialManager.start_trial(trial_days: int = 7) -> Tuple[bool, str]
开始试用期。
参数:
trial_days(int): 试用天数,默认为7
返回:
Tuple[bool, str]: (是否成功, 消息)
示例:
from registration.client_license_validator import TrialManager
trial_manager = TrialManager()
success, message = trial_manager.start_trial(7)
if success:
print("试用期已开始")
else:
print(f"开始试用失败: {message}")
TrialManager.check_trial_status() -> Tuple[bool, int, bool]
检查试用期状态。
返回:
Tuple[bool, int, bool]: (是否在试用期, 剩余天数, 是否已过期)
示例:
from registration.client_license_validator import TrialManager
trial_manager = TrialManager()
in_trial, remaining_days, expired = trial_manager.check_trial_status()
if in_trial:
if expired:
print("试用期已过期")
else:
print(f"试用期中,剩余 {remaining_days} 天")
else:
print("不在试用期")
📝 使用示例
完整示例:生成29组2码并检查匹配
from core_algorithm import get_29_groups, check_match
from data_fetcher import DataFetcher
# 1. 获取最新开奖号码
fetcher = DataFetcher()
success, message, number = fetcher.get_latest_number("3D")
if not success:
print(f"获取失败: {message}")
exit(1)
print(f"最新开奖号码: {number}")
# 2. 生成29组2码
groups = get_29_groups(number)
print(f"生成的29组2码: {groups}")
# 3. 检查下一个号码是否匹配
next_success, next_message, next_number = fetcher.get_latest_number("3D")
if next_success:
is_match = check_match(next_number, groups)
print(f"下一期号码 {next_number} 是否匹配: {is_match}")
完整示例:历史回测
from core_algorithm import get_29_groups, check_match
from data_fetcher import DataFetcher
fetcher = DataFetcher()
success, message, history = fetcher.get_history_data("3D", 100)
if not success:
print(f"获取失败: {message}")
exit(1)
success_count = 0
fail_count = 0
# 从第2期开始(因为需要上一期)
for i in range(1, len(history)):
current_period, current_number = history[i]
prev_period, prev_number = history[i - 1]
# 根据上一期号码生成大底
groups = get_29_groups(prev_number)
# 检查当前期号码是否匹配
is_match = check_match(current_number, groups)
if is_match:
success_count += 1
print(f"✓ {current_period}: {current_number} 匹配")
else:
fail_count += 1
print(f"✗ {current_period}: {current_number} 不匹配")
total = success_count + fail_count
success_rate = (success_count / total * 100) if total > 0 else 0
print(f"\n统计结果:")
print(f"总期数: {total}")
print(f"成功: {success_count}")
print(f"失败: {fail_count}")
print(f"成功率: {success_rate:.2f}%")
文档版本: v1.5
最后更新: 2026-01-03