Created
May 1, 2018 18:21
-
-
Save libasoles/b0f1d744316aeed13a4eb22cc5971ab0 to your computer and use it in GitHub Desktop.
Exposición de metodos para crear stopLoss y takeProfit
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 crear stopLoss y takeProfit. | |
* | |
* Este script solo funciona en la consola del navegador | |
* en cryptomkt.com | |
* | |
*******************************************************/ | |
const cryptoapi = (()=>{ | |
function init() {} | |
function update() {} | |
/** config */ | |
const config = { | |
base: 'ARS', | |
interval: 5, // segundos | |
limits: {}, | |
} | |
/** 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() | |
}) | |
}, | |
/** | |
* type: stopLoss|takeProfit | |
*/ | |
setLimit(type, coin, price) { | |
if(typeof config.limits[coin] === 'undefined') { | |
config.limits[coin] = {} | |
} | |
config.limits[coin][type] = price | |
}, | |
getLimits() { | |
return config.limits | |
}, | |
setStopLoss(coin, price) { | |
helpers.setLimit('stopLoss', coin, price) | |
}, | |
setTakeProfit(coin, price) { | |
helpers.setLimit('takeProfit', coin, price) | |
}, | |
} | |
init() | |
update() | |
setInterval(update, config.interval * 1000) | |
/** | |
* API | |
*/ | |
return { | |
getAvailableBalance: helpers.getAvailableBalance, | |
createOrder: helpers.createOrder, | |
setStopLoss: helpers.setStopLoss, | |
setTakeProfit: helpers.setTakeProfit, | |
getLimits: helpers.getLimits, | |
}; | |
})(); | |
cryptoapi.setStopLoss('XLM', 9.56); | |
cryptoapi.getLimits(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment