Coinguide Update: A cryptocurrency trade guide (Cryptopia BTC Market data now available)

Words
321
Reading
2 min
9y
Listen to this post
~2 min

Coinguide Update: A cryptocurrency trade guide (Cryptopia BTC Market data now available)


Project Overview

coinlogo.png

COINGUIDE : a webapp that aims to guide crypto traders on the most popular Cryptocurrencies. It achieves this by fetching records from poloniex using their api, rating these records according to their buy orders.

Coinguide aims to keep traders informed about the popular coins (coins which the highest number of buy orders within a specific time range). A future goal of the project is to become a reliable platform that accurately ranks coins/tokens based on how much traders and buying a selling using a mathematical algorithms. Coinguide isn't a website that gives investors financial advise on which coin to buy or not, it simply gets the required data from crypto exchanges's api processes the data using an algorithm and tells users the coins gaining popularity and those loosing popularity.

Previous Update

Link to first update here

Link to second update here

Link to third update here

Link to fourth update here

Link to fifth update here

Link to sixth update here

Link to seventh update here

New Features

Coinguide now has market data from cryptopia exchange. Investors can now view cryptopia market data on coinguide as well as market data from other exchanges.

cryptopia.png

How I implemented this.

I started by fetching all available coins from cryptopia using the API endpoint https://www.cryptopia.co.nz/api/GetTradePairs , then i got the market summary for each for the coins using the endpoint https://www.cryptopia.co.nz/api/GetMarketHistory/'.$currencypair.'/100

I analyzed and processed the data to produce the table above

<?php

function getCoins () {

    $coins = file_get_contents('https://www.cryptopia.co.nz/api/GetTradePairs');

    // Convert JSOn resource to object
    $coins = json_decode($coins);

    // Convert object to array
    $coins = json_decode(json_encode($coins) , TRUE);

    return $coins;

}

function getBuy ($currencypair) {

    $buy = file_get_contents('https://www.cryptopia.co.nz/api/GetMarketHistory/'.$currencypair.'/100');

    // Convert JSOn resource to object
    $buy = json_decode($buy);

    // Convert object to array
    $buy = json_decode(json_encode($buy) , TRUE);

    return $buy;

}

function saveData ($coin, $symbol, $currencypair) {

    require '../database/database.php';
    $query = $pdo->prepare('INSERT into cryptopia (coin, symbol, currencypair) values (:coin, :symbol, :currencypair) ');
    $query->bindParam(':coin' , $coin);
    $query->bindParam(':symbol' , $symbol);
    $query->bindParam(':currencypair' , $currencypair);

    if ($query->execute()) {

      return true;

    }else {

      return false;

    }

}


function getAll ()
{
    require '../database/database.php';
    $query = $pdo->prepare('SELECT * FROM cryptopia ORDER BY buy DESC LIMIT 30');

    if ($query->execute()) {
      $data = $query->fetchAll(PDO::FETCH_ASSOC);
    }

      return $data;

}

function updateBuy ($buy, $symbol)
{
    require '../database/database.php';
    $query = $pdo->prepare('UPDATE cryptopia SET current_buy = :buy WHERE symbol = :symbol');
    $query->bindParam(':symbol' , $symbol);
    $query->bindParam(':buy' , $buy);
    if ($query->execute()) {
        return true;
    }else {
      return false;
    }
}

function updateTotalBuy ($total_buy_trade)
{
    require '../database/database.php';
    $query = $pdo->prepare('UPDATE cryptopia SET total_buy_trade = :total_buy_trade');
    $query->bindParam(':total_buy_trade' , $total_buy_trade);
    if ($query->execute()) {
        return true;
    }else {
      return false;
    }
}

I processed the data

<?php

require_once '../function/cryptopia.php';

$coins = getCoins();

$coins = $coins['Data'];

foreach ($coins as $key => $coin) {

    if ($coin['Status'] == "OK" && $coin['BaseSymbol'] == "BTC") {

      $coin_name = $coin['Currency'];
      $symbol = $coin['Symbol'];
      $currencypair = $coin['Label'];

      saveData ($coin_name, $symbol, $currencypair);

    }

}

$all = getAll();

$total_buy_trade = 0;

foreach ($all as $key => $pair) {

    $currencypair = $pair['symbol']."_BTC";

    if (!empty($currencypair)) {

      $trades = getBuy ($currencypair);

      $trades = $trades['Data'];

      $buy = 0;

      foreach ($trades as $key => $trade) {

          if ($trade['Type'] == "Buy") {

              $buy = $buy + 1;

          }

      }

      $update = updateBuy ($buy, $pair['symbol']);
      $total_buy_trade = $total_buy_trade + $buy;

    }

}

updateTotalBuy ($total_buy_trade);

foreach ($all as $key => $value) {

    $total_buy_trade = $total_buy_trade + $value['buy'];

}
//
updateTotalBuy ($total_buy_trade);

?>

Links to commits:

Link 1

Website can be temporarily accessed here

I will be adding Eth Market data from other exchanges whose BTC data is currently available before i move on to adding other exchanges which haven't been added.

I will also be refactoring the code base to improve code quality and software functionalities.



Posted on Utopian.io - Rewarding Open Source Contributors

Coinguide Update: A cryptocurrency trade guide (Cryptopia BTC Marke... | Ecency