In order to pass these variables to a separate function, you may do something like this -
var calculateOrder = function (bid, ask, spread) {
// Use variables
}
function getSpread() {
poloniex.getTicker(function(err, data) {
if (err){
console.log('ERROR', err);
return;
}
var ask = data.BTC_LTC.lowestAsk;
var bid = data.BTC_LTC.highestBid;
var spread = ((ask - bid) / ask);
calculateOrder(bid, ask, spread);
});
}
You should always convert lowestAsk and highestBid to numbers before doing mathematical operations on them
var ask = Number(data.BTC_LTC.lowestAsk);
var bid = Number(data.BTC_LTC.highestBid);