diff --git a/Enumerations.ixx b/Enumerations.ixx new file mode 100644 index 0000000..9ebe3ef --- /dev/null +++ b/Enumerations.ixx @@ -0,0 +1,18 @@ +export module Enumerations; + +export +{ + enum class OrderType + { + GoodTillCancel, + FillAndKill, + FillOrKill, + GoodForDay, + }; + + enum class Side + { + Buy, + Sell + }; +} \ No newline at end of file diff --git a/Globals.ixx b/Globals.ixx new file mode 100644 index 0000000..71162a5 --- /dev/null +++ b/Globals.ixx @@ -0,0 +1,11 @@ +export module Globals; + +import ; + +export +{ + using Price = std::int32_t; + using Quantity = std::uint32_t; + using OrderId = std::uint64_t; + using OrderIds = std::vector; +} \ No newline at end of file diff --git a/LevelInfo.ixx b/LevelInfo.ixx new file mode 100644 index 0000000..4c9272e --- /dev/null +++ b/LevelInfo.ixx @@ -0,0 +1,14 @@ +export module LevelInfo; + +import Globals; + +export +{ + struct LevelInfo + { + Price price_; + Quantity quantity_; + }; + + using LevelInfos = std::vector; +} diff --git a/Order.ixx b/Order.ixx new file mode 100644 index 0000000..eecc750 --- /dev/null +++ b/Order.ixx @@ -0,0 +1,52 @@ +export module Order; + +import Globals; +import Enumerations; + +import ; +import ; +import ; +import ; + +export +{ + class Order + { + public: + Order(OrderType orderType, OrderId orderId, Side side, Price price, Quantity quantity) + : orderType_{ orderType } + , orderId_{ orderId } + , side_{ side } + , price_{ price } + , initialQuantity_{ quantity } + , remainingQuantity_{ quantity } + { } + + OrderId GetOrderId() const { return orderId_; } + Side GetSide() const { return side_; } + Price GetPrice() const { return price_; } + OrderType GetOrderType() const { return orderType_; } + Quantity GetInitialQuantity() const { return initialQuantity_; } + Quantity GetRemainingQuantity() const { return remainingQuantity_; } + Quantity GetFilledQuantity() const { return GetInitialQuantity() - GetRemainingQuantity(); } + bool IsFilled() const { return GetRemainingQuantity() == 0; } + void Fill(Quantity quantity) + { + if (quantity > GetRemainingQuantity()) + throw std::logic_error(std::format("Order ({}) cannot be filled for more than its remaining quantity.", GetOrderId())); + + remainingQuantity_ -= quantity; + } + + private: + OrderType orderType_; + OrderId orderId_; + Side side_; + Price price_; + Quantity initialQuantity_; + Quantity remainingQuantity_; + }; + + using OrderPointer = std::shared_ptr; + using OrderPointers = std::list; +} \ No newline at end of file diff --git a/OrderModify.ixx b/OrderModify.ixx new file mode 100644 index 0000000..323d25a --- /dev/null +++ b/OrderModify.ixx @@ -0,0 +1,32 @@ +export module OrderModify; + +import Globals; +import Enumerations; +import Order; + +export class OrderModify +{ +public: + OrderModify(OrderId orderId, Side side, Price price, Quantity quantity) + : orderId_{ orderId } + , price_{ price } + , side_{ side } + , quantity_{ quantity } + { } + + OrderId GetOrderId() const { return orderId_; } + Price GetPrice() const { return price_; } + Side GetSide() const { return side_; } + Quantity GetQuantity() const { return quantity_; } + + OrderPointer ToOrderPointer(OrderType type) const + { + return std::make_shared(type, GetOrderId(), GetSide(), GetPrice(), GetQuantity()); + } + +private: + OrderId orderId_; + Price price_; + Side side_; + Quantity quantity_; +}; diff --git a/Orderbook.cpp b/Orderbook.ixx similarity index 73% rename from Orderbook.cpp rename to Orderbook.ixx index 14fb29b..ddf4467 100644 --- a/Orderbook.cpp +++ b/Orderbook.ixx @@ -1,163 +1,24 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum class OrderType -{ - GoodTillCancel, - FillAndKill, - FillOrKill, - GoodForDay, -}; - -enum class Side -{ - Buy, - Sell -}; - -using Price = std::int32_t; -using Quantity = std::uint32_t; -using OrderId = std::uint64_t; -using OrderIds = std::vector; - -struct LevelInfo -{ - Price price_; - Quantity quantity_; -}; - -using LevelInfos = std::vector; - -class OrderbookLevelInfos -{ -public: - OrderbookLevelInfos(const LevelInfos& bids, const LevelInfos& asks) - : bids_{ bids } - , asks_{ asks } - { } - - const LevelInfos& GetBids() const { return bids_; } - const LevelInfos& GetAsks() const { return asks_; } - -private: - LevelInfos bids_; - LevelInfos asks_; -}; - -class Order -{ -public: - Order(OrderType orderType, OrderId orderId, Side side, Price price, Quantity quantity) - : orderType_{ orderType } - , orderId_{ orderId } - , side_{ side } - , price_{ price } - , initialQuantity_{ quantity } - , remainingQuantity_{ quantity } - { } - - OrderId GetOrderId() const { return orderId_; } - Side GetSide() const { return side_; } - Price GetPrice() const { return price_; } - OrderType GetOrderType() const { return orderType_; } - Quantity GetInitialQuantity() const { return initialQuantity_; } - Quantity GetRemainingQuantity() const { return remainingQuantity_; } - Quantity GetFilledQuantity() const { return GetInitialQuantity() - GetRemainingQuantity(); } - bool IsFilled() const { return GetRemainingQuantity() == 0; } - void Fill(Quantity quantity) - { - if (quantity > GetRemainingQuantity()) - throw std::logic_error(std::format("Order ({}) cannot be filled for more than its remaining quantity.", GetOrderId())); - - remainingQuantity_ -= quantity; - } - -private: - OrderType orderType_; - OrderId orderId_; - Side side_; - Price price_; - Quantity initialQuantity_; - Quantity remainingQuantity_; -}; - -using OrderPointer = std::shared_ptr; -using OrderPointers = std::list; - -class OrderModify -{ -public: - OrderModify(OrderId orderId, Side side, Price price, Quantity quantity) - : orderId_{ orderId } - , price_{ price } - , side_{ side } - , quantity_{ quantity } - { } - - OrderId GetOrderId() const { return orderId_; } - Price GetPrice() const { return price_; } - Side GetSide() const { return side_; } - Quantity GetQuantity() const { return quantity_; } - - OrderPointer ToOrderPointer(OrderType type) const - { - return std::make_shared(type, GetOrderId(), GetSide(), GetPrice(), GetQuantity()); - } - -private: - OrderId orderId_; - Price price_; - Side side_; - Quantity quantity_; -}; - -struct TradeInfo -{ - OrderId orderId_; - Price price_; - Quantity quantity_; -}; - -class Trade -{ -public: - Trade(const TradeInfo& bidTrade, const TradeInfo& askTrade) - : bidTrade_{ bidTrade } - , askTrade_{ askTrade } - { } - - const TradeInfo& GetBidTrade() const { return bidTrade_; } - const TradeInfo& GetAskTrade() const { return askTrade_; } - -private: - TradeInfo bidTrade_; - TradeInfo askTrade_; -}; - -using Trades = std::vector; - -class Orderbook +export module Orderbook; + +import Globals; +import Enumerations; +import Order; +import OrderModify; +import OrderbookLevelInfos; +import TradeInfo; +import Trade; + +import ; +import ; +import ; +import ; +import ; +import ; +import ; +import ; +import ; + +export class Orderbook { private: @@ -198,7 +59,7 @@ class Orderbook const auto now = system_clock::now(); const auto now_c = system_clock::to_time_t(now); std::tm now_parts; - localtime_s(&now_parts, &now_c); + _localtime64_s(&now_parts, &now_c); if (now_parts.tm_hour >= end.count()) now_parts.tm_mday += 1; @@ -207,7 +68,7 @@ class Orderbook now_parts.tm_min = 0; now_parts.tm_sec = 0; - auto next = system_clock::from_time_t(mktime(&now_parts)); + auto next = system_clock::from_time_t(_mktime64(&now_parts)); auto till = next - now + milliseconds(100); { @@ -547,10 +408,4 @@ class Orderbook return OrderbookLevelInfos{ bidInfos, askInfos }; } - }; - -int main() -{ - return 0; -} diff --git a/Orderbook.vcxproj b/Orderbook.vcxproj index da7d62c..3e79660 100644 --- a/Orderbook.vcxproj +++ b/Orderbook.vcxproj @@ -129,7 +129,16 @@ - + + + + + + + + + + diff --git a/Orderbook.vcxproj.filters b/Orderbook.vcxproj.filters index 48fef51..47f8433 100644 --- a/Orderbook.vcxproj.filters +++ b/Orderbook.vcxproj.filters @@ -15,8 +15,35 @@ - + Source Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/OrderbookLevelInfos.ixx b/OrderbookLevelInfos.ixx new file mode 100644 index 0000000..ebc3095 --- /dev/null +++ b/OrderbookLevelInfos.ixx @@ -0,0 +1,22 @@ +export module OrderbookLevelInfos; + +import LevelInfo; + +export +{ + class OrderbookLevelInfos + { + public: + OrderbookLevelInfos(const LevelInfos& bids, const LevelInfos& asks) + : bids_{ bids } + , asks_{ asks } + { } + + const LevelInfos& GetBids() const { return bids_; } + const LevelInfos& GetAsks() const { return asks_; } + + private: + LevelInfos bids_; + LevelInfos asks_; + }; +} diff --git a/Trade.ixx b/Trade.ixx new file mode 100644 index 0000000..e16be71 --- /dev/null +++ b/Trade.ixx @@ -0,0 +1,26 @@ +export module Trade; + +import TradeInfo; + +import ; + +export +{ + class Trade + { + public: + Trade(const TradeInfo& bidTrade, const TradeInfo& askTrade) + : bidTrade_{ bidTrade } + , askTrade_{ askTrade } + { } + + const TradeInfo& GetBidTrade() const { return bidTrade_; } + const TradeInfo& GetAskTrade() const { return askTrade_; } + + private: + TradeInfo bidTrade_; + TradeInfo askTrade_; + }; + + using Trades = std::vector; +} diff --git a/TradeInfo.ixx b/TradeInfo.ixx new file mode 100644 index 0000000..5fbc0b9 --- /dev/null +++ b/TradeInfo.ixx @@ -0,0 +1,10 @@ +export module TradeInfo; + +import Globals; + +export struct TradeInfo +{ + OrderId orderId_; + Price price_; + Quantity quantity_; +}; diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5d9312d --- /dev/null +++ b/main.cpp @@ -0,0 +1,7 @@ +import Orderbook; + +int main() +{ + Orderbook orderbook; + return 0; +}