kraken: engine: add 'CsvEngineListener'
This is the listener that implements the expected output.
This commit is contained in:
parent
e3b2d29463
commit
346dfc4e17
|
@ -1,4 +1,6 @@
|
|||
add_library(engine STATIC
|
||||
csv-engine-listener.cc
|
||||
csv-engine-listener.hh
|
||||
engine-listener.cc
|
||||
engine-listener.hh
|
||||
)
|
||||
|
|
66
src/engine/csv-engine-listener.cc
Normal file
66
src/engine/csv-engine-listener.cc
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include "csv-engine-listener.hh"
|
||||
|
||||
namespace kraken::engine {
|
||||
|
||||
CsvEngineListener::CsvEngineListener() = default;
|
||||
|
||||
CsvEngineListener::~CsvEngineListener() = default;
|
||||
|
||||
void CsvEngineListener::on_acknowledgement(User user, UserOrderId id) {
|
||||
output_.emplace_back(csv::csv_line_type{
|
||||
"A",
|
||||
std::to_string(int(user)),
|
||||
std::to_string(int(id)),
|
||||
});
|
||||
}
|
||||
|
||||
void CsvEngineListener::on_bad_order(User, UserOrderId) {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
void CsvEngineListener::on_top_of_book_change(Side side, Price price,
|
||||
Quantity quantity) {
|
||||
output_.emplace_back(csv::csv_line_type{
|
||||
"B",
|
||||
side == Side::BID ? "B" : "S",
|
||||
std::to_string(int(price)),
|
||||
std::to_string(int(quantity)),
|
||||
});
|
||||
}
|
||||
|
||||
void CsvEngineListener::on_top_of_book_change(Side side) {
|
||||
output_.emplace_back(csv::csv_line_type{
|
||||
"B",
|
||||
side == Side::BID ? "B" : "S",
|
||||
"-",
|
||||
"-",
|
||||
});
|
||||
}
|
||||
|
||||
void CsvEngineListener::on_rejection(User user, UserOrderId id) {
|
||||
output_.emplace_back(csv::csv_line_type{
|
||||
"R",
|
||||
std::to_string(int(user)),
|
||||
std::to_string(int(id)),
|
||||
});
|
||||
}
|
||||
|
||||
void CsvEngineListener::on_match(User user_buy, UserOrderId id_bid,
|
||||
User user_sell, UserOrderId id_ask,
|
||||
Price price, Quantity quantity) {
|
||||
output_.emplace_back(csv::csv_line_type{
|
||||
"T",
|
||||
std::to_string(int(user_buy)),
|
||||
std::to_string(int(id_bid)),
|
||||
std::to_string(int(user_sell)),
|
||||
std::to_string(int(id_ask)),
|
||||
std::to_string(int(price)),
|
||||
std::to_string(int(quantity)),
|
||||
});
|
||||
}
|
||||
|
||||
void CsvEngineListener::on_flush() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
} // namespace kraken::engine
|
42
src/engine/csv-engine-listener.hh
Normal file
42
src/engine/csv-engine-listener.hh
Normal file
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
#include "csv/csv.hh"
|
||||
|
||||
#include "engine-listener.hh"
|
||||
|
||||
namespace kraken::engine {
|
||||
|
||||
struct CsvEngineListener : EngineListener {
|
||||
CsvEngineListener();
|
||||
|
||||
virtual ~CsvEngineListener();
|
||||
|
||||
/// Called when a new trade or cancel order has been acknowledged.
|
||||
void on_acknowledgement(User user, UserOrderId id) override;
|
||||
|
||||
/// Called when an order is invalid.
|
||||
void on_bad_order(User user, UserOrderId id) override;
|
||||
|
||||
/// Called when the top of the book changes.
|
||||
void on_top_of_book_change(Side side, Price price,
|
||||
Quantity total_quantity) override;
|
||||
/// Called when the top of the book changes, no orders remaining on a side.
|
||||
void on_top_of_book_change(Side side) override;
|
||||
|
||||
/// Called when an order is rejected by the engine for crossing the book.
|
||||
void on_rejection(User user, UserOrderId id) override;
|
||||
|
||||
/// Called when an order is matched by the engine.
|
||||
void on_match(User user_buy, UserOrderId id_bid, User user_sell,
|
||||
UserOrderId id_ask, Price price, Quantity quantity) override;
|
||||
|
||||
/// Called when a flush order is processed.
|
||||
void on_flush() override;
|
||||
|
||||
private:
|
||||
csv::csv_type output_{};
|
||||
};
|
||||
|
||||
}; // namespace kraken::engine
|
Loading…
Reference in a new issue