教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 范文大全 > 经典范文 >

雅虎和新浪股票接口调用方法收集(2)

来源:网络收集 时间:2026-09-15
导读: $result = [RegEx]::matches($content, $reg) foreach($item in $result) { $date = $item.Groups[1].Value # 时间 $opening = $item.Groups[2].Value # 开盘 $maxHigh = $item.Groups[3].Value # 最高 $closing =

$result = [RegEx]::matches($content, $reg)

foreach($item in $result)

{

$date = $item.Groups[1].Value # 时间

$opening = $item.Groups[2].Value # 开盘

$maxHigh = $item.Groups[3].Value # 最高

$closing = $item.Groups[4].Value # 收盘

$maxLow = $item.Groups[5].Value # 最低

Write-Host $date $opening $maxHigh $closing $maxLow

}

第二篇范文:C# Sina股票接口

C# Sina股票接口

(2011-01-25 14:05:52)

转载

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

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

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

namespace Qianfa.net.Library.Entity

{

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;

}

}

}

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={0}";

#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;

…… 此处隐藏:1411字,全部文档内容请下载后查看。喜欢就下载吧 ……
雅虎和新浪股票接口调用方法收集(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/fanwen/17135.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)