mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-27 06:34:30 -07:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 31110a740d | |||
| b64d8b1d7f | |||
| c46006aacc | |||
| 92f81b1493 | |||
| 70213cfc8f | |||
| 8a82bf5c50 | |||
| 37405384a2 | |||
| 54ea6cc53b | |||
| 339c00d815 | |||
| ea6b4dcde2 |
Generated
+18
-18
@@ -388,7 +388,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"brk_cli",
|
||||
"brk_computer",
|
||||
@@ -407,7 +407,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_cli"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"bitcoincore-rpc",
|
||||
"brk_computer",
|
||||
@@ -432,7 +432,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_computer"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"bitcoin",
|
||||
"bitcoincore-rpc",
|
||||
@@ -453,7 +453,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_core"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"bitcoin",
|
||||
@@ -474,7 +474,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_exit"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"brk_logger",
|
||||
"ctrlc",
|
||||
@@ -483,7 +483,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_fetcher"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"brk_core",
|
||||
"brk_logger",
|
||||
@@ -496,7 +496,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_indexer"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"bitcoin",
|
||||
"bitcoincore-rpc",
|
||||
@@ -514,7 +514,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_logger"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"color-eyre",
|
||||
"env_logger",
|
||||
@@ -524,7 +524,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_parser"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"bitcoin",
|
||||
"bitcoincore-rpc",
|
||||
@@ -539,7 +539,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_query"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"brk_computer",
|
||||
"brk_core",
|
||||
@@ -557,7 +557,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_server"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"bitcoincore-rpc",
|
||||
@@ -586,7 +586,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_state"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"brk_core",
|
||||
@@ -600,7 +600,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_store"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"brk_core",
|
||||
@@ -610,7 +610,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "brk_vec"
|
||||
version = "0.0.51"
|
||||
version = "0.0.54"
|
||||
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
@@ -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.51"
|
||||
package.version = "0.0.54"
|
||||
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.51", path = "crates/brk_cli" }
|
||||
brk_computer = { version = "0.0.51", path = "crates/brk_computer" }
|
||||
brk_core = { version = "0.0.51", path = "crates/brk_core" }
|
||||
brk_exit = { version = "0.0.51", path = "crates/brk_exit" }
|
||||
brk_fetcher = { version = "0.0.51", path = "crates/brk_fetcher" }
|
||||
brk_indexer = { version = "0.0.51", path = "crates/brk_indexer" }
|
||||
brk_logger = { version = "0.0.51", path = "crates/brk_logger" }
|
||||
brk_parser = { version = "0.0.51", path = "crates/brk_parser" }
|
||||
brk_query = { version = "0.0.51", path = "crates/brk_query" }
|
||||
brk_server = { version = "0.0.51", path = "crates/brk_server" }
|
||||
brk_state = { version = "0.0.51", path = "crates/brk_state" }
|
||||
brk_store = { version = "0.0.51", path = "crates/brk_store" }
|
||||
brk_vec = { version = "0.0.51", path = "crates/brk_vec" }
|
||||
brk_cli = { version = "0.0.54", path = "crates/brk_cli" }
|
||||
brk_computer = { version = "0.0.54", path = "crates/brk_computer" }
|
||||
brk_core = { version = "0.0.54", path = "crates/brk_core" }
|
||||
brk_exit = { version = "0.0.54", path = "crates/brk_exit" }
|
||||
brk_fetcher = { version = "0.0.54", path = "crates/brk_fetcher" }
|
||||
brk_indexer = { version = "0.0.54", path = "crates/brk_indexer" }
|
||||
brk_logger = { version = "0.0.54", path = "crates/brk_logger" }
|
||||
brk_parser = { version = "0.0.54", path = "crates/brk_parser" }
|
||||
brk_query = { version = "0.0.54", path = "crates/brk_query" }
|
||||
brk_server = { version = "0.0.54", path = "crates/brk_server" }
|
||||
brk_state = { version = "0.0.54", path = "crates/brk_state" }
|
||||
brk_store = { version = "0.0.54", path = "crates/brk_store" }
|
||||
brk_vec = { version = "0.0.54", path = "crates/brk_vec" }
|
||||
byteview = "=0.6.1"
|
||||
clap = { version = "4.5.40", features = ["string"] }
|
||||
clap_derive = "4.5.40"
|
||||
|
||||
@@ -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
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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...");
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
@@ -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()?;
|
||||
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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()?;
|
||||
|
||||
|
||||
@@ -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((
|
||||
(
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
@@ -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,10 @@
|
||||
|
||||
/**
|
||||
* @typedef {Object} Series
|
||||
* @property {ISeriesApi<SeriesType>} inner
|
||||
* @property {ISeriesApi<SeriesType, number>} inner
|
||||
* @property {string} id
|
||||
* @property {Signal<boolean>} active
|
||||
* @property {Signal<boolean>} hasData
|
||||
* @property {VoidFunction} remove
|
||||
*/
|
||||
|
||||
@@ -26,8 +27,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) => {
|
||||
@@ -123,7 +128,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
}
|
||||
: {}),
|
||||
// ..._options,
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
ichart.priceScale("right").applyOptions({
|
||||
@@ -155,7 +160,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
let timeScaleSet = false;
|
||||
@@ -167,12 +172,12 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
index === /** @satisfies {MonthIndex} */ (7)
|
||||
? 1
|
||||
: index === /** @satisfies {QuarterIndex} */ (19)
|
||||
? 3
|
||||
: index === /** @satisfies {YearIndex} */ (23)
|
||||
? 12
|
||||
: index === /** @satisfies {DecadeIndex} */ (1)
|
||||
? 120
|
||||
: 0.5;
|
||||
? 3
|
||||
: index === /** @satisfies {YearIndex} */ (23)
|
||||
? 12
|
||||
: index === /** @satisfies {DecadeIndex} */ (1)
|
||||
? 120
|
||||
: 0.5;
|
||||
|
||||
ichart.applyOptions({
|
||||
timeScale: {
|
||||
@@ -195,12 +200,12 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
activeResources.forEach((v) => {
|
||||
v.fetch();
|
||||
});
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (fitContent) {
|
||||
new ResizeObserver(() => ichart.timeScale().fitContent()).observe(
|
||||
chartDiv,
|
||||
chartDiv
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,7 +234,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
const children = Array.from(parent.childNodes).filter(
|
||||
(element) =>
|
||||
/** @type {HTMLElement} */ (element).dataset.position ===
|
||||
position,
|
||||
position
|
||||
);
|
||||
|
||||
if (children.length === 1) {
|
||||
@@ -251,7 +256,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
|
||||
fieldset.append(createChild(pane));
|
||||
}),
|
||||
paneIndex ? 50 : 0,
|
||||
paneIndex ? 50 : 0
|
||||
);
|
||||
}
|
||||
|
||||
@@ -293,14 +298,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 +317,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
unit,
|
||||
order,
|
||||
seriesType,
|
||||
setDataCallback,
|
||||
paneIndex,
|
||||
defaultActive,
|
||||
colors,
|
||||
@@ -327,13 +334,15 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
},
|
||||
});
|
||||
|
||||
const hasData = signals.createSignal(false);
|
||||
|
||||
let url = /** @type {string | undefined} */ (undefined);
|
||||
|
||||
signals.createEffect(active, (active) =>
|
||||
// Or remove ?
|
||||
iseries.applyOptions({
|
||||
visible: active,
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
iseries.setSeriesOrder(order);
|
||||
@@ -345,9 +354,11 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
const series = {
|
||||
inner: iseries,
|
||||
active,
|
||||
hasData,
|
||||
id,
|
||||
remove() {
|
||||
dispose();
|
||||
// @ts-ignore
|
||||
chart.inner.removeSeries(iseries);
|
||||
if (_valuesResource) {
|
||||
activeResources.delete(_valuesResource);
|
||||
@@ -361,7 +372,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
index,
|
||||
index === /** @satisfies {Height} */ (5)
|
||||
? "timestamp-fixed"
|
||||
: "timestamp",
|
||||
: "timestamp"
|
||||
);
|
||||
timeResource.fetch();
|
||||
|
||||
@@ -446,6 +457,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 (
|
||||
@@ -461,7 +478,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
}
|
||||
});
|
||||
timeScaleSet = true;
|
||||
},
|
||||
}
|
||||
);
|
||||
} else {
|
||||
activeResources.delete(valuesResource);
|
||||
@@ -471,6 +488,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();
|
||||
@@ -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,
|
||||
@@ -824,7 +868,7 @@ function createLegend({ signals, utils }) {
|
||||
} else {
|
||||
spanColor.style.backgroundColor = tameColor(color);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -930,7 +974,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 +988,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) {
|
||||
@@ -978,17 +1025,17 @@ function numberToShortUSFormat(value) {
|
||||
if (modulused === 0) {
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
3,
|
||||
3
|
||||
)}${letter}`;
|
||||
} else if (modulused === 1) {
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
2,
|
||||
2
|
||||
)}${letter}`;
|
||||
} else {
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
1,
|
||||
1
|
||||
)}${letter}`;
|
||||
}
|
||||
}
|
||||
@@ -1038,7 +1085,7 @@ function createOklchToRGBA() {
|
||||
return rgb.map((c) =>
|
||||
Math.abs(c) > 0.0031308
|
||||
? (c < 0 ? -1 : 1) * (1.055 * Math.abs(c) ** (1 / 2.4) - 0.055)
|
||||
: 12.92 * c,
|
||||
: 12.92 * c
|
||||
);
|
||||
}
|
||||
/**
|
||||
@@ -1050,7 +1097,7 @@ function createOklchToRGBA() {
|
||||
1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586,
|
||||
-0.0638541728258133, 1, -0.0894841775298119, -1.2914855480194092,
|
||||
]),
|
||||
lab,
|
||||
lab
|
||||
);
|
||||
const LMS = /** @type {[number, number, number]} */ (
|
||||
LMSg.map((val) => val ** 3)
|
||||
@@ -1061,7 +1108,7 @@ function createOklchToRGBA() {
|
||||
-0.0405757452148008, 1.112286803280317, -0.0717110580655164,
|
||||
-0.0763729366746601, -0.4214933324022432, 1.5869240198367816,
|
||||
]),
|
||||
LMS,
|
||||
LMS
|
||||
);
|
||||
}
|
||||
/**
|
||||
@@ -1074,7 +1121,7 @@ function createOklchToRGBA() {
|
||||
-0.9692436362808796, 1.8759675015077202, 0.04155505740717559,
|
||||
0.05563007969699366, -0.20397695888897652, 1.0569715142428786,
|
||||
],
|
||||
xyz,
|
||||
xyz
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1097,8 +1144,8 @@ function createOklchToRGBA() {
|
||||
});
|
||||
const rgb = srgbLinear2rgb(
|
||||
xyz2rgbLinear(
|
||||
oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch))),
|
||||
),
|
||||
oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch)))
|
||||
)
|
||||
).map((v) => {
|
||||
return Math.max(Math.min(Math.round(v * 255), 255), 0);
|
||||
});
|
||||
|
||||
@@ -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 (_) {}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
|
||||
+238
-176
@@ -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"
|
||||
@@ -67,14 +67,14 @@ function initPackages() {
|
||||
const imports = {
|
||||
async signals() {
|
||||
return import("../packages/solid-signals/wrapper.js").then((d) =>
|
||||
d.default.then((d) => d),
|
||||
d.default.then((d) => d)
|
||||
);
|
||||
},
|
||||
async lightweightCharts() {
|
||||
return window.document.fonts.ready.then(() =>
|
||||
import("../packages/lightweight-charts/wrapper.js").then((d) =>
|
||||
d.default.then((d) => d),
|
||||
),
|
||||
d.default.then((d) => d)
|
||||
)
|
||||
);
|
||||
},
|
||||
async leanQr() {
|
||||
@@ -82,7 +82,7 @@ function initPackages() {
|
||||
},
|
||||
async ufuzzy() {
|
||||
return import("../packages/ufuzzy/v1.0.18/script.js").then(
|
||||
({ default: d }) => d,
|
||||
({ default: d }) => d
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -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) => {
|
||||
@@ -580,7 +596,7 @@ function createUtils() {
|
||||
window.history.pushState(
|
||||
null,
|
||||
"",
|
||||
`${pathname}?${urlParams.toString()}`,
|
||||
`${pathname}?${urlParams.toString()}`
|
||||
);
|
||||
} catch (_) {}
|
||||
},
|
||||
@@ -597,7 +613,7 @@ function createUtils() {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
`${pathname}?${urlParams.toString()}`,
|
||||
`${pathname}?${urlParams.toString()}`
|
||||
);
|
||||
} catch (_) {}
|
||||
},
|
||||
@@ -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 = {
|
||||
@@ -1120,8 +1246,8 @@ function createUtils() {
|
||||
today.getUTCDate(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
0
|
||||
)
|
||||
);
|
||||
},
|
||||
/**
|
||||
@@ -1223,7 +1349,7 @@ function createUtils() {
|
||||
*/
|
||||
function getNumberOfDaysBetweenTwoDates(oldest, youngest) {
|
||||
return Math.round(
|
||||
Math.abs((youngest.getTime() - oldest.getTime()) / date.ONE_DAY_IN_MS),
|
||||
Math.abs((youngest.getTime() - oldest.getTime()) / date.ONE_DAY_IN_MS)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
@@ -1497,7 +1567,7 @@ function createVecsResources(signals, utils) {
|
||||
const fetchedRecord = signals.createSignal(
|
||||
/** @type {Map<string, {loading: boolean, at: Date | null, vec: Signal<T[] | null>}>} */ (
|
||||
new Map()
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -1545,7 +1615,7 @@ function createVecsResources(signals, utils) {
|
||||
index,
|
||||
id,
|
||||
from,
|
||||
to,
|
||||
to
|
||||
)
|
||||
);
|
||||
fetched.at = new Date();
|
||||
@@ -1806,7 +1876,7 @@ function initWebSockets(signals, utils) {
|
||||
|
||||
window.document.addEventListener(
|
||||
"visibilitychange",
|
||||
reinitWebSocketIfDocumentNotHidden,
|
||||
reinitWebSocketIfDocumentNotHidden
|
||||
);
|
||||
|
||||
window.document.addEventListener("online", reinitWebSocket);
|
||||
@@ -1815,7 +1885,7 @@ function initWebSockets(signals, utils) {
|
||||
ws?.close();
|
||||
window.document.removeEventListener(
|
||||
"visibilitychange",
|
||||
reinitWebSocketIfDocumentNotHidden,
|
||||
reinitWebSocketIfDocumentNotHidden
|
||||
);
|
||||
window.document.removeEventListener("online", reinitWebSocket);
|
||||
live.set(false);
|
||||
@@ -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", () => {
|
||||
@@ -1842,7 +1911,7 @@ function initWebSockets(signals, utils) {
|
||||
symbol: ["BTC/USD"],
|
||||
interval: 1440,
|
||||
},
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
@@ -1934,7 +2000,7 @@ function main() {
|
||||
}
|
||||
|
||||
const frame = window.document.getElementById(
|
||||
/** @type {string} */ (input.value),
|
||||
/** @type {string} */ (input.value)
|
||||
);
|
||||
|
||||
if (!frame) {
|
||||
@@ -2032,23 +2098,23 @@ function main() {
|
||||
|
||||
function initDark() {
|
||||
const preferredColorSchemeMatchMedia = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
"(prefers-color-scheme: dark)"
|
||||
);
|
||||
const dark = signals.createSignal(
|
||||
preferredColorSchemeMatchMedia.matches,
|
||||
preferredColorSchemeMatchMedia.matches
|
||||
);
|
||||
preferredColorSchemeMatchMedia.addEventListener(
|
||||
"change",
|
||||
({ matches }) => {
|
||||
dark.set(matches);
|
||||
},
|
||||
}
|
||||
);
|
||||
return dark;
|
||||
}
|
||||
const dark = initDark();
|
||||
|
||||
const qrcode = signals.createSignal(
|
||||
/** @type {string | null} */ (null),
|
||||
/** @type {string | null} */ (null)
|
||||
);
|
||||
|
||||
function createLastHeightResource() {
|
||||
@@ -2059,7 +2125,7 @@ function main() {
|
||||
lastHeight.set(h);
|
||||
},
|
||||
/** @satisfies {Height} */ (5),
|
||||
"height",
|
||||
"height"
|
||||
);
|
||||
}
|
||||
fetchLastHeight();
|
||||
@@ -2106,10 +2172,10 @@ function main() {
|
||||
const owner = signals.getOwner();
|
||||
|
||||
const chartOption = signals.createSignal(
|
||||
/** @type {ChartOption | null} */ (null),
|
||||
/** @type {ChartOption | null} */ (null)
|
||||
);
|
||||
const simOption = signals.createSignal(
|
||||
/** @type {SimulationOption | null} */ (null),
|
||||
/** @type {SimulationOption | null} */ (null)
|
||||
);
|
||||
|
||||
let previousElement = /** @type {HTMLElement | undefined} */ (
|
||||
@@ -2148,7 +2214,7 @@ function main() {
|
||||
colors,
|
||||
elements,
|
||||
lightweightCharts,
|
||||
selected: /** @type {Accessor<ChartOption>} */ (
|
||||
option: /** @type {Accessor<ChartOption>} */ (
|
||||
chartOption
|
||||
),
|
||||
signals,
|
||||
@@ -2156,10 +2222,10 @@ function main() {
|
||||
webSockets,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
firstTimeLoadingChart = false;
|
||||
@@ -2182,9 +2248,9 @@ function main() {
|
||||
vecsResources,
|
||||
option,
|
||||
vecIdToIndexes,
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
firstTimeLoadingTable = false;
|
||||
@@ -2212,10 +2278,10 @@ function main() {
|
||||
signals,
|
||||
utils,
|
||||
vecsResources,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
firstTimeLoadingSimulation = false;
|
||||
@@ -2244,56 +2310,52 @@ function main() {
|
||||
createMobileSwitchEffect();
|
||||
|
||||
utils.dom.onFirstIntersection(elements.aside, () =>
|
||||
signals.runWithOwner(owner, initSelectedFrame),
|
||||
signals.runWithOwner(owner, initSelectedFrame)
|
||||
);
|
||||
}
|
||||
initSelected();
|
||||
|
||||
function initFolders() {
|
||||
function initTreeElement() {
|
||||
// async function scrollToSelected() {
|
||||
// if (!options.selected()) throw "Selected should be set by now";
|
||||
// const selectedId = options.selected().id;
|
||||
|
||||
// const path = options.selected().path;
|
||||
|
||||
// let i = 0;
|
||||
// while (i !== path.length) {
|
||||
// try {
|
||||
// const id = path[i];
|
||||
// const details = /** @type {HTMLDetailsElement} */ (
|
||||
// utils.dom.getElementById(id)
|
||||
// );
|
||||
// details.open = true;
|
||||
// i++;
|
||||
// } catch {
|
||||
// await utils.next();
|
||||
// }
|
||||
// }
|
||||
|
||||
// await utils.next();
|
||||
// await utils.next();
|
||||
|
||||
// utils.dom
|
||||
// .getElementById(`${selectedId}-nav-selector`)
|
||||
// .scrollIntoView({
|
||||
// behavior: "instant",
|
||||
// block: "center",
|
||||
// });
|
||||
// }
|
||||
|
||||
utils.dom.onFirstIntersection(elements.nav, () => {
|
||||
options.treeElement.set(() => {
|
||||
const treeElement = window.document.createElement("div");
|
||||
treeElement.classList.add("tree");
|
||||
elements.nav.append(treeElement);
|
||||
return treeElement;
|
||||
});
|
||||
}
|
||||
|
||||
async function scrollToSelected() {
|
||||
if (!options.selected()) throw "Selected should be set by now";
|
||||
const selectedId = options.selected().id;
|
||||
|
||||
const path = options.selected().path;
|
||||
|
||||
let i = 0;
|
||||
while (i !== path.length) {
|
||||
try {
|
||||
const id = path[i];
|
||||
const details = /** @type {HTMLDetailsElement} */ (
|
||||
utils.dom.getElementById(id)
|
||||
);
|
||||
details.open = true;
|
||||
i++;
|
||||
} catch {
|
||||
await utils.next();
|
||||
}
|
||||
}
|
||||
|
||||
await utils.next();
|
||||
await utils.next();
|
||||
|
||||
utils.dom
|
||||
.getElementById(`${selectedId}-nav-selector`)
|
||||
.scrollIntoView({
|
||||
behavior: "instant",
|
||||
block: "center",
|
||||
});
|
||||
}
|
||||
|
||||
utils.dom.onFirstIntersection(elements.nav, () => {
|
||||
console.log("nav: init");
|
||||
initTreeElement();
|
||||
scrollToSelected();
|
||||
// setTimeout(scrollToSelected, 10);
|
||||
});
|
||||
}
|
||||
initFolders();
|
||||
@@ -2326,7 +2388,7 @@ function main() {
|
||||
if (indexes?.length) {
|
||||
const maxIndex = Math.min(
|
||||
(order || indexes).length - 1,
|
||||
minIndex + RESULTS_PER_PAGE - 1,
|
||||
minIndex + RESULTS_PER_PAGE - 1
|
||||
);
|
||||
|
||||
list = Array(maxIndex - minIndex + 1);
|
||||
@@ -2402,7 +2464,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
undefined,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
|
||||
if (!result?.[0]?.length || !result?.[1]) {
|
||||
@@ -2410,7 +2472,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2419,7 +2481,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2428,7 +2490,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2437,7 +2499,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
undefined,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2446,7 +2508,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2529,7 +2591,7 @@ function main() {
|
||||
|
||||
shareDiv.hidden = false;
|
||||
});
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
initShare();
|
||||
@@ -2551,7 +2613,7 @@ function main() {
|
||||
localStorage.setItem(barWidthLocalStorageKey, String(width));
|
||||
} else {
|
||||
elements.main.style.width = elements.style.getPropertyValue(
|
||||
"--default-main-width",
|
||||
"--default-main-width"
|
||||
);
|
||||
localStorage.removeItem(barWidthLocalStorageKey);
|
||||
}
|
||||
@@ -2587,9 +2649,9 @@ function main() {
|
||||
window.addEventListener("mouseleave", setResizeFalse);
|
||||
}
|
||||
initDesktopResizeBar();
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
main();
|
||||
|
||||
@@ -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
|
||||
@@ -1430,7 +1430,7 @@ function createPartialOptions(colors) {
|
||||
key: `${fixKey(key)}realized-price`,
|
||||
name,
|
||||
color,
|
||||
}),
|
||||
})
|
||||
),
|
||||
}
|
||||
: createPriceWithRatio({
|
||||
@@ -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: {
|
||||
@@ -1603,7 +1607,7 @@ function createPartialOptions(colors) {
|
||||
key: `${fixKey(key)}sell-side-risk-ratio`,
|
||||
name: useGroupName ? name : "Risk",
|
||||
color: color,
|
||||
}),
|
||||
})
|
||||
),
|
||||
},
|
||||
],
|
||||
@@ -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: {
|
||||
@@ -1868,7 +1874,7 @@ function createPartialOptions(colors) {
|
||||
key: `${key}-sma`,
|
||||
name: key,
|
||||
color,
|
||||
}),
|
||||
})
|
||||
),
|
||||
},
|
||||
...averages.map(({ key, name, color }) =>
|
||||
@@ -1878,7 +1884,7 @@ function createPartialOptions(colors) {
|
||||
title: `${name} Market Price Moving Average`,
|
||||
legend: "average",
|
||||
color,
|
||||
}),
|
||||
})
|
||||
),
|
||||
],
|
||||
},
|
||||
@@ -1969,7 +1975,7 @@ function createPartialOptions(colors) {
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
})
|
||||
),
|
||||
.../** @type {const} */ ([
|
||||
{ name: "2 Year", key: "2y" },
|
||||
@@ -2040,7 +2046,7 @@ function createPartialOptions(colors) {
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
})
|
||||
),
|
||||
],
|
||||
},
|
||||
@@ -2056,7 +2062,7 @@ function createPartialOptions(colors) {
|
||||
name: `${year}`,
|
||||
color,
|
||||
defaultActive,
|
||||
}),
|
||||
})
|
||||
),
|
||||
},
|
||||
...dcaClasses.map(
|
||||
@@ -2083,7 +2089,7 @@ function createPartialOptions(colors) {
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
})
|
||||
),
|
||||
],
|
||||
},
|
||||
@@ -2144,10 +2150,10 @@ function createPartialOptions(colors) {
|
||||
bottom: [
|
||||
...createAverageSumCumulativeMinMaxPercentilesSeries("fee"),
|
||||
...createAverageSumCumulativeMinMaxPercentilesSeries(
|
||||
"fee-in-btc",
|
||||
"fee-in-btc"
|
||||
),
|
||||
...createAverageSumCumulativeMinMaxPercentilesSeries(
|
||||
"fee-in-usd",
|
||||
"fee-in-usd"
|
||||
),
|
||||
],
|
||||
},
|
||||
@@ -2911,7 +2917,7 @@ export function initOptions({
|
||||
const detailsList = [];
|
||||
|
||||
const treeElement = signals.createSignal(
|
||||
/** @type {HTMLDivElement | null} */ (null),
|
||||
/** @type {HTMLDivElement | null} */ (null)
|
||||
);
|
||||
|
||||
/** @type {string[] | undefined} */
|
||||
@@ -3030,7 +3036,7 @@ export function initOptions({
|
||||
return null;
|
||||
}
|
||||
},
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
partialTree.forEach((anyPartial, partialIndex) => {
|
||||
@@ -3053,7 +3059,7 @@ export function initOptions({
|
||||
|
||||
if ("tree" in anyPartial) {
|
||||
const folderId = utils.stringToId(
|
||||
`${(path || []).join(" ")} ${anyPartial.name} folder`,
|
||||
`${(path || []).join(" ")} ${anyPartial.name} folder`
|
||||
);
|
||||
|
||||
/** @type {Omit<OptionsGroup, keyof PartialOptionsGroup>} */
|
||||
@@ -3068,13 +3074,13 @@ export function initOptions({
|
||||
const thisPath = groupAddons.id;
|
||||
|
||||
const passedDetails = signals.createSignal(
|
||||
/** @type {HTMLDivElement | HTMLDetailsElement | null} */ (null),
|
||||
/** @type {HTMLDivElement | HTMLDetailsElement | null} */ (null)
|
||||
);
|
||||
|
||||
const childOptionsCount = recursiveProcessPartialTree(
|
||||
anyPartial.tree,
|
||||
passedDetails,
|
||||
[...(path || []), thisPath],
|
||||
[...(path || []), thisPath]
|
||||
);
|
||||
|
||||
listForSum.push(childOptionsCount);
|
||||
@@ -3206,7 +3212,7 @@ export function initOptions({
|
||||
});
|
||||
|
||||
return signals.createMemo(() =>
|
||||
listForSum.reduce((acc, s) => acc + s(), 0),
|
||||
listForSum.reduce((acc, s) => acc + s(), 0)
|
||||
);
|
||||
}
|
||||
recursiveProcessPartialTree(partialOptions, treeElement);
|
||||
@@ -3233,7 +3239,7 @@ export function initOptions({
|
||||
console.log(
|
||||
[...m.entries()]
|
||||
.filter(([_, value]) => value > 1)
|
||||
.map(([key, _]) => key),
|
||||
.map(([key, _]) => key)
|
||||
);
|
||||
|
||||
throw Error("ID duplicate");
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// File auto-generated, any modifications will be overwritten
|
||||
//
|
||||
|
||||
export const VERSION = "v0.0.48";
|
||||
export const VERSION = "v0.0.52";
|
||||
|
||||
/** @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,5 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"strict": true,
|
||||
"target": "ESNext",
|
||||
|
||||
Reference in New Issue
Block a user