Skip to content

coinprices/PriceResponseParsers.hpp

Namespaces

Name
sgns

Types

Name
enum class ResponseFormat { CoinGeckoSimplePrice, GnusEnvelope}
Which wire format a PriceHttpClient instance speaks.

Functions

Name
PriceResult< std::vector< PriceQuote > > ParseCoinGeckoSimplePrice(const std::string & body, const std::vector< std::string > & tokenIds, const std::string & currency, std::chrono::system_clock::time_point fetchTime)
Parse a CoinGecko /simple/price 200-body into quotes.
PriceResult< std::vector< PriceQuote > > ParseGnusPriceEnvelope(const std::string & body, const std::vector< std::string > & tokenIds, const std::string & currency)
Parse a token.gnus.ai price envelope into quotes.

Types Documentation

enum ResponseFormat

Enumerator Value Description
CoinGeckoSimplePrice tier 1 — CoinGecko direct: {"id":{"usd":0.19}}
GnusEnvelope tier 2 — token.gnus.ai:

Which wire format a PriceHttpClient instance speaks.

Functions Documentation

function ParseCoinGeckoSimplePrice

PriceResult< std::vector< PriceQuote > > ParseCoinGeckoSimplePrice(
    const std::string & body,
    const std::vector< std::string > & tokenIds,
    const std::string & currency,
    std::chrono::system_clock::time_point fetchTime
)

Parse a CoinGecko /simple/price 200-body into quotes.

Parameters:

  • body The 200 response body
  • tokenIds Requested ids — quotes are emitted for requested ids present in the body; unknown ids stay absent, not errors (D-09)
  • currency Target currency
  • fetchTime D-14 fetch time stamped on every quote

Return: One PriceQuote per requested id found in the body, or NoDataFound when none matched, or JsonParseError on malformed JSON (status 0 — the HTTP status belongs to the facade layer)

function ParseGnusPriceEnvelope

PriceResult< std::vector< PriceQuote > > ParseGnusPriceEnvelope(
    const std::string & body,
    const std::vector< std::string > & tokenIds,
    const std::string & currency
)

Parse a token.gnus.ai price envelope into quotes.

Parameters:

  • body The 200 response body (Phase-1 envelope.ts contract)
  • tokenIds Requested ids — quotes are emitted for requested ids present in prices; absent ids stay absent, not errors (D-09)
  • currency Expected target currency (envelope currency)

Return: One PriceQuote per requested id found in prices, or NoDataFound when none matched, or JsonParseError on malformed JSON / an unknown source string (status 0 — the HTTP status belongs to the facade layer)

Note:

  • LANDMINE: envelope fetchedAt is epoch SECONDS (never ms) and is the max across the returned ids, SHARED by all quotes — do not invent per-id timestamps (Phase-1 D-11).
  • LANDMINE: the envelope source names the upstream that PRODUCED the price, not the serving tier — "coingecko" maps to PriceSource::CoinGecko and "coingecko-cache" to PriceSource::GnusPriceService (Phase-1 D-06). Counterintuitive but contractual; do NOT "fix" this.

Source code

#pragma once

#include "PriceFetchError.hpp"
#include "PriceQuote.hpp"

#include <chrono>
#include <string>
#include <vector>

namespace sgns
{
    enum class ResponseFormat
    {
        CoinGeckoSimplePrice, 
        GnusEnvelope          
    };

    PriceResult<std::vector<PriceQuote>> ParseCoinGeckoSimplePrice( const std::string              &body,
                                                                    const std::vector<std::string> &tokenIds,
                                                                    const std::string              &currency,
                                                                    std::chrono::system_clock::time_point fetchTime );

    PriceResult<std::vector<PriceQuote>> ParseGnusPriceEnvelope( const std::string              &body,
                                                                 const std::vector<std::string> &tokenIds,
                                                                 const std::string              &currency );
} // namespace sgns

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