Skip to content

Commit

Permalink
[EN-7314] Implement the DXPublisher: Series + TheoPrice + Underlying
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Aug 23, 2023
1 parent d859b23 commit 8649d62
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 55 deletions.
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/event/option/Series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Series> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/event/option/TheoPrice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TheoPrice> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

Expand Down
4 changes: 3 additions & 1 deletion include/dxfeed_graal_cpp_api/event/option/Underlying.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Underlying> fromGraal(void *graalNative) noexcept;
//TODO: implement
void* toGraal() const noexcept;
static void freeGraal(void* graalNative) noexcept;

Expand Down
86 changes: 68 additions & 18 deletions src/event/option/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dxfg_series_t *>(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<dxfg_series_t *>(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> Series::fromGraal(void *graalNative) noexcept {
if (!graalNative) {
return {};
}

auto eventType = bit_cast<dxfg_event_type_t *>(graalNative);

if (eventType->clazz != DXFG_EVENT_SERIES) {
if (static_cast<dxfg_event_type_t *>(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_SERIES) {
return {};
}

try {
auto graalSeries = bit_cast<dxfg_series_t *>(graalNative);
auto series = std::make_shared<Series>(dxfcpp::toString(graalSeries->market_event.event_symbol));
auto series = std::make_shared<Series>();

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 (...) {
Expand All @@ -62,23 +99,36 @@ 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<void *>(graalSeries));

return static_cast<void *>(graalSeries);
}

void Series::freeGraal(void *graalNative) noexcept {
if (!graalNative) {
return;
}

auto eventType = bit_cast<dxfg_event_type_t *>(graalNative);

if (eventType->clazz != DXFG_EVENT_SERIES) {
if (static_cast<dxfg_event_type_t *>(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_SERIES) {
return;
}

auto graalSeries = bit_cast<dxfg_series_t *>(graalNative);
auto graalSeries = static_cast<dxfg_series_t *>(graalNative);

delete[] graalSeries->market_event.event_symbol;
MarketEvent::freeGraalData(graalNative);

delete graalSeries;
}
Expand Down
79 changes: 62 additions & 17 deletions src/event/option/TheoPrice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dxfg_theo_price_t *>(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<dxfg_theo_price_t *>(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> TheoPrice::fromGraal(void *graalNative) noexcept {
if (!graalNative) {
return {};
}

auto eventType = bit_cast<dxfg_event_type_t *>(graalNative);

if (eventType->clazz != DXFG_EVENT_THEO_PRICE) {
if (static_cast<dxfg_event_type_t *>(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_THEO_PRICE) {
return {};
}

try {
auto graalTheoPrice = bit_cast<dxfg_theo_price_t *>(graalNative);
auto theoPrice = std::make_shared<TheoPrice>(dxfcpp::toString(graalTheoPrice->market_event.event_symbol));
auto theoPrice = std::make_shared<TheoPrice>();

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 (...) {
Expand All @@ -60,23 +92,36 @@ 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<void *>(graalTheoPrice));

return static_cast<void *>(graalTheoPrice);
}

void TheoPrice::freeGraal(void *graalNative) noexcept {
if (!graalNative) {
return;
}

auto eventType = bit_cast<dxfg_event_type_t *>(graalNative);

if (eventType->clazz != DXFG_EVENT_THEO_PRICE) {
if (static_cast<dxfg_event_type_t *>(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_THEO_PRICE) {
return;
}

auto graalTheoPrice = bit_cast<dxfg_theo_price_t *>(graalNative);
auto graalTheoPrice = static_cast<dxfg_theo_price_t *>(graalNative);

delete[] graalTheoPrice->market_event.event_symbol;
MarketEvent::freeGraalData(graalNative);

delete graalTheoPrice;
}
Expand Down
79 changes: 62 additions & 17 deletions src/event/option/Underlying.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dxfg_underlying_t *>(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<dxfg_underlying_t *>(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> Underlying::fromGraal(void *graalNative) noexcept {
if (!graalNative) {
return {};
}

auto eventType = bit_cast<dxfg_event_type_t *>(graalNative);

if (eventType->clazz != DXFG_EVENT_UNDERLYING) {
if (static_cast<dxfg_event_type_t *>(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_UNDERLYING) {
return {};
}

try {
auto graalUnderlying = bit_cast<dxfg_underlying_t *>(graalNative);
auto underlying = std::make_shared<Underlying>(dxfcpp::toString(graalUnderlying->market_event.event_symbol));
auto underlying = std::make_shared<Underlying>();

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 (...) {
Expand All @@ -61,23 +93,36 @@ 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<void *>(graalUnderlying));

return static_cast<void *>(graalUnderlying);
}

void Underlying::freeGraal(void *graalNative) noexcept {
if (!graalNative) {
return;
}

auto eventType = bit_cast<dxfg_event_type_t *>(graalNative);

if (eventType->clazz != DXFG_EVENT_UNDERLYING) {
if (static_cast<dxfg_event_type_t *>(graalNative)->clazz != dxfg_event_clazz_t::DXFG_EVENT_UNDERLYING) {
return;
}

auto graalUnderlying = bit_cast<dxfg_underlying_t *>(graalNative);
auto graalUnderlying = static_cast<dxfg_underlying_t *>(graalNative);

delete[] graalUnderlying->market_event.event_symbol;
MarketEvent::freeGraalData(graalNative);

delete graalUnderlying;
}
Expand Down

0 comments on commit 8649d62

Please sign in to comment.