Create your own Crypto Apps/Bots with Coingecko's Free API - includes Twitter bot and Android app examples

Create your own Crypto Apps/Bots with Coingecko's Free API - includes Twitter bot and Android app examples

By Holdman | Crypto Automations | 14 Mar 2021

As I was analysing APIs to get the coin prices and statistics, I found that Coingecko provides this service FREE without any keys or logins necessary.

This can allows us to really automate stuff in crypto like creating portfolio watchers, alerts, automatic tweets, price checkers, discord bots, etc.

Examples of stuff you can do with the API:

Android App: WOW - A dogecoin price tracker

See it live

Relevant code using API (Java/Android)

refreshCoin('dogecoin', 'eur');
public void refreshCoin(String coin_id, String coin_currency) {
                .load(""+ coin_id)
                .setCallback(new FutureCallback<JsonObject>() {
                    public void onCompleted(Exception e, JsonObject result) {
                        if(result!=null && result.getAsJsonObject("market_data")!=null) {
                            JsonObject marketData = result.getAsJsonObject("market_data");
                            JsonObject currentPrice = marketData.getAsJsonObject("current_price");

                            JsonObject ath = marketData.getAsJsonObject("ath");
                            String price_change_percentage_24h = marketData.get("price_change_percentage_24h").toString();
                            String price_change_percentage_7d = marketData.get("price_change_percentage_7d").toString();
                            String price_change_percentage_30d = marketData.get("price_change_percentage_30d").toString();
                            String price_change_percentage_1y = marketData.get("price_change_percentage_1y").toString();
                            String CurrentPriceInCurrency = Float.parseFloat(currentPrice.get(coin_currency).toString())
                            String athWithInCurrency = Float.parseFloat(ath.get(coin_currency).toString());

API URL used 


Twitter Bot: All time High alerts (every 15min)


See it live 

Relevant code using API (PHP/TwitterAPI)


//download here:
use DG\Twitter\Twitter;

//Display errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

//You can get this info here:
$consumerKey = 'XXX';
$consumerSecret = 'XXX';
$accessToken = 'XXX';
$accessTokenSecret = 'XXX';

$twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);

$coinsToAnalyze = array('bitcoin', 'dogecoin', 'ethereum', 'chainlink', 'polkadot', 'cardano', 'stellar', 'ripple', 'binancecoin', 'litecoin', 'filecoin', 'vechain','algorand','the-graph');

foreach($coinsToAnalyze as $coin) {
    $coinData = analyzeDataFromAPI(getDataFromCoin($coin));
    //Should be the same as cronjob (every 15 min)
    if(wasAllTimeHighLast('-15 minutes', $coinData['ath_date'])) {
        $msg = "🙃 New all time high on ".'$'.strtoupper($coinData['symbol'])." $".$coinData['ath'];
        tweet($twitter, $msg);
    sleep (1); //let API sleep a bit

function wasAllTimeHighLast($dateIntervalString, $athOfTheCoinDate) {
    $date_last_x_min = strtotime($dateIntervalString);
    $ath_coin = strtotime($athOfTheCoinDate);
    return $ath_coin>$date_last_x_min;

function analyzeDataFromAPI($apiObj) {
    return array('symbol' => $apiObj->symbol,
                 'current_price' => $apiObj->market_data->current_price->usd,
                 'ath' => $apiObj->market_data->ath->usd,
                 'ath_change_percent' => $apiObj->market_data->ath_change_percentage->usd,
                 'ath_date' => $apiObj->market_data->ath_date->usd,
                 'price_change_percentage_24h' => $apiObj->market_data->price_change_percentage_24h,
                 'price_change_percentage_7d' => $apiObj->market_data->price_change_percentage_7d,
                 'price_change_percentage_14d' => $apiObj->market_data->price_change_percentage_14d,
                 'price_change_percentage_30d' => $apiObj->market_data->price_change_percentage_30d,
                 'price_change_percentage_60d' => $apiObj->market_data->price_change_percentage_60d,
                 'price_change_percentage_200d' => $apiObj->market_data->price_change_percentage_200d,
                 'price_change_percentage_1y' => $apiObj->market_data->price_change_percentage_1y,

function tweet($twitter, $msg) {
    try {
    } catch (DG\Twitter\Exception $e) {
        echo "Error: ", $e->getMessage();

function getDataFromCoin($coinname) {
    $url = '' . $coinname;
    return json_decode(curl($url));

function curl($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    return $output;

API URL used 

Future projects

  • Discord Bot with price alerts and on demand requests
  • Telegram Bot
  • Image Generation

How do you rate this article?




I'm a fullstack developer with a strong passion for automation and crypto (especially $BAN)

Crypto Automations
Crypto Automations

Join me in my adventure on creating automations, bots and miners for crypto currencies

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.