Skip to content

Latest commit

 

History

History

documentation

Documentation resources for the library and CoinGecko's API.


Introduction

CoinGecko's source code follows an object.memberObject.memberObjectMethod() code structure (with the exception of ping) like below:

main.cpp

#include "parentClass.h"

int main() {
  parentClass object;
  object.memberObject1.memberObjectMethod();
  object.memberObject2.memberObjectMethod();
  return 0;
}

parentClass.h

#include "childClass1.h"
#include "childClass2.h"

class parentClass {
  public: 
    childClass1 memberObject1;
    childClass2 memberObject2;
};



Examples

All functions (except ping) return a gecko::web::response struct upon completion. You can find the struct and its members below:

typedef struct response {
  std::string text;
  std::string response_code;
  std::string url;
  cpr::Response cURL_Object;
};

Below you can find a few quick examples using CoinGecko. For documentation regarding individual functions, refer to the appropriate folder above.

getBitcoinPrice.cpp -> obtains current price of Bitcoin in USD

#include "gecko.h"

int main() {
  // CoinGecko main class object
  gecko::api coinGecko;
  
  // check if CoinGecko API is online
  if (coinGecko.ping()) {
    // if online, get Bitcoin's most recent price in USD and print the JSON response
    std::cout << coinGecko.simple.getPrice("bitcoin", "usd").text << std::endl;
  } else {
    // if offline, print offline.
    std::cout << "CoinGecko offline!" << std::endl;
  }
  
  return 0;
}

getUSMeetups.cpp -> obtains cryptocurrency meetups in the United States

#include "gecko.h"

int main() {
  gecko::api coinGecko;
  
  if (coinGecko.ping()) {
    std::cout << coinGecko.events.getEvents("US", "Meetups").text << std::endl;
  } else {
    std::cout << "CoinGecko offline!" << std::endl;
  }
  
  return 0;
}

getContractHistoricalData.cpp -> obtains historical market data from contract address

#include "gecko.h"

int main() {
  gecko::api coinGecko;
  
  if (coinGecko.ping()) {
    std::cout << coinGecko.contract.getContractMarketHistory("ethereum", "0x4363e1485764d206b01ddc9ca121030585259f6f", "usd", "1").text << std::endl;
  } else {
    std::cout << "CoinGecko offline!" << std::endl;
  }
  
  return 0;
}