Skip to content

Commit

Permalink
[EN-8147] Add the ability to accept IPF URI as a symbols' source.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed Nov 20, 2023
1 parent 17e1771 commit a54261a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
18 changes: 11 additions & 7 deletions include/dxfeed_graal_cpp_api/isolated/Isolated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ struct StringList {
};

struct TimeFormat {
static /* dxfg_time_format_t* */ void* getDefault() noexcept;
static /* dxfg_time_format_t* */ void* getGmt() noexcept;
static /* dxfg_time_format_t* */ void* withTimeZone(/* dxfg_time_format_t* */ void* timeFormat) noexcept;
static /* dxfg_time_format_t* */ void* withMillis(/* dxfg_time_format_t* */ void* timeFormat) noexcept;
static std::int64_t parse(/* dxfg_time_format_t* */ void* timeFormat, const std::string& value) noexcept;
static std::string format(/* dxfg_time_format_t* */ void* timeFormat, std::int64_t value) noexcept;
static /* dxfg_time_format_t* */ void *getDefault() noexcept;
static /* dxfg_time_format_t* */ void *getGmt() noexcept;
static /* dxfg_time_format_t* */ void *withTimeZone(/* dxfg_time_format_t* */ void *timeFormat) noexcept;
static /* dxfg_time_format_t* */ void *withMillis(/* dxfg_time_format_t* */ void *timeFormat) noexcept;
static std::int64_t parse(/* dxfg_time_format_t* */ void *timeFormat, const std::string &value) noexcept;
static std::string format(/* dxfg_time_format_t* */ void *timeFormat, std::int64_t value) noexcept;
};

struct Tools {
static std::unordered_set<std::string> /* dxfg_string_list* */ parseSymbols(const std::string &symbolList) noexcept;
};

namespace api {
Expand Down Expand Up @@ -62,7 +66,7 @@ struct InstrumentProfileCollector {
static bool addUpdateListener(/* dxfg_ipf_collector_t* */ void *instrumentProfileCollectorHandle,
/* dxfg_ipf_update_listener_t* */ void *listener) noexcept;
static bool removeUpdateListener(/* dxfg_ipf_collector_t* */ void *instrumentProfileCollectorHandle,
/* dxfg_ipf_update_listener_t* */ void *listener) noexcept;
/* dxfg_ipf_update_listener_t* */ void *listener) noexcept;
};

struct InstrumentProfileConnection {
Expand Down
23 changes: 23 additions & 0 deletions src/internal/Isolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,29 @@ std::string TimeFormat::format(/* dxfg_time_format_t* */ void *timeFormat, std::
return result;
}

std::unordered_set<std::string> /* dxfg_string_list* */
Tools::parseSymbols(const std::string &symbolList) noexcept {
std::unordered_set<std::string> result{};

auto graalStringList = runIsolatedOrElse(
[](auto threadHandle, auto &&symbolList) {
return dxfg_Tools_parseSymbols(dxfcpp::bit_cast<graal_isolatethread_t *>(threadHandle), symbolList.c_str());
},
nullptr, symbolList);

if (!graalStringList) {
return result;
}

for (auto i = 0; i < graalStringList->size; i++) {
result.emplace(dxfcpp::toString(graalStringList->elements[i]));
}

StringList::release(graalStringList);

return result;
}

namespace api {

static dxfcpp::DXEndpoint::State graalStateToState(dxfg_endpoint_state_t state) {
Expand Down
12 changes: 9 additions & 3 deletions src/internal/utils/CmdArgsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <chrono>
#include <cstring>
#include <ctime>
#include <locale>
#include <memory>
#include <sstream>
#include <string>
#include <utf8.h>
#include <utility>
#include <vector>
#include <locale>

#include <fmt/chrono.h>
#include <fmt/format.h>
Expand Down Expand Up @@ -131,7 +131,7 @@ std::unordered_set<SymbolWrapper> CmdArgsUtils::parseSymbols(const std::string &
return {};
}

auto parsed = parseStringSymbols(trimmedSymbols);
auto parsed = isolated::Tools::parseSymbols(trimmedSymbols);

if (parsed.contains("*") || parsed.contains("all") || parsed.contains("All") || parsed.contains("ALL")) {
return {WildcardSymbol::ALL};
Expand All @@ -141,7 +141,13 @@ std::unordered_set<SymbolWrapper> CmdArgsUtils::parseSymbols(const std::string &
}

std::unordered_set<CandleSymbol> CmdArgsUtils::parseCandleSymbols(const std::string &symbols) noexcept {
auto parsed = parseStringSymbols(symbols);
auto trimmedSymbols = trimStr(symbols);

if (trimmedSymbols.empty()) {
return {};
}

auto parsed = isolated::Tools::parseSymbols(trimmedSymbols);

return parsed | ranges::views::transform([](auto &&s) {
return CandleSymbol::valueOf(s);
Expand Down
4 changes: 2 additions & 2 deletions tools/Tools/src/Args/Args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const std::string SymbolsArg::NAME{"symbols"};
const std::size_t SymbolsArg::POSITION{2};
const std::string SymbolsArg::HELP_TEXT{R"(
Comma-separated list of symbol names to get events for (e.g. "IBM, AAPL, MSFT").
Use "all" for wildcard subscription.
The "dxfeed.wildcard.enable" property must be set to true to enable wildcard subscription.
Use "all" for wildcard subscription. The "dxfeed.wildcard.enable" property must be set to true to enable wildcard subscription.
A symbol filter set format can also be used as symbols source, for example: "ipf[https://demo:[email protected]/ipf?TYPE=STOCK]"
)"};

const std::string PropertiesArg::NAME{"properties"};
Expand Down

0 comments on commit a54261a

Please sign in to comment.