Compare commits

...

10 Commits

Author SHA1 Message Date
nym21 f477bd66f3 release: v0.0.55 2025-06-13 10:23:38 +02:00
nym21 d7d77ae8f0 global: multiple fixes 2025-06-13 10:22:03 +02:00
nym21 31110a740d release: v0.0.54 2025-06-12 22:18:36 +02:00
nym21 b64d8b1d7f release: v0.0.53 2025-06-12 22:16:33 +02:00
nym21 c46006aacc web: filter possible index choices in charts 2025-06-12 22:09:33 +02:00
nym21 92f81b1493 web: fix css 2025-06-12 20:23:23 +02:00
nym21 70213cfc8f websites: default: add auto price series type 2025-06-12 18:41:56 +02:00
nym21 8a82bf5c50 websites: default: add live price 2025-06-12 18:10:24 +02:00
nym21 37405384a2 vec: fixed compressed, still slow par read, cli: made raw the default 2025-06-12 16:31:54 +02:00
nym21 54ea6cc53b indexer: only raw format + global: fixes 2025-06-12 12:33:43 +02:00
32 changed files with 767 additions and 467 deletions
Generated
+18 -18
View File
@@ -388,7 +388,7 @@ dependencies = [
[[package]]
name = "brk"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"brk_cli",
"brk_computer",
@@ -407,7 +407,7 @@ dependencies = [
[[package]]
name = "brk_cli"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"bitcoincore-rpc",
"brk_computer",
@@ -432,7 +432,7 @@ dependencies = [
[[package]]
name = "brk_computer"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
@@ -453,7 +453,7 @@ dependencies = [
[[package]]
name = "brk_core"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"bincode",
"bitcoin",
@@ -474,7 +474,7 @@ dependencies = [
[[package]]
name = "brk_exit"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"brk_logger",
"ctrlc",
@@ -483,7 +483,7 @@ dependencies = [
[[package]]
name = "brk_fetcher"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"brk_core",
"brk_logger",
@@ -496,7 +496,7 @@ dependencies = [
[[package]]
name = "brk_indexer"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
@@ -514,7 +514,7 @@ dependencies = [
[[package]]
name = "brk_logger"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"color-eyre",
"env_logger",
@@ -524,7 +524,7 @@ dependencies = [
[[package]]
name = "brk_parser"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
@@ -539,7 +539,7 @@ dependencies = [
[[package]]
name = "brk_query"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"brk_computer",
"brk_core",
@@ -557,7 +557,7 @@ dependencies = [
[[package]]
name = "brk_server"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"axum",
"bitcoincore-rpc",
@@ -586,7 +586,7 @@ dependencies = [
[[package]]
name = "brk_state"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"bincode",
"brk_core",
@@ -600,7 +600,7 @@ dependencies = [
[[package]]
name = "brk_store"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"arc-swap",
"brk_core",
@@ -610,7 +610,7 @@ dependencies = [
[[package]]
name = "brk_vec"
version = "0.0.52"
version = "0.0.55"
dependencies = [
"arc-swap",
"brk_core",
@@ -1698,9 +1698,9 @@ checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]]
name = "memchr"
version = "2.7.4"
version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "memmap2"
@@ -3352,9 +3352,9 @@ dependencies = [
[[package]]
name = "windows-link"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
checksum = "d3bfe459f85da17560875b8bf1423d6f113b7a87a5d942e7da0ac71be7c61f8b"
[[package]]
name = "windows-result"
+14 -14
View File
@@ -4,7 +4,7 @@ members = ["crates/*"]
package.description = "The Bitcoin Research Kit is a suite of tools designed to extract, compute and display data stored on a Bitcoin Core node"
package.license = "MIT"
package.edition = "2024"
package.version = "0.0.52"
package.version = "0.0.55"
package.homepage = "https://bitcoinresearchkit.org"
package.repository = "https://github.com/bitcoinresearchkit/brk"
@@ -22,19 +22,19 @@ axum = "0.8.4"
bincode = { version = "2.0.1", features = ["serde"] }
bitcoin = { version = "0.32.6", features = ["serde"] }
bitcoincore-rpc = "0.19.0"
brk_cli = { version = "0.0.52", path = "crates/brk_cli" }
brk_computer = { version = "0.0.52", path = "crates/brk_computer" }
brk_core = { version = "0.0.52", path = "crates/brk_core" }
brk_exit = { version = "0.0.52", path = "crates/brk_exit" }
brk_fetcher = { version = "0.0.52", path = "crates/brk_fetcher" }
brk_indexer = { version = "0.0.52", path = "crates/brk_indexer" }
brk_logger = { version = "0.0.52", path = "crates/brk_logger" }
brk_parser = { version = "0.0.52", path = "crates/brk_parser" }
brk_query = { version = "0.0.52", path = "crates/brk_query" }
brk_server = { version = "0.0.52", path = "crates/brk_server" }
brk_state = { version = "0.0.52", path = "crates/brk_state" }
brk_store = { version = "0.0.52", path = "crates/brk_store" }
brk_vec = { version = "0.0.52", path = "crates/brk_vec" }
brk_cli = { version = "0.0.55", path = "crates/brk_cli" }
brk_computer = { version = "0.0.55", path = "crates/brk_computer" }
brk_core = { version = "0.0.55", path = "crates/brk_core" }
brk_exit = { version = "0.0.55", path = "crates/brk_exit" }
brk_fetcher = { version = "0.0.55", path = "crates/brk_fetcher" }
brk_indexer = { version = "0.0.55", path = "crates/brk_indexer" }
brk_logger = { version = "0.0.55", path = "crates/brk_logger" }
brk_parser = { version = "0.0.55", path = "crates/brk_parser" }
brk_query = { version = "0.0.55", path = "crates/brk_query" }
brk_server = { version = "0.0.55", path = "crates/brk_server" }
brk_state = { version = "0.0.55", path = "crates/brk_state" }
brk_store = { version = "0.0.55", path = "crates/brk_store" }
brk_vec = { version = "0.0.55", path = "crates/brk_vec" }
byteview = "=0.6.1"
clap = { version = "4.5.40", features = ["string"] }
clap_derive = "4.5.40"
+1 -1
View File
@@ -10,7 +10,7 @@ pub fn query(params: QueryParams) -> color_eyre::Result<()> {
let format = config.format();
let mut indexer = Indexer::new(&config.outputsdir(), format, config.check_collisions())?;
let mut indexer = Indexer::new(&config.outputsdir(), config.check_collisions())?;
indexer.import_vecs()?;
let mut computer = Computer::new(&config.outputsdir(), config.fetcher(), format);
+30 -15
View File
@@ -7,7 +7,7 @@ use std::{
use bitcoincore_rpc::{self, Auth, Client, RpcApi};
use brk_computer::Computer;
use brk_core::{default_bitcoin_path, default_brk_path, dot_brk_path};
use brk_core::{default_bitcoin_path, default_brk_path, default_on_error, dot_brk_path};
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
@@ -29,7 +29,7 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
let format = config.format();
let mut indexer = Indexer::new(&config.outputsdir(), format, config.check_collisions())?;
let mut indexer = Indexer::new(&config.outputsdir(), config.check_collisions())?;
indexer.import_stores()?;
indexer.import_vecs()?;
@@ -109,62 +109,77 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
#[derive(Parser, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
pub struct RunConfig {
/// Bitcoin main directory path, defaults: ~/.bitcoin, ~/Library/Application\ Support/Bitcoin, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "PATH")]
bitcoindir: Option<String>,
/// Bitcoin blocks directory path, default: --bitcoindir/blocks, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "PATH")]
blocksdir: Option<String>,
/// Bitcoin Research Kit outputs directory path, default: ~/.brk, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "PATH")]
brkdir: Option<String>,
/// Executed by the runner, default: all, saved
/// Activated services, default: all, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short, long)]
mode: Option<Mode>,
services: Option<Services>,
/// Computation mode for compatible datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: Lazy, saved
/// Computation of computed datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: `lazy`, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short, long)]
computation: Option<Computation>,
/// Activate compression of datasets, set to true to save disk space or false if prioritize speed, default: compressed, saved
#[arg(short, long, value_name = "FORMAT")]
/// Format of computed datasets, `compressed` to save disk space (experimental), `raw` to prioritize speed, default: `raw`, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short, long)]
format: Option<Format>,
/// Activate fetching prices from exchanges APIs and the computation of all related datasets, default: true, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short = 'F', long, value_name = "BOOL")]
fetch: Option<bool>,
/// Website served by the server (if active), default: default, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short, long)]
website: Option<Website>,
/// Bitcoin RPC ip, default: localhost, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "IP")]
rpcconnect: Option<String>,
/// Bitcoin RPC port, default: 8332, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "PORT")]
rpcport: Option<u16>,
/// Bitcoin RPC cookie file, default: --bitcoindir/.cookie, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "PATH")]
rpccookiefile: Option<String>,
/// Bitcoin RPC username, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "USERNAME")]
rpcuser: Option<String>,
/// Bitcoin RPC password, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "PASSWORD")]
rpcpassword: Option<String>,
/// Delay between runs, default: 0, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "SECONDS")]
delay: Option<u64>,
/// DEV: Activate checking address hashes for collisions when indexing, default: false, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(long, value_name = "BOOL")]
check_collisions: Option<bool>,
}
@@ -192,8 +207,8 @@ impl RunConfig {
config_saved.brkdir = Some(brkdir);
}
if let Some(mode) = config_args.mode.take() {
config_saved.mode = Some(mode);
if let Some(services) = config_args.services.take() {
config_saved.services = Some(services);
}
if let Some(computation) = config_args.computation.take() {
@@ -255,7 +270,7 @@ impl RunConfig {
// info!("Configuration {{");
// info!(" bitcoindir: {:?}", config.bitcoindir);
// info!(" brkdir: {:?}", config.brkdir);
// info!(" mode: {:?}", config.mode);
// info!(" services: {:?}", config.services);
// info!(" website: {:?}", config.website);
// info!(" rpcconnect: {:?}", config.rpcconnect);
// info!(" rpcport: {:?}", config.rpcport);
@@ -375,13 +390,13 @@ impl RunConfig {
}
pub fn process(&self) -> bool {
self.mode
.is_none_or(|m| m == Mode::All || m == Mode::Processor)
self.services
.is_none_or(|m| m == Services::All || m == Services::Processor)
}
pub fn serve(&self) -> bool {
self.mode
.is_none_or(|m| m == Mode::All || m == Mode::Server)
self.services
.is_none_or(|m| m == Services::All || m == Services::Server)
}
fn path_cookiefile(&self) -> PathBuf {
@@ -449,7 +464,7 @@ impl RunConfig {
PartialOrd,
Ord,
)]
pub enum Mode {
pub enum Services {
#[default]
All,
Processor,
+1 -1
View File
@@ -33,7 +33,7 @@ pub fn main() -> color_eyre::Result<()> {
let format = Format::Raw;
let mut indexer = Indexer::new(outputs_dir, format, true)?;
let mut indexer = Indexer::new(outputs_dir, true)?;
indexer.import_stores()?;
indexer.import_vecs()?;
@@ -226,7 +226,11 @@ impl ComputedValueVecsFromTxindex {
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
[
self.sats.vecs(),
vec![&self.bitcoin_txindex as &dyn AnyCollectableVec],
self.bitcoin.vecs(),
self.dollars_txindex
.as_ref()
.map_or(vec![], |v| vec![v as &dyn AnyCollectableVec]),
self.dollars.as_ref().map_or(vec![], |v| v.vecs()),
]
.into_iter()
+1
View File
@@ -124,6 +124,7 @@ impl Vecs {
fetcher: Option<&mut Fetcher>,
exit: &Exit,
) -> color_eyre::Result<()> {
info!("Computing indexes...");
let starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?;
info!("Computing constants...");
+2
View File
@@ -3,9 +3,11 @@ mod checked_sub;
mod paths;
mod pause;
mod rlimit;
mod serde;
pub use bytes::*;
pub use checked_sub::*;
pub use paths::*;
pub use pause::*;
pub use rlimit::*;
pub use serde::*;
+12
View File
@@ -0,0 +1,12 @@
use serde::{Deserialize, Deserializer};
pub fn default_on_error<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + Default,
{
match T::deserialize(deserializer) {
Ok(v) => Ok(v),
Err(_) => Ok(T::default()),
}
}
+14 -1
View File
@@ -1,5 +1,5 @@
use brk_core::{Date, Height};
use brk_fetcher::{BRK, Fetcher};
use brk_fetcher::{BRK, Binance, Fetcher, Kraken};
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
@@ -12,6 +12,19 @@ fn main() -> color_eyre::Result<()> {
let mut fetcher = Fetcher::import(None)?;
Binance::fetch_1d().map(|b| {
dbg!(b.last_key_value());
});
Kraken::fetch_1d().map(|b| {
dbg!(b.last_key_value());
});
Binance::fetch_1mn().map(|b| {
dbg!(b.last_key_value());
});
Kraken::fetch_1mn().map(|b| {
dbg!(b.last_key_value());
});
dbg!(fetcher.get_date(Date::new(2025, 6, 5))?);
dbg!(fetcher.get_height(
899911_u32.into(),
+2 -2
View File
@@ -32,7 +32,7 @@ impl Kraken {
)
}
fn fetch_1mn() -> color_eyre::Result<BTreeMap<Timestamp, OHLCCents>> {
pub fn fetch_1mn() -> color_eyre::Result<BTreeMap<Timestamp, OHLCCents>> {
info!("Fetching 1mn prices from Kraken...");
retry(
@@ -54,7 +54,7 @@ impl Kraken {
.ok_or(color_eyre::eyre::Error::msg("Couldn't find date"))
}
fn fetch_1d() -> color_eyre::Result<BTreeMap<Date, OHLCCents>> {
pub fn fetch_1d() -> color_eyre::Result<BTreeMap<Date, OHLCCents>> {
info!("Fetching daily prices from Kraken...");
retry(
+5 -5
View File
@@ -40,11 +40,11 @@ impl Fetcher {
}
fn get_date_(&mut self, date: Date, tries: usize) -> color_eyre::Result<OHLCCents> {
self.binance
self.kraken
.get_from_1d(&date)
.or_else(|_| {
// eprintln!("{e}");
self.kraken.get_from_1d(&date)
self.binance.get_from_1d(&date)
})
.or_else(|_| {
// eprintln!("{e}");
@@ -90,11 +90,11 @@ impl Fetcher {
let previous_timestamp = previous_timestamp.map(|t| t.floor_seconds());
let ohlc = self
.binance
.kraken
.get_from_1mn(timestamp, previous_timestamp)
.unwrap_or_else(|_report| {
// eprintln!("{_report}");
self.kraken
self.binance
.get_from_1mn(timestamp, previous_timestamp)
.unwrap_or_else(|_report| {
// // eprintln!("{_report}");
@@ -185,8 +185,8 @@ How to fix this:
}
pub fn clear(&mut self) {
self.kraken.clear();
self.binance.clear();
self.brk.clear();
self.kraken.clear();
}
}
+1 -2
View File
@@ -4,7 +4,6 @@ use brk_core::default_bitcoin_path;
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::Parser;
use brk_vec::Format;
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
@@ -25,7 +24,7 @@ fn main() -> color_eyre::Result<()> {
let outputs = Path::new("../../_outputs");
let mut indexer = Indexer::new(outputs, Format::Raw, false)?;
let mut indexer = Indexer::new(outputs, false)?;
indexer.import_stores()?;
indexer.import_vecs()?;
+2 -9
View File
@@ -19,7 +19,7 @@ use brk_core::{
use bitcoin::{Transaction, TxIn, TxOut};
use brk_exit::Exit;
use brk_parser::Parser;
use brk_vec::{AnyVec, Format, VecIterator};
use brk_vec::{AnyVec, VecIterator};
use color_eyre::eyre::{ContextCompat, eyre};
use fjall::TransactionalKeyspace;
use log::{error, info};
@@ -42,21 +42,15 @@ pub struct Indexer {
vecs: Option<Vecs>,
stores: Option<Stores>,
check_collisions: bool,
format: Format,
}
impl Indexer {
pub fn new(
outputs_dir: &Path,
format: Format,
check_collisions: bool,
) -> color_eyre::Result<Self> {
pub fn new(outputs_dir: &Path, check_collisions: bool) -> color_eyre::Result<Self> {
setrlimit()?;
Ok(Self {
path: outputs_dir.to_owned(),
vecs: None,
stores: None,
format,
check_collisions,
})
}
@@ -65,7 +59,6 @@ impl Indexer {
self.vecs = Some(Vecs::forced_import(
&self.path.join("vecs/indexed"),
VERSION + Version::ZERO,
self.format,
)?);
Ok(())
}
+34 -38
View File
@@ -66,11 +66,7 @@ pub struct Vecs {
}
impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
format: Format,
) -> color_eyre::Result<Self> {
pub fn forced_import(path: &Path, version: Version) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
Ok(Self {
@@ -78,7 +74,7 @@ impl Vecs {
path,
"txindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_blockhash: IndexedVec::forced_import(
path,
@@ -90,145 +86,145 @@ impl Vecs {
path,
"difficulty",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_emptyoutputindex: IndexedVec::forced_import(
path,
"first_emptyoutputindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_inputindex: IndexedVec::forced_import(
path,
"first_inputindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_opreturnindex: IndexedVec::forced_import(
path,
"first_opreturnindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_outputindex: IndexedVec::forced_import(
path,
"first_outputindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2aindex: IndexedVec::forced_import(
path,
"first_p2aindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2msindex: IndexedVec::forced_import(
path,
"first_p2msindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2pk33index: IndexedVec::forced_import(
path,
"first_p2pk33index",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2pk65index: IndexedVec::forced_import(
path,
"first_p2pk65index",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2pkhindex: IndexedVec::forced_import(
path,
"first_p2pkhindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2shindex: IndexedVec::forced_import(
path,
"first_p2shindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2trindex: IndexedVec::forced_import(
path,
"first_p2trindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2wpkhindex: IndexedVec::forced_import(
path,
"first_p2wpkhindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_p2wshindex: IndexedVec::forced_import(
path,
"first_p2wshindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_txindex: IndexedVec::forced_import(
path,
"first_txindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_first_unknownoutputindex: IndexedVec::forced_import(
path,
"first_unknownoutputindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_timestamp: IndexedVec::forced_import(
path,
"timestamp",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_total_size: IndexedVec::forced_import(
path,
"total_size",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
height_to_weight: IndexedVec::forced_import(
path,
"weight",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
inputindex_to_outputindex: IndexedVec::forced_import(
path,
"outputindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
opreturnindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
outputindex_to_outputtype: IndexedVec::forced_import(
path,
"outputtype",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
outputindex_to_outputtypeindex: IndexedVec::forced_import(
path,
"outputtypeindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
outputindex_to_value: IndexedVec::forced_import(
path,
"value",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
p2aindex_to_p2abytes: IndexedVec::forced_import(
path,
@@ -240,7 +236,7 @@ impl Vecs {
path,
"txindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
p2pk33index_to_p2pk33bytes: IndexedVec::forced_import(
path,
@@ -288,13 +284,13 @@ impl Vecs {
path,
"base_size",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
txindex_to_first_inputindex: IndexedVec::forced_import(
path,
"first_inputindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
txindex_to_first_outputindex: IndexedVec::forced_import(
path,
@@ -306,19 +302,19 @@ impl Vecs {
path,
"is_explicitly_rbf",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
txindex_to_rawlocktime: IndexedVec::forced_import(
path,
"rawlocktime",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
txindex_to_total_size: IndexedVec::forced_import(
path,
"total_size",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
txindex_to_txid: IndexedVec::forced_import(
path,
@@ -330,13 +326,13 @@ impl Vecs {
path,
"txversion",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
unknownoutputindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
version + VERSION + Version::ZERO,
format,
Format::Raw,
)?,
})
}
+1 -1
View File
@@ -12,7 +12,7 @@ pub fn main() -> color_eyre::Result<()> {
let format = Format::Compressed;
let mut indexer = Indexer::new(outputs_dir, format, true)?;
let mut indexer = Indexer::new(outputs_dir, true)?;
indexer.import_vecs()?;
let mut computer = Computer::new(outputs_dir, None, format);
+1 -1
View File
@@ -31,7 +31,7 @@ pub fn main() -> color_eyre::Result<()> {
let format = Format::Compressed;
let mut indexer = Indexer::new(outputs_dir, format, true)?;
let mut indexer = Indexer::new(outputs_dir, true)?;
indexer.import_stores()?;
indexer.import_vecs()?;
+1
View File
@@ -124,6 +124,7 @@ pub async fn variant_handler(
Query(params_opt): Query<ParamsOpt>,
state: State<AppState>,
) -> Response {
let variant = variant.replace("_", "-");
let mut split = variant.split(TO_SEPARATOR);
let params = Params::from((
(
+1 -1
View File
@@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, ValueEnum,
)]
pub enum Format {
#[default]
Compressed,
#[default]
Raw,
}
+2 -1
View File
@@ -31,7 +31,7 @@ where
}
#[inline]
fn get_or_read_(&self, index: usize, mmap: &Mmap) -> Result<Option<Value<T>>> {
let stored_len = mmap.len() / Self::SIZE_OF_T;
let stored_len = self.stored_len_(mmap);
if index >= stored_len {
let pushed = self.pushed();
@@ -53,6 +53,7 @@ where
fn mmap(&self) -> &ArcSwap<Mmap>;
fn stored_len(&self) -> usize;
fn stored_len_(&self, mmap: &Mmap) -> usize;
fn pushed(&self) -> &[T];
#[inline]
+13 -5
View File
@@ -21,7 +21,9 @@ use crate::{
const ONE_KIB: usize = 1024;
const ONE_MIB: usize = ONE_KIB * ONE_KIB;
pub const MAX_CACHE_SIZE: usize = 100 * ONE_MIB;
pub const MAX_PAGE_SIZE: usize = 16 * ONE_KIB;
pub const MAX_PAGE_SIZE: usize = 64 * ONE_KIB;
const VERSION: Version = Version::ONE;
#[derive(Debug)]
pub struct CompressedVec<I, T> {
@@ -39,7 +41,9 @@ where
pub const CACHE_LENGTH: usize = MAX_CACHE_SIZE / Self::PAGE_SIZE;
/// Same as import but will reset the folder under certain errors, so be careful !
pub fn forced_import(path: &Path, version: Version) -> Result<Self> {
pub fn forced_import(path: &Path, mut version: Version) -> Result<Self> {
version = version + VERSION;
let res = Self::import(path, version);
match res {
Err(Error::WrongEndian)
@@ -129,7 +133,7 @@ where
page_index * Self::PER_PAGE
}
fn stored_len_(pages_meta: &Guard<Arc<CompressedPagesMetadata>>) -> usize {
fn stored_len__(pages_meta: &Guard<Arc<CompressedPagesMetadata>>) -> usize {
if let Some(last) = pages_meta.last() {
(pages_meta.len() - 1) * Self::PER_PAGE + last.values_len as usize
} else {
@@ -178,7 +182,11 @@ where
#[inline]
fn stored_len(&self) -> usize {
Self::stored_len_(&self.pages_meta.load())
Self::stored_len__(&self.pages_meta.load())
}
#[inline]
fn stored_len_(&self, _: &Mmap) -> usize {
self.stored_len()
}
#[inline]
@@ -477,7 +485,7 @@ where
fn into_iter(self) -> Self::IntoIter {
let pages_meta = self.pages_meta.load();
let stored_len = CompressedVec::<I, T>::stored_len_(&pages_meta);
let stored_len = CompressedVec::<I, T>::stored_len__(&pages_meta);
CompressedVecIterator {
vec: self,
guard: self.mmap().load(),
+5 -1
View File
@@ -104,7 +104,11 @@ where
#[inline]
fn stored_len(&self) -> usize {
self.mmap.load().len() / Self::SIZE_OF_T
self.stored_len_(&self.mmap.load())
}
#[inline]
fn stored_len_(&self, mmap: &Mmap) -> usize {
mmap.len() / Self::SIZE_OF_T
}
#[inline]
+7
View File
@@ -73,6 +73,13 @@ where
StoredVec::Compressed(v) => v.stored_len(),
}
}
#[inline]
fn stored_len_(&self, mmap: &Mmap) -> usize {
match self {
StoredVec::Raw(v) => v.stored_len_(mmap),
StoredVec::Compressed(v) => v.stored_len_(mmap),
}
}
#[inline]
fn pushed(&self) -> &[T] {
+10 -21
View File
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
@@ -965,7 +965,7 @@
display: flex;
align-items: center;
gap: 1.5rem;
margin: -0.75rem var(--negative-main-padding);
margin: -0.5rem var(--negative-main-padding);
padding: 0.75rem var(--main-padding);
overflow-x: auto;
min-width: 0;
@@ -1113,7 +1113,7 @@
// @ts-check
const preferredColorSchemeMatchMedia = window.matchMedia(
"(prefers-color-scheme: dark)",
"(prefers-color-scheme: dark)"
);
const themeColor = window.document.createElement("meta");
@@ -1123,7 +1123,7 @@
/** @param {boolean} dark */
function updateThemeColor(dark) {
const theme = getComputedStyle(
window.document.documentElement,
window.document.documentElement
).getPropertyValue(dark ? "--black" : "--white");
themeColor.content = theme;
}
@@ -1133,29 +1133,18 @@
"change",
({ matches }) => {
updateThemeColor(matches);
},
}
);
if ("standalone" in window.navigator && !!window.navigator.standalone) {
window.document.documentElement.dataset.display = "standalone";
}
window.addEventListener("load", () => {
navigator.serviceWorker
.register("/service-worker.js")
.then((registration) => {
console.log(
"Service Worker registered with scope:",
registration.scope,
);
})
.catch((error) => {
console.error("Service Worker registration failed:", error);
});
});
// if ("serviceWorker" in navigator) {
// navigator.serviceWorker.register("/service-worker.js");
// }
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("/service-worker.js");
});
}
</script>
<!-- --- -->
@@ -14,9 +14,11 @@
/**
* @typedef {Object} Series
* @property {ISeriesApi<SeriesType>} inner
* @property {ISeriesApi<SeriesType, number>} inner
* @property {string} id
* @property {Signal<boolean>} active
* @property {Signal<boolean>} hasData
* @property {Signal<string | null>} url
* @property {VoidFunction} remove
*/
@@ -26,8 +28,12 @@
*/
/**
* @typedef {ChartData<_SingleValueData>} SingleValueData
* @typedef {ChartData<_CandlestickData>} CandlestickData
* @typedef {ChartData<_SingleValueData<number>>} SingleValueData
* @typedef {ChartData<_CandlestickData<number>>} CandlestickData
*/
/**
* @typedef {function({ iseries: ISeriesApi<any, number>; unit: Unit; index: Index }): void} SetDataCallback
*/
export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
@@ -293,14 +299,15 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
/**
* @param {Object} args
* @param {ISeriesApi<SeriesType>} args.iseries
* @param {ISeriesApi<SeriesType, number>} args.iseries
* @param {string} args.name
* @param {Unit} args.unit
* @param {number} args.order
* @param {Color[]} args.colors
* @param {SeriesType} args.seriesType
* @param {VecId} [args.vecId]
* @param {Accessor<WhitespaceData[]>} [args.data]
* @param {SetDataCallback} [args.setDataCallback]
* @param {Accessor<WhitespaceData<number>[]>} [args.data]
* @param {number} args.paneIndex
* @param {boolean} [args.defaultActive]
*/
@@ -311,6 +318,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
unit,
order,
seriesType,
setDataCallback,
paneIndex,
defaultActive,
colors,
@@ -327,7 +335,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
},
});
let url = /** @type {string | undefined} */ (undefined);
const hasData = signals.createSignal(false);
signals.createEffect(active, (active) =>
// Or remove ?
@@ -345,9 +353,12 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
const series = {
inner: iseries,
active,
hasData,
id,
url: signals.createSignal(/** @type {string | null} */ (null)),
remove() {
dispose();
// @ts-ignore
chart.inner.removeSeries(iseries);
if (_valuesResource) {
activeResources.delete(_valuesResource);
@@ -368,7 +379,8 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
const valuesResource = vecsResources.getOrCreate(index, vecId);
_valuesResource = valuesResource;
url = valuesResource.url;
series.url.set(() => valuesResource.url);
signals.createEffect(active, (active) => {
if (active) {
valuesResource.fetch();
@@ -446,6 +458,12 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
// iseries.update(bar, true);
// });
// }
hasData.set(true);
setDataCallback?.({
iseries,
index,
unit,
});
timeScaleSetCallback?.(() => {
if (
@@ -471,6 +489,12 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
} else if (data) {
signals.createEffect(data, (data) => {
iseries.setData(data);
hasData.set(true);
setDataCallback?.({
iseries,
index: index(),
unit,
});
if (fitContent) {
ichart.timeScale().fitContent();
@@ -482,7 +506,6 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
series,
name,
colors,
url,
order,
});
@@ -520,6 +543,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
* @param {number} [args.paneIndex]
* @param {boolean} [args.defaultActive]
* @param {boolean} [args.inverse]
* @param {SetDataCallback} [args.setDataCallback]
* @param {DeepPartial<CandlestickStyleOptions & SeriesOptionsCommon & CreatePriceLineOptions>} [args.options]
*/
addCandlestickSeries({
@@ -529,22 +553,29 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
order,
paneIndex = 0,
defaultActive,
setDataCallback,
data,
inverse,
}) {
const green = inverse ? colors.red : colors.green;
const red = inverse ? colors.green : colors.red;
const iseries = ichart.addSeries(
/** @type {SeriesDefinition<'Candlestick'>} */ (lc.CandlestickSeries),
{
upColor: green(),
downColor: red(),
wickUpColor: green(),
wickDownColor: red(),
borderVisible: false,
visible: defaultActive !== false,
},
paneIndex,
/** @type {ISeriesApi<'Candlestick', number>} */
const iseries = /** @type {any} */ (
ichart.addSeries(
/** @type {SeriesDefinition<'Candlestick'>} */ (
lc.CandlestickSeries
),
{
upColor: green(),
downColor: red(),
wickUpColor: green(),
wickDownColor: red(),
borderVisible: false,
visible: defaultActive !== false,
},
paneIndex,
)
);
return addSeries({
@@ -556,6 +587,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
seriesType: "Candlestick",
unit,
data,
setDataCallback,
defaultActive,
vecId,
});
@@ -565,9 +597,10 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
* @param {string} args.name
* @param {Unit} args.unit
* @param {number} args.order
* @param {Accessor<LineData[]>} [args.data]
* @param {Accessor<LineData<number>[]>} [args.data]
* @param {VecId} [args.vecId]
* @param {Color} [args.color]
* @param {SetDataCallback} [args.setDataCallback]
* @param {number} [args.paneIndex]
* @param {boolean} [args.defaultActive]
* @param {DeepPartial<LineStyleOptions & SeriesOptionsCommon & CreatePriceLineOptions>} [args.options]
@@ -577,6 +610,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
name,
unit,
order,
setDataCallback,
color,
paneIndex = 0,
defaultActive,
@@ -585,16 +619,19 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
}) {
color ||= unit === "USD" ? colors.green : colors.orange;
const iseries = ichart.addSeries(
/** @type {SeriesDefinition<'Line'>} */ (lc.LineSeries),
{
lineWidth: /** @type {any} */ (1.5),
visible: defaultActive !== false,
priceLineVisible: false,
color: color(),
...options,
},
paneIndex,
/** @type {ISeriesApi<'Line', number>} */
const iseries = /** @type {any} */ (
ichart.addSeries(
/** @type {SeriesDefinition<'Line'>} */ (lc.LineSeries),
{
lineWidth: /** @type {any} */ (1.5),
visible: defaultActive !== false,
priceLineVisible: false,
color: color(),
...options,
},
paneIndex,
)
);
const priceLineOptions = options?.createPriceLine;
@@ -610,6 +647,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
paneIndex,
seriesType: "Line",
unit,
setDataCallback,
data,
defaultActive,
vecId,
@@ -620,8 +658,9 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
* @param {string} args.name
* @param {Unit} args.unit
* @param {number} args.order
* @param {Accessor<BaselineData[]>} [args.data]
* @param {Accessor<BaselineData<number>[]>} [args.data]
* @param {VecId} [args.vecId]
* @param {SetDataCallback} [args.setDataCallback]
* @param {number} [args.paneIndex]
* @param {boolean} [args.defaultActive]
* @param {DeepPartial<BaselineStyleOptions & SeriesOptionsCommon & CreatePriceLineOptions>} [args.options]
@@ -632,31 +671,35 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
unit,
order,
paneIndex: _paneIndex,
setDataCallback,
defaultActive,
data,
options,
}) {
const paneIndex = _paneIndex ?? 0;
const iseries = ichart.addSeries(
/** @type {SeriesDefinition<'Baseline'>} */ (lc.BaselineSeries),
{
lineWidth: /** @type {any} */ (1.5),
visible: defaultActive !== false,
baseValue: {
price: options?.createPriceLine?.value ?? 0,
/** @type {ISeriesApi<'Baseline', number>} */
const iseries = /** @type {any} */ (
ichart.addSeries(
/** @type {SeriesDefinition<'Baseline'>} */ (lc.BaselineSeries),
{
lineWidth: /** @type {any} */ (1.5),
visible: defaultActive !== false,
baseValue: {
price: options?.createPriceLine?.value ?? 0,
},
...options,
topLineColor: options?.topLineColor ?? colors.green(),
bottomLineColor: options?.bottomLineColor ?? colors.red(),
priceLineVisible: false,
bottomFillColor1: "transparent",
bottomFillColor2: "transparent",
topFillColor1: "transparent",
topFillColor2: "transparent",
lineVisible: true,
},
...options,
topLineColor: options?.topLineColor ?? colors.green(),
bottomLineColor: options?.bottomLineColor ?? colors.red(),
priceLineVisible: false,
bottomFillColor1: "transparent",
bottomFillColor2: "transparent",
topFillColor1: "transparent",
topFillColor2: "transparent",
lineVisible: true,
},
paneIndex,
paneIndex,
)
);
const priceLineOptions = options?.createPriceLine;
@@ -674,6 +717,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
order,
paneIndex,
seriesType: "Baseline",
setDataCallback,
unit,
data,
defaultActive,
@@ -746,9 +790,8 @@ function createLegend({ signals, utils }) {
* @param {string} args.name
* @param {number} args.order
* @param {Color[]} args.colors
* @param {string} [args.url]
*/
addOrReplace({ series, name, colors, url, order }) {
addOrReplace({ series, name, colors, order }) {
const div = window.document.createElement("div");
const prev = legends[order];
@@ -853,14 +896,17 @@ function createLegend({ signals, utils }) {
}
});
if (url) {
const anchor = window.document.createElement("a");
anchor.href = url;
anchor.target = "_blank";
anchor.rel = "noopener noreferrer";
anchor.title = "Click to view data";
div.append(anchor);
}
const anchor = window.document.createElement("a");
signals.createEffect(series.url, (url) => {
if (url) {
anchor.href = url;
anchor.target = "_blank";
anchor.rel = "noopener noreferrer";
anchor.title = "Click to view data";
div.append(anchor);
}
});
},
/**
* @param {number} start
@@ -930,7 +976,7 @@ function createPaneHeightObserver({ ichart, paneIndex, signals, utils }) {
}
/**
* @param {ISeriesApi<SeriesType>} series
* @param {ISeriesApi<SeriesType, number>} series
* @param {DeepPartial<CreatePriceLine>} options
* @param {Colors} colors
*/
@@ -944,18 +990,21 @@ function createPriceLine(series, options, colors) {
});
}
/** @param {number} value */
function numberToShortUSFormat(value) {
/**
* @param {number} value
* @param {0 | 2} [digits]
*/
function numberToShortUSFormat(value, digits) {
const absoluteValue = Math.abs(value);
if (isNaN(value)) {
return "";
} else if (absoluteValue < 10) {
return numberToUSFormat(value, 3);
return numberToUSFormat(value, Math.min(3, digits || 10));
} else if (absoluteValue < 1_000) {
return numberToUSFormat(value, 2);
return numberToUSFormat(value, Math.min(2, digits || 10));
} else if (absoluteValue < 10_000) {
return numberToUSFormat(value, 1);
return numberToUSFormat(value, Math.min(1, digits || 10));
} else if (absoluteValue < 1_000_000) {
return numberToUSFormat(value, 0);
} else if (absoluteValue >= 900_000_000_000_000_000) {
@@ -62,7 +62,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
createSignal(initialValue, options) {
const [get, set] = this.createSolidSignal(
/** @type {any} */ (initialValue),
options,
options
);
// @ts-ignore
@@ -77,13 +77,17 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
const paramKey = save.key;
const storageKey = this.createMemo(
() =>
`${typeof save.keyPrefix === "string" ? save.keyPrefix : save.keyPrefix()}-${paramKey}`,
`${
typeof save.keyPrefix === "string"
? save.keyPrefix
: save.keyPrefix()
}-${paramKey}`
);
let serialized = /** @type {string | null} */ (null);
if (options.save.serializeParam !== false) {
serialized = new URLSearchParams(window.location.search).get(
paramKey,
paramKey
);
}
if (serialized === null) {
@@ -91,7 +95,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
}
if (serialized) {
set(() =>
serialized ? save.deserialize(serialized) : initialValue,
serialized ? save.deserialize(serialized) : initialValue
);
}
@@ -100,7 +104,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
if (!firstRun1) {
serialized = localStorage.getItem(storageKey);
set(() =>
serialized ? save.deserialize(serialized) : initialValue,
serialized ? save.deserialize(serialized) : initialValue
);
}
firstRun1 = false;
@@ -146,7 +150,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
};
return signals;
},
}
);
/**
@@ -166,7 +170,7 @@ function writeParam(key, value) {
window.history.replaceState(
null,
"",
`${window.location.pathname}?${urlParams.toString()}`,
`${window.location.pathname}?${urlParams.toString()}`
);
} catch (_) {}
}
+201 -70
View File
@@ -1,12 +1,16 @@
// @ts-check
const keyPrefix = "chart";
const ONE_BTC_IN_SATS = 100_000_000;
const AUTO = "auto";
const LINE = "line";
const CANDLE = "candle";
/**
* @param {Object} args
* @param {Colors} args.colors
* @param {LightweightCharts} args.lightweightCharts
* @param {Accessor<ChartOption>} args.selected
* @param {Accessor<ChartOption>} args.option
* @param {Signals} args.signals
* @param {Utilities} args.utils
* @param {WebSockets} args.webSockets
@@ -18,7 +22,7 @@ export function init({
colors,
elements,
lightweightCharts,
selected,
option,
signals,
utils,
webSockets,
@@ -31,10 +35,15 @@ export function init({
const { headerElement, headingElement } = utils.dom.createHeader();
elements.charts.append(headerElement);
const { index, fieldset } = createIndexSelector({ signals, utils });
const { index, fieldset } = createIndexSelector({
option,
vecIdToIndexes,
signals,
utils,
});
const TIMERANGE_LS_KEY = signals.createMemo(
() => `chart-timerange-${index()}`,
() => `chart-timerange-${index()}`
);
let firstRun = true;
@@ -89,20 +98,37 @@ export function init({
from.set(t.from);
to.set(t.to);
}
}),
})
);
elements.charts.append(fieldset);
const { field: seriesTypeField, selected: topSeriesType } =
const { field: seriesTypeField, selected: topSeriesType_ } =
utils.dom.createHorizontalChoiceField({
defaultValue: "Line",
defaultValue: CANDLE,
keyPrefix,
key: "seriestype-0",
choices: /** @type {const} */ (["Candles", "Line"]),
choices: /** @type {const} */ ([AUTO, CANDLE, LINE]),
signals,
});
const topSeriesType = signals.createMemo(() => {
const topSeriesType = topSeriesType_();
if (topSeriesType === AUTO) {
const t = to();
const f = from();
if (!t || !f) return null;
const diff = t - f;
if (diff / chart.inner.paneSize().width <= 0.5) {
return CANDLE;
} else {
return LINE;
}
} else {
return topSeriesType;
}
});
const { field: topUnitField, selected: topUnit } =
utils.dom.createHorizontalChoiceField({
defaultValue: "USD",
@@ -128,7 +154,89 @@ export function init({
const seriesListTop = /** @type {Series[]} */ ([]);
const seriesListBottom = /** @type {Series[]} */ ([]);
signals.createEffect(selected, (option) => {
/**
* @param {Object} params
* @param {ISeriesApi<any, number>} params.iseries
* @param {Unit} params.unit
* @param {Index} params.index
*/
function printLatest({ iseries, unit, index }) {
const _latest = webSockets.kraken1dCandle.latest();
if (!_latest) return;
const latest = { ..._latest };
if (unit === "Sats") {
latest.open = Math.floor(ONE_BTC_IN_SATS / latest.open);
latest.high = Math.floor(ONE_BTC_IN_SATS / latest.high);
latest.low = Math.floor(ONE_BTC_IN_SATS / latest.low);
latest.close = Math.floor(ONE_BTC_IN_SATS / latest.close);
latest.value = Math.floor(ONE_BTC_IN_SATS / latest.value);
}
const last_ = iseries.data().at(-1);
if (!last_) return;
const last = { ...last_ };
if ("close" in last) {
last.close = latest.close;
}
if ("value" in last) {
last.value = latest.value;
}
const date = new Date(latest.time * 1000);
switch (index) {
case /** @satisfies {Height} */ (5): {
if ("close" in last) {
last.low = Math.min(last.low, latest.close);
last.high = Math.max(last.high, latest.close);
}
iseries.update(last);
break;
}
case /** @satisfies {DateIndex} */ (0): {
iseries.update(latest);
break;
}
default: {
if (index === /** @satisfies {WeekIndex} */ (22)) {
date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7));
} else if (index === /** @satisfies {MonthIndex} */ (7)) {
date.setUTCDate(1);
} else if (index === /** @satisfies {QuarterIndex} */ (19)) {
const month = date.getUTCMonth();
date.setUTCMonth(month - (month % 3), 1);
} else if (index === /** @satisfies {YearIndex} */ (23)) {
date.setUTCMonth(0, 1);
} else if (index === /** @satisfies {DecadeIndex} */ (1)) {
date.setUTCFullYear(
Math.floor(date.getUTCFullYear() / 10) * 10,
0,
1
);
} else {
throw Error("Unsupported");
}
const time = date.valueOf() / 1000;
if (time === last.time) {
if ("close" in last) {
last.low = Math.min(last.low, latest.low);
last.high = Math.max(last.high, latest.high);
}
iseries.update(last);
} else {
latest.time = time;
iseries.update(latest);
}
}
}
}
signals.createEffect(option, (option) => {
headingElement.innerHTML = option.title;
const bottomUnits = /** @type {readonly Unit[]} */ (
@@ -166,80 +274,92 @@ export function init({
signals.createEffect(index, (index) => {
signals.createEffect(
() => [topUnit(), topSeriesType()],
([topUnit, topSeriesType]) => {
() => ({
topUnit: topUnit(),
topSeriesType: topSeriesType(),
}),
({ topUnit, topSeriesType }) => {
/** @type {Series | undefined} */
let series;
switch (topUnit) {
case "USD": {
switch (topSeriesType) {
case "Candles": {
const series = chart.addCandlestickSeries({
case CANDLE: {
series = chart.addCandlestickSeries({
vecId: "ohlc",
name: "Price",
unit: topUnit,
setDataCallback: printLatest,
order: 0,
});
seriesListTop[0]?.remove();
seriesListTop[0] = series;
break;
}
case "Line": {
const series = chart.addLineSeries({
case LINE: {
series = chart.addLineSeries({
vecId: "close",
name: "Price",
unit: topUnit,
color: colors.default,
setDataCallback: printLatest,
options: {
priceLineVisible: true,
},
order: 0,
});
seriesListTop[0]?.remove();
seriesListTop[0] = series;
}
}
// signals.createEffect(webSockets.kraken1dCandle.latest, (latest) => {
// if (!latest) return;
// const last = /** @type { CandlestickData | undefined} */ (
// candles.data().at(-1)
// );
// if (!last) return;
// candles?.update({ ...last, close: latest.close });
// });
break;
}
case "Sats": {
switch (topSeriesType) {
case "Candles": {
const series = chart.addCandlestickSeries({
case CANDLE: {
series = chart.addCandlestickSeries({
vecId: "ohlc-in-sats",
name: "Price",
unit: topUnit,
inverse: true,
setDataCallback: printLatest,
order: 0,
});
seriesListTop[0]?.remove();
seriesListTop[0] = series;
break;
}
case "Line": {
const series = chart.addLineSeries({
case LINE: {
series = chart.addLineSeries({
vecId: "close-in-sats",
name: "Price",
unit: topUnit,
color: colors.default,
setDataCallback: printLatest,
options: {
priceLineVisible: true,
},
order: 0,
});
seriesListTop[0]?.remove();
seriesListTop[0] = series;
}
}
break;
}
}
},
if (!series) throw Error("Unreachable");
seriesListTop[0]?.remove();
seriesListTop[0] = series;
// setDataCallback insimport("./options").tead of hasData
signals.createEffect(
() => ({
latest: webSockets.kraken1dCandle.latest(),
hasData: series.hasData(),
}),
({ latest, hasData }) => {
if (!series || !latest || !hasData) return;
printLatest({ iseries: series.inner, unit: topUnit, index });
}
);
}
);
[
@@ -300,7 +420,7 @@ export function init({
blueprint.color?.() ?? blueprint.colors?.[1](),
},
order,
}),
})
);
break;
}
@@ -318,13 +438,13 @@ export function init({
paneIndex,
options: blueprint.options,
order,
}),
})
);
}
}
});
});
},
}
);
firstRun = false;
@@ -334,25 +454,53 @@ export function init({
/**
* @param {Object} args
* @param {Accessor<ChartOption>} args.option
* @param {VecIdToIndexes} args.vecIdToIndexes
* @param {Signals} args.signals
* @param {Utilities} args.utils
*/
function createIndexSelector({ signals, utils }) {
function createIndexSelector({ option, vecIdToIndexes, signals, utils }) {
const choices_ = /** @type {const} */ ([
"timestamp",
"date",
"week",
// "difficulty epoch",
"month",
"quarter",
"year",
// "halving epoch",
"decade",
]);
/** @type {Accessor<typeof choices_>} */
const choices = signals.createMemo(() => {
const o = option();
if (!Object.keys(o.top).length && !Object.keys(o.bottom).length) {
return [...choices_];
}
const rawIndexes = new Set(
[Object.values(o.top), Object.values(o.bottom)]
.flat(2)
.map((blueprint) => vecIdToIndexes[blueprint.key])
.flat()
);
const serializedIndexes = [...rawIndexes].flatMap((index) => {
const c = utils.serde.chartableIndex.serialize(index);
return c ? [c] : [];
});
return /** @type {any} */ (
choices_.filter((choice) => serializedIndexes.includes(choice))
);
});
const { field, selected } = utils.dom.createHorizontalChoiceField({
defaultValue: "date",
keyPrefix,
key: "index",
choices: /**@type {const} */ ([
"timestamp",
"date",
"week",
// "difficulty epoch",
"month",
"quarter",
"year",
// "halving epoch",
"decade",
]),
choices,
id: "index",
signals,
});
@@ -361,25 +509,8 @@ function createIndexSelector({ signals, utils }) {
fieldset.append(field);
fieldset.dataset.size = "sm";
const index = signals.createMemo(
/** @returns {ChartableIndex} */ () => {
switch (selected()) {
case "timestamp":
return /** @satisfies {Height} */ (5);
case "date":
return /** @satisfies {DateIndex} */ (0);
case "week":
return /** @satisfies {WeekIndex} */ (22);
case "month":
return /** @satisfies {MonthIndex} */ (7);
case "quarter":
return /** @satisfies {QuarterIndex} */ (19);
case "year":
return /** @satisfies {YearIndex} */ (23);
case "decade":
return /** @satisfies {DecadeIndex} */ (1);
}
},
const index = signals.createMemo(() =>
utils.serde.chartableIndex.deserialize(selected())
);
return { fieldset, index };
+169 -105
View File
@@ -1,7 +1,7 @@
// @ts-check
/**
* @import { Option, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, SimulationOption, AnySeriesBlueprint, ChartableIndex,CreatePriceLineOptions, CreatePriceLine } from "./options"
* @import { Option, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, SimulationOption, AnySeriesBlueprint, ChartableIndex,CreatePriceLineOptions, CreatePriceLine, SeriesType } from "./options"
* @import { Valued, SingleValueData, CandlestickData, ChartData, OHLCTuple, Series } from "../packages/lightweight-charts/wrapper"
* @import * as _ from "../packages/ufuzzy/v1.0.18/types"
* @import { createChart as CreateClassicChart, LineStyleOptions, DeepPartial, ChartOptions, IChartApi, IHorzScaleBehavior, WhitespaceData, ISeriesApi, Time, LineData, LogicalRange, BaselineStyleOptions, SeriesOptionsCommon, BaselineData, CandlestickStyleOptions } from "../packages/lightweight-charts/v5.0.7-treeshaked/types"
@@ -362,11 +362,11 @@ function createUtils() {
* @param {Object} args
* @param {T[number]} args.defaultValue
* @param {string} [args.id]
* @param {T} args.choices
* @param {T | Accessor<T>} args.choices
* @param {string} [args.keyPrefix]
* @param {string} args.key
* @param {boolean} [args.sorted]
* @param {{createEffect: CreateEffect, createSignal: Signals["createSignal"]}} args.signals
* @param {{createEffect: CreateEffect, createMemo: CreateMemo, createSignal: Signals["createSignal"]}} args.signals
*/
createHorizontalChoiceField({
id,
@@ -377,13 +377,21 @@ function createUtils() {
signals,
sorted,
}) {
const choices = sorted
? /** @type {T} */ (
/** @type {any} */ (
unsortedChoices.toSorted((a, b) => a.localeCompare(b))
const choices = signals.createMemo(() => {
/** @type {T} */
let c;
if (typeof unsortedChoices === "function") {
c = unsortedChoices();
} else {
c = unsortedChoices;
}
return sorted
? /** @type {T} */ (
/** @type {any} */ (c.toSorted((a, b) => a.localeCompare(b)))
)
)
: unsortedChoices;
: c;
});
/** @type {Signal<T[number]>} */
const selected = signals.createSignal(defaultValue, {
@@ -394,31 +402,39 @@ function createUtils() {
},
});
if (!choices.includes(selected())) {
console.log(choices, "don't include", selected());
selected.set(() => defaultValue);
}
const field = window.document.createElement("div");
field.classList.add("field");
const div = window.document.createElement("div");
field.append(div);
choices.forEach((choice) => {
const inputValue = choice;
const { label } = this.createLabeledInput({
inputId: `${id ?? key}-${choice.toLowerCase()}`,
inputName: id ?? key,
inputValue,
inputChecked: inputValue === selected(),
labelTitle: choice,
type: "radio",
});
signals.createEffect(choices, (choices) => {
const s = selected();
if (!choices.includes(s)) {
if (choices.includes(defaultValue)) {
selected.set(() => defaultValue);
} else if (choices.length) {
selected.set(() => choices[0]);
}
}
const text = window.document.createTextNode(choice);
label.append(text);
div.append(label);
div.innerHTML = "";
choices.forEach((choice) => {
const inputValue = choice;
const { label } = this.createLabeledInput({
inputId: `${id ?? key}-${choice.toLowerCase()}`,
inputName: id ?? key,
inputValue,
inputChecked: inputValue === selected(),
labelTitle: choice,
type: "radio",
});
const text = window.document.createTextNode(choice);
label.append(text);
div.append(label);
});
});
field.addEventListener("change", (event) => {
@@ -1093,6 +1109,116 @@ function createUtils() {
}
},
},
index: {
/**
* @param {Index} v
*/
serialize(v) {
switch (v) {
case /** @satisfies {DateIndex} */ (0):
return "dateindex";
case /** @satisfies {DecadeIndex} */ (1):
return "decadeindex";
case /** @satisfies {DifficultyEpoch} */ (2):
return "difficultyepoch";
case /** @satisfies {EmptyOutputIndex} */ (3):
return "emptyoutputindex";
case /** @satisfies {HalvingEpoch} */ (4):
return "halvingepoch";
case /** @satisfies {Height} */ (5):
return "height";
case /** @satisfies {InputIndex} */ (6):
return "inputindex";
case /** @satisfies {MonthIndex} */ (7):
return "monthindex";
case /** @satisfies {OpReturnIndex} */ (8):
return "opreturnindex";
case /** @satisfies {OutputIndex} */ (9):
return "outputindex";
case /** @satisfies {P2AIndex} */ (10):
return "p2aindex";
case /** @satisfies {P2MSIndex} */ (11):
return "p2msindex";
case /** @satisfies {P2PK33Index} */ (12):
return "p2pk33index";
case /** @satisfies {P2PK65Index} */ (13):
return "p2pk65index";
case /** @satisfies {P2PKHIndex} */ (14):
return "p2pkhindex";
case /** @satisfies {P2SHIndex} */ (15):
return "p2shindex";
case /** @satisfies {P2TRIndex} */ (16):
return "p2trindex";
case /** @satisfies {P2WPKHIndex} */ (17):
return "p2wpkhindex";
case /** @satisfies {P2WSHIndex} */ (18):
return "p2wshindex";
case /** @satisfies {QuarterIndex} */ (19):
return "quarterindex";
case /** @satisfies {TxIndex} */ (20):
return "txindex";
case /** @satisfies {UnknownOutputIndex} */ (21):
return "unknownoutputindex";
case /** @satisfies {WeekIndex} */ (22):
return "weekindex";
case /** @satisfies {YearIndex} */ (23):
return "yearindex";
}
},
},
chartableIndex: {
/**
* @param {Index} v
*/
serialize(v) {
switch (v) {
case /** @satisfies {DateIndex} */ (0):
return "date";
case /** @satisfies {DecadeIndex} */ (1):
return "decade";
// case /** @satisfies {DifficultyEpoch} */ (2):
// return "difficulty";
// case /** @satisfies {HalvingEpoch} */ (4):
// return "halving";
case /** @satisfies {Height} */ (5):
return "timestamp";
case /** @satisfies {MonthIndex} */ (7):
return "month";
case /** @satisfies {QuarterIndex} */ (19):
return "quarter";
case /** @satisfies {WeekIndex} */ (22):
return "week";
case /** @satisfies {YearIndex} */ (23):
return "year";
default:
return null;
}
},
/**
* @param {string} v
* @returns {ChartableIndex}
*/
deserialize(v) {
switch (v) {
case "timestamp":
return /** @satisfies {Height} */ (5);
case "date":
return /** @satisfies {DateIndex} */ (0);
case "week":
return /** @satisfies {WeekIndex} */ (22);
case "month":
return /** @satisfies {MonthIndex} */ (7);
case "quarter":
return /** @satisfies {QuarterIndex} */ (19);
case "year":
return /** @satisfies {YearIndex} */ (23);
case "decade":
return /** @satisfies {DecadeIndex} */ (1);
default:
throw Error("Unsupported");
}
},
},
};
const formatters = {
@@ -1333,62 +1459,6 @@ function createUtils() {
}
}
/**
* @param {Index} index
*/
function vecIndexToString(index) {
switch (index) {
case /** @satisfies {DateIndex} */ (0):
return "dateindex";
case /** @satisfies {DecadeIndex} */ (1):
return "decadeindex";
case /** @satisfies {DifficultyEpoch} */ (2):
return "difficultyepoch";
case /** @satisfies {EmptyOutputIndex} */ (3):
return "emptyoutputindex";
case /** @satisfies {HalvingEpoch} */ (4):
return "halvingepoch";
case /** @satisfies {Height} */ (5):
return "height";
case /** @satisfies {InputIndex} */ (6):
return "inputindex";
case /** @satisfies {MonthIndex} */ (7):
return "monthindex";
case /** @satisfies {OpReturnIndex} */ (8):
return "opreturnindex";
case /** @satisfies {OutputIndex} */ (9):
return "outputindex";
case /** @satisfies {P2AIndex} */ (10):
return "p2aindex";
case /** @satisfies {P2MSIndex} */ (11):
return "p2msindex";
case /** @satisfies {P2PK33Index} */ (12):
return "p2pk33index";
case /** @satisfies {P2PK65Index} */ (13):
return "p2pk65index";
case /** @satisfies {P2PKHIndex} */ (14):
return "p2pkhindex";
case /** @satisfies {P2SHIndex} */ (15):
return "p2shindex";
case /** @satisfies {P2TRIndex} */ (16):
return "p2trindex";
case /** @satisfies {P2WPKHIndex} */ (17):
return "p2wpkhindex";
case /** @satisfies {P2WSHIndex} */ (18):
return "p2wshindex";
case /** @satisfies {QuarterIndex} */ (19):
return "quarterindex";
case /** @satisfies {TxIndex} */ (20):
return "txindex";
case /** @satisfies {UnknownOutputIndex} */ (21):
return "unknownoutputindex";
case /** @satisfies {WeekIndex} */ (22):
return "weekindex";
case /** @satisfies {YearIndex} */ (23):
return "yearindex";
}
}
/**
* @param {Index} index
* @param {VecId} vecId
@@ -1396,7 +1466,7 @@ function createUtils() {
* @param {number} [to]
*/
function genPath(index, vecId, from, to) {
let path = `/query?index=${vecIndexToString(index)}&values=${vecId}`;
let path = `/query?index=${serde.index.serialize(index)}&values=${vecId}`;
if (from !== undefined) {
path += `&from=${from}`;
}
@@ -1828,9 +1898,8 @@ function initWebSockets(signals, utils) {
/**
* @param {(candle: CandlestickData) => void} callback
* @param {number} interval
*/
function krakenCandleWebSocketCreator(callback, interval) {
function krakenCandleWebSocketCreator(callback) {
const ws = new WebSocket("wss://ws.kraken.com/v2");
ws.addEventListener("open", () => {
@@ -1853,14 +1922,10 @@ function initWebSockets(signals, utils) {
const { interval_begin, open, high, low, close } = result.data.at(-1);
const date = new Date(interval_begin);
const dateStr = utils.date.toString(date);
/** @type {CandlestickData} */
const candle = {
index: -1,
time: dateStr,
time: new Date(interval_begin).valueOf() / 1000,
open: Number(open),
high: Number(high),
low: Number(low),
@@ -1874,8 +1939,9 @@ function initWebSockets(signals, utils) {
return ws;
}
/** @type {ReturnType<typeof createWebsocket<CandlestickData>>} */
const kraken1dCandle = createWebsocket((callback) =>
krakenCandleWebSocketCreator(callback, 1440),
krakenCandleWebSocketCreator(callback),
);
kraken1dCandle.open();
@@ -2079,21 +2145,18 @@ function main() {
env,
signals,
utils,
webSockets,
qrcode,
});
// const urlSelected = utils.url.pathnameToSelectedId();
// function createWindowPopStateEvent() {
// window.addEventListener("popstate", (event) => {
// const urlSelected = utils.url.pathnameToSelectedId();
// const option = options.list.find((option) => urlSelected === option.id);
// if (option) {
// options.selected.set(option);
// }
// });
// }
// createWindowPopStateEvent();
// window.addEventListener("popstate", (_) => {
// const urlSelected = utils.url.pathnameToSelectedId();
// const option = options.list.find(
// (option) => urlSelected === option.id,
// );
// if (option) {
// options.selected.set(option);
// }
// });
function initSelected() {
let firstRun = true;
@@ -2120,6 +2183,7 @@ function main() {
let firstTimeLoadingSimulation = true;
signals.createEffect(options.selected, (option) => {
console.log(utils.url.pathnameToSelectedId(), option.id);
if (previousElement) {
previousElement.hidden = true;
utils.url.resetParams(option);
@@ -2148,7 +2212,7 @@ function main() {
colors,
elements,
lightweightCharts,
selected: /** @type {Accessor<ChartOption>} */ (
option: /** @type {Accessor<ChartOption>} */ (
chartOption
),
signals,
+14 -16
View File
@@ -1,7 +1,7 @@
// @ts-check
/**
* @typedef {Height | DateIndex | WeekIndex | DifficultyEpoch | MonthIndex | QuarterIndex | YearIndex | HalvingEpoch | DecadeIndex} ChartableIndex
* @typedef {Height | DateIndex | WeekIndex | MonthIndex | QuarterIndex | YearIndex | DecadeIndex} ChartableIndex
*/
/**
* @template {readonly unknown[]} T
@@ -27,7 +27,7 @@
* @property {Color} [color]
* @property {[Color, Color]} [colors]
* @property {DeepPartial<BaselineStyleOptions & SeriesOptionsCommon & CreatePriceLineOptions>} [options]
* @property {Accessor<BaselineData[]>} [data]
* @property {Accessor<BaselineData<number>[]>} [data]
* @typedef {BaseSeriesBlueprint & BaselineSeriesBlueprintSpecific} BaselineSeriesBlueprint
*
* @typedef {Object} CandlestickSeriesBlueprintSpecific
@@ -41,7 +41,7 @@
* @property {"Line"} [type]
* @property {Color} [color]
* @property {DeepPartial<LineStyleOptions & SeriesOptionsCommon & CreatePriceLineOptions>} [options]
* @property {Accessor<LineData[]>} [data]
* @property {Accessor<LineData<number>[]>} [data]
* @typedef {BaseSeriesBlueprint & LineSeriesBlueprintSpecific} LineSeriesBlueprint
*
* @typedef {BaselineSeriesBlueprint | CandlestickSeriesBlueprint | LineSeriesBlueprint} AnySeriesBlueprint
@@ -1512,7 +1512,9 @@ function createPartialOptions(colors) {
}),
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
type: "Baseline",
key: `${fixKey(key)}net-realized-profit-and-loss-relative-to-realized-cap`,
key: `${fixKey(
key,
)}net-realized-profit-and-loss-relative-to-realized-cap`,
title: useGroupName ? name : "Net",
color: useGroupName ? color : undefined,
options: {
@@ -1581,7 +1583,9 @@ function createPartialOptions(colors) {
bottom: list.flatMap(({ color, name, key }) => [
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
type: "Baseline",
key: `${fixKey(key)}adjusted-spent-output-profit-ratio`,
key: `${fixKey(
key,
)}adjusted-spent-output-profit-ratio`,
title: useGroupName ? name : "asopr",
color: useGroupName ? color : undefined,
options: {
@@ -1691,7 +1695,9 @@ function createPartialOptions(colors) {
}),
/** @satisfies {FetchedBaselineSeriesBlueprint} */ ({
type: "Baseline",
key: `${fixKey(key)}net-unrealized-profit-and-loss-relative-to-market-cap`,
key: `${fixKey(
key,
)}net-unrealized-profit-and-loss-relative-to-market-cap`,
title: useGroupName ? name : "Net",
color: useGroupName ? color : undefined,
options: {
@@ -1987,7 +1993,7 @@ function createPartialOptions(colors) {
top: [
createBaseSeries({
key: `${key}-dca-avg-price`,
name: `dca avg. price`,
name: `dca`,
color: colors.orange,
}),
createBaseSeries({
@@ -2883,17 +2889,9 @@ function createPartialOptions(colors) {
* @param {Signals} args.signals
* @param {Env} args.env
* @param {Utilities} args.utils
* @param {WebSockets} args.webSockets
* @param {Signal<string | null>} args.qrcode
*/
export function initOptions({
colors,
signals,
env,
utils,
webSockets,
qrcode,
}) {
export function initOptions({ colors, signals, env, utils, qrcode }) {
const LS_SELECTED_KEY = `selected-id`;
const urlSelected = utils.url.pathnameToSelectedId();
+72 -66
View File
@@ -76,7 +76,7 @@ export function init({
input.value = value;
stateValue = value;
}
},
}
);
input.addEventListener("input", () => {
@@ -139,7 +139,7 @@ export function init({
input.value = value;
stateValue = value;
}
},
}
);
input.addEventListener("change", () => {
@@ -328,7 +328,7 @@ export function init({
keyPrefix,
key: "top-up-freq",
},
},
}
),
},
},
@@ -356,7 +356,7 @@ export function init({
keyPrefix,
key: "swap-freq",
},
},
}
),
},
},
@@ -369,7 +369,7 @@ export function init({
keyPrefix,
key: "interval-start",
},
},
}
),
end: signals.createSignal(/** @type {Date | null} */ (new Date()), {
save: {
@@ -391,7 +391,7 @@ export function init({
};
parametersElement.append(
utils.dom.createHeader("Save in Bitcoin").headerElement,
utils.dom.createHeader("Save in Bitcoin").headerElement
);
/**
@@ -410,7 +410,9 @@ export function init({
* @param {string} param0.text
*/
function createColoredSpan({ color, text }) {
return `<span style="color: ${colors[color]()}; font-weight: 500; text-transform: uppercase;
return `<span style="color: ${colors[
color
]()}; font-weight: 500; text-transform: uppercase;
font-size: var(--font-size-sm);">${text}</span>`;
}
@@ -429,9 +431,9 @@ export function init({
title: "Initial Dollar Amount",
signal: settings.dollars.initial.amount,
signals,
}),
})
),
}),
})
);
parametersElement.append(
@@ -449,9 +451,9 @@ export function init({
list: frequencies.list,
signal: settings.dollars.topUp.frenquency,
deep: true,
}),
})
),
}),
})
);
parametersElement.append(
@@ -469,9 +471,9 @@ export function init({
title: "Top Up Dollar Amount",
signal: settings.dollars.topUp.amount,
signals,
}),
})
),
}),
})
);
parametersElement.append(
@@ -489,9 +491,9 @@ export function init({
title: "Initial Swap Amount",
signal: settings.bitcoin.investment.initial,
signals,
}),
})
),
}),
})
);
parametersElement.append(
@@ -508,9 +510,9 @@ export function init({
list: frequencies.list,
signal: settings.bitcoin.investment.frequency,
deep: true,
}),
})
),
}),
})
);
parametersElement.append(
@@ -528,9 +530,9 @@ export function init({
title: "Bitcoin Recurrent Investment",
signal: settings.bitcoin.investment.recurrent,
signals,
}),
})
),
}),
})
);
parametersElement.append(
@@ -547,9 +549,9 @@ export function init({
title: "First Simulation Date",
signal: settings.interval.start,
signals,
}),
})
),
}),
})
);
parametersElement.append(
@@ -566,9 +568,9 @@ export function init({
title: "Last Simulation Day",
signal: settings.interval.end,
signals,
}),
})
),
}),
})
);
parametersElement.append(
@@ -589,9 +591,9 @@ export function init({
step: 0.01,
signals,
placeholder: "Fees",
}),
})
),
}),
})
);
const p1 = window.document.createElement("p");
@@ -606,94 +608,94 @@ export function init({
const owner = signals.getOwner();
const totalInvestedAmountData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const bitcoinValueData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const bitcoinData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const resultData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const dollarsLeftData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const totalValueData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const investmentData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const bitcoinAddedData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const averagePricePaidData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const bitcoinPriceData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const buyCountData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const totalFeesPaidData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const daysCountData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const profitableDaysRatioData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const unprofitableDaysRatioData = signals.createSignal(
/** @type {LineData<Time>[]} */ ([]),
/** @type {LineData<number>[]} */ ([]),
{
equals: false,
},
}
);
const index = () => /** @type {DateIndex} */ (0);
@@ -933,8 +935,7 @@ export function init({
let lastSatsAdded = 0;
range.forEach((date, index) => {
const year = date.getUTCFullYear();
const time = utils.date.toString(date);
const time = date.valueOf() / 1000;
if (topUpFrequency.isTriggerDay(date)) {
dollars += topUpAmount;
@@ -1095,16 +1096,21 @@ export function init({
p1.innerHTML = `After exchanging ${serInvestedAmount} in the span of ${serDaysCount} days, you would have accumulated ${serSats} Satoshis (${serBitcoin} Bitcoin) worth today ${serBitcoinValue} at an average price of ${serAveragePricePaid} per Bitcoin with a return of investment of ${serRoi}, have ${serDollars} left and paid a total of ${serTotalFeesPaid} in fees.`;
const dayDiff = Math.floor(
utils.date.differenceBetween(new Date(), lastInvestDay),
utils.date.differenceBetween(new Date(), lastInvestDay)
);
const serDailyInvestment = c("emerald", fd(dailyInvestment));
const setLastSatsAdded = c("orange", f(lastSatsAdded));
p2.innerHTML = `You would've last bought ${c("blue", dayDiff ? `${f(dayDiff)} ${dayDiff > 1 ? "days" : "day"} ago` : "today")} and exchanged ${serDailyInvestment} for approximately ${setLastSatsAdded} Satoshis`;
p2.innerHTML = `You would've last bought ${c(
"blue",
dayDiff
? `${f(dayDiff)} ${dayDiff > 1 ? "days" : "day"} ago`
: "today"
)} and exchanged ${serDailyInvestment} for approximately ${setLastSatsAdded} Satoshis`;
const serProfitableDaysRatio = c("green", fp(profitableDaysRatio));
const serUnprofitableDaysRatio = c(
"red",
fp(unprofitableDaysRatio),
fp(unprofitableDaysRatio)
);
p3.innerHTML = `You would've been ${serProfitableDaysRatio} of the time profitable and ${serUnprofitableDaysRatio} of the time unprofitable.`;
@@ -1114,7 +1120,7 @@ export function init({
(lowestAnnual4YReturn) => {
const serLowestAnnual4YReturn = c(
"cyan",
`${fp(lowestAnnual4YReturn)}`,
`${fp(lowestAnnual4YReturn)}`
);
const lowestAnnual4YReturnPercentage = 1 + lowestAnnual4YReturn;
@@ -1130,22 +1136,22 @@ export function init({
const bitcoinValueAfter4y = bitcoinValueReturn(4);
const serBitcoinValueAfter4y = c(
"purple",
fd(bitcoinValueAfter4y),
fd(bitcoinValueAfter4y)
);
const bitcoinValueAfter10y = bitcoinValueReturn(10);
const serBitcoinValueAfter10y = c(
"fuchsia",
fd(bitcoinValueAfter10y),
fd(bitcoinValueAfter10y)
);
const bitcoinValueAfter21y = bitcoinValueReturn(21);
const serBitcoinValueAfter21y = c(
"pink",
fd(bitcoinValueAfter21y),
fd(bitcoinValueAfter21y)
);
/** @param {number} v */
p4.innerHTML = `The lowest annual return after 4 years has historically been ${serLowestAnnual4YReturn}.<br/>Using it as the baseline, your Bitcoin would be worth ${serBitcoinValueAfter4y} after 4 years, ${serBitcoinValueAfter10y} after 10 years and ${serBitcoinValueAfter21y} after 21 years.`;
},
}
);
totalInvestedAmountData.set((a) => a);
@@ -1163,7 +1169,7 @@ export function init({
daysCountData.set((a) => a);
profitableDaysRatioData.set((a) => a);
unprofitableDaysRatioData.set((a) => a);
},
}
);
});
});
+3 -1
View File
@@ -2,7 +2,7 @@
// File auto-generated, any modifications will be overwritten
//
export const VERSION = "v0.0.48";
export const VERSION = "v0.0.54";
/** @typedef {0} DateIndex */
/** @typedef {1} DecadeIndex */
@@ -1251,6 +1251,7 @@ export function createVecIdToIndexes() {
"fee-75p": [5],
"fee-90p": [5],
"fee-average": [0, 1, 2, 5, 7, 19, 22, 23],
"fee-in-btc": [20],
"fee-in-btc-10p": [5],
"fee-in-btc-25p": [5],
"fee-in-btc-75p": [5],
@@ -1260,6 +1261,7 @@ export function createVecIdToIndexes() {
"fee-in-btc-median": [5],
"fee-in-btc-min": [0, 1, 2, 5, 7, 19, 22, 23],
"fee-in-btc-sum": [0, 1, 2, 5, 7, 19, 22, 23],
"fee-in-usd": [20],
"fee-in-usd-10p": [5],
"fee-in-usd-25p": [5],
"fee-in-usd-75p": [5],
+1
View File
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"strict": true,
"target": "ESNext",