转自:陆子野
1、获得当前有哪几个月份的合约
(50ETF)http://stock.finance.sina.com.cn ... null&cate=50ETF
(上交所300ETF)http://stock.finance.sina.com.cn ... ull&cate=300ETF
返回结果示例如下,contractMonth字段就是我们想要的数据
- {
- "result": {
- "status": {
- "code": 0
- },
- "data": {
- "cateList": [
- "300ETF",
- "50ETF",
- "300ETF"
- ],
- "contractMonth": [
- "2020-01",
- "2020-01",
- "2020-02",
- "2020-03",
- "2020-06"
- ],
- "stockId": "510300",
- "cateId": "510300C2001"
- }
- }
- }
复制代码 2、获得某个月份合约的到期日和剩余天数
非除权日http://stock.finance.sina.com.cn ... TF&date=2020-06
除权日http://stock.finance.sina.com.cn ... TF&date=2020-06
上交所300ETF的需要将上面url中的50ETF改为300ETF
大家调用的时候把年和月改成上面第一个接口返回的年和月,例如2019年4月就是date=2019-04,结果示例如下,expireDay字段为到期日,remainderDays字段为剩余天数
- {
- "result": {
- "status": {
- "code": 0
- },
- "data": {
- "expireDay": "2020-06-24",
- "remainderDays": 180,
- "stockId": "510300",
- "cateId": "510300C2006",
- "zhulikanzhang": "",
- "zhulikandie": "",
- "other": {
- "name": "华泰柏瑞沪深300ETF",
- "type": 10,
- "symbol": "s_sh510300",
- "url": "http://finance.sina.com.cn/fund/quotes/510300/bc.shtml"
- }
- }
- }
- }
复制代码 3、获得某月到期的看涨期权代码列表http://hq.sinajs.cn/list=OP_UP_5100502006,510050为标的代码,2006代表到期年月。
上交所300ETFhttp://hq.sinajs.cn/list=OP_UP_5103002006
结果示例如下
- var hq_str_OP_UP_5100502006="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,";
复制代码 4、获得某月到期的看跌期权代码列表http://hq.sinajs.cn/list=OP_DOWN_5103002006,同上
5、根据合约代码获得实时期权行情http://hq.sinajs.cn/list=CON_OP_10002180,结果示例如下
- var hq_str_CON_OP_10002176="1,0.2822,0.2849,0.2852,1,4096,-0.38,4.1000,0.2860,
- 0.2987,0.7018,0.0001,0.2920,10,0.2894,1,0.2888,1,0.2881,10,0.2852,1,0.2822,1,0.2768,
- 15,0.2689,1,0.2683,1,0.2661,1,2020-01-10 14:55:35,0,E 01,EBS,510300,300ETF购6月4100,
- 7.10,0.2987,0.2784,521,1485322.00,M,0.2860,C,2020-06-24,166,2,0.057,0.2279";
- 各个字段的意思
- var hq_str_CON_OP_代码=“买量(0),买价,最新价,卖价,卖量,持仓量,涨幅,行权价,昨收价,开盘价,涨停价,跌停价(11),
- 申卖 价五,申卖量五,申卖价四,申卖量四,申卖价三,申卖量三,申卖价二,申卖量二,申卖价一,申卖量一,申买价一,
- 申买量一 ,申买价二,申买量二,申买价三,申买量三,申买价四,申买量四,申买价五,申买量五,行情时间,主力合约标识,状态码,
- 标的证券类型,标的股票,期权合约简称,振幅(38),最高价,最低价,成交量,成交额,分红调整标志,昨结算价,认购认沽标志,
- 到期日,剩余天数,虚实值标志,内在价值,时间价值
复制代码 6、50ETF实时行情http://hq.sinajs.cn/list=sh510050,结果示例如下
上交所300ETF实时行情http://hq.sinajs.cn/list=sh510300
- var hq_str_sh510050="
- 50ETF,2.715,2.690,2.701,2.744,2.687,2.700,2.701,1323173371,3593093810.000,2134800,
- 2.700,1175600,2.699,466500,2.698,154000,2.697,1451100,2.696,257800,2.701,525100,2.702,
- 299500,2.703,233800,2.704,1286100,2.705,2019-03-12,15:00:05,00";
- 各个字段意义
- var hq_str_sh510050=证券简称,今日开盘价,昨日收盘价,最近成交价,最高成交价,最低成交价,买入价,
- 卖出价,成交数量,成交金额,买数量一,买价位一,买数量二,买价位二,买数量三 ,买价位三,买数量四,
- 买价位四,买数量五,买价位五,卖数量一,卖价位一,卖数量二,卖价位二,卖数量三,卖价位三,卖数量四,
- 卖价位四,卖数量五,卖价位五,行情日期,行情时间,停牌状态
复制代码 简版的接口http://hq.sinajs.cn/list=s_sh510300
- var hq_str_s_sh510300="300ETF,4.017,-0.004,-0.10,4368130,176618";
- var hq_str_s_sh510300=证券简称,最新价,涨跌额,涨跌幅,成交量,成交额
复制代码 7、期权隐含波动率,希腊字母等信息http://hq.sinajs.cn/list=CON_SO_10002180,结果示例如下
- var hq_str_CON_SO_10002180="300ETF沽6月3600,,,,4204,-0.0595,0.3455,-0.0312,0.3339,0.1549,0.0235,0.0192,
- 510300P2006M03600,3.6000,0.0235,0.0091,M";
- 各个字段意思
- 期权合约简称,,,,成交量,Delta,Gamma,Theta,Vega,隐含波动率,最高价,最低价,交易代码,行权价,最新价,理论价值
复制代码 8、期权分时线数据接口
https://stock.finance.sina.com.c ... bol=CON_OP_10002180
- {"result":{"status":{"code":0},"data":[
- {"i":"09:26:00","p":"0.0000","v":"0","t":"0","a":"0.0000","d":"2019-12-27"},{"i":"09:27:00","p":"0.0000","v":"0","t":"0","a":"0.0000"},
- {"i":"09:28:00","p":"0.0000","v":"0","t":"0","a":"0.0000"},{"i":"09:29:00","p":"0.0000","v":"0","t":"0","a":"0.0000"},
- {"i":"09:30:00","p":"0.0000","v":"0","t":"2247","a":"0.0000"},{"i":"09:31:00","p":"0.0000","v":"0","t":"2247","a":"0.0000"},
- {"i":"09:32:00","p":"0.0200","v":"0","t":"2247","a":"0.0200"},{"i":"09:33:00","p":"0.0200","v":"0","t":"2247","a":"0.0200"},
- {"i":"09:34:00","p":"0.0197","v":"0","t":"2269","a":"0.0196"},{"i":"09:35:00","p":"0.0198","v":"12","t":"2281","a":"0.0197"},
- {"i":"09:36:00","p":"0.0194","v":"66","t":"2324","a":"0.0197"},{"i":"09:37:00","p":"0.0194","v":"0","t":"2324","a":"0.0197"},
- {"i":"09:38:00","p":"0.0200","v":"6","t":"2330","a":"0.0197"},{"i":"09:39:00","p":"0.0200","v":"1","t":"2331","a":"0.0197"},
- 各字段意义:i时间,p价格,v成交,t持仓,a均价
复制代码 9、期权日K线数据接口
http://stock.finance.sina.com.cn ... bol=CON_OP_10002180
- /*<script>location.href='//sina.com';</script>*/
- ([{"d":"2019-12-23","o":"0.0310","h":"0.0378","l":"0.0218","c":"0.0307","v":"9546855"},
- {"d":"2019-12-24","o":"0.0312","h":"0.0312","l":"0.0243","c":"0.0252","v":"1379181"},
- {"d":"2019-12-25","o":"0.0249","h":"0.0276","l":"0.0234","c":"0.0252","v":"2920675"},
- {"d":"2019-12-26","o":"0.0252","h":"0.0252","l":"0.0210","c":"0.0210","v":"3132585"},
- {"d":"2019-12-27","o":"0.0200","h":"0.0235","l":"0.0192","c":"0.0235","v":"7747007"}]);
- 各字段意义:d日期,o开盘,h最高,l最低,c收盘,v成交
复制代码 10、期权最近5个交易日的分时线数据接口
https://stock.finance.sina.com.c ... bol=CON_OP_10002180
11、另外我还在js代码里发现了其它一些行情接口,与以上接口有些功能是重合的
http://hq.sinajs.cn/list=CON_ZL_10002122
这些接口可以一次传入多个参数来获取多条数据,多个参数用逗号连接,例如http://hq.sinajs.cn/list=CON_SO_10001585,CON_SO_10001727,CON_SO_10001619一次获取了3个合约的数据。
以下是我写的用于获取数据的python代码:
- # python3
- from json import loads
- from requests import get
- def get_option_dates(cate='50ETF', exchange='null'):
- url = f"http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName?" \
- f"exchange={exchange}&cate={cate}"
- dates = get(url).json()['result']['data']['contractMonth']
- return [''.join(i.split('-')) for i in dates][1:]
- def get_option_expire_day(date, cate='50ETF', exchange='null'):
- url = "http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay?" \
- "exchange={exchange}&cate={cate}&date={year}-{month}"
- url2 = url.format(year=date[:4], month=date[4:], cate=cate, exchange=exchange)
- data = get(url2).json()['result']['data']
- if int(data['remainderDays']) < 0:
- url2 = url.format(year=date[:4], month=date[4:], cate='XD' + cate, exchange=exchange)
- data = get(url2).json()['result']['data']
- return data['expireDay'], int(data['remainderDays'])
- def get_option_codes(date, underlying='510050'):
- url_up = ''.join(["http://hq.sinajs.cn/list=OP_UP_", underlying, str(date)[-4:]])
- url_down = ''.join(["http://hq.sinajs.cn/list=OP_DOWN_", underlying, str(date)[-4:]])
- data_up = str(get(url_up).content).replace('"', ',').split(',')
- codes_up = [i[7:] for i in data_up if i.startswith('CON_OP_')]
- data_down = str(get(url_down).content).replace('"', ',').split(',')
- codes_down = [i[7:] for i in data_down if i.startswith('CON_OP_')]
- return codes_up, codes_down
- def get_option_price(code):
- url = "http://hq.sinajs.cn/list=CON_OP_{code}".format(code=code)
- data = get(url).content.decode('gbk')
- data = data[data.find('"') + 1: data.rfind('"')].split(',')
- fields = ['买量', '买价', '最新价', '卖价', '卖量', '持仓量', '涨幅', '行权价', '昨收价', '开盘价', '涨停价',
- '跌停价', '申卖价五', '申卖量五', '申卖价四', '申卖量四', '申卖价三', '申卖量三', '申卖价二',
- '申卖量二', '申卖价一', '申卖量一', '申买价一', '申买量一 ', '申买价二', '申买量二', '申买价三',
- '申买量三', '申买价四', '申买量四', '申买价五', '申买量五', '行情时间', '主力合约标识', '状态码',
- '标的证券类型', '标的股票', '期权合约简称', '振幅', '最高价', '最低价', '成交量', '成交额',
- '分红调整标志', '昨结算价', '认购认沽标志', '到期日', '剩余天数', '虚实值标志', '内在价值', '时间价值']
- result = list(zip(fields, data))
- return result
- def get_underlying_security_price(code='sh510050'):
- url = "http://hq.sinajs.cn/list=" + code
- data = get(url).content.decode('gbk')
- data = data[data.find('"') + 1: data.rfind('"')].split(',')
- fields = ['证券简称', '今日开盘价', '昨日收盘价', '最近成交价', '最高成交价', '最低成交价', '买入价',
- '卖出价', '成交数量', '成交金额', '买数量一', '买价位一', '买数量二', '买价位二', '买数量三',
- '买价位三', '买数量四', '买价位四', '买数量五', '买价位五', '卖数量一', '卖价位一', '卖数量二',
- '卖价位二', '卖数量三', '卖价位三', '卖数量四', '卖价位四', '卖数量五', '卖价位五', '行情日期',
- '行情时间', '停牌状态']
- return list(zip(fields, data))
- def get_option_greek_alphabet(code):
- url = "http://hq.sinajs.cn/list=CON_SO_{code}".format(code=code)
- data = get(url).content.decode('gbk')
- data = data[data.find('"') + 1: data.rfind('"')].split(',')
- fields = ['期权合约简称', '成交量', 'Delta', 'Gamma', 'Theta', 'Vega', '隐含波动率', '最高价', '最低价',
- '交易代码', '行权价', '最新价', '理论价值']
- return list(zip(fields, [data[0]] + data[4:]))
- def get_option_time_line(code):
- url = f"https://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionDaylineService.getOptionMinline?" \
- f"symbol=CON_OP_{code}"
- data = get(url).json()['result']['data']
- return data
- def get_option_day_kline(code):
- url = f"http://stock.finance.sina.com.cn/futures/api/jsonp_v2.php//StockOptionDaylineService.getSymbolInfo?" \
- f"symbol=CON_OP_{code}"
- data = get(url).content
- data = loads(data[data.find(b'(') + 1: data.rfind(b')')])
- return data
- def my_test():
- dates = get_option_dates(cate='300ETF')
- print('期权合约月份:{}'.format(dates))
- for date in dates:
- print('期权月份{}:到期日{} 剩余天数{}'.format(date, *get_option_expire_day(date, cate='300ETF')))
- demo_code = '10002180'
- for date in dates:
- call_codes, put_codes = get_option_codes(date, underlying='510300')
- print('期权月份{} 看涨期权代码:{}\n期权月份{} 看跌期权代码:{}'.format(date, call_codes, date, put_codes))
- demo_code = call_codes[0]
- for index, i in enumerate(get_option_price(demo_code)):
- print('期权' + demo_code, index, *i)
- for index, i in enumerate(get_underlying_security_price(code='sh510300')):
- print(index, *i)
- for index, i in enumerate(get_option_greek_alphabet(demo_code)):
- print('期权' + demo_code, index, *i)
- time_line = get_option_time_line(demo_code)
- for i in time_line[-10:]:
- print('时间:{i}, 价格:{p}, 成交:{v}, 持仓:{t}, 均价:{a}'.format(**i))
- day_kline = get_option_day_kline(demo_code)
- for i in day_kline:
- print('日期:{d}, 开盘:{o}, 最高:{h}, 最低:{l}, 收盘:{c}, 成交:{v}'.format(**i))
- if __name__ == '__main__':
- my_test()
复制代码 程序运行的结果:
- 期权合约月份:['202001', '202002', '202003', '202006']
- 期权月份202001:到期日2020-01-22 剩余天数15
- 期权月份202002:到期日2020-02-26 剩余天数50
- 期权月份202003:到期日2020-03-25 剩余天数78
- 期权月份202006:到期日2020-06-24 剩余天数169
- 期权月份202001 看涨期权代码:['10002117', '10002118', '10002119', '10002120', '10002121', '10002122', '10002123', '10002124', '10002125', '10002215']
- 期权月份202001 看跌期权代码:['10002126', '10002127', '10002128', '10002129', '10002130', '10002131', '10002132', '10002133', '10002134', '10002216']
- 期权月份202002 看涨期权代码:['10002135', '10002136', '10002137', '10002138', '10002139', '10002140', '10002141', '10002142', '10002143', '10002217']
- 期权月份202002 看跌期权代码:['10002144', '10002145', '10002146', '10002147', '10002148', '10002149', '10002150', '10002151', '10002152', '10002218']
- 期权月份202003 看涨期权代码:['10002153', '10002154', '10002155', '10002156', '10002157', '10002158', '10002159', '10002160', '10002161', '10002219']
- 期权月份202003 看跌期权代码:['10002162', '10002163', '10002164', '10002165', '10002166', '10002167', '10002168', '10002169', '10002170', '10002220']
- 期权月份202006 看涨期权代码:['10002171', '10002172', '10002173', '10002174', '10002175', '10002176', '10002177', '10002178', '10002179', '10002221']
- 期权月份202006 看跌期权代码:['10002180', '10002181', '10002182', '10002183', '10002184', '10002185', '10002186', '10002187', '10002188', '10002222']
- 期权10002171 0 买量 2
- 期权10002171 1 买价 0.6200
- 期权10002171 2 最新价 0.6330
- 期权10002171 3 卖价 0.6428
- 期权10002171 4 卖量 1
- 期权10002171 5 持仓量 3465
- 期权10002171 6 涨幅 -2.69
- 期权10002171 7 行权价 3.6000
- 期权10002171 8 昨收价 0.6505
- 期权10002171 9 开盘价 0.6300
- 期权10002171 10 涨停价 1.0644
- 期权10002171 11 跌停价 0.2366
- 期权10002171 12 申卖价五 0.6817
- 期权10002171 13 申卖量五 1
- 期权10002171 14 申卖价四 0.6798
- 期权10002171 15 申卖量四 1
- 期权10002171 16 申卖价三 0.6729
- 期权10002171 17 申卖量三 1
- 期权10002171 18 申卖价二 0.6500
- 期权10002171 19 申卖量二 1
- 期权10002171 20 申卖价一 0.6428
- 期权10002171 21 申卖量一 1
- 期权10002171 22 申买价一 0.6200
- 期权10002171 23 申买量一 2
- 期权10002171 24 申买价二 0.6009
- 期权10002171 25 申买量二 1
- 期权10002171 26 申买价三 0.5936
- 期权10002171 27 申买量三 5
- 期权10002171 28 申买价四 0.5900
- 期权10002171 29 申买量四 1
- 期权10002171 30 申买价五 0.5877
- 期权10002171 31 申买量五 1
- 期权10002171 32 行情时间 2020-01-06 15:00:00
- 期权10002171 33 主力合约标识 0
- 期权10002171 34 状态码 E 01
- 期权10002171 35 标的证券类型 EBS
- 期权10002171 36 标的股票 510300
- 期权10002171 37 期权合约简称 300ETF购6月3600
- 期权10002171 38 振幅 10.33
- 期权10002171 39 最高价 0.6799
- 期权10002171 40 最低价 0.6127
- 期权10002171 41 成交量 488
- 期权10002171 42 成交额 3184024.00
- 0 证券简称 300ETF
- 1 今日开盘价 4.126
- 2 昨日收盘价 4.139
- 3 最近成交价 4.123
- 4 最高成交价 4.171
- 5 最低成交价 4.094
- 6 买入价 4.124
- 7 卖出价 4.125
- 8 成交数量 666504783
- 9 成交金额 2760524448.000
- 10 买数量一 15200
- 11 买价位一 4.124
- 12 买数量二 59100
- 13 买价位二 4.123
- 14 买数量三 656200
- 15 买价位三 4.122
- 16 买数量四 77800
- 17 买价位四 4.121
- 18 买数量五 278800
- 19 买价位五 4.120
- 20 卖数量一 40600
- 21 卖价位一 4.125
- 22 卖数量二 19700
- 23 卖价位二 4.126
- 24 卖数量三 663100
- 25 卖价位三 4.127
- 26 卖数量四 301600
- 27 卖价位四 4.128
- 28 卖数量五 213300
- 29 卖价位五 4.129
- 30 行情日期 2020-01-06
- 31 行情时间 15:00:00
- 32 停牌状态 00
- 期权10002171 0 期权合约简称 300ETF购6月3600
- 期权10002171 1 成交量 488
- 期权10002171 2 Delta 0.9693
- 期权10002171 3 Gamma 0.1992
- 期权10002171 4 Theta -0.162
- 期权10002171 5 Vega 0.1949
- 期权10002171 6 隐含波动率 0.2173
- 期权10002171 7 最高价 0.6799
- 期权10002171 8 最低价 0.6127
- 期权10002171 9 交易代码 510300C2006M03600
- 期权10002171 10 行权价 3.6000
- 期权10002171 11 最新价 0.6330
- 期权10002171 12 理论价值 0.5937
- 时间:14:51:00, 价格:0.6404, 成交:3, 持仓:3464, 均价:0.6526
- 时间:14:52:00, 价格:0.6400, 成交:0, 持仓:3463, 均价:0.6525
- 时间:14:53:00, 价格:0.6400, 成交:0, 持仓:3463, 均价:0.6525
- 时间:14:54:00, 价格:0.6400, 成交:0, 持仓:3463, 均价:0.6525
- 时间:14:55:00, 价格:0.6400, 成交:1, 持仓:3464, 均价:0.6525
- 时间:14:56:00, 价格:0.6400, 成交:0, 持仓:3464, 均价:0.6525
- 时间:14:57:00, 价格:0.6400, 成交:0, 持仓:3464, 均价:0.6525
- 时间:14:58:00, 价格:0.6400, 成交:0, 持仓:0, 均价:0.6525
- 时间:14:59:00, 价格:0.6400, 成交:0, 持仓:0, 均价:0.6525
- 时间:15:00:00, 价格:0.6330, 成交:1, 持仓:3465, 均价:0.6525
- 日期:2019-12-23, 开盘:0.5142, 最高:0.5984, 最低:0.4677, 收盘:0.4726, 成交:8571737
- 日期:2019-12-24, 开盘:0.4631, 最高:0.4936, 最低:0.4631, 收盘:0.4889, 成交:297199
- 日期:2019-12-25, 开盘:0.4825, 最高:0.4990, 最低:0.4800, 收盘:0.4925, 成交:339024
- 日期:2019-12-26, 开盘:0.5005, 最高:0.5225, 最低:0.4985, 收盘:0.5220, 成交:1109657
- 日期:2019-12-27, 开盘:0.5230, 最高:0.5676, 最低:0.5230, 收盘:0.5284, 成交:2176759
- 日期:2019-12-30, 开盘:0.5280, 最高:0.5936, 最低:0.5100, 收盘:0.5862, 成交:2030851
- 日期:2019-12-31, 开盘:0.5919, 最高:0.6060, 最低:0.5729, 收盘:0.6019, 成交:494130
- 日期:2020-01-02, 开盘:0.6254, 最高:0.6832, 最低:0.6254, 收盘:0.6582, 成交:1594542
- 日期:2020-01-03, 开盘:0.6737, 最高:0.6737, 最低:0.6500, 收盘:0.6505, 成交:787486
- 日期:2020-01-06, 开盘:0.6300, 最高:0.6799, 最低:0.6127, 收盘:0.6330, 成交:1658548
复制代码 另外我用以上接口写了一个画期权隐含波动率曲面(和标的历史波动率)的程序,能够随着行情变化动态更新。见https://blog.csdn.net/u013781175/article/details/88628844
新浪财经沪深300指数期权和商品期权的接口见https://blog.csdn.net/u013781175/article/details/88564280
东方财富期权行情接口https://blog.csdn.net/u013781175/article/details/90315476
陆子野 发布了15 篇原创文章 · 获赞 13 · 访问量 4万+ 私信 关注
|
|