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的更多相关文章

  1. protocol buffers的使用示例[z]

    [http://blog.csdn.net/zhu_xun/article/details/19397081] protocol buffers的使用示例 如果不了解protocol buffers, ...

  2. EasyHook远注简单监控示例 z

    http://www.csdn 123.com/html/itweb/20130827/83559_83558_83544.htm 免费开源库EasyHook(inline hook),下面是下载地址 ...

  3. spring与disruptor集成的简单示例[z]

    [z]https://www.jb51.net/article/135475.htm disruptor不过多介绍了,描述下当前的业务场景,两个应用A,B,应用 A 向应用 B 传递数据 . 数据传送 ...

  4. SQL函数返回表的示例-Z

    create function [dbo].[GetOperateCustGroup] ( ), ) ) returns @TempTable table (MaxPrice float,MinPri ...

  5. Programming Erlang 学习笔记(一)

    入门 启动Shell 在cmd中输入命令”erl”,百分号(%)表示一个注释的开始,从百分号开始到这行结束的所有文本都被看做是注释. 一个完整的命令需要以一个句点和一个回车结束. 退出erlang的命 ...

  6. 原创:vsphere概念深入系列三:vSphere命令行管理

    假设无法近距离接触物理主机,只能远程命令行管理,. 以下命令行可以起到点作用. 首先需要安装vSphere CLI工具. 启动后界面: 1.查看datastore内容 所有命令行工具都可以加上-ser ...

  7. NOIP练习赛题目4

    肥得更高 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 自2009年以来,A.B站的历史就已经步入了农业变革的黎明期.在两站的 ...

  8. Linux系统中使用netcat命令的奇技淫巧

    netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的 ...

  9. matlab 常用函数(数学建模-复习)

    常用函数 fscanf(fid, '%c', inf) -> 直接读取整个文件, 因为inf表示无穷 strtrim char(num): 将num转为ASCII字符 strtok(conten ...

随机推荐

  1. 一款不错的Linux终端颜色设置

    PS1="\[\e[37;40m\][\[\e[32;40m\]\u\[\e[37;40m\]@\h \[\e[36;40m\]\w\[\e[0m\]]\\$ " #步骤# vi ...

  2. Selenium => Debugging “Element is not clickable at point” error

    [From] http://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error ...

  3. JavaScript学习笔记1_基础与常识

    1.六种数据类型 5种基础的:Undefined,Null,Boolean,Number,String(其中Undefined派生自Null) 1种复杂的:Object(本质是一组无序键值对) 2.字 ...

  4. vue 的计算属性computed自我理解

    类型:{ [key: string]: Function | { get: Function, set: Function } } 计算属性的结果会被缓存,除非依赖的响应式属性变化才会重新计算.注意, ...

  5. Linux——文件和文件夹的操作

    Linux有三种文件: 普通文件(包括文本文件.源码文件.可执行文件等等) 设备文件(或者成为特殊文件,linux通过设备文件与外部设备进行通讯,例如:光驱.打印机.终端.modern) 设备文件有两 ...

  6. gulp打包js

    在终端定位到你要创建目录的地方,输入 sudo mkdir js 创建文件夹,这个文件夹就是放你要压缩js文件的地方 输入 sudo vim gulpfile.js 这个js就是写gulp所有的配置信 ...

  7. Linux-Xshell5

    Linux-Xshell5 1.下载 2.安装 3.新建会话(连接) 点击新建 需要知道要连接的 IP, 查看命令   ifconfig 配置 名称可以自己命名,主机写要连接的 IP,其他的不能改 输 ...

  8. pjsip与QT进行适配

    pjsip是纯C语言写的一个sip协议库,整个代码写得还是比较模块化的,得益于此的设计,只要理解了pjsip的设计,就可以对其网络层进行扩展. 我们项目是QT作为主要开发工具,而PJSIP的库默认是利 ...

  9. css使用text-align: justify不能实现两段对其的问题解决方式

    一行文本不进行处理.还有就是强制换行的也不处理.所以你强制占满(在后面加个span)了一行他才处理 <p class="home">test test test < ...

  10. awk - Unix, Linux Command---reference

    http://www.tutorialspoint.com/unix_commands/awk.htm NAME gawk - pattern scanning and processing lang ...