-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
49 lines (38 loc) · 1.33 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Exchange/Exchange.h"
#include "Order/Order.h"
#include "Utils/Utils.h"
#include <thread>
#include <memory>
int main() {
Exchange::Exchange exchange;
// List stock
try {
exchange.listStock("AAPL", "Apple Inc.", 150.0, 1000000);
} catch (const std::exception& e) {
Utils::Logger::getInstance().log("Stock listing error: " + std::string(e.what()));
return 1;
}
// Start exchange processing
exchange.start();
// Create orders
try {
Order::Order buyOrder1("AAPL", Order::OrderType::LIMIT_BUY, 150.0, 10);
Order::Order sellOrder1("AAPL", Order::OrderType::LIMIT_SELL, 150.0, 5);
Order::Order marketBuyOrder("AAPL", Order::OrderType::MARKET_BUY, 0.0, 15);
exchange.placeOrder(buyOrder1);
exchange.placeOrder(sellOrder1);
exchange.placeOrder(marketBuyOrder);
// Cancel order
exchange.cancelOrder(buyOrder1.id);
} catch (const std::exception& e) {
Utils::Logger::getInstance().log("Order creation error: " + std::string(e.what()));
return 1;
}
std::this_thread::sleep_for(std::chrono::seconds(5));
// Query order book and trade history
exchange.getOrderBook("AAPL");
exchange.getTradeHistory("AAPL");
// Stop exchange processing
exchange.stop();
return 0;
}