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 数据加密代码
Dec 24 Python
Python实现的下载8000首儿歌的代码分享
Nov 21 Python
Python中使用HTMLParser解析html实例
Feb 08 Python
利用Python批量生成任意尺寸的图片
Aug 29 Python
Python实现购物车功能的方法分析
Nov 10 Python
numpy排序与集合运算用法示例
Dec 15 Python
在pycharm 中添加运行参数的操作方法
Jan 19 Python
浅谈Python中函数的定义及其调用方法
Jul 19 Python
Python进阶之使用selenium爬取淘宝商品信息功能示例
Sep 16 Python
Django密码存储策略分析
Jan 09 Python
python mock测试的示例
Oct 19 Python
Python装饰器详细介绍
Mar 25 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
基于php设计模式中工厂模式详细介绍
2013/05/15 PHP
php如何解决无法上传大于8M的文件问题
2014/03/10 PHP
PHP中使用hidef扩展代替define提高性能
2015/04/09 PHP
PHP文件管理之实现网盘及压缩包的功能操作
2017/09/20 PHP
利用PHP扩展Xhprof分析项目性能实践教程
2018/09/05 PHP
Thinkphp5.0框架的Db操作实例分析【连接、增删改查、链式操作等】
2019/10/11 PHP
Nigma vs Alliance BO5 第一场2.14
2021/03/10 DOTA
formStorage 基于jquery的一个插件(存储表单中元素的状态到本地)
2012/01/20 Javascript
JavaScript截取字符串的2个函数介绍
2014/08/27 Javascript
ion content 滚动到底部会遮住一部分视图的快速解决方法
2016/09/06 Javascript
Bootstrap提示框效果的实例代码
2017/07/12 Javascript
Vue中之nextTick函数源码分析详解
2017/10/17 Javascript
Vue-Access-Control 前端用户权限控制解决方案
2017/12/01 Javascript
AngularJS动态添加数据并删除的实例
2018/02/27 Javascript
jQuery实现的点击按钮改变样式功能示例
2018/07/21 jQuery
详解微信小程序框架wepy踩坑记录(与vue对比)
2019/03/12 Javascript
jQuery中使用validate插件校验表单功能
2019/05/24 jQuery
细说Vue组件的服务器端渲染的过程
2019/05/30 Javascript
vue iview的菜单组件Mune 点击不高亮的解决方案
2019/11/01 Javascript
vue-resourc发起异步请求的方法
2020/02/11 Javascript
extjs4图表绘制之折线图实现方法分析
2020/03/06 Javascript
Python复制文件操作实例详解
2015/11/10 Python
CentOS7下python3.7.0安装教程
2018/07/30 Python
浅析Python与Mongodb数据库之间的操作方法
2019/07/01 Python
Python with关键字,上下文管理器,@contextmanager文件操作示例
2019/10/17 Python
Python连接Hadoop数据中遇到的各种坑(汇总)
2020/04/14 Python
解决HTML5中的audio在手机端和微信端的不能自动播放问题
2019/11/04 HTML / CSS
俄罗斯首家面向中国消费者的一站式购物网站:Wruru
2020/05/08 全球购物
应聘教师推荐信
2013/10/31 职场文书
就业推荐表自我鉴定范文
2014/03/21 职场文书
求职信范文大全
2014/05/26 职场文书
办公室个人总结
2015/02/28 职场文书
2015年人事科工作总结
2015/04/28 职场文书
读《方与圆》有感:交友方圆有度
2020/01/14 职场文书
如何用Navicat操作MySQL
2021/05/12 MySQL
为什么MySQL选择Repeatable Read作为默认隔离级别
2021/07/26 MySQL