-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (44 loc) · 1.68 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (44 loc) · 1.68 KB
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
50
51
52
53
54
55
56
57
58
59
// Backtesting Engine in C++
//
// (c) 2025 Ryan McCaffery | https://mccaffers.com
// This code is licensed under MIT license (see LICENSE.txt for details)
// ---------------------------------------
// std headers
#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <iomanip>
// external headers
#include <nlohmann/json.hpp>
// backtesting engine headers
#include "configManager.hpp"
#include "serviceA.hpp"
#include "databaseConnection.hpp"
#include "base64.hpp"
#include "trading_definitions.hpp" // For everything
#include "tradeManager.hpp"
#include "jsonParser.hpp"
#include "sqlManager.hpp"
using json = nlohmann::json;
int main(int argc, const char * argv[]) {
// Connect to QuestDb argv[1]
DatabaseConnection db(argv[1], 8812, "qdb", "admin", "quest");
// Load strategy from Base64 argv[2]
JsonParser::parseConfigurationFromBase64(argv[2]);
std::vector<PriceData> priceData = SqlManager::getInitialPriceData(db);
// Convert timestamp to readable format for debugging
auto timeT = std::chrono::system_clock::to_time_t(priceData[0].timestamp);
std::cout << "Timestamp: " << std::put_time(std::localtime(&timeT), "%Y-%m-%d %H:%M:%S") << std::endl;
auto tradeManager = TradeManager::getInstance();
// Open a trade
std::string tradeId = tradeManager->openTrade(1.2345, 100000, true);
std::cout << "Opened trade: " << tradeId << std::endl;
// Review account
size_t openTrades = tradeManager->reviewAccount();
std::cout << "Number of open trades: " << openTrades << std::endl;
// Close trade
bool closed = tradeManager->closeTrade(tradeId);
std::cout << "Trade closed: " << (closed ? "yes" : "no") << std::endl;
return 0;
}