kraken: parse: define 'Order' type

Use strong typing for the various components of the order.
This commit is contained in:
Bruno BELANYI 2022-03-12 01:54:16 +01:00
parent b7182826ab
commit 9550598a87
4 changed files with 78 additions and 0 deletions

View file

@ -2,10 +2,12 @@ add_executable(kraken kraken.cc)
target_link_libraries(kraken PRIVATE common_options) target_link_libraries(kraken PRIVATE common_options)
add_subdirectory(csv) add_subdirectory(csv)
add_subdirectory(parse)
add_subdirectory(utils) add_subdirectory(utils)
target_link_libraries(kraken PRIVATE target_link_libraries(kraken PRIVATE
csv csv
parse
) )
install(TARGETS kraken) install(TARGETS kraken)

10
src/parse/CMakeLists.txt Normal file
View file

@ -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)

1
src/parse/order.cc Normal file
View file

@ -0,0 +1 @@
#include "order.hh"

65
src/parse/order.hh Normal file
View file

@ -0,0 +1,65 @@
#pragma once
#include <string>
#include <variant>
#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<int, PriceTag>;
struct QuantityTag;
/// A strongly-typed quantity value.
using Quantity = utils::StrongType<int, PriceTag>;
struct SymbolTag;
/// A strongly-typed symbol value.
using Symbol = utils::StrongType<std::string, SymbolTag>;
struct UserTag;
/// A strongly-typed user id value.
using User = utils::StrongType<int, UserTag>;
struct UserOrderIdTag;
/// A strongly-typed user/order id value.
using UserOrderId = utils::StrongType<int, UserOrderIdTag>;
/// 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<TradeOrder, CancelOrder, FlushOrder>;
} // namespace kraken::parse