-
Notifications
You must be signed in to change notification settings - Fork 3
feat: coingecko opg price feed #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4047a25
feat: Add CoinGecko OPG/USD price feed background service
kylexqian 5ff9fc9
refactor: Reorganize price feed into tee_gateway/price_feed/ package
kylexqian 69f7150
refactor: dependency injection for OPG price feed via make_cost_calcu…
kylexqian 7d52080
refactor: replace make_cost_calculator factory with calculate_session…
kylexqian c0d8373
feat: include price feed status in /health response
kylexqian f1b6526
test: verify calculate_session_cost fetches live price on every call
kylexqian 092f14d
fix: update test_pricing.py for calculate_session_cost signature change
kylexqian 996a950
fix: add attr-defined to type: ignore on monkey-patch line
kylexqian 3e1b81c
fix: address Copilot review comments on price feed
kylexqian 340476c
Update .github/workflows/test.yml
kylexqian be53f76
fix: update stale dynamic_session_cost_calculator references
kylexqian 5891728
feat: add pre-inference pricing gate and remove ineffective monkey-patch
kylexqian ba2258f
fix: address Copilot review comments (docstrings, defensive coding, t…
kylexqian 3b1da9a
feat: TGE fallback price and CoinGecko sanity checks
kylexqian b2e9702
feat: expire stale OPG price after 4 hours
kylexqian 6289250
Update tee_gateway/price_feed/feed.py
kylexqian caf076c
Update tee_gateway/util.py
kylexqian 4b9e582
Merge branch 'ani/token-update' into feat/coingecko-opg-price-feed
kylexqian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from .config import PriceFeedConfig | ||
| from .feed import OPGPriceFeed | ||
|
|
||
| __all__ = [ | ||
| "OPGPriceFeed", | ||
| "PriceFeedConfig", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Configuration constants and dataclass for the OPG price feed. | ||
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import datetime, timezone | ||
| from decimal import Decimal | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # CoinGecko API | ||
| # --------------------------------------------------------------------------- | ||
| COINGECKO_BASE_URL = "https://api.coingecko.com/api/v3" | ||
| COINGECKO_PLATFORM = "base" # Base mainnet platform identifier on CoinGecko | ||
| FETCH_TIMEOUT = 10 # seconds per HTTP request | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Refresh / retry defaults | ||
| # --------------------------------------------------------------------------- | ||
| DEFAULT_REFRESH_INTERVAL = 300 # 5 minutes between background refresh cycles | ||
| DEFAULT_MAX_RETRIES = 3 # attempts per refresh cycle before giving up | ||
| DEFAULT_RETRY_DELAY = 10 # seconds between retry attempts within a cycle | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # TGE (Token Generation Event) fallback | ||
| # --------------------------------------------------------------------------- | ||
| # Before the TGE cutover, OPG is not yet listed on CoinGecko. Return a fixed | ||
| # fallback price so inference requests can be priced immediately at launch. | ||
| # After the cutover, the live CoinGecko price is used. | ||
| TGE_CUTOVER_UTC = datetime(2026, 4, 21, 12, 30, 0, tzinfo=timezone.utc) | ||
| TGE_FALLBACK_PRICE_USD = Decimal("0.10") | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Stale-price thresholds | ||
| # --------------------------------------------------------------------------- | ||
| # get_price() logs WARNING when last successful fetch is older than | ||
| # STALE_WARNING_MULTIPLIER × refresh_interval seconds. | ||
| STALE_WARNING_MULTIPLIER = 2 | ||
|
|
||
| # get_price() raises ValueError when last successful fetch is older than | ||
| # STALE_PRICE_MAX_AGE seconds — at this point the cached price is considered | ||
| # too outdated to use for billing. | ||
| STALE_PRICE_MAX_AGE = 4 * 60 * 60 # 4 hours | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class PriceFeedConfig: | ||
| """Runtime configuration for the OPG price feed background service.""" | ||
|
|
||
| refresh_interval: int = DEFAULT_REFRESH_INTERVAL | ||
| max_retries: int = DEFAULT_MAX_RETRIES | ||
| retry_delay: float = DEFAULT_RETRY_DELAY |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_price_feed.start()performs a synchronous initial fetch with retries before returning. With defaults (FETCH_TIMEOUT=10,max_retries=3,retry_delay=10), a CoinGecko outage can delay process startup by ~50s. Consider starting the background thread first and doing the initial fetch asynchronously, or making the initial fetch/retry parameters configurable (or reduced) specifically for startup so the server can come up promptly.