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对两个有序列表进行合并和排序的例子
Jun 13 Python
python使用PyGame绘制图像并保存为图片文件的方法
Apr 24 Python
Python实现针对中文排序的方法
May 09 Python
python写入并获取剪切板内容的实例
May 31 Python
详解基于django实现的webssh简单例子
Jul 17 Python
Django+uni-app实现数据通信中的请求跨域的示例代码
Oct 12 Python
python爬取王者荣耀全皮肤的简单实现代码
Jan 31 Python
python如何删除文件、目录
Jun 23 Python
理解Django 中Call Stack机制的小Demo
Sep 01 Python
python 如何上传包到pypi
Dec 24 Python
详解tf.device()指定tensorflow运行的GPU或CPU设备实现
Feb 20 Python
Python 机器学习工具包SKlearn的安装与使用
May 14 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编程效率 引入缓存机制提升性能
2010/02/15 PHP
在Win7 中为php扩展配置Xcache
2014/10/08 PHP
PHP+Mysql+Ajax实现淘宝客服或阿里旺旺聊天功能(前台页面)
2017/06/16 PHP
判断脚本加载是否完成的方法
2009/05/26 Javascript
Tips 带三角可关闭的文字提示
2010/10/06 Javascript
JavaScript实现在页面间传值的方法
2015/04/07 Javascript
如何写好你的JavaScript【推荐】
2017/03/02 Javascript
Javarscript中模块(module)、加载(load)与捆绑(bundle)详解
2017/05/28 Javascript
NodeJs实现简易WEB上传下载服务器
2019/08/10 NodeJs
在layui中layer弹出层点击事件无效的解决方法
2019/09/05 Javascript
layui的布局和表格的渲染以及动态生成表格的方法
2019/09/18 Javascript
微信小程序点击view动态添加样式过程解析
2020/01/21 Javascript
JavaScript实现拖拽盒子效果
2020/02/06 Javascript
微信小程序实现点击生成随机验证码
2020/09/09 Javascript
OpenLayers3实现对地图的基本操作
2020/09/28 Javascript
跟老齐学Python之玩转字符串(2)
2014/09/14 Python
Python and、or以及and-or语法总结
2015/04/14 Python
Python实现矩阵加法和乘法的方法分析
2017/12/19 Python
Python类的继承和多态代码详解
2017/12/27 Python
Python3实现的字典遍历操作详解
2018/04/18 Python
解决python3读取Python2存储的pickle文件问题
2018/10/25 Python
python生成lmdb格式的文件实例
2018/11/08 Python
通过实例解析python subprocess模块原理及用法
2020/10/10 Python
eDreams巴西:廉价机票,酒店优惠和度假套餐
2017/04/14 全球购物
英国第一的购买便宜玩具和游戏的在线购物网站:Bargain Max
2018/01/24 全球购物
新英格兰最大的特色礼品连锁店:The Paper Store
2018/07/23 全球购物
俄罗斯达美乐比萨外送服务:Domino’s Pizza
2020/12/18 全球购物
大学生专科毕业生自我评价
2013/11/17 职场文书
技能比赛获奖感言
2014/02/14 职场文书
化妆品促销方案
2014/02/24 职场文书
医学院毕业生自荐信范文
2014/03/06 职场文书
企业总经理任命书
2014/06/05 职场文书
教师批评与自我批评心得体会
2014/10/16 职场文书
如何用 Python 子进程关闭 Excel 自动化中的弹窗
2021/05/07 Python
以MySQL5.7为例了解一下执行计划
2022/04/13 MySQL
使用Django框架创建项目
2022/06/10 Python