t d x 示例z
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text; namespace demo
{
class Program
{
static void Main(string[] args)
{
//DLL是32位的,因此必须把C#工程生成的目标平台从Any CPU改为X86,才能调用DLL;
//必须把Trade.dll等4个DLL复制到Debug或Release工程目录下; StringBuilder ErrInfo=new StringBuilder(256);
StringBuilder Result = new StringBuilder(1024*1024); GetEdition(Result);//获取交易DLL版本
Console.WriteLine(Result); OpenTdx();//打开通达信
int ClientID = Logon("119.145.12.70", 443, "2.20", "1111", "1111", string.Empty, ErrInfo);//登录
if (ClientID==-1)
{
Console.WriteLine(ErrInfo);
return;
} SendOrder(ClientID, 0, 0, "A000001", "601988", 2.5, 100, Result, ErrInfo);//下单
Console.WriteLine("下单结果: {0}", Result); GetQuote(ClientID, "601988", Result, ErrInfo);//查询五档报价
if (ErrInfo.ToString() != string.Empty)
{
Console.WriteLine(ErrInfo.ToString());
return;
}
Console.WriteLine("行情结果: {0}", Result); QueryData(ClientID, 0, Result, ErrInfo);//查询资金
if (ErrInfo.ToString()!=string.Empty)
{
Console.WriteLine(ErrInfo.ToString());
return;
}
Console.WriteLine("查询结果: {0}", Result); //批量查询多个证券的五档报价
string[] Zqdm=new string[]{"600030","600031"};
string[] Results = new string[Zqdm.Length];
string[] ErrInfos = new string[Zqdm.Length]; IntPtr[] ResultPtr = new IntPtr[Zqdm.Length];
IntPtr[] ErrInfoPtr = new IntPtr[Zqdm.Length]; for (int i = 0; i < Zqdm.Length; i++)
{
ResultPtr[i] = Marshal.AllocHGlobal(1024 * 1024);
ErrInfoPtr[i] = Marshal.AllocHGlobal(256);
} GetQuotes(ClientID, Zqdm, Zqdm.Length, ResultPtr, ErrInfoPtr); for (int i = 0; i < Zqdm.Length; i++)
{
Results[i] =Marshal.PtrToStringAnsi(ResultPtr[i]);
ErrInfos[i] = Marshal.PtrToStringAnsi(ErrInfoPtr[i]); Marshal.FreeHGlobal(ResultPtr[i]);
Marshal.FreeHGlobal(ErrInfoPtr[i]);
} Logoff(ClientID);//注销
CloseTdx();//关闭通达信 Console.ReadLine();
} [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void OpenTdx(); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void CloseTdx(); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern int Logon(string IP, short Port, string Version, string AccountNo, string JyPassword, string TxPassword, StringBuilder ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void Logoff(int ClientID); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void QueryData(int ClientID, int Category, StringBuilder Result, StringBuilder ErrInfo); [DllImport("trade.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, StringBuilder ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void CancelOrder(int ClientID, string hth, StringBuilder Result, StringBuilder ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void GetQuote(int ClientID, string Zqdm, StringBuilder Result, StringBuilder ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void GetEdition(StringBuilder Result); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void QueryHistoryData(int ClientID, int Category, string StartDate, string EndDate, StringBuilder Result, StringBuilder ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void QueryDatas(int ClientID, int[] Category, int Count, IntPtr[] Result, IntPtr[] ErrInfo); [DllImport("trade.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[] Result, IntPtr[] ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void CancelOrders(int ClientID, string[] hth, int Count, IntPtr[] Result, IntPtr[] ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void GetQuotes(int ClientID, string[] Zqdm, int Count, IntPtr[] Result, IntPtr[] ErrInfo); [DllImport("trade.dll", CharSet = CharSet.Ansi)]
public static extern void Repay(int ClientID, string Amount, StringBuilder Result, StringBuilder ErrInfo); }
}
t d x 示例z的更多相关文章
- protocol buffers的使用示例[z]
[http://blog.csdn.net/zhu_xun/article/details/19397081] protocol buffers的使用示例 如果不了解protocol buffers, ...
- EasyHook远注简单监控示例 z
http://www.csdn 123.com/html/itweb/20130827/83559_83558_83544.htm 免费开源库EasyHook(inline hook),下面是下载地址 ...
- spring与disruptor集成的简单示例[z]
[z]https://www.jb51.net/article/135475.htm disruptor不过多介绍了,描述下当前的业务场景,两个应用A,B,应用 A 向应用 B 传递数据 . 数据传送 ...
- SQL函数返回表的示例-Z
create function [dbo].[GetOperateCustGroup] ( ), ) ) returns @TempTable table (MaxPrice float,MinPri ...
- Programming Erlang 学习笔记(一)
入门 启动Shell 在cmd中输入命令”erl”,百分号(%)表示一个注释的开始,从百分号开始到这行结束的所有文本都被看做是注释. 一个完整的命令需要以一个句点和一个回车结束. 退出erlang的命 ...
- 原创:vsphere概念深入系列三:vSphere命令行管理
假设无法近距离接触物理主机,只能远程命令行管理,. 以下命令行可以起到点作用. 首先需要安装vSphere CLI工具. 启动后界面: 1.查看datastore内容 所有命令行工具都可以加上-ser ...
- NOIP练习赛题目4
肥得更高 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 自2009年以来,A.B站的历史就已经步入了农业变革的黎明期.在两站的 ...
- Linux系统中使用netcat命令的奇技淫巧
netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的 ...
- matlab 常用函数(数学建模-复习)
常用函数 fscanf(fid, '%c', inf) -> 直接读取整个文件, 因为inf表示无穷 strtrim char(num): 将num转为ASCII字符 strtok(conten ...
随机推荐
- Magic Odd Square (思维+构造)
Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both ma ...
- 2018南京icpc现场赛心得
第一次参加icpc的比赛,也是第一块奖牌,虽然只是铜,但其实打的已经很好了,稍微差一点就可以摸银了. 之前参加省赛,成为那次比赛我校唯一一个没拿奖的队伍,其实还是一直都有一些心结的,而这段时间和新的队 ...
- Qt随笔 - QSettings
QSettings类提供了持久的跨平台应用程序设置. 嗯,一句话概括QSettings-- 创建 来看一下原型: QSettings::QSettings(const QString &org ...
- 108th LeetCode Weekly Contest Binary Subarrays With Sum
In an array A of 0s and 1s, how many non-empty subarrays have sum S? Example 1: Input: A = [1,0,1,0, ...
- VBS添加Windows登陆账号
Set o=CreateObject( "Shell.Users" ) Set z=o.create("test") z.changePassword &quo ...
- SpringMVC 商城项目
1. 商城视频中有word 笔记文档
- 第五次 Scrum Meeting
第五次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/4/9 22:00 30min 大运村1号楼6F 附Github仓库:WEDO 例会照片 工作情况总结(4.9) ...
- DbUtils(二) 结果集实例
单行数据处理:ScalarHandler ArrayHandler MapHandler BeanHandler 多行数据处理:BeanListHandler Abstract ...
- 转帖 JS的基础语法2
条件语句(if.switch). 循环语句(while.do…while. for … in).跳转语句(break,continue) 1.条件语句 Ø if语句 javascrip中的if语句 v ...
- Linux私房菜阅读笔记
在线man:http://www.linux.com/linux-man-pages 计算机硬件五大单元: 1.输入 2.输出 3.控制单元 4.算数逻辑单元 5.内存 CPU种类 1.RISC( ...