股票api的调用,前端怎么调用api接口股票的api

扫码关注“i财富”微信基于C#的股票数据api调用代码实例 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 10时,
代码描述:基于C#的股票数据api调用代码实例关联数据:股票数据接口地址:/docs/api/id/21
代码片段(1)
1.&[代码][C#]代码&&&&
using System.Collections.G
using System.L
using System.T
using System.N
using System.IO;
using Xfrog.N
using System.D
using System.W
//----------------------------------
// 股票数据调用示例代码 - 聚合数据
// 在线接口文档:/docs/21
// 代码中JsonObject类下载地址:http://download.csdn.net/download/gcm5/7458439
//----------------------------------
namespace ConsoleAPI
class Program
static void Main(string[] args)
string appkey = "*******************"; //配置您申请的appkey
//1.沪深股市
string url1 = ":8080/finance/stock/hs";
var parameters1 = new Dictionary&string, string&();
parameters1.Add("gid" , ""); //股票编号,上海股市以sh开头,深圳股市以sz开头如:sh601009
parameters1.Add("key", appkey);//你申请的key
string result1 = sendPost(url1, parameters1, "get");
JsonObject newObj1 = new JsonObject(result1);
String errorCode1 = newObj1["error_code"].V
if (errorCode1 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj1);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj1["error_code"].Value+":"+newObj1["reason"].Value);
//2.香港股市
string url2 = ":8080/finance/stock/hk";
var parameters2 = new Dictionary&string, string&();
parameters2.Add("num" , ""); //股票代码,如:00001 为“长江实业”股票代码
parameters2.Add("key", appkey);//你申请的key
string result2 = sendPost(url2, parameters2, "get");
JsonObject newObj2 = new JsonObject(result2);
String errorCode2 = newObj2["error_code"].V
if (errorCode2 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj2);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj2["error_code"].Value+":"+newObj2["reason"].Value);
//3.美国股市
string url3 = ":8080/finance/stock/usa";
var parameters3 = new Dictionary&string, string&();
parameters3.Add("gid" , ""); //股票代码,如:aapl 为“苹果公司”的股票代码
parameters3.Add("key", appkey);//你申请的key
string result3 = sendPost(url3, parameters3, "get");
JsonObject newObj3 = new JsonObject(result3);
String errorCode3 = newObj3["error_code"].V
if (errorCode3 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj3);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj3["error_code"].Value+":"+newObj3["reason"].Value);
//4.香港股市列表
string url4 = ":8080/finance/stock/hkall";
var parameters4 = new Dictionary&string, string&();
parameters4.Add("key", appkey);//你申请的key
parameters4.Add("page" , ""); //第几页,每页20条数据,默认第1页
string result4 = sendPost(url4, parameters4, "get");
JsonObject newObj4 = new JsonObject(result4);
String errorCode4 = newObj4["error_code"].V
if (errorCode4 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj4);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj4["error_code"].Value+":"+newObj4["reason"].Value);
//5.美国股市列表
string url5 = ":8080/finance/stock/usaall";
var parameters5 = new Dictionary&string, string&();
parameters5.Add("key", appkey);//你申请的key
parameters5.Add("page" , ""); //第几页,每页20条数据,默认第1页
string result5 = sendPost(url5, parameters5, "get");
JsonObject newObj5 = new JsonObject(result5);
String errorCode5 = newObj5["error_code"].V
if (errorCode5 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj5);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj5["error_code"].Value+":"+newObj5["reason"].Value);
//6.深圳股市列表
string url6 = ":8080/finance/stock/szall";
var parameters6 = new Dictionary&string, string&();
parameters6.Add("key", appkey);//你申请的key
parameters6.Add("page" , ""); //第几页(每页20条数据),默认第1页
string result6 = sendPost(url6, parameters6, "get");
JsonObject newObj6 = new JsonObject(result6);
String errorCode6 = newObj6["error_code"].V
if (errorCode6 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj6);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj6["error_code"].Value+":"+newObj6["reason"].Value);
//7.沪股列表
string url7 = ":8080/finance/stock/shall";
var parameters7 = new Dictionary&string, string&();
parameters7.Add("key", appkey);//你申请的key
parameters7.Add("page" , ""); //第几页,每页20条数据,默认第1页
string result7 = sendPost(url7, parameters7, "get");
JsonObject newObj7 = new JsonObject(result7);
String errorCode7 = newObj7["error_code"].V
if (errorCode7 == "0")
Debug.WriteLine("成功");
Debug.WriteLine(newObj7);
//Debug.WriteLine("失败");
Debug.WriteLine(newObj7["error_code"].Value+":"+newObj7["reason"].Value);
/// &summary&
/// Http (GET/POST)
/// &/summary&
/// &param name="url"&请求URL&/param&
/// &param name="parameters"&请求参数&/param&
/// &param name="method"&请求方法&/param&
/// &returns&响应内容&/returns&
static string sendPost(string url, IDictionary&string, string& parameters, string method)
if (method.ToLower() == "post")
HttpWebRequest req =
HttpWebResponse rsp =
System.IO.Stream reqStream =
req = (HttpWebRequest)WebRequest.Create(url);
req.Method =
req.KeepAlive =
req.ProtocolVersion = HttpVersion.Version10;
req.Timeout = 5000;
req.ContentType = "application/x-www-form-charset=utf-8";
byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(parameters, "utf8"));
reqStream = req.GetRequestStream();
reqStream.Write(postData, 0, postData.Length);
rsp = (HttpWebResponse)req.GetResponse();
Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
return GetResponseAsString(rsp, encoding);
catch (Exception ex)
return ex.M
if (reqStream != null) reqStream.Close();
if (rsp != null) rsp.Close();
//创建请求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "?" + BuildQuery(parameters, "utf8"));
request.Method = "GET";
request.ReadWriteTimeout = 5000;
request.ContentType = "text/charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
//返回内容
string retString = myStreamReader.ReadToEnd();
return retS
/// &summary&
/// 组装普通文本请求参数。
/// &/summary&
/// &param name="parameters"&Key-Value形式请求参数字典&/param&
/// &returns&URL编码后的请求数据&/returns&
static string BuildQuery(IDictionary&string, string& parameters, string encode)
StringBuilder postData = new StringBuilder();
bool hasParam =
IEnumerator&KeyValuePair&string, string&& dem = parameters.GetEnumerator();
while (dem.MoveNext())
string name = dem.Current.K
string value = dem.Current.V
// 忽略参数名或参数值为空的参数
if (!string.IsNullOrEmpty(name))//&& !string.IsNullOrEmpty(value)
if (hasParam)
postData.Append("&");
postData.Append(name);
postData.Append("=");
if (encode == "gb2312")
postData.Append(HttpUtility.UrlEncode(value, Encoding.GetEncoding("gb2312")));
else if (encode == "utf8")
postData.Append(HttpUtility.UrlEncode(value, Encoding.UTF8));
postData.Append(value);
hasParam =
return postData.ToString();
/// &summary&
/// 把响应流转换为文本。
/// &/summary&
/// &param name="rsp"&响应流对象&/param&
/// &param name="encoding"&编码方式&/param&
/// &returns&响应文本&/returns&
static string GetResponseAsString(HttpWebResponse rsp, Encoding encoding)
System.IO.Stream stream =
StreamReader reader =
// 以字符流的方式读取HTTP响应
stream = rsp.GetResponseStream();
reader = new StreamReader(stream, encoding);
return reader.ReadToEnd();
// 释放资源
if (reader != null) reader.Close();
if (stream != null) stream.Close();
if (rsp != null) rsp.Close();
开源中国-程序员在线工具:
相关的代码(13)
开源从代码分享开始
熊babi的其它代码用户名:lwglucky
文章数:250
评论数:85
访问量:694038
注册日期:
阅读量:1297
阅读量:3317
阅读量:432516
阅读量:1120494
51CTO推荐博文
& matlab无疑是科学计算的强大工具,很少的代码就可以完成非常复杂的功能。这些功能如果用c++实现是难以想象的。
& &如何利用matlab来进行股票数据分析呢?在前面的文章中,我分析了如何通过股票行情软件下载行情数据来读取。但是这个方法不是很方便,需要人工工作太多,我在海洋部落里看到很多人都在通过计算方式来进行买卖决策,让我又有了进一步工作下去的信心。
& &kline.c 文件是一个mex c文件,编译出来一个接口,通过该接口 得到日行情数据。详情请参见源代码。如何使用这个编译出来的接口文件呢?请查看stock.m文件。
& 这个接口文件直接从行情服务器下载数据,非常方便了,可以在matlab中使用很少的代码实现根据决策筛选股票。 由于数据格式是逆向得到的,不便公开,所以网络接口代码就不公开源代码了。
stock.m文件如下:
function ay=stock(code , lday , windowSize)&
% &windowSize均值窗口长度
[kp,hp,lp,sp,vol,tm]=kline(code,lday);%调用mex 接口文件获得日K线行情数据。%其中code问股票代码,lday为取得的数据天数。
%&[kp,hp,lp,sp,vol,tm] 为行情数据,最高价,最低价,开盘价,收盘价,量,价
subplot(2,2,1); candle(hp',lp',sp',kp');
a = filter(ones(1,windowSize)/windowSize,1,sp')';&
a(1:5) = a(6);
plot(xx , a ,'r');
plot(xx , tm.*10000./vol./10000 ,'c');
ylabel('价格'); xlabel('红色 收盘均价 ; 品色 均价');
subplot(2,2,2);
plot(xx , vol);
ylabel('成交量');
subplot(2,2,3);
plot(diff(sp));
ylabel('价格差分');
subplot(2,2,4);
plot(diff(vol));
ylabel('成交量差分');
===========
在matlab命令命令窗口中敲入 stock(,5),即可查看到数据。
其中 002159 --- 股票代码;
& & &60 ---- 取多少天的数据,从当前日子开始向前数60天。
& & &5 &---- 均线平滑窗口。
得到数据了,很简单的就可以做一个均值方差的买卖交易系统。有了数据,matlab做科学分析统计工作的威力就发挥出来了。650) this.width=650;" alt="" src="/neweditor/editor/images/smiley/15.gif" />
均值方差的买卖交易系统的源代码稍后发布出来。
下一步准备接受分笔行情数据,实时监测盘中买卖点。源代码也随后发布。
花了我2天时间,真累。
&本文出自 “” 博客,请务必保留此出处
了这篇文章
附件下载:  
类别:┆阅读(0)┆评论(0)
17:00:29 21:18:15 21:32:31 08:12:13 10:17:13
请输入验证码:网站被关闭提示
网站被关闭提示
网站因有违规内容而被关闭
具体事宜请联系您的接入商(window.slotbydup=window.slotbydup || []).push({
id: '4051700',
container: s,
size: '400,50',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '3991088',
container: s,
size: '100,240',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '3991102',
container: s,
size: '100,240',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '4044404',
container: s,
size: '240,146',
display: 'inlay-fix'
请问TdxHqApi.dll如何使用?
用户被禁止发言
请问TdxHqApi.dll如何使用?
浏览:8276
欢迎光临理想论坛,由于您没有登录,所以无法查看到论坛的附件及隐藏分区,也无法与其他会员交流。
还没有理想论坛的帐号?
提示: 作者被禁止或删除 内容自动屏蔽
积分2826&理想币175 个&彩币0 个&共享币308 个&注册时间&
理想大二级同学
还需要 9169 积分才能升级
我也不懂,求解。。。
积分40831&理想币24790 个&彩币3 个&共享币1400 个&注册时间&
理想初一级同学
还需要 1546 积分才能升级
求解。。。
积分2454&理想币580 个&彩币0 个&共享币1040 个&注册时间&
理想初二级同学
还需要 895 积分才能升级
作用是什么????
积分5105&理想币1 个&彩币0 个&共享币2598 个&注册时间&
理想小四级同学
还需要 313 积分才能升级
搜下到处都是源代码,写程序获取数据
积分387&理想币0 个&彩币0 个&共享币10 个&注册时间&
理想小四级同学
还需要 313 积分才能升级
from ctypes import *& &
import sys
reload(sys)
sys.setdefaultencoding('latin1')
#编码到市场转换
def codetomkt(strCode):
& & mkt = 0
& & if strCode[0] == '6':
& && &&&mkt = 1
& & return mkt
class tdxoperation():
& & def __init__(self,strdllname = 'TdxHqApi.dll'):
& && &&&self.api = WinDLL(strdllname)# &TdxHqApi.dll&
& && &&&self.Count = c_short(30000)
& && &&&self.Result = create_string_buffer('/0'*1024 * 1024)&&
& && &&&self.ErrInfo= create_string_buffer('/0'*256)&&
& && && && && &
& && &&&'''
& && &&&TdxL2Hq_GetDetailTransactionData(byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取逐笔成交
& && &&&TdxL2Hq_GetDetailOrderData(byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取逐笔委托
& && &&&TdxL2Hq_GetSecurityQuotes10 (byte Market[], char* Zqdm[], short& Count, char* Result, char* ErrInfo);
& && &&&#获取十挡报价
& && &&&TdxL2Hq_GetBuySellQueue(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取买卖队列
& && &&&TdxL2Hq_Connect(char* IP, int Port, char* Result, char* ErrInfo);
& && &&&#连接券商行情服务器
& && &&&TdxL2Hq_Disconnect();
& && &&&#断开服务器
& && &&&TdxL2Hq_GetSecurityCount(byte Market, short& Result, char* ErrInfo);
& && &&&#获取市场内所有证券的数目
& && &&&TdxL2Hq_GetSecurityList(byte Market, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取指定范围内所有的证券代码
& && &&&TdxL2Hq_GetSecurityBars(byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取股票K线
& && &&&TdxL2Hq_GetIndexBars(byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);/
& && &&&#获取指数K线
& && &&&TdxL2Hq_GetMinuteTimeData(byte Market,&&char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取分时图数据
& && &&&TdxL2Hq_GetHistoryMinuteTimeData(byte Market, char* Zqdm, int date, char* Result, char* ErrInfo);
& && &&&#获取历史分时图数据
& && &&&TdxL2Hq_GetTransactionData(byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取分时成交
& && &&&TdxL2Hq_GetHistoryTransactionData(byte Market, char* Zqdm, short Start, short& Count, int date, char* Result, char* ErrInfo);
& && &&&#获取历史分时成交
& && &&&TdxL2Hq_GetSecurityQuotes(byte Market[], char* Zqdm[], short& Count, char* Result, char* ErrInfo);
& && &&&#获取盘口五档报价
& && &&&TdxL2Hq_GetCompanyInfoCategory(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取F10信息类别
& && &&&TdxL2Hq_GetCompanyInfoContent(byte Market, char* Zqdm, char* FileName, int Start, int Length, char* Result, char* ErrInfo);
& && &&&#获取F10信息内容
& && &&&TdxL2Hq_GetXDXRInfo(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取权息数据
& && &&&TdxL2Hq_GetFinanceInfo(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取财务信息
& && &&&'''
& && &&&'''
& & & & ///所有券商L2服务器都一样,为以下地址:
& & & & ///高级行情_上海电信1:61.152.107.173:7707
& & & & ///高级行情_上海电信2:61.152.168.232:7715
& & & & ///高级行情_上海电信3:61.152.168.227:7709
& & & & ///高级行情_上海电信4:61.152.107.170:7707
& & & & ///高级行情_深圳电信1:119.147.86.172:443
& & & & ///高级行情_深圳电信2:113.105.73.81:7721
& & & & ///高级行情_东莞电信1:113.105.142.138:7709
& & & & ///高级行情_东莞电信2:113.105.142.139:7709
& & & & ///高级行情_武汉电信1:59.175.238.41:443
& & & & ///高级行情_武汉电信2:119.97.185.4:7709
& & & & ///高级行情_武汉电信3:59.175.238.38:7707
& & & & ///高级行情_济南联通: 123.129.245.202:80
& & & & ///高级行情_北京联通: 61.135.142.90:443
& & & & ///高级行情_上海联通: 210.51.55.212:80
& & & & ///高级行情_东莞联通1:58.253.96.198:7709
& & & & ///高级行情_东莞联通2:58.253.96.200:7709
& && &&&'''
& & #连接服务器
& & def connectserver(self, listip=['61.152.107.173:7707',
& && && && && && && && && && && && &'61.152.168.232:7715',
& && && && && && && && && && && && &'61.152.168.227:7709',
& && && && && && && && && && && && &'61.152.107.170:7707',
& && && && && && && && && && && && &&&#'119.147.86.172:443',
& && && && && && && && && && && && &'113.105.73.81:7721',
& && && && && && && && && && && && &'113.105.142.138:7709',
& && && && && && && && && && && && &'113.105.142.139:7709',
& && && && && && && && && && && && &'59.175.238.41:443',
& && && && && && && && && && && && &'119.97.185.4:7709',
& && && && && && && && && && && && &'59.175.238.38:7707',
& && && && && && && && && && && && &'123.129.245.202:80',
& && && && && && && && && && && && &'61.135.142.90:443',
& && && && && && && && && && && && &'210.51.55.212:80',
& && && && && && && && && && && && &'58.253.96.198:7709',
& && && && && && && && && && && && &'58.253.96.200:7709']):
& && &&&self.api.TdxL2Hq_Connect.argtypes=[c_char_p, c_int, c_char_p, c_char_p]
& && &&&self.api.TdxL2Hq_Connect.restype =c_bool
& && &&&for ip in listip:
& && && && &ipa=ip.split(&:&)[0]
& && && && &ipp=ip.split(&:&)[1]
& && && && &ret = self.api.TdxL2Hq_Connect(ipa, int(ipp),self.Result, self.ErrInfo)
& && && && &print self.Result.value
& && && && &print self.ErrInfo.value
& && && && &if ret :
& && && && && & break
& && && && &
& & #获取买卖队列
& & def GetBuySellQueue(self,strCode):
& && &&&self.api.TdxL2Hq_GetBuySellQueue.argtypes=[c_byte, c_char_p, c_char_p, c_char_p]
& && &&&self.api.TdxL2Hq_GetBuySellQueue.restype =c_bool
& && &&&if len(strCode) != 6:
& && && && &return None
& && &&&mkt = codetomkt(strCode)& &
& && &&&ret = self.api.TdxL2Hq_GetBuySellQueue(mkt, strCode,self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& && &&&return self.Result.value
& & #获取十挡报价
& & #('002168','002104','002657','000166',&600030&,'600611','601519','600686','600880','600061','601901','601992')
& & def GetSecurityQuotes10(self, lisCode):
& && &&&LPBYTE = POINTER(c_ubyte)
& && &&&LPTSTR = POINTER(c_char)
& && &&&#api.TdxL2Hq_GetSecurityQuotes10.argtypes=[LPBYTE, POINTER(LPTSTR), c_short, c_char_p, c_char_p]
& && &&&self.api.TdxL2Hq_GetSecurityQuotes10.restype =c_bool
& && &&&num = len(lisCode)
& && &&&mkts = [codetomkt(strCode) for strCode in lisCode]
& && &&&Market=(c_ubyte*num)(*tuple(mkts))
& && &&&Zqdm = (c_char_p*num)(*lisCode)
& && &&&ZqdmCount = c_short(num);
& && &&&bool1 = self.api.TdxL2Hq_GetSecurityQuotes10(Market, Zqdm, byref(ZqdmCount), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取逐笔成交
& & def GetDetailTransactionData(self, strCode):
& && &&&#(byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&bool1 = self.api.TdxL2Hq_GetDetailTransactionData(codetomkt(strCode) , strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #//获取逐笔委托
& & def GetDetailOrderData(self, strCode):& && &
& && &&&#byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&bool1 = self.api.TdxL2Hq_GetDetailOrderData(codetomkt(strCode), strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取股票K线
& & def GetSecurityBars(self, strCode, category):&&
& && &&&#(byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&bool1 = self.api.TdxL2Hq_GetSecurityBars(category, codetomkt(strCode), strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取指数K线数据
& & def GetIndexBars(self, strCode, category):&&
& && &&&#数据种类, 0-&5分钟K线& & 1-&15分钟K线& & 2-&30分钟K线&&3-&1小时K线& & 4-&日K线&&5-&周K线&&6-&月K线&&7-&1分钟K线& &&&8-&1分钟K线& & 9-&日K线&&10-&季K线&&11-&年K线
& && &&&#byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo
& && &&&bool1 = self.api.TdxL2Hq_GetIndexBars(category, codetomkt(strCode),strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取分时图数据
& & def GetMinuteTimeData(self, strCode):
& && &&&bool1 = self.api.TdxL2Hq_GetMinuteTimeData(codetomkt(strCode),strCode,&&self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取历史分时图数据
& & def GetHistoryMinuteTimeData(self, strCode,date):
& && &&&bool1 = self.api.TdxL2Hq_GetHistoryMinuteTimeData(codetomkt(strCode),strCode, date, self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取分笔图数据
& & def GetTransactionData(self, strCode,date):
& && &&&bool1 = self.api.TdxL2Hq_GetTransactionData(codetomkt(strCode),strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取历史分笔图数据&&
& & def GetHistoryTransactionData(self, strCode,date):
& && &&&bool1 = self.api.TdxL2Hq_GetHistoryTransactionData(codetomkt(strCode),strCode, 0, byref(self.Count), ,&&self.Result, self.ErrInfo);
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
积分387&理想币0 个&彩币0 个&共享币10 个&注册时间&
理想小四级同学
还需要 313 积分才能升级
from ctypes import *& &
import sys
reload(sys)
sys.setdefaultencoding('latin1')
#编码到市场转换
def codetomkt(strCode):
& & mkt = 0
& & if strCode[0] == '6':
& && &&&mkt = 1
& & return mkt
class tdxoperation():
& & def __init__(self,strdllname = 'TdxHqApi.dll'):
& && &&&self.api = WinDLL(strdllname)# &TdxHqApi.dll&
& && &&&self.Count = c_short(30000)
& && &&&self.Result = create_string_buffer('/0'*1024 * 1024)&&
& && &&&self.ErrInfo= create_string_buffer('/0'*256)&&
& && && && && &
& && &&&'''
& && &&&TdxL2Hq_GetDetailTransactionData(byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取逐笔成交
& && &&&TdxL2Hq_GetDetailOrderData(byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取逐笔委托
& && &&&TdxL2Hq_GetSecurityQuotes10 (byte Market[], char* Zqdm[], short& Count, char* Result, char* ErrInfo);
& && &&&#获取十挡报价
& && &&&TdxL2Hq_GetBuySellQueue(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取买卖队列
& && &&&TdxL2Hq_Connect(char* IP, int Port, char* Result, char* ErrInfo);
& && &&&#连接券商行情服务器
& && &&&TdxL2Hq_Disconnect();
& && &&&#断开服务器
& && &&&TdxL2Hq_GetSecurityCount(byte Market, short& Result, char* ErrInfo);
& && &&&#获取市场内所有证券的数目
& && &&&TdxL2Hq_GetSecurityList(byte Market, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取指定范围内所有的证券代码
& && &&&TdxL2Hq_GetSecurityBars(byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取股票K线
& && &&&TdxL2Hq_GetIndexBars(byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);/
& && &&&#获取指数K线
& && &&&TdxL2Hq_GetMinuteTimeData(byte Market,&&char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取分时图数据
& && &&&TdxL2Hq_GetHistoryMinuteTimeData(byte Market, char* Zqdm, int date, char* Result, char* ErrInfo);
& && &&&#获取历史分时图数据
& && &&&TdxL2Hq_GetTransactionData(byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&#获取分时成交
& && &&&TdxL2Hq_GetHistoryTransactionData(byte Market, char* Zqdm, short Start, short& Count, int date, char* Result, char* ErrInfo);
& && &&&#获取历史分时成交
& && &&&TdxL2Hq_GetSecurityQuotes(byte Market[], char* Zqdm[], short& Count, char* Result, char* ErrInfo);
& && &&&#获取盘口五档报价
& && &&&TdxL2Hq_GetCompanyInfoCategory(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取F10信息类别
& && &&&TdxL2Hq_GetCompanyInfoContent(byte Market, char* Zqdm, char* FileName, int Start, int Length, char* Result, char* ErrInfo);
& && &&&#获取F10信息内容
& && &&&TdxL2Hq_GetXDXRInfo(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取权息数据
& && &&&TdxL2Hq_GetFinanceInfo(byte Market, char* Zqdm, char* Result, char* ErrInfo);
& && &&&#获取财务信息
& && &&&'''
& && &&&'''
& & & & ///所有券商L2服务器都一样,为以下地址:
& & & & ///高级行情_上海电信1:61.152.107.173:7707
& & & & ///高级行情_上海电信2:61.152.168.232:7715
& & & & ///高级行情_上海电信3:61.152.168.227:7709
& & & & ///高级行情_上海电信4:61.152.107.170:7707
& & & & ///高级行情_深圳电信1:119.147.86.172:443
& & & & ///高级行情_深圳电信2:113.105.73.81:7721
& & & & ///高级行情_东莞电信1:113.105.142.138:7709
& & & & ///高级行情_东莞电信2:113.105.142.139:7709
& & & & ///高级行情_武汉电信1:59.175.238.41:443
& & & & ///高级行情_武汉电信2:119.97.185.4:7709
& & & & ///高级行情_武汉电信3:59.175.238.38:7707
& & & & ///高级行情_济南联通: 123.129.245.202:80
& & & & ///高级行情_北京联通: 61.135.142.90:443
& & & & ///高级行情_上海联通: 210.51.55.212:80
& & & & ///高级行情_东莞联通1:58.253.96.198:7709
& & & & ///高级行情_东莞联通2:58.253.96.200:7709
& && &&&'''
& & #连接服务器
& & def connectserver(self, listip=['61.152.107.173:7707',
& && && && && && && && && && && && &'61.152.168.232:7715',
& && && && && && && && && && && && &'61.152.168.227:7709',
& && && && && && && && && && && && &'61.152.107.170:7707',
& && && && && && && && && && && && &&&#'119.147.86.172:443',
& && && && && && && && && && && && &'113.105.73.81:7721',
& && && && && && && && && && && && &'113.105.142.138:7709',
& && && && && && && && && && && && &'113.105.142.139:7709',
& && && && && && && && && && && && &'59.175.238.41:443',
& && && && && && && && && && && && &'119.97.185.4:7709',
& && && && && && && && && && && && &'59.175.238.38:7707',
& && && && && && && && && && && && &'123.129.245.202:80',
& && && && && && && && && && && && &'61.135.142.90:443',
& && && && && && && && && && && && &'210.51.55.212:80',
& && && && && && && && && && && && &'58.253.96.198:7709',
& && && && && && && && && && && && &'58.253.96.200:7709']):
& && &&&self.api.TdxL2Hq_Connect.argtypes=[c_char_p, c_int, c_char_p, c_char_p]
& && &&&self.api.TdxL2Hq_Connect.restype =c_bool
& && &&&for ip in listip:
& && && && &ipa=ip.split(&:&)[0]
& && && && &ipp=ip.split(&:&)[1]
& && && && &ret = self.api.TdxL2Hq_Connect(ipa, int(ipp),self.Result, self.ErrInfo)
& && && && &print self.Result.value
& && && && &print self.ErrInfo.value
& && && && &if ret :
& && && && && & break
& && && && &
& & #获取买卖队列
& & def GetBuySellQueue(self,strCode):
& && &&&self.api.TdxL2Hq_GetBuySellQueue.argtypes=[c_byte, c_char_p, c_char_p, c_char_p]
& && &&&self.api.TdxL2Hq_GetBuySellQueue.restype =c_bool
& && &&&if len(strCode) != 6:
& && && && &return None
& && &&&mkt = codetomkt(strCode)& &
& && &&&ret = self.api.TdxL2Hq_GetBuySellQueue(mkt, strCode,self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& && &&&return self.Result.value
& & #获取十挡报价
& & #('002168','002104','002657','000166',&600030&,'600611','601519','600686','600880','600061','601901','601992')
& & def GetSecurityQuotes10(self, lisCode):
& && &&&LPBYTE = POINTER(c_ubyte)
& && &&&LPTSTR = POINTER(c_char)
& && &&&#api.TdxL2Hq_GetSecurityQuotes10.argtypes=[LPBYTE, POINTER(LPTSTR), c_short, c_char_p, c_char_p]
& && &&&self.api.TdxL2Hq_GetSecurityQuotes10.restype =c_bool
& && &&&num = len(lisCode)
& && &&&mkts = [codetomkt(strCode) for strCode in lisCode]
& && &&&Market=(c_ubyte*num)(*tuple(mkts))
& && &&&Zqdm = (c_char_p*num)(*lisCode)
& && &&&ZqdmCount = c_short(num);
& && &&&bool1 = self.api.TdxL2Hq_GetSecurityQuotes10(Market, Zqdm, byref(ZqdmCount), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取逐笔成交
& & def GetDetailTransactionData(self, strCode):
& && &&&#(byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&bool1 = self.api.TdxL2Hq_GetDetailTransactionData(codetomkt(strCode) , strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #//获取逐笔委托
& & def GetDetailOrderData(self, strCode):& && &
& && &&&#byte Market, char* Zqdm, int Start, short& Count, char* Result, char* ErrInfo);
& && &&&bool1 = self.api.TdxL2Hq_GetDetailOrderData(codetomkt(strCode), strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取股票K线
& & def GetSecurityBars(self, strCode, category):&&
& && &&&#(byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo);
& && &&&bool1 = self.api.TdxL2Hq_GetSecurityBars(category, codetomkt(strCode), strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取指数K线数据
& & def GetIndexBars(self, strCode, category):&&
& && &&&#数据种类, 0-&5分钟K线& & 1-&15分钟K线& & 2-&30分钟K线&&3-&1小时K线& & 4-&日K线&&5-&周K线&&6-&月K线&&7-&1分钟K线& &&&8-&1分钟K线& & 9-&日K线&&10-&季K线&&11-&年K线
& && &&&#byte Category, byte Market, char* Zqdm, short Start, short& Count, char* Result, char* ErrInfo
& && &&&bool1 = self.api.TdxL2Hq_GetIndexBars(category, codetomkt(strCode),strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取分时图数据
& & def GetMinuteTimeData(self, strCode):
& && &&&bool1 = self.api.TdxL2Hq_GetMinuteTimeData(codetomkt(strCode),strCode,&&self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取历史分时图数据
& & def GetHistoryMinuteTimeData(self, strCode,date):
& && &&&bool1 = self.api.TdxL2Hq_GetHistoryMinuteTimeData(codetomkt(strCode),strCode, date, self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取分笔图数据
& & def GetTransactionData(self, strCode,date):
& && &&&bool1 = self.api.TdxL2Hq_GetTransactionData(codetomkt(strCode),strCode, 0, byref(self.Count), self.Result, self.ErrInfo)
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
& & #获取历史分笔图数据&&
& & def GetHistoryTransactionData(self, strCode,date):
& && &&&bool1 = self.api.TdxL2Hq_GetHistoryTransactionData(codetomkt(strCode),strCode, 0, byref(self.Count), ,&&self.Result, self.ErrInfo);
& && &&&print self.Result.value
& && &&&print self.ErrInfo.value
积分387&理想币0 个&彩币0 个&共享币10 个&注册时间&
理想初三级同学
还需要 1266 积分才能升级
积分6734&理想币1377 个&彩币5 个&共享币744 个&注册时间&
理想小四级同学
还需要 313 积分才能升级
要审核,发重了,上面是python调用代码
积分387&理想币0 个&彩币0 个&共享币10 个&注册时间&
理想小五级同学
还需要 137 积分才能升级
回复 9楼 @闻道启悟
您好&&请问这是完整的源代码吗?能上传一份吗?非常感谢
积分863&理想币3 个&彩币5 个&共享币418 个&注册时间&
理想小四级同学
还需要 313 积分才能升级
是完整的l2行情,k线的不能用,队列,十档,逐笔都好使,你试试
积分387&理想币0 个&彩币0 个&共享币10 个&注册时间&
理想小五级同学
还需要 255 积分才能升级
是完整的l2行情,k线的不能用,队列,十档,逐笔都好使,你试试
积分745&理想币16 个&彩币0 个&共享币4 个&注册时间&
理想初二级同学
还需要 552 积分才能升级
感谢闻道老师分享
积分5448&理想币172 个&彩币5 个&共享币689 个&注册时间&
理想小四级同学
还需要 50 积分才能升级
谢谢!感谢闻道分享
积分650&理想币3 个&彩币0 个&共享币72 个&注册时间&
理想大二级同学
还需要 3681 积分才能升级
谢谢分享 !!!!!!
积分46319&理想币21029 个&彩币0 个&共享币5014 个&注册时间&
用户被禁止发言
谢谢!感谢闻道分享
提示: 作者被禁止或删除 内容自动屏蔽
积分2826&理想币175 个&彩币0 个&共享币308 个&注册时间&
理想初一级同学
还需要 1260 积分才能升级
积分2740&理想币1489 个&彩币0 个&共享币273 个&注册时间&
理想小四级同学
还需要 423 积分才能升级
还要懂编程呀
积分277&理想币40 个&彩币0 个&共享币104 个&注册时间&
理想初二级同学
还需要 1777 积分才能升级
貌似现在不能用了
积分4223&理想币21 个&彩币0 个&共享币87 个&注册时间&
理想小二级同学
还需要 32 积分才能升级
回复 11楼 @闻道启悟
老师,是否可合作开发程序化交易接口?望回复,谢谢
积分68&理想币8 个&彩币0 个&共享币11 个&注册时间&
快速回复主题
禁用 URL 识别
使用个人签名
接收新回复邮件通知
发帖请务遵守本站的相关规则,所有发表(包括转发)政治、色情非法信息者本站将实时提供发贴者个人信息给公安局,追究责任,特此申明!
具体规则请参见《》
您需要登录后才可以发帖
发表帖子[完成后可按 Ctrl+Enter 发布]
理想论坛上的网友发表的帖子纯属个人意见,理想论坛不负任何责任!广告赞助商内容与本站无关!
理想论坛值班电话[9:30~18:30]: &#6 5518-1 &#66 3090 ☎ 187 (广告)
工业和信息化部信息备案:}

我要回帖

更多关于 怎么调用api接口 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信