parent
fbcb54d23f
commit
0b4c4eb233
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,20 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import urllib.request
|
|
||||||
import json
|
|
||||||
|
|
||||||
req = urllib.request.Request(
|
|
||||||
'http://localhost:8080/v1/admin/adapters',
|
|
||||||
headers={'X-Admin-Token': ''}
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = urllib.request.urlopen(req, timeout=10)
|
|
||||||
data = json.loads(response.read().decode())
|
|
||||||
print('✓ Success!')
|
|
||||||
print(f"Code: {data['code']}")
|
|
||||||
print(f"Message: {data['message']}")
|
|
||||||
print(f"Adapters count: {len(data['data']['adapters'])}")
|
|
||||||
for adapter in data['data']['adapters']:
|
|
||||||
print(f" - {adapter['name']}: {adapter['status']} ({adapter['type']})")
|
|
||||||
except Exception as e:
|
|
||||||
print(f'✗ Error: {e}')
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import urllib.request
|
|
||||||
import json
|
|
||||||
|
|
||||||
req = urllib.request.Request(
|
|
||||||
'http://localhost:8080/v1/admin/adapters',
|
|
||||||
headers={'X-Admin-Token': ''}
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = urllib.request.urlopen(req, timeout=10)
|
|
||||||
data = json.loads(response.read().decode())
|
|
||||||
print('Success!')
|
|
||||||
print("Code:", data['code'])
|
|
||||||
print("Adapters count:", len(data['data']['adapters']))
|
|
||||||
for adapter in data['data']['adapters']:
|
|
||||||
print(" -", adapter['name'] + ":", adapter['status'])
|
|
||||||
except Exception as e:
|
|
||||||
print('Error:', e)
|
|
||||||
@ -1,46 +0,0 @@
|
|||||||
"""测试数据库连接"""
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# 添加项目根目录到路径
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
from app.repositories.database import init_db, engine
|
|
||||||
from sqlalchemy import text
|
|
||||||
|
|
||||||
print("=" * 50)
|
|
||||||
print("数据库连接测试")
|
|
||||||
print("=" * 50)
|
|
||||||
|
|
||||||
try:
|
|
||||||
# 测试连接
|
|
||||||
with engine.connect() as conn:
|
|
||||||
result = conn.execute(text("SELECT version()"))
|
|
||||||
version = result.scalar()
|
|
||||||
print(f"✅ 数据库连接成功")
|
|
||||||
print(f" PostgreSQL 版本: {version}")
|
|
||||||
|
|
||||||
# 初始化数据库(创建表)
|
|
||||||
print("\n正在初始化数据库表...")
|
|
||||||
init_db()
|
|
||||||
print("✅ 数据库表创建成功")
|
|
||||||
|
|
||||||
# 显示所有表
|
|
||||||
from sqlalchemy import inspect
|
|
||||||
inspector = inspect(engine)
|
|
||||||
tables = inspector.get_table_names()
|
|
||||||
print(f"\n已创建的表 ({len(tables)} 个):")
|
|
||||||
for table in sorted(tables):
|
|
||||||
print(f" - {table}")
|
|
||||||
|
|
||||||
print("\n" + "=" * 50)
|
|
||||||
print("数据库初始化完成!")
|
|
||||||
print("=" * 50)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ 错误: {e}")
|
|
||||||
print("\n请检查:")
|
|
||||||
print("1. Docker 是否已启动: docker ps")
|
|
||||||
print("2. 数据库端口是否正确: netstat -ano | findstr 5432")
|
|
||||||
print("3. 数据库密码是否正确")
|
|
||||||
sys.exit(1)
|
|
||||||
@ -1,112 +0,0 @@
|
|||||||
"""测试股票K线接口返回的字段"""
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
|
|
||||||
# API 配置
|
|
||||||
BASE_URL = "http://localhost:8080/v1"
|
|
||||||
API_KEY = ""
|
|
||||||
|
|
||||||
# 测试获取股票K线
|
|
||||||
def test_stock_klines():
|
|
||||||
"""测试股票K线接口返回的字段"""
|
|
||||||
url = f"{BASE_URL}/stock/klines/000001.SZ"
|
|
||||||
headers = {"X-API-Key": API_KEY}
|
|
||||||
params = {
|
|
||||||
"start": "20260301",
|
|
||||||
"end": "20260310",
|
|
||||||
"freq": "1d"
|
|
||||||
}
|
|
||||||
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
print(f"测试接口: GET {url}")
|
|
||||||
print(f"{'='*60}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.get(url, headers=headers, params=params)
|
|
||||||
data = response.json()
|
|
||||||
|
|
||||||
if data.get("code") == 0:
|
|
||||||
kline_data = data.get("data", {})
|
|
||||||
items = kline_data.get("items", [])
|
|
||||||
|
|
||||||
print(f"\n标的: {kline_data.get('symbol')}")
|
|
||||||
print(f"周期: {kline_data.get('freq')}")
|
|
||||||
print(f"数据条数: {len(items)}")
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
|
|
||||||
if items:
|
|
||||||
# 显示第一条数据的完整字段
|
|
||||||
first_item = items[0]
|
|
||||||
print("\n第一条数据详情:")
|
|
||||||
print(f"{'-'*60}")
|
|
||||||
|
|
||||||
# 基础字段
|
|
||||||
print(f"时间戳: {first_item.get('time')}")
|
|
||||||
print(f"开盘价: {first_item.get('open')}")
|
|
||||||
print(f"最高价: {first_item.get('high')}")
|
|
||||||
print(f"最低价: {first_item.get('low')}")
|
|
||||||
print(f"收盘价: {first_item.get('close')}")
|
|
||||||
print(f"成交量: {first_item.get('volume')}")
|
|
||||||
print(f"成交额: {first_item.get('amount')}")
|
|
||||||
|
|
||||||
# 扩展字段
|
|
||||||
print(f"\n扩展字段:")
|
|
||||||
print(f" 交易日: {first_item.get('trade_date')}")
|
|
||||||
print(f" 是否涨停: {first_item.get('is_limit_up')}")
|
|
||||||
print(f" 是否跌停: {first_item.get('is_limit_down')}")
|
|
||||||
print(f" 总市值: {first_item.get('total_market_cap')}")
|
|
||||||
print(f" 流通市值: {first_item.get('float_market_cap')}")
|
|
||||||
print(f" 机构持仓占比: {first_item.get('inst_holding_ratio')}")
|
|
||||||
print(f" 可交易日数: {first_item.get('trading_days')}")
|
|
||||||
print(f" 创建时间: {first_item.get('created_at')}")
|
|
||||||
|
|
||||||
# 验证所有字段是否存在
|
|
||||||
expected_fields = [
|
|
||||||
'symbol', 'time', 'open', 'high', 'low', 'close',
|
|
||||||
'volume', 'amount', 'trade_date', 'is_limit_up',
|
|
||||||
'is_limit_down', 'total_market_cap', 'float_market_cap',
|
|
||||||
'inst_holding_ratio', 'trading_days', 'created_at'
|
|
||||||
]
|
|
||||||
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
print("字段完整性检查:")
|
|
||||||
print(f"{'-'*60}")
|
|
||||||
|
|
||||||
missing_fields = []
|
|
||||||
for field in expected_fields:
|
|
||||||
if field in first_item:
|
|
||||||
print(f" ✓ {field}")
|
|
||||||
else:
|
|
||||||
print(f" ✗ {field} (缺失)")
|
|
||||||
missing_fields.append(field)
|
|
||||||
|
|
||||||
if missing_fields:
|
|
||||||
print(f"\n缺失字段: {', '.join(missing_fields)}")
|
|
||||||
else:
|
|
||||||
print(f"\n所有字段都存在!")
|
|
||||||
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
print("没有获取到数据")
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
print(f"请求失败: {data.get('message')}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"请求异常: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print("\n" + "="*60)
|
|
||||||
print("股票K线接口字段测试")
|
|
||||||
print("="*60)
|
|
||||||
|
|
||||||
success = test_stock_klines()
|
|
||||||
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
if success:
|
|
||||||
print("测试完成!")
|
|
||||||
else:
|
|
||||||
print("测试失败!")
|
|
||||||
print("="*60 + "\n")
|
|
||||||
@ -1,133 +0,0 @@
|
|||||||
"""测试K线数据扩展字段获取"""
|
|
||||||
import asyncio
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
||||||
|
|
||||||
from app.adapters.amazingdata_adapter import AmazingDataAdapter
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
async def test_klines_with_extended_fields():
|
|
||||||
"""测试获取带有扩展字段的K线数据"""
|
|
||||||
print("\n" + "="*60)
|
|
||||||
print("测试K线数据扩展字段")
|
|
||||||
print("="*60)
|
|
||||||
|
|
||||||
adapter = AmazingDataAdapter()
|
|
||||||
|
|
||||||
# 连接配置(请根据实际情况修改)
|
|
||||||
config = {
|
|
||||||
"username": os.getenv("AMAZINGDATA_USERNAME", ""),
|
|
||||||
"password": os.getenv("AMAZINGDATA_PASSWORD", ""),
|
|
||||||
"host": os.getenv("AMAZINGDATA_HOST", "140.206.44.234"),
|
|
||||||
"port": int(os.getenv("AMAZINGDATA_PORT", "8600")),
|
|
||||||
"local_path": "./amazing_data_cache/",
|
|
||||||
"use_local_cache": True
|
|
||||||
}
|
|
||||||
|
|
||||||
try:
|
|
||||||
# 连接适配器
|
|
||||||
print("\n[1/3] 正在连接 AmazingData...")
|
|
||||||
await adapter.connect(config)
|
|
||||||
print("✓ 连接成功")
|
|
||||||
|
|
||||||
# 获取K线数据
|
|
||||||
symbol = "000001.SZ" # 平安银行
|
|
||||||
start_date = "20260301"
|
|
||||||
end_date = "20260310"
|
|
||||||
|
|
||||||
print(f"\n[2/3] 正在获取 {symbol} 的K线数据 ({start_date} ~ {end_date})...")
|
|
||||||
klines = await adapter.fetch_klines(symbol, start_date, end_date, "1d")
|
|
||||||
print(f"✓ 获取到 {len(klines)} 条K线数据")
|
|
||||||
|
|
||||||
# 显示第一条数据的完整信息
|
|
||||||
if klines:
|
|
||||||
print(f"\n[3/3] 数据字段验证")
|
|
||||||
print("-"*60)
|
|
||||||
|
|
||||||
k = klines[0]
|
|
||||||
print(f"\n标的代码: {k.symbol}")
|
|
||||||
print(f"交易日: {k.trade_date}")
|
|
||||||
print(f"时间戳: {datetime.fromtimestamp(k.time)}")
|
|
||||||
|
|
||||||
print(f"\n基础行情:")
|
|
||||||
print(f" 开盘价: {k.open}")
|
|
||||||
print(f" 最高价: {k.high}")
|
|
||||||
print(f" 最低价: {k.low}")
|
|
||||||
print(f" 收盘价: {k.close}")
|
|
||||||
print(f" 成交量: {k.volume}")
|
|
||||||
print(f" 成交额: {k.amount}")
|
|
||||||
|
|
||||||
print(f"\n扩展字段:")
|
|
||||||
print(f" 是否涨停: {k.is_limit_up} {'✓' if k.is_limit_up is not None else '✗'}")
|
|
||||||
print(f" 是否跌停: {k.is_limit_down} {'✓' if k.is_limit_down is not None else '✗'}")
|
|
||||||
print(f" 总市值: {k.total_market_cap:,.0f} 元" if k.total_market_cap else " 总市值: None ✗")
|
|
||||||
print(f" 流通市值: {k.float_market_cap:,.0f} 元" if k.float_market_cap else " 流通市值: None ✗")
|
|
||||||
print(f" 机构持仓占比: {k.inst_holding_ratio}%" if k.inst_holding_ratio else " 机构持仓占比: None")
|
|
||||||
print(f" 可交易日数: {k.trading_days} {'✓' if k.trading_days else '✗'}")
|
|
||||||
|
|
||||||
# 验证字段完整性
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
print("字段完整性检查:")
|
|
||||||
print("-"*60)
|
|
||||||
|
|
||||||
checks = [
|
|
||||||
("symbol", k.symbol is not None),
|
|
||||||
("time", k.time > 0),
|
|
||||||
("open", k.open > 0),
|
|
||||||
("high", k.high > 0),
|
|
||||||
("low", k.low > 0),
|
|
||||||
("close", k.close > 0),
|
|
||||||
("volume", k.volume > 0),
|
|
||||||
("amount", k.amount > 0),
|
|
||||||
("trade_date", k.trade_date is not None),
|
|
||||||
("is_limit_up", k.is_limit_up is not None),
|
|
||||||
("is_limit_down", k.is_limit_down is not None),
|
|
||||||
("total_market_cap", k.total_market_cap is not None and k.total_market_cap > 0),
|
|
||||||
("float_market_cap", k.float_market_cap is not None and k.float_market_cap > 0),
|
|
||||||
("trading_days", k.trading_days is not None and k.trading_days > 0),
|
|
||||||
]
|
|
||||||
|
|
||||||
passed = 0
|
|
||||||
for field, check in checks:
|
|
||||||
status = "✓" if check else "✗"
|
|
||||||
print(f" {status} {field}")
|
|
||||||
if check:
|
|
||||||
passed += 1
|
|
||||||
|
|
||||||
print(f"\n通过: {passed}/{len(checks)}")
|
|
||||||
|
|
||||||
# 显示涨跌停判断逻辑验证
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
print("涨跌停判断示例:")
|
|
||||||
print("-"*60)
|
|
||||||
for k in klines[:3]: # 显示前3条
|
|
||||||
limit_status = ""
|
|
||||||
if k.is_limit_up:
|
|
||||||
limit_status = "📈 涨停"
|
|
||||||
elif k.is_limit_down:
|
|
||||||
limit_status = "📉 跌停"
|
|
||||||
else:
|
|
||||||
limit_status = "—"
|
|
||||||
print(f" {k.trade_date}: 收盘{k.close} {limit_status}")
|
|
||||||
|
|
||||||
# 断开连接
|
|
||||||
await adapter.close()
|
|
||||||
print(f"\n{'='*60}")
|
|
||||||
print("测试完成!")
|
|
||||||
print("="*60 + "\n")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"\n✗ 测试失败: {e}")
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
success = asyncio.run(test_klines_with_extended_fields())
|
|
||||||
sys.exit(0 if success else 1)
|
|
||||||
Binary file not shown.
@ -1,17 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import urllib.request
|
|
||||||
import json
|
|
||||||
|
|
||||||
# Test source status
|
|
||||||
req = urllib.request.Request(
|
|
||||||
'http://localhost:8080/v1/admin/source/status',
|
|
||||||
headers={'X-API-Key': ''}
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = urllib.request.urlopen(req, timeout=10)
|
|
||||||
data = json.loads(response.read().decode())
|
|
||||||
print('Source Status:')
|
|
||||||
print(json.dumps(data, indent=2, ensure_ascii=False))
|
|
||||||
except Exception as e:
|
|
||||||
print('Error:', e)
|
|
||||||
Binary file not shown.
Loading…
Reference in new issue