From c01f9440f9d4f692a72959fb52189465a3ed1520 Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 12:33:31 +0000 Subject: [PATCH 1/8] try get rid of paprika --- src/app/app.cpp | 3 - .../atomicdex/api/coinpaprika/coinpaprika.cpp | 133 --------- .../atomicdex/api/coinpaprika/coinpaprika.hpp | 139 ---------- .../coinpaprika/coinpaprika.provider.cpp | 259 ------------------ .../coinpaprika/coinpaprika.provider.hpp | 122 --------- .../atomicdex/services/price/defi.stats.cpp | 1 - .../services/price/global.provider.cpp | 64 ----- 7 files changed, 721 deletions(-) delete mode 100644 src/core/atomicdex/api/coinpaprika/coinpaprika.cpp delete mode 100644 src/core/atomicdex/api/coinpaprika/coinpaprika.hpp delete mode 100644 src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.cpp delete mode 100644 src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.hpp diff --git a/src/app/app.cpp b/src/app/app.cpp index 54cfc55fb4..98e0e4d25b 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -43,7 +43,6 @@ #include "atomicdex/services/mm2/auto.update.maker.order.service.hpp" #include "atomicdex/services/price/komodo_prices/komodo.prices.provider.hpp" #include "atomicdex/services/price/coingecko/coingecko.wallet.charts.hpp" -#include "atomicdex/services/price/coinpaprika/coinpaprika.provider.hpp" #include "atomicdex/services/price/orderbook.scanner.service.hpp" namespace @@ -347,7 +346,6 @@ namespace atomic_dex { system_manager_.create_system(system_manager_); - // system_manager_.create_system(system_manager_); // system_manager_.create_system(system_manager_); connect_signals(); m_event_actions[events_action::need_a_full_refresh_of_mm2] = false; @@ -500,7 +498,6 @@ namespace atomic_dex system_manager_.create_system(system_manager_, settings_page_system.get_cfg()); system_manager_.create_system(system_manager_); system_manager_.create_system(system_manager_); - //system_manager_.create_system(system_manager_); //system_manager_.create_system(system_manager_); system_manager_.create_system(); system_manager_.create_system(); diff --git a/src/core/atomicdex/api/coinpaprika/coinpaprika.cpp b/src/core/atomicdex/api/coinpaprika/coinpaprika.cpp deleted file mode 100644 index 0287e13302..0000000000 --- a/src/core/atomicdex/api/coinpaprika/coinpaprika.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/****************************************************************************** - * Copyright © 2013-2024 The Komodo Platform Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * Komodo Platform software, including this file may be copied, modified, * - * propagated or distributed except according to the terms contained in the * - * LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -//! Deps -#include -#include - -//! Project Headers -#include "atomicdex/api/coinpaprika/coinpaprika.hpp" -#include "atomicdex/utilities/global.utilities.hpp" - -//! Private -#include "atomicdex/utilities/nlohmann.json.sax.private.cpp" - -namespace -{ - //! Constants - constexpr const char* g_coinpaprika_endpoint = "https://api.coinpaprika.com/v1/"; - web::http::client::http_client_config g_paprika_cfg{[]() { - web::http::client::http_client_config cfg; - cfg.set_validate_certificates(false); - cfg.set_timeout(std::chrono::seconds(5)); - return cfg; - }()}; - t_http_client_ptr g_coinpaprika_client = std::make_unique(FROM_STD_STR(g_coinpaprika_endpoint), g_paprika_cfg); -} // namespace - -namespace atomic_dex -{ - namespace coinpaprika::api - { - void - to_json(nlohmann::json& j, const price_converter_request& evt) - { - j["base_currency_id"] = evt.base_currency_id; - j["quote_currency_id"] = evt.quote_currency_id; - j["amount"] = 1; - } - - void - from_json(const nlohmann::json& j, price_converter_answer& evt) - { - // utils::details::my_json_sax sx; - // nlohmann::json::sax_parse(j.dump(), &sx); - - evt.base_currency_id = j.at("base_currency_id").get(); - evt.base_currency_name = j.at("base_currency_name").get(); - evt.base_price_last_updated = j.at("base_price_last_updated").get(); - evt.quote_currency_id = j.at("quote_currency_id").get(); - evt.quote_currency_name = j.at("quote_currency_name").get(); - evt.quote_price_last_updated = j.at("quote_price_last_updated").get(); - evt.amount = j.at("amount").get(); - evt.price = std::to_string(j.at("price").get()); - - std::replace(evt.price.begin(), evt.price.end(), ',', '.'); - } - - void - from_json(const nlohmann::json& j, ticker_info_answer& evt) - { - evt.answer = j.at("quotes"); - } - - void - from_json(const nlohmann::json& j, ticker_historical_answer& evt) - { - evt.answer = j; - } - - pplx::task - async_price_converter(const price_converter_request& request) - { - using namespace std::string_literals; - web::http::http_request req; - req.set_method(web::http::methods::GET); - auto&& [base_id, quote_id] = request; - const auto url = "/price-converter?base_currency_id="s + base_id + ""e_currency_id="s + quote_id + "&amount=1"s; - req.set_request_uri(FROM_STD_STR(url)); - return g_coinpaprika_client->request(req); - } - - pplx::task - async_ticker_info(const ticker_infos_request& request) - { - using ranges::views::ints; - using ranges::views::zip; - using namespace std::string_literals; - web::http::http_request req; - req.set_method(web::http::methods::GET); - auto&& [ticker_id, quotes] = request; - auto url = "/tickers/"s + ticker_id + "?quotes="s; - for (auto&& [cur_quote, idx]: zip(quotes, ints(0u, ranges::unreachable))) - { - url.append(cur_quote); - - //! Append only if not last element, idx start at 0, if idx + 1 == quotes.size(), we are on the last elemnt, we don't append. - if (idx < quotes.size() - 1) - { - url.append(","); - } - } - SPDLOG_INFO("url: {}", TO_STD_STR(g_coinpaprika_client->base_uri().to_string()) + url); - req.set_request_uri(FROM_STD_STR(url)); - return g_coinpaprika_client->request(req); - } - - pplx::task - async_ticker_historical(const ticker_historical_request& request) - { - using namespace std::string_literals; - web::http::http_request req; - req.set_method(web::http::methods::GET); - auto&& [ticker_id, timestamp, interval] = request; - const auto url = "/tickers/"s + ticker_id + "/historical?start="s + std::to_string(timestamp) + "&interval="s + interval; - SPDLOG_INFO("url: {}", url); - req.set_request_uri(FROM_STD_STR(url)); - return g_coinpaprika_client->request(req); - } - } // namespace coinpaprika::api -} // namespace atomic_dex diff --git a/src/core/atomicdex/api/coinpaprika/coinpaprika.hpp b/src/core/atomicdex/api/coinpaprika/coinpaprika.hpp deleted file mode 100644 index 3650d3f733..0000000000 --- a/src/core/atomicdex/api/coinpaprika/coinpaprika.hpp +++ /dev/null @@ -1,139 +0,0 @@ -/****************************************************************************** - * Copyright © 2013-2024 The Komodo Platform Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * Komodo Platform software, including this file may be copied, modified, * - * propagated or distributed except according to the terms contained in the * - * LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#pragma once - -//! Deps -#include -#include -#include - -//! Project Headers -#include "atomicdex/utilities/cpprestsdk.utilities.hpp" - -namespace -{ - constexpr const std::size_t g_nb_hours_in_a_week{168}; -} - -namespace atomic_dex -{ - namespace coinpaprika::api - { - struct ticker_historical_request - { - std::string ticker_currency_id; - std::size_t timestamp{static_cast( - std::chrono::duration_cast((std::chrono::system_clock::now() - std::chrono::hours(g_nb_hours_in_a_week)).time_since_epoch()).count())}; - std::string interval{"1d"}; - }; - - struct ticker_historical_answer - { - nlohmann::json answer{nlohmann::json::array()}; - int rpc_result_code; - std::string raw_result; - }; - - struct ticker_infos_request - { - std::string ticker_currency_id; - std::vector ticker_quotes; - }; - - struct ticker_info_answer - { - nlohmann::json answer; - int rpc_result_code; - std::string raw_result; - }; - - struct price_converter_request - { - std::string base_currency_id; - std::string quote_currency_id; - }; - - struct price_converter_answer - { - std::string base_currency_id; - std::string base_currency_name; - std::string base_price_last_updated; - std::string quote_currency_id; - std::string quote_currency_name; - std::string quote_price_last_updated; - std::size_t amount; - std::string price{"0.00"}; ///< we need trick here - int rpc_result_code; - std::string raw_result; - }; - - void to_json(nlohmann::json& j, const price_converter_request& evt); - - void from_json(const nlohmann::json& j, price_converter_answer& evt); - - void from_json(const nlohmann::json& j, ticker_info_answer& evt); - - void from_json(const nlohmann::json& j, ticker_historical_answer& evt); - - pplx::task async_price_converter(const price_converter_request& request); - pplx::task async_ticker_info(const ticker_infos_request& request); - pplx::task async_ticker_historical(const ticker_historical_request& request); - - template - TAnswer static inline process_generic_resp(web::http::http_response resp) - { - TAnswer answer; - std::string body = TO_STD_STR(resp.extract_string(true).get()); - if (resp.status_code() == static_cast(antara::app::http_code::bad_request)) - { - SPDLOG_WARN("rpc answer code is 400 (Bad Parameters), body: {}", body); - answer.rpc_result_code = resp.status_code(); - answer.raw_result = body; - return answer; - } - if (resp.status_code() == static_cast(antara::app::http_code::too_many_requests)) - { - SPDLOG_WARN("rpc answer code is 429 (Too Many requests), body: {}", body); - answer.rpc_result_code = resp.status_code(); - answer.raw_result = body; - return answer; - } - try - { - const auto json_answer = nlohmann::json::parse(body); - from_json(json_answer, answer); - answer.rpc_result_code = resp.status_code(); - answer.raw_result = body; - } - catch (const std::exception& error) - { - SPDLOG_ERROR("exception caught: error[{}], body: {}", error.what(), body); - answer.rpc_result_code = -1; - answer.raw_result = error.what(); - } - return answer; - } - } // namespace coinpaprika::api - - - using t_price_converter_answer = coinpaprika::api::price_converter_answer; - using t_price_converter_request = coinpaprika::api::price_converter_request; - using t_ticker_info_answer = coinpaprika::api::ticker_info_answer; - using t_ticker_infos_request = coinpaprika::api::ticker_infos_request; - using t_ticker_historical_answer = coinpaprika::api::ticker_historical_answer; - using t_ticker_historical_request = coinpaprika::api::ticker_historical_request; -} // namespace atomic_dex diff --git a/src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.cpp b/src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.cpp deleted file mode 100644 index 9719887871..0000000000 --- a/src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/****************************************************************************** - * Copyright © 2013-2024 The Komodo Platform Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * Komodo Platform software, including this file may be copied, modified, * - * propagated or distributed except according to the terms contained in the * - * LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -// Deps Headers -#include - -// Project Headers -#include "atomicdex/pages/qt.portfolio.page.hpp" -#include "atomicdex/services/price/coinpaprika/coinpaprika.provider.hpp" - -namespace -{ - //! Using namespace - using namespace std::chrono_literals; - using namespace atomic_dex::coinpaprika::api; - - //! Constants - constexpr std::uint16_t g_pending_init_tasks_limit = 3; -} // namespace - -//! Constructor/Destructor -namespace atomic_dex -{ - coinpaprika_provider::coinpaprika_provider(entt::registry& registry, ag::ecs::system_manager& system_manager) : - system(registry), m_system_manager(system_manager) - { - SPDLOG_INFO("coinpaprika_provider created"); - disable(); - dispatcher_.sink().connect<&coinpaprika_provider::on_mm2_started>(*this); - dispatcher_.sink().connect<&coinpaprika_provider::on_coin_enabled>(*this); - dispatcher_.sink().connect<&coinpaprika_provider::on_coin_disabled>(*this); - } - - coinpaprika_provider::~coinpaprika_provider() - { - SPDLOG_INFO("coinpaprika_provider destroyed"); - dispatcher_.sink().disconnect<&coinpaprika_provider::on_mm2_started>(*this); - dispatcher_.sink().disconnect<&coinpaprika_provider::on_coin_enabled>(*this); - dispatcher_.sink().disconnect<&coinpaprika_provider::on_coin_disabled>(*this); - } -} // namespace atomic_dex - -//! Private Generics -namespace atomic_dex -{ - template - TAnswer - coinpaprika_provider::get_infos(const std::string& ticker, const TRegistry& registry, TLockable& mutex) const - { - std::shared_lock lock(mutex); - const auto it = registry.find(ticker); - return it != registry.cend() ? it->second : TAnswer{}; - } -} // namespace atomic_dex - -//! RPC Generics -namespace atomic_dex -{ - void - coinpaprika_provider::verify_idx(t_ref_count_idx idx, uint16_t target_size, const std::vector& tickers) - { - if (idx != nullptr) - { - const auto cur = idx->fetch_add(1) + 1; - // SPDLOG_DEBUG("cur: {}, target size: {}, remaining before adding in the model: {}", cur, target_size, target_size - cur); - if (cur == target_size) - { - if (not tickers.empty()) - { - dispatcher_.trigger(tickers); - } - else - { - this->dispatcher_.trigger(""); - } - } - } - } - - template - void - coinpaprika_provider::generic_post_verification(std::shared_mutex& mtx, TContainer& container, std::string&& ticker, TAnswer&& answer, Args... args) - { - { - std::unique_lock lock(mtx); - container.insert_or_assign(std::move(ticker), std::forward(answer)); - } - verify_idx(std::move(args)...); - } - - template - void - coinpaprika_provider::generic_rpc_paprika_process( - const TRequest& request, std::string ticker, std::shared_mutex& mtx, std::unordered_map& container, TExecutorFunctor&& functor, - Args... args) - { - const auto answer_functor = [this, &mtx, &container, functor = std::forward(functor), request, ticker = std::move(ticker), - ... args = std::move(args)](web::http::http_response resp) mutable { - const auto answer = process_generic_resp(resp); - if (answer.rpc_result_code == static_cast(antara::app::http_code::too_many_requests)) - { - std::this_thread::sleep_for(1s); - generic_rpc_paprika_process(request, std::move(ticker), mtx, container, std::forward(functor), std::move(args)...); - } - else - { - generic_post_verification(mtx, container, std::move(ticker), std::move(answer), std::move(args)...); - } - }; - - functor(request).then(answer_functor).then(&handle_exception_pplx_task); - } -} // namespace atomic_dex - -//! RPC call -namespace atomic_dex -{ - template - void - coinpaprika_provider::process_provider(const coin_config_t& current_coin, Args... args) - { - const price_converter_request request{.base_currency_id = current_coin.coinpaprika_id, .quote_currency_id = "usd-us-dollars"}; - generic_rpc_paprika_process( - request, current_coin.ticker, m_provider_mutex, m_usd_rate_providers, - [](auto&& request) { return async_price_converter(std::forward(request)); }, std::move(args)...); - } - - template - void - coinpaprika_provider::process_ticker_infos(const coin_config_t& current_coin, Args... args) - { - const ticker_infos_request request{.ticker_currency_id = current_coin.coinpaprika_id, .ticker_quotes = {"USD", "EUR", "BTC"}}; - generic_rpc_paprika_process( - request, current_coin.ticker, m_ticker_infos_mutex, m_ticker_infos_registry, - [](auto&& request) { return async_ticker_info(std::forward(request)); }, std::move(args)...); - } - - template - void - coinpaprika_provider::process_ticker_historical(const coin_config_t& current_coin, Args... args) - { - const ticker_historical_request request{.ticker_currency_id = current_coin.coinpaprika_id, .interval = "2h"}; - generic_rpc_paprika_process( - request, current_coin.ticker, m_ticker_historical_mutex, m_ticker_historical_registry, - [](auto&& request) { return async_ticker_historical(std::forward(request)); }, std::move(args)...); - } -} // namespace atomic_dex - -//! System Override -namespace atomic_dex -{ - void - coinpaprika_provider::update() - { - } -} // namespace atomic_dex - -//! Events -namespace atomic_dex -{ - void - coinpaprika_provider::on_mm2_started([[maybe_unused]] const mm2_started& evt) - { - update_ticker_and_provider(); - } - - void - coinpaprika_provider::on_coin_enabled(const coin_enabled& evt) - { - SPDLOG_INFO("{} enabled, retrieve coinpaprika infos", fmt::format("{}", fmt::join(evt.tickers, ", "))); - auto idx{std::make_shared(0)}; - const auto target_size = evt.tickers.size() * g_pending_init_tasks_limit; - const auto* global_cfg_system = m_system_manager.get_system().get_global_cfg(); - for (auto&& ticker: evt.tickers) - { - const auto config = global_cfg_system->get_coin_info(ticker); - if (config.coinpaprika_id != "test-coin") - { - process_provider(config, idx, target_size, evt.tickers); - process_ticker_infos(config, idx, target_size, evt.tickers); - process_ticker_historical(config, idx, target_size, evt.tickers); - } - else - { - const std::uint16_t cur = idx->fetch_add(g_pending_init_tasks_limit) + g_pending_init_tasks_limit; ///< Manually skip the above 3 operations - if (cur == target_size) - { - this->dispatcher_.trigger(evt.tickers); - } - } - } - } - - void - coinpaprika_provider::on_coin_disabled(const coin_disabled& evt) - { - SPDLOG_INFO("{} disabled, removing from paprika provider", evt.ticker); - std::unique_lock lock(m_provider_mutex); - m_usd_rate_providers.erase(evt.ticker); - } -} // namespace atomic_dex - -//! Public member functions -namespace atomic_dex -{ - void - coinpaprika_provider::update_ticker_and_provider() - { - const auto coins = this->m_system_manager.get_system().get_global_cfg()->get_enabled_coins(); - auto idx{std::make_shared(0)}; - const auto target_size = coins.size(); - for (auto&& [_, current_coin]: coins) - { - if (current_coin.coinpaprika_id == "test-coin") - { - const std::uint16_t cur = idx->fetch_add(1) + 1; - if (cur == target_size) - { - dispatcher_.trigger(""); - } - continue; - } - process_ticker_infos(current_coin); - process_ticker_historical(current_coin); - process_provider(current_coin, idx, target_size, std::vector{}); - } - } - - std::string - coinpaprika_provider::get_rate_conversion(const std::string& ticker) const - { - return get_infos(ticker, m_usd_rate_providers, m_provider_mutex).price; - } - - t_ticker_info_answer - coinpaprika_provider::get_ticker_infos(const std::string& ticker) const - { - return get_infos(ticker, m_ticker_infos_registry, m_ticker_infos_mutex); - } - - t_ticker_historical_answer - coinpaprika_provider::get_ticker_historical(const std::string& ticker) const - { - return get_infos(ticker, m_ticker_historical_registry, m_ticker_historical_mutex); - } -} // namespace atomic_dex \ No newline at end of file diff --git a/src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.hpp b/src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.hpp deleted file mode 100644 index 01352719e5..0000000000 --- a/src/core/atomicdex/services/price/coinpaprika/coinpaprika.provider.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/****************************************************************************** - * Copyright © 2013-2024 The Komodo Platform Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * Komodo Platform software, including this file may be copied, modified, * - * propagated or distributed except according to the terms contained in the * - * LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -#pragma once - -//! STD -#include - -//! Deps -#include - -//! Project Headers -#include "atomicdex/api/coinpaprika/coinpaprika.hpp" -#include "atomicdex/events/events.hpp" - -namespace atomic_dex -{ - namespace ag = antara::gaming; - - class coinpaprika_provider final : public ag::ecs::pre_update_system - { - //! Typedefs - using t_ref_count_idx = std::shared_ptr; - using t_providers_registry = std::unordered_map; - using t_ticker_infos_registry = std::unordered_map; - using t_ticker_historical_registry = std::unordered_map; - - //! Private fields - - //! ag::system_manager - ag::ecs::system_manager& m_system_manager; - - //! Containers - t_providers_registry m_usd_rate_providers{}; ///< USD Rate Providers - t_ticker_infos_registry m_ticker_infos_registry{}; ///< Ticker info registry, key is the ticker - t_ticker_historical_registry m_ticker_historical_registry{}; ///< Ticker historical registry, key is the ticker - - //! Mutexes - mutable std::shared_mutex m_ticker_historical_mutex; - mutable std::shared_mutex m_ticker_infos_mutex; - mutable std::shared_mutex m_provider_mutex; - - //! Private member functions - void verify_idx(t_ref_count_idx idx = nullptr, uint16_t target_size = 0, const std::vector& tickers = {}); - - //! Private templated member functions - template - TAnswer get_infos(const std::string& ticker, const TRegistry& registry, TLockable& mutex) const ; - - template - void generic_post_verification(std::shared_mutex& mtx, TContainer& container, std::string&& ticker, TAnswer&& answer, Args... args); - - template - void generic_rpc_paprika_process( - const TRequest& request, std::string ticker, std::shared_mutex& mtx, std::unordered_map& container, - TExecutorFunctor&& functor, Args... args); - - //! Private RPC Call - template - void process_provider(const coin_config_t& current_coin, Args... args); - template - void process_ticker_infos(const coin_config_t& current_coin, Args... args); - template - void process_ticker_historical(const coin_config_t& current_coin, Args... args); - - public: - //! Deleted operation - coinpaprika_provider(coinpaprika_provider& other) = delete; - coinpaprika_provider(coinpaprika_provider&& other) = delete; - coinpaprika_provider& operator=(coinpaprika_provider& other) = delete; - coinpaprika_provider& operator=(coinpaprika_provider&& other) = delete; - - //! Constructor - coinpaprika_provider(entt::registry& registry, ag::ecs::system_manager& system_manager) ; - - //! Destructor - ~coinpaprika_provider() final; - - ///< Public API - - //! Update all the data of the provider in an async way - void update_ticker_and_provider(); - - //! Get the rate conversion for the given fiat. - [[nodiscard]] std::string get_rate_conversion(const std::string& ticker) const ; - - //! Get the ticker informations. - [[nodiscard]] t_ticker_info_answer get_ticker_infos(const std::string& ticker) const ; - - //! Get the ticker informations. - [[nodiscard]] t_ticker_historical_answer get_ticker_historical(const std::string& ticker) const ; - - ///< Events - - //! Event that occur when the mm2 process is launched correctly. - void on_mm2_started(const mm2_started& evt) ; - - //! Event that occur when a coin is correctly enabled. - void on_coin_enabled(const coin_enabled& evt) ; - - //! Event that occur when a coin is correctly disabled. - void on_coin_disabled(const coin_disabled& evt) ; - - //! Override ag::system functions - void update() final; - }; -} // namespace atomic_dex - -REFL_AUTO(type(atomic_dex::coinpaprika_provider)) \ No newline at end of file diff --git a/src/core/atomicdex/services/price/defi.stats.cpp b/src/core/atomicdex/services/price/defi.stats.cpp index 22bbd98d4c..1fc0b23356 100644 --- a/src/core/atomicdex/services/price/defi.stats.cpp +++ b/src/core/atomicdex/services/price/defi.stats.cpp @@ -17,7 +17,6 @@ //! Project Headers #include "atomicdex/services/price/defi.stats.hpp" #include "atomicdex/services/price/komodo_prices/komodo.prices.provider.hpp" -#include "atomicdex/api/coinpaprika/coinpaprika.hpp" #include "atomicdex/pages/qt.settings.page.hpp" #include "atomicdex/services/price/global.provider.hpp" diff --git a/src/core/atomicdex/services/price/global.provider.cpp b/src/core/atomicdex/services/price/global.provider.cpp index 1da473e6a7..179f187d5c 100644 --- a/src/core/atomicdex/services/price/global.provider.cpp +++ b/src/core/atomicdex/services/price/global.provider.cpp @@ -16,7 +16,6 @@ //! Project Headers #include "atomicdex/services/price/global.provider.hpp" -#include "atomicdex/api/coinpaprika/coinpaprika.hpp" #include "atomicdex/pages/qt.settings.page.hpp" #include "atomicdex/services/price/komodo_prices/komodo.prices.provider.hpp" @@ -96,69 +95,6 @@ namespace namespace atomic_dex { - void - global_price_service::refresh_other_coins_rates( - const std::string& quote_id, const std::string& ticker, bool with_update_providers, std::atomic_uint16_t nb_try) - { - nb_try += 1; - SPDLOG_INFO("refresh_other_coins_rates - try {}", nb_try.load()); - if (nb_try == 10) - { - SPDLOG_WARN("refresh other coins rates max try reached, skipping"); - return; - } - using namespace std::chrono_literals; - coinpaprika::api::price_converter_request request{.base_currency_id = "usd-us-dollars", .quote_currency_id = quote_id}; - auto error_functor = [this, quote_id, ticker, with_update_providers, nb_try_load = nb_try.load()](pplx::task previous_task) - { - try - { - previous_task.wait(); - } - catch (const std::exception& e) - { - SPDLOG_ERROR("pplx task error from refresh_other_coins_rates: {} - nb_try {}", e.what(), nb_try_load); - using namespace std::chrono_literals; - std::this_thread::sleep_for(1s); - this->refresh_other_coins_rates(quote_id, ticker, with_update_providers, nb_try_load); - }; - }; - coinpaprika::api::async_price_converter(request) - .then( - [this, quote_id, ticker, with_update_providers, nb_try_cap = nb_try.load()](web::http::http_response resp) - { - auto answer = coinpaprika::api::process_generic_resp(resp); - if (answer.rpc_result_code == static_cast(antara::app::http_code::too_many_requests)) - { - std::this_thread::sleep_for(1s); - SPDLOG_WARN("too many request - retrying"); - this->refresh_other_coins_rates(quote_id, ticker, with_update_providers, nb_try_cap); - } - else - { - SPDLOG_INFO("Successfully get the coinpaprika::api::async_price_converter answer after {} try", nb_try_cap); - if (answer.raw_result.find("error") == std::string::npos) - { - if (not answer.price.empty()) - { - std::unique_lock lock(m_coin_rate_mutex); - this->m_coin_rate_providers[ticker] = answer.price; - } - } - else - { - std::unique_lock lock(m_coin_rate_mutex); - this->m_coin_rate_providers[ticker] = "0.00"; - } - } - if (with_update_providers) - { - //this->m_system_manager.get_system().update_ticker_and_provider(); - } - }) - .then(error_functor); - } - global_price_service::global_price_service(entt::registry& registry, ag::ecs::system_manager& system_manager, atomic_dex::cfg& cfg) : system(registry), m_system_manager(system_manager), m_cfg(cfg) { From a547330214fefc3806a1f618a3a174591af6c385 Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 12:37:29 +0000 Subject: [PATCH 2/8] try get rid of paprika --- .../services/price/global.provider.cpp | 58 ------------------- 1 file changed, 58 deletions(-) diff --git a/src/core/atomicdex/services/price/global.provider.cpp b/src/core/atomicdex/services/price/global.provider.cpp index 179f187d5c..12d3cf403d 100644 --- a/src/core/atomicdex/services/price/global.provider.cpp +++ b/src/core/atomicdex/services/price/global.provider.cpp @@ -349,64 +349,6 @@ namespace atomic_dex } } - void - global_price_service::on_force_update_providers([[maybe_unused]] const force_update_providers& evt) - { - static std::atomic_size_t nb_try = 0; - nb_try += 1; - SPDLOG_INFO("Forcing update providers"); - auto error_functor = [this, evt](pplx::task previous_task) - { - try - { - previous_task.wait(); - } - catch (const std::exception& e) - { - SPDLOG_ERROR("pplx task error from async_fetch_fiat_rates: {} - nb_try {}", e.what(), nb_try); - using namespace std::chrono_literals; - std::this_thread::sleep_for(1s); - this->on_force_update_providers(evt); - }; - }; - async_fetch_fiat_rates() - .then( - [this](web::http::http_response resp) - { - this->m_other_fiats_rates = process_fetch_fiat_answer(resp); - const auto& mm2 = this->m_system_manager.get_system(); - const bool with_update = mm2.is_mm2_running(); - bool already_send = false; - const auto first_id = mm2.get_coin_info(g_primary_dex_coin).coinpaprika_id; - const auto second_id = mm2.get_coin_info(g_second_primary_dex_coin).coinpaprika_id; - - if (!first_id.empty()) - { - refresh_other_coins_rates(first_id, g_primary_dex_coin, false, 0); - } - if (!second_id.empty()) - { - refresh_other_coins_rates(second_id, g_second_primary_dex_coin, with_update, 0); - already_send = true; - } - for (auto&& coin: this->m_cfg.possible_currencies) - { - if (g_primary_dex_coin != coin && g_second_primary_dex_coin != coin) - { - refresh_other_coins_rates( - mm2.get_coin_info(coin).coinpaprika_id, - coin, - !already_send, - 0 - ); - } - } - SPDLOG_INFO("Successfully retrieving rate after {} try", nb_try); - nb_try = 0; - }) - .then(error_functor); - } - std::string global_price_service::get_fiat_rates(const std::string& fiat) const { From 0cad3dbceec8d33dea926a0f6e08dde6efd44034 Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 12:38:28 +0000 Subject: [PATCH 3/8] try get rid of paprika --- src/core/atomicdex/services/price/global.provider.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/atomicdex/services/price/global.provider.hpp b/src/core/atomicdex/services/price/global.provider.hpp index e4234e7fbe..ffaa2e818f 100644 --- a/src/core/atomicdex/services/price/global.provider.hpp +++ b/src/core/atomicdex/services/price/global.provider.hpp @@ -41,8 +41,6 @@ namespace atomic_dex t_update_time_point m_update_clock; mutable std::shared_mutex m_coin_rate_mutex; - void refresh_other_coins_rates(const std::string& quote_id, const std::string& ticker, bool with_update_providers = false, std::atomic_uint16_t idx = 0); - public: explicit global_price_service(entt::registry& registry, ag::ecs::system_manager& system_manager, atomic_dex::cfg& cfg); ~global_price_service() final = default; From 09f8b4c5039da6294858cf8ed47487cacc087d83 Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 13:10:07 +0000 Subject: [PATCH 4/8] try get rid of paprika --- src/core/atomicdex/events/events.hpp | 1 - src/core/atomicdex/pages/qt.settings.page.cpp | 1 - src/core/atomicdex/services/mm2/mm2.service.cpp | 1 - 3 files changed, 3 deletions(-) diff --git a/src/core/atomicdex/events/events.hpp b/src/core/atomicdex/events/events.hpp index 8b468b8031..ff32d7bbe4 100644 --- a/src/core/atomicdex/events/events.hpp +++ b/src/core/atomicdex/events/events.hpp @@ -31,7 +31,6 @@ namespace atomic_dex using mm2_initialized = entt::tag<"mm2_running_and_enabling"_hs>; using default_coins_enabled = entt::tag<"default_coins_enabled"_hs>; using current_currency_changed = entt::tag<"update_orders_and_swap_values"_hs>; - using force_update_providers = entt::tag<"force_update_providers"_hs>; using force_update_defi_stats = entt::tag<"force_update_defi_stats"_hs>; using download_started = entt::tag<"download_started"_hs>; using download_complete = entt::tag<"download_complete"_hs>; diff --git a/src/core/atomicdex/pages/qt.settings.page.cpp b/src/core/atomicdex/pages/qt.settings.page.cpp index 35ac7792d5..cf40fd257b 100644 --- a/src/core/atomicdex/pages/qt.settings.page.cpp +++ b/src/core/atomicdex/pages/qt.settings.page.cpp @@ -288,7 +288,6 @@ namespace atomic_dex SPDLOG_INFO("change currency {} to {}", m_config.current_currency, current_currency.toStdString()); atomic_dex::change_currency(m_config, current_currency.toStdString()); - // this->dispatcher_.trigger(); this->dispatcher_.trigger(); this->dispatcher_.trigger(); emit onCurrencyChanged(); diff --git a/src/core/atomicdex/services/mm2/mm2.service.cpp b/src/core/atomicdex/services/mm2/mm2.service.cpp index cccedaed77..5eee682678 100644 --- a/src/core/atomicdex/services/mm2/mm2.service.cpp +++ b/src/core/atomicdex/services/mm2/mm2.service.cpp @@ -2221,7 +2221,6 @@ namespace atomic_dex SPDLOG_DEBUG("{} l{} f[{}]", __FUNCTION__, __LINE__, std::filesystem::path(__FILE__).filename().string()); this->m_current_wallet_name = std::move(wallet_name); this->dispatcher_.trigger(this->retrieve_coins_informations()); - this->dispatcher_.trigger(); this->dispatcher_.trigger(); mm2_config cfg{ .passphrase = std::move(passphrase), From 91243700fb8da34b45a2e277322fc8f35b3e1d67 Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 13:30:55 +0000 Subject: [PATCH 5/8] try get rid of paprika --- src/core/atomicdex/services/price/global.provider.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/atomicdex/services/price/global.provider.cpp b/src/core/atomicdex/services/price/global.provider.cpp index 12d3cf403d..30514a7dcb 100644 --- a/src/core/atomicdex/services/price/global.provider.cpp +++ b/src/core/atomicdex/services/price/global.provider.cpp @@ -99,7 +99,6 @@ namespace atomic_dex system(registry), m_system_manager(system_manager), m_cfg(cfg) { m_update_clock = std::chrono::high_resolution_clock::now(); - this->dispatcher_.sink().connect<&global_price_service::on_force_update_providers>(*this); } } // namespace atomic_dex @@ -115,7 +114,6 @@ namespace atomic_dex if (s >= 5min) { SPDLOG_INFO("[global_price_service::update()] - 5min elapsed, updating providers"); - this->on_force_update_providers({}); m_update_clock = std::chrono::high_resolution_clock::now(); } } From 1e04f4f25421a0fd2b822cc30f0903553cfefedb Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 13:38:12 +0000 Subject: [PATCH 6/8] try get rid of paprika --- src/core/atomicdex/services/price/global.provider.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/atomicdex/services/price/global.provider.hpp b/src/core/atomicdex/services/price/global.provider.hpp index ffaa2e818f..0536326f64 100644 --- a/src/core/atomicdex/services/price/global.provider.hpp +++ b/src/core/atomicdex/services/price/global.provider.hpp @@ -61,8 +61,6 @@ namespace atomic_dex bool is_fiat_available(const std::string& fiat) const; bool is_currency_available(const std::string& currency) const; - //! Events - void on_force_update_providers([[maybe_unused]] const force_update_providers& evt); }; } // namespace atomic_dex From 75e61f6b3ce887ae2d1515aa578ee82580de0a6a Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 19:18:55 +0000 Subject: [PATCH 7/8] try get rid of paprika --- src/core/atomicdex/services/price/global.provider.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/core/atomicdex/services/price/global.provider.cpp b/src/core/atomicdex/services/price/global.provider.cpp index 30514a7dcb..267320df26 100644 --- a/src/core/atomicdex/services/price/global.provider.cpp +++ b/src/core/atomicdex/services/price/global.provider.cpp @@ -98,7 +98,7 @@ namespace atomic_dex global_price_service::global_price_service(entt::registry& registry, ag::ecs::system_manager& system_manager, atomic_dex::cfg& cfg) : system(registry), m_system_manager(system_manager), m_cfg(cfg) { - m_update_clock = std::chrono::high_resolution_clock::now(); + //m_update_clock = std::chrono::high_resolution_clock::now(); } } // namespace atomic_dex @@ -108,14 +108,6 @@ namespace atomic_dex global_price_service::update() { using namespace std::chrono_literals; - - const auto now = std::chrono::high_resolution_clock::now(); - const auto s = std::chrono::duration_cast(now - m_update_clock); - if (s >= 5min) - { - SPDLOG_INFO("[global_price_service::update()] - 5min elapsed, updating providers"); - m_update_clock = std::chrono::high_resolution_clock::now(); - } } std::string From ac46a281e129f78e2a36dffab619eae87abe461e Mon Sep 17 00:00:00 2001 From: cipig Date: Fri, 22 Mar 2024 21:36:04 +0000 Subject: [PATCH 8/8] remove duplicate code --- .../services/price/global.provider.cpp | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/src/core/atomicdex/services/price/global.provider.cpp b/src/core/atomicdex/services/price/global.provider.cpp index 267320df26..5bb7ca6bdc 100644 --- a/src/core/atomicdex/services/price/global.provider.cpp +++ b/src/core/atomicdex/services/price/global.provider.cpp @@ -19,43 +19,6 @@ #include "atomicdex/pages/qt.settings.page.hpp" #include "atomicdex/services/price/komodo_prices/komodo.prices.provider.hpp" -namespace -{ - web::http::client::http_client_config g_openrates_cfg{[]() - { - web::http::client::http_client_config cfg; - cfg.set_validate_certificates(false); - cfg.set_timeout(std::chrono::seconds(5)); - return cfg; - }()}; - t_http_client_ptr g_openrates_client = std::make_unique(FROM_STD_STR("https://defi-stats.komodo.earth"), g_openrates_cfg); - pplx::cancellation_token_source g_token_source; - - pplx::task - async_fetch_fiat_rates() - { - web::http::http_request req; - req.set_method(web::http::methods::GET); - req.set_request_uri(FROM_STD_STR("api/v3/rates/fixer_io")); - //SPDLOG_INFO("req: {}", TO_STD_STR(req.to_string())); - return g_openrates_client->request(req, g_token_source.get_token()); - } - - nlohmann::json - process_fetch_fiat_answer(web::http::http_response resp) - { - nlohmann::json answer; - if (resp.status_code() == 200) - { - answer = nlohmann::json::parse(TO_STD_STR(resp.extract_string(true).get())); - return answer; - } - - SPDLOG_WARN("unable to fetch last open rates"); - return answer; - } -} // namespace - namespace { std::string @@ -92,7 +55,6 @@ namespace } } // namespace - namespace atomic_dex { global_price_service::global_price_service(entt::registry& registry, ag::ecs::system_manager& system_manager, atomic_dex::cfg& cfg) :