Initial: MoFin 持仓分析与策略管理系统

核心模块:
- 策略生命周期管理 (strategy_lifecycle.py)
- 技术分析引擎 (technical_analysis.py)
- 双维度策略评估 (strategy_evaluator.py)
- 实时行情获取 (get_realtime_prices.py)
- Web Dashboard (server.py, :8899)

提示词版本管理:
- prompt_manager 模块 — 统一管理所有知微提示词
- 8个提示词共24个版本已录入
- 策略→提示词版本关联追踪
- Dashboard「提示词」Tab

数据源增强:
- 服务端 POST /api/update/realtime 端点已就绪
- clients/tdx-relay/ — 小小莫在Windows上开发的通达信中继
- 解决港股15分钟延迟问题
This commit is contained in:
2026-06-12 22:54:51 +08:00
commit 9b9c37002a
65 changed files with 8659 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
"""tdx-relay package — 通达信行情中继"""
+39
View File
@@ -0,0 +1,39 @@
"""配置管理 — 请在 Windows 上填好招商证券行情主站IP后运行"""
# 招商证券行情主站列表
# 打开招商证券PC客户端 → 通信设置 查看
# 格式: (名称, IP, 端口)
MARKET_SERVERS = [
# 示例(替换为你的实际IP):
# ("招商证券深圳主站", "113.105.73.88", 7709),
# ("招商证券上海主站", "211.154.53.106", 7709),
# TODO: 小小莫替换为实际IP
]
# MoFin Dashboard 地址
MOFIN_URL = "http://192.168.1.246:8899"
# 推送频率(秒)
PUSH_INTERVAL = 15
# 港股列表(市场代码, 股票代码)
# 港股主板 market_code = 31
HK_STOCKS = [
(31, "00700"), # 腾讯控股
(31, "09988"), # 阿里巴巴-W
(31, "00981"), # 中芯国际
(31, "01211"), # 比亚迪股份
(31, "01888"), # 建滔积层板
(31, "02318"), # 中国平安
(31, "02359"), # 药明康德
(31, "02388"), # 中银香港
(31, "02628"), # 中国人寿
(31, "06160"), # 百济神州
(31, "06869"), # 长飞光纤
(31, "09868"), # 小鹏汽车-W
(31, "01070"), # TCL电子
(31, "01088"), # 中国神华
(31, "00968"), # 信义光能
(31, "02202"), # 万科企业
(31, "01478"), # 丘钛科技
]
+40
View File
@@ -0,0 +1,40 @@
"""数据推送器 — 推送实时行情到 MoFin Dashboard"""
import json
import time
import urllib.request
import urllib.error
class MoFinPusher:
"""推送实时行情到 MoFin Dashboard API"""
def __init__(self, base_url: str = "http://192.168.1.246:8899"):
self.base_url = base_url.rstrip("/")
self.endpoint = f"{self.base_url}/api/update/realtime"
def push(self, stocks: list) -> dict:
"""推送一批实时行情
Args:
stocks: [{"code", "price", "change_pct", ...}, ...]
Returns:
{"status": "ok", "updated": N, "timestamp": "..."}
"""
payload = json.dumps({
"stocks": stocks,
"source": "tdx_relay",
}).encode("utf-8")
req = urllib.request.Request(
self.endpoint,
data=payload,
headers={"Content-Type": "application/json"},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=10) as resp:
return json.loads(resp.read().decode("utf-8"))
except (urllib.error.URLError, urllib.error.HTTPError, OSError) as e:
return {"status": "error", "message": str(e)}
+62
View File
@@ -0,0 +1,62 @@
"""TDX 行情客户端 — 连接通达信行情服务器获取实时数据
小小莫:
1. pip install opentdx
2. 在 config.py 中填入招商证券行情主站IP
3. 实现下面的方法
4. 运行 test_tdx_connect.py 验证
"""
# ═══════════════════════════════════════════
# 配置区 — 请替换为你的招商证券行情主站IP
# ═══════════════════════════════════════════
from .config import MARKET_SERVERS, HK_STOCKS
class TDXClient:
"""通达信行情客户端封装
用法:
client = TDXClient()
client.connect("113.105.73.88", 7709)
data = client.get_hk_quotes()
client.close()
"""
def __init__(self):
self.client = None
def connect(self, ip: str, port: int = 7709):
"""连接到通达信行情服务器"""
# TODO: 小小莫实现
# from opentdx.client.macExtendedClient import MacExtendedClient
# self.client = MacExtendedClient()
# self.client.connect(ip, port)
raise NotImplementedError("由小小莫实现")
def get_hk_quote(self, market_code: int, code: str) -> dict:
"""获取单只港股实时报价
Args:
market_code: 港股主板=31
code: 如 "00700"
Returns:
{"code": "00700", "name": "腾讯控股", "price": 463.6,
"change_pct": 1.55, "high": 468.0, "low": 460.2, ...}
"""
raise NotImplementedError("由小小莫实现")
def get_hk_quotes(self, codes: list = None) -> list:
"""批量获取港股实时报价"""
if codes is None:
codes = [(31, code) for _, code in HK_STOCKS]
raise NotImplementedError("由小小莫实现")
def close(self):
if self.client:
try:
self.client.disconnect()
except Exception:
pass
self.client = None