File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -86,31 +86,33 @@ void Fiat::_update()
8686 }
8787}
8888
89- // rate returns the exchange rate of the fiat pair.
90- // eg. pair(eur,usd) -> amount of usd to buy/sell eur
89+ // rate returns the exchange rate of the fiat pair
9190double Fiat::rate (const currency_pair_t &pair)
9291{
93- _update ();
92+ try {
93+ _update ();
94+ }
95+ catch (...) {
96+ // if here _eur_to_currency_rate was aready filled by
97+ // the constructor, hence let's use the old values
98+ }
99+
94100 std::string base, quote;
95101 base = pair.first ;
96102 quote = pair.second ;
97103
98104 toupper (base);
99105 toupper (quote);
100106
101- // First convert eveything to EUR quotation, than change from
102- // base to quote
103107 if (base == " EUR" ) {
104- return _eur_to_currency_rate[quote];
108+ return 1 . / _eur_to_currency_rate[quote];
105109 }
106110
107111 if (quote == " EUR" ) {
108- return 1 . / _eur_to_currency_rate[base];
112+ return _eur_to_currency_rate[base];
109113 }
110114
111- // (1 / number of base for eur) * (number of quote for eur)
112- // number of quote for base
113- return _eur_to_currency_rate[quote] / _eur_to_currency_rate[base];
115+ return _eur_to_currency_rate[base] / _eur_to_currency_rate[quote];
114116}
115117
116118} // namespace at
You can’t perform that action at this time.
0 commit comments