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.
52 lines
1.2 KiB
52 lines
1.2 KiB
# -*- coding: utf-8 -*-
|
|
import psycopg2
|
|
|
|
# 数据库连接参数
|
|
db_config = {
|
|
'host': '192.168.31.201',
|
|
'port': 5432,
|
|
'database': 'alpha',
|
|
'user': 'jack',
|
|
'password': 'aaaAAA111'
|
|
}
|
|
|
|
results = []
|
|
|
|
try:
|
|
# 连接数据库
|
|
conn = psycopg2.connect(**db_config)
|
|
# 创建游标
|
|
cur = conn.cursor()
|
|
|
|
keys = ["pcr_oi_90", "implied_volatility_call_90", "implied_volatility_put_90", "pcr_oi_270", "implied_volatility_call_270", "implied_volatility_put_270", "volume", "open_interest", "volume_call", "volume_put", "open_interest_call", "open_interest_put", "close", "vwap", "adv20", "market_cap", "subindustry", "sector", "industry"]
|
|
|
|
for key in keys:
|
|
# SQL 查询语句
|
|
sql = """
|
|
select * from data_sets
|
|
where name like '%{}%'
|
|
""".format(key)
|
|
|
|
# 执行查询
|
|
cur.execute(sql)
|
|
|
|
# 获取所有结果
|
|
rows = cur.fetchall()
|
|
|
|
# 打印结果
|
|
for row in rows:
|
|
results.append({
|
|
"name": row[1],
|
|
"description": row[2],
|
|
})
|
|
|
|
# 关闭游标和连接
|
|
cur.close()
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print("数据库连接或查询出错:", e)
|
|
|
|
|
|
for result in results:
|
|
print(result) |