From 1fad2ec7c135ebe87bb34838f21adaac720dda03 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 24 Jun 2009 18:08:56 +0100 Subject: More refactoring for --download --- src/commodity.cc | 56 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'src/commodity.cc') diff --git a/src/commodity.cc b/src/commodity.cc index db7fabd6..900fe07d 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -346,26 +346,6 @@ optional " found price " << best.price << " from " << best.when); DEBUG("commodity.download", "found price " << best.price << " from " << best.when); -#endif -#if 0 - DEBUG("commodity.download", "leeway = " << download_leeway); - datetime_t::sec_type seconds_diff; - if (moment) { - seconds_diff = (*moment - best.when).total_seconds(); - DEBUG("commodity.download", "moment = " << *moment); - DEBUG("commodity.download", "slip.moment = " << seconds_diff); - } else { - seconds_diff = (CURRENT_TIME() - best.when).total_seconds(); - DEBUG("commodity.download", "slip.now = " << seconds_diff); - } - - if (download_quotes && ! source.has_flags(COMMODITY_NOMARKET) && - seconds_diff > download_leeway) { - DEBUG("commodity.download", - "attempting to download a more current quote..."); - if (optional quote = source.download_quote(commodity)) - return quote; - } #endif return best; } @@ -398,6 +378,42 @@ optional return none; } +optional +commodity_t::check_for_updated_price(const optional& point, + const optional& moment, + const optional& in_terms_of) +{ + if (parent().get_quotes && ! has_flags(COMMODITY_NOMARKET)) { + bool exceeds_leeway = true; + + if (point) { + time_duration_t::sec_type seconds_diff; + if (moment) { + seconds_diff = (*moment - point->when).total_seconds(); + DEBUG("commodity.download", "moment = " << *moment); + DEBUG("commodity.download", "slip.moment = " << seconds_diff); + } else { + seconds_diff = (CURRENT_TIME() - point->when).total_seconds(); + DEBUG("commodity.download", "slip.now = " << seconds_diff); + } + + DEBUG("commodity.download", "leeway = " << parent().quote_leeway); + if (seconds_diff < parent().quote_leeway) + exceeds_leeway = false; + } + + if (exceeds_leeway) { + DEBUG("commodity.download", + "attempting to download a more current quote..."); + if (optional quote = + parent().get_commodity_quote(*this, in_terms_of)) { + return quote; + } + } + } + return point; +} + commodity_t::operator bool() const { return this != parent().null_commodity; -- cgit v1.2.3