mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-15 13:08:12 -07:00
general: snapshot
This commit is contained in:
@@ -145,8 +145,8 @@ impl Binance {
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>())
|
||||
},
|
||||
30,
|
||||
10,
|
||||
5,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ impl Binance {
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>())
|
||||
},
|
||||
10,
|
||||
30,
|
||||
10,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Kibo {
|
||||
.map(Self::value_to_ohlc)
|
||||
.collect_vec())
|
||||
},
|
||||
10,
|
||||
30,
|
||||
RETRIES,
|
||||
)
|
||||
}
|
||||
@@ -92,7 +92,7 @@ impl Kibo {
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>())
|
||||
},
|
||||
10,
|
||||
30,
|
||||
RETRIES,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl Kraken {
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>())
|
||||
},
|
||||
10,
|
||||
30,
|
||||
10,
|
||||
)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ impl Kraken {
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>())
|
||||
},
|
||||
10,
|
||||
30,
|
||||
10,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
use std::fs::{self};
|
||||
use std::{
|
||||
fs::{self},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use biter::bitcoincore_rpc::Auth;
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre::eyre;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::log;
|
||||
@@ -20,6 +25,10 @@ pub struct Config {
|
||||
#[arg(long, value_name = "PORT")]
|
||||
pub rpcport: Option<u16>,
|
||||
|
||||
/// Bitcoin RPC cookie file, saved
|
||||
#[arg(long, value_name = "PATH")]
|
||||
pub rpccookiefile: Option<String>,
|
||||
|
||||
/// Bitcoin RPC username, saved
|
||||
#[arg(long, value_name = "USERNAME")]
|
||||
pub rpcuser: Option<String>,
|
||||
@@ -75,6 +84,10 @@ impl Config {
|
||||
config_saved.rpcport = Some(rpcport);
|
||||
}
|
||||
|
||||
if let Some(rpccookiefile) = config_args.rpccookiefile.take() {
|
||||
config_saved.rpccookiefile = Some(rpccookiefile);
|
||||
}
|
||||
|
||||
if let Some(rpcuser) = config_args.rpcuser.take() {
|
||||
config_saved.rpcuser = Some(rpcuser);
|
||||
}
|
||||
@@ -109,6 +122,7 @@ impl Config {
|
||||
log(&format!("datadir: {:?}", config.datadir));
|
||||
log(&format!("rpcconnect: {:?}", config.rpcconnect));
|
||||
log(&format!("rpcport: {:?}", config.rpcport));
|
||||
log(&format!("rpccookiefile: {:?}", config.rpccookiefile));
|
||||
log(&format!("rpcuser: {:?}", config.rpcuser));
|
||||
log(&format!("rpcpassword: {:?}", config.rpcpassword));
|
||||
log(&format!("delay: {:?}", config.delay));
|
||||
@@ -132,30 +146,53 @@ impl Config {
|
||||
|
||||
fn check(&self) {
|
||||
if self.datadir.is_none() {
|
||||
Self::exit("datadir");
|
||||
println!(
|
||||
"You need to set the --datadir parameter at least once to run the parser.\nRun the program with '-h' for help."
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if self.rpcuser.is_none() {
|
||||
Self::exit("rpcuser");
|
||||
let path = Path::new(self.datadir.as_ref().unwrap());
|
||||
if !path.is_dir() {
|
||||
println!("Expect path '{:#?}' to be a directory.", path);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if self.rpcpassword.is_none() {
|
||||
Self::exit("rpcpassword");
|
||||
if self.to_rpc_auth().is_err() {
|
||||
println!(
|
||||
"No way found to authenticate the RPC client, please either set --rpccookiefile or --rpcuser and --rpcpassword.\nRun the program with '-h' for help."
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn exit(attribute: &str) {
|
||||
println!(
|
||||
"You need to set the --{} parameter at least once to run the parser.\nRun the program with '-h' for help.", attribute
|
||||
);
|
||||
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
fn write(&self) -> std::io::Result<()> {
|
||||
fs::write(Self::PATH, toml::to_string(self).unwrap())
|
||||
}
|
||||
|
||||
pub fn to_rpc_auth(&self) -> color_eyre::Result<Auth> {
|
||||
let cookie = Path::new(self.datadir.as_ref().unwrap()).join(".cookie");
|
||||
|
||||
if cookie.is_file() {
|
||||
Ok(Auth::CookieFile(cookie))
|
||||
} else if self
|
||||
.rpccookiefile
|
||||
.as_ref()
|
||||
.is_some_and(|cookie| Path::new(cookie).is_file())
|
||||
{
|
||||
Ok(Auth::CookieFile(PathBuf::from(
|
||||
self.rpccookiefile.as_ref().unwrap(),
|
||||
)))
|
||||
} else if self.rpcuser.is_some() && self.rpcpassword.is_some() {
|
||||
Ok(Auth::UserPass(
|
||||
self.rpcuser.clone().unwrap(),
|
||||
self.rpcpassword.clone().unwrap(),
|
||||
))
|
||||
} else {
|
||||
Err(eyre!("Failed to find correct auth"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dry_run(&self) -> bool {
|
||||
self.dry_run.is_some_and(|b| b)
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ where
|
||||
})
|
||||
.into();
|
||||
|
||||
if previous_average.is_nan() {
|
||||
if previous_average.is_nan() || previous_average.is_infinite() {
|
||||
previous_average = 0.0;
|
||||
}
|
||||
|
||||
@@ -708,17 +708,11 @@ where
|
||||
panic!()
|
||||
}));
|
||||
|
||||
if last_value.is_nan() {
|
||||
if last_value.is_nan() || last_value.is_infinite() {
|
||||
last_value = 0.0;
|
||||
}
|
||||
|
||||
let _average = (previous_average * (len - 1.0) + last_value) / len;
|
||||
|
||||
if _average.is_nan() || _average.is_infinite() {
|
||||
average.replace(0.0.into());
|
||||
} else {
|
||||
average.replace(_average.into());
|
||||
}
|
||||
average.replace(((previous_average * (len - 1.0) + last_value) / len).into());
|
||||
|
||||
self.insert_computed(*key, average.unwrap());
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use biter::bitcoincore_rpc::{Auth, Client};
|
||||
use biter::bitcoincore_rpc::Client;
|
||||
|
||||
use crate::Config;
|
||||
|
||||
@@ -12,9 +12,6 @@ pub fn create_rpc(config: &Config) -> color_eyre::Result<Client> {
|
||||
.unwrap_or(&"localhost".to_owned()),
|
||||
config.rpcport.unwrap_or(8332)
|
||||
),
|
||||
Auth::UserPass(
|
||||
config.rpcuser.clone().unwrap(),
|
||||
config.rpcpassword.clone().unwrap(),
|
||||
),
|
||||
config.to_rpc_auth().unwrap(),
|
||||
)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user