Skip to content

coinprices/PriceFreshness.hpp

Namespaces

Name
sgns

Types

Name
enum class FreshnessBand { Fresh, StaleButUsable, Unavailable}
Freshness classification for a PriceQuote (FRESH-02).

Functions

Name
FreshnessBand ClassifyFreshness(std::chrono::system_clock::time_point fetchedAt, std::chrono::system_clock::time_point now)
Classify the freshness of a fetched quote.

Attributes

Name
constexpr std::chrono::seconds kFreshMaxAge
Shared freshness band constants (D-16) consumed by code and tests.
constexpr std::chrono::seconds kStaleMaxAge

Types Documentation

enum FreshnessBand

Enumerator Value Description
Fresh
StaleButUsable
Unavailable

Freshness classification for a PriceQuote (FRESH-02).

Functions Documentation

function ClassifyFreshness

inline FreshnessBand ClassifyFreshness(
    std::chrono::system_clock::time_point fetchedAt,
    std::chrono::system_clock::time_point now
)

Classify the freshness of a fetched quote.

Parameters:

  • fetchedAt D-14 fetch time of the quote
  • now Current time to classify against

Return: The freshness band for age = now - fetchedAt

Note:

  • Boundary rule (D-16): bands are closed on the fresh side. An age of exactly kFreshMaxAge (60s) classifies Fresh, and an age of exactly kStaleMaxAge (300s) classifies StaleButUsable.
  • The age is compared at the clock's native precision (no truncation to whole seconds) so sub-second boundary cases classify exactly.

Attributes Documentation

variable kFreshMaxAge

constexpr std::chrono::seconds kFreshMaxAge { 60 };

Shared freshness band constants (D-16) consumed by code and tests.

variable kStaleMaxAge

constexpr std::chrono::seconds kStaleMaxAge { 300 };

Source code

#pragma once

#include <chrono>

namespace sgns
{
    inline constexpr std::chrono::seconds kFreshMaxAge{ 60 };
    inline constexpr std::chrono::seconds kStaleMaxAge{ 300 };

    enum class FreshnessBand
    {
        Fresh,
        StaleButUsable,
        Unavailable
    };

    inline FreshnessBand ClassifyFreshness( std::chrono::system_clock::time_point fetchedAt,
                                             std::chrono::system_clock::time_point now )
    {
        const auto age = now - fetchedAt;
        if ( age <= kFreshMaxAge )
        {
            return FreshnessBand::Fresh;
        }
        if ( age <= kStaleMaxAge )
        {
            return FreshnessBand::StaleButUsable;
        }
        return FreshnessBand::Unavailable;
    }
}

Updated on 2026-10-09 at 04:02:50 +0000