这篇博客用来把在Mac平台上使用python接入东方财富Choice接口的流程细化并重写,官方文档有些地方说的太含糊了,有的地方博主尝试了多种方法才试出来,这里直接把标准答案给到大家,尽量避坑吧~

吐槽:同花顺科技感很足,赞,但是没有Mac版本的,而且券商数据太少太少啦,希望再接再厉吧

Choice账号获取

首先使用这个接口的时候,需要有购买的账号哈,价格请参考:https://choice.eastmoney.com/buyingcenter,应该是每年3w

一般你注册账号之后会有人打电话联系你,或是主动打客服,都可以的。

然后给账号绑定一个手机号,后续需要这个手机号

Choice接口激活

Choice 官方使用接口的文档如下:http://quantapi.eastmoney.com/Manual/Index?from=web&loc=%E6%8E%A5%E5%8F%A3%E9%85%8D%E7%BD%AE&ploc=%E6%8E%A5%E5%8F%A3%E9%85%8D%E7%BD%AE

  1. 首先进入网站:http://quantapi.eastmoney.com/Download?from=web,下载python的版本:
    在这里插入图片描述
    下载的链接是:http://updates.jg.eastmoney.com/Choice/EMQuantAPI/EMQuantAPI_Python.zip

  2. 下载压缩包后,使用:

unzip EMQuantAPI_Python.zip
cd EMQuantAPI_Python
cd python3
python installEmQuantAPI.py 

这样就在当前的环境中添加依赖了

  1. 激活接口(这里用官网的第一种,大家也可以使用后面两种看着就很麻烦的方法…)

运行命令:

brew install gtk+3
cd libs/mac
chmod +x loginactivator_mac
./loginactivator_mac

然后打开了一个界面:
在这里插入图片描述
点击激活,这里需要账号当时绑定的手机号,配置完成后就OK啦

此时当前的文件夹下会有一个文件userInfo,文件中是一串字符串

Python接口拉取数据

大家可以尝试运行下面的示例代码:

代码拉取的数据是000001.SZ,000002.SZ这两个证券的股票名称与IPO时间

from EmQuantAPI import c
import pandas as pd

# 登录
loginresult = c.start()
print(loginresult)
# 数据
choice_data = c.css("000001.SZ,000002.SZ", "NAME,LISTDATE", "")
if choice_data.ErrorMsg == "success":
    data_df = pd.DataFrame(choice_data.Data).T
    data_df.columns = choice_data.Indicators
    print(data_df)
# 登出
logoutresult = c.stop()

结果:

[EmQuantAPI Python] [Em_Info][2022-07-01 11:24:10]:The current version is EmQuantAPI(V2.5.3.4).

[EmQuantAPI Python] [Em_Info][2022-07-01 11:24:10]:verifying your token...

[EmQuantAPI Python] [Em_Info][2022-07-01 11:24:10]:connect server...

[EmQuantAPI Python] [Em_Info][2022-07-01 11:24:11]:start success!

ErrorCode=0, ErrorMsg=success, Data={}
[EmQuantAPI Python] [Em_Info][2022-07-01 11:24:11]:percentflag(for csd/css/cses) update success.

           NAME   LISTDATE
000001.SZ  平安银行   1991/4/3
000002.SZ   万科A  1991/1/29
[EmQuantAPI Python] [Em_Info][2022-07-01 11:24:12]:heartbeatthread end.

其中,前面的[EmQuantAPI Python]是登录登出的日志,中间的对应data_df的数据如下:

           NAME   LISTDATE
000001.SZ  平安银行   1991/4/3
000002.SZ   万科A  1991/1/29

更多代码

请参考代码生成的工具:http://quantapi.eastmoney.com/Cmd/ChoiceSerialSection?from=web

量化接口的数据是有每周的调用限制的:

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐