Python的净值数据接口调用示例分享


Posted in Python onMarch 15, 2016

代码描述:基于Python的净值数据接口调用代码实例
关联数据:净值数据
接口地址:https://www.juhe.cn/docs/api/id/25

#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, urllib
from urllib import urlencode

#----------------------------------
# 净值数据调用示例代码 - 聚合数据
# 在线接口文档:http://www.juhe.cn/docs/25
#----------------------------------

def main():

  #配置您申请的APPKey
  appkey = "*********************"

  #1.全部开放基金
  request1(appkey,"GET")

  #2.股票型基金
  request2(appkey,"GET")

  #3.普通债券型基金
  request3(appkey,"GET")

  #4.货币型基金
  request4(appkey,"GET")

  #5.封闭型基金
  request5(appkey,"GET")
 
  #6.创新封基
  request6(appkey,"GET")

  #7.LOF
  request7(appkey,"GET")

  #8.ETF
  request8(appkey,"GET")

  #9.QDII
  request9(appkey,"GET")

#全部开放基金
def request1(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/all"
  params = {
    "key" : appkey, #APPKEY值

  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#股票型基金
def request2(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/stock"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#普通债券型基金
def request3(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/bond"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#货币型基金
def request4(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/monet"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#封闭型基金
def request5(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/close"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#创新封基
def request6(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/innov"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#LOF
def request7(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/lof"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#ETF
def request8(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/etf"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"
 
#QDII
def request9(appkey, m="GET"):
  url = "http://web.juhe.cn:8080/fund/netdata/qdii"
  params = {
    "key" : appkey, #APPKEY值
 
  }
  params = urlencode(params)
  if m =="GET":
    f = urllib.urlopen("%s?%s" % (url, params))
  else:
    f = urllib.urlopen(url, params)
 
  content = f.read()
  res = json.loads(content)
  if res:
    error_code = res["error_code"]
    if error_code == 0:
      #成功请求
      print res["result"]
    else:
      print "%s:%s" % (res["error_code"],res["reason"])
  else:
    print "request api error"

if __name__ == '__main__':
  main()
Python 相关文章推荐
python验证码识别的实例详解
Sep 09 Python
CentOS下使用yum安装python-pip失败的完美解决方法
Aug 16 Python
Python set常用操作函数集锦
Nov 15 Python
解决Python3中的中文字符编码的问题
Jul 18 Python
python 自定义异常和异常捕捉的方法
Oct 18 Python
python3对拉勾数据进行可视化分析的方法详解
Apr 03 Python
在PyCharm的 Terminal(终端)切换Python版本的方法
Aug 02 Python
python+selenium 点击单选框-radio的实现方法
Sep 03 Python
Python倒排索引之查找包含某主题或单词的文件
Nov 13 Python
Python list运算操作代码实例解析
Jan 20 Python
2020最新pycharm汉化安装(python工程狮亲测有效)
Apr 26 Python
Python 使用 Frame tkraise() 方法在 Tkinter 应用程序中的Frame之间切换
Apr 24 Python
Python简单连接MongoDB数据库的方法
Mar 15 #Python
Python函数中的函数(闭包)用法实例
Mar 15 #Python
实例讲解Python中函数的调用与定义
Mar 14 #Python
Python使用multiprocessing实现一个最简单的分布式作业调度系统
Mar 14 #Python
简单讲解Python中的字符串与字符串的输入输出
Mar 13 #Python
深入解析Python中的list列表及其切片和迭代操作
Mar 13 #Python
Python中的列表生成式与生成器学习教程
Mar 13 #Python
You might like
Zend Studio for Eclipse的java.lang.NullPointerException错误的解决方法
2008/12/06 PHP
PHP自动生成后台导航网址的最佳方法
2013/08/27 PHP
php使用memcoder将视频转成mp4格式的方法
2015/03/12 PHP
PHP实现微信申请退款功能
2018/10/01 PHP
php数组和链表的区别总结
2019/09/20 PHP
laravel 之 Eloquent 模型修改器和序列化示例
2019/10/17 PHP
js 完美图片新闻轮转效果,腾讯大粤网首页图片轮转改造而来
2011/11/21 Javascript
用js实现in_array的方法
2013/11/05 Javascript
JavaScript禁止页面操作的示例代码
2013/12/17 Javascript
jQuery position() 函数详解以及jQuery中position函数的应用
2015/12/14 Javascript
jQuery日历插件datepicker用法详解
2016/03/03 Javascript
JS中对数组元素进行增删改移的方法总结
2016/12/15 Javascript
浅谈js中同名函数和同名变量的执行问题
2017/02/12 Javascript
js中setTimeout的妙用--防止循环超时
2017/03/06 Javascript
简单实现jQuery上传图片显示预览功能
2020/06/29 jQuery
vue中使用refs定位dom出现undefined的解决方法
2017/12/21 Javascript
Vue render深入开发讲解
2018/04/13 Javascript
js 图片转base64的方式(两种)
2018/04/24 Javascript
vue-router的hooks用法详解
2020/06/08 Javascript
基于element-ui对话框el-dialog初始化的校验问题解决
2020/09/11 Javascript
[47:42]Fnatic vs Liquid 2018国际邀请赛小组赛BO2 第一场 8.16
2018/08/17 DOTA
[01:32]完美世界DOTA2联赛10月29日精彩集锦
2020/10/30 DOTA
Python脚本实现下载合并SAE日志
2015/02/10 Python
python清除字符串里非数字字符的方法
2015/07/02 Python
在django中使用自定义标签实现分页功能
2017/07/04 Python
python中for循环输出列表索引与对应的值方法
2018/11/07 Python
如何使用Python脚本实现文件拷贝
2019/11/20 Python
flask 使用 flask_apscheduler 做定时循环任务的实现
2019/12/10 Python
Python如何批量获取文件夹的大小并保存
2020/03/31 Python
德国大型和小型家用电器网上商店:Energeto
2019/05/15 全球购物
教师绩效考核方案
2014/01/21 职场文书
高中生物教学反思
2014/02/05 职场文书
公证委托书大全
2014/04/04 职场文书
井冈山红色之旅心得体会
2014/10/07 职场文书
银行培训心得体会范文
2016/01/09 职场文书
css3实现背景图片半透明内容不透明的方法示例
2021/04/13 HTML / CSS