global: snapshot

This commit is contained in:
nym21
2026-03-07 00:25:20 +01:00
parent 9507eb3de5
commit 011e49e1cc
28 changed files with 256 additions and 395 deletions
@@ -25,15 +25,15 @@ pub struct RealizedAdjusted<M: StorageMode = Rw> {
impl RealizedAdjusted {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
Ok(RealizedAdjusted {
adjusted_value_created: cfg.import_computed("adjusted_value_created", Version::ZERO)?,
adjusted_value_created: cfg.import("adjusted_value_created", Version::ZERO)?,
adjusted_value_destroyed: cfg
.import_computed("adjusted_value_destroyed", Version::ZERO)?,
.import("adjusted_value_destroyed", Version::ZERO)?,
adjusted_value_created_sum: cfg
.import_rolling("adjusted_value_created", Version::ONE)?,
.import("adjusted_value_created", Version::ONE)?,
adjusted_value_destroyed_sum: cfg
.import_rolling("adjusted_value_destroyed", Version::ONE)?,
adjusted_sopr: cfg.import_rolling("adjusted_sopr", Version::ONE)?,
adjusted_sopr_ema: cfg.import_emas_1w_1m("adjusted_sopr_24h", Version::ONE)?,
.import("adjusted_value_destroyed", Version::ONE)?,
adjusted_sopr: cfg.import("adjusted_sopr", Version::ONE)?,
adjusted_sopr_ema: cfg.import("adjusted_sopr_24h", Version::ONE)?,
})
}
@@ -76,26 +76,26 @@ impl RealizedBase {
cfg.indexes,
);
let realized_profit_ema_1w = cfg.import_computed("realized_profit_ema_1w", v0)?;
let realized_loss_ema_1w = cfg.import_computed("realized_loss_ema_1w", v0)?;
let realized_profit_ema_1w = cfg.import("realized_profit_ema_1w", v0)?;
let realized_loss_ema_1w = cfg.import("realized_loss_ema_1w", v0)?;
let net_realized_pnl = cfg.import_cumulative("net_realized_pnl", v0)?;
let net_realized_pnl_ema_1w = cfg.import_computed("net_realized_pnl_ema_1w", v0)?;
let gross_pnl = cfg.import_fiat("realized_gross_pnl", v0)?;
let net_realized_pnl = cfg.import("net_realized_pnl", v0)?;
let net_realized_pnl_ema_1w = cfg.import("net_realized_pnl_ema_1w", v0)?;
let gross_pnl = cfg.import("realized_gross_pnl", v0)?;
let realized_profit_rel_to_realized_cap =
cfg.import_percent_bp32("realized_profit_rel_to_realized_cap", Version::new(2))?;
cfg.import("realized_profit_rel_to_realized_cap", Version::new(2))?;
let realized_loss_rel_to_realized_cap =
cfg.import_percent_bp32("realized_loss_rel_to_realized_cap", Version::new(2))?;
cfg.import("realized_loss_rel_to_realized_cap", Version::new(2))?;
let net_realized_pnl_rel_to_realized_cap =
cfg.import_percent_bps32("net_realized_pnl_rel_to_realized_cap", Version::new(2))?;
cfg.import("net_realized_pnl_rel_to_realized_cap", Version::new(2))?;
let value_created = cfg.import_computed("value_created", v0)?;
let value_destroyed = cfg.import_computed("value_destroyed", v0)?;
let value_created_sum = cfg.import_rolling("value_created", v1)?;
let value_destroyed_sum = cfg.import_rolling("value_destroyed", v1)?;
let sopr = cfg.import_rolling("sopr", v1)?;
let sopr_24h_ema = cfg.import_emas_1w_1m("sopr_24h", v1)?;
let value_created = cfg.import("value_created", v0)?;
let value_destroyed = cfg.import("value_destroyed", v0)?;
let value_created_sum = cfg.import("value_created", v1)?;
let value_destroyed_sum = cfg.import("value_destroyed", v1)?;
let sopr = cfg.import("sopr", v1)?;
let sopr_24h_ema = cfg.import("sopr_24h", v1)?;
let realized_price_ratio_percentiles =
ComputedFromHeightRatioPercentiles::forced_import(
@@ -107,7 +107,7 @@ impl RealizedBase {
Ok(Self {
minimal,
realized_cap_change_1m: cfg.import_computed("realized_cap_change_1m", v0)?,
realized_cap_change_1m: cfg.import("realized_cap_change_1m", v0)?,
neg_realized_loss,
net_realized_pnl,
net_realized_pnl_ema_1w,
@@ -124,10 +124,10 @@ impl RealizedBase {
sopr,
sopr_24h_ema,
realized_price_ratio_percentiles,
sent_in_profit: cfg.import_value_cumulative("sent_in_profit", v0)?,
sent_in_loss: cfg.import_value_cumulative("sent_in_loss", v0)?,
sent_in_profit_ema: cfg.import_emas_2w("sent_in_profit", v0)?,
sent_in_loss_ema: cfg.import_emas_2w("sent_in_loss", v0)?,
sent_in_profit: cfg.import("sent_in_profit", v0)?,
sent_in_loss: cfg.import("sent_in_loss", v0)?,
sent_in_profit_ema: cfg.import("sent_in_profit", v0)?,
sent_in_loss_ema: cfg.import("sent_in_loss", v0)?,
})
}
@@ -82,10 +82,12 @@ impl RealizedFull {
let core = RealizedBase::forced_import(cfg)?;
let profit_value_created = cfg.import_computed("profit_value_created", v0)?;
let profit_value_destroyed = cfg.import_computed("profit_value_destroyed", v0)?;
let loss_value_created = cfg.import_computed("loss_value_created", v0)?;
let loss_value_destroyed = cfg.import_computed("loss_value_destroyed", v0)?;
let profit_value_created = cfg.import("profit_value_created", v0)?;
let profit_value_destroyed: ComputedFromHeight<Cents> =
cfg.import("profit_value_destroyed", v0)?;
let loss_value_created = cfg.import("loss_value_created", v0)?;
let loss_value_destroyed: ComputedFromHeight<Cents> =
cfg.import("loss_value_destroyed", v0)?;
let capitulation_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
&cfg.name("capitulation_flow"),
@@ -100,24 +102,24 @@ impl RealizedFull {
&profit_value_destroyed,
);
let gross_pnl_sum = cfg.import_rolling("gross_pnl_sum", Version::ONE)?;
let gross_pnl_sum = cfg.import("gross_pnl_sum", Version::ONE)?;
let investor_price = cfg.import_price("investor_price", v0)?;
let investor_price_ratio = cfg.import_ratio("investor_price", v0)?;
let lower_price_band = cfg.import_price("lower_price_band", v0)?;
let upper_price_band = cfg.import_price("upper_price_band", v0)?;
let investor_price = cfg.import("investor_price", v0)?;
let investor_price_ratio = cfg.import("investor_price", v0)?;
let lower_price_band = cfg.import("lower_price_band", v0)?;
let upper_price_band = cfg.import("upper_price_band", v0)?;
let cap_raw = cfg.import_bytes("cap_raw", v0)?;
let investor_cap_raw = cfg.import_bytes("investor_cap_raw", v0)?;
let cap_raw = cfg.import("cap_raw", v0)?;
let investor_cap_raw = cfg.import("investor_cap_raw", v0)?;
let sell_side_risk_ratio =
cfg.import_percent_rolling_bp32("sell_side_risk_ratio", Version::new(2))?;
cfg.import("sell_side_risk_ratio", Version::new(2))?;
let sell_side_risk_ratio_24h_ema =
cfg.import_percent_emas_1w_1m_bp32("sell_side_risk_ratio_24h", Version::new(2))?;
cfg.import("sell_side_risk_ratio_24h", Version::new(2))?;
let peak_regret = cfg.import_cumulative("realized_peak_regret", Version::new(2))?;
let peak_regret = cfg.import("realized_peak_regret", Version::new(2))?;
let peak_regret_rel_to_realized_cap =
cfg.import_percent_bp32("realized_peak_regret_rel_to_realized_cap", Version::new(2))?;
cfg.import("realized_peak_regret_rel_to_realized_cap", Version::new(2))?;
let realized_price_name = cfg.name("realized_price");
let realized_price_version = cfg.version + v1;
@@ -133,11 +135,11 @@ impl RealizedFull {
capitulation_flow,
profit_flow,
gross_pnl_sum,
net_pnl_change_1m: cfg.import_computed("net_pnl_change_1m", Version::new(3))?,
net_pnl_change_1m: cfg.import("net_pnl_change_1m", Version::new(3))?,
net_pnl_change_1m_rel_to_realized_cap: cfg
.import_percent_bps32("net_pnl_change_1m_rel_to_realized_cap", Version::new(4))?,
.import("net_pnl_change_1m_rel_to_realized_cap", Version::new(4))?,
net_pnl_change_1m_rel_to_market_cap: cfg
.import_percent_bps32("net_pnl_change_1m_rel_to_market_cap", Version::new(4))?,
.import("net_pnl_change_1m_rel_to_market_cap", Version::new(4))?,
investor_price,
investor_price_ratio,
lower_price_band,
@@ -149,11 +151,11 @@ impl RealizedFull {
peak_regret,
peak_regret_rel_to_realized_cap,
realized_cap_rel_to_own_market_cap: cfg
.import_percent_bp32("realized_cap_rel_to_own_market_cap", v1)?,
realized_profit_sum: cfg.import_rolling("realized_profit", v1)?,
realized_loss_sum: cfg.import_rolling("realized_loss", v1)?,
.import("realized_cap_rel_to_own_market_cap", v1)?,
realized_profit_sum: cfg.import("realized_profit", v1)?,
realized_loss_sum: cfg.import("realized_loss", v1)?,
realized_profit_to_loss_ratio: cfg
.import_rolling("realized_profit_to_loss_ratio", v1)?,
.import("realized_profit_to_loss_ratio", v1)?,
realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import(
cfg.db,
&realized_price_name,
@@ -29,7 +29,8 @@ pub struct RealizedMinimal<M: StorageMode = Rw> {
impl RealizedMinimal {
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
let realized_cap_cents = cfg.import_computed("realized_cap_cents", Version::ZERO)?;
let realized_cap_cents: ComputedFromHeight<Cents> =
cfg.import("realized_cap_cents", Version::ZERO)?;
let realized_cap = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
&cfg.name("realized_cap"),
cfg.version,
@@ -37,11 +38,12 @@ impl RealizedMinimal {
&realized_cap_cents,
);
let realized_profit = cfg.import_cumulative("realized_profit", Version::ZERO)?;
let realized_loss = cfg.import_cumulative("realized_loss", Version::ZERO)?;
let realized_profit = cfg.import("realized_profit", Version::ZERO)?;
let realized_loss = cfg.import("realized_loss", Version::ZERO)?;
let realized_price = cfg.import_price("realized_price", Version::ONE)?;
let realized_price_ratio = cfg.import_ratio("realized_price", Version::ONE)?;
let realized_price = cfg.import("realized_price", Version::ONE)?;
let realized_price_ratio: ComputedFromHeightRatio =
cfg.import("realized_price", Version::ONE)?;
let mvrv = LazyFromHeight::from_lazy::<Identity<StoredF32>, BasisPoints32>(
&cfg.name("mvrv"),
cfg.version,
@@ -3,7 +3,7 @@ mod base;
mod full;
mod minimal;
pub use adjusted::*;
pub use base::*;
pub use full::*;
pub use minimal::*;
pub use adjusted::RealizedAdjusted;
pub use base::RealizedBase;
pub use full::RealizedFull;
pub use minimal::RealizedMinimal;