Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/atomic.dex.app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,17 @@ namespace atomic_dex
}
} // namespace atomic_dex

//! Trading functions
namespace atomic_dex
{
QString
application::get_cex_rates(const QString& base, const QString& rel)
{
std::error_code ec;
return QString::fromStdString(get_paprika().get_cex_rates(base.toStdString(), rel.toStdString(), ec));
}
}

//! OHLC Relative functions
namespace atomic_dex
{
Expand Down
1 change: 1 addition & 0 deletions src/atomic.dex.app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ namespace atomic_dex
Q_INVOKABLE QObject* claim_rewards(const QString& ticker);
Q_INVOKABLE QVariantList get_ohlc_data(const QString& range);
Q_INVOKABLE QVariantMap find_closest_ohlc_data(int range, int timestamp);
Q_INVOKABLE QString get_cex_rates(const QString& base, const QString& rel);

Q_INVOKABLE bool is_supported_ohlc_data_ticker_pair(const QString& base, const QString& rel);
Q_INVOKABLE QObject* get_coin_info(const QString& ticker);
Expand Down
29 changes: 28 additions & 1 deletion src/atomic.dex.provider.coinpaprika.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,32 @@ namespace atomic_dex
return m_ticker_historical_registry.find(ticker) != m_ticker_historical_registry.cend() ? m_ticker_historical_registry.at(ticker)
: t_ticker_historical_answer{.answer = nlohmann::json::array()};
}


std::string
coinpaprika_provider::get_cex_rates(const std::string& base, const std::string& rel, std::error_code& ec) const noexcept
{
std::string base_rate_str = get_rate_conversion("USD", base, ec, false);
if (ec)
{
return "0.00";
}
std::string rel_rate_str = get_rate_conversion("USD", rel, ec, false);
if (ec)
{
return "0.00";
}
if (base_rate_str == "0.00" || rel_rate_str == "0.00")
{
//! One of the rate is not available
return "0.00";
}
t_float_50 base_rate_f(base_rate_str);
t_float_50 rel_rate_f(rel_rate_str);
t_float_50 result = base_rate_f / rel_rate_f;
std::string result_str = result.str(8, std::ios_base::fixed);
boost::trim_right_if(result_str, boost::is_any_of("0"));
boost::trim_right_if(result_str, boost::is_any_of("."));
return result_str;
}

} // namespace atomic_dex
3 changes: 3 additions & 0 deletions src/atomic.dex.provider.coinpaprika.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ namespace atomic_dex
//! Get the price in fiat from a transaction.
std::string get_price_in_fiat_from_tx(const std::string& fiat, const std::string& ticker, const tx_infos& tx, std::error_code& ec) const noexcept;

//! Get the cex rates base / rel eg: VRSC / KMD = price of usd VRSC / KMD price USD
std::string get_cex_rates(const std::string& base, const std::string& rel, std::error_code& ec) const noexcept;

//! Get the ticker informations.
t_ticker_info_answer get_ticker_infos(const std::string& ticker) const noexcept;

Expand Down