广发证券开放平台 API 客户端
Project description
该接口服务,可通过已封装的Python SDK实现调用。使用方式如下:
安装
pip install gf_inst_client
使用示例
from gf_inst_client import APIConfig, GFAPIClient, Condition
# API配置
config = APIConfig(
app_id="your_app_id_here",
key="your_key_here"
)
# 创建API客户端
client = GFAPIClient(config)
# 查询参数
secu_ids = ['000300.SH']
fields = ['secu_id', 'pric_open', 'pric_clos', 'trd_dt']
endpoint = "/dsp/ds/service/news/news_idx_mkt_quot_gfzh_nc" # 仅示例,实际调用路径及参数,请以本身接口文档为准
conditions = [
Condition.in_list("secu_id", secu_ids),
Condition.gt("trd_dt", '20250101')
]
orderFields = ['trd_dt,desc']
# 执行查询
result = client.query(endpoint, conditions, fields, orderFields, auto_paging=True, return_dataframe=True)
print(result)
条件构建器
提供了多种条件构建方法:
eq: 等于lt: 小于gt: 大于le: 小于等于ge: 大于等于begin_with: 以...开始end_with: 以...结束contain: 包含in_list: 在列表中between: 在指定区间条件or_conditions: 或条件
条件构建器使用示例
Condition 类提供了多种条件构建方法,以下是每个方法的详细示例:
1. 等于条件 (eq)
# 查询股票代码等于 000001.SZ 的数据
condition = Condition.eq("secu_id", "000001.SZ")
# 结果: "eq,secu_id,'000001.SZ'"
2. 小于条件 (lt)
# 查询价格小于 10 的数据
condition = Condition.lt("price", 10)
# 结果: "lt,price,10"
3. 大于条件 (gt)
# 查询日期大于 2024-01-01 的数据
condition = Condition.gt("trd_dt", "20240101")
# 结果: "gt,trd_dt,'20240101'"
4. 小于等于条件 (le)
# 查询成交量小于等于 1000000 的数据
condition = Condition.le("volume", 1000000)
# 结果: "le,volume,1000000"
5. 大于等于条件 (ge)
# 查询市值大于等于 1000000000 的数据
condition = Condition.ge("market_value", 1000000000)
# 结果: "ge,market_value,1000000000"
6. 以...开始条件 (begin_with)
# 查询以 "沪" 开头的股票名称
condition = Condition.begin_with("stock_name", "沪")
# 结果: "beginWith,stock_name,'沪'"
7. 以...结束条件 (end_with)
# 查询以 "银行" 结尾的股票名称
condition = Condition.end_with("stock_name", "银行")
# 结果: "endWith,stock_name,'银行'"
8. 包含条件 (contain)
# 查询名称中包含 "科技" 的股票
condition = Condition.contain("stock_name", "科技")
# 结果: "contain,stock_name,'科技'"
9. 在列表中条件 (in_list)
# 查询多个股票代码的数据
secu_ids = ["000001.SZ", "000002.SZ", "000003.SZ"]
condition = Condition.in_list("secu_id", secu_ids)
# 结果: "in,secu_id,'000001.SZ;000002.SZ;000003.SZ'"
11. 在指定区间条件 (between)
# 查询日期范围在 20250101 和 20250601 之间的数据
condition = Condition.between("trd_dt", ['20250101','20250601'])
# 结果: "between,trd_dt,'20250101'#'20250601'"
12. 或条件 (or_conditions)
# 查询沪深300或上证50的股票
condition1 = Condition.eq("index_code", "000300.SH") # 沪深300
condition2 = Condition.eq("index_code", "000016.SH") # 上证50
condition = Condition.or_conditions(condition1, condition2)
# 结果: "or,eq#index_code#'000300.SH',eq#index_code#'000016.SH'"
组合条件示例
# 组合多个条件:查询 2024年1月1日 之后的 沪深300 成分股的数据
conditions = [
Condition.gt("trd_dt", "20240101"),
Condition.eq("index_code", "000300.SH")
]
result = client.query(
endpoint="/your/endpoint",
conditions=conditions,
fields=["secu_id", "stock_name", "close_price"]
)
注意事项
- 条件值如果是字符串类型,会自动添加单引号
- 数值类型(整数、浮点数)不会添加引号
- 日期格式推荐使用 "YYYYMMDD" 格式
- 多个条件可以组合使用,形成一个条件列表
- 使用
or_conditions时,内部的逗号会被替换为 '#' 符号
依赖要求
- Python >= 3.6
- requests >= 2.31.0
- pandas >= 2.0.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gf_inst_client-1.1.1.tar.gz
(6.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gf_inst_client-1.1.1.tar.gz.
File metadata
- Download URL: gf_inst_client-1.1.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
777b942ae7fc39ad29c6b3e4353a4e379d1db7ae27c4707ba7478c608b548f7f
|
|
| MD5 |
1bda4a1f9251da44b1625205b9372b70
|
|
| BLAKE2b-256 |
322db860c0613beec92db9aa886eb3905c7c567c7212f674252565f093c5ab30
|
File details
Details for the file gf_inst_client-1.1.1-py3-none-any.whl.
File metadata
- Download URL: gf_inst_client-1.1.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31116a0db128424614f5b2a9c747c02cf67cc41532f52f7f16521ca04a58ceb1
|
|
| MD5 |
a4a0794dafac7fd620623d32ede2baf7
|
|
| BLAKE2b-256 |
e4386b6188f62e2f14524f2623da585117af9733233a9092d486159f40091cc6
|