Skip to content

Instantly share code, notes, and snippets.

@Milerius
Created November 19, 2020 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Milerius/5d5f860df14ad1a400579c44361bc639 to your computer and use it in GitHub Desktop.
Save Milerius/5d5f860df14ad1a400579c44361bc639 to your computer and use it in GitHub Desktop.
void
trading_page::determine_fees() noexcept
{
const auto* market_pair = get_market_pairs_mdl();
const auto& mm2 = this->m_system_manager.get_system<mm2_service>();
//! Send
const auto base = market_pair->get_base_selected_coin();
//! Receive
const auto rel = market_pair->get_rel_selected_coin();
//! (send) BCH <-> ETH (receive)
bool is_max = false;
//! If We are in sell mode check if it's max
if (m_market_mode == MarketMode::Sell)
{
if (m_volume == m_max_volume) //! It's capped, means max_trade_vol means all the fees are included
{
is_max = true;
}
}
//! Trading fees
//! 1 / 777 * total_amount (if max is true, total_amount will be the balance);
const t_float_50 trade_fee_f = mm2.get_trading_fees(base.toStdString(), m_total_amount.toStdString(), is_max);
//! Transaction Fees
const auto answer = mm2.get_transaction_fees(base.toStdString());
t_float_50 tx_fee_f = 0;
//! If answer is valid
if (!answer.amount.empty())
{
tx_fee_f = t_float_50(answer.amount) * 2;
}
t_float_50 specific_fees(0);
const std::string extra_fees_ticker = mm2.apply_specific_fees(rel.toStdString(), specific_fees);
//! Write output
QVariantMap fees;
fees["trading_fee"] = QString::fromStdString(utils::format_float(trade_fee_f));
//! for BCH <-> ETH, trading_fee_ticker will be BCH
fees["trading_fee_ticker"] = base;
//! Base transaction fees
fees["base_transaction_fees"] = QString::fromStdString(utils::format_float(tx_fee_f));
fees["base_transaction_fees_ticker"] = QString::fromStdString(answer.coin);
if (not extra_fees_ticker.empty())
{
fees["rel_transaction_fees"] = QString::fromStdString(utils::format_float(specific_fees));
fees["rel_transaction_fees_ticker"] = QString::fromStdString(extra_fees_ticker);
}
this->set_fees(fees);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment