mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 09:09:58 -07:00
global: sats version of all prices
This commit is contained in:
@@ -5,7 +5,7 @@ use vecdb::Database;
|
||||
use super::Vecs;
|
||||
use crate::{
|
||||
indexes,
|
||||
internal::{ComputedFromHeightLast, ComputedFromDateRatio},
|
||||
internal::{ComputedFromDateRatio, PriceFromHeight},
|
||||
price,
|
||||
};
|
||||
|
||||
@@ -16,41 +16,61 @@ impl Vecs {
|
||||
indexes: &indexes::Vecs,
|
||||
price: Option<&price::Vecs>,
|
||||
) -> Result<Self> {
|
||||
macro_rules! computed_h {
|
||||
($name:expr) => {
|
||||
ComputedFromHeightLast::forced_import(db, $name, version, indexes)?
|
||||
};
|
||||
}
|
||||
let vaulted_price = PriceFromHeight::forced_import(db, "vaulted_price", version, indexes)?;
|
||||
let vaulted_price_ratio = ComputedFromDateRatio::forced_import(
|
||||
db,
|
||||
"vaulted_price",
|
||||
Some(&vaulted_price),
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
price,
|
||||
)?;
|
||||
|
||||
// Extract price vecs before struct literal so they can be used as sources for ratios
|
||||
let vaulted_price = computed_h!("vaulted_price");
|
||||
let active_price = computed_h!("active_price");
|
||||
let true_market_mean = computed_h!("true_market_mean");
|
||||
let cointime_price = computed_h!("cointime_price");
|
||||
let active_price = PriceFromHeight::forced_import(db, "active_price", version, indexes)?;
|
||||
let active_price_ratio = ComputedFromDateRatio::forced_import(
|
||||
db,
|
||||
"active_price",
|
||||
Some(&active_price),
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
price,
|
||||
)?;
|
||||
|
||||
macro_rules! ratio_di {
|
||||
($name:expr, $source:expr) => {
|
||||
ComputedFromDateRatio::forced_import(
|
||||
db,
|
||||
$name,
|
||||
Some($source),
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
price,
|
||||
)?
|
||||
};
|
||||
}
|
||||
let true_market_mean =
|
||||
PriceFromHeight::forced_import(db, "true_market_mean", version, indexes)?;
|
||||
let true_market_mean_ratio = ComputedFromDateRatio::forced_import(
|
||||
db,
|
||||
"true_market_mean",
|
||||
Some(&true_market_mean),
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
price,
|
||||
)?;
|
||||
|
||||
let cointime_price =
|
||||
PriceFromHeight::forced_import(db, "cointime_price", version, indexes)?;
|
||||
let cointime_price_ratio = ComputedFromDateRatio::forced_import(
|
||||
db,
|
||||
"cointime_price",
|
||||
Some(&cointime_price),
|
||||
version,
|
||||
indexes,
|
||||
true,
|
||||
price,
|
||||
)?;
|
||||
|
||||
Ok(Self {
|
||||
vaulted_price_ratio: ratio_di!("vaulted_price", &vaulted_price),
|
||||
vaulted_price,
|
||||
active_price_ratio: ratio_di!("active_price", &active_price),
|
||||
vaulted_price_ratio,
|
||||
active_price,
|
||||
true_market_mean_ratio: ratio_di!("true_market_mean", &true_market_mean),
|
||||
active_price_ratio,
|
||||
true_market_mean,
|
||||
cointime_price_ratio: ratio_di!("cointime_price", &cointime_price),
|
||||
true_market_mean_ratio,
|
||||
cointime_price,
|
||||
cointime_price_ratio,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
use brk_traversable::Traversable;
|
||||
use brk_types::Dollars;
|
||||
|
||||
use crate::internal::{ComputedFromHeightLast, ComputedFromDateRatio};
|
||||
use crate::internal::{ComputedFromDateRatio, PriceFromHeight};
|
||||
|
||||
#[derive(Clone, Traversable)]
|
||||
pub struct Vecs {
|
||||
pub vaulted_price: ComputedFromHeightLast<Dollars>,
|
||||
pub vaulted_price: PriceFromHeight,
|
||||
pub vaulted_price_ratio: ComputedFromDateRatio,
|
||||
pub active_price: ComputedFromHeightLast<Dollars>,
|
||||
pub active_price: PriceFromHeight,
|
||||
pub active_price_ratio: ComputedFromDateRatio,
|
||||
pub true_market_mean: ComputedFromHeightLast<Dollars>,
|
||||
pub true_market_mean: PriceFromHeight,
|
||||
pub true_market_mean_ratio: ComputedFromDateRatio,
|
||||
pub cointime_price: ComputedFromHeightLast<Dollars>,
|
||||
pub cointime_price: PriceFromHeight,
|
||||
pub cointime_price_ratio: ComputedFromDateRatio,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user