Coinguide Update: A cryptocurrency trade guide (HitBTC market data now available)
Coinguide Update: A cryptocurrency trade guide (HitBTC 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 poloniex 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
New Features
Coinguide now has market data from HitBTC exchange. So the big update is HitBTC market data is now available on coinguide. Traders can now view HitBTC market data on coinguide as well as market data from other exchanges.
How I implemented this.
I started by fetching all available coins from HitBTC using the API endpoint https://api.hitbtc.com/api/2/public/currency
, then i got the market summary for each for the coins using the endpoint https://api.hitbtc.com/api/2/public/trades/'.$currencypair
I analyzed and processed the data to produce the table above
function.php
<?php
function getCoins () {
$coins = file_get_contents('https://api.hitbtc.com/api/2/public/currency');
// Convert JSOn resource to object
$coins = json_decode($coins);
// Convert object to array
$coins = json_decode(json_encode($coins) , TRUE);
return $coins;
}
function getSummary () {
$coins = file_get_contents('https://api.hitbtc.com/api/2/public/symbol');
// 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://api.hitbtc.com/api/2/public/trades/'.$currencypair);
// 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) {
require '../database/database.php';
$query = $pdo->prepare('INSERT into hibtc (coin, symbol) values (:coin, :symbol) ');
$query->bindParam(':coin' , $coin);
$query->bindParam(':symbol' , $symbol);
if ($query->execute()) {
return true;
}else {
return false;
}
}
function updateTable ($symbol, $currencypair)
{
require '../database/database.php';
$query = $pdo->prepare('UPDATE hibtc SET currencypair = :currencypair WHERE symbol = :symbol');
$query->bindParam(':currencypair' , $currencypair);
$query->bindParam(':symbol' , $symbol);
if ($query->execute()) {
return true;
}else {
return false;
}
}
function updateBuy ($buy, $currencypair)
{
require '../database/database.php';
$query = $pdo->prepare('UPDATE hibtc SET current_buy = :buy WHERE currencypair = :currencypair');
$query->bindParam(':currencypair' , $currencypair);
$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 hibtc SET total_buy_trade = :total_buy_trade');
$query->bindParam(':total_buy_trade' , $total_buy_trade);
if ($query->execute()) {
return true;
}else {
return false;
}
}
function getAll ()
{
require '../database/database.php';
$query = $pdo->prepare('SELECT * FROM hibtc ORDER BY buy DESC LIMIT 30');
if ($query->execute()) {
$data = $query->fetchAll(PDO::FETCH_ASSOC);
}
return $data;
}
?>
I processed the fetched data in the process.php page
<?php
require_once '../function/hitbtc.php';
$coins = getCoins();
foreach ($coins as $key => $coin) {
if ($coin['delisted'] == false) {
$coin_name = $coin['fullName'];
$symbol = $coin['id'];
$save_data = saveData($coin_name , $symbol);
}
}
$summary = getSummary();
foreach ($summary as $key => $coins) {
if ($coins['quoteCurrency'] == "BTC") {
$symbol = $coins['baseCurrency'];
$currencypair = $coins['id'];
$update_data = updateTable ($symbol, $currencypair);
}
}
$all = getAll();
$total_buy_trade = 0;
foreach ($all as $key => $pair) {
$currencypair = $pair['currencypair'];
if (!empty($currencypair)) {
$trades = getBuy ($currencypair);
$buy = 0;
foreach ($trades as $key => $trade) {
if ($trade['side'] == "buy") {
$buy = $buy + 1;
}
}
$update = updateBuy ($buy, $currencypair);
$total_buy_trade = $total_buy_trade + $buy;
}
}
updateTotalBuy ($total_buy_trade);
foreach ($all as $key => $value) {
$total_buy_trade = $total_buy_trade + $value['current_buy'];
}
//
updateTotalBuy ($total_buy_trade);
//
// ?>
Links to commits:
Please i will gladly welcome your suggestions and idea, or even an algorithm you think will suit this webapp better. I will be adding data soon from other exchanges like kraken and binance. I will have to check the algorithm again to see if it will be efficient enough to provide the right results when data comes in from other exchanges. Your suggestions are highly valued.
Posted on Utopian.io - Rewarding Open Source Contributors
https://steemit.com/@a-0-0
Than you for your contribution.
Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.
[utopian-moderator]
Hey @profchydon I am @utopian-io. I have just upvoted you!
Achievements
Utopian Witness!
Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x