新浪的股票接口 c#

需要注意的这个只是获取单只股票

 代码的用处,通过这个代码有炒股的朋友就可以写出简单的自动止损和按一定价格入场的程序了。(国内正规券商不支持这种功能,可能是为了防止一些东西。)

我们先来看一下股票信息的类

 namespace Qianfa.net.Library.Entity
{
    /*http://hq.sinajs.cn/list=sh600066  sh上海 sz深圳
     * 0:”大秦铁路”,股票名字;
   1:”27.55″,今日开盘价;
   2:”27.25″,昨日收盘价;
   3:”26.91″,当前价格;//时间结束后也就是收盘价了
   4:”27.55″,今日最高价;
   5:”26.20″,今日最低价;
   6:”26.91″,竞买价,即“买一”报价;
   7:”26.92″,竞卖价,即“卖一”报价;
   8:”22114263″,成交的股票数,由于股票交易以一百股为基本单位,所以在使用时,通常把该值除以一百;
   9:”589824680″,成交金额,单位为“元”,为了一目了然,通常以“万元”为成交金额的单位,所以通常把该值除以一万;
   10:”4695″,“买一”申请4695股,即47手;
   11:”26.91″,“买一”报价;
   12:”57590″,“买二”
   13:”26.90″,“买二”
   14:”14700″,“买三”
   15:”26.89″,“买三”
   16:”14300″,“买四”
   17:”26.88″,“买四”
   18:”15100″,“买五”
   19:”26.87″,“买五”
   20:”3100″,“卖一”申报3100股,即31手;
   21:”26.92″,“卖一”报价
   (22, 23), (24, 25), (26,27), (28, 29)分别为“卖二”至“卖四的情况”
   30:”2008-01-11″,日期;
   31:”15:05:32″,时间;
   */
    public class StockInfo
    {
        public string Name
        {
            get;
            set;
        }

        public decimal TodayOpen
        {
            get;
            set;
        }

        public decimal YesterdayClose
        {
            get;
            set;
        }

        public decimal Current
        {
            get;
            set;
        }

        public decimal High
        {
            get;
            set;
        }

        public decimal Low
        { get; set; }

        /// <summary>
        /// 竟买价 买1
        /// </summary>
        public decimal Buy
        { get; set; }

        /// <summary>
        /// 竟卖价 卖1
        /// </summary>
        public decimal Sell { get; set; }

        /// <summary>
        /// 成交数 单位股数 通常除于100成为手
        /// </summary>
        public int VolAmount { get; set; }

        /// <summary>
        /// 成交多少钱,单位元
        /// </summary>
        public decimal VolMoney { get; set; }

        /// <summary>
        /// 新浪是可以看到5个,5档看盘 ,买1-买5
        /// </summary>
        public List<GoodsInfo> BuyList { get; set; }

        /// <summary>
        /// 卖1-卖5
        /// </summary>
        public List<GoodsInfo> SellList { get; set; }

        /// <summary>
        /// Date and Time
        /// </summary>
        public DateTime Time { get; set; }

        public override string ToString()
        {
            return Name + ": " + VolAmount + ":" + Current;
        }
       
    }

/*现在爬文章的很多,原文在http://www.cnblogs.com/lovebanyi/archive/2010/05/02/1725874.html */
}

 

 

namespace Qianfa.net.Library
{

///股票数据获取接口,你可以自己实现新浪yahoo...
    public interface IDataService
    {
         StockInfo GetCurrent(string stockCode);   
    }
}

 

namespace Qianfa.net.DataServices
{
    public class Sina : IDataService
    {

        private const string dataurl = "http://hq.sinajs.cn/list=%7B0}";
        #region IStockInfo Members
        HttpClient client;
        private StockInfo PrevInfo;
        public StockInfo GetCurrent(string stockCode)
        {
            try
            {
                if (client == null)
                {
                    client = new HttpClient();
                }
                if (stockCode.Substring(0, 2) == "60")//上海是600打头
                {
                    stockCode = "sh" + stockCode;
                }
                else if(stockCode.Substring(0,2)=="00")//深圳
                {
                    stockCode = "sz" + stockCode;
                }
                else if (stockCode.Substring(0, 2) == "51")//上海基金
                {
                    stockCode = "sh" + stockCode;
                }
                string url = string.Format(dataurl, stockCode);
                string data = client.DownloadString(string.Format(url, stockCode));
                PrevInfo = Parse(data);
                return PrevInfo;
            }
            catch
            {
                return PrevInfo;
            }
           
        }

        /// <summary>
        /// Parse Sina data to stock Info
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static StockInfo Parse(string content)
        {
           // var hq_str_sh600066 = "宇通客车,9.27,9.35,9.76,9.80,9.27,9.77,9.78,4567858,44306952,3100,9.77,1200,9.76,20500,9.75,1400,9.74,15300,9.73,10030,9.78,28093,9.79,156827,9.80,2800,9.81,6400,9.82,2009-01-09,15:03:32";
            int start = content.IndexOf('"')+1;
            int end = content.IndexOf('"',start);
            string input = content.Substring(start, end - start);
            string[] temp = input.Split(',');
            if (temp.Length != 32)
            {
                return null;
            }
            StockInfo info = new StockInfo();
            info.Name = temp[0];
            info.TodayOpen = decimal.Parse(temp[1]);
            info.YesterdayClose = decimal.Parse(temp[2]);
            info.Current = decimal.Parse(temp[3]);
            info.High = decimal.Parse(temp[4]);
            info.Low = decimal.Parse(temp[5]);
            info.Buy = decimal.Parse(temp[6]);
            info.Sell = decimal.Parse(temp[7]);
            info.VolAmount = int.Parse(temp[8]);
            info.VolMoney = decimal.Parse(temp[9]);
            info.BuyList = new List<GoodsInfo>(5);
            int index = 10;
            for (int i = 0; i < 5; i++)
            {
                GoodsInfo goods = new GoodsInfo();
                goods.State = GoodsState.Buy;
                goods.Amount = int.Parse(temp[index]);
                index++;
                goods.Price = decimal.Parse(temp[index]);
                index++;
                info.BuyList.Add(goods);
            }
            info.SellList = new List<GoodsInfo>(5);

            for (int i = 0; i < 5; i++)
            {
                GoodsInfo goods = new GoodsInfo();
                goods.State = GoodsState.Sell;
                goods.Amount = int.Parse(temp[index]);
                index++;
                goods.Price = decimal.Parse(temp[index]);
                index++;
                info.SellList.Add(goods);
            }
            info.Time = DateTime.Parse(temp[30] + " " + temp[31]);
            return info;

        }

        #endregion
    }
}

 

 
    public class GoodsInfo
    {
        public int Amount
        { get; set; }
        public decimal Price
        {
            get;
            set;
        }
        public GoodsState State { get; set; }
    }

 如果你想要商业类型的股票接口可以可以跟我联系哦。

http://www.qianfa.net/StockInfoSoft.aspx

转载于:https://www.cnblogs.com/lovebanyi/archive/2010/05/02/1725874.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/411057.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.data()与.detach()的区别

.data()和.detach()都可以获取Variable内部的Tensor&#xff0c;但.detach()更加安全 https://zhuanlan.zhihu.com/p/38475183 转载于:https://www.cnblogs.com/Manuel/p/11077202.html

[html] 直接使用b标签和使用css的font-weight有什么区别?

[html] 直接使用b标签和使用css的font-weight有什么区别&#xff1f; HTML 的标签负责将内容标记为 HTML 元素&#xff0c;浏览器的默认 CSS 样式表负责按照 W3C 的建议来指定 HTML 元素的默认样式。 可以这样理解&#xff0c;使用 b 标签标记的内容浏览器会使用相应的默认 CS…

Flash/Flex学习笔记(47):反向运动学(上)

先回顾上篇所说的"正向运动学"&#xff1a;以人行走的例子来说&#xff0c;基本上可以理解为大腿驱动小腿&#xff0c;小腿驱动脚&#xff0c;从而引发的一系列姿态调整和运动。再举一个例子&#xff0c;我们用着拿一根软鞭或链条的一端挥舞&#xff0c;被手挥舞的这…

java pojo 转 map_JSON和JAVA的POJO的相互转换

正在做一个进销存的项目&#xff0c;为了JSON和JAVA的POJO之间转换&#xff0c;很费劲啊&#xff0c;上传&#xff0c;以备以后有用&#xff01;importjava.util.Collection;importjava.util.HashMap;importjava.util.Map;importnet.sf.json.JSONArray;importnet.sf.json.JSONO…

[html] 说说你对abbr标签的理解,它有什么含义?

[html] 说说你对abbr标签的理解&#xff0c;它有什么含义&#xff1f; 缩略词个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

静,动态数组总结

本文转自万一老师的博客 原文出处: http://www.cnblogs.com/del/category/114641.html静态数组的定义方法: //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<&l…

java tomcat jms_JavaWeb之使用Tomcat、JNDI与ActiveMQ实现JMS消息通信服务

前言之所以使用JNDI 是出于通用性考虑&#xff0c;该例子使用JMS规范提供的通用接口&#xff0c;没有使用具体JMS提供者的接口&#xff0c;这样可以保证我们编写的程序适用于任何一种JMS实现(ActiveMQ、HornetQ等)。什么是JNDI&#xff1a;JNDI(Java Naming and Directory Inte…

[html] HTML5的触屏事件有哪些?

[html] HTML5的触屏事件有哪些&#xff1f; touchstart 触摸开始 touchmove 接触点移动&#xff08;手指不离开屏幕&#xff09; touchend 触摸结束 touchcancel 触摸被取消个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很…

你是第几名:Excel 中 Large 和 Small 的用法

类似于 SQL 语言中的 TOP X, Large 和Small 有2个参数 Large(Array,k) Array 可以为一个单元格区域&#xff0c;k 为第k各最大值&#xff0c;Small 与之对应返回第k个最小值。 注意&#xff1a;单元格区域中的非数字会被忽略掉。 例子如下&#xff1a; 可以类比Rank的用法&…

mac系统下android studio创建手机模拟器

打开android studio&#xff0c;点击右上角的模拟器图标&#xff0c;打开“Android Virtual Device Manager” 窗口&#xff0c;如下图 点击“Create Virtual Device”&#xff0c;在打开的设备定义列表中&#xff0c;选择“Phone -> Nexus 5X”&#xff0c;右边列出了改机型…

java wait 参数_Java sleep()和wait()的区别

一、什么是sleep()?sleep()是Thread类的方法&#xff0c;导致线程暂停执行的时间&#xff0c;给其他线程执行机会&#xff0c;但是依然保持监控状态&#xff0c;过了指定时间会自动恢复执行&#xff0c;调用sleep()方法不会释放锁对象。当调用sleep()方法后&#xff0c;当前线…

[html]html实现页面跳转都有哪些方法?

[html]html实现页面跳转都有哪些方法&#xff1f; 创建A标签跳转location.hrefform submit<meta http-equiv"refresh" content"5;urlother.html">window.history个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c…

如何设置Hyper-V的虚拟机快捷方式

在Windows Server 2008中&#xff0c;提供的Hyper-V功能&#xff0c;可以很方便地在企业环境中部署多个虚拟机&#xff0c;以适应不同的开发需要。一般我们都是通过下面的方式 1. 打开服务器管理器 2.打开Hyper-V管理器&#xff0c;找到有关的虚拟机&#xff0c;然后右键点击“…

使用 keytool 生成安卓应用程序签名

下载 keytool jar包&#xff1b; 解压jar包到固定目录 如&#xff1a; cd /Library/Java/JavaVirtualMachines/ 进入到jar包目录: cd /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home 输入keytool&#xff0c;可以查看各种命令。 执行&#xff1a; keytool -…

java 音频对比_java – 比较两个不同的音频文件不起作用

我想比较两个音频文件,例如mp3和wav.我使用musicg来比较指纹.Wave record1 new Wave(music1.toString());Wave record2 new Wave(music2.toString());FingerprintSimilarity Similarityrecord1.getFingerprintSimilarity(record2);System.out.println(Similarity.getSimilari…

[html] 如何在页面引用外部的html页面?

[html] 如何在页面引用外部的html页面&#xff1f; 1.是完整的页面。拥有header&#xff0c;body。使用<iframe> 2.是一个页面片段。使用get请求。或者使用<link ref"import" href"some.html">个人简介 我是歌谣&#xff0c;欢迎和大家一起交…

解析C#中is和as操作符的用法 two

c# 中 is和as 操作符是用来进行强制类型转换的 is : 检查一个对象是否兼容于其他指定的类型,并返回一个Bool值,永远不会抛出异常 objecto newobject(); if(o isLabel) { Label lb (Label)o; Response.Write("类型转换成功"); } else{ …

java跨函数跳转_VS code 函数无法跨文件跳转到定义

现状&#xff1a;本文件函数通过this打点调用的函数&#xff0c;引入绝对路径的文件&#xff0c;调用的函数都可以通过Ctrl 点击 实现跳转到定义处。而如果在 webpack 通过alias 设置了别名&#xff0c;无法跳转成功。解决方案: 新建文件 jsconfig.json&#xff0c;配置如下。…

uname命令

uname命令用于打印当前系统相关信息&#xff08;内核版本号、硬件架构、主机名称和操作系统类型等&#xff09;。 语法 uname(选项) 选项 -a或--all&#xff1a;显示全部的信息&#xff1b; -m或--machine&#xff1a;显示电脑类型&#xff1b; -n或-nodename&#xff1a;显示在…