Skip to content

Commit c0538a5

Browse files
authored
Merge pull request #11 from midassystems/updated_mbinary_instrument_fields
Updated mbinary instrument fields
2 parents 119a681 + 2cd4f48 commit c0538a5

File tree

10 files changed

+335
-62
lines changed

10 files changed

+335
-62
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ chrono-tz = "0.10.1"
2828
inquire={version="0.7.5", features=["date"]}
2929
ctrlc = "3.4"
3030
nix = "0.29.0"
31-
mbinary = {version= "1.0.26"}
32-
midas-client = {version = "1.0.22"}
31+
mbinary = {version= "1.0.35"}
32+
midas-client = {version = "1.0.23"}
3333

3434
[dev-dependencies]
3535
sqlx = { version = "0.8.3", features = ["postgres","runtime-tokio-rustls", "macros", "bigdecimal", "json"] }

src/cli/commands/instrument.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ pub struct CreateArgs {
9595
/// last date available in database
9696
#[arg(long)]
9797
pub expiration_date: String,
98+
/// Conntinuous status
99+
#[arg(long)]
100+
pub is_continuous: bool,
98101
/// Active status
99102
#[arg(long)]
100103
pub active: bool,
@@ -139,6 +142,9 @@ pub struct UpdateArgs {
139142
/// last date available in database
140143
#[arg(long)]
141144
pub expiration_date: String,
145+
/// Conntinuous status
146+
#[arg(long)]
147+
pub is_continuous: bool,
142148
/// Active status
143149
#[arg(long)]
144150
pub active: bool,
@@ -176,6 +182,7 @@ impl InstrumentCommands {
176182
first_available as u64,
177183
first_available as u64,
178184
expiration_date as u64,
185+
args.is_continuous,
179186
args.active,
180187
);
181188

@@ -216,6 +223,7 @@ impl InstrumentCommands {
216223
first_available as u64,
217224
last_available as u64,
218225
expiration_date as u64,
226+
args.is_continuous,
219227
args.active,
220228
);
221229

src/shell/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Vendor;
5757

5858
impl Vendor {
5959
pub fn list() -> Vec<&'static str> {
60-
vec!["databento", "yfinance"]
60+
vec!["databento", "yfinance", "internal"]
6161
}
6262
}
6363

src/shell/commands/instrument.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn construct_vendor_data(vendor: &Vendors) -> Result<VendorData> {
4646
dataset: dataset_enum,
4747
}))
4848
}
49+
Vendors::Internal => Ok(VendorData::Internal),
4950
_ => Err(Error::CustomError("Vendor not implemeted".to_string())),
5051
}
5152
}
@@ -65,15 +66,27 @@ pub fn create_instrument() -> Result<Instrument> {
6566
)?;
6667

6768
let vendor_data = construct_vendor_data(&vendor)?;
68-
let first_available =
69-
date_to_unix_nanos(&DateSelect::new("Start Date:").prompt()?.to_string(), None)?;
70-
let expiration_date = date_to_unix_nanos(
71-
&DateSelect::new("Expiration Date:").prompt()?.to_string(),
72-
None,
73-
)?;
69+
70+
let is_continuous = Confirm::new("Is instrument continuous : ")
71+
.with_default(false)
72+
.prompt()?;
73+
74+
let first_available: i64;
75+
let expiration_date: i64;
76+
if is_continuous {
77+
first_available = 0;
78+
expiration_date = 0;
79+
} else {
80+
first_available =
81+
date_to_unix_nanos(&DateSelect::new("Start Date:").prompt()?.to_string(), None)?;
82+
expiration_date = date_to_unix_nanos(
83+
&DateSelect::new("Expiration Date:").prompt()?.to_string(),
84+
None,
85+
)?;
86+
}
87+
7488
let active = Confirm::new("Set instrument active : ")
7589
.with_default(false)
76-
.with_help_message("This data is stored for good reasons")
7790
.prompt()?;
7891

7992
Ok(Instrument::new(
@@ -86,6 +99,7 @@ pub fn create_instrument() -> Result<Instrument> {
8699
first_available as u64,
87100
first_available as u64,
88101
expiration_date as u64,
102+
is_continuous,
89103
active,
90104
))
91105
}

src/shell/commands/vendors/databento.rs

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,93 @@
1+
use super::super::Datasets;
12
use crate::commands::TaskManager;
23
use crate::error::{Error, Result};
3-
use crate::shell::commands::Datasets;
44
use clap::{Args, Subcommand};
55
use dbn;
66
use inquire::Confirm;
77
use inquire::{DateSelect, Select, Text};
8-
use mbinary::enums::Dataset;
98
use std::path::PathBuf;
109
use std::str::FromStr;
1110
use std::sync::Arc;
1211
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
1312
use tokio::sync::Mutex;
1413

14+
// Data options
15+
struct Dataset;
16+
17+
impl Dataset {
18+
pub fn list() -> Vec<&'static str> {
19+
vec![
20+
"GLBX.MDP3",
21+
"XNAS.ITCH",
22+
"XBOS.ITCH",
23+
"XPSX.ITCH",
24+
"BATS.PITCH",
25+
"BATY.PITCH",
26+
"EDGA.PITCH",
27+
"EDGX.PITCH",
28+
"XNYS.PILLAR",
29+
"XCIS.PILLAR",
30+
"XASE.PILLAR",
31+
"XCHI.PILLAR",
32+
"XCIS.BBO",
33+
"XCIS.TRADES",
34+
"MEMX.MEMOIR",
35+
"EPRL.DOM",
36+
"OPRA.PILLAR",
37+
"DBEQ.BASIC",
38+
"ARCX.PILLAR",
39+
"IEXG.TOPS",
40+
"EQUS.PLUS",
41+
"XNYS.BBO",
42+
"XNYS.TRADES",
43+
"XNAS.QBBO",
44+
"XNAS.NLS",
45+
"IFEU.IMPACT",
46+
"NDEX.IMPACT",
47+
"EQUS.ALL",
48+
"XNAS.BASIC",
49+
"EQUS.SUMMARY",
50+
"XCIS.TRADESBBO",
51+
"XNYS.TRADESBBO",
52+
"EQUS.MINI",
53+
]
54+
}
55+
}
56+
struct Schema;
57+
58+
impl Schema {
59+
pub fn list() -> Vec<&'static str> {
60+
vec![
61+
"mbo",
62+
"mbp-1",
63+
"mbp-10",
64+
"tbbo",
65+
"trades",
66+
"bbo-1s",
67+
"bbo-1m",
68+
"ohlcv-1s",
69+
"ohlcv-1m",
70+
"ohlcv-1h",
71+
"ohlcv-1d",
72+
"ohlcv-eod",
73+
]
74+
}
75+
}
76+
77+
struct SType;
78+
79+
impl SType {
80+
pub fn list() -> Vec<&'static str> {
81+
vec![
82+
"instrument_id",
83+
"raw_symbol",
84+
"smart",
85+
"continuous",
86+
"parent",
87+
]
88+
}
89+
}
90+
1591
#[derive(Debug, Args)]
1692
pub struct DatabentoArgs {
1793
#[command(subcommand)]
@@ -36,36 +112,34 @@ impl DatabentoCommands {
36112
.map(|opt| opt.to_string())
37113
.collect::<Vec<String>>(); // Split by newline characters
38114

39-
let start = DateSelect::new("Start Date:").prompt()?.to_string();
40-
let end = DateSelect::new("End Date:").prompt()?.to_string();
115+
let mut start = DateSelect::new("Start Date:").prompt()?.to_string();
116+
let mut end = DateSelect::new("End Date:").prompt()?.to_string();
117+
println!("Date {:?}", start);
41118

42119
// Try to parse the datetime string as an OffsetDateTime
120+
start = format!("{}T00:00:00Z", start);
43121
let start_date = OffsetDateTime::parse(&start, &Rfc3339).map_err(|_| {
44122
Error::DateError(
45123
"Error: Invalid start date format. Expected format: YYYY-MM-DD".to_string(),
46124
)
47125
})?;
48126

49127
// Try to parse the datetime string as an OffsetDateTime
128+
end = format!("{}T00:00:00Z", end);
50129
let end_date = OffsetDateTime::parse(&end, &Rfc3339).map_err(|_| {
51130
Error::DateError(
52-
"Error: Invalid start date format. Expected format: YYYY-MM-DD".to_string(),
131+
"Error: Invalid end date format. Expected format: YYYY-MM-DD".to_string(),
53132
)
54133
})?;
55-
let stype = Text::new("Stype:").prompt()?;
56-
let schema = Text::new("Schema:").prompt()?;
57-
let dataset = Text::new("Dataset:").prompt()?;
58-
59-
// Convert `stype` to the correct type (e.g., dbn::SType)
60-
let stype_enum = dbn::SType::from_str(&stype)
61-
.map_err(|_| Error::CustomError(format!("Invalid 'stype': {}", stype)))?;
62-
let schema_enum = dbn::Schema::from_str(&schema)
63-
.map_err(|_| Error::CustomError(format!("Invalid 'schema': {}", stype)))?;
64-
let dataset_enum = dbn::Dataset::from_str(&dataset)
65-
.map_err(|_| Error::CustomError(format!("Invalid 'dataset': {}", stype)))?;
134+
135+
let schema =
136+
dbn::Schema::from_str(Select::new("Schema:", Schema::list()).prompt()?)?;
137+
let stype = dbn::SType::from_str(Select::new("Stype:", SType::list()).prompt()?)?;
138+
let dataset =
139+
dbn::Dataset::from_str(Select::new("Dataset:", Dataset::list()).prompt()?)?;
140+
66141
let approval = Confirm::new("Approval on download : ")
67142
.with_default(false)
68-
.with_help_message("This data is stored for good reasons")
69143
.prompt()?;
70144

71145
let dir_path = Text::new("File Path:").prompt()?;
@@ -75,9 +149,9 @@ impl DatabentoCommands {
75149
.await
76150
.download(
77151
&symbols,
78-
&schema_enum,
79-
&dataset_enum,
80-
&stype_enum,
152+
&schema,
153+
&dataset,
154+
&stype,
81155
start_date,
82156
end_date,
83157
approval,
@@ -86,7 +160,7 @@ impl DatabentoCommands {
86160
.await;
87161
}
88162
DatabentoCommands::Transform => {
89-
let dataset = Dataset::from_str(
163+
let dataset = mbinary::enums::Dataset::from_str(
90164
&Select::new("Dataset:", Datasets::list())
91165
.prompt()?
92166
.to_lowercase(),

0 commit comments

Comments
 (0)