Finology 大数据金融

通过大数据以量化金融

行情数据

股票

期货

期权

债券

参考数据

合约信息

交易日历

仓单库存

财务数据

每股盈利

市盈率

一致预期

经济数据

GDP

CPI

非农就业

使用 python 3.10 连接 MySQL 8.0 数据库

安装 peewee

Peewee 是一个轻量级的 Python ORM(对象关系映射)库,它让您可以用 Python 代码来操作数据库,而不需要直接写 SQL 语句。

1
mamba install peewee

安装 pymysql

1
mamba install pymysql
1
2
3
4
5
6
7
Python 代码

Peewee ORM

PyMySQL 驱动

MySQL 数据库

数据库连接

1
2
3
import peewee
db = peewee.MySQLDatabase("vnpy", user="root", password="password", host="127.0.0.1", port=3306)
db.connect()

后来发现使用 SQLAlchemy 也不错。

写一个使用 SQL 查询的案例

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
from sqlalchemy import create_engine, text

# 创建数据库引擎
engine = create_engine('mysql+pymysql://root:password@localhost:3306/ticket_system')

with engine.connect() as connection:
# 使用命名参数
sql_with_params = text("""
SELECT id, title, status, create_time
FROM ticket
WHERE status = :status
AND create_time >= :start_date
ORDER BY create_time DESC
LIMIT :limit_num
""")

params = {
"status": "PENDING",
"start_date": "2020-01-01",
"limit_num": 5
}

result = connection.execute(sql_with_params, params)
print("参数化查询结果:")
for row in result:
print(f"ID: {row.id}, 标题: {row.title}, 时间: {row.create_time}")

以下是 Windows 10 安装Claude Code,Window 11 往下翻。

安装 nodejs

安装 Volta,目的是可以自由切换 nodejs 版本,下载地址:https://github.com/volta-cli/volta/releases

安装 nodejs 20 版本。每个版本只会下载一次。

1
volta install node@20

安装 Claude Code 工具

1
npm install -g @anthropic-ai/claude-code

查看以下两个文件是否存在,如果存在即安装成功

1
2
C:\Users\{USER}]\AppData\Local\Volta\bin\claude
C:\Users\{USER}\AppData\Local\Volta\bin\claude.cmd

如果没有用 Volta 来安装,直接安装的 nodejs.msi,那么 claude 的安装位置可能会在 C:\Users\{USER}\AppData\Roaming\npm,需要把这个位置添加到环境变量中的 PATH 正面。

使用 Claude Code

设置用户环境变量

ANTHROPIC_BASE_URLANTHROPIC_AUTH_TOKEN,要么配置代理做转发,要么使用魔法。

在任何目录输入命令 claude,即进入到使用界面。

设置 prompt 页面的主题风格。

安装提示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
╭──────────────────────────╮
│ ✻ Welcome to Claude Code │
╰──────────────────────────╯

Security notes:

Claude can make mistakes
You should always review Claude's responses, especially when
running code.

Due to prompt injection risks, only use it with code you trust
For more details see:
https://docs.claude.com/s/claude-code-security

Press Enter to continue…

下一步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Do you trust the files in this folder? │
│ │
│ D:\development\python │
│ │
│ Claude Code may read, write, or execute files contained in this directory. This can pose security risks, so only use │
│ files from trusted sources. │
│ │
│ Learn more ( https://docs.claude.com/s/claude-code-security ) │
│ │
│ > 1. Yes, proceed │
│ 2. No, exit │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Enter to confirm · Esc to exit

如果是在 Windows 11 下安装,又要使用 Volta 的话,还得多几步。

默认安装 Volta,是在 Program Files 下面的,但因为里面有个空格,运行 claude 时会报错。

‘C:\Program’ is not recognized as an internal or external command,
operable program or batch file.

路径中的空格(C:\Program Files...)导致命令解析出错。这是 Windows 命令行(cmd.exe)常见的路径空格问题。

所以需要把安装文件拷贝到一个没有空格的目录下面。同时再设置好Path,就可以了。

0%