forked from nehcuh/quantbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_data.py
56 lines (51 loc) · 1.79 KB
/
test_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from pymongo import MongoClient
import pandas as pd
from datetime import datetime
# 连接到 MongoDB
client = MongoClient('mongodb://localhost:27018')
db = client['quantbox']
def test_trade_dates():
"""测试交易日期数据"""
collection = db['trade_date']
# 获取最新的交易日期
latest = collection.find_one(sort=[('datestamp', -1)])
print("\n=== 交易日期测试 ===")
print(f"总记录数: {collection.count_documents({})}")
print(f"最新交易日: {latest['datestamp'] if latest else 'N/A'}")
print(f"数据示例:")
for doc in collection.find().limit(3):
print(doc)
def test_future_contracts():
"""测试期货合约数据"""
collection = db['future_contracts']
# 获取一条数据来查看结构
sample = collection.find_one()
print("\n=== 期货合约测试 ===")
print(f"总记录数: {collection.count_documents({})}")
print(f"数据结构示例:")
if sample:
print("字段列表:", list(sample.keys()))
print("数据示例:", sample)
print(f"\n数据示例:")
for doc in collection.find().limit(3):
print(doc)
def test_future_holdings():
"""测试期货持仓数据"""
collection = db['future_holdings']
# 获取一条数据来查看结构
sample = collection.find_one()
print("\n=== 期货持仓测试 ===")
print(f"总记录数: {collection.count_documents({})}")
print(f"数据结构示例:")
if sample:
print("字段列表:", list(sample.keys()))
print("数据示例:", sample)
print(f"\n数据示例:")
for doc in collection.find().limit(3):
print(doc)
if __name__ == '__main__':
print("开始测试数据库...")
test_trade_dates()
test_future_contracts()
test_future_holdings()
print("\n测试完成!")