mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -16,8 +16,8 @@ pub struct ActivityBase<M: StorageMode = Rw> {
|
|||||||
impl ActivityBase {
|
impl ActivityBase {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
sent: cfg.import_value_cumulative("sent", Version::ZERO)?,
|
sent: cfg.import("sent", Version::ZERO)?,
|
||||||
sent_ema: cfg.import_emas_2w("sent", Version::ZERO)?,
|
sent_ema: cfg.import("sent", Version::ZERO)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ impl ActivityFull {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
base: ActivityBase::forced_import(cfg)?,
|
base: ActivityBase::forced_import(cfg)?,
|
||||||
coinblocks_destroyed: cfg
|
coinblocks_destroyed: cfg
|
||||||
.import_cumulative_sum("coinblocks_destroyed", Version::ONE)?,
|
.import("coinblocks_destroyed", Version::ONE)?,
|
||||||
coindays_destroyed: cfg.import_cumulative_sum("coindays_destroyed", Version::ONE)?,
|
coindays_destroyed: cfg.import("coindays_destroyed", Version::ONE)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
mod base;
|
mod base;
|
||||||
mod full;
|
mod full;
|
||||||
|
|
||||||
pub use base::*;
|
pub use base::ActivityBase;
|
||||||
pub use full::*;
|
pub use full::ActivityFull;
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ impl AllCohortMetrics {
|
|||||||
unrealized: Box::new(unrealized),
|
unrealized: Box::new(unrealized),
|
||||||
adjusted: Box::new(adjusted),
|
adjusted: Box::new(adjusted),
|
||||||
relative: Box::new(relative),
|
relative: Box::new(relative),
|
||||||
dormancy: cfg.import_computed("dormancy", Version::ONE)?,
|
dormancy: cfg.import("dormancy", Version::ONE)?,
|
||||||
velocity: cfg.import_computed("velocity", Version::ONE)?,
|
velocity: cfg.import("velocity", Version::ONE)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_traversable::Traversable;
|
use brk_traversable::Traversable;
|
||||||
use brk_types::{Dollars, Height, Indexes, Sats};
|
use brk_types::{Dollars, Height, Indexes, Sats, Version};
|
||||||
use vecdb::{Exit, ReadableVec, Rw, StorageMode};
|
use vecdb::{AnyStoredVec, Exit, ReadableVec, Rw, StorageMode};
|
||||||
|
|
||||||
use crate::{blocks, prices};
|
use crate::{blocks, prices};
|
||||||
|
|
||||||
use crate::distribution::metrics::{
|
use crate::distribution::metrics::{
|
||||||
ActivityFull, CostBasisBase, ImportConfig, OutputsMetrics, RealizedBase,
|
ActivityFull, CohortMetricsBase, CostBasisBase, ImportConfig, OutputsMetrics, RealizedBase,
|
||||||
RelativeWithRelToAll, SupplyMetrics, UnrealizedFull,
|
RelativeWithRelToAll, SupplyMetrics, UnrealizedFull,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -26,7 +26,26 @@ pub struct BasicCohortMetrics<M: StorageMode = Rw> {
|
|||||||
pub relative: Box<RelativeWithRelToAll<M>>,
|
pub relative: Box<RelativeWithRelToAll<M>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_cohort_metrics_base!(BasicCohortMetrics, base_cost_basis);
|
impl CohortMetricsBase for BasicCohortMetrics {
|
||||||
|
impl_cohort_metrics_base!(@accessors);
|
||||||
|
|
||||||
|
fn validate_computed_versions(&mut self, base_version: Version) -> Result<()> {
|
||||||
|
self.supply.validate_computed_versions(base_version)?;
|
||||||
|
self.activity.validate_computed_versions(base_version)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn AnyStoredVec> {
|
||||||
|
let mut vecs: Vec<&mut dyn AnyStoredVec> = Vec::new();
|
||||||
|
vecs.extend(self.supply.collect_vecs_mut());
|
||||||
|
vecs.extend(self.outputs.collect_vecs_mut());
|
||||||
|
vecs.extend(self.activity.collect_vecs_mut());
|
||||||
|
vecs.extend(self.realized.collect_vecs_mut());
|
||||||
|
vecs.extend(self.cost_basis.collect_vecs_mut());
|
||||||
|
vecs.extend(self.unrealized.collect_vecs_mut());
|
||||||
|
vecs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BasicCohortMetrics {
|
impl BasicCohortMetrics {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ impl ExtendedCohortMetrics {
|
|||||||
cost_basis: Box::new(CostBasisWithExtended::forced_import(cfg)?),
|
cost_basis: Box::new(CostBasisWithExtended::forced_import(cfg)?),
|
||||||
unrealized: Box::new(unrealized),
|
unrealized: Box::new(unrealized),
|
||||||
relative: Box::new(relative),
|
relative: Box::new(relative),
|
||||||
dormancy: cfg.import_computed("dormancy", Version::ONE)?,
|
dormancy: cfg.import("dormancy", Version::ONE)?,
|
||||||
velocity: cfg.import_computed("velocity", Version::ONE)?,
|
velocity: cfg.import("velocity", Version::ONE)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ pub struct MinimalCohortMetrics<M: StorageMode = Rw> {
|
|||||||
impl MinimalUnrealized {
|
impl MinimalUnrealized {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply_in_profit: cfg.import_value("supply_in_profit", Version::ZERO)?,
|
supply_in_profit: cfg.import("supply_in_profit", Version::ZERO)?,
|
||||||
supply_in_loss: cfg.import_value("supply_in_loss", Version::ZERO)?,
|
supply_in_loss: cfg.import("supply_in_loss", Version::ZERO)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,9 +117,9 @@ impl MinimalRelative {
|
|||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply_in_profit_rel_to_own_supply: cfg
|
supply_in_profit_rel_to_own_supply: cfg
|
||||||
.import_percent_bp16("supply_in_profit_rel_to_own_supply", Version::ONE)?,
|
.import("supply_in_profit_rel_to_own_supply", Version::ONE)?,
|
||||||
supply_in_loss_rel_to_own_supply: cfg
|
supply_in_loss_rel_to_own_supply: cfg
|
||||||
.import_percent_bp16("supply_in_loss_rel_to_own_supply", Version::ONE)?,
|
.import("supply_in_loss_rel_to_own_supply", Version::ONE)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ mod extended;
|
|||||||
mod extended_adjusted;
|
mod extended_adjusted;
|
||||||
mod minimal;
|
mod minimal;
|
||||||
|
|
||||||
pub use all::*;
|
pub use all::AllCohortMetrics;
|
||||||
pub use basic::*;
|
pub use basic::BasicCohortMetrics;
|
||||||
pub use core::*;
|
pub use core::CoreCohortMetrics;
|
||||||
pub use extended::*;
|
pub use extended::ExtendedCohortMetrics;
|
||||||
pub use extended_adjusted::*;
|
pub use extended_adjusted::ExtendedAdjustedCohortMetrics;
|
||||||
pub use minimal::*;
|
pub use minimal::MinimalCohortMetrics;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
use brk_types::{BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, Height, Version};
|
use brk_types::{
|
||||||
|
BasisPoints16, BasisPoints32, BasisPointsSigned32, Cents, Height, Version,
|
||||||
|
};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
|
use vecdb::{BytesVec, BytesVecValue, Database, ImportableVec};
|
||||||
|
|
||||||
@@ -15,6 +17,80 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Trait for types importable via `ImportConfig::import`.
|
||||||
|
pub(crate) trait ConfigImport: Sized {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement `ConfigImport` for types whose `forced_import` takes `(db, name, version, indexes)`.
|
||||||
|
macro_rules! impl_config_import {
|
||||||
|
($($type:ty),+ $(,)?) => {
|
||||||
|
$(
|
||||||
|
impl ConfigImport for $type {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-generic types
|
||||||
|
impl_config_import!(
|
||||||
|
ValueFromHeight,
|
||||||
|
ValueFromHeightCumulative,
|
||||||
|
ValueFromHeightChange,
|
||||||
|
ComputedFromHeightRatio,
|
||||||
|
RollingEmas2w,
|
||||||
|
PercentFromHeight<BasisPoints16>,
|
||||||
|
PercentFromHeight<BasisPoints32>,
|
||||||
|
PercentFromHeight<BasisPointsSigned32>,
|
||||||
|
PercentRollingWindows<BasisPoints32>,
|
||||||
|
PercentRollingEmas1w1m<BasisPoints32>,
|
||||||
|
Price<ComputedFromHeight<Cents>>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Generic types (macro_rules can't parse generic bounds, so written out)
|
||||||
|
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeight<T> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeightCumulative<T> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: NumericValue + JsonSchema> ConfigImport for ComputedFromHeightCumulativeSum<T> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: NumericValue + JsonSchema> ConfigImport for RollingWindows<T> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: NumericValue + JsonSchema> ConfigImport for RollingEmas1w1m<T> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<C: CentsType> ConfigImport for FiatFromHeight<C> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Self::forced_import(cfg.db, &cfg.name(suffix), cfg.version + offset, cfg.indexes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: BytesVecValue> ConfigImport for BytesVec<Height, T> {
|
||||||
|
fn config_import(cfg: &ImportConfig, suffix: &str, offset: Version) -> Result<Self> {
|
||||||
|
Ok(Self::forced_import(
|
||||||
|
cfg.db,
|
||||||
|
&cfg.name(suffix),
|
||||||
|
cfg.version + offset,
|
||||||
|
)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct ImportConfig<'a> {
|
pub struct ImportConfig<'a> {
|
||||||
pub db: &'a Database,
|
pub db: &'a Database,
|
||||||
@@ -35,228 +111,11 @@ impl<'a> ImportConfig<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn import_computed<T: NumericValue + JsonSchema>(
|
pub(crate) fn import<T: ConfigImport>(
|
||||||
&self,
|
&self,
|
||||||
suffix: &str,
|
suffix: &str,
|
||||||
offset: Version,
|
offset: Version,
|
||||||
) -> Result<ComputedFromHeight<T>> {
|
) -> Result<T> {
|
||||||
ComputedFromHeight::forced_import(
|
T::config_import(self, suffix, offset)
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_cumulative<T: NumericValue + JsonSchema>(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<ComputedFromHeightCumulative<T>> {
|
|
||||||
ComputedFromHeightCumulative::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_cumulative_sum<T: NumericValue + JsonSchema>(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<ComputedFromHeightCumulativeSum<T>> {
|
|
||||||
ComputedFromHeightCumulativeSum::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_percent_bp16(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<PercentFromHeight<BasisPoints16>> {
|
|
||||||
PercentFromHeight::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_percent_bps32(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<PercentFromHeight<BasisPointsSigned32>> {
|
|
||||||
PercentFromHeight::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_fiat<C: CentsType>(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<FiatFromHeight<C>> {
|
|
||||||
FiatFromHeight::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_value(&self, suffix: &str, offset: Version) -> Result<ValueFromHeight> {
|
|
||||||
ValueFromHeight::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_value_cumulative(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<ValueFromHeightCumulative> {
|
|
||||||
ValueFromHeightCumulative::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_value_change(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<ValueFromHeightChange> {
|
|
||||||
ValueFromHeightChange::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_price(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<Price<ComputedFromHeight<Cents>>> {
|
|
||||||
Price::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_ratio(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<ComputedFromHeightRatio> {
|
|
||||||
ComputedFromHeightRatio::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_bytes<T: BytesVecValue>(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<BytesVec<Height, T>> {
|
|
||||||
Ok(BytesVec::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_rolling<T: NumericValue + JsonSchema>(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<RollingWindows<T>> {
|
|
||||||
RollingWindows::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_percent_bp32(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<PercentFromHeight<BasisPoints32>> {
|
|
||||||
PercentFromHeight::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_percent_rolling_bp32(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<PercentRollingWindows<BasisPoints32>> {
|
|
||||||
PercentRollingWindows::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_emas_1w_1m<T: NumericValue + JsonSchema>(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<RollingEmas1w1m<T>> {
|
|
||||||
RollingEmas1w1m::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_percent_emas_1w_1m_bp32(
|
|
||||||
&self,
|
|
||||||
suffix: &str,
|
|
||||||
offset: Version,
|
|
||||||
) -> Result<PercentRollingEmas1w1m<BasisPoints32>> {
|
|
||||||
PercentRollingEmas1w1m::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn import_emas_2w(&self, suffix: &str, offset: Version) -> Result<RollingEmas2w> {
|
|
||||||
RollingEmas2w::forced_import(
|
|
||||||
self.db,
|
|
||||||
&self.name(suffix),
|
|
||||||
self.version + offset,
|
|
||||||
self.indexes,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ pub struct CostBasisBase<M: StorageMode = Rw> {
|
|||||||
impl CostBasisBase {
|
impl CostBasisBase {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
min: cfg.import_price("cost_basis_min", Version::ZERO)?,
|
min: cfg.import("cost_basis_min", Version::ZERO)?,
|
||||||
max: cfg.import_price("cost_basis_max", Version::ZERO)?,
|
max: cfg.import("cost_basis_max", Version::ZERO)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
mod base;
|
mod base;
|
||||||
mod extended;
|
mod extended;
|
||||||
|
|
||||||
mod with_extended;
|
mod with_extended;
|
||||||
|
|
||||||
pub use base::*;
|
pub use base::CostBasisBase;
|
||||||
pub use extended::*;
|
pub use extended::CostBasisExtended;
|
||||||
|
pub use with_extended::CostBasisWithExtended;
|
||||||
pub use with_extended::*;
|
|
||||||
|
|||||||
@@ -13,36 +13,14 @@ mod activity;
|
|||||||
|
|
||||||
/// DRY macro for `CohortMetricsBase` impl on cohort metric types.
|
/// DRY macro for `CohortMetricsBase` impl on cohort metric types.
|
||||||
///
|
///
|
||||||
/// All types share the same 13 accessor methods and common `collect_all_vecs_mut` shape.
|
/// Two variants handle extended cost basis types that need direct field access
|
||||||
/// Two variants handle the cost basis difference:
|
/// (bypassing Deref to call methods on concrete `RealizedFull`):
|
||||||
///
|
///
|
||||||
/// - `base_cost_basis`: `CostBasisBase` only (no percentiles, no cost_basis version check)
|
|
||||||
/// - `extended_cost_basis`: `CostBasisWithExtended` (percentiles + cost_basis version check)
|
/// - `extended_cost_basis`: `CostBasisWithExtended` (percentiles + cost_basis version check)
|
||||||
/// - `deref_extended_cost_basis`: Deref wrapper delegating to `self.inner` (avoids DerefMut borrow conflicts)
|
/// - `deref_extended_cost_basis`: Deref wrapper delegating to `self.inner` (avoids DerefMut borrow conflicts)
|
||||||
|
///
|
||||||
|
/// The `@accessors` helper is also used directly by `BasicCohortMetrics`.
|
||||||
macro_rules! impl_cohort_metrics_base {
|
macro_rules! impl_cohort_metrics_base {
|
||||||
($type:ident, base_cost_basis) => {
|
|
||||||
impl $crate::distribution::metrics::CohortMetricsBase for $type {
|
|
||||||
impl_cohort_metrics_base!(@accessors);
|
|
||||||
|
|
||||||
fn validate_computed_versions(&mut self, base_version: brk_types::Version) -> brk_error::Result<()> {
|
|
||||||
self.supply.validate_computed_versions(base_version)?;
|
|
||||||
self.activity.validate_computed_versions(base_version)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn collect_all_vecs_mut(&mut self) -> Vec<&mut dyn vecdb::AnyStoredVec> {
|
|
||||||
let mut vecs: Vec<&mut dyn vecdb::AnyStoredVec> = Vec::new();
|
|
||||||
vecs.extend(self.supply.collect_vecs_mut());
|
|
||||||
vecs.extend(self.outputs.collect_vecs_mut());
|
|
||||||
vecs.extend(self.activity.collect_vecs_mut());
|
|
||||||
vecs.extend(self.realized.collect_vecs_mut());
|
|
||||||
vecs.extend(self.cost_basis.collect_vecs_mut());
|
|
||||||
vecs.extend(self.unrealized.collect_vecs_mut());
|
|
||||||
vecs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
($type:ident, extended_cost_basis) => {
|
($type:ident, extended_cost_basis) => {
|
||||||
impl $crate::distribution::metrics::CohortMetricsBase for $type {
|
impl $crate::distribution::metrics::CohortMetricsBase for $type {
|
||||||
impl_cohort_metrics_base!(@accessors);
|
impl_cohort_metrics_base!(@accessors);
|
||||||
@@ -280,15 +258,20 @@ mod relative;
|
|||||||
mod supply;
|
mod supply;
|
||||||
mod unrealized;
|
mod unrealized;
|
||||||
|
|
||||||
pub use activity::*;
|
pub use activity::{ActivityBase, ActivityFull};
|
||||||
pub use cohort::*;
|
pub use cohort::{
|
||||||
pub use config::*;
|
AllCohortMetrics, BasicCohortMetrics, CoreCohortMetrics, ExtendedAdjustedCohortMetrics,
|
||||||
pub use cost_basis::*;
|
ExtendedCohortMetrics, MinimalCohortMetrics,
|
||||||
pub use outputs::*;
|
};
|
||||||
pub use realized::*;
|
pub use config::ImportConfig;
|
||||||
pub use relative::*;
|
pub use cost_basis::{CostBasisBase, CostBasisExtended, CostBasisWithExtended};
|
||||||
pub use supply::*;
|
pub use outputs::OutputsMetrics;
|
||||||
pub use unrealized::*;
|
pub use realized::{RealizedAdjusted, RealizedBase, RealizedFull, RealizedMinimal};
|
||||||
|
pub use relative::{
|
||||||
|
RelativeBaseWithRelToAll, RelativeForAll, RelativeWithExtended, RelativeWithRelToAll,
|
||||||
|
};
|
||||||
|
pub use supply::SupplyMetrics;
|
||||||
|
pub use unrealized::{UnrealizedBase, UnrealizedFull};
|
||||||
|
|
||||||
use brk_cohort::Filter;
|
use brk_cohort::Filter;
|
||||||
use brk_error::Result;
|
use brk_error::Result;
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ impl OutputsMetrics {
|
|||||||
/// Import output metrics from database.
|
/// Import output metrics from database.
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
utxo_count: cfg.import_computed("utxo_count", Version::ZERO)?,
|
utxo_count: cfg.import("utxo_count", Version::ZERO)?,
|
||||||
utxo_count_change_1m: cfg.import_computed("utxo_count_change_1m", Version::ZERO)?,
|
utxo_count_change_1m: cfg.import("utxo_count_change_1m", Version::ZERO)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ pub struct RealizedAdjusted<M: StorageMode = Rw> {
|
|||||||
impl RealizedAdjusted {
|
impl RealizedAdjusted {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(RealizedAdjusted {
|
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
|
adjusted_value_destroyed: cfg
|
||||||
.import_computed("adjusted_value_destroyed", Version::ZERO)?,
|
.import("adjusted_value_destroyed", Version::ZERO)?,
|
||||||
adjusted_value_created_sum: cfg
|
adjusted_value_created_sum: cfg
|
||||||
.import_rolling("adjusted_value_created", Version::ONE)?,
|
.import("adjusted_value_created", Version::ONE)?,
|
||||||
adjusted_value_destroyed_sum: cfg
|
adjusted_value_destroyed_sum: cfg
|
||||||
.import_rolling("adjusted_value_destroyed", Version::ONE)?,
|
.import("adjusted_value_destroyed", Version::ONE)?,
|
||||||
adjusted_sopr: cfg.import_rolling("adjusted_sopr", Version::ONE)?,
|
adjusted_sopr: cfg.import("adjusted_sopr", Version::ONE)?,
|
||||||
adjusted_sopr_ema: cfg.import_emas_1w_1m("adjusted_sopr_24h", Version::ONE)?,
|
adjusted_sopr_ema: cfg.import("adjusted_sopr_24h", Version::ONE)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,26 +76,26 @@ impl RealizedBase {
|
|||||||
cfg.indexes,
|
cfg.indexes,
|
||||||
);
|
);
|
||||||
|
|
||||||
let realized_profit_ema_1w = cfg.import_computed("realized_profit_ema_1w", v0)?;
|
let realized_profit_ema_1w = cfg.import("realized_profit_ema_1w", v0)?;
|
||||||
let realized_loss_ema_1w = cfg.import_computed("realized_loss_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 = cfg.import("net_realized_pnl", v0)?;
|
||||||
let net_realized_pnl_ema_1w = cfg.import_computed("net_realized_pnl_ema_1w", v0)?;
|
let net_realized_pnl_ema_1w = cfg.import("net_realized_pnl_ema_1w", v0)?;
|
||||||
let gross_pnl = cfg.import_fiat("realized_gross_pnl", v0)?;
|
let gross_pnl = cfg.import("realized_gross_pnl", v0)?;
|
||||||
|
|
||||||
let realized_profit_rel_to_realized_cap =
|
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 =
|
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 =
|
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_created = cfg.import("value_created", v0)?;
|
||||||
let value_destroyed = cfg.import_computed("value_destroyed", v0)?;
|
let value_destroyed = cfg.import("value_destroyed", v0)?;
|
||||||
let value_created_sum = cfg.import_rolling("value_created", v1)?;
|
let value_created_sum = cfg.import("value_created", v1)?;
|
||||||
let value_destroyed_sum = cfg.import_rolling("value_destroyed", v1)?;
|
let value_destroyed_sum = cfg.import("value_destroyed", v1)?;
|
||||||
let sopr = cfg.import_rolling("sopr", v1)?;
|
let sopr = cfg.import("sopr", v1)?;
|
||||||
let sopr_24h_ema = cfg.import_emas_1w_1m("sopr_24h", v1)?;
|
let sopr_24h_ema = cfg.import("sopr_24h", v1)?;
|
||||||
|
|
||||||
let realized_price_ratio_percentiles =
|
let realized_price_ratio_percentiles =
|
||||||
ComputedFromHeightRatioPercentiles::forced_import(
|
ComputedFromHeightRatioPercentiles::forced_import(
|
||||||
@@ -107,7 +107,7 @@ impl RealizedBase {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
minimal,
|
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,
|
neg_realized_loss,
|
||||||
net_realized_pnl,
|
net_realized_pnl,
|
||||||
net_realized_pnl_ema_1w,
|
net_realized_pnl_ema_1w,
|
||||||
@@ -124,10 +124,10 @@ impl RealizedBase {
|
|||||||
sopr,
|
sopr,
|
||||||
sopr_24h_ema,
|
sopr_24h_ema,
|
||||||
realized_price_ratio_percentiles,
|
realized_price_ratio_percentiles,
|
||||||
sent_in_profit: cfg.import_value_cumulative("sent_in_profit", v0)?,
|
sent_in_profit: cfg.import("sent_in_profit", v0)?,
|
||||||
sent_in_loss: cfg.import_value_cumulative("sent_in_loss", v0)?,
|
sent_in_loss: cfg.import("sent_in_loss", v0)?,
|
||||||
sent_in_profit_ema: cfg.import_emas_2w("sent_in_profit", v0)?,
|
sent_in_profit_ema: cfg.import("sent_in_profit", v0)?,
|
||||||
sent_in_loss_ema: cfg.import_emas_2w("sent_in_loss", v0)?,
|
sent_in_loss_ema: cfg.import("sent_in_loss", v0)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,10 +82,12 @@ impl RealizedFull {
|
|||||||
|
|
||||||
let core = RealizedBase::forced_import(cfg)?;
|
let core = RealizedBase::forced_import(cfg)?;
|
||||||
|
|
||||||
let profit_value_created = cfg.import_computed("profit_value_created", v0)?;
|
let profit_value_created = cfg.import("profit_value_created", v0)?;
|
||||||
let profit_value_destroyed = cfg.import_computed("profit_value_destroyed", v0)?;
|
let profit_value_destroyed: ComputedFromHeight<Cents> =
|
||||||
let loss_value_created = cfg.import_computed("loss_value_created", v0)?;
|
cfg.import("profit_value_destroyed", v0)?;
|
||||||
let loss_value_destroyed = cfg.import_computed("loss_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>(
|
let capitulation_flow = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||||
&cfg.name("capitulation_flow"),
|
&cfg.name("capitulation_flow"),
|
||||||
@@ -100,24 +102,24 @@ impl RealizedFull {
|
|||||||
&profit_value_destroyed,
|
&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 = cfg.import("investor_price", v0)?;
|
||||||
let investor_price_ratio = cfg.import_ratio("investor_price", v0)?;
|
let investor_price_ratio = cfg.import("investor_price", v0)?;
|
||||||
let lower_price_band = cfg.import_price("lower_price_band", v0)?;
|
let lower_price_band = cfg.import("lower_price_band", v0)?;
|
||||||
let upper_price_band = cfg.import_price("upper_price_band", v0)?;
|
let upper_price_band = cfg.import("upper_price_band", v0)?;
|
||||||
|
|
||||||
let cap_raw = cfg.import_bytes("cap_raw", v0)?;
|
let cap_raw = cfg.import("cap_raw", v0)?;
|
||||||
let investor_cap_raw = cfg.import_bytes("investor_cap_raw", v0)?;
|
let investor_cap_raw = cfg.import("investor_cap_raw", v0)?;
|
||||||
|
|
||||||
let sell_side_risk_ratio =
|
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 =
|
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 =
|
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_name = cfg.name("realized_price");
|
||||||
let realized_price_version = cfg.version + v1;
|
let realized_price_version = cfg.version + v1;
|
||||||
@@ -133,11 +135,11 @@ impl RealizedFull {
|
|||||||
capitulation_flow,
|
capitulation_flow,
|
||||||
profit_flow,
|
profit_flow,
|
||||||
gross_pnl_sum,
|
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
|
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
|
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,
|
||||||
investor_price_ratio,
|
investor_price_ratio,
|
||||||
lower_price_band,
|
lower_price_band,
|
||||||
@@ -149,11 +151,11 @@ impl RealizedFull {
|
|||||||
peak_regret,
|
peak_regret,
|
||||||
peak_regret_rel_to_realized_cap,
|
peak_regret_rel_to_realized_cap,
|
||||||
realized_cap_rel_to_own_market_cap: cfg
|
realized_cap_rel_to_own_market_cap: cfg
|
||||||
.import_percent_bp32("realized_cap_rel_to_own_market_cap", v1)?,
|
.import("realized_cap_rel_to_own_market_cap", v1)?,
|
||||||
realized_profit_sum: cfg.import_rolling("realized_profit", v1)?,
|
realized_profit_sum: cfg.import("realized_profit", v1)?,
|
||||||
realized_loss_sum: cfg.import_rolling("realized_loss", v1)?,
|
realized_loss_sum: cfg.import("realized_loss", v1)?,
|
||||||
realized_profit_to_loss_ratio: cfg
|
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(
|
realized_price_ratio_std_dev: ComputedFromHeightRatioStdDevBands::forced_import(
|
||||||
cfg.db,
|
cfg.db,
|
||||||
&realized_price_name,
|
&realized_price_name,
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ pub struct RealizedMinimal<M: StorageMode = Rw> {
|
|||||||
|
|
||||||
impl RealizedMinimal {
|
impl RealizedMinimal {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
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>(
|
let realized_cap = LazyFromHeight::from_computed::<CentsUnsignedToDollars>(
|
||||||
&cfg.name("realized_cap"),
|
&cfg.name("realized_cap"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
@@ -37,11 +38,12 @@ impl RealizedMinimal {
|
|||||||
&realized_cap_cents,
|
&realized_cap_cents,
|
||||||
);
|
);
|
||||||
|
|
||||||
let realized_profit = cfg.import_cumulative("realized_profit", Version::ZERO)?;
|
let realized_profit = cfg.import("realized_profit", Version::ZERO)?;
|
||||||
let realized_loss = cfg.import_cumulative("realized_loss", Version::ZERO)?;
|
let realized_loss = cfg.import("realized_loss", Version::ZERO)?;
|
||||||
|
|
||||||
let realized_price = cfg.import_price("realized_price", Version::ONE)?;
|
let realized_price = cfg.import("realized_price", Version::ONE)?;
|
||||||
let realized_price_ratio = cfg.import_ratio("realized_price", Version::ONE)?;
|
let realized_price_ratio: ComputedFromHeightRatio =
|
||||||
|
cfg.import("realized_price", Version::ONE)?;
|
||||||
let mvrv = LazyFromHeight::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
let mvrv = LazyFromHeight::from_lazy::<Identity<StoredF32>, BasisPoints32>(
|
||||||
&cfg.name("mvrv"),
|
&cfg.name("mvrv"),
|
||||||
cfg.version,
|
cfg.version,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ mod base;
|
|||||||
mod full;
|
mod full;
|
||||||
mod minimal;
|
mod minimal;
|
||||||
|
|
||||||
pub use adjusted::*;
|
pub use adjusted::RealizedAdjusted;
|
||||||
pub use base::*;
|
pub use base::RealizedBase;
|
||||||
pub use full::*;
|
pub use full::RealizedFull;
|
||||||
pub use minimal::*;
|
pub use minimal::RealizedMinimal;
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ impl RelativeBase {
|
|||||||
let v1 = Version::ONE;
|
let v1 = Version::ONE;
|
||||||
let v2 = Version::new(2);
|
let v2 = Version::new(2);
|
||||||
|
|
||||||
let net_unrealized_pnl_rel_to_market_cap =
|
let net_unrealized_pnl_rel_to_market_cap: PercentFromHeight<BasisPointsSigned32> =
|
||||||
cfg.import_percent_bps32("net_unrealized_pnl_rel_to_market_cap", Version::new(3))?;
|
cfg.import("net_unrealized_pnl_rel_to_market_cap", Version::new(3))?;
|
||||||
|
|
||||||
let nupl = LazyFromHeight::from_computed::<Bps32ToFloat>(
|
let nupl = LazyFromHeight::from_computed::<Bps32ToFloat>(
|
||||||
&cfg.name("nupl"),
|
&cfg.name("nupl"),
|
||||||
@@ -45,16 +45,16 @@ impl RelativeBase {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply_in_profit_rel_to_own_supply: cfg
|
supply_in_profit_rel_to_own_supply: cfg
|
||||||
.import_percent_bp16("supply_in_profit_rel_to_own_supply", v1)?,
|
.import("supply_in_profit_rel_to_own_supply", v1)?,
|
||||||
supply_in_loss_rel_to_own_supply: cfg
|
supply_in_loss_rel_to_own_supply: cfg
|
||||||
.import_percent_bp16("supply_in_loss_rel_to_own_supply", v1)?,
|
.import("supply_in_loss_rel_to_own_supply", v1)?,
|
||||||
unrealized_profit_rel_to_market_cap: cfg
|
unrealized_profit_rel_to_market_cap: cfg
|
||||||
.import_percent_bp16("unrealized_profit_rel_to_market_cap", v2)?,
|
.import("unrealized_profit_rel_to_market_cap", v2)?,
|
||||||
unrealized_loss_rel_to_market_cap: cfg
|
unrealized_loss_rel_to_market_cap: cfg
|
||||||
.import_percent_bp16("unrealized_loss_rel_to_market_cap", v2)?,
|
.import("unrealized_loss_rel_to_market_cap", v2)?,
|
||||||
net_unrealized_pnl_rel_to_market_cap,
|
net_unrealized_pnl_rel_to_market_cap,
|
||||||
neg_unrealized_loss_rel_to_market_cap: cfg
|
neg_unrealized_loss_rel_to_market_cap: cfg
|
||||||
.import_percent_bps32("neg_unrealized_loss_rel_to_market_cap", Version::new(3))?,
|
.import("neg_unrealized_loss_rel_to_market_cap", Version::new(3))?,
|
||||||
nupl,
|
nupl,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ impl RelativeExtendedOwnMarketCap {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
unrealized_profit_rel_to_own_market_cap: cfg
|
unrealized_profit_rel_to_own_market_cap: cfg
|
||||||
.import_percent_bp16("unrealized_profit_rel_to_own_market_cap", v2)?,
|
.import("unrealized_profit_rel_to_own_market_cap", v2)?,
|
||||||
unrealized_loss_rel_to_own_market_cap: cfg
|
unrealized_loss_rel_to_own_market_cap: cfg
|
||||||
.import_percent_bp32("unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
|
.import("unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
|
||||||
neg_unrealized_loss_rel_to_own_market_cap: cfg
|
neg_unrealized_loss_rel_to_own_market_cap: cfg
|
||||||
.import_percent_bps32("neg_unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
|
.import("neg_unrealized_loss_rel_to_own_market_cap", Version::new(3))?,
|
||||||
net_unrealized_pnl_rel_to_own_market_cap: cfg
|
net_unrealized_pnl_rel_to_own_market_cap: cfg
|
||||||
.import_percent_bps32("net_unrealized_pnl_rel_to_own_market_cap", Version::new(3))?,
|
.import("net_unrealized_pnl_rel_to_own_market_cap", Version::new(3))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ impl RelativeExtendedOwnPnl {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
unrealized_profit_rel_to_own_gross_pnl: cfg
|
unrealized_profit_rel_to_own_gross_pnl: cfg
|
||||||
.import_percent_bp16("unrealized_profit_rel_to_own_gross_pnl", v1)?,
|
.import("unrealized_profit_rel_to_own_gross_pnl", v1)?,
|
||||||
unrealized_loss_rel_to_own_gross_pnl: cfg
|
unrealized_loss_rel_to_own_gross_pnl: cfg
|
||||||
.import_percent_bp16("unrealized_loss_rel_to_own_gross_pnl", v1)?,
|
.import("unrealized_loss_rel_to_own_gross_pnl", v1)?,
|
||||||
neg_unrealized_loss_rel_to_own_gross_pnl: cfg
|
neg_unrealized_loss_rel_to_own_gross_pnl: cfg
|
||||||
.import_percent_bps32("neg_unrealized_loss_rel_to_own_gross_pnl", Version::new(2))?,
|
.import("neg_unrealized_loss_rel_to_own_gross_pnl", Version::new(2))?,
|
||||||
net_unrealized_pnl_rel_to_own_gross_pnl: cfg
|
net_unrealized_pnl_rel_to_own_gross_pnl: cfg
|
||||||
.import_percent_bps32("net_unrealized_pnl_rel_to_own_gross_pnl", Version::new(3))?,
|
.import("net_unrealized_pnl_rel_to_own_gross_pnl", Version::new(3))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ impl RelativeFull {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
base,
|
base,
|
||||||
invested_capital_in_profit_rel_to_realized_cap: cfg.import_percent_bp16(
|
invested_capital_in_profit_rel_to_realized_cap: cfg.import(
|
||||||
"invested_capital_in_profit_rel_to_realized_cap",
|
"invested_capital_in_profit_rel_to_realized_cap",
|
||||||
Version::ZERO,
|
Version::ZERO,
|
||||||
)?,
|
)?,
|
||||||
invested_capital_in_loss_rel_to_realized_cap: cfg.import_percent_bp16(
|
invested_capital_in_loss_rel_to_realized_cap: cfg.import(
|
||||||
"invested_capital_in_loss_rel_to_realized_cap",
|
"invested_capital_in_loss_rel_to_realized_cap",
|
||||||
Version::ZERO,
|
Version::ZERO,
|
||||||
)?,
|
)?,
|
||||||
|
|||||||
@@ -3,19 +3,17 @@ mod extended_own_market_cap;
|
|||||||
mod extended_own_pnl;
|
mod extended_own_pnl;
|
||||||
mod for_all;
|
mod for_all;
|
||||||
mod full;
|
mod full;
|
||||||
|
|
||||||
mod to_all;
|
mod to_all;
|
||||||
mod with_extended;
|
mod with_extended;
|
||||||
mod with_rel_to_all;
|
mod with_rel_to_all;
|
||||||
mod with_rel_to_all_base;
|
mod with_rel_to_all_base;
|
||||||
|
|
||||||
pub use base::*;
|
pub use base::RelativeBase;
|
||||||
pub use extended_own_market_cap::*;
|
pub use extended_own_market_cap::RelativeExtendedOwnMarketCap;
|
||||||
pub use extended_own_pnl::*;
|
pub use extended_own_pnl::RelativeExtendedOwnPnl;
|
||||||
pub use for_all::*;
|
pub use for_all::RelativeForAll;
|
||||||
pub use full::*;
|
pub use full::RelativeFull;
|
||||||
|
pub use to_all::RelativeToAll;
|
||||||
pub use to_all::*;
|
pub use with_extended::RelativeWithExtended;
|
||||||
pub use with_extended::*;
|
pub use with_rel_to_all::RelativeWithRelToAll;
|
||||||
pub use with_rel_to_all::*;
|
pub use with_rel_to_all_base::RelativeBaseWithRelToAll;
|
||||||
pub use with_rel_to_all_base::*;
|
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ impl RelativeToAll {
|
|||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply_rel_to_circulating_supply: cfg
|
supply_rel_to_circulating_supply: cfg
|
||||||
.import_percent_bp16("supply_rel_to_circulating_supply", Version::ONE)?,
|
.import("supply_rel_to_circulating_supply", Version::ONE)?,
|
||||||
supply_in_profit_rel_to_circulating_supply: cfg
|
supply_in_profit_rel_to_circulating_supply: cfg
|
||||||
.import_percent_bp16("supply_in_profit_rel_to_circulating_supply", Version::ONE)?,
|
.import("supply_in_profit_rel_to_circulating_supply", Version::ONE)?,
|
||||||
supply_in_loss_rel_to_circulating_supply: cfg
|
supply_in_loss_rel_to_circulating_supply: cfg
|
||||||
.import_percent_bp16("supply_in_loss_rel_to_circulating_supply", Version::ONE)?,
|
.import("supply_in_loss_rel_to_circulating_supply", Version::ONE)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub struct SupplyMetrics<M: StorageMode = Rw> {
|
|||||||
impl SupplyMetrics {
|
impl SupplyMetrics {
|
||||||
/// Import supply metrics from database.
|
/// Import supply metrics from database.
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
let supply = cfg.import_value("supply", Version::ZERO)?;
|
let supply = cfg.import("supply", Version::ZERO)?;
|
||||||
|
|
||||||
let supply_halved = LazyValueFromHeight::from_block_source::<
|
let supply_halved = LazyValueFromHeight::from_block_source::<
|
||||||
HalveSats,
|
HalveSats,
|
||||||
@@ -33,7 +33,7 @@ impl SupplyMetrics {
|
|||||||
HalveDollars,
|
HalveDollars,
|
||||||
>(&cfg.name("supply_halved"), &supply, cfg.version);
|
>(&cfg.name("supply_halved"), &supply, cfg.version);
|
||||||
|
|
||||||
let change_1m = cfg.import_value_change("supply_change_1m", Version::ZERO)?;
|
let change_1m = cfg.import("supply_change_1m", Version::ZERO)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
total: supply,
|
total: supply,
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ pub struct UnrealizedBase<M: StorageMode = Rw> {
|
|||||||
impl UnrealizedBase {
|
impl UnrealizedBase {
|
||||||
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
pub(crate) fn forced_import(cfg: &ImportConfig) -> Result<Self> {
|
||||||
let v0 = Version::ZERO;
|
let v0 = Version::ZERO;
|
||||||
let supply_in_profit = cfg.import_value("supply_in_profit", v0)?;
|
let supply_in_profit = cfg.import("supply_in_profit", v0)?;
|
||||||
let supply_in_loss = cfg.import_value("supply_in_loss", v0)?;
|
let supply_in_loss = cfg.import("supply_in_loss", v0)?;
|
||||||
|
|
||||||
let unrealized_profit = cfg.import_fiat("unrealized_profit", v0)?;
|
let unrealized_profit = cfg.import("unrealized_profit", v0)?;
|
||||||
let unrealized_loss = cfg.import_fiat("unrealized_loss", v0)?;
|
let unrealized_loss: FiatFromHeight<Cents> = cfg.import("unrealized_loss", v0)?;
|
||||||
|
|
||||||
let neg_unrealized_loss = LazyFromHeight::from_computed::<NegCentsUnsignedToDollars>(
|
let neg_unrealized_loss = LazyFromHeight::from_computed::<NegCentsUnsignedToDollars>(
|
||||||
&cfg.name("neg_unrealized_loss"),
|
&cfg.name("neg_unrealized_loss"),
|
||||||
@@ -50,9 +50,9 @@ impl UnrealizedBase {
|
|||||||
&unrealized_loss.cents,
|
&unrealized_loss.cents,
|
||||||
);
|
);
|
||||||
|
|
||||||
let gross_pnl = cfg.import_fiat("unrealized_gross_pnl", v0)?;
|
let gross_pnl = cfg.import("unrealized_gross_pnl", v0)?;
|
||||||
|
|
||||||
let net_unrealized_pnl = cfg.import_fiat("net_unrealized_pnl", v0)?;
|
let net_unrealized_pnl = cfg.import("net_unrealized_pnl", v0)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
supply_in_profit,
|
supply_in_profit,
|
||||||
|
|||||||
@@ -47,18 +47,18 @@ impl UnrealizedFull {
|
|||||||
|
|
||||||
let base = UnrealizedBase::forced_import(cfg)?;
|
let base = UnrealizedBase::forced_import(cfg)?;
|
||||||
|
|
||||||
let invested_capital_in_profit = cfg.import_fiat("invested_capital_in_profit", v0)?;
|
let invested_capital_in_profit = cfg.import("invested_capital_in_profit", v0)?;
|
||||||
let invested_capital_in_loss = cfg.import_fiat("invested_capital_in_loss", v0)?;
|
let invested_capital_in_loss = cfg.import("invested_capital_in_loss", v0)?;
|
||||||
|
|
||||||
let invested_capital_in_profit_raw =
|
let invested_capital_in_profit_raw =
|
||||||
cfg.import_bytes("invested_capital_in_profit_raw", v0)?;
|
cfg.import("invested_capital_in_profit_raw", v0)?;
|
||||||
let invested_capital_in_loss_raw = cfg.import_bytes("invested_capital_in_loss_raw", v0)?;
|
let invested_capital_in_loss_raw = cfg.import("invested_capital_in_loss_raw", v0)?;
|
||||||
let investor_cap_in_profit_raw = cfg.import_bytes("investor_cap_in_profit_raw", v0)?;
|
let investor_cap_in_profit_raw = cfg.import("investor_cap_in_profit_raw", v0)?;
|
||||||
let investor_cap_in_loss_raw = cfg.import_bytes("investor_cap_in_loss_raw", v0)?;
|
let investor_cap_in_loss_raw = cfg.import("investor_cap_in_loss_raw", v0)?;
|
||||||
|
|
||||||
let pain_index = cfg.import_fiat("pain_index", v0)?;
|
let pain_index = cfg.import("pain_index", v0)?;
|
||||||
let greed_index = cfg.import_fiat("greed_index", v0)?;
|
let greed_index = cfg.import("greed_index", v0)?;
|
||||||
let net_sentiment = cfg.import_fiat("net_sentiment", Version::ONE)?;
|
let net_sentiment = cfg.import("net_sentiment", Version::ONE)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
base,
|
base,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
mod base;
|
mod base;
|
||||||
mod full;
|
mod full;
|
||||||
|
|
||||||
pub use base::*;
|
pub use base::UnrealizedBase;
|
||||||
pub use full::*;
|
pub use full::UnrealizedFull;
|
||||||
|
|||||||
Reference in New Issue
Block a user