-
Notifications
You must be signed in to change notification settings - Fork 13
/
streaming.cpp
59 lines (45 loc) · 1.63 KB
/
streaming.cpp
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
/*
This is a demo app in C++ for streaming feature using OANDA open api and libcurl
*/
#include <curl/curl.h>
#include <iostream>
int main()
{
CURL *connection;
CURLcode code;
connection = curl_easy_init();
if (connection)
{
// Please update the following parameters with proper value
// [:domain] : use either fxpractice.oanda.com or fxtrade.oanda.com
// [:instruments] : feel free to subscribe more instruments (at most 10 instruments)
// [:accountId] : your account ID
code = curl_easy_setopt(connection, CURLOPT_URL, "https://<domain>/v1/quote?instruments=EUR_USD&accountId=<your account ID>");
if (code != CURLE_OK)
{
std::cout << "Failed to set URL" << std::endl;
}
struct curl_slist *headers = NULL;
// Headers
// [:access_token] : "Authorization: Bearer <your access token>"
headers = curl_slist_append(headers, "Authorization: Bearer <your access token>");
code = curl_easy_setopt(connection, CURLOPT_HTTPHEADER, headers);
if (code != CURLE_OK)
{
std::cout << "Failed to set headers" << std::endl;
}
code = curl_easy_setopt(connection, CURLOPT_SSL_VERIFYPEER, 0);
if (code != CURLE_OK)
{
std::cout << "Failed to disable 'verify the peer'" << std::endl;
}
code = curl_easy_perform(connection);
if (code != CURLE_OK)
{
std::cout << "Failed to perform connection" << std::endl;
}
curl_easy_cleanup(connection);
curl_slist_free_all(headers);
}
return 0;
}