python 行情数据_python爬取期权行情数据
想要弄点数据要求高的可以找收费的数据服务商,例如wind,东方财富,后者便宜点,tushare也提供了期权行情数据,但是门槛是有积分限制,其他的地方只能爬取了。做期权策略分析没有数据怎么行,没钱就写一个吧。
数据源
主要涉及的接口
当前交易的期权合约月份
{"result":{"status":{"code":0},"data":{"cateList":["50ETF","50ETF","300ETF"],"contractMonth":["2020-06","2020-06","2020-07","2020-09","2020-12"],"stockId":"510050","cateId":"510050C2006A02800"}}}
当前标的月份下的期权合约
var hq_str_OP_UP_5100502006="CON_OP_10002421,CON_OP_10002401,CON_OP_10002402,CON_OP_10002291,CON_OP_10002292,CON_OP_10002293,CON_OP_10002294,CON_OP_10002083,CON_OP_10002009,CON_OP_10002084,CON_OP_10001989,CON_OP_10002085,CON_OP_10001990,CON_OP_10002086,CON_OP_10001991,CON_OP_10002087,CON_OP_10001992,CON_OP_10002088,CON_OP_10001993,CON_OP_10002089,CON_OP_10001994,CON_OP_10002090,CON_OP_10001995,CON_OP_10002091,CON_OP_10001996,CON_OP_10002107,CON_OP_10001997,CON_OP_10002115,CON_OP_10002007,CON_OP_10002213,";
当前期权合约行情
var hq_str_CON_OP_10002086="10,0.0614,0.0615,0.0615,24,102344,15.38,2.8500,0.0533,0.0550,0.3411,0.0001,0.0619,3,0.0618,26,0.0617,3,0.0616,1,0.0615,24,0.0614,10,0.0613,25,0.0612,65,0.0611,5,0.0610,161,2020-06-05 15:00:00,0,E 01,EBS,510050,50ETF购6月2850,29.83,0.0615,0.0456,121255,63182460.00,M,0.0533,C,2020-06-24,19,2,0.042,0.0195";
python实现
import requests
import json
from itertools import product
import pandas as pd
get_option_months_api = "http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName"
get_option_quot = 'http://hq.sinajs.cn/list='
underlying = ['510050', '510300']
call_put_type = ['OP_UP_', 'OP_DOWN_']
col = ['买量', '买价', '最新价', '卖价', '卖量', '持仓量', '涨跌幅', '行权价', '昨收', '今开', '涨停', '跌停', '卖5价', '卖5量', '卖4价', '卖4量', '卖3价',
'卖3量', '卖2价', '卖2量', '卖1价', '卖1量', '买1价', '买1量', '买2价', '买2量', '买3价', '买3量', '买4价', '买4量', '买5价', '买5量', '闭市时段',
'未知', '未知', '未知', '标的', '名称', '振幅', '时间价值', '最低价', '成交量', '未知', '未知', '昨结算', '类型', '行权日', '距离行权', '未知', '内在价值',
'未知', '编码']
def get_contract_months():
"""
获取合约月
:return:
"""
resp = requests.get(get_option_months_api)
result = json.loads(resp.text)
months = result['result']['data']['contractMonth']
format_funtion = lambda month: str(month).replace("-", '')[2:]
months = [format_funtion(month) for month in months]
return list(set(months))
def get_contracts(months):
"""
获取合约月
:return:
"""
result = {}
resp = requests.get('{}{}'.format(get_option_quot, ','.join(months)))
lines = resp.text.splitlines()
for line in lines:
temp = line.split('=')
key_name = temp[0].split('_')[-1]
value = temp[1].split('\"')[1].split(',')[:-1]
if key_name in result:
result[key_name].extend(value)
else:
result[key_name] = value
return result
def get_contract_quot(month_contract, writer):
"""
获取行情详情
:param month_contract:
:param writer:
:return:
"""
for key, value in month_contract.items():
resp = requests.get('{}{}'.format(get_option_quot, ','.join(value)))
result_temp = []
lines = resp.text.splitlines()
for line in lines:
temp = line.split('=')
code = temp[0].split('_')[-1]
value = temp[1].split('\"')[1].split(',')
value.append(code)
result_temp.append(value)
df = pd.DataFrame(result_temp, columns=col)
df.to_excel(writer, key)
if __name__ == '__main__':
contract_months = get_contract_months()
underlying_months_param = ['{}{}{}'.format(call_put_type_item, underlying_item, contract_month) for
call_put_type_item, underlying_item, contract_month in
product(call_put_type, underlying, contract_months)]
print(underlying_months_param)
month_contract = get_contracts(underlying_months_param)
print(month_contract)
writer = pd.ExcelWriter('output.xlsx')
get_contract_quot(month_contract=month_contract, writer=writer)
writer.save()
结果如下
其他可用的接口
A股股票&基金
http://hq.sinajs.cn/list=sh601006
http://hq.sinajs.cn/list=sh502007
A股指数
http://hq.sinajs.cn/list=s_sz399001
港股股票
http://hq.sinajs.cn/list=hk02333
http://hq.sinajs.cn/list=rt_hkCSCSHQ #沪港通资金流量
港股指数
http://hq.sinajs.cn/list=int_hangseng
http://hq.sinajs.cn/list=rt_hkHSI
http://hq.sinajs.cn/list=hkHSI,hkHSCEI,hkHSCCI #恒生指数,恒生国企指数,恒生红筹指数
美股股票&基金
http://hq.sinajs.cn/list=gb_amzn
http://hq.sinajs.cn/list=usr_amzn
http://hq.sinajs.cn/list=usr_russ
美股指数
http://hq.sinajs.cn/list=int_nasdaq
http://hq.sinajs.cn/list=gb_ixic #纳斯达克指数
http://hq.sinajs.cn/list=int_dji
http://hq.sinajs.cn/list=int_sp500
http://hq.sinajs.cn/list=int_ftse #伦敦指数
http://hq.sinajs.cn/list=int_bloombergeuropean500 #彭博欧洲500指数
http://hq.sinajs.cn/list=int_dax30,int_djstoxx50
外汇行情
http://hq.sinajs.cn/list=XAUUSD
http://hq.sinajs.cn/list=DINIW #美元指数
黄金&白银
http://hq.sinajs.cn/list=hf_XAU
http://hq.sinajs.cn/list=hf_XAG
http://hq.sinajs.cn/list=hf_GC #COMEX黄金
http://hq.sinajs.cn/list=hf_SI #COMEX白银
http://hq.sinajs.cn/list=hf_AUTD #黄金TD
http://hq.sinajs.cn/list=hf_AGTD #白银TD
http://hq.sinajs.cn/list=AU0 #黄金期货
http://hq.sinajs.cn/list=AG0 #白银期货
http://hq.sinajs.cn/list=hf_CL #NYMEX原油
期货
http://hq.sinajs.cn/list=CFF_LIST #金融期货合约
http://finance.sina.com.cn/iframe/futures_info_cff.js #商品与金融期货合约
http://hq.sinajs.cn/?list=CFF_RE_IF1705 #合约行情
期权合约的月份
http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName
期权合约到期日
http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay?date=201705
看涨期权合约
http://hq.sinajs.cn/list=OP_UP_5100501705
看跌期权合约
http://hq.sinajs.cn/list=OP_DOWN_5100501705
期权行情
http://hq.sinajs.cn/list=CON_OP_10000869
http://hq.sinajs.cn/list=CON_ZL_10000869
http://hq.sinajs.cn/list=CON_SO_10000869
热门股票
http://finance.sina.com.cn/realstock/company/hotstock_daily_a.js
新股日历
http://vip.stock.finance.sina.com.cn/corp/view/iframe/vAK_NewStockIssueFrame_2015.php?num=10
定增列表
http://vip.stock.finance.sina.com.cn/corp/view/vAK_IncreaseStockIssueFrame_2015.php?num=10
基金公司
http://vip.stock.finance.sina.com.cn/fund_center/api/jsonp.php/var%20companyList=/NetValue_Service.getAllCompany
python 行情数据_python爬取期权行情数据相关推荐
- python爬取天气数据_Python爬取历史天气数据
Python爬取历史天气数据 作者:梅昊铭 1. 导读 之前Mo给大家分享过杭州历年天气情况的数据集,相信有不少小伙伴好奇这些数据是怎么获取.今天Mo就来教大家如何使用Python来进行历史天气数据的 ...
- python二手房数据分析_Python 爬取北京二手房数据,分析北漂族买得起房吗? | 附完整源码...
作者 徐麟 本文经授权转自公众号数据森麟(ID: shujusenlin) 房价高是北漂们一直关心的话题,本文就对北京的二手房数据进行了分析. 本文主要分为两部分:Python爬取赶集网北京二手房数据 ...
- python抓取招聘数据_Python爬取招聘网站数据并做数据可视化处理
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章来源于青灯编程 ,作者:清风 前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有 ...
- python爬取微博数据存入数据库_Python爬取新浪微博评论数据,写入csv文件中
因为新浪微博网页版爬虫比较困难,故采取用手机网页端爬取的方式 操作步骤如下: 1. 网页版登陆新浪微博 2.打开m.weibo.cn 3.查找自己感兴趣的话题,获取对应的数据接口链接 4.获取cook ...
- python 柱状图上显示字体_Python爬取百部电影数据,我发现了这个惊人真相!
2019年就这么匆匆过去了,就在前几天国家电影局发布了2019年中国电影市场数据,数据显示去年总票房为642.66亿元,同比增长5.4%:国产电影总票房411.75亿元,同比增长8.65%,市场占比 ...
- python爬取app中的音频_Python爬取喜马拉雅音频数据详解
码农公社 210.net.cn 210是何含义?10月24日是程序员节,1024 =210.210既 210 之意. Python爬取喜马拉雅音频数据详解 一.项目目标 爬取喜马拉雅音频数据 受害 ...
- python爬取网页json数据_python爬取json数据库
手把手教你使用Python抓取QQ音乐数据(第一弹) [一.项目目标] 获取 QQ 音乐指定歌手单曲排行指定页数的歌曲的歌名.专辑名.播放链接. 由浅入深,层层递进,非常适合刚入门的同学练手. [二. ...
- python爬取历史天气_Python 爬取历史天气数据
Python 爬取历史天气数据 作者:梅昊铭 1. 导读 之前Mo给大家分享过杭州历年天气情况的数据集,相信有不少小伙伴好奇这些数据是怎么获取.今天Mo就来教大家如何使用Python来进行历史天气数据 ...
- python爬取动态网页_python爬取动态网页数据,详解
原理:动态网页,即用js代码实现动态加载数据,就是可以根据用户的行为,自动访问服务器请求数据,重点就是:请求数据,那么怎么用python获取这个数据了? 浏览器请求数据方式:浏览器向服务器的api(例 ...
最新文章
- 电脑人会得哪些病----------关注健康,关爱生命!
- oracle文件夹cwallet,Oracle Wallet
- 北京 10 年,难说再见!
- Libgdx学习笔记:分享自己写的异步加载
- SQL查询语句[0]
- PHP 单元测试工具 SimpleTest
- Linux时间 时区 同步
- How is html text displayed in Assignment block
- python函数学习1
- pitr 原理_PostgreSQL基于时间点恢复(PITR)
- sort降序shell_排序之希尔排序(shell sort)
- poj 2001 Shortest Prefixes(特里)
- 防窥屏的膜能真的防止别人偷看吗,其原理是什么?
- [APIO / CTSC2007]数据备份 --- 贪心
- Error writing to registry key: RegSetValueEx failed; code 5
- [渝粤教育] 中国地质大学(武汉) 走近国粹 中国陶瓷 参考 资料
- html description字数限制,description标签如何正确使用?
- 【DD应用系统源码】软件库源码
- python tan_Python tan() 函数 - Python 教程 - 自强学堂
- WordPress+BuddyPress注册页面404问题的解决
热门文章
- SQL中实用的小技巧
- Thymeleaf【快速入门】
- android 发广播屏蔽home键,如何在Android App中屏蔽(拦截)Home按键及其他按键
- 04.Quartz 触发器
- QT起一个线程实时监测某个进程是否正常运行
- Python自学笔记6:实操案例三(十进制转换二、八、十六进制),手机充值,计算能量消耗,预测未来子女身高
- 【电信学】【2016.02】基于IMU的遥控车自主导航位置跟踪
- 代码详细教程+文档+PPT+源码等]SSM框架美妆商城全套|电商购物计算机专业毕业论文java毕业设计网站
- 可发教育类论文的期刊《家长》简介及投稿邮箱
- 世界各国劳动力总数数据集1990-2019年