kraken: parse: expose 'parse_single_order'
This commit is contained in:
parent
d159cfb877
commit
e601250e7b
|
@ -57,20 +57,24 @@ CancelOrder cancel_from_raw(csv::csv_line_type const& raw_order) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
Order parse_single_order(csv::csv_line_type const& order) {
|
||||||
|
if (order[0] == "N") {
|
||||||
|
return trade_from_raw(order);
|
||||||
|
} else if (order[0] == "C") {
|
||||||
|
return cancel_from_raw(order);
|
||||||
|
} else if (order[0] == "F") {
|
||||||
|
return FlushOrder{};
|
||||||
|
} else {
|
||||||
|
throw ParseError("Not a valid order");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Order> parse_orders(std::istream& input) {
|
std::vector<Order> parse_orders(std::istream& input) {
|
||||||
auto const raw_orders = read_csv(input, kraken::csv::CsvHeader::KEEP);
|
auto const raw_orders = read_csv(input, kraken::csv::CsvHeader::KEEP);
|
||||||
auto orders = std::vector<Order>{};
|
auto orders = std::vector<Order>{};
|
||||||
|
|
||||||
for (auto const& raw_order : raw_orders) {
|
for (auto const& raw_order : raw_orders) {
|
||||||
if (raw_order[0] == "N") {
|
orders.emplace_back(parse_single_order(raw_order));
|
||||||
orders.emplace_back(trade_from_raw(raw_order));
|
|
||||||
} else if (raw_order[0] == "C") {
|
|
||||||
orders.emplace_back(cancel_from_raw(raw_order));
|
|
||||||
} else if (raw_order[0] == "F") {
|
|
||||||
orders.emplace_back(FlushOrder{});
|
|
||||||
} else {
|
|
||||||
throw ParseError("Not a valid order");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return orders;
|
return orders;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "book/order.hh"
|
#include "book/order.hh"
|
||||||
|
#include "csv/csv.hh"
|
||||||
|
|
||||||
namespace kraken::parse {
|
namespace kraken::parse {
|
||||||
|
|
||||||
|
@ -12,6 +13,10 @@ struct ParseError : public std::runtime_error {
|
||||||
using std::runtime_error::runtime_error;
|
using std::runtime_error::runtime_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Convert a single CSV input line to an `Order`.
|
||||||
|
Order parse_single_order(csv::csv_line_type const& order);
|
||||||
|
|
||||||
|
/// Parse orders from an input stream as CSV.
|
||||||
std::vector<Order> parse_orders(std::istream& input);
|
std::vector<Order> parse_orders(std::istream& input);
|
||||||
|
|
||||||
} // namespace kraken::parse
|
} // namespace kraken::parse
|
||||||
|
|
Loading…
Reference in a new issue