From 9550598a8701dbd72ce5ec098b929191895dcbd4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 12 Mar 2022 01:54:16 +0100 Subject: [PATCH] kraken: parse: define 'Order' type Use strong typing for the various components of the order. --- src/CMakeLists.txt | 2 ++ src/parse/CMakeLists.txt | 10 +++++++ src/parse/order.cc | 1 + src/parse/order.hh | 65 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 src/parse/CMakeLists.txt create mode 100644 src/parse/order.cc create mode 100644 src/parse/order.hh diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07ea1fa..e7ca454 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,10 +2,12 @@ add_executable(kraken kraken.cc) target_link_libraries(kraken PRIVATE common_options) add_subdirectory(csv) +add_subdirectory(parse) add_subdirectory(utils) target_link_libraries(kraken PRIVATE csv + parse ) install(TARGETS kraken) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt new file mode 100644 index 0000000..340b554 --- /dev/null +++ b/src/parse/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(parse STATIC + order.cc + order.hh +) + +target_link_libraries(parse PRIVATE + utils +) + +target_link_libraries(parse PRIVATE common_options) diff --git a/src/parse/order.cc b/src/parse/order.cc new file mode 100644 index 0000000..749b7e9 --- /dev/null +++ b/src/parse/order.cc @@ -0,0 +1 @@ +#include "order.hh" diff --git a/src/parse/order.hh b/src/parse/order.hh new file mode 100644 index 0000000..aec13d1 --- /dev/null +++ b/src/parse/order.hh @@ -0,0 +1,65 @@ +#pragma once + +#include +#include + +#include "utils/strong-type.hh" + +namespace kraken::parse { + +/// Which side the order is on. +enum class Side { + /// An offer to sell. + BID, + /// An offer to buy. + ASK, +}; + +struct PriceTag; +/// A strongly-typed price value. +using Price = utils::StrongType; + +struct QuantityTag; +/// A strongly-typed quantity value. +using Quantity = utils::StrongType; + +struct SymbolTag; +/// A strongly-typed symbol value. +using Symbol = utils::StrongType; + +struct UserTag; +/// A strongly-typed user id value. +using User = utils::StrongType; + +struct UserOrderIdTag; +/// A strongly-typed user/order id value. +using UserOrderId = utils::StrongType; + +/// DTO to represent an order +struct TradeOrder { + /// User of the order. + User user; + /// Symbol of the order. + Symbol symbol; + /// Price of the order. + Price price; + /// Quantity of the order. + Quantity quantity; + /// Side of the order. + Side side; + /// User/order id. + UserOrderId id; +}; + +struct CancelOrder { + /// User of the order. + User user; + /// User/order id to cancel. + UserOrderId id; +}; + +struct FlushOrder {}; + +using Order = std::variant; + +} // namespace kraken::parse