Skip to content

Feat: add GET /auth/finance/energy-balance endpoint#3

Open
mukama wants to merge 4 commits intotetherto:developfrom
mukama:feat/finance-energy-balance
Open

Feat: add GET /auth/finance/energy-balance endpoint#3
mukama wants to merge 4 commits intotetherto:developfrom
mukama:feat/finance-energy-balance

Conversation

@mukama
Copy link
Contributor

@mukama mukama commented Feb 11, 2026

Summary

  • Add GET /auth/finance/energy-balance endpoint with daily consumption, revenue, BTC price, and cost data
  • Add curtailment rate, operational issues rate, and power utilization calculations
  • Support period param for daily/monthly/yearly aggregation
  • Support site param for site-specific production costs

Example Queries

Daily (default):

/auth/finance/energy-balance?start=1735689600000&end=1770898000000

Monthly:

/auth/finance/energy-balance?start=1735689600000&end=1770898000000&period=monthly

Yearly:

/auth/finance/energy-balance?start=1735689600000&end=1770898000000&period=yearly

Force fresh data (skip cache):

/auth/finance/energy-balance?start=1735689600000&end=1770898000000&overwriteCache=true

Add energy balance API endpoint that aggregates power consumption,
pool transactions, BTC prices, and production costs into a unified
time-series response with period-based aggregation (daily/monthly/yearly).

Includes shared infrastructure: period.utils, constants for RPC methods,
worker types, aggregation fields, and utility functions (getStartOfDay,
safeDiv, runParallel).
…nergy-balance

- Add ELECTRICITY worker type, ENERGY_AGGR/ACTIVE_ENERGY_IN/UTE_ENERGY aggr fields,
  and GLOBAL_CONFIG RPC method to constants
- Add 3 new parallel RPC calls: electricity stats-history (active_energy_in,
  ute_energy) and getGlobalConfig (nominalPowerAvailability_MW)
- Calculate curtailmentMWh, curtailmentRate, operationalIssuesRate, and
  powerUtilization per log entry
- Add avgCurtailmentRate, avgOperationalIssuesRate, avgPowerUtilization to summary
- Fix getProductionCosts to use ctx.globalDataLib instead of direct Hyperbee access
- Fix processCostsData to return daily costs (energyCostPerDay, operationalCostPerDay)
- Update tests to match new cost format and globalDataLib mock
@mukama mukama marked this pull request as ready for review February 12, 2026 15:27
@mukama mukama changed the base branch from main to develop February 13, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant