t d x例z

6316 ワード

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


	
    }
}