package top.baogutang.strategy.backtests;

import top.baogutang.strategy.models.Kline;

import java.nio.file.*;
import java.util.*;

public class CsvLoader {

    public static List<Kline> load(String path, long tfMillis) throws Exception {
        List<String> lines = java.nio.file.Files.readAllLines(Paths.get(path));
        List<Kline> list = new ArrayList<>();
        for (int i = 1; i < lines.size(); i++) {
            String[] a = lines.get(i).split(",");
            long ts = Long.parseLong(a[0]);
            double o = Double.parseDouble(a[1]);
            double h = Double.parseDouble(a[2]);
            double l = Double.parseDouble(a[3]);
            double c = Double.parseDouble(a[4]);
            double v = Double.parseDouble(a[5]);
            list.add(new Kline(ts, o, h, l, c, v, ts + tfMillis - 1, true));
        }
        return list;
    }
}
