diff --git a/hikyuu_cpp/hikyuu/DataType.h b/hikyuu_cpp/hikyuu/DataType.h index 03290544..7b4f4f7c 100644 --- a/hikyuu_cpp/hikyuu/DataType.h +++ b/hikyuu_cpp/hikyuu/DataType.h @@ -115,6 +115,22 @@ using std::isnan; using fmt::format; +inline std::ostream &operator<<(std::ostream &os, const PriceList &p) { + size_t len = p.size(); + const size_t print = 3; + os << "["; + for (size_t i = 0; i < len; i++) { + if ((i < print) || (i >= len - print)) { + os << p[i]; + if (i != len - 1) + os << ", "; + } else if (i == 3) + os << "..., "; + } + os << "]"; + return os; +} + /** @} */ } // namespace hku diff --git a/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp b/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp index 77217af5..70410474 100644 --- a/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp +++ b/hikyuu_cpp/hikyuu/global/agent/SpotAgent.cpp @@ -70,7 +70,7 @@ unique_ptr SpotAgent::parseFlatSpot(const hikyuu::flat::Spot* spot) result->low = spot->low(); result->close = spot->close(); result->amount = spot->amount(); - result->volumn = spot->volumn(); + result->volumn = spot->volume(); result->bid1 = spot->bid1(); result->bid1_amount = spot->bid1_amount(); result->bid2 = spot->bid2(); @@ -123,9 +123,9 @@ void SpotAgent::parseSpotData(const void* buf, size_t buf_len) { m_batch_count += total; for (size_t i = 0; i < total; i++) { auto* spot = spots->Get(i); - for (auto& process : m_processList) { - auto spot_record = parseFlatSpot(spot); - if (spot_record) { + auto spot_record = parseFlatSpot(spot); + if (spot_record) { + for (auto& process : m_processList) { m_process_task_list.push_back(m_tg.submit(ProcessTask(process, *spot_record))); } } @@ -165,10 +165,10 @@ void SpotAgent::work_thread() { size_t length = 0; try { rv = nng_recv(sock, &buf, &length, NNG_FLAG_ALLOC); + HKU_CHECK(rv == 0 || rv == NNG_ETIMEDOUT, "Failed nng_recv! {} ", nng_strerror(rv)); if (!buf || length == 0) { continue; } - HKU_CHECK(rv == 0 || rv == NNG_ETIMEDOUT, "Failed nng_recv! {} ", nng_strerror(rv)); switch (m_status) { case WAITING: if (memcmp(buf, ms_startTag, ms_startTagLength) == 0) { diff --git a/hikyuu_cpp/hikyuu/global/agent/spot.fbs b/hikyuu_cpp/hikyuu/global/agent/spot.fbs index b910370a..f5260ec1 100644 --- a/hikyuu_cpp/hikyuu/global/agent/spot.fbs +++ b/hikyuu_cpp/hikyuu/global/agent/spot.fbs @@ -11,7 +11,7 @@ table Spot { low: double; close: double; amount: double; - volumn: double; + volume: double; bid1: double; bid1_amount: double; bid2: double; diff --git a/hikyuu_cpp/hikyuu/global/agent/spot_generated.h b/hikyuu_cpp/hikyuu/global/agent/spot_generated.h index 8a78cfca..3f2ae28b 100644 --- a/hikyuu_cpp/hikyuu/global/agent/spot_generated.h +++ b/hikyuu_cpp/hikyuu/global/agent/spot_generated.h @@ -6,6 +6,13 @@ #include "flatbuffers/flatbuffers.h" +// Ensure the included flatbuffers.h is the same version as when this file was +// generated, otherwise it may not be compatible. +static_assert(FLATBUFFERS_VERSION_MAJOR == 2 && + FLATBUFFERS_VERSION_MINOR == 0 && + FLATBUFFERS_VERSION_REVISION == 8, + "Non-compatible flatbuffers version included"); + namespace hikyuu { namespace flat { @@ -28,7 +35,7 @@ struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_LOW = 18, VT_CLOSE = 20, VT_AMOUNT = 22, - VT_VOLUMN = 24, + VT_VOLUME = 24, VT_BID1 = 26, VT_BID1_AMOUNT = 28, VT_BID2 = 30, @@ -80,8 +87,8 @@ struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { double amount() const { return GetField(VT_AMOUNT, 0.0); } - double volumn() const { - return GetField(VT_VOLUMN, 0.0); + double volume() const { + return GetField(VT_VOLUME, 0.0); } double bid1() const { return GetField(VT_BID1, 0.0); @@ -153,33 +160,33 @@ struct Spot FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { verifier.VerifyString(name()) && VerifyOffset(verifier, VT_DATETIME) && verifier.VerifyString(datetime()) && - VerifyField(verifier, VT_YESTERDAY_CLOSE) && - VerifyField(verifier, VT_OPEN) && - VerifyField(verifier, VT_HIGH) && - VerifyField(verifier, VT_LOW) && - VerifyField(verifier, VT_CLOSE) && - VerifyField(verifier, VT_AMOUNT) && - VerifyField(verifier, VT_VOLUMN) && - VerifyField(verifier, VT_BID1) && - VerifyField(verifier, VT_BID1_AMOUNT) && - VerifyField(verifier, VT_BID2) && - VerifyField(verifier, VT_BID2_AMOUNT) && - VerifyField(verifier, VT_BID3) && - VerifyField(verifier, VT_BID3_AMOUNT) && - VerifyField(verifier, VT_BID4) && - VerifyField(verifier, VT_BID4_AMOUNT) && - VerifyField(verifier, VT_BID5) && - VerifyField(verifier, VT_BID5_AMOUNT) && - VerifyField(verifier, VT_ASK1) && - VerifyField(verifier, VT_ASK1_AMOUNT) && - VerifyField(verifier, VT_ASK2) && - VerifyField(verifier, VT_ASK2_AMOUNT) && - VerifyField(verifier, VT_ASK3) && - VerifyField(verifier, VT_ASK3_AMOUNT) && - VerifyField(verifier, VT_ASK4) && - VerifyField(verifier, VT_ASK4_AMOUNT) && - VerifyField(verifier, VT_ASK5) && - VerifyField(verifier, VT_ASK5_AMOUNT) && + VerifyField(verifier, VT_YESTERDAY_CLOSE, 8) && + VerifyField(verifier, VT_OPEN, 8) && + VerifyField(verifier, VT_HIGH, 8) && + VerifyField(verifier, VT_LOW, 8) && + VerifyField(verifier, VT_CLOSE, 8) && + VerifyField(verifier, VT_AMOUNT, 8) && + VerifyField(verifier, VT_VOLUME, 8) && + VerifyField(verifier, VT_BID1, 8) && + VerifyField(verifier, VT_BID1_AMOUNT, 8) && + VerifyField(verifier, VT_BID2, 8) && + VerifyField(verifier, VT_BID2_AMOUNT, 8) && + VerifyField(verifier, VT_BID3, 8) && + VerifyField(verifier, VT_BID3_AMOUNT, 8) && + VerifyField(verifier, VT_BID4, 8) && + VerifyField(verifier, VT_BID4_AMOUNT, 8) && + VerifyField(verifier, VT_BID5, 8) && + VerifyField(verifier, VT_BID5_AMOUNT, 8) && + VerifyField(verifier, VT_ASK1, 8) && + VerifyField(verifier, VT_ASK1_AMOUNT, 8) && + VerifyField(verifier, VT_ASK2, 8) && + VerifyField(verifier, VT_ASK2_AMOUNT, 8) && + VerifyField(verifier, VT_ASK3, 8) && + VerifyField(verifier, VT_ASK3_AMOUNT, 8) && + VerifyField(verifier, VT_ASK4, 8) && + VerifyField(verifier, VT_ASK4_AMOUNT, 8) && + VerifyField(verifier, VT_ASK5, 8) && + VerifyField(verifier, VT_ASK5_AMOUNT, 8) && verifier.EndTable(); } }; @@ -218,8 +225,8 @@ struct SpotBuilder { void add_amount(double amount) { fbb_.AddElement(Spot::VT_AMOUNT, amount, 0.0); } - void add_volumn(double volumn) { - fbb_.AddElement(Spot::VT_VOLUMN, volumn, 0.0); + void add_volume(double volume) { + fbb_.AddElement(Spot::VT_VOLUME, volume, 0.0); } void add_bid1(double bid1) { fbb_.AddElement(Spot::VT_BID1, bid1, 0.0); @@ -285,7 +292,6 @@ struct SpotBuilder { : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpotBuilder &operator=(const SpotBuilder &); flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); auto o = flatbuffers::Offset(end); @@ -305,7 +311,7 @@ inline flatbuffers::Offset CreateSpot( double low = 0.0, double close = 0.0, double amount = 0.0, - double volumn = 0.0, + double volume = 0.0, double bid1 = 0.0, double bid1_amount = 0.0, double bid2 = 0.0, @@ -347,7 +353,7 @@ inline flatbuffers::Offset CreateSpot( builder_.add_bid2(bid2); builder_.add_bid1_amount(bid1_amount); builder_.add_bid1(bid1); - builder_.add_volumn(volumn); + builder_.add_volume(volume); builder_.add_amount(amount); builder_.add_close(close); builder_.add_low(low); @@ -373,7 +379,7 @@ inline flatbuffers::Offset CreateSpotDirect( double low = 0.0, double close = 0.0, double amount = 0.0, - double volumn = 0.0, + double volume = 0.0, double bid1 = 0.0, double bid1_amount = 0.0, double bid2 = 0.0, @@ -410,7 +416,7 @@ inline flatbuffers::Offset CreateSpotDirect( low, close, amount, - volumn, + volume, bid1, bid1_amount, bid2, @@ -461,7 +467,6 @@ struct SpotListBuilder { : fbb_(_fbb) { start_ = fbb_.StartTable(); } - SpotListBuilder &operator=(const SpotListBuilder &); flatbuffers::Offset Finish() { const auto end = fbb_.EndTable(start_); auto o = flatbuffers::Offset(end); diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp index 7dd5a819..b208cdac 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp @@ -138,6 +138,7 @@ HKU_API std::ostream &operator<<(std::ostream &os, const IndicatorImp &imp) { os << "}"; } os << "\n formula: " << imp.formula() << "\n}"; + os << "\n values: " << *imp.m_pBuffer[0]; return os; } @@ -360,7 +361,7 @@ IndicatorImpPtr IndicatorImp::getResult(size_t result_num) { return imp; } -price_t IndicatorImp::get(size_t pos, size_t num) { +price_t IndicatorImp::get(size_t pos, size_t num) const { #if CHECK_ACCESS_BOUND HKU_CHECK_THROW((m_pBuffer[num] != NULL) && pos < m_pBuffer[num]->size(), std::out_of_range, "Try to access value ({}) out of bounds [0..{})! {}", pos, diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h index 0d9a9123..315f0863 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h @@ -56,7 +56,7 @@ class HKU_API IndParam; */ class HKU_API IndicatorImp : public enable_shared_from_this { PARAMETER_SUPPORT - + friend HKU_API std::ostream &operator<<(std::ostream &os, const IndicatorImp &imp); public: enum OPType { LEAF, ///< 叶子节点 @@ -99,7 +99,7 @@ public: size_t size() const; - price_t get(size_t pos, size_t num = 0); + price_t get(size_t pos, size_t num = 0) const; price_t getByDate(Datetime, size_t num = 0); diff --git a/hikyuu_cpp/hikyuu/indicator/crt/RSI.h b/hikyuu_cpp/hikyuu/indicator/crt/RSI.h index a1533768..0d0d2407 100644 --- a/hikyuu_cpp/hikyuu/indicator/crt/RSI.h +++ b/hikyuu_cpp/hikyuu/indicator/crt/RSI.h @@ -25,6 +25,7 @@ Indicator RSI(int n = 14) { Indicator d = IF(diff < 0, (-1) * diff, 0); Indicator ema_u = EMA(u, n); Indicator ema_d = EMA(d, n); + ema_d = IF(ema_d == 0.0, 1, ema_d); Indicator rs = ema_u / ema_d; Indicator _1 = CVAL(1); Indicator rsi = (_1 - _1 / (_1 + rs)) * CVAL(100); diff --git a/xmake.lua b/xmake.lua index aca3e087..65362181 100644 --- a/xmake.lua +++ b/xmake.lua @@ -113,7 +113,7 @@ set_languages("cxx17", "c99") local boost_version = "1.81.0" local hdf5_version = "1.12.2" local fmt_version = "10.0.0" -local flatbuffers_version = "2.0.0" +local flatbuffers_version = "2.0.8" local mysql_version = "8.0.31" if is_plat("windows") or (is_plat("linux", "cross") and is_arch("aarch64", "arm64.*")) then mysql_version = "8.0.21"