2019-02-10 23:31:27 +08:00
|
|
|
/*
|
|
|
|
* TransRecord.cpp
|
|
|
|
*
|
|
|
|
* Created on: 2019年2月10日
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TransRecord.h"
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
2019-02-11 02:14:14 +08:00
|
|
|
HKU_API std::ostream & operator<<(std::ostream& os, const TransRecord& record) {
|
|
|
|
string strip(", ");
|
|
|
|
os << std::fixed;
|
|
|
|
os.precision(4);
|
|
|
|
os << "TransRecord(Datetime(" << record.datetime.number() << ")" << strip
|
|
|
|
<< record.price << strip
|
|
|
|
<< record.vol << strip
|
|
|
|
<< record.direct << ")";
|
|
|
|
os.unsetf(std::ostream::floatfield);
|
|
|
|
os.precision();
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API std::ostream& operator <<(std::ostream &os, const TransList& data) {
|
2019-02-11 21:13:06 +08:00
|
|
|
if (data.size() > 0) {
|
|
|
|
os << "TransList{\n size : " << data.size()
|
|
|
|
<< "\n start: " << data.front().datetime
|
|
|
|
<< "\n last : " << data.back().datetime
|
|
|
|
<< "\n }";
|
|
|
|
} else {
|
|
|
|
os << "TransList{\n size : " << data.size() << "\n }";
|
|
|
|
}
|
2019-02-11 02:14:14 +08:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool HKU_API operator==(const TransRecord& d1, const TransRecord& d2) {
|
|
|
|
if (d1.datetime == d2.datetime
|
|
|
|
&& (std::fabs(d1.price - d2.price) < 0.0001)
|
|
|
|
&& (std::fabs(d1.vol - d2.vol) < 0.0001)
|
|
|
|
&& (d1.direct == d2.direct)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TransRecord::TransRecord()
|
|
|
|
: datetime(Datetime()), price(0.0), vol(0.0), direct(BUY) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TransRecord::TransRecord(const Datetime& datetime,
|
|
|
|
price_t price, price_t vol, DIRECT direct)
|
2019-02-11 21:13:06 +08:00
|
|
|
: datetime(datetime), price(price), vol(vol), direct(direct) {
|
2019-02-10 23:31:27 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-11 02:14:14 +08:00
|
|
|
bool TransRecord::isValid() const {
|
|
|
|
return datetime == Null<Datetime>() ? false : true;
|
2019-02-10 23:31:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace hku */
|