Skip to content

coinprices/PriceHttpClientSource.hpp

Namespaces

Name
sgns

Classes

Name
class sgns::PriceHttpClientSource
Production tier adapter: a PriceHttpClient wrapped in the IPriceSource seam, closing over the manager's io_context (D-04).

Source code

#pragma once

#include "IPriceSource.hpp"
#include "PriceHttpClient.hpp"

#include <chrono>
#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace sgns
{
    class PriceHttpClientSource : public IPriceSource
    {
    public:
        PriceHttpClientSource( std::shared_ptr<boost::asio::io_context> ioc,
                               std::string                              baseUrl,
                               RetryConfig                              retryConfig     = {},
                               std::chrono::seconds                     holdOffDuration = std::chrono::seconds( 60 ),
                               RateLimitHoldOff::Clock                  clock = [] { return std::chrono::system_clock::now(); },
                               std::chrono::milliseconds                requestTimeout = std::chrono::milliseconds( 5000 ),
                               ResponseFormat                           responseFormat = ResponseFormat::CoinGeckoSimplePrice )
            : ioc_( std::move( ioc ) ),
              client_( std::move( baseUrl ),
                       std::move( retryConfig ),
                       holdOffDuration,
                       std::move( clock ),
                       requestTimeout,
                       responseFormat )
        {
        }

        PriceResult<std::vector<PriceQuote>> FetchPrices( const std::vector<std::string> &tokenIds,
                                                          const std::string              &currency = "usd" ) override
        {
            return client_.FetchPrices( ioc_, tokenIds, currency );
        }

    private:
        std::shared_ptr<boost::asio::io_context> ioc_;
        PriceHttpClient                          client_;
    };
} // namespace sgns

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