Beispiel #1
0
 /// <summary>
 /// 控件添加方法
 /// </summary>
 public override void OnAdd()
 {
     base.OnAdd();
     if (m_gridTransaction == null)
     {
         m_latestData                    = new SecurityLatestData();
         m_gridTransaction               = new GridA();
         m_gridTransaction.BackColor     = COLOR.EMPTY;
         m_gridTransaction.BorderColor   = COLOR.EMPTY;
         m_gridTransaction.GridLineColor = COLOR.EMPTY;
         m_gridTransaction.HeaderVisible = false;
         m_gridTransaction.SelectionMode = GridSelectionMode.SelectNone;
         AddControl(m_gridTransaction);
         GridColumn dateColumn = new GridColumn();
         dateColumn.Width = 80;
         m_gridTransaction.AddColumn(dateColumn);
         GridColumn priceColumn = new GridColumn();
         priceColumn.Width = 70;
         m_gridTransaction.AddColumn(priceColumn);
         GridColumn volumeColumn = new GridColumn();
         volumeColumn.Width = 100;
         m_gridTransaction.AddColumn(volumeColumn);
         m_gridTransaction.Update();
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获取最新数据
        /// </summary>
        /// <param name="code">代码</param>
        /// <param name="latestData">最新数据</param>
        /// <returns>状态</returns>
        public static int GetLatestData(String code, ref SecurityLatestData latestData)
        {
            int state = 0;

            lock (m_latestDatas)
            {
                if (m_latestDatas.ContainsKey(code))
                {
                    latestData.Copy(m_latestDatas[code]);
                    state = 1;
                }
            }
            return(state);
        }
Beispiel #3
0
        /// <summary>
        /// 根据字符串获取新浪最新数据
        /// </summary>
        /// <param name="str">数据字符串</param>
        /// <param name="formatType">格式</param>
        /// <param name="datas">最新数据</param>
        /// <returns>状态</returns>
        public static int GetLatestDatasBySinaStr(String str, int formatType, List <SecurityLatestData> datas)
        {
            String[] strs   = str.Split(new String[] { ";\n" }, StringSplitOptions.RemoveEmptyEntries);
            int      strLen = strs.Length;

            for (int i = 0; i < strLen; i++)
            {
                SecurityLatestData latestData = new SecurityLatestData();
                String             dataStr    = strs[i];
                GetLatestDataBySinaStr(strs[i], formatType, ref latestData);
                if (latestData.m_date > 0)
                {
                    datas.Add(latestData);
                }
            }
            return(1);
        }
Beispiel #4
0
 /// <summary>
 /// 比较是否相同
 /// </summary>
 /// <param name="data">数据</param>
 /// <returns>是否相同</returns>
 public bool Equal(SecurityLatestData data)
 {
     if (data == null)
     {
         return(false);
     }
     if (m_amount == data.m_amount &&
         m_buyVolume1 == data.m_buyVolume1 &&
         m_buyVolume2 == data.m_buyVolume2 &&
         m_buyVolume3 == data.m_buyVolume3 &&
         m_buyVolume4 == data.m_buyVolume4 &&
         m_buyVolume5 == data.m_buyVolume5 &&
         m_buyPrice1 == data.m_buyPrice1 &&
         m_buyPrice2 == data.m_buyPrice2 &&
         m_buyPrice3 == data.m_buyPrice3 &&
         m_buyPrice4 == data.m_buyPrice4 &&
         m_buyPrice5 == data.m_buyPrice5 &&
         m_close == data.m_close &&
         m_date == data.m_date &&
         m_high == data.m_high &&
         m_innerVol == data.m_innerVol &&
         m_lastClose == data.m_lastClose &&
         m_low == data.m_low &&
         m_open == data.m_open &&
         m_openInterest == data.m_openInterest &&
         m_outerVol == data.m_outerVol &&
         m_securityCode == data.m_securityCode &&
         m_securityName == data.m_securityName &&
         m_sellVolume1 == data.m_sellVolume1 &&
         m_sellVolume2 == data.m_sellVolume2 &&
         m_sellVolume3 == data.m_sellVolume3 &&
         m_sellVolume4 == data.m_sellVolume4 &&
         m_sellVolume5 == data.m_sellVolume5 &&
         m_sellPrice1 == data.m_sellPrice1 &&
         m_sellPrice2 == data.m_sellPrice2 &&
         m_sellPrice3 == data.m_sellPrice3 &&
         m_sellPrice4 == data.m_sellPrice4 &&
         m_sellPrice5 == data.m_sellPrice5 &&
         m_settlePrice == data.m_settlePrice &&
         m_turnoverRate == data.m_turnoverRate &&
         m_volume == data.m_volume)
     {
         return(true);
     }
     return(false);
 }
Beispiel #5
0
 /// <summary>
 /// 复制数据
 /// </summary>
 /// <param name="data">数据</param>
 public void Copy(SecurityLatestData data)
 {
     if (data == null)
     {
         return;
     }
     m_amount       = data.m_amount;
     m_buyVolume1   = data.m_buyVolume1;
     m_buyVolume2   = data.m_buyVolume2;
     m_buyVolume3   = data.m_buyVolume3;
     m_buyVolume4   = data.m_buyVolume4;
     m_buyVolume5   = data.m_buyVolume5;
     m_buyPrice1    = data.m_buyPrice1;
     m_buyPrice2    = data.m_buyPrice2;
     m_buyPrice3    = data.m_buyPrice3;
     m_buyPrice4    = data.m_buyPrice4;
     m_buyPrice5    = data.m_buyPrice5;
     m_close        = data.m_close;
     m_date         = data.m_date;
     m_high         = data.m_high;
     m_innerVol     = data.m_innerVol;
     m_lastClose    = data.m_lastClose;
     m_low          = data.m_low;
     m_open         = data.m_open;
     m_openInterest = data.m_openInterest;
     m_outerVol     = data.m_outerVol;
     m_securityCode = data.m_securityCode;
     m_securityName = data.m_securityName;
     m_sellVolume1  = data.m_sellVolume1;
     m_sellVolume2  = data.m_sellVolume2;
     m_sellVolume3  = data.m_sellVolume3;
     m_sellVolume4  = data.m_sellVolume4;
     m_sellVolume5  = data.m_sellVolume5;
     m_sellPrice1   = data.m_sellPrice1;
     m_sellPrice2   = data.m_sellPrice2;
     m_sellPrice3   = data.m_sellPrice3;
     m_sellPrice4   = data.m_sellPrice4;
     m_sellPrice5   = data.m_sellPrice5;
     m_settlePrice  = data.m_settlePrice;
     m_turnoverRate = data.m_turnoverRate;
     m_volume       = data.m_volume;
 }
Beispiel #6
0
        /// <summary>
        /// 计算指标
        /// </summary>
        /// <param name="id">指标ID</param>
        /// <param name="code">代码</param>
        /// <returns>返回数据</returns>
        public static Dictionary <String, double> CalculateIndicatorExtern(int id, String code)
        {
            Dictionary <String, double> list = new Dictionary <String, double>();

            if (m_indicators.ContainsKey(id) &&
                SecurityService.m_historyDatas.ContainsKey(code) &&
                SecurityService.m_latestDatas.ContainsKey(code))
            {
                CIndicator        indicator  = m_indicators[id];
                List <CIndicator> indicators = new List <CIndicator>();
                indicators.Add(indicator);
                List <SecurityData> datas            = new List <SecurityData>();
                List <SecurityData> oldSecurityDatas = SecurityService.m_historyDatas[code];
                int oldSecurityDatasSize             = oldSecurityDatas.Count;
                for (int i = 0; i < oldSecurityDatasSize; i++)
                {
                    datas.Add(oldSecurityDatas[i]);
                }
                SecurityLatestData latestData = SecurityService.m_latestDatas[code];
                SecurityData       newData    = new SecurityData();
                StockService.GetSecurityData(latestData, latestData.m_lastClose, 1440, 1, ref newData);
                datas.Add(newData);
                CTable dataSource = indicator.DataSource;
                int[]  fields     = new int[] { KeyFields.CLOSE_INDEX, KeyFields.HIGH_INDEX, KeyFields.LOW_INDEX, KeyFields.OPEN_INDEX, KeyFields.VOL_INDEX, KeyFields.AMOUNT_INDEX };
                SecurityDataHelper.BindHistoryDatas(m_chart, dataSource, indicators, fields, datas);
                datas.Clear();
                int rowsCount     = dataSource.RowsCount;
                int variablesSize = indicator.MainVariables.Count;
                if (rowsCount > 0)
                {
                    foreach (String name in indicator.MainVariables.Keys)
                    {
                        int    field = indicator.MainVariables[name];
                        double value = dataSource.Get2(rowsCount - 1, field);
                        list[name] = value;
                    }
                }
                dataSource.Clear();
            }
            return(list);
        }
Beispiel #7
0
        /// <summary>
        /// 获取股票历史数据
        /// </summary>
        /// <param name="latestData">最新数据</param>
        /// <param name="lastClose">上一期收盘价</param>
        /// <param name="cycle">周期</param>
        /// <param name="subscription">复权模式</param>
        /// <param name="securityData">历史数据</param>
        /// <returns>历史数据</returns>
        public static void GetSecurityData(SecurityLatestData latestData, double lastClose, int cycle, int subscription, ref SecurityData securityData)
        {
            if (cycle <= 60)
            {
                securityData.m_date = GetDivideDate(latestData.m_date, 60 * 60);
            }
            else
            {
                securityData.m_date = (long)latestData.m_date / (3600 * 24) * (3600 * 24);
            }
            //前复权计算
            double factor = 1;

            if (lastClose > 0 && latestData.m_lastClose > 0 && subscription == 2)
            {
                factor = lastClose / latestData.m_lastClose;
            }
            securityData.m_close  = latestData.m_close * factor;
            securityData.m_high   = latestData.m_high * factor;
            securityData.m_low    = latestData.m_low * factor;
            securityData.m_open   = latestData.m_open * factor;
            securityData.m_volume = latestData.m_volume;
            securityData.m_amount = latestData.m_amount;
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="param"></param>
        public void DealStrategyThread(object param)
        {
            SecurityLatestData latestData = param as SecurityLatestData;

            if (latestData == null)
            {
                return;
            }

            if (m_securityStrategySettingCurrnet == null || m_securityStrategySettingCurrnet.m_strategyType != 0)
            {
                return;
            }

            SecurityRangeTradeCondition securityRangeTradeCondition
                = JsonConvert.DeserializeObject <SecurityRangeTradeCondition>(m_securityStrategySettingCurrnet.m_strategySettingInfo);

            if (securityRangeTradeCondition == null)
            {
                return;
            }

            bool  isInitBuild      = securityRangeTradeCondition.m_initBuildFlag;
            float bottomRangePrice = securityRangeTradeCondition.m_bottomRangePrice;
            float topRangePrice    = securityRangeTradeCondition.m_topRangePrice;

            // 当前价格超过了区间的上限价格或者低于区间的下限,则不做处理
            if (latestData.m_close > topRangePrice || latestData.m_close < bottomRangePrice)
            {
                return;
            }
            // 已经建仓完成
            if (isInitBuild)
            {
                bool  isBasePrice      = securityRangeTradeCondition.m_isBasePrice;
                float lastDealPrice    = securityRangeTradeCondition.m_lastDealPrice;
                int   buyCount         = securityRangeTradeCondition.m_buyCount;
                int   sellCount        = securityRangeTradeCondition.m_sellCount;
                float lowLastDealBuy   = securityRangeTradeCondition.m_lowLastDealBuy;
                float overLastDealSell = securityRangeTradeCondition.m_overLastDealSell;
                bool  isCrossBuy       = securityRangeTradeCondition.m_isCrossBuy;
                bool  isCrossSell      = securityRangeTradeCondition.m_isCrossSell;

                // 当前价格和上次委托未成交价格的比较
                double diffPrice1 = latestData.m_close - m_lastCommissionNoTradePrice;
                if (diffPrice1 == 0)
                {
                    return;
                }
                if (diffPrice1 > 0 && diffPrice1 < overLastDealSell)
                {
                    return;
                }
                if (diffPrice1 < 0 && Math.Abs(diffPrice1) < lowLastDealBuy)
                {
                    return;
                }

                // 计算当前价格和上次成交价格的差值
                double diffPrice = latestData.m_close - lastDealPrice;
                if (diffPrice > 0)
                {
                    SecurityPosition postion = null;
                    if (!m_dictSecurityPositions.TryGetValue(latestData.m_code, out postion))
                    {
                        // 没有持仓信息,不做处理
                        return;
                    }

                    // 高于上次成交价格
                    int readSellCount = 0;
                    int sepaCount     = (int)(diffPrice / overLastDealSell);
                    if (sepaCount < 1)
                    {
                        // 价格没有达到预期值
                        return;
                    }
                    if (isCrossSell)
                    {
                        readSellCount = sepaCount * sellCount;
                    }
                    else
                    {
                        readSellCount = sellCount;
                    }

                    if (readSellCount < 100)
                    {
                        return;
                    }

                    // 股票余额小于可卖数量
                    if (postion.m_stockBalance < readSellCount)
                    {
                        readSellCount = (int)postion.m_stockBalance;
                    }

                    OrderInfo info = new OrderInfo();
                    info.m_code  = CStrA.ConvertDBCodeToDealCode(latestData.m_code);
                    info.m_price = (float)Math.Round(latestData.m_close, 2);
                    info.m_qty   = readSellCount;
                    m_lastCommissionNoTradePrice = info.m_price;
                    AutoTradeService.Sell(info);
                    Thread.Sleep(3000);
                    THSDealInfo req = new THSDealInfo();
                    req.m_operateType = 4;
                    req.m_reqID       = DataCenter.ThsDealService.GetRequestID();
                    DataCenter.ThsDealService.AddTHSDealReq(req);
                }
                else if (diffPrice < 0)
                {
                    if (m_securityTradingAccount == null)
                    {
                        // 没有资金账户信息
                        return;
                    }

                    // 低于上次成交价格
                    int readBuyCount = 0;
                    int sepaCount    = (int)(Math.Abs(diffPrice) / overLastDealSell);
                    if (sepaCount < 1)
                    {
                        // 价格没有达到预期值
                        return;
                    }
                    if (isCrossBuy)
                    {
                        readBuyCount = sepaCount * buyCount;
                    }
                    else
                    {
                        readBuyCount = buyCount;
                    }

                    if (readBuyCount < 100)
                    {
                        return;
                    }

                    int capitalAllowBuyCount = (int)((m_securityTradingAccount.m_capitalBalance - m_securityTradingAccount.m_frozenCash) / latestData.m_close) / 100 * 100;
                    // 资金余额小于可买的数量
                    if (capitalAllowBuyCount < readBuyCount)
                    {
                        readBuyCount = capitalAllowBuyCount;
                    }

                    OrderInfo info = new OrderInfo();
                    info.m_code  = CStrA.ConvertDBCodeToDealCode(latestData.m_code);
                    info.m_price = (float)Math.Round(latestData.m_close, 2);
                    info.m_qty   = readBuyCount;
                    m_lastCommissionNoTradePrice = info.m_price;
                    AutoTradeService.Buy(info);
                    Thread.Sleep(3000);
                    THSDealInfo req = new THSDealInfo();
                    req.m_operateType = 3;
                    req.m_reqID       = DataCenter.ThsDealService.GetRequestID();
                    DataCenter.ThsDealService.AddTHSDealReq(req);
                }
            }
            else
            {
            }
        }
Beispiel #9
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);
        }
Beispiel #10
0
 /// <summary>
 /// 重绘背景方法
 /// </summary>
 /// <param name="paint">绘图对象</param>
 public void OnPaintBackground(CPaint paint)
 {
     if (m_k != 0 && m_b != 0)
     {
         if (IsClick)
         {
             int a = 0, r = 0, g = 0, b = 0;
             COLOR.ToARGB(paint, m_backColor, ref a, ref r, ref g, ref b);
             RECT bRect = new RECT(m_location.x - m_tick3, m_location.y - m_tick3, m_location.x + m_tick3, m_location.y + m_tick3);
             if (m_tick3 < 400)
             {
                 paint.FillEllipse(COLOR.ARGB(200 - 200 * m_tick3 / 400, r, g, b), bRect);
             }
             paint.DrawEllipse(m_backColor, 2, 0, bRect);
             m_tick3 += 40;
             bRect    = new RECT(m_location.x - m_tick4, m_location.y - m_tick4, m_location.x + m_tick4, m_location.y + m_tick4);
             if (m_tick4 < 300)
             {
                 paint.FillEllipse(COLOR.ARGB(150 - 150 * m_tick4 / 400, r, g, b), bRect);
             }
             m_tick4 += 20;
             bRect    = new RECT(m_location.x - m_tick5, m_location.y - m_tick5, m_location.x + m_tick5, m_location.y + m_tick5);
             if (m_tick5 < 200)
             {
                 paint.FillEllipse(COLOR.ARGB(100 - 100 * m_tick5 / 400, r, g, b), bRect);
             }
             m_tick5 += 10;
         }
         else
         {
             RECT drawRect = new RECT(m_location.x - m_tick, m_location.y - m_tick, m_location.x + m_tick, m_location.y + m_tick);
             paint.FillGradientEllipse(m_backColor, COLOR.RatioColor(paint, m_backColor, 1.1), drawRect, 90);
             paint.DrawEllipse(m_backColor, 2, 0, new RECT(m_location.x - 20, m_location.y - 20, m_location.x + 20, m_location.y + 20));
         }
         if (m_tick2 % 5 == 0)
         {
             if (m_mode == 0)
             {
                 m_tick++;
                 if (m_tick > 10)
                 {
                     m_mode = 1;
                 }
             }
             else if (m_mode == 1)
             {
                 m_tick--;
                 if (m_tick < 4)
                 {
                     m_mode = 0;
                 }
             }
         }
         m_tick2++;
         if (m_tick2 > 1000)
         {
             m_tick2 = 0;
         }
         if (m_security != null)
         {
             SecurityLatestData latestData = new SecurityLatestData();
             if (SecurityService.GetLatestData(m_security.m_code, ref latestData) == 0)
             {
                 latestData.m_securityName = m_security.m_name;
             }
             if (IsClick)
             {
                 FONT   nFont = new FONT("Arial", 30, true, false, false);
                 FONT   iFont = new FONT("SimSum", 30, true, false, false);
                 String name  = m_security.m_name;
                 SIZE   tSize = paint.TextSize(name, iFont);
                 int    x     = m_location.x - tSize.cx / 2;
                 int    mid   = x + tSize.cx / 2;
                 int    y     = m_location.y - 90;
                 RECT   tRect = new RECT(x, y, x + tSize.cx, y + tSize.cy);
                 paint.DrawText(name, m_backColor, iFont, tRect);
                 double diff = 0;
                 if (latestData.m_lastClose > 0)
                 {
                     diff = 100 * (latestData.m_close - latestData.m_lastClose) / latestData.m_lastClose;
                 }
                 y += tSize.cy;
                 String strClose = latestData.m_close.ToString();
                 tSize = paint.TextSize(strClose, nFont);
                 x     = mid - tSize.cx / 2;
                 tRect = new RECT(x, y, x + tSize.cx, y + tSize.cy);
                 if (diff >= 0)
                 {
                     paint.DrawText(strClose, COLOR.ARGB(255, 82, 82), nFont, tRect);
                 }
                 else
                 {
                     paint.DrawText(strClose, COLOR.ARGB(82, 255, 82), nFont, tRect);
                 }
                 y += tSize.cy;
                 String value = diff.ToString("0.00") + "%";
                 if (diff >= 0)
                 {
                     value = "+" + value;
                 }
                 if (latestData.m_close == 0)
                 {
                     value = "停牌";
                 }
                 tSize = paint.TextSize(value, nFont);
                 x     = mid - tSize.cx / 2;
                 tRect = new RECT(x, y, x + tSize.cx, y + tSize.cy);
                 if (diff >= 0)
                 {
                     paint.DrawText(value, COLOR.ARGB(255, 82, 82), nFont, tRect);
                 }
                 else
                 {
                     paint.DrawText(value, COLOR.ARGB(82, 255, 82), nFont, tRect);
                 }
                 y += tSize.cy;
                 double volume = latestData.m_volume / 100;
                 String unit   = "";
                 if (volume > 100000000)
                 {
                     volume /= 100000000;
                     unit    = "亿";
                 }
                 else if (volume > 10000)
                 {
                     volume /= 10000;
                     unit    = "万";
                 }
                 String strVol = (volume).ToString("0.00") + unit;
                 tSize = paint.TextSize(strVol, nFont);
                 x     = mid - tSize.cx / 2;
                 tRect = new RECT(x, y, x + tSize.cx, y + tSize.cy);
                 paint.DrawText(strVol, COLOR.ARGB(255, 255, 0), nFont, tRect);
             }
             else
             {
                 FONT   iFont = new FONT("SimSum", 30, true, false, false);
                 String name  = m_security.m_name;
                 SIZE   tSize = paint.TextSize(name, iFont);
                 int    x     = m_location.x - tSize.cx / 2;
                 int    mid   = x + tSize.cx / 2;
                 int    y     = m_location.y - 60;
                 RECT   tRect = new RECT(x, y, x + tSize.cx, y + tSize.cy);
                 paint.DrawText(name, m_backColor, iFont, tRect);
             }
         }
     }
 }
Beispiel #11
0
        /// <summary>
        /// 数据落地线程工作
        /// </summary>
        public static void StartWork3()
        {
            //复制数据
            LoadHistoryDatas();
            GetMinuteDatas();
            //新旧数据合并
            foreach (String oCode in m_historyDatas.Keys)
            {
                if (!m_latestDatas.ContainsKey(oCode) || !m_historyDatas.ContainsKey(oCode))
                {
                    continue;
                }
                SecurityLatestData  securityLatestData = m_latestDatas[oCode];
                List <SecurityData> oldSecurityDatas = m_historyDatas[oCode];
                SecurityData        oldSecurityData = oldSecurityDatas[oldSecurityDatas.Count - 1];
                int myear = 0, mmonth = 0, mday = 0, mhour = 0, mmin = 0, msec = 0, mmsec = 0;
                CStrA.M130(oldSecurityData.m_date, ref myear, ref mmonth, ref mday, ref mhour, ref mmin, ref msec, ref mmsec);
                int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, msec2 = 0;
                CStrA.M130(securityLatestData.m_date, ref year, ref month, ref day, ref hour, ref min, ref sec, ref msec2);
                if (year >= myear && month >= mmonth && day >= mday)
                {
                    SecurityData nSecurityData = new SecurityData();
                    nSecurityData.m_amount = securityLatestData.m_amount;
                    nSecurityData.m_close  = securityLatestData.m_close;
                    nSecurityData.m_date   = securityLatestData.m_date;
                    nSecurityData.m_high   = securityLatestData.m_high;
                    nSecurityData.m_low    = securityLatestData.m_low;
                    nSecurityData.m_open   = securityLatestData.m_open;
                    nSecurityData.m_volume = securityLatestData.m_volume;
                    if (day == mday)
                    {
                        m_historyDatas[oCode].RemoveAt(m_historyDatas[oCode].Count - 1);
                    }
                    m_historyDatas[oCode].Add(nSecurityData);
                }
            }
            String outputFileTemplate = DataCenter.GetAppPath() + "\\day\\{0}.txt";
            String fileInfo           = "{0} {1} 日线 前复权\r\n";
            String title         = "      日期	    开盘	    最高	    最低	    收盘	    成交量	    成交额\r\n";
            String lineTemp      = "{0},{1},{2},{3},{4},{5},{6}\r\n";
            String timeFormatStr = "yyyy-MM-dd";

            //写入文件
            foreach (String code in m_historyDatas.Keys)
            {
                List <SecurityData> temp3   = m_historyDatas[code];
                StringBuilder       strbuff = new StringBuilder();
                strbuff.Append(String.Format(fileInfo, m_codedMap[code].m_code, m_codedMap[code].m_name));
                strbuff.Append(title);
                foreach (SecurityData sdt in temp3)
                {
                    strbuff.Append(String.Format(lineTemp,                                                  //
                                                 CStr.ConvertNumToDate(sdt.m_date).ToString(timeFormatStr), //
                                                 sdt.m_open,                                                //
                                                 sdt.m_high,                                                //
                                                 sdt.m_low,                                                 //
                                                 sdt.m_close,                                               //
                                                 sdt.m_volume,                                              //
                                                 sdt.m_amount));
                }
                strbuff.Append("数据来源:通达信\r\n");
                CFileA.Write(String.Format(outputFileTemplate, code), strbuff.ToString());
            }
        }
Beispiel #12
0
        /// <summary>
        /// 开始工作
        /// </summary>
        private static void StartWork()
        {
            //加载代码表//step 1
            String codes = "";

            if (m_codedMap.Count == 0)
            {
                Dictionary <String, KwItem> items = EMSecurityService.KwItems;
                foreach (KwItem item in items.Values)
                {
                    GSecurity security = new GSecurity();
                    security.m_code    = item.Code;
                    security.m_name    = item.Name;
                    security.m_pingyin = item.Pingyin;
                    security.m_type    = item.Type;
                    if (!security.m_code.StartsWith("A"))
                    {
                        m_codedMap[security.m_code] = security;
                        codes += security.m_code;
                        codes += ",";
                    }
                }
            }
            while (true)
            {
                if (codes != null && codes.Length > 0)
                {
                    if (codes.EndsWith(","))
                    {
                        codes.Remove(codes.Length - 1);
                    }
                    String[] strCodes    = codes.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    int      codesSize   = strCodes.Length;
                    String   latestCodes = "";
                    for (int i = 0; i < codesSize; i++)
                    {
                        latestCodes += strCodes[i];
                        if (i == codesSize - 1 || (i > 0 && i % 50 == 0))
                        {
                            String latestDatasResult = StockService.GetSinaLatestDatasStrByCodes(latestCodes);
                            if (latestDatasResult != null && latestDatasResult.Length > 0)
                            {
                                List <SecurityLatestData> latestDatas = new List <SecurityLatestData>();
                                StockService.GetLatestDatasBySinaStr(latestDatasResult, 0, latestDatas);
                                String[] subStrs         = latestDatasResult.Split(new String[] { ";\n" }, StringSplitOptions.RemoveEmptyEntries);
                                int      latestDatasSize = latestDatas.Count;
                                for (int j = 0; j < latestDatasSize; j++)
                                {
                                    SecurityLatestData latestData = latestDatas[j];
                                    if (latestData.m_close == 0)
                                    {
                                        latestData.m_close = latestData.m_buyPrice1;
                                    }
                                    if (latestData.m_close == 0)
                                    {
                                        latestData.m_close = latestData.m_sellPrice1;
                                    }
                                    lock (m_latestDatas)
                                    {
                                        m_latestDatasStr[latestData.m_code] = subStrs[j];
                                        //bool append = true;
                                        //if (m_latestDatas.ContainsKey(latestData.m_code))
                                        //{
                                        //    if (!m_latestDatas[CStrA.ConvertFileCodeToMemoryCode(latestData.m_code)].Equals(latestData))
                                        //    {
                                        //        append = false;
                                        //    }
                                        //}
                                        //if(append)
                                        //{
                                        //    long today = (long)DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds / 86400000;
                                        //    if (m_today < today)
                                        //    {
                                        //        m_today = today;
                                        //        String nPath = DataCenter.GetAppPath() + "\\tick\\" + DateTime.Now.ToString("yyyy-MM-dd");
                                        //        if (!Directory.Exists(nPath))
                                        //        {
                                        //            Directory.CreateDirectory(nPath);
                                        //        }
                                        //        m_newFileDir = nPath + "\\";
                                        //    }
                                        //    String line = String.Format("{0},{1},{2},{3}\r\n", latestData.m_date,//
                                        //        latestData.m_close, latestData.m_volume, latestData.m_amount);
                                        //    CFileA.Append(m_newFileDir + latestData.m_code + ".txt", line);
                                        //}
                                        if (!m_latestDatas.ContainsKey(latestData.m_code))
                                        {
                                            m_latestDatas[latestData.m_code] = latestData;
                                        }
                                        else
                                        {
                                            m_latestDatas[latestData.m_code].Copy(latestData);
                                        }
                                        if (latestData.m_code == "000001.SH")
                                        {
                                            m_shTradeTime = latestData.m_date;
                                        }
                                    }
                                }
                                latestDatas.Clear();
                            }
                            latestCodes = "";
                        }
                        else
                        {
                            latestCodes += ",";
                        }
                    }
                }
                Thread.Sleep(1);
            }
        }
Beispiel #13
0
        /// <summary>
        /// 开始工作
        /// </summary>
        private static void StartWork()
        {
            Dictionary <String, String> m_codesMap = new Dictionary <String, String>();
            String codes = "";

            while (true)
            {
                if (m_securities.Count == 0)
                {
                    String codesStr = "";
                    CFileA.Read(DataCenter.GetAppPath() + "\\codes.txt", ref codesStr);
                    String[]      strs = codesStr.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    StringBuilder sb   = new StringBuilder();
                    for (int i = 0; i < strs.Length; i++)
                    {
                        String[] subStrs  = strs[i].Split(',');
                        Security security = new Security();
                        security.m_code = subStrs[0];
                        security.m_name = subStrs[1];
                        lock (m_securities)
                        {
                            m_securities.Add(security);
                        }
                        m_codesMap[security.m_code] = security.m_name;
                        codes += security.m_code;
                        codes += ",";
                        if (!security.m_code.StartsWith("A"))
                        {
                            sb.Append(security.m_code + "," + security.m_name + "\r\n");
                        }
                    }
                    CFileA.Write(DataCenter.GetAppPath() + "\\codes.txt", sb.ToString());
                }
                if (codes != null && codes.Length > 0)
                {
                    if (codes.EndsWith(","))
                    {
                        codes.Remove(codes.Length - 1);
                    }
                    String[] strCodes    = codes.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    int      codesSize   = strCodes.Length;
                    String   latestCodes = "";
                    for (int i = 0; i < codesSize; i++)
                    {
                        latestCodes += strCodes[i];
                        if (i == codesSize - 1 || (i > 0 && i % 50 == 0))
                        {
                            String latestDatasResult = GetSinaLatestDatasStrByCodes(latestCodes);
                            if (latestDatasResult != null && latestDatasResult.Length > 0)
                            {
                                List <SecurityLatestData> latestDatas = new List <SecurityLatestData>();
                                GetLatestDatasBySinaStr(latestDatasResult, 0, latestDatas);
                                int latestDatasSize = latestDatas.Count;
                                for (int j = 0; j < latestDatasSize; j++)
                                {
                                    SecurityLatestData latestData = latestDatas[j];
                                    if (latestData.m_close == 0)
                                    {
                                        latestData.m_close = latestData.m_buyPrice1;
                                    }
                                    if (latestData.m_close == 0)
                                    {
                                        latestData.m_close = latestData.m_sellPrice1;
                                    }
                                    lock (m_latestDatas)
                                    {
                                        m_latestDatas[latestData.m_securityCode] = latestData;
                                    }
                                }
                                latestDatas.Clear();
                            }
                            latestCodes = "";
                        }
                        else
                        {
                            latestCodes += ",";
                        }
                    }
                }
                Thread.Sleep(1);
            }
        }