读取通达信日线数据

 public class StockInfo
    {     // 日K线数据结构
        public DateTime  _Date;   // e.g. 20100304
        public decimal _Open;           // *0.01 开盘价
        public decimal _High;           // *0.01 最高价
        public decimal _Low;            // *0.01 最低价
        public decimal _Close;          // *0.01 收盘价
        public float _Amount;        // 成交额
        public int _Vol;             // 成交量(手)


        public DateTime Date
        {
          get { return _Date; }
          set{ _Date =value ;}
        }
        public decimal Open
        {
          get { return _Open; }
            set { _Open = value; }
        }
        public decimal High
        {
            get { return _High; }
            set { _High = value; }
        }
        public decimal Low
        {
            get { return _Low; }
            set { _Low = value; }
        }
        public decimal Close
        {
            get { return _Close; }
            set { _Close = value; }
        }
        public float Amount
        {
            get { return _Amount; }
            set { _Amount = value; }
        }
        public int Vol
        {
            get { return _Vol; }
            set { _Vol = value; }
        }
        }
  public   class TDX
    {
      public string path ="";
      public  List<StockInfo> GetStockInfo(string code)
      {          
          if (!File.Exists(path))
          {
              return null;
          }
          FileStream fs = File.OpenRead(path);
          BinaryReader br = new BinaryReader(fs);
          int days = (int)fs.Length / 32;
          List<StockInfo> list = new List<StockInfo>();
          for (int i = 0; i < days; i++)
          {
              StockInfo item = new StockInfo();
              //item.DataDate =DateTime.Parse(new string(br.ReadChars(8)));
              int date = br.ReadInt32();
              int year = date / 10000;
              int month = int.Parse(date.ToString().Substring(4, 2));
              int day = int.Parse(date.ToString().Substring(6, 2));
              int open = br.ReadInt32();
              int high = br.ReadInt32();
              int low = br.ReadInt32();
              int close = br.ReadInt32();
              Single amount = br.ReadSingle();
              //Int32 amount = br.ReadInt32();
              decimal am = Convert.ToDecimal(amount);
              long amstr = Convert.ToInt64(amount);
              int vol = br.ReadInt32();
              int preclose = br.ReadInt32();


              //Decimal open = Convert.ToDecimal(br.ReadSingle());
              item.Date = new DateTime(year, month, day);
              item.Open = Convert.ToDecimal(open / 100m);
              item.High = Convert.ToDecimal(high / 100m);
              item.Low = Convert.ToDecimal(low / 100m);
              item.Close = Convert.ToDecimal(close / 100m);
              item.Amount = amstr;
              item.Vol = vol;
             
              list.Add(item);
          }
          br.Close();
          fs.Close();
          return list;
      }


    }



 private void btnReadData_Click(object sender, EventArgs e)
        {
            string code = txtStockCode.Text.Trim ();
            if (code == "" || code.Length != 6) return;
            string type;
            if (code.Substring(0, 1) == "6") type = "sh";//上证指数
            else type = "sz";
            string path;
            if (type == "sh") path = @"D:\new_ztzq_v6\vipdoc\sh\lday\";
            else path =@"D:\new_ztzq_v6\vipdoc\sz\lday\";
            path = path +type+ code + ".day";


           // dataGridView.Rows.Clear();
            TDX tdx = new TDX();
            tdx.path = path;
            List<StockInfo> lstStock= tdx.GetStockInfo(txtStockCode.Text,type  );
            dataGridView.DataSource = lstStock;
            
        }



  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值