2019-08-24 00:11:50 -04:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::path::Path;
|
2019-08-25 00:02:55 -04:00
|
|
|
use std::time::SystemTime;
|
2019-08-24 00:11:50 -04:00
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
|
2019-08-25 21:21:10 -04:00
|
|
|
use crate::iex::{IexMessage, IexParser};
|
2019-08-24 00:11:50 -04:00
|
|
|
|
2019-08-18 19:45:47 -04:00
|
|
|
// Cap'n'Proto and Flatbuffers typically ask that you generate code on the fly to match
|
|
|
|
// the schemas. For purposes of auto-complete and easy browsing in the repository,
|
|
|
|
// we generate the code and just copy it into the src/ tree.
|
|
|
|
pub mod marketdata_capnp;
|
2019-08-24 00:11:50 -04:00
|
|
|
#[allow(unused_imports)]
|
2019-08-18 19:45:47 -04:00
|
|
|
pub mod marketdata_generated; // Flatbuffers
|
|
|
|
|
2019-08-25 21:21:10 -04:00
|
|
|
mod capnp_runner;
|
2019-08-24 22:49:07 -04:00
|
|
|
mod iex;
|
|
|
|
mod parsers;
|
2019-08-24 00:11:50 -04:00
|
|
|
|
2019-08-18 19:45:47 -04:00
|
|
|
fn main() {
|
2019-08-24 00:11:50 -04:00
|
|
|
let matches = App::new("Marketdata Shootout")
|
2019-08-25 21:21:10 -04:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("file")
|
|
|
|
.short("f")
|
|
|
|
.long("file")
|
|
|
|
.value_name("FILE")
|
|
|
|
.help("IEX DEEP file to process")
|
|
|
|
.required(true)
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2019-08-24 00:11:50 -04:00
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
let deep = matches.value_of("file").unwrap();
|
|
|
|
let path = Path::new(deep);
|
|
|
|
let mut file = File::open(path).expect(&format!("Unable to open file={}", path.display()));
|
|
|
|
|
|
|
|
let mut buf = Vec::new();
|
2019-08-25 21:21:10 -04:00
|
|
|
file.read_to_end(&mut buf)
|
|
|
|
.expect(&format!("Unable to read file={}", path.display()));
|
2019-08-24 00:11:50 -04:00
|
|
|
|
2019-08-25 00:02:55 -04:00
|
|
|
let start = SystemTime::now();
|
2019-08-25 21:21:10 -04:00
|
|
|
|
|
|
|
// Try with Capnproto for now
|
|
|
|
let parser = IexParser::new(&buf[..]);
|
|
|
|
let capnp_buf = capnp_runner::serialize_capnp(parser, buf.len(), true);
|
|
|
|
let stats = capnp_runner::read_capnp(&capnp_buf, true);
|
|
|
|
|
|
|
|
dbg!(stats);
|
|
|
|
|
|
|
|
println!(
|
|
|
|
"Parse time seconds={}",
|
|
|
|
SystemTime::now().duration_since(start).unwrap().as_secs()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct SummaryStats {
|
|
|
|
symbol: String,
|
|
|
|
trade_volume: u64,
|
|
|
|
bid_high: u64,
|
|
|
|
bid_low: u64,
|
|
|
|
ask_high: u64,
|
|
|
|
ask_low: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SummaryStats {
|
|
|
|
fn new(sym: &str) -> SummaryStats {
|
|
|
|
SummaryStats {
|
|
|
|
symbol: sym.to_string(),
|
|
|
|
trade_volume: 0,
|
|
|
|
bid_high: 0,
|
|
|
|
bid_low: u64::max_value(),
|
|
|
|
ask_high: 0,
|
|
|
|
ask_low: u64::max_value(),
|
|
|
|
}
|
2019-08-24 00:11:50 -04:00
|
|
|
}
|
2019-08-18 19:45:47 -04:00
|
|
|
}
|