refactor get url

This commit is contained in:
Elijah McMorris 2024-06-08 05:58:59 +00:00
parent 23e8655632
commit a4617e1128
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
2 changed files with 31 additions and 30 deletions

View file

@ -16,6 +16,10 @@ Create data folder next to docker-compose.yml
`docker compose up --pull always` `docker compose up --pull always`
If build the parquet file from the first time use: `ARK_SOURCE=ApiFull` or `ARK_SOURCE=ArkFundsIoFull`
Afterwards use `ARK_SOURCE=ApiIncremental`
# Changing the data source # Changing the data source
In docker-compose.yml, change the data source by changing the environment variable In docker-compose.yml, change the data source by changing the environment variable
``` ```

View file

@ -602,37 +602,34 @@ impl Ark {
last_day: Option<NaiveDate>, last_day: Option<NaiveDate>,
source: Option<&Source>, source: Option<&Source>,
) -> Result<DataFrame, Error> { ) -> Result<DataFrame, Error> {
let url = match (&self.ticker, last_day) { let default_start_day = "2000-01-01";
(self::Ticker::ARKVX, Some(last_day)) => format!( let url = match (&self.ticker, last_day, source) {
(self::Ticker::ARKVX, Some(last_day), _) => format!(
"https://api.nexveridian.com/ark_holdings?ticker=ARKVX&start={}", "https://api.nexveridian.com/ark_holdings?ticker=ARKVX&start={}",
last_day last_day
), ),
(tic, Some(last_day)) => match source { (self::Ticker::ARKVX, None, _) => format!(
Some(Source::ArkFundsIoIncremental) => format!( "https://api.nexveridian.com/ark_holdings?ticker=ARKVX&start={}",
"https://arkfunds.io/api/v2/etf/holdings?symbol={}&date_from={}", default_start_day
tic, last_day ),
),
_ => format!( (tic, Some(last_day), Some(Source::ArkFundsIoIncremental)) => format!(
"https://api.nexveridian.com/ark_holdings?ticker={}&start={}", "https://arkfunds.io/api/v2/etf/holdings?symbol={}&date_from={}",
tic, last_day tic, last_day
), ),
}, (tic, None, Some(Source::ArkFundsIoFull)) => format!(
(self::Ticker::ARKVX, None) => { "https://arkfunds.io/api/v2/etf/holdings?symbol={}&date_from={}",
"https://api.nexveridian.com/ark_holdings?ticker=ARKVX&start=2000-01-01".to_owned() tic, default_start_day
} ),
(tic, None) => {
match source { (tic, Some(last_day), _) => format!(
Some(Source::ArkFundsIoFull) => { "https://api.nexveridian.com/ark_holdings?ticker={}&start={}",
format!("https://arkfunds.io/api/v2/etf/holdings?symbol={}&date_from=2000-01-01", tic) tic, last_day
} ),
_ => { (tic, None, _) => format!(
format!( "https://api.nexveridian.com/ark_holdings?ticker={}&start={}",
"https://api.nexveridian.com/ark_holdings?ticker={}&start=2000-01-01", tic, default_start_day
tic ),
)
}
}
}
}; };
let mut df = Reader::Json.get_data_url(url)?; let mut df = Reader::Json.get_data_url(url)?;
@ -655,8 +652,8 @@ impl Ark {
pub fn get_csv_ark(&self) -> Result<DataFrame, Error> { pub fn get_csv_ark(&self) -> Result<DataFrame, Error> {
let url = match self.ticker { let url = match self.ticker {
self::Ticker::ARKVX => format!("https://assets.ark-funds.com/fund-documents/funds-etf-csv/{}", self.ticker.value()), self::Ticker::ARKVX => format!("https://assets.ark-funds.com/fund-documents/funds-etf-csv/{}", self.ticker.value()),
self::Ticker::ARKA | self::Ticker::ARKZ | self::Ticker::ARKA | self::Ticker::ARKZ | self::Ticker::ARKC | self::Ticker::ARKD |
self::Ticker::ARKC | self::Ticker::ARKD | self::Ticker::ARKY => format!("https://cdn.21shares-funds.com/uploads/fund-documents/us-bank/holdings/product/current/{}-Export.csv", self.ticker.value()), self::Ticker::ARKY => format!("https://cdn.21shares-funds.com/uploads/fund-documents/us-bank/holdings/product/current/{}-Export.csv", self.ticker.value()),
_ => format!("https://assets.ark-funds.com/fund-documents/funds-etf-csv/ARK_{}_ETF_{}_HOLDINGS.csv", self.ticker.value(), self.ticker), _ => format!("https://assets.ark-funds.com/fund-documents/funds-etf-csv/ARK_{}_ETF_{}_HOLDINGS.csv", self.ticker.value(), self.ticker),
}; };
Reader::Csv.get_data_url(url) Reader::Csv.get_data_url(url)