kraken: engine: add 'EngineListener'

The `Engine` will be in charge of updating the book, triggering the
listener on each event.
This commit is contained in:
Bruno BELANYI 2022-03-12 03:51:43 +01:00
parent 21ff896730
commit e3b2d29463
4 changed files with 57 additions and 0 deletions

View File

@ -3,6 +3,7 @@ target_link_libraries(kraken PRIVATE common_options)
add_subdirectory(book)
add_subdirectory(csv)
add_subdirectory(engine)
add_subdirectory(parse)
add_subdirectory(utils)
@ -11,6 +12,7 @@ configure_file(config.h.in config.h)
target_link_libraries(kraken PRIVATE
book
csv
engine
parse
)

10
src/engine/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
add_library(engine STATIC
engine-listener.cc
engine-listener.hh
)
target_link_libraries(engine PRIVATE
book
)
target_link_libraries(engine PRIVATE common_options)

View File

@ -0,0 +1,7 @@
#include "engine-listener.hh"
namespace kraken::engine {
EngineListener::~EngineListener() = default;
} // namespace kraken::engine

View File

@ -0,0 +1,38 @@
#pragma once
#include <optional>
#include "book/order.hh"
namespace kraken::engine {
/// Listener interface which is called by the engine on trading events.
struct EngineListener {
virtual ~EngineListener();
/// Called when a new trade or cancel order has been acknowledged.
virtual void on_acknowledgement(User user, UserOrderId id) = 0;
/// Called when an order is invalid.
virtual void on_bad_order(User user, UserOrderId id) = 0;
/// Called when the top of the book changes.
virtual void on_top_of_book_change(Side side, Price price,
Quantity total_quantity)
= 0;
/// Called when the top of the book changes, no orders remaining on a side.
virtual void on_top_of_book_change(Side side) = 0;
/// Called when an order is rejected by the engine for crossing the book.
virtual void on_rejection(User user, UserOrderId id) = 0;
/// Called when an order is matched by the engine.
virtual void on_match(User user_buy, UserOrderId id_bid, User user_sell,
UserOrderId id_ask, Price price, Quantity quantity)
= 0;
/// Called when a flush order is processed.
virtual void on_flush() = 0;
};
} // namespace kraken::engine