aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/economy/trading
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/economy/trading')
-rw-r--r--src/openvic-simulation/economy/trading/MarketInstance.cpp28
-rw-r--r--src/openvic-simulation/economy/trading/MarketInstance.hpp15
-rw-r--r--src/openvic-simulation/economy/trading/MarketSellOrder.cpp19
-rw-r--r--src/openvic-simulation/economy/trading/MarketSellOrder.hpp32
-rw-r--r--src/openvic-simulation/economy/trading/SellResult.cpp11
-rw-r--r--src/openvic-simulation/economy/trading/SellResult.hpp16
6 files changed, 121 insertions, 0 deletions
diff --git a/src/openvic-simulation/economy/trading/MarketInstance.cpp b/src/openvic-simulation/economy/trading/MarketInstance.cpp
new file mode 100644
index 0000000..06a470b
--- /dev/null
+++ b/src/openvic-simulation/economy/trading/MarketInstance.cpp
@@ -0,0 +1,28 @@
+#include "MarketInstance.hpp"
+
+#include <execution>
+
+using namespace OpenVic;
+
+bool MarketInstance::setup(GoodInstanceManager& new_good_instance_manager) {
+ good_instance_manager = &new_good_instance_manager;
+ return true;
+}
+
+void MarketInstance::place_market_sell_order(const MarketSellOrder market_sell_order) {
+ GoodDefinition const* const good = market_sell_order.get_good();
+ GoodInstance* const good_instance = good_instance_manager->get_good_instance_by_identifier(good->get_identifier());
+ good_instance->add_market_sell_order(market_sell_order);
+}
+
+void MarketInstance::execute_orders() {
+ std::vector<GoodInstance>& good_instances = good_instance_manager->get_good_instances();
+ std::for_each(
+ std::execution::par,
+ good_instances.begin(),
+ good_instances.end(),
+ [](GoodInstance& good_instance) -> void {
+ good_instance.execute_orders();
+ }
+ );
+}
diff --git a/src/openvic-simulation/economy/trading/MarketInstance.hpp b/src/openvic-simulation/economy/trading/MarketInstance.hpp
new file mode 100644
index 0000000..2d8a651
--- /dev/null
+++ b/src/openvic-simulation/economy/trading/MarketInstance.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "openvic-simulation/economy/GoodInstance.hpp"
+#include "openvic-simulation/economy/trading/MarketSellOrder.hpp"
+
+namespace OpenVic {
+ struct MarketInstance {
+ private:
+ GoodInstanceManager* PROPERTY(good_instance_manager);
+ public:
+ bool setup(GoodInstanceManager& new_good_instance_manager);
+ void place_market_sell_order(const MarketSellOrder market_sell_order);
+ void execute_orders();
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/economy/trading/MarketSellOrder.cpp b/src/openvic-simulation/economy/trading/MarketSellOrder.cpp
new file mode 100644
index 0000000..8522c8c
--- /dev/null
+++ b/src/openvic-simulation/economy/trading/MarketSellOrder.cpp
@@ -0,0 +1,19 @@
+#include "MarketSellOrder.hpp"
+
+using namespace OpenVic;
+
+GoodMarketSellOrder::GoodMarketSellOrder(
+ const fixed_point_t new_quantity,
+ const std::function<void(const SellResult)> new_after_trade
+):
+ quantity { new_quantity },
+ after_trade { new_after_trade }
+ {}
+
+MarketSellOrder::MarketSellOrder(
+ GoodDefinition const& new_good,
+ const fixed_point_t new_quantity,
+ const std::function<void(const SellResult)> new_after_trade
+): GoodMarketSellOrder(new_quantity, new_after_trade),
+ good { &new_good }
+ {} \ No newline at end of file
diff --git a/src/openvic-simulation/economy/trading/MarketSellOrder.hpp b/src/openvic-simulation/economy/trading/MarketSellOrder.hpp
new file mode 100644
index 0000000..21c931d
--- /dev/null
+++ b/src/openvic-simulation/economy/trading/MarketSellOrder.hpp
@@ -0,0 +1,32 @@
+#pragma once
+
+#include "openvic-simulation/economy/GoodDefinition.hpp"
+#include "openvic-simulation/economy/trading/SellResult.hpp"
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+#include "openvic-simulation/utility/Getters.hpp"
+
+namespace OpenVic {
+ struct GoodMarketSellOrder {
+ private:
+ const fixed_point_t PROPERTY(quantity);
+ const std::function<void(const SellResult)> PROPERTY(after_trade);
+
+ public:
+ GoodMarketSellOrder(
+ const fixed_point_t new_quantity,
+ const std::function<void(const SellResult)> new_after_trade
+ );
+ };
+
+ struct MarketSellOrder : GoodMarketSellOrder {
+ private:
+ GoodDefinition const* const PROPERTY(good);
+
+ public:
+ MarketSellOrder(
+ GoodDefinition const& new_good,
+ const fixed_point_t new_quantity,
+ const std::function<void(const SellResult)> new_after_trade
+ );
+ };
+} \ No newline at end of file
diff --git a/src/openvic-simulation/economy/trading/SellResult.cpp b/src/openvic-simulation/economy/trading/SellResult.cpp
new file mode 100644
index 0000000..91de626
--- /dev/null
+++ b/src/openvic-simulation/economy/trading/SellResult.cpp
@@ -0,0 +1,11 @@
+#include "SellResult.hpp"
+
+using namespace OpenVic;
+
+SellResult::SellResult(
+ const fixed_point_t new_quantity_sold,
+ const fixed_point_t new_money_gained
+) :
+ quantity_sold { new_quantity_sold },
+ money_gained { new_money_gained }
+ {} \ No newline at end of file
diff --git a/src/openvic-simulation/economy/trading/SellResult.hpp b/src/openvic-simulation/economy/trading/SellResult.hpp
new file mode 100644
index 0000000..f3a40ad
--- /dev/null
+++ b/src/openvic-simulation/economy/trading/SellResult.hpp
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+
+namespace OpenVic {
+ struct SellResult {
+ private:
+ fixed_point_t PROPERTY(quantity_sold);
+ fixed_point_t PROPERTY(money_gained);
+ public:
+ SellResult(
+ const fixed_point_t new_quantity_sold,
+ const fixed_point_t new_money_gained
+ );
+ };
+} \ No newline at end of file