-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (70 loc) · 2.62 KB
/
main.cpp
File metadata and controls
89 lines (70 loc) · 2.62 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <thread>
#include <latch>
#include <chrono>
#include <mutex>
#include "src/util/spsc_queue.h"
#include <boost/lockfree/spsc_queue.hpp>
#include <gtest/gtest.h>
#include "src/client/ws_order_book_client.h"
#include "src/trading/feature_engine.h"
#include "src/trading/trading_engine.h"
using namespace std::literals::chrono_literals;
std::latch latch(2);
std::mutex cout_mutex;
struct X {
int x;
};
template<typename T>
using QueueT = util::SpscQueue<T>;
const int F = 10;
const int N = 100000;
const int M = F * N;
auto consumeFunction(QueueT<X> &lfq) {
latch.arrive_and_wait();
size_t count{0};
auto start = std::chrono::high_resolution_clock::now();
while (count < M) {
X item{};
if (lfq.pop(item)) count++;
}
auto end = std::chrono::high_resolution_clock::now(); // End time
std::chrono::duration<double, std::micro> duration = end - start; // Measure time in microseconds
cout_mutex.lock();
std::cout << "consumed " << count << " items, duration [micros] = " << duration.count() << ", tps="
<< (double) M / (duration.count() / 1000000) << std::endl;
cout_mutex.unlock();
}
int main(int argc, char *argv[]) {
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]).find("--gtest") == 0 || std::string(argv[i]) == "--run_tests") {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
}
util::SpscQueue<client::WsOrderBookClient::WsBestBidBestAskMsg> incoming_order_book_updates_queue(10000);
util::SpscQueue<client::WsOrderEntryClient::WsOrderEntryReqMsg> outgoing_order_entry_req_queue(10000);
util::SpscQueue<client::WsOrderEntryClient::WsOrderEntryResMsg> incoming_order_entry_res_queue(10000);
client::WsOrderBookClient ws_order_book_client("wss://api.gemini.com/v2/marketdata",
incoming_order_book_updates_queue);
ws_order_book_client.start();
client::WsOrderEntryClient ws_order_entry_client("https://api.gemini.com", outgoing_order_entry_req_queue,
incoming_order_entry_res_queue,
"key", "secret");
ws_order_entry_client.start();
trading::FeatureEngine feature_engine;
trading::OrderManager order_manager(outgoing_order_entry_req_queue);
trading::MarketMaker market_maker(order_manager, feature_engine);
trading::TradingEngine trading_engine(
feature_engine,
order_manager,
market_maker,
incoming_order_book_updates_queue,
incoming_order_entry_res_queue
);
trading_engine.start();
while (true) {
std::this_thread::sleep_for(10ms);
}
return 0;
}