Beispiel #1
0
        //显示
        public void ShowUnPacker(CT2UnPacker lpUnPack)
        {
            int count = lpUnPack.GetDatasetCount();

            for (int k = 0; k < count; k++)
            {
                Debug.Print(string.Format("第[{0}]个数据集", k));
                lpUnPack.SetCurrentDatasetByIndex(k);
                String strInfo = string.Format("记录行数:           {0}", lpUnPack.GetRowCount());
                Debug.Print(strInfo);
                strInfo = string.Format("列行数:			 {0}", lpUnPack.GetColCount());
                Debug.Print(strInfo);
                while (lpUnPack.IsEOF() == 0)
                {
                    for (int i = 0; i < lpUnPack.GetColCount(); i++)
                    {
                        String colName = lpUnPack.GetColName(i);
                        sbyte  colType = lpUnPack.GetColType(i);
                        if (!colType.Equals('R'))
                        {
                            String colValue = lpUnPack.GetStrByIndex(i);
                            String str      = string.Format("{0}:			[{1}]", colName, colValue);
                            Debug.Print(str);
                        }
                        else
                        {
                            int colLength = 0;
                            unsafe
                            {
                                void * colValue = (char *)lpUnPack.GetRawByIndex(i, &colLength);
                                string str      = string.Format("{0}:			[{1}]({2})", colName, Marshal.PtrToStringAuto(new IntPtr(colValue)), colLength);
                            }
                        }
                    }
                    lpUnPack.Next();
                }
            }
        }
Beispiel #2
0
        public void PrintUnPack(CT2UnPacker lpUnPack)
        {
            Console.WriteLine("记录行数: {0}", lpUnPack.GetRowCount());
            Console.WriteLine("列行数:{0}", lpUnPack.GetColCount());

            for (int i = 0; i < lpUnPack.GetDatasetCount(); i++)
            {
                //设置当前结果集
                lpUnPack.SetCurrentDatasetByIndex(i);

                //打印字段
                for (int j = 0; j < lpUnPack.GetColCount(); j++)
                {
                    Console.Write("{0,20:G}", lpUnPack.GetColName(j));
                }

                Console.WriteLine();

                //打印所有记录
                for (int k = 0; k < lpUnPack.GetRowCount(); k++)
                {
                    //打印每条记录
                    for (int t = 0; t < lpUnPack.GetColCount(); t++)
                    {
                        switch (lpUnPack.GetColType(t))
                        {
                        case (sbyte)'I':      //I 整数
                            Console.Write("{0,20:D}", lpUnPack.GetIntByIndex(t));
                            break;

                        case (sbyte)'C':      //C
                            Console.Write("{0,20:G}", (char)lpUnPack.GetCharByIndex(t));
                            break;

                        case (sbyte)'S':       //S
                            Console.Write("{0,20:G}", lpUnPack.GetStrByIndex(t));
                            break;

                        case (sbyte)'F':      //F
                            Console.Write("{0,20:F2}", lpUnPack.GetDoubleByIndex(t));
                            break;

                        case (sbyte)'R':      //R
                        {
                            break;
                        }

                        default:
                            // 未知数据类型
                            Console.Write("未知数据类型\n");
                            break;
                        }
                    }

                    Console.WriteLine();
                    lpUnPack.Next();
                }
            }

            Console.WriteLine();


            /*
             * while (lpUnPack.IsEOF() != 1)
             * {
             *  for (int i = 0; i < lpUnPack.GetColCount(); i++)
             *  {
             *      String colName = lpUnPack.GetColName(i);
             *      sbyte colType = lpUnPack.GetColType(i);
             *      if (!colType.Equals('R'))
             *      {
             *          String colValue = lpUnPack.GetStrByIndex(i);
             *          Console.WriteLine("{0}:{1}", colName, colValue);
             *      }
             *      else
             *      {
             *          int colLength = 0;
             *          unsafe
             *          {
             *              void* colValue = (char*)lpUnPack.GetRawByIndex(i, &colLength);
             *              string str = String.Format("{0}:[{1}]({2})", colName, Marshal.PtrToStringAuto(new IntPtr(colValue)), colLength);
             *          }
             *      }
             *  }
             *  lpUnPack.Next();
             * }
             */
        }
        public void Parse(CT2UnPacker lpUnPack)
        {
            for (int i = 0, dsLen = lpUnPack.GetDatasetCount(); i < dsLen; i++)
            {
                RawDataSet dataSet = new RawDataSet();
                dataSet.Rows = new List <RawDataRow>();
                //设置当前结果集
                lpUnPack.SetCurrentDatasetByIndex(i);

                Dictionary <int, string> columnDic = new Dictionary <int, string>();
                //数据包中字段
                for (int j = 0, hLen = lpUnPack.GetColCount(); j < hLen; j++)
                {
                    columnDic.Add(j, lpUnPack.GetColName(j));
                }

                //所有记录
                for (int k = 0, rLen = (int)lpUnPack.GetRowCount(); k < rLen; k++)
                {
                    RawDataRow row = new RawDataRow();
                    row.Columns = new Dictionary <string, DataValue>();

                    //每条记录
                    for (int t = 0, cLen = lpUnPack.GetColCount(); t < cLen; t++)
                    {
                        string    colName   = columnDic[t];
                        DataValue dataValue = new DataValue();
                        switch (lpUnPack.GetColType(t))
                        {
                        case (sbyte)'I':      //I 整数
                        {
                            dataValue.Type  = DataValueType.Int;
                            dataValue.Value = lpUnPack.GetIntByIndex(t);
                        }
                        break;

                        case (sbyte)'C':      //C
                        {
                            dataValue.Type  = DataValueType.Char;
                            dataValue.Value = lpUnPack.GetCharByIndex(t);
                        }
                        break;

                        case (sbyte)'S':       //S
                        {
                            dataValue.Type  = DataValueType.String;
                            dataValue.Value = lpUnPack.GetStrByIndex(t);
                        }
                        break;

                        case (sbyte)'F':      //F
                        {
                            dataValue.Type  = DataValueType.Float;
                            dataValue.Value = lpUnPack.GetDoubleByIndex(t);
                        }
                        break;

                        case (sbyte)'R':      //R
                        {
                            break;
                        }

                        default:
                            // 未知数据类型
                            break;
                        }

                        if (!row.Columns.ContainsKey(colName))
                        {
                            row.Columns.Add(colName, dataValue);
                        }
                    }//end to read all column for each row

                    dataSet.Rows.Add(row);

                    Console.WriteLine();
                    lpUnPack.Next();
                }//end to read rows

                _dataSets.Add(dataSet);
            }
        }
Beispiel #4
0
        public void UpdateOrderBook(int iRet, List <OrderBook> orderbooklist)
        {
            //清除旧记录
            orderbooklist.Clear();

            //读取新记录
            CT2BizMessage lpMsg; //外部所指向的消息对象的内存由SDK内部管理,外部切勿释放

            this.connMain.RecvBizMsg(iRet, out lpMsg, 5000, 1);

            int iRetCode   = lpMsg.GetErrorNo();    //获取返回码
            int iErrorCode = lpMsg.GetReturnCode(); //获取错误码
            int iFunction  = lpMsg.GetFunction();

            if (iRetCode != 0)
            {
                Debug.Print("异步接收出错:" + lpMsg.GetErrorNo().ToString() + lpMsg.GetErrorInfo());
            }
            else
            {
                //读packer
                CT2UnPacker unpacker = null;
                unsafe
                {
                    int   iLen   = 0;
                    void *lpdata = lpMsg.GetContent(&iLen);
                    unpacker = new CT2UnPacker(lpdata, (uint)iLen);
                }

                //解析
                int count = unpacker.GetDatasetCount();
                for (int k = 1; k < count; k++)
                {
                    unpacker.SetCurrentDatasetByIndex(k);
                    while (unpacker.IsEOF() == 0)
                    {
                        OrderBook ob = new OrderBook();
                        switch (iFunction)
                        {
                        case 31004:     //持仓查询
                            ob.tradecode = unpacker.GetStr("stock_code");
                            ob.volume    = unpacker.GetInt("enable_amount");
                            string positionflag = unpacker.GetStr("position_flag");
                            ob.tradedirection = (positionflag == "1") ? TradeDirection.BUY : TradeDirection.SELL;
                            if (ob.volume > 0)
                            {
                                orderbooklist.Add(ob);
                            }
                            break;

                        case 32004:     //委托查询
                            ob.entrustno = unpacker.GetInt("entrust_no");
                            ob.tradecode = unpacker.GetStr("stock_code");
                            string entrustdirection = unpacker.GetStr("entrust_direction");     //1=买,2=卖,3=...,4=...;
                            string futuresdirection = unpacker.GetStr("futures_direction");     //1=开,2=平;
                            string entruststate     = unpacker.GetStr("entrust_state");         //委托状态
                            ob.tradedirection  = (entrustdirection == "1") ? TradeDirection.BUY : TradeDirection.SELL;
                            ob.futuredirection = (futuresdirection == "1") ? FutureDirection.OPEN : FutureDirection.COVER;
                            ob.price           = unpacker.GetDouble("entrust_price");
                            int entrustvol = unpacker.GetInt("entrust_amount");
                            int dealvol    = unpacker.GetInt("deal_amount");
                            ob.volume = entrustvol - dealvol;
                            switch (entruststate)
                            {
                            case "1":            //未报
                            case "4":            //已报
                            case "6":            //部成
                                orderbooklist.Add(ob);
                                break;

                            case "5":            //废单
                            case "7":            //已成
                            case "8":            //部撤
                            case "9":            //已撤
                            case "a":            //待撤
                            case "A":            //未撤
                            case "B":            //待撤
                            case "C":            //正撤
                            case "D":            //撤认
                            case "E":            //撤废
                            case "F":            //已撤
                                break;

                            default:
                                break;
                            }
                            break;

                        default:
                            break;
                        }
                        unpacker.Next();
                    }
                }
            }
        }
        public void Parse(CT2UnPacker lpUnPack)
        {
            for (int i = 0; i < lpUnPack.GetDatasetCount(); i++)
            {
                DataSet dataSet = new DataSet();
                dataSet.Rows = new List <DataRow>();
                //设置当前结果集
                lpUnPack.SetCurrentDatasetByIndex(i);

                Dictionary <int, string> columnDic = new Dictionary <int, string>();
                //打印字段
                for (int j = 0; j < lpUnPack.GetColCount(); j++)
                {
                    columnDic.Add(j, lpUnPack.GetColName(j));
                }

                //打印所有记录
                for (int k = 0; k < lpUnPack.GetRowCount(); k++)
                {
                    DataRow row = new DataRow();
                    row.Columns = new Dictionary <string, DataValue>();

                    //打印每条记录
                    for (int t = 0; t < lpUnPack.GetColCount(); t++)
                    {
                        string colName = columnDic[t];
                        switch (lpUnPack.GetColType(t))
                        {
                        case (sbyte)'I':      //I 整数
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.Int,
                                Value = lpUnPack.GetIntByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'C':      //C
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.Char,
                                Value = lpUnPack.GetCharByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'S':       //S
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.String,
                                Value = lpUnPack.GetStrByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'F':      //F
                        {
                            DataValue dataValue = new DataValue
                            {
                                Type  = DataValueType.Float,
                                Value = lpUnPack.GetDoubleByIndex(t)
                            };


                            row.Columns.Add(colName, dataValue);
                        }
                        break;

                        case (sbyte)'R':      //R
                        {
                            break;
                        }

                        default:
                            // 未知数据类型
                            break;
                        }
                    }//end to read all column for each row

                    dataSet.Rows.Add(row);

                    Console.WriteLine();
                    lpUnPack.Next();
                }//end to read rows

                _dataSets.Add(dataSet);
            }

            /*
             * while (lpUnPack.IsEOF() != 1)
             * {
             *  for (int i = 0; i < lpUnPack.GetColCount(); i++)
             *  {
             *      String colName = lpUnPack.GetColName(i);
             *      sbyte colType = lpUnPack.GetColType(i);
             *      if (!colType.Equals('R'))
             *      {
             *          String colValue = lpUnPack.GetStrByIndex(i);
             *          Console.WriteLine("{0}:{1}", colName, colValue);
             *      }
             *      else
             *      {
             *          int colLength = 0;
             *          unsafe
             *          {
             *              void* colValue = (char*)lpUnPack.GetRawByIndex(i, &colLength);
             *              string str = String.Format("{0}:[{1}]({2})", colName, Marshal.PtrToStringAuto(new IntPtr(colValue)), colLength);
             *          }
             *      }
             *  }
             *  lpUnPack.Next();
             * }
             */
        }