Coinguide Update: A cryptocurrency trade guide (Cryptopia BTC Market data now available)
Project Overview
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.
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:
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
Thank you for your contribution. Like what I said in your last contribution, there are lots of code duplication such as
updateBuy
andupdateTotalBuy
.I strongly suggest that you refactor your code first and use PHP template framework to avoid mixing presentation and logics.
Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks @justyy
I appreciate your recommendations. I was planning on completing some implementations before moving code to a PHP framework. But I guess I'll have to do the later first.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
More insights @profchydon, all the best.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @profchydon! Thank you for the great work you've done!
We're already looking forward to your next contribution!
Fully Decentralized Rewards
We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.
Utopian Witness!
Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.
Want to chat? Join us on Discord https://discord.me/utopian-io
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit