Skip to content

Commit

Permalink
csv file: half done
Browse files Browse the repository at this point in the history
  • Loading branch information
ryqdev committed May 31, 2024
1 parent d3c895d commit 22f69d2
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions src/green/green.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::fs::File;
use std::io::Read;
use std::ptr::read;
use anyhow::format_err;
use ibapi::{Client};
use ibapi::contracts::{Contract, SecurityType};
use ibapi::market_data::realtime::{BarSize, WhatToShow};
Expand Down Expand Up @@ -199,34 +202,25 @@ pub struct Bar {
}


fn fetch_csv_data(symbol: &str) -> impl Iterator<Item = Bar> {
let csv_file = File::open(format!("data/{symbol}.csv")).unwrap();

let mut reader = csv::ReaderBuilder::new()
.has_headers(true)
.from_reader(csv_file)
.deserialize();

// TODO: Why move here
reader.map(move |record:(String, Vec<f64>)| Bar{
date: OffsetDateTime::now_utc(),
open: record.1[0],
high: record.1[1],
low: record.1[2],
close: record.1[3],
volume: 0.0,
wap: 0.0,
count: 0,
})

fn fetch_csv_data(symbol: &str) -> Result<String, Error> {
let mut buffer = String::new();
let mut csv_file = File::open(format!("data/{symbol}.csv")).unwrap();
csv_file.read_to_string(&mut buffer);
if buffer.is_empty() {
return Err("csv file missing")
}
Ok(buffer)
}

fn bar_from_csv<T>(
csv_reader: impl Iterator<Item = XXXX>
) -> impl Iterator<Item = Bar>
where T: XXXX
{
// TODO:
fn get_bar_from_csv<T>(symbol: &str) -> impl Iterator<Item = T> {
let buffer = fetch_csv_data(symbol).unwrap();
let mut lines = buffer.lines();
let headers = lines.next().unwrap();
let columns = headers.split(',').collect();

for line in lines {
let mut record = line.split(',').collect();
}
csv_reader.map(move |r| Bar{
date: OffsetDateTime::now_utc(),
open: r.1[0],
Expand All @@ -240,5 +234,4 @@ where T: XXXX
}

// fn connect_and_fetch_market_data() -> impl Iterator<Item = Bar>{
//
// }
//

0 comments on commit 22f69d2

Please sign in to comment.