mirror of
https://github.com/NexVeridian/ark-invest-api-rust-data.git
synced 2025-09-02 09:59:12 +00:00
0.3.12
This commit is contained in:
parent
0de1bcb725
commit
41bd1e8fe7
3 changed files with 52 additions and 30 deletions
36
src/main.rs
36
src/main.rs
|
@ -36,24 +36,29 @@ use util::*;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let read = Ark::new(Source::Read, Ticker::ARKK, None)
|
// let csv = Ark::merge_old_csv_to_parquet(Ticker::ARKK, None)
|
||||||
.unwrap()
|
// .unwrap()
|
||||||
.collect()
|
// .format()
|
||||||
.unwrap();
|
// .unwrap()
|
||||||
println!("{:#?}", read.dtypes());
|
// .write_parquet()
|
||||||
println!("{:#?}", read);
|
|
||||||
|
|
||||||
let api = Ark::new(Source::ApiFull, Ticker::ARKK, None)
|
|
||||||
.unwrap()
|
|
||||||
.collect()
|
|
||||||
.unwrap();
|
|
||||||
println!("{:#?}", api);
|
|
||||||
|
|
||||||
// let ark = Ark::new(Source::Ark, Ticker::ARKK, None)
|
|
||||||
// .unwrap()
|
// .unwrap()
|
||||||
// .collect()
|
// .collect()
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
|
// println!("{:#?}", csv);
|
||||||
|
|
||||||
|
let read = Ark::new(Source::Read, Ticker::ARKK, None)?.collect()?;
|
||||||
|
println!("{:#?}", read.dtypes());
|
||||||
|
println!("{:#?}", read.get_column_names());
|
||||||
|
println!("{:#?}", read);
|
||||||
|
|
||||||
|
// let api = Ark::new(Source::ApiFull, Ticker::ARKK, None)
|
||||||
|
// .unwrap()
|
||||||
|
// .collect()
|
||||||
|
// .unwrap();
|
||||||
|
// println!("{:#?}", api);
|
||||||
|
|
||||||
|
// let ark = Ark::new(Source::Ark, Ticker::ARKK, None)?.collect()?;
|
||||||
// println!("{:#?}", ark);
|
// println!("{:#?}", ark);
|
||||||
|
|
||||||
// let ark = Ark::new(Source::Ark, Ticker::ARKVC, None)
|
// let ark = Ark::new(Source::Ark, Ticker::ARKVC, None)
|
||||||
|
@ -61,4 +66,5 @@ fn main() {
|
||||||
// .collect()
|
// .collect()
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
// println!("{:#?}", ark);
|
// println!("{:#?}", ark);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
43
src/util.rs
43
src/util.rs
|
@ -1,14 +1,14 @@
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use polars::datatypes::DataType;
|
use polars::datatypes::DataType;
|
||||||
|
use polars::lazy::dsl::StrptimeOptions;
|
||||||
use polars::prelude::*;
|
use polars::prelude::*;
|
||||||
use polars::prelude::{DataFrame, StrptimeOptions, UniqueKeepStrategy};
|
|
||||||
use reqwest::blocking::Client;
|
use reqwest::blocking::Client;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::{create_dir_all, File};
|
use std::fs::{create_dir_all, File};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use std::result::Result;
|
use std::result::Result;
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
|
@ -249,21 +249,38 @@ impl Ark {
|
||||||
if df.get_column_names().contains(&"weight_rank") {
|
if df.get_column_names().contains(&"weight_rank") {
|
||||||
_ = df.drop_in_place("weight_rank");
|
_ = df.drop_in_place("weight_rank");
|
||||||
}
|
}
|
||||||
|
if df.get_column_names().contains(&"") {
|
||||||
let mut expressions: Vec<Expr> = vec![];
|
let mut cols = df.get_column_names();
|
||||||
|
cols.retain(|&item| !item.is_empty());
|
||||||
|
df = df.select(cols)?;
|
||||||
|
}
|
||||||
|
|
||||||
if !df.fields().contains(&Field::new("date", DataType::Date)) {
|
if !df.fields().contains(&Field::new("date", DataType::Date)) {
|
||||||
expressions.push(col("date").str().strptime(
|
let date_format = |df: DataFrame, format: &str| -> Result<DataFrame, Box<dyn Error>> {
|
||||||
DataType::Date,
|
Ok(df
|
||||||
StrptimeOptions {
|
.lazy()
|
||||||
format: Some("%m/%d/%Y".into()),
|
.with_column(col("date").str().strptime(
|
||||||
strict: false,
|
DataType::Date,
|
||||||
exact: true,
|
StrptimeOptions {
|
||||||
cache: true,
|
format: Some(format.into()),
|
||||||
},
|
strict: false,
|
||||||
));
|
exact: true,
|
||||||
|
cache: true,
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.collect()?)
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Ok(x) = date_format(df.clone(), "%m/%d/%Y") {
|
||||||
|
df = x
|
||||||
|
}
|
||||||
|
if let Ok(x) = date_format(df.clone(), "%Y/%m/%d") {
|
||||||
|
df = x
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut expressions: Vec<Expr> = vec![];
|
||||||
|
|
||||||
if df.fields().contains(&Field::new("weight", DataType::Utf8)) {
|
if df.fields().contains(&Field::new("weight", DataType::Utf8)) {
|
||||||
expressions.push(
|
expressions.push(
|
||||||
col("weight")
|
col("weight")
|
||||||
|
|
|
@ -25,8 +25,7 @@ fn get_api_arkk() -> Result<(), Box<dyn Error>> {
|
||||||
"share_price",
|
"share_price",
|
||||||
"shares",
|
"shares",
|
||||||
"ticker",
|
"ticker",
|
||||||
"weight",
|
"weight"
|
||||||
"weight_rank"
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue