Skip to content

Commit

Permalink
update day
Browse files Browse the repository at this point in the history
  • Loading branch information
bai committed Nov 6, 2023
1 parent a15b110 commit e52e133
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct UpdateToday {
#[derive(Parser, Debug)]
pub struct UpdateDay {
/// 默认系统当前日期y-m-d
date: Option<String>,
pub date: Option<String>,
}

#[cfg(test)]
Expand Down
45 changes: 25 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use qlib_data::{
command::{self, Opts, UpdateToday},
command::{self, Opts, UpdateToday, UpdateDay},
source_data,
};
use qshare::{
Expand All @@ -17,12 +17,15 @@ async fn main() -> anyhow::Result<()> {
let opts: Opts = Opts::parse();

match opts.updatecmd {
command::UpdateCommand::UpdateToday(args) => {
command::UpdateCommand::UpdateToday(_args) => {
// 更新当天股票数据
update_today(args).await?;
update_today(None).await?;
}

command::UpdateCommand::UpdateDay(_args) => todo!(),
command::UpdateCommand::UpdateDay(args) => {
// 更新指定日期数据,前提是已经缓存过实时行情
update_today(Some(args)).await?;
},
};

Ok(())
Expand All @@ -31,7 +34,7 @@ async fn main() -> anyhow::Result<()> {
///
/// 使用当天数据更新 source 数据
///
async fn update_today(args: UpdateToday) -> Result<()> {
async fn update_today(args: Option<UpdateDay>) -> Result<()> {
tracing::debug!("{:?} 更新当天实时行情数据", args);

// 1. 使用东方财富数据源获取数据
Expand All @@ -46,21 +49,23 @@ async fn update_today(args: UpdateToday) -> Result<()> {
// 3. 股指当天实时行情
let spot_data = sina_source.real_time_data().await?;

if let Some(date) = args.date {
tracing::debug!("更新实时行情数据:{:?}", &em_data);
source_data::update_today_data(
Some(date.clone()),
em_data.data,
qlib_data::util::IoUtils::em_row_to_csv(),
)
.await?;
tracing::debug!("更新实时行情数据:{:?}", &spot_data);
source_data::update_today_data(
Some(date.clone()),
spot_data.data,
qlib_data::util::IoUtils::spot_index_row_to_csv(),
)
.await?;
if let Some(args_opt) = args {
if let Some(date) = args_opt.date{
tracing::debug!("更新实时行情数据:{:?}", &em_data);
source_data::update_today_data(
Some(date.clone()),
em_data.data,
qlib_data::util::IoUtils::em_row_to_csv(),
)
.await?;
tracing::debug!("更新实时行情数据:{:?}", &spot_data);
source_data::update_today_data(
Some(date.clone()),
spot_data.data,
qlib_data::util::IoUtils::spot_index_row_to_csv(),
)
.await?;
}
} else {
source_data::update_today_data(
None,
Expand Down

0 comments on commit e52e133

Please sign in to comment.