Bitcoin Forum

Economy => Services => Topic started by: tomaso88 on March 13, 2018, 10:46:25 AM



Title: WTB simple C++ code.
Post by: tomaso88 on March 13, 2018, 10:46:25 AM
Hi,

I'm looking for someone to program me a very simple code using acx.io api and send me the source code.

Requirements.
1. 1 file.
2. has to be in C++
3. All it has to do is print the price of btc every minute.

I will pay in BTC, ltc or eth. Please reply with your offers.


Title: Re: WTB simple C++ code.
Post by: deisik on March 13, 2018, 06:59:08 PM
Hi,

I'm looking for someone to program me a very simple code using acx.io api and send me the source code.

Requirements.
1. 1 file.
2. has to be in C++
3. All it has to do is print the price of btc every minute.

I will pay in BTC, ltc or eth. Please reply with your offers.

What framework should be used (e.g. Qt, VS) or it should be a console only application? And which system is the code supposed to be run on (e.g. Windows, Linux)?


Title: Re: WTB simple C++ code.
Post by: starmyc on March 15, 2018, 03:00:03 PM
Hi,

I'm looking for someone to program me a very simple code using acx.io api and send me the source code.

Requirements.
1. 1 file.
2. has to be in C++
3. All it has to do is print the price of btc every minute.

I will pay in BTC, ltc or eth. Please reply with your offers.

Hi,
Is C++ using curl is OK ?

If so:

Code:
#include <curl/curl.h>
#include <unistd.h>

#include <iostream>

using namespace std;

// url is https://acx.io/api/v2/tickers/btcaud.json

static size_t catch_body(void *buffer, size_t size, size_t nmemb, void *stream)
{
  string s = string((char*)buffer);
  string delim = "\"";
  int idx = -1;

  size_t pos = 0;
  string token;
  while ((pos = s.find(delim)) != string::npos) {
    token = s.substr(0, pos);
    if (token == "last")
      idx = 0;

    if (idx != -1)
      idx ++;

    if (idx == 3)
      cout << token << endl;
   
    s.erase(0, pos + delim.length());
  }

  return size * nmemb;
}

void run()
{
  CURL *curl;
  CURLcode res;
 
  curl_global_init(CURL_GLOBAL_DEFAULT);
 
  curl = curl_easy_init();
 
  if (!curl) {
      cerr << "Could not initialize curl" << endl;
      return;
  }
 
  curl_easy_setopt(curl, CURLOPT_URL, "https://acx.io/api/v2/tickers/btcaud.json");
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, catch_body);
  // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
  res = curl_easy_perform(curl);
  if (CURLE_OK != res) {
    cerr << "Error while querying acx.io: " << res << endl;
  }

  curl_easy_cleanup(curl);
}

int main(void)
{
  while(true) {
    run();
    sleep(60);
  }
 
  return 0;
}

Compile it & run it:

Code:
g++ -o go-acx go.cpp   -lcurl && ./go-acx
10806.78
10806.78
...

Don't forget to tip me !!!
Cheers.