正在开发一个股票分析软件,有兴趣的大家来我的博客交流一下:http://blog.sun0769.com/user1/23688/今天刚完成了读取通达信日线行情数据部份,呵呵,大概完成了整个软件的15%左右吧,下面是部份代码,我看到这里有很多人想知道怎样读取日线的行情数据,贴出来给大家分享一下,呵呵,不要全部搬抄,有些数据结构我没有贴出来,这只不过是核心部份,:)public void getDaily(String dailyFile,String m_date) {
//dailyFile 行情软件中的日线数据,m_date 只要此日之后的日线数据
DailyStruct dailyRecord; //转换后的日线记录
double lastClosePrice; //昨天收盘价
FileChannel fileChannel;
MappedByteBuffer mapBuffer;
long fileSize, count;
int date; m_records = new DataSet<String, DailyStruct>(); //清空 lastClosePrice = 0.00;
if (new File(dailyFile).exists()) {
try {
fileChannel = new FileInputStream(dailyFile).getChannel();
fileSize = fileChannel.size();
mapBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
mapBuffer.order(ByteOrder.LITTLE_ENDIAN); //低字节二进制文件
count = 0;
while (count < fileSize) {
date = mapBuffer.getInt();
if (String.Of(date).compareTo(m_date) >= 0) {
dailyRecord = new DailyStruct();
dailyRecord.m_f001 = String.Of(date); //日期
dailyRecord.m_f002 = mapBuffer.getInt() / 100.00; //开盘价
dailyRecord.m_f003 = mapBuffer.getInt() / 100.00; //最低价
dailyRecord.m_f004 = mapBuffer.getInt() / 100.00; //最高价
dailyRecord.m_f005 = mapBuffer.getInt() / 100.00; //收盘价
dailyRecord.m_f006 = mapBuffer.getFloat() / 10000.00; //成交额
dailyRecord.m_f007 = mapBuffer.getInt() / 10000.00; //成交量
mapBuffer.getInt(); //保留?
dailyRecord.m_f008 = lastClosePrice; //昨收盘价
lastClosePrice = dailyRecord.m_f005;
m_records.put(dailyRecord.m_f001, dailyRecord);
count += 32;
}
}
m_records.toList();
fileChannel.close();
} catch (IOException e) {
MSG.ShowMessage("更新指数的日线数据文件(" + dailyFile + ")时,出现了以下错误:\n" + e.getLocalizedMessage());
}
}
}
//dailyFile 行情软件中的日线数据,m_date 只要此日之后的日线数据
DailyStruct dailyRecord; //转换后的日线记录
double lastClosePrice; //昨天收盘价
FileChannel fileChannel;
MappedByteBuffer mapBuffer;
long fileSize, count;
int date; m_records = new DataSet<String, DailyStruct>(); //清空 lastClosePrice = 0.00;
if (new File(dailyFile).exists()) {
try {
fileChannel = new FileInputStream(dailyFile).getChannel();
fileSize = fileChannel.size();
mapBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
mapBuffer.order(ByteOrder.LITTLE_ENDIAN); //低字节二进制文件
count = 0;
while (count < fileSize) {
date = mapBuffer.getInt();
if (String.Of(date).compareTo(m_date) >= 0) {
dailyRecord = new DailyStruct();
dailyRecord.m_f001 = String.Of(date); //日期
dailyRecord.m_f002 = mapBuffer.getInt() / 100.00; //开盘价
dailyRecord.m_f003 = mapBuffer.getInt() / 100.00; //最低价
dailyRecord.m_f004 = mapBuffer.getInt() / 100.00; //最高价
dailyRecord.m_f005 = mapBuffer.getInt() / 100.00; //收盘价
dailyRecord.m_f006 = mapBuffer.getFloat() / 10000.00; //成交额
dailyRecord.m_f007 = mapBuffer.getInt() / 10000.00; //成交量
mapBuffer.getInt(); //保留?
dailyRecord.m_f008 = lastClosePrice; //昨收盘价
lastClosePrice = dailyRecord.m_f005;
m_records.put(dailyRecord.m_f001, dailyRecord);
count += 32;
}
}
m_records.toList();
fileChannel.close();
} catch (IOException e) {
MSG.ShowMessage("更新指数的日线数据文件(" + dailyFile + ")时,出现了以下错误:\n" + e.getLocalizedMessage());
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货