You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RustyTrader/src/data/price_history.rs

56 lines
1.3 KiB

use polars::{prelude::DataFrame, df, prelude::{NamedFrom}};
use crate::DynResult;
pub struct Candle {
pub high: f64,
pub open: f64,
pub low: f64,
pub close: f64,
pub volume: Option<u64>,
pub timestamp: i64 // mls since epoch
}
impl Candle {
pub fn new(high: f64, open: f64, low: f64, close: f64, volume: Option<u64>, timestamp: i64) -> Self {
Candle { high, open, low, close, volume, timestamp }
}
}
pub struct PriceHistory {
symbol: String,
candles: Vec<Candle>
}
pub trait ToPriceHistory {
fn to_pricehistorty(&self) -> DynResult<PriceHistory>;
}
pub fn create_timeseries_dataframe(timeseries_data: &Vec<Candle>) -> DynResult<DataFrame> {
let mut high = vec![];
let mut open = vec![];
let mut low = vec![];
let mut close = vec![];
let mut volume = vec![];
let mut timestamp = vec![];
for candle in timeseries_data {
high.push(candle.high);
open.push(candle.open);
low.push(candle.low);
close.push(candle.close);
volume.push(candle.volume);
timestamp.push(candle.timestamp);
}
Ok(df!(
"High" => &high,
"Open" => &open,
"Low" => &low,
"Close"=> &close,
"Volume"=> &volume,
"TimeStamp" => &timestamp
)?)
}