Browse Source

streamlined csv (fewer cols)

tags/v0.2.0
Jonathan Strong 4 years ago
parent
commit
4201ddc182
1 changed files with 8 additions and 15 deletions
  1. +8
    -15
      src/csv.rs

+ 8
- 15
src/csv.rs View File

@@ -202,7 +202,12 @@ fn run(start: Instant, logger: &slog::Logger) -> Result<usize, String> {

let mut wtr = csv::Writer::from_writer(wtr);

wtr.write_record(&["time","ratio","bmex","gdax","n_bmex","n_gdax","bmex_amt","gdax_amt"]).map_err(|e| format!("writing CSV headers to output file failed: {}", e))?;
wtr.write_record(&[
"time",
"ratio",
"bmex",
"gdax",
]).map_err(|e| format!("writing CSV headers to output file failed: {}", e))?;

let headers: csv::StringRecord = rdr.headers().map_err(|e| format!("failed to parse CSV headers: {}", e))?.clone();
let mut row = csv::StringRecord::new();
@@ -241,12 +246,12 @@ fn run(start: Instant, logger: &slog::Logger) -> Result<usize, String> {

n += 1;

if trade.ticker != t!(btc-usd) { continue }

// verify data is sorted by time
assert!(trade.time >= last_time);
last_time = trade.time;

if trade.ticker != t!(btc-usd) { continue }

if trade.time >= next_hour { // finalize last hour, and prepare for this hour
if n_bmex == 0 || n_gdax == 0 {
wtr.write_record(&[
@@ -254,10 +259,6 @@ fn run(start: Instant, logger: &slog::Logger) -> Result<usize, String> {
"NaN",
"NaN",
"NaN",
&format!("{}", n_bmex),
&format!("{}", n_gdax),
&format!("{}", bmex_amt),
&format!("{}", gdax_amt),
]).map_err(|e| format!("writing output row failed: {}", e))?;
} else {
let bmex_wt_avg = bmex_total / bmex_amt;
@@ -268,10 +269,6 @@ fn run(start: Instant, logger: &slog::Logger) -> Result<usize, String> {
&format!("{}", ratio),
&format!("{}", bmex_wt_avg),
&format!("{}", gdax_wt_avg),
&format!("{}", n_bmex),
&format!("{}", n_gdax),
&format!("{}", bmex_amt),
&format!("{}", gdax_amt),
]).map_err(|e| format!("writing output row failed: {}", e))?;
}
n_written += 1;
@@ -295,10 +292,6 @@ fn run(start: Instant, logger: &slog::Logger) -> Result<usize, String> {
"NaN",
"NaN",
"NaN",
"0",
"0",
"0.0",
"0.0",
]).map_err(|e| format!("writing output row failed: {}", e))?;

n_written += 1;


Loading…
Cancel
Save