diff --git a/include/dxfeed_graal_cpp_api/event/option/Series.hpp b/include/dxfeed_graal_cpp_api/event/option/Series.hpp index dd54245c..46d6e64a 100644 --- a/include/dxfeed_graal_cpp_api/event/option/Series.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/Series.hpp @@ -83,8 +83,10 @@ class DXFCPP_EXPORT Series final : public MarketEvent, public IndexedEvent { Data data_{}; + void fillData(void *graalNative) noexcept override; + void fillGraalData(void *graalNative) const noexcept override; + static std::shared_ptr fromGraal(void *graalNative) noexcept; - //TODO: implement void* toGraal() const noexcept; static void freeGraal(void* graalNative) noexcept; diff --git a/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp b/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp index 202802ee..d686861e 100644 --- a/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp @@ -82,8 +82,10 @@ class DXFCPP_EXPORT TheoPrice final : public MarketEvent, public TimeSeriesEvent Data data_{}; + void fillData(void *graalNative) noexcept override; + void fillGraalData(void *graalNative) const noexcept override; + static std::shared_ptr fromGraal(void *graalNative) noexcept; - //TODO: implement void* toGraal() const noexcept; static void freeGraal(void* graalNative) noexcept; diff --git a/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp b/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp index 2b121a8d..769b6c4d 100644 --- a/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp +++ b/include/dxfeed_graal_cpp_api/event/option/Underlying.hpp @@ -78,8 +78,10 @@ class DXFCPP_EXPORT Underlying final : public MarketEvent, public TimeSeriesEven Data data_{}; + void fillData(void *graalNative) noexcept override; + void fillGraalData(void *graalNative) const noexcept override; + static std::shared_ptr fromGraal(void *graalNative) noexcept; - //TODO: implement void* toGraal() const noexcept; static void freeGraal(void* graalNative) noexcept; diff --git a/src/event/option/Series.cpp b/src/event/option/Series.cpp index a4af7f84..2bcc36f8 100644 --- a/src/event/option/Series.cpp +++ b/src/event/option/Series.cpp @@ -20,28 +20,65 @@ namespace dxfcpp { const EventTypeEnum &Series::TYPE = EventTypeEnum::SERIES; +void Series::fillData(void *graalNative) noexcept { + if (graalNative == nullptr) { + return; + } + + MarketEvent::fillData(graalNative); + + auto graalSeries = static_cast(graalNative); + + data_ = { + .eventFlags = graalSeries->event_flags, + .index = graalSeries->index, + .timeSequence = graalSeries->time_sequence, + .expiration = graalSeries->expiration, + .volatility = graalSeries->volatility, + .callVolume = graalSeries->call_volume, + .putVolume = graalSeries->put_volume, + .putCallRatio = graalSeries->put_call_ratio, + .forwardPrice = graalSeries->forward_price, + .dividend = graalSeries->dividend, + .interest = graalSeries->interest, + }; +} + +void Series::fillGraalData(void *graalNative) const noexcept { + if (graalNative == nullptr) { + return; + } + + MarketEvent::fillGraalData(graalNative); + + auto graalSeries = static_cast(graalNative); + + graalSeries->event_flags = data_.eventFlags; + graalSeries->index = data_.index; + graalSeries->time_sequence = data_.timeSequence; + graalSeries->expiration = data_.expiration; + graalSeries->volatility = data_.volatility; + graalSeries->call_volume = data_.callVolume; + graalSeries->put_volume = data_.putVolume; + graalSeries->put_call_ratio = data_.putCallRatio; + graalSeries->forward_price = data_.forwardPrice; + graalSeries->dividend = data_.dividend; + graalSeries->interest = data_.interest; +} + std::shared_ptr Series::fromGraal(void *graalNative) noexcept { if (!graalNative) { return {}; } - auto eventType = bit_cast(graalNative); - - if (eventType->clazz != DXFG_EVENT_SERIES) { + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_SERIES) { return {}; } try { - auto graalSeries = bit_cast(graalNative); - auto series = std::make_shared(dxfcpp::toString(graalSeries->market_event.event_symbol)); + auto series = std::make_shared(); - series->setEventTime(graalSeries->market_event.event_time); - series->data_ = { - graalSeries->event_flags, graalSeries->index, graalSeries->time_sequence, - graalSeries->expiration, graalSeries->volatility, graalSeries->call_volume, - graalSeries->put_volume, graalSeries->put_call_ratio, graalSeries->forward_price, - graalSeries->dividend, graalSeries->interest, - }; + series->fillData(graalNative); return series; } catch (...) { @@ -62,7 +99,22 @@ std::string Series::toString() const noexcept { } void *Series::toGraal() const noexcept { - return nullptr; + if constexpr (Debugger::isDebug) { + Debugger::debug(toString() + "::toGraal()"); + } + + auto *graalSeries = new (std::nothrow) + dxfg_series_t{.market_event = {.event_type = {.clazz = dxfg_event_clazz_t::DXFG_EVENT_SERIES}}}; + + if (!graalSeries) { + // TODO: error handling + + return nullptr; + } + + fillGraalData(static_cast(graalSeries)); + + return static_cast(graalSeries); } void Series::freeGraal(void *graalNative) noexcept { @@ -70,15 +122,13 @@ void Series::freeGraal(void *graalNative) noexcept { return; } - auto eventType = bit_cast(graalNative); - - if (eventType->clazz != DXFG_EVENT_SERIES) { + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_SERIES) { return; } - auto graalSeries = bit_cast(graalNative); + auto graalSeries = static_cast(graalNative); - delete[] graalSeries->market_event.event_symbol; + MarketEvent::freeGraalData(graalNative); delete graalSeries; } diff --git a/src/event/option/TheoPrice.cpp b/src/event/option/TheoPrice.cpp index 25aec2cd..c69ca883 100644 --- a/src/event/option/TheoPrice.cpp +++ b/src/event/option/TheoPrice.cpp @@ -20,27 +20,59 @@ namespace dxfcpp { const EventTypeEnum &TheoPrice::TYPE = EventTypeEnum::THEO_PRICE; +void TheoPrice::fillData(void *graalNative) noexcept { + if (graalNative == nullptr) { + return; + } + + MarketEvent::fillData(graalNative); + + auto graalTheoPrice = static_cast(graalNative); + + data_ = { + .eventFlags = graalTheoPrice->event_flags, + .index = graalTheoPrice->index, + .price = graalTheoPrice->price, + .underlyingPrice = graalTheoPrice->underlying_price, + .delta = graalTheoPrice->delta, + .gamma = graalTheoPrice->gamma, + .dividend = graalTheoPrice->dividend, + .interest = graalTheoPrice->interest, + }; +} + +void TheoPrice::fillGraalData(void *graalNative) const noexcept { + if (graalNative == nullptr) { + return; + } + + MarketEvent::fillGraalData(graalNative); + + auto graalTheoPrice = static_cast(graalNative); + + graalTheoPrice->event_flags = data_.eventFlags; + graalTheoPrice->index = data_.index; + graalTheoPrice->price = data_.price; + graalTheoPrice->underlying_price = data_.underlyingPrice; + graalTheoPrice->delta = data_.delta; + graalTheoPrice->gamma = data_.gamma; + graalTheoPrice->dividend = data_.dividend; + graalTheoPrice->interest = data_.interest; +} + std::shared_ptr TheoPrice::fromGraal(void *graalNative) noexcept { if (!graalNative) { return {}; } - auto eventType = bit_cast(graalNative); - - if (eventType->clazz != DXFG_EVENT_THEO_PRICE) { + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_THEO_PRICE) { return {}; } try { - auto graalTheoPrice = bit_cast(graalNative); - auto theoPrice = std::make_shared(dxfcpp::toString(graalTheoPrice->market_event.event_symbol)); + auto theoPrice = std::make_shared(); - theoPrice->setEventTime(graalTheoPrice->market_event.event_time); - theoPrice->data_ = { - graalTheoPrice->event_flags, graalTheoPrice->index, graalTheoPrice->price, - graalTheoPrice->underlying_price, graalTheoPrice->delta, graalTheoPrice->gamma, - graalTheoPrice->dividend, graalTheoPrice->interest, - }; + theoPrice->fillData(graalNative); return theoPrice; } catch (...) { @@ -60,7 +92,22 @@ std::string TheoPrice::toString() const noexcept { } void *TheoPrice::toGraal() const noexcept { - return nullptr; + if constexpr (Debugger::isDebug) { + Debugger::debug(toString() + "::toGraal()"); + } + + auto *graalTheoPrice = new (std::nothrow) + dxfg_theo_price_t{.market_event = {.event_type = {.clazz = dxfg_event_clazz_t::DXFG_EVENT_THEO_PRICE}}}; + + if (!graalTheoPrice) { + // TODO: error handling + + return nullptr; + } + + fillGraalData(static_cast(graalTheoPrice)); + + return static_cast(graalTheoPrice); } void TheoPrice::freeGraal(void *graalNative) noexcept { @@ -68,15 +115,13 @@ void TheoPrice::freeGraal(void *graalNative) noexcept { return; } - auto eventType = bit_cast(graalNative); - - if (eventType->clazz != DXFG_EVENT_THEO_PRICE) { + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_THEO_PRICE) { return; } - auto graalTheoPrice = bit_cast(graalNative); + auto graalTheoPrice = static_cast(graalNative); - delete[] graalTheoPrice->market_event.event_symbol; + MarketEvent::freeGraalData(graalNative); delete graalTheoPrice; } diff --git a/src/event/option/Underlying.cpp b/src/event/option/Underlying.cpp index f312a441..ded9ae46 100644 --- a/src/event/option/Underlying.cpp +++ b/src/event/option/Underlying.cpp @@ -20,27 +20,59 @@ namespace dxfcpp { const EventTypeEnum &Underlying::TYPE = EventTypeEnum::UNDERLYING; +void Underlying::fillData(void *graalNative) noexcept { + if (graalNative == nullptr) { + return; + } + + MarketEvent::fillData(graalNative); + + auto graalUnderlying = static_cast(graalNative); + + data_ = { + .eventFlags = graalUnderlying->event_flags, + .index = graalUnderlying->index, + .volatility = graalUnderlying->volatility, + .frontVolatility = graalUnderlying->front_volatility, + .backVolatility = graalUnderlying->back_volatility, + .callVolume = graalUnderlying->call_volume, + .putVolume = graalUnderlying->put_volume, + .putCallRatio = graalUnderlying->put_call_ratio, + }; +} + +void Underlying::fillGraalData(void *graalNative) const noexcept { + if (graalNative == nullptr) { + return; + } + + MarketEvent::fillGraalData(graalNative); + + auto graalUnderlying = static_cast(graalNative); + + graalUnderlying->event_flags = data_.eventFlags; + graalUnderlying->index = data_.index; + graalUnderlying->volatility = data_.volatility; + graalUnderlying->front_volatility = data_.frontVolatility; + graalUnderlying->back_volatility = data_.backVolatility; + graalUnderlying->call_volume = data_.callVolume; + graalUnderlying->put_volume = data_.putVolume; + graalUnderlying->put_call_ratio = data_.putCallRatio; +} + std::shared_ptr Underlying::fromGraal(void *graalNative) noexcept { if (!graalNative) { return {}; } - auto eventType = bit_cast(graalNative); - - if (eventType->clazz != DXFG_EVENT_UNDERLYING) { + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_UNDERLYING) { return {}; } try { - auto graalUnderlying = bit_cast(graalNative); - auto underlying = std::make_shared(dxfcpp::toString(graalUnderlying->market_event.event_symbol)); + auto underlying = std::make_shared(); - underlying->setEventTime(graalUnderlying->market_event.event_time); - underlying->data_ = { - graalUnderlying->event_flags, graalUnderlying->index, graalUnderlying->volatility, - graalUnderlying->front_volatility, graalUnderlying->back_volatility, graalUnderlying->call_volume, - graalUnderlying->put_volume, graalUnderlying->put_call_ratio, - }; + underlying->fillData(graalNative); return underlying; } catch (...) { @@ -61,7 +93,22 @@ std::string Underlying::toString() const noexcept { } void *Underlying::toGraal() const noexcept { - return nullptr; + if constexpr (Debugger::isDebug) { + Debugger::debug(toString() + "::toGraal()"); + } + + auto *graalUnderlying = new (std::nothrow) + dxfg_underlying_t{.market_event = {.event_type = {.clazz = dxfg_event_clazz_t::DXFG_EVENT_UNDERLYING}}}; + + if (!graalUnderlying) { + // TODO: error handling + + return nullptr; + } + + fillGraalData(static_cast(graalUnderlying)); + + return static_cast(graalUnderlying); } void Underlying::freeGraal(void *graalNative) noexcept { @@ -69,15 +116,13 @@ void Underlying::freeGraal(void *graalNative) noexcept { return; } - auto eventType = bit_cast(graalNative); - - if (eventType->clazz != DXFG_EVENT_UNDERLYING) { + if (static_cast(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_UNDERLYING) { return; } - auto graalUnderlying = bit_cast(graalNative); + auto graalUnderlying = static_cast(graalNative); - delete[] graalUnderlying->market_event.event_symbol; + MarketEvent::freeGraalData(graalNative); delete graalUnderlying; }