|
|
@@ -0,0 +1,64 @@ |
|
|
|
#![allow(unused_imports)] |
|
|
|
|
|
|
|
#[macro_use] |
|
|
|
extern crate slog; |
|
|
|
|
|
|
|
use std::path::PathBuf; |
|
|
|
use std::time::*; |
|
|
|
use std::io::{self, prelude::*}; |
|
|
|
use std::fs; |
|
|
|
use structopt::StructOpt; |
|
|
|
use serde::{Serialize, Deserialize}; |
|
|
|
use slog::Drain; |
|
|
|
use markets::crypto::{Exchange, Ticker, Side}; |
|
|
|
|
|
|
|
|
|
|
|
// equivalent to panic! but without the ugly 'thread main panicked' yada yada |
|
|
|
macro_rules! fatal { ($fmt:expr, $($args:tt)*) => {{ |
|
|
|
eprintln!($fmt, $($args)*); |
|
|
|
std::process::exit(1); |
|
|
|
}}} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)] |
|
|
|
struct Opt { |
|
|
|
/// Path to CSV file with trades data |
|
|
|
#[structopt(short = "f", long = "trades-csv")] |
|
|
|
#[structopt(parse(from_os_str))] |
|
|
|
trades_csv: PathBuf, |
|
|
|
} |
|
|
|
|
|
|
|
#[derive(Deserialize)] |
|
|
|
struct Trade { |
|
|
|
/// Unix nanoseconds |
|
|
|
pub time: u64, |
|
|
|
pub exch: Exchange, |
|
|
|
pub ticker: Ticker, |
|
|
|
pub side: Option<Side>, |
|
|
|
pub price: f64, |
|
|
|
pub amount: f64, |
|
|
|
} |
|
|
|
|
|
|
|
fn main() { |
|
|
|
let start = Instant::now(); |
|
|
|
|
|
|
|
let decorator = slog_term::TermDecorator::new().stdout().force_color().build(); |
|
|
|
let drain = slog_term::FullFormat::new(decorator).use_utc_timestamp().build().fuse(); |
|
|
|
let drain = slog_async::Async::new(drain).chan_size(1024 * 64).thread_name("recv".into()).build().fuse(); |
|
|
|
let logger = slog::Logger::root(drain, o!("version" => structopt::clap::crate_version!())); |
|
|
|
|
|
|
|
info!(logger, "initializing..."); |
|
|
|
|
|
|
|
|
|
|
|
let opt = Opt::from_args(); |
|
|
|
|
|
|
|
if ! opt.trades_csv.exists() { |
|
|
|
error!(logger, "path does not exist: {}", opt.trades_csv.display()); |
|
|
|
fatal!("Error: path does not exist: {}", opt.trades_csv.display()); |
|
|
|
} |
|
|
|
|
|
|
|
info!(logger, "verified csv path exists"; "trades_csv" => %opt.trades_csv.display()); |
|
|
|
|
|
|
|
let took = Instant::now() - start; |
|
|
|
info!(logger, "finished in {:?}", took); |
|
|
|
} |