加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

我为C狂0002:通达信5分钟和1分钟K线数据解密

(2020-05-05 18:19:08)
标签:

股票

创业板

期货

财经

上证

分类: 我为C狂
//通达信股票1分钟K线数据和5分钟K线数据,文件为szXXXXXX.lc1和shXXXXXX.lc1或szXXXXXX.lc5和shXXXXXX.lc5,二进制文件
//多空俊秀编译测试,完全正确无误。微博中#include中只能用引号
#include “iostream“
#include ”fstream”
#include“string“
#include ”iomanip”
using namespace std;
struct eachday //通达信5分钟和1分钟K线数据结构
{
uint16_t time1; //年月日
uint16_t time2; //小时分钟
float open; //开盘价
float high; //收盘价
float low; //最低价
float close; //收盘价
float vol1; //成交额,元
int vol2; //成交量,股
int reserve; //保留字
};

int main()
{
eachday A1;
string name;
string str1("C:\\专业投机\\bhzqrzrq\\vipdoc\\");//改为自己系统里的相应路径
string str2("\\fzline\\");//对于一分钟数,用string str2("\\minline\\");
string str3(".lc5");//对于一分钟数,用string str3(".lc1");
string str4;
cout << "请输入股票代码:";
cin >> name;
if (name[0] == '6')
str4 = "sh";
else
str4 = "sz";
ifstream fin;
string file = str1 + str4 + str2 +str4+ name + str3;
fin.open(file, ios_base::in | ios_base::binary);//可以不需要用file.c_str()转换成C风格字符串
if (fin.is_open())
{
cout << "Here are the current contents of the " << file << " file:\n";
cout << setw(10) << "日期" << setw(15) << "开盘价" << setw(10) << "最高价" << setw(10) << "最低价" << setw(10) 
<< "收盘价" << setw(16) << "成交额(元)" << setw(18) << "成交量(股)" << setw(12) << "保留值" << endl;
while (fin.read((char*)&A1, sizeof A1))
{
int year =floor(A1.time1 / 2048) + 2004; //年计算
int month =floor((A1.time1 % 2048) / 100); //月计算
int day = (A1.time1 % 2048) % 100; //日计算
int hour = A1.time2 / 60; //小时计算
int minute = A1.time2 % 60; //分钟计算
cout << fixed << right << setprecision(3);
cout << setw(4) <<year<< setw(2)<<setfill('0')<< month<< setw(2) << day <<' '<<setw(2)<<hour<<":"<< setw(2) 
<< minute<<setfill(' ')<<setw(10) << A1.open << setw(10) << A1.high << setw(10) << A1.low << setw(10) << A1.close
<< setw(15) << A1.vol1 << setw(15) << A1.vol2 << setw(15) << A1.reserve << endl;
}
}
fin.close();
return 0;
}
5分钟输出例子:
我为C狂0002:通达信5分钟和1分钟K线数据解密

一分钟输出例子:
我为C狂0002:通达信5分钟和1分钟K线数据解密

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有