use pine_core::{Data, Ohlcv};
mod static_provider;
mod binance;
mod kraken;
mod yahoo;
pub use binance::BinanceSource;
pub use kraken::KrakenSource;
pub use static_provider::{resample, StaticProvider};
pub use yahoo::YahooSource;
pub(crate) fn fetch(url: &str) -> Result<String, DataError> {
ureq::get(url)
.set("User-Agent", "pinecone/0.1")
.call()
.map_err(|source| DataError::Http {
url: url.to_string(),
message: source.to_string(),
})?
.into_string()
.map_err(|source| DataError::Http {
url: url.to_string(),
message: source.to_string(),
})
}
pub(crate) fn quoted(value: &serde_json::Value) -> Option<f64> {
match value {
serde_json::Value::String(text) => text.parse().ok(),
other => other.as_f64(),
}
}
pub fn synthetic(count: usize) -> Data {
Data::from_ohlcv((0..count).map(|i| {
let close = 100.0 + i as f64;
Ohlcv {
time: i as i64 * 60_000,
open: close - 1.0,
high: close + 1.0,
low: close - 2.0,
close,
volume: 1000.0,
}
}))
}
#[derive(Debug, thiserror::Error)]
pub enum DataError {
#[error("{path}: {source}")]
Read {
path: String,
#[source]
source: ::csv::Error,
},
#[error("{url}: {message}")]
Http { url: String, message: String },
#[error("{provider}: {message}")]
Provider {
provider: &'static str,
message: String,
},
}