-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccapi_runner.cpp
More file actions
37 lines (31 loc) · 1.15 KB
/
ccapi_runner.cpp
File metadata and controls
37 lines (31 loc) · 1.15 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
#include "pch.h"
#include "ccapi_cpp/ccapi_session.h"
#include <thread>
#include <iostream>
// Initialize the CCAPI logger.
namespace ccapi {
Logger* Logger::logger = nullptr;
}
void runCCAPISession() {
// 1) Create session options and configs.
ccapi::SessionOptions sessionOptions;
ccapi::SessionConfigs sessionConfigs;
// 2) Define an event handler.
class MyEventHandler : public ccapi::EventHandler {
public:
bool processEvent(const ccapi::Event& event, ccapi::Session* session) override {
std::cout << "Received event:\n"
<< event.toStringPretty(2, 2) << std::endl;
return true;
}
} eventHandler;
// 3) Create a session.
ccapi::Session session(sessionOptions, sessionConfigs, &eventHandler);
// 4) Construct a "get recent trades" request for Coinbase BTC-USD.
ccapi::Request request(ccapi::Request::Operation::GET_RECENT_TRADES, "coinbase", "BTC-USD");
request.appendParam({{"LIMIT", "1"}});
session.sendRequest(request);
// 5) Run the session briefly to receive data.
std::this_thread::sleep_for(std::chrono::seconds(5));
session.stop();
}