Ejemplo n.º 1
0
        /// <summary>
        /// 字符串转换成委托对象
        /// </summary>
        /// <param name="commissionResult"></param>
        /// <returns></returns>
        public static SecurityCommission ConvertToSecurityCommission(String commissionResult)
        {
            if (commissionResult == null || commissionResult.Length == 0)
            {
                return(null);
            }
            String[] orderFields = commissionResult.Split("	".ToCharArray());
            if (orderFields == null || orderFields.Length < 12)
            {
                return(null);
            }
            int index = 0;
            SecurityCommission commission = new SecurityCommission();

            commission.m_orderDate     = orderFields[index++];
            commission.m_stockCode     = orderFields[index++];
            commission.m_stockName     = orderFields[index++];
            commission.m_operate       = orderFields[index++];
            commission.m_remark        = orderFields[index++];
            commission.m_orderVolume   = CStrA.ConvertStrToDouble(orderFields[index++]);
            commission.m_tradeVolume   = CStrA.ConvertStrToDouble(orderFields[index++]);
            commission.m_cancelVolume  = CStrA.ConvertStrToDouble(orderFields[index++]);
            commission.m_orderPrice    = CStrA.ConvertStrToDouble(orderFields[index++]);
            commission.m_orderType     = orderFields[index++];
            commission.m_tradeAvgPrice = CStrA.ConvertStrToDouble(orderFields[index++]);
            commission.m_orderSysID    = orderFields[index++];
            return(commission);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 字符串转换成持仓对象
        /// </summary>
        /// <param name="positionResult"></param>
        /// <returns></returns>
        public static SecurityPosition ConvertToStockPosition(String positionResult)
        {
            if (positionResult == null || positionResult.Length == 0)
            {
                return(null);
            }
            String[] positionFields = positionResult.Split("	".ToCharArray());
            if (positionFields == null || positionFields.Length < 14)
            {
                return(null);
            }
            int index = 0;
            SecurityPosition position = new SecurityPosition();

            position.m_stockCode           = positionFields[index++];
            position.m_stockName           = positionFields[index++];
            position.m_stockBalance        = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_availableBalance    = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_volume              = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_frozenVolume        = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_positionProfit      = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_positionCost        = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_positionProfitRatio = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_marketPrice         = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_marketValue         = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_redemptionVolume    = CStrA.ConvertStrToDouble(positionFields[index++]);
            position.m_marketName          = positionFields[index++];
            position.m_investorAccount     = positionFields[index++];
            return(position);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 字符串转换成成交对象
        /// </summary>
        /// <param name="tradeResult"></param>
        /// <returns></returns>
        public static SecurityTrade ConvertToStockTrade(String tradeResult)
        {
            if (tradeResult == null || tradeResult.Length == 0)
            {
                return(null);
            }
            String[] tradeFields = tradeResult.Split("	".ToCharArray());
            if (tradeFields == null || tradeFields.Length < 11)
            {
                return(null);
            }
            int           index = 0;
            SecurityTrade trade = new SecurityTrade();

            trade.m_tradeDate     = tradeFields[index++];
            trade.m_stockCode     = tradeFields[index++];
            trade.m_stockName     = tradeFields[index++];
            trade.m_operate       = tradeFields[index++];
            trade.m_tradeVolume   = CStrA.ConvertStrToDouble(tradeFields[index++]);
            trade.m_tradeAvgPrice = CStrA.ConvertStrToDouble(tradeFields[index++]);
            trade.m_tradeAmount   = CStrA.ConvertStrToDouble(tradeFields[index++]);
            trade.m_orderSysID    = tradeFields[index++];
            trade.m_orderTradeID  = tradeFields[index++];
            trade.m_cancelVolume  = CStrA.ConvertStrToDouble(tradeFields[index++]);
            trade.m_stockBalance  = CStrA.ConvertStrToDouble(tradeFields[index++]);
            return(trade);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取通达信的历史数据
        /// </summary>
        /// <param name="str">数据字符串</param>
        /// <param name="datas">历史数据</param>
        /// <returns>状态</returns>
        public static int GetHistoryDatasByTdxStr(String str, List <SecurityData> datas)
        {
            String[] strs   = str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      strLen = strs.Length;

            for (int i = 2; i < strLen - 1; i++)
            {
                String[] strs2     = strs[i].Split(',');
                int      strs2Size = strs2.Length;
                if (strs2Size >= 7)
                {
                    String[] dateStrs = strs2[0].Split('-');
                    int      year = 0, month = 0, day = 0, hour = 0, minute = 0;
                    if (dateStrs.Length == 3)
                    {
                        year  = CStrA.ConvertStrToInt(dateStrs[0]);
                        month = CStrA.ConvertStrToInt(dateStrs[1]);
                        day   = CStrA.ConvertStrToInt(dateStrs[2]);
                    }
                    int si = 1;
                    if (strs2Size == 8)
                    {
                        si     = 2;
                        hour   = CStrA.ConvertStrToInt(strs2[1].Substring(0, 2));
                        minute = CStrA.ConvertStrToInt(strs2[1].Substring(2, 2));
                    }
                    double open   = CStrA.ConvertStrToDouble(strs2[si]);
                    double high   = CStrA.ConvertStrToDouble(strs2[si + 1]);
                    double low    = CStrA.ConvertStrToDouble(strs2[si + 2]);
                    double close  = CStrA.ConvertStrToDouble(strs2[si + 3]);
                    double volume = CStrA.ConvertStrToDouble(strs2[si + 4]);
                    double amount = CStrA.ConvertStrToDouble(strs2[si + 5]);
                    if (volume == 0)
                    {
                        continue;
                    }
                    if (year != 0 && month != 0 && day != 0)
                    {
                        SecurityData securityData = new SecurityData();
                        if (hour != 0 || minute != 0)
                        {
                            securityData.m_date = CStrA.M129(year, month, day, hour, minute, 0, 0) - 300;
                        }
                        else
                        {
                            securityData.m_date = CStrA.M129(year, month, day, 0, 0, 0, 0);
                        }
                        securityData.m_open   = open;
                        securityData.m_high   = high;
                        securityData.m_low    = low;
                        securityData.m_close  = close;
                        securityData.m_volume = volume;
                        securityData.m_amount = amount;
                        datas.Add(securityData);
                    }
                }
            }
            return(1);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 字符串转换成持仓对象
        /// </summary>
        /// <param name="tradingAccountResult"></param>
        /// <returns></returns>
        public static SecurityTradingAccount ConvertToStockTradingAccount(String tradingAccountResult)
        {
            if (tradingAccountResult == null || tradingAccountResult.Length == 0)
            {
                return(null);
            }
            String[] tradingAccountFields = tradingAccountResult.Split(Environment.NewLine.ToCharArray(),
                                                                       StringSplitOptions.RemoveEmptyEntries);
            if (tradingAccountFields == null || tradingAccountFields.Length < 6)
            {
                return(null);
            }
            int index = 0;
            SecurityTradingAccount stockTradingAccount = new SecurityTradingAccount();

            stockTradingAccount.m_capitalBalance = CStrA.ConvertStrToDouble(tradingAccountFields[index++]);
            stockTradingAccount.m_frozenCash     = CStrA.ConvertStrToDouble(tradingAccountFields[index++]);
            stockTradingAccount.m_available      = CStrA.ConvertStrToDouble(tradingAccountFields[index++]);
            stockTradingAccount.m_withdrawQuota  = CStrA.ConvertStrToDouble(tradingAccountFields[index++]);
            stockTradingAccount.m_stockValue     = CStrA.ConvertStrToDouble(tradingAccountFields[index++]);
            stockTradingAccount.m_totalCapital   = CStrA.ConvertStrToDouble(tradingAccountFields[index++]);
            return(stockTradingAccount);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取分时线的历史数据
        /// </summary>
        /// <param name="str">数据字符串</param>
        /// <param name="datas">历史数据</param>
        /// <returns>状态</returns>
        public static int GetHistoryDatasByMinuteStr(String str, List <SecurityData> datas)
        {
            String[] strs = str.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      strLen = strs.Length;
            double   lClose = 0, lHigh = 0, lLow = 0, lOpen = 0;
            double   lVolume = 0, lAmount = 0, fVolume = 0, fAmount = 0, sum = 0;
            int      lYear = 0, lMonth = 0, lDay = 0, lHour = 0, lMinute = 0;
            int      startIndex = 0;

            for (int i = startIndex; i < strLen; i++)
            {
                String[] strs2 = strs[i].Split(',');
                if (strs2.Length == 4)
                {
                    double date = CStrA.ConvertStrToDouble(strs2[0]);
                    double close = CStrA.ConvertStrToDouble(strs2[1]);
                    double volume = CStrA.ConvertStrToDouble(strs2[2]);
                    double amount = CStrA.ConvertStrToDouble(strs2[3]);
                    int    year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, ms = 0;
                    CStrA.M130(date, ref year, ref month, ref day, ref hour, ref minute, ref second, ref ms);
                    if (hour * 60 + minute >= 899)
                    {
                        hour   = 14;
                        minute = 59;
                    }
                    if (i == startIndex)
                    {
                        lClose  = close;
                        lHigh   = close;
                        lLow    = close;
                        lOpen   = close;
                        lVolume = volume;
                        lAmount = amount;
                        lYear   = year;
                        lMonth  = month;
                        lDay    = day;
                        lHour   = hour;
                        lMinute = minute;
                    }
                    bool inSameTime = false;
                    if (hour == lHour && minute == lMinute)
                    {
                        inSameTime = true;
                        if (close > lHigh)
                        {
                            lHigh = close;
                        }
                        if (close < lLow)
                        {
                            lLow = close;
                        }
                    }
                    if (!inSameTime || i == strLen - 1)
                    {
                        SecurityData data = new SecurityData();
                        data.m_date  = CStrA.M129(lYear, lMonth, lDay, lHour, lMinute, 0, 0);
                        data.m_close = lClose;
                        if (lHigh != 0)
                        {
                            data.m_high = lHigh;
                        }
                        else
                        {
                            data.m_high = lClose;
                        }
                        if (lLow != 0)
                        {
                            data.m_low = lLow;
                        }
                        else
                        {
                            data.m_low = lClose;
                        }
                        if (lOpen != 0)
                        {
                            data.m_open = lOpen;
                        }
                        else
                        {
                            data.m_open = lClose;
                        }
                        data.m_volume = lVolume - fVolume;
                        data.m_amount = lAmount - fAmount;
                        if (data.m_close != 0 && data.m_volume != 0)
                        {
                            sum            += data.m_close;
                            data.m_avgPrice = sum / (datas.Count + 1);
                            datas.Add(data);
                        }
                        fVolume = lVolume;
                        fAmount = lAmount;
                    }
                    if (!inSameTime)
                    {
                        lHigh   = close;
                        lLow    = close;
                        lOpen   = close;
                        lYear   = year;
                        lMonth  = month;
                        lDay    = day;
                        lHour   = hour;
                        lMinute = minute;
                    }
                    lClose  = close;
                    lVolume = volume;
                    lAmount = amount;
                }
            }
            return(1);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 根据字符串获取新浪的最新数据
        /// </summary>
        /// <param name="str">数据字符串</param>
        /// <param name="formatType">格式</param>
        /// <param name="data">最新数据</param>
        /// <returns>状态</returns>
        public static int GetLatestDataBySinaStr(String str, int formatType, ref SecurityLatestData data)
        {
            //分析数据
            String date = "";

            String[] strs2   = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int      strLen2 = strs2.Length;
            bool     szIndex = false;

            for (int j = 0; j < strLen2; j++)
            {
                String str2 = strs2[j];
                switch (j)
                {
                case 0:
                    data.m_code = CStrA.ConvertSinaCodeToDBCode(str2);
                    if (data.m_code.StartsWith("399"))
                    {
                        szIndex = true;
                    }
                    break;

                case 1:
                {
                    data.m_open = CStrA.ConvertStrToDouble(str2);
                    break;
                }

                case 2:
                {
                    data.m_lastClose = CStrA.ConvertStrToDouble(str2);
                    break;
                }

                case 3:
                {
                    data.m_close = CStrA.ConvertStrToDouble(str2);
                    break;
                }

                case 4:
                {
                    data.m_high = CStrA.ConvertStrToDouble(str2);
                    break;
                }

                case 5:
                {
                    data.m_low = CStrA.ConvertStrToDouble(str2);
                    break;
                }

                case 8:
                {
                    data.m_volume = CStrA.ConvertStrToDouble(str2);
                    if (szIndex)
                    {
                        data.m_volume /= 100;
                    }
                    break;
                }

                case 9:
                {
                    data.m_amount = CStrA.ConvertStrToDouble(str2);
                    break;
                }

                case 10:
                {
                    if (formatType == 0)
                    {
                        data.m_buyVolume1 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 11:
                {
                    if (formatType == 0)
                    {
                        data.m_buyPrice1 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 12:
                {
                    if (formatType == 0)
                    {
                        data.m_buyVolume2 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 13:
                {
                    if (formatType == 0)
                    {
                        data.m_buyPrice2 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 14:
                {
                    if (formatType == 0)
                    {
                        data.m_buyVolume3 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 15:
                {
                    if (formatType == 0)
                    {
                        data.m_buyPrice3 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 16:
                {
                    if (formatType == 0)
                    {
                        data.m_buyVolume4 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 17:
                {
                    if (formatType == 0)
                    {
                        data.m_buyPrice4 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 18:
                {
                    if (formatType == 0)
                    {
                        data.m_buyVolume5 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 19:
                {
                    if (formatType == 0)
                    {
                        data.m_buyPrice5 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 20:
                {
                    if (formatType == 0)
                    {
                        data.m_sellVolume1 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 21:
                {
                    if (formatType == 0)
                    {
                        data.m_sellPrice1 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 22:
                {
                    if (formatType == 0)
                    {
                        data.m_sellVolume2 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 23:
                {
                    if (formatType == 0)
                    {
                        data.m_sellPrice2 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 24:
                {
                    if (formatType == 0)
                    {
                        data.m_sellVolume3 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 25:
                {
                    if (formatType == 0)
                    {
                        data.m_sellPrice3 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 26:
                {
                    if (formatType == 0)
                    {
                        data.m_sellVolume4 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 27:
                {
                    if (formatType == 0)
                    {
                        data.m_sellPrice4 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 28:
                {
                    if (formatType == 0)
                    {
                        data.m_sellVolume5 = (int)CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 29:
                {
                    if (formatType == 0)
                    {
                        data.m_sellPrice5 = CStrA.ConvertStrToDouble(str2);
                    }
                    break;
                }

                case 30:
                    date = str2;
                    break;

                case 31:
                    date += " " + str2;
                    break;
                }
            }
            //获取时间
            if (date != null && date.Length > 0)
            {
                DateTime dateTime = Convert.ToDateTime(date);
                data.m_date = CStrA.M129(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second, 0);
            }
            //价格修正
            if (data.m_close != 0)
            {
                if (data.m_open == 0)
                {
                    data.m_open = data.m_close;
                }
                if (data.m_high == 0)
                {
                    data.m_high = data.m_close;
                }
                if (data.m_low == 0)
                {
                    data.m_low = data.m_close;
                }
            }
            return(0);
        }