Member-only story

Using C++ code to retrieve the eur/usd value from finance.yahoo

Luiggi Trejo
2 min readDec 29, 2022

--

Photo by Jaimie Harmsen on Unsplash

Yahoo used to be “The” search engine years ago, before the advent of Google. In order to survive, Yahoo has adapted and transformed itself into an information company. I had a subscription for a stock screening service they offered, but it was ditched some 5 years ago.

However, it offers a treasure chest of free data: one can access it in a manual or programmatic fashion, and play with it in endless trading simulations. In this piece, my dear reader, you can find a C++ coding example for retrieving such data, in this particular case the eur/usd pair values.

To retrieve eur/usd values from finance.yahoo.com, you can use the libcurl library to send an HTTP request to the Yahoo Finance API and receive a response with the current exchange rate. Here is an example of how you can do this in C++:

// 2022 - JL Trejo

#include <iostream>
#include <string>
#include <curl/curl.h>

int main()
{
// Set up the curl library
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
// Set the URL for the Yahoo Finance API
std::string url = "https://finance.yahoo.com/quote/EUR=X?p=EUR=X";
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

// Send the request and receive the response
res = curl_easy_perform(curl);
if(res !=…

--

--

Luiggi Trejo
Luiggi Trejo

No responses yet