Skip to content

Commit

Permalink
Merge pull request #2383 from KomodoPlatform/show-stats
Browse files Browse the repository at this point in the history
Show trade volume for pair under pro orderbook
  • Loading branch information
smk762 authored Dec 5, 2023
2 parents 769d948 + e09ff3e commit e85f7ef
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 30 deletions.
20 changes: 18 additions & 2 deletions atomic_defi_design/Dex/Constants/General.qml
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,21 @@ QtObject {
return (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol
}

function convertUsd(v) {
let rate = API.app.get_rate_conversion("USD", API.app.settings_pg.current_currency)
let value = parseFloat(v) / parseFloat(rate)

if (API.app.settings_pg.current_fiat == API.app.settings_pg.current_currency) {
let fiat_rate = API.app.get_fiat_rate(API.app.settings_pg.current_fiat)
value = parseFloat(v) * parseFloat(fiat_rate)
}
return formatFiat("", value, API.app.settings_pg.current_currency)
}

function formatFiat(received, amount, fiat, precision=2) {
if (precision == 2 && fiat == "BTC") {
precision = 8
}
return diffPrefix(received) +
(fiat === API.app.settings_pg.current_fiat ? API.app.settings_pg.current_fiat_sign : API.app.settings_pg.current_currency_sign)
+ " " + (amount < 1E5 ? formatDouble(parseFloat(amount), precision, true) : nFormatter(parseFloat(amount), 2))
Expand Down Expand Up @@ -737,8 +751,10 @@ QtObject {
}

function getFiatText(v, ticker, has_info_icon=true) {
return General.formatFiat('', v === '' ? 0 : API.app.get_fiat_from_amount(ticker, v), API.app.settings_pg.current_fiat)
+ (has_info_icon ? " " + General.cex_icon : "")
let fiat_from_amount = API.app.get_fiat_from_amount(ticker, v)
let current_fiat = API.app.settings_pg.current_fiat
let formatted_fiat = General.formatFiat('', v === '' ? 0 : fiat_from_amount, current_fiat)
return formatted_fiat + (has_info_icon ? " " + General.cex_icon : "")
}

function hasParentCoinFees(trade_info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ RowLayout
id: bottom_line

property string fiat_value: !details ? "" :
General.formatFiat("", details.main_currency_balance, API.app.settings_pg.current_fiat_sign)
General.formatFiat("", details.main_currency_balance, API.app.settings_pg.current_currency)
text: fiat_value
Layout.fillWidth: true
elide: Text.ElideRight
Expand Down
23 changes: 19 additions & 4 deletions atomic_defi_design/Dex/Exchange/Trade/OrderBook/Vertical.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import Dex.Themes 1.0 as Dex
Widget
{
title: qsTr("Order Book")
readonly property string pair_volume_24hr: API.app.trading_pg.pair_volume_24hr
readonly property string pair: atomic_qt_utilities.retrieve_main_ticker(left_ticker) + "/" + atomic_qt_utilities.retrieve_main_ticker(right_ticker)

margins: 10
spacing: 10
margins: 8
spacing: 2

Header
{
Expand All @@ -32,14 +34,15 @@ Widget

Item
{
Layout.preferredHeight: 4
Layout.preferredHeight: 1
Layout.fillWidth: true
Rectangle
{
width: parent.width
height: parent.height
anchors.horizontalCenter: parent.horizontalCenter
color: Dex.CurrentTheme.floatingBackgroundColor
color: Dex.CurrentTheme.backgroundColor
opacity: 0.5
}
}

Expand All @@ -49,4 +52,16 @@ Widget
Layout.fillHeight: true
Layout.fillWidth: true
}

DefaultText
{
id: volume_text
visible: parseFloat(pair_volume_24hr) > 0
Layout.topMargin: 2
Layout.bottomMargin: 2
Layout.alignment: Qt.AlignHCenter
color: Dex.CurrentTheme.foregroundColor2
text_value: pair + qsTr(" traded 24hrs: %1").arg("<b>" + General.convertUsd(pair_volume_24hr) + "</b>")
font.pixelSize: Style.textSizeSmall1
}
}
2 changes: 1 addition & 1 deletion atomic_defi_design/Dex/Portfolio/AssetsList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Dex.DexListView
verticalAlignment: Text.AlignVCenter

text_value: Dex.General.formatFiat('', main_currency_price_for_one_unit,
Dex.API.app.settings_pg.current_currency, 6)
Dex.API.app.settings_pg.current_currency, 8)
}

Item // Price Provider
Expand Down
2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ set(EXPECTED_ENABLE_TESTS OFF CACHE BOOL "Override option" FORCE)

FetchContent_Declare(
expected
URL https://github.com/Milerius/expected/archive/patch-1.zip
URL https://github.com/KomodoPlatform/expected/archive/patch-1.zip
)

FetchContent_Declare(
Expand Down
15 changes: 15 additions & 0 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ namespace atomic_dex

system_manager_.create_system<wallet_page>(system_manager_, this);
system_manager_.create_system<global_price_service>(system_manager_, settings_page_system.get_cfg());
system_manager_.create_system<global_defi_stats_service>(system_manager_);
system_manager_.create_system<orderbook_scanner_service>(system_manager_);
//system_manager_.create_system<coinpaprika_provider>(system_manager_);
//system_manager_.create_system<coingecko_provider>(system_manager_);
Expand Down Expand Up @@ -684,6 +685,20 @@ namespace atomic_dex
//! Trading functions
namespace atomic_dex
{
QString
application::get_rate_conversion(const QString& fiat, const QString& ticker, bool adjusted)
{
const auto& price_service = system_manager_.get_system<global_price_service>();
return QString::fromStdString(price_service.get_rate_conversion(fiat.toStdString(), ticker.toStdString(), adjusted));
}

QString
application::get_fiat_rate(const QString& fiat)
{
const auto& price_service = system_manager_.get_system<global_price_service>();
return QString::fromStdString(price_service.get_fiat_rates(fiat.toStdString()));
}

QString
application::get_fiat_from_amount(const QString& ticker, const QString& amount)
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "atomicdex/services/exporter/exporter.service.hpp"
#include "atomicdex/services/internet/internet.checker.service.hpp"
#include "atomicdex/services/mm2/mm2.service.hpp"
#include "atomicdex/services/price/defi.stats.hpp"
#include "atomicdex/services/price/global.provider.hpp"
#include "atomicdex/services/update/update.checker.service.hpp"
#include "atomicdex/services/update/zcash.params.service.hpp"
Expand Down Expand Up @@ -165,7 +166,9 @@ namespace atomic_dex
Q_INVOKABLE bool disable_coins(const QStringList& coins);
Q_INVOKABLE bool disable_no_balance_coins();
Q_INVOKABLE bool has_coins_with_balance();
Q_INVOKABLE QString get_fiat_rate(const QString& fiat);
Q_INVOKABLE QString get_fiat_from_amount(const QString& ticker, const QString& amount);
Q_INVOKABLE QString get_rate_conversion(const QString& fiat, const QString& ticker, bool adjusted = false);

signals:
void walletMgrChanged();
Expand Down
13 changes: 7 additions & 6 deletions src/core/atomicdex/events/events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

namespace atomic_dex
{
using mm2_started = entt::tag<"mm2_started"_hs>;
using post_login = entt::tag<"post_login"_hs>;
using gui_enter_trading = entt::tag<"gui_enter_trading"_hs>;
using gui_leave_trading = entt::tag<"gui_leave_trading"_hs>;
using mm2_initialized = entt::tag<"mm2_running_and_enabling"_hs>;
using default_coins_enabled = entt::tag<"default_coins_enabled"_hs>;
using mm2_started = entt::tag<"mm2_started"_hs>;
using post_login = entt::tag<"post_login"_hs>;
using gui_enter_trading = entt::tag<"gui_enter_trading"_hs>;
using gui_leave_trading = entt::tag<"gui_leave_trading"_hs>;
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>;
using download_failed = entt::tag<"download_failed"_hs>;
Expand Down
2 changes: 1 addition & 1 deletion src/core/atomicdex/pages/qt.portfolio.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace atomic_dex
void
portfolio_page::on_update_portfolio_values_event(const update_portfolio_values& evt)
{
SPDLOG_INFO("Updating portfolio values with model: {}", evt.with_update_model);
// SPDLOG_DEBUG("Updating portfolio values with model: {}", evt.with_update_model);

bool res = true;
if (evt.with_update_model)
Expand Down
34 changes: 30 additions & 4 deletions src/core/atomicdex/pages/qt.trading.page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "atomicdex/pages/qt.trading.page.hpp"
#include "atomicdex/services/mm2/auto.update.maker.order.service.hpp"
#include "atomicdex/services/mm2/mm2.service.hpp"
#include "atomicdex/services/price/defi.stats.hpp"
#include "atomicdex/services/price/global.provider.hpp"
#include "atomicdex/utilities/qt.utilities.hpp"
#include "atomicdex/utilities/qt.download.manager.hpp"
Expand Down Expand Up @@ -702,6 +703,7 @@ namespace atomic_dex
this->m_preferred_order = std::nullopt;
this->m_fees = QVariantMap();
this->m_cex_price = "0";
this->m_pair_volume_24hr = "0";
this->m_post_clear_forms = true;
this->set_selected_order_status(SelectedOrderStatus::None);
this->reset_fees();
Expand Down Expand Up @@ -1039,6 +1041,7 @@ namespace atomic_dex
}
}
this->determine_cex_rates();
this->determine_pair_volume_24hr();
emit priceChanged();
emit priceReversedChanged();
return true;
Expand Down Expand Up @@ -1352,10 +1355,11 @@ namespace atomic_dex
{
const auto& price_service = m_system_manager.get_system<global_price_service>();
const auto* market_selector = get_market_pairs_mdl();
const auto& base = market_selector->get_left_selected_coin();
const auto& rel = market_selector->get_right_selected_coin();

if (auto cex_price = QString::fromStdString(price_service.get_cex_rates(base.toStdString(), rel.toStdString())); cex_price != m_cex_price)
const auto& base = market_selector->get_left_selected_coin().toStdString();
const auto& rel = market_selector->get_right_selected_coin().toStdString();
auto cex_price = QString::fromStdString(price_service.get_cex_rates(base, rel));

if (cex_price != m_cex_price)
{
m_cex_price = std::move(cex_price);
emit cexPriceChanged();
Expand All @@ -1365,6 +1369,28 @@ namespace atomic_dex
emit cexPriceDiffChanged();
}

void
trading_page::determine_pair_volume_24hr()
{
const auto& defi_stats_service = m_system_manager.get_system<global_defi_stats_service>();
const auto* market_selector = get_market_pairs_mdl();
const auto& base = utils::retrieve_main_ticker(market_selector->get_left_selected_coin().toStdString(), true);
const auto& rel = utils::retrieve_main_ticker(market_selector->get_right_selected_coin().toStdString(), true);
QString vol = QString::fromStdString(defi_stats_service.get_volume_24h_usd(base, rel));

if (vol != m_pair_volume_24hr)
{
m_pair_volume_24hr = vol;
emit pairVolume24hrChanged();
}
}

QString
trading_page::get_pair_volume_24hr() const
{
return m_pair_volume_24hr;
}

QString
trading_page::get_cex_price() const
{
Expand Down
7 changes: 6 additions & 1 deletion src/core/atomicdex/pages/qt.trading.page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace atomic_dex
Q_PROPERTY(QVariantMap preffered_order READ get_preferred_order WRITE set_preferred_order NOTIFY prefferedOrderChanged)
Q_PROPERTY(SelectedOrderStatus selected_order_status READ get_selected_order_status WRITE set_selected_order_status NOTIFY selectedOrderStatusChanged)
Q_PROPERTY(QString price_reversed READ get_price_reversed NOTIFY priceReversedChanged)
Q_PROPERTY(QString pair_volume_24hr READ get_pair_volume_24hr NOTIFY pairVolume24hrChanged)
Q_PROPERTY(QString cex_price READ get_cex_price NOTIFY cexPriceChanged)
Q_PROPERTY(QString cex_price_reversed READ get_cex_price_reversed NOTIFY cexPriceReversedChanged)
Q_PROPERTY(QString cex_price_diff READ get_cex_price_diff NOTIFY cexPriceDiffChanged)
Expand Down Expand Up @@ -113,6 +114,7 @@ namespace atomic_dex
QString m_max_volume{"0"};
QString m_total_amount{"0.00777"};
QString m_cex_price{"0"};
QString m_pair_volume_24hr{"0"};
QString m_minimal_trading_amount{"0.0001"};
std::optional<nlohmann::json> m_preferred_order;
boost::synchronized_value<QVariantMap> m_fees;
Expand All @@ -122,11 +124,12 @@ namespace atomic_dex
void determine_max_volume();
void determine_total_amount();
void determine_cex_rates();
void determine_pair_volume_24hr();
void cap_volume();
[[nodiscard]] t_float_50 get_max_balance_without_dust(const std::optional<QString>& trade_with = std::nullopt) const;
[[nodiscard]] TradingError generate_fees_error(QVariantMap fees) const;
void set_preferred_settings();
static QString calculate_total_amount(QString price, QString volume) ;
static QString calculate_total_amount(QString price, QString volume) ;

public:
//! Constructor
Expand Down Expand Up @@ -194,6 +197,7 @@ namespace atomic_dex
void set_total_amount(QString total_amount);
[[nodiscard]] QString get_base_amount() const;
[[nodiscard]] QString get_rel_amount() const;
[[nodiscard]] QString get_pair_volume_24hr() const;
[[nodiscard]] QString get_cex_price() const;
[[nodiscard]] QString get_cex_price_reversed() const;
[[nodiscard]] QString get_cex_price_diff() const;
Expand Down Expand Up @@ -234,6 +238,7 @@ namespace atomic_dex
void baseAmountChanged();
void relAmountChanged();
void feesChanged();
void pairVolume24hrChanged();
void cexPriceChanged();
void cexPriceReversedChanged();
void cexPriceDiffChanged();
Expand Down
3 changes: 2 additions & 1 deletion src/core/atomicdex/services/mm2/mm2.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ namespace atomic_dex

nlohmann::json mm2_service::prepare_batch_orderbook(bool is_a_reset)
{
SPDLOG_INFO("[prepare_batch_orderbook] is_a_reset: {}", is_a_reset);
// SPDLOG_DEBUG("[prepare_batch_orderbook] is_a_reset: {}", is_a_reset);
auto&& [base, rel] = m_synchronized_ticker_pair.get();
if (rel.empty())
return nlohmann::json::array();
Expand Down Expand Up @@ -1915,6 +1915,7 @@ namespace atomic_dex
this->m_current_wallet_name = std::move(wallet_name);
this->dispatcher_.trigger<coin_cfg_parsed>(this->retrieve_coins_informations());
this->dispatcher_.trigger<force_update_providers>();
this->dispatcher_.trigger<force_update_defi_stats>();
mm2_config cfg{.passphrase = std::move(passphrase), .rpc_password = atomic_dex::gen_random_password()};
mm2::set_system_manager(m_system_manager);
mm2::set_rpc_password(cfg.rpc_password);
Expand Down
Loading

0 comments on commit e85f7ef

Please sign in to comment.