Skip to content

Instantly share code, notes, and snippets.

@thirdy
Last active May 29, 2017 00:27
Show Gist options
  • Save thirdy/d91e3249611e60603800c618847c3b44 to your computer and use it in GitHub Desktop.
Save thirdy/d91e3249611e60603800c618847c3b44 to your computer and use it in GitHub Desktop.
Bookmarklet for assisting buy and sell decisions in coins.ph
/* Copyright 2017 Vicente de Rivera III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Bookmarklet for coins.ph to assist in revealing important details about it's Buy and Sell prices.
To generate the bookmarklet:
1. Go to http://bookmarklets.org/maker/
2. Paste this code.
3. Drag n drop the link found in the bottom.
*/
var quotes = document.getElementsByClassName('quotes')[0];
var buyStr = quotes.children[0].innerText.split(" ")[1].replace(",","");
var buy = parseInt(buyStr);
var sellStr = quotes.children[2].innerText.split(" ")[1].replace(",","");
var sell = parseInt(sellStr);
var diff = buy - sell
var diffStr = "Difference: " + diff + " PHP";
var spread = (buy - sell) / sell;
var spreadStr = "Spread: " + (spread * 100).toFixed(2) + " %";
/*var breakEven = diff / buy;
var breakEvenStr = "To break even, you need BTC to go up " + (breakEven * 100).toFixed(2) + " %";*/
var breakEvenStr = "Remember to only sell at price " + buyStr + " PHP or higher."
quotes.appendChild(document.createTextNode(" ---> "));
quotes.appendChild(document.createTextNode(diffStr));
quotes.appendChild(document.createTextNode(" ---> "));
quotes.appendChild(document.createTextNode(spreadStr));
quotes.appendChild(document.createTextNode(" ---> "));
quotes.appendChild(document.createTextNode(breakEvenStr));
/*EXPERIMENT calling Gemini*/
function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
var geminiUSD = response.USD;
/* assume 1 USD = 50 PHP */
var geminiPHP = (response.USD * 50).toFixed(2);
var geminiPHPStr = geminiPHP + " PHP";
var geminiCPHpercentDiff = (buy - geminiPHP) / geminiPHP;
var geminiCPHpercentDiffStr = (geminiCPHpercentDiff * 100).toFixed(2) + " %";
quotes.appendChild(document.createTextNode(" --> "));
quotes.appendChild(document.createTextNode("Gemini: " + geminiPHPStr));
quotes.appendChild(document.createTextNode(" --> "));
quotes.appendChild(document.createTextNode("Gemini/CPH % Diff: " + geminiCPHpercentDiffStr));
}
}
var xhr = new XMLHttpRequest();
xhr.open('GET', "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD&e=Gemini", true);
xhr.onreadystatechange = processRequest;
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment