2015-01-07 01:26:14 +08:00
|
|
|
|
/*
|
|
|
|
|
* KData.cpp
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2013-1-20
|
|
|
|
|
* Author: fasiondog
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "KData.h"
|
|
|
|
|
#include "StockManager.h"
|
|
|
|
|
#include "KDataBufferImp.h"
|
2019-03-19 01:41:12 +08:00
|
|
|
|
#include "indicator/crt/KDATA.h"
|
2015-01-07 01:26:14 +08:00
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
|
2019-11-10 19:45:57 +08:00
|
|
|
|
HKU_API std::ostream& operator<<(std::ostream& os, const KData& kdata) {
|
|
|
|
|
os << "KData{\n size : " << kdata.size() << "\n stock: " << kdata.getStock()
|
2020-06-10 00:17:24 +08:00
|
|
|
|
<< "\n query: " << kdata.getQuery() << "\n}";
|
2015-01-07 01:26:14 +08:00
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-03 00:08:31 +08:00
|
|
|
|
string KData::toString() const {
|
|
|
|
|
std::stringstream os;
|
2019-11-10 19:45:57 +08:00
|
|
|
|
os << "KData{\n size : " << size() << "\n stock: " << getStock().toString()
|
2020-06-10 00:17:24 +08:00
|
|
|
|
<< ",\n query: " << getQuery() << "\n}";
|
2016-04-03 00:08:31 +08:00
|
|
|
|
return os.str();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
|
KData::KData(const Stock& stock, const KQuery& query) {
|
2019-03-28 02:11:13 +08:00
|
|
|
|
if (stock.isNull()) {
|
2015-01-07 01:26:14 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-01-11 01:28:54 +08:00
|
|
|
|
|
|
|
|
|
m_imp = KDataImpPtr(new KDataBufferImp(stock, query));
|
|
|
|
|
return;
|
2015-01-07 01:26:14 +08:00
|
|
|
|
#if 0
|
|
|
|
|
if (stock.isBuffer(query.kType())
|
|
|
|
|
&& query.recoverType() == KQuery::NO_RECOVER) {
|
|
|
|
|
//当Stock已缓存了该类型的K线数据,且不进行复权
|
|
|
|
|
m_imp = KDataImpPtr(new KDataImp(stock, query));
|
|
|
|
|
} else {
|
|
|
|
|
m_imp = KDataImpPtr(new KDataBufferImp(stock, query));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KData::tocsv(const string& filename) {
|
|
|
|
|
std::ofstream file(filename.c_str());
|
|
|
|
|
if (!file) {
|
2019-06-16 17:56:34 +08:00
|
|
|
|
HKU_ERROR("Can't open file! ({})", filename);
|
2015-01-07 01:26:14 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file << "date, open, high, low, close, amount, count" << std::endl;
|
|
|
|
|
file.setf(std::ios_base::fixed);
|
|
|
|
|
file.precision(4);
|
|
|
|
|
string sep = ",";
|
|
|
|
|
KRecord record;
|
|
|
|
|
for (size_t i = 0; i < size(); ++i) {
|
|
|
|
|
record = getKRecord(i);
|
2019-11-10 19:45:57 +08:00
|
|
|
|
file << record.datetime << sep << record.openPrice << sep << record.highPrice << sep
|
|
|
|
|
<< record.lowPrice << sep << record.closePrice << sep << record.transAmount << sep
|
|
|
|
|
<< record.transCount << std::endl;
|
2015-01-07 01:26:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 23:17:49 +08:00
|
|
|
|
Indicator KData::open() const {
|
|
|
|
|
return OPEN(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-19 01:41:12 +08:00
|
|
|
|
Indicator KData::close() const {
|
|
|
|
|
return CLOSE(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 23:17:49 +08:00
|
|
|
|
Indicator KData::low() const {
|
|
|
|
|
return LOW(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Indicator KData::high() const {
|
|
|
|
|
return HIGH(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Indicator KData::vol() const {
|
|
|
|
|
return VOL(*this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Indicator KData::amo() const {
|
|
|
|
|
return AMO(*this);
|
|
|
|
|
}
|
2019-03-19 01:41:12 +08:00
|
|
|
|
|
2020-07-07 00:34:25 +08:00
|
|
|
|
KData HKU_API getKData(const string& market_code, const KQuery& query) {
|
|
|
|
|
return StockManager::instance().getStock(market_code).getKData(query);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 00:17:24 +08:00
|
|
|
|
KData HKU_API getKData(const string& market_code, const Datetime& start, const Datetime& end,
|
|
|
|
|
KQuery::KType ktype, KQuery::RecoverType recoverType) {
|
|
|
|
|
KQuery query(start, end, ktype, recoverType);
|
2020-07-07 00:34:25 +08:00
|
|
|
|
return StockManager::instance().getStock(market_code).getKData(query);
|
2020-06-10 00:17:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 22:52:50 +08:00
|
|
|
|
KData HKU_API getKData(const string& market_code, int64_t start, int64_t end, KQuery::KType ktype,
|
2020-06-10 00:17:24 +08:00
|
|
|
|
KQuery::RecoverType recoverType) {
|
|
|
|
|
KQuery query(start, end, ktype, recoverType);
|
2020-07-07 00:34:25 +08:00
|
|
|
|
return StockManager::instance().getStock(market_code).getKData(query);
|
2020-06-10 00:17:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-10 19:45:57 +08:00
|
|
|
|
} // namespace hku
|