Coinguide Update: A cryptocurrency trade guide
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 previous update here
New Features:
Coinguide nows make update every 5 mins and perform an algorithm on the fetched resource from poloniex API and the resource already stored in the database. Every 5mins, a fresh request is made to get recent data. Below is a video of making a new request and displaying a fresh data based on the algorithm used.
"Who's gaining the shift" feature: Now traders can see information about trade trends, which coin seem to be getting the most attention now.
Top Coin:
This features gives a visual representation of the coin having the most buy orders the last time data was fetched (5mins ago) and also inform traders whether the coin increased or decreased in buy order from the last data gotten.
Current Top Coin:
Even though a coin has the greater number of buy orders, we can't ascertain that it is the current trending coin in terms of buys, this features informs traders the current top coin based on the maximum percentage difference of buy order history.
Example: from the gif above, we can see that 5mins ago STR had 117 total buy orders and 5mins later it had 107 total buy order. Also XMR had 34 buy orders 5 mins ago but increased to 42 total buy orders 5 mins later. Even though buy orders for STR seems greater than XMR coinguide ranks XMR as the current top coin simply because of the percentage difference in the buy order 5mins and buy order 5 mins later.
How I implemented this.
- I added the header helper function to make a request every 120 seconds. After this request is made, i queried the database to get the time of last request and minus it from the current time and if the result is greater than 5 minutes then the process.php script is run to perform the calculation using the recently fetched data and the data stored in the database.
<?php
header("Refresh: 120; url=index.php");
include 'include/main.php';
$last_time = selectPastTime();
$last_time = $last_time[0]['date_saved'];
$now = time();
$diff = $now - $last_time;
if ($diff > 300) {
redirect('process.php');
}
?>
The process.php file is run every five minutes.
<?php
ob_start();
/**
** Algorithm for this page
** Delete records in previous table
** Fetch records in current table
** Move records from current table to previous table
** Delete records in current table
** Process POloniex API
** Save processed data in current table
**/
require_once 'function/functions.php';
// Lets Delete all records in the previous table
deletePreviousRecords();
// Reset table ID
ResetTableID ();
// Lets fetch records from current so we can move it to the previous table
$records = fetchRecordsFromCurrent ();
foreach ($records as $key => $record) {
$coin = $record['coin'];
$currencypair = $record['currencypair'];
$buy = $record['buy'];
$sell = $record['sell'];
$date_saved = $record['date_saved'];
// We can now move the records from current table to previous table to enable us delete all record in current table
$update_previous_table = updatePreviousTable ($coin, $currencypair, $buy, $sell, $date_saved );
}
if ($update_previous_table) {
// Lets Delete all records in the current table since we have moved them to the previous table
deleteCurrentRecords ();
/**
** Call the poloniex API to get all coins available
**
**/
$coins = file_get_contents('https://poloniex.com/public?command=returnCurrencies');
// Convert JSOn resource to object
$coins = json_decode($coins);
// Convert object to array
$coins = json_decode(json_encode($coins) , TRUE);
//Get current time in UNIX timestamp
$now = time();
//Lets go back 5mins
$then = $now - 300;
// Loop through coins array to get details for each coin
foreach ($coins as $key => $coin) {
$coin_delisted = $coin['delisted'];
$coin_disabled = $coin['disabled'];
// drop delisted coins
if ((!$coin_delisted)) {
// drop disabled coins
if ((!$coin_disabled)) {
// Get the coin abbreviation example Bitcoin (BTC), Ethereum (ETH)
$currency = $key;
// Form a currency pair with the abbreviation example BTC_ETH
$currencypair = "BTC_".$key;
//Get coin name
$coin_name = $coin['name'];
/**
** Call the poloniex API to get all trade history for the currency pair
**
**/
$trades = file_get_contents("https://poloniex.com/public?command=returnTradeHistory¤cyPair=$currencypair&start=$then&end=$now");
// Convert JSOn resource to object
$trades = json_decode($trades);
// Convert object to array
$trades = json_decode(json_encode($trades) , TRUE);
// Initialize trade buy and trade sell
$trade_buy = 0;
$trade_sell = 0;
// Loop through trade history to get details for each currency pair
foreach ($trades as $key => $trade) {
// Check if the type of trade done is a buy or a sell
if ($trade['type'] == "buy") {
// if trade is buy increment trade_buy
$trade_buy = $trade_buy + 1;
}elseif ($trade['type'] == "sell") {
// if trade is sell increment trade_sell
$trade_sell = $trade_sell + 1;
}
}
$total_volume += $trade_buy;
$update_current_table = updateCurrentTable ($coin_name, $currency, $trade_sell, $trade_buy, $now);
$update_current_buy = updateCurrentBuyInPreviousTable ($trade_sell, $total_volume, $currency);
}
}
}
}else {
}
redirect('index.php');
?>
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 coinexchange. 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.
Site can be accessed temporarily on
https://coinguide.000webhostapp.com/
Posted on Utopian.io - Rewarding Open Source Contributors