Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// SlickTrader - Production Trading System
2//
3// This is the main executable for the SlickTrader algorithmic trading framework.
4// It demonstrates the complete system including:
5// - TradingEngine initialization and lifecycle management
6// - Multi-broker support
7// - Strategy registration and execution
8// - Position tracking and PnL calculation
9// - Risk management
10// - Web API for monitoring
11//
12// Usage:
13// ./slick-trader config.json
14//
15// Required environment variables (for order submission):
16// COINBASE_API_KEY - Coinbase API key
17// COINBASE_API_SECRET - Coinbase API secret
18
19#include <slick/logger.hpp>
21
22#include <atomic>
23#include <chrono>
24#include <csignal>
25#include <iostream>
26#include <thread>
27
28#ifdef _WIN32
29#include <windows.h>
30#endif
31
32using namespace slick::trader;
33
34std::atomic_bool running{true};
35
36void signal_handler(int signal) {
37 LOG_INFO("Received signal {}, shutting down gracefully...", signal);
38 running.store(false, std::memory_order_release);
39}
40
41int main(int argc, char* argv[]) {
42 // Check command line arguments
43 if (argc < 2) {
44 std::cout << "Usage: " << argv[0] << " <config.json>" << std::endl;
45 return 1;
46 }
47
48 std::string config_path = argv[1];
49
50 auto &engine = TradingEngine::instance();
51 if (!engine.initialize(config_path)) {
52 LOG_ERROR("TradingEngine failed to initialize");
53 return 1;
54 }
55
56 engine.start();
57
58 // Register signal handlers after libraries have initialized
59 // (Some libraries may override signal handlers during initialization)
60 std::signal(SIGINT, signal_handler);
61 std::signal(SIGTERM, signal_handler);
62
63 // ========================================================================
64 // System Ready
65 // ========================================================================
66 LOG_INFO("");
67 LOG_INFO("========================================================================");
68 LOG_INFO(" SlickTrader {} is now RUNNING...", SLICK_TRADER_VERSION);
69 LOG_INFO("========================================================================");
70 LOG_INFO("");
71 LOG_INFO("Press Ctrl+C to shutdown gracefully");
72 LOG_INFO("");
73
74 // ========================================================================
75 // Main Event Loop
76 // ========================================================================
77 while (running.load(std::memory_order_relaxed)) {
78 std::this_thread::sleep_for(std::chrono::milliseconds(100));
79 }
80
81 // ========================================================================
82 // Graceful Shutdown
83 // ========================================================================
84 LOG_INFO("");
85 LOG_INFO("========================================================================");
86 LOG_INFO(" Initiating Graceful Shutdown...");
87 LOG_INFO("========================================================================");
88
89 engine.shutdown();
90
91 LOG_INFO("");
92 LOG_INFO("========================================================================");
93 LOG_INFO(" SlickTrader Shutdown Complete");
94 LOG_INFO("========================================================================");
95
96 return 0;
97}
static TradingEngine & instance()
int main(int argc, char *argv[])
Definition main.cpp:41
std::atomic_bool running
Definition main.cpp:34
void signal_handler(int signal)
Definition main.cpp:36