Created
May 1, 2018 15:43
-
-
Save libasoles/9ae54b10574261568b0edceb627b892c to your computer and use it in GitHub Desktop.
Creando ordenes limit con la api interna de cryptomkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************** | |
* | |
* Expone metodos para consultar balance y crear ordenes. | |
* | |
* Este script solo funciona en la consola del navegador | |
* en cryptomkt.com | |
* | |
* init: se ejecuta una sola vez | |
* update: se ejecuta cada x segundos | |
* | |
*******************************************************/ | |
const cryptoapi = (()=>{ | |
function init() { | |
const balance = helpers.getAvailableBalance() | |
console.log(`Balance disponible ${balance} ARS`) | |
} | |
function update() { | |
for(const coin of config.coins) { | |
const ticker = helpers.getTicker(coin) | |
console.log(coin, ticker) | |
} | |
console.log('---') | |
} | |
/** config */ | |
const config = { | |
base: 'ARS', | |
coins: ['ETH', 'XLM'], | |
interval: 5, // segundos | |
} | |
/** helpers */ | |
const helpers = { | |
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) | |
}, | |
getAvailableBalance: (currency = 'ARS') => { | |
return parseFloat(helpers.getBalance(currency).disponible).toFixed(2); | |
}, | |
createOrder(pair_name, order_type, price, amount) { | |
ajax_start() | |
$.post("/platform/market/" + pair_name + "/open_order", { | |
csrfmiddlewaretoken: $("[name='csrfmiddlewaretoken']").val(), | |
order_type: order_type, | |
price: price, | |
amount: amount | |
}).done(function(e) { | |
if ("success" == e.status) { | |
toastr.success(trans.order_ha_sido_abierta, trans.order_abierta); | |
get_market_data(); | |
try { | |
"buy" == order_type ? dataLayer.push({ | |
event: "ordenCompra" | |
}) : dataLayer.push({ | |
event: "ordenVenta" | |
}) | |
} catch (t) {} | |
} else toastr.error(e.message, trans.ha_ocurrido_error) | |
}).fail(function() { | |
toastr.error(trans.lo_lamentamos, trans.ha_ocurrido_error) | |
}).always(function() { | |
ajax_stop() | |
}) | |
}, | |
} | |
init() | |
update() | |
setInterval(update, config.interval * 1000) | |
/** | |
* API | |
*/ | |
return { | |
getAvailableBalance: helpers.getAvailableBalance, | |
createOrder: helpers.createOrder, | |
}; | |
})(); | |
// crear una orden de prueba por un valor tan bajo que no se va a ejecutar ;) | |
cryptoapi.createOrder('XLMARS', 'buy', 1, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment