Skip to content

Instantly share code, notes, and snippets.

@libasoles
Last active April 30, 2018 19:38
Show Gist options
  • Save libasoles/211409cd0c58e6b46950e971394a5f3b to your computer and use it in GitHub Desktop.
Save libasoles/211409cd0c58e6b46950e971394a5f3b to your computer and use it in GitHub Desktop.
Calculo de ganancia aproximada en cryptomkt según ticker actual
/******************************************************
*
* Calcula beneficio cada x segundos
*
* Este script solo funciona en la consola del navegador
* en cryptomkt.com
*
* init: se ejecuta una sola vez
* update: se ejecuta cada x segundos
*
* config \
* config.interval: cantidad de segundos de espera
*
* Datos disponibles en la api interna de cryptomkt:
*
* window.balances
*
* window.orders
*
* window.board \
* window.board.ETHARS
* window.board.XMLARS
*
*******************************************************/
(()=>{
var investment = 7200 // en moneda corriente ($)
// *************************** //
// *** logic ***************** //
// *************************** //
function init() {
// balance moneda corriente
let balance = helpers.getBalance(config.base)
let available = parseFloat(balance.disponible).toFixed(2)
console.log(`${config.base} balance: ${available} ${config.base}`)
}
function update() {
let profit
for(const coin of config.coins) {
profit = calculateProfit(coin, investment)
const msg = `${coin} profit: ${profit} ${config.base}`
if(profit >= config.minProfit) {
helpers.notify( 'Oportunidad spread', msg )
}
console.log(msg)
}
console.log('---')
}
/**
* Calcula ganancia aproximada segun ticker actual
*/
function calculateProfit(coin, investment) {
let {bid, ask} = helpers.getTicker(coin)
let profit = helpers.calculateProfit(bid, ask, investment)
return profit
}
// *************************** //
// *** config **************** //
// *************************** //
const config = {
fee: 1.006, // aprox
coins: ['ETH', 'XLM'],
base: 'ARS',
interval: 5, // segundos
notifications: {
logo: 'https://www.cryptomkt.com/static/principal/img/xcrypto-logo-mini.png.pagespeed.ic.oEbyJO3iOB.webp'
},
minProfit: 100
}
// *************************** //
// *** functions ************* //
// *************************** //
const helpers =
{
calculateProfit: (bid, ask, investment) => {
let amount_crypto = (investment / bid) / config.fee
let new_balance = (amount_crypto * ask) / config.fee
let profit = new_balance - investment
return profit.toFixed(2)
},
getTicker: (coin = 'ETH') => {
const ticker = window.board[coin+config.base]
return {
bid: ticker.BID,
ask: ticker.ASK,
spread: ticker.ASK - ticker.BID
}
},
getBalance: (currency = 'ARS') => {
return window.balances.find(x=>x.currency_name === currency)
},
notify: (message, title = '', link = null) => {
if (Notification.permission === "granted") {
if(typeof this.notification !== 'undefined') {
this.notification.close()
}
this.notification = new Notification(title, {
icon: config.notifications.logo,
body: message,
});
if(link) {
this.notification.onclick = () => {
window.open(link);
};
}
}
}
}
init()
update()
setInterval(()=>update(), config.interval*1000)
return '_';
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment