通达信客户端程序化下单
通达信是股票市场上最常⽤的客户端之⼀,⼏乎所有的券商都有通达信客户端,⽽很多朋友在盘中都想有⼀个⾃⼰的下单程序。下⾯从2⽅
⾯探讨⼀下通过通达信⾃动化下单的办法:
⼀、利⽤模拟按键类程序
利⽤通达信的客户端界⾯本⾝,获取各个控件的类型和实例名,通过AUTOIT等脚本程序实现通达信客户端的⾃动化下单。此种⽅法简单⽅
便,都是通过windows的库函数的调⽤来模拟消息,从⽽实现⾃动化下单。但是此⽅法只可⽤于代替⼈⼿⼯敲单⽽已,盘中需要⼈盯盘、同
时将股票提前写⼊脚本或者配置⽂件中,时效性太差。
⼆、利⽤⽹络上流出的通达信接⼝进⾏⼆次编程开发。
先贴出可调⽤的⽅法
/
// 打开通达信实例
/// </summary>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void OpenTdx();
/// <summary>
/// 关闭通达信实例
/// </summary>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void CloseTdx();
/// <summary>
/// 交易账户登录
/
// </summary>
/// <param name="IP">券商交易服务器IP</param>
/// <param name="Port">券商交易服务器端⼝</param>
/// <param name="Version">设置通达信客户端的版本号:6.00或8.00</param>
/// <param name="YybId">营业部编码:国泰君安为7</param>
/// <param name="AccountNo">资⾦账号</param>
/// <param name="TradeAccount">交易帐号与资⾦帐号相同</param>
/// <param name="JyPassword">交易密码</param>
/// <param name="TxPassword">通讯密码为空</param>
/// <param name="ErrInfo">此API执⾏返回后,如果出错,保存了错误信息说明。⼀般要分配256字节的空间。没出错时为空字符串</param>
param name/// <returns>客户端ID,失败时返回-1。正确时为从0开始按登陆次数叠加</returns>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern int Logon(string IP, short Port, string Version, short YybId, string AccountNo, string TradeAccount, string JyPassword, string TxPassword,
/// <summary>
/// 交易账户注销
/// </summary>
/// <param name="ClientID">客户端ID</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void Logoff(int ClientID);
/// <summary>
/// 融资融券直接还款
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Amount">还款⾦额</param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void Repay(int ClientID, string Amount, StringBuilder Result, StringBuilder ErrInfo);
/// <summary>
/// 查询各种历史数据
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="ClientID">客户端ID</param>
/// <param name="Category">表⽰查询信息的种类,0历史委托 1历史成交 2交割单</param>
/// <param name="StartDate">表⽰开始⽇期,格式为yyyyMMdd,⽐如2014年3⽉1⽇为 20140301</param>
/// <param name="EndDate">表⽰结束⽇期,格式为yyyyMMdd,⽐如2014年3⽉1⽇为 20140301</param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void QueryHistoryData(int ClientID, int Category, string StartDate, string EndDate, StringBuilder Result, StringBuilder ErrInfo);
/// <summary>
/// 查询各种交易数据
/
// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Category">表⽰查询信息的种类,0资⾦ 1股份 2当⽇委托 3当⽇成交 4可撤单 5股东代码 6融资余额 7融券余额 8可融证券</param> /// <param name="Result">此API执⾏返回后,Result内保存了返回的查询数据, 形式为表格数据,⾏数据之间通过\n字符分割,列数据之间通过\t分隔。⼀般要分 /// <param name="ErrInfo">此API执⾏返回后,如果出错,保存了错误信息说明。⼀般要分配256字节的空间。没出错时为空字符串</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void QueryData(int ClientID, int Category, StringBuilder Result, StringBuilder ErrInfo);
/// <summary>
/// 批量查询各种交易数据,⽤数组传⼊每个委托的参数,数组第i个元素表⽰第i个查询的相应参数。暂时意义不⼤
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Category">表⽰查询信息的种类,0资⾦ 1股份 2当⽇委托 3当⽇成交 4可撤单 5股东代码 6融资余额 7融券余额 8可融证券</param> /// <param name="Count"></param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void QueryDatas(int ClientID, int[] Category, int Count, IntPtr[] Result, IntPtr[] ErrInfo);
/// <summary>
/// 下委托交易证券
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Category">表⽰委托的种类,0买⼊ 1卖出 2融资买⼊ 3融券卖出 4买券还券 5卖券还款 6现券还券</param>
/// <param name="PriceType">表⽰报价⽅式 0 上海限价委托深圳限价委托 1深圳对⽅最优价格 2深圳本⽅最优价格 3深圳即时成交剩余撤销 4上海五档即成剩 /// <param name="Gddm">股东代码</param>
/// <param name="Zqdm">证券代码</param>
/// <param name="Price">委托价格</param>
/// <param name="Quantity">委托数量</param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void SendOrder(int ClientID, int Category, int PriceType, string Gddm, string Zqdm, float Price, int Quantity, StringBuilder Result, StringBu
/// <summary>
/// 批量下委托交易,暂时意义不⼤
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Category">表⽰委托的种类,0买⼊ 1卖出 2融资买⼊ 3融券卖出 4买券还券 5卖券还款 6现券还券</param>
/// <param name="PriceType">表⽰报价⽅式 0 上海限价委托深圳限价委托 1深圳对⽅最优价格 2深圳本⽅最优价格 3深圳即时成交剩余撤销 4上海五档即成剩 /// <param name="Gddm">股东代码</param>
/// <param name="Zqdm">证券代码</param>
/// <param name="Price">委托价格</param>
/// <param name="Quantity">委托数量</param>
/
// <param name="Count">批量下单数量</param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void SendOrders(int ClientID, int[] Category, int[] PriceType, string[] Gddm, string[] Zqdm, float[] Price, int[] Quantity, int Count, IntPtr[] Re
/// <summary>
/// 撤委托
/// 撤委托
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="ExchangeID">交易所类别,上海A1,深圳A0(招商证券普通账户深圳是2)</param>
/// <param name="hth">委托编号</param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void CancelOrder(int ClientID, string ExchangeID, string hth, StringBuilder Result, StringBuilder ErrInfo);
/// <summary>
/// 批量撤单
/// </summary>
/// <param name="ClientID"></param>
/// <param name="ExchangeID">交易所类别,上海A1,深圳A0(招商证券普通账户深圳是2)</param>
/// <param name="hth"></param>
/// <param name="Count"></param>
/// <param name="Result"></param>
/// <param name="ErrInfo"></param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void CancelOrders(int ClientID, string[] ExchangeID, string[] hth, int Count, IntPtr[] Result, IntPtr[] ErrInfo);
/// <summary>
/// 获取证券的实时五档⾏情
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Zqdm">证券代码</param>
/// <param name="Result">同上</param>
/// <param name="ErrInfo">同上</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void GetQuote(int ClientID, string Zqdm, StringBuilder Result, StringBuilder ErrInfo);
/// <summary>
/// 批量获取证券的实时五档⾏情
/// </summary>
/// <param name="ClientID">客户端ID</param>
/// <param name="Zqdm">证券代码</param>
/// <param name="Count">证券合约数量</param>
/// <param name="Result">同</param>
/// <param name="ErrInfo">同</param>
[DllImport("tdxtraderapi.dll", CharSet = CharSet.Ansi)]
public static extern void GetQuotes(int ClientID, string[] Zqdm, int Count, IntPtr[] Result, IntPtr[] ErrInfo);
#region ⾼级批量版,暂未测试
这个是我见过的⽐较好的⼀个纯交易类的接⼝了,基于这些接⼝的开发⾮常灵活,定制化程度很⾼,⼏乎可以完成绝⼤多数功能,交易速度可以到达毫秒级(不考虑极端地理情况)。缺点是这个是交易接⼝,还需要⾏情接⼝(尤其是LEVEL2)的⾏情解析,配合起来才爽。
3、券商柜台的第三⽅接⼝
这个是绝⼤多数普通客户没法调⽤的接⼝,只为特定的VIP客户和机构使⽤,与券商的接⼊前端在同⼀局域⽹,经过本⼈测试,⼏乎是微秒级的交易速度了。同时服务器会放置于交易所托管机房,本⾝的容灾能⼒最强。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论