Merge pull request #124 from yangrq1018/pr-flatbuffers

Several changes
This commit is contained in:
fasiondog 2023-11-02 21:04:35 +08:00 committed by GitHub
commit f61d33e454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 71 additions and 48 deletions

View File

@ -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

View File

@ -70,7 +70,7 @@ unique_ptr<SpotRecord> 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) {

View File

@ -11,7 +11,7 @@ table Spot {
low: double;
close: double;
amount: double;
volumn: double;
volume: double;
bid1: double;
bid1_amount: double;
bid2: double;

View File

@ -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<double>(VT_AMOUNT, 0.0);
}
double volumn() const {
return GetField<double>(VT_VOLUMN, 0.0);
double volume() const {
return GetField<double>(VT_VOLUME, 0.0);
}
double bid1() const {
return GetField<double>(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<double>(verifier, VT_YESTERDAY_CLOSE) &&
VerifyField<double>(verifier, VT_OPEN) &&
VerifyField<double>(verifier, VT_HIGH) &&
VerifyField<double>(verifier, VT_LOW) &&
VerifyField<double>(verifier, VT_CLOSE) &&
VerifyField<double>(verifier, VT_AMOUNT) &&
VerifyField<double>(verifier, VT_VOLUMN) &&
VerifyField<double>(verifier, VT_BID1) &&
VerifyField<double>(verifier, VT_BID1_AMOUNT) &&
VerifyField<double>(verifier, VT_BID2) &&
VerifyField<double>(verifier, VT_BID2_AMOUNT) &&
VerifyField<double>(verifier, VT_BID3) &&
VerifyField<double>(verifier, VT_BID3_AMOUNT) &&
VerifyField<double>(verifier, VT_BID4) &&
VerifyField<double>(verifier, VT_BID4_AMOUNT) &&
VerifyField<double>(verifier, VT_BID5) &&
VerifyField<double>(verifier, VT_BID5_AMOUNT) &&
VerifyField<double>(verifier, VT_ASK1) &&
VerifyField<double>(verifier, VT_ASK1_AMOUNT) &&
VerifyField<double>(verifier, VT_ASK2) &&
VerifyField<double>(verifier, VT_ASK2_AMOUNT) &&
VerifyField<double>(verifier, VT_ASK3) &&
VerifyField<double>(verifier, VT_ASK3_AMOUNT) &&
VerifyField<double>(verifier, VT_ASK4) &&
VerifyField<double>(verifier, VT_ASK4_AMOUNT) &&
VerifyField<double>(verifier, VT_ASK5) &&
VerifyField<double>(verifier, VT_ASK5_AMOUNT) &&
VerifyField<double>(verifier, VT_YESTERDAY_CLOSE, 8) &&
VerifyField<double>(verifier, VT_OPEN, 8) &&
VerifyField<double>(verifier, VT_HIGH, 8) &&
VerifyField<double>(verifier, VT_LOW, 8) &&
VerifyField<double>(verifier, VT_CLOSE, 8) &&
VerifyField<double>(verifier, VT_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_VOLUME, 8) &&
VerifyField<double>(verifier, VT_BID1, 8) &&
VerifyField<double>(verifier, VT_BID1_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_BID2, 8) &&
VerifyField<double>(verifier, VT_BID2_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_BID3, 8) &&
VerifyField<double>(verifier, VT_BID3_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_BID4, 8) &&
VerifyField<double>(verifier, VT_BID4_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_BID5, 8) &&
VerifyField<double>(verifier, VT_BID5_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_ASK1, 8) &&
VerifyField<double>(verifier, VT_ASK1_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_ASK2, 8) &&
VerifyField<double>(verifier, VT_ASK2_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_ASK3, 8) &&
VerifyField<double>(verifier, VT_ASK3_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_ASK4, 8) &&
VerifyField<double>(verifier, VT_ASK4_AMOUNT, 8) &&
VerifyField<double>(verifier, VT_ASK5, 8) &&
VerifyField<double>(verifier, VT_ASK5_AMOUNT, 8) &&
verifier.EndTable();
}
};
@ -218,8 +225,8 @@ struct SpotBuilder {
void add_amount(double amount) {
fbb_.AddElement<double>(Spot::VT_AMOUNT, amount, 0.0);
}
void add_volumn(double volumn) {
fbb_.AddElement<double>(Spot::VT_VOLUMN, volumn, 0.0);
void add_volume(double volume) {
fbb_.AddElement<double>(Spot::VT_VOLUME, volume, 0.0);
}
void add_bid1(double bid1) {
fbb_.AddElement<double>(Spot::VT_BID1, bid1, 0.0);
@ -285,7 +292,6 @@ struct SpotBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
SpotBuilder &operator=(const SpotBuilder &);
flatbuffers::Offset<Spot> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Spot>(end);
@ -305,7 +311,7 @@ inline flatbuffers::Offset<Spot> 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<Spot> 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<Spot> 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<Spot> 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<SpotList> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<SpotList>(end);

View File

@ -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,

View File

@ -56,7 +56,7 @@ class HKU_API IndParam;
*/
class HKU_API IndicatorImp : public enable_shared_from_this<IndicatorImp> {
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);

View File

@ -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);

View File

@ -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"