-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (44 loc) · 1.63 KB
/
main.cpp
File metadata and controls
54 lines (44 loc) · 1.63 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
#include "ccapi_cpp/ccapi_session.h"
namespace ccapi {
Logger* Logger::logger = nullptr; // This line is needed.
class MyEventHandler : public EventHandler {
public:
void processEvent(const Event& event, Session* sessionPtr) override {
std::cout << "Received an event from session " << this->sessionPtrs.at(sessionPtr) << " on thread " << std::this_thread::get_id() << std::endl;
}
void setSessionPtrs(const std::map<Session*, std::string>& sessionPtrs) { this->sessionPtrs = sessionPtrs; }
private:
std::map<Session*, std::string> sessionPtrs;
};
} /* namespace ccapi */
using ::ccapi::MyEventHandler;
using ::ccapi::ServiceContext;
using ::ccapi::Session;
using ::ccapi::SessionConfigs;
using ::ccapi::SessionOptions;
using ::ccapi::Subscription;
using ::ccapi::toString;
int main(int argc, char** argv) {
SessionOptions sessionOptions_1;
SessionOptions sessionOptions_2;
SessionConfigs sessionConfigs_1;
SessionConfigs sessionConfigs_2;
MyEventHandler eventHandler;
ServiceContext serviceContext;
serviceContext.start();
Session session_1(sessionOptions_1, sessionConfigs_1, &eventHandler, nullptr, &serviceContext);
Session session_2(sessionOptions_2, sessionConfigs_2, &eventHandler, nullptr, &serviceContext);
eventHandler.setSessionPtrs({
{&session_1, "1"},
{&session_2, "2"},
});
Subscription subscription("bybit", "BTCUSDT", "MARKET_DEPTH");
session_1.subscribe(subscription);
session_2.subscribe(subscription);
std::this_thread::sleep_for(std::chrono::seconds(10));
session_1.stop();
session_2.stop();
serviceContext.stop();
std::cout << "Bye" << std::endl;
return EXIT_SUCCESS;
}