More market fixes

-Fixed a bug with the freiexchange pair volume value when paired with LTC
-Added a default value of zero for many of the fields for each market in the event that the data returned for a particular field is not numeric
This commit is contained in:
Joe Uhren
2023-10-27 19:29:01 -06:00
parent 74ca66d44e
commit 9392187eed
8 changed files with 127 additions and 127 deletions
+18 -18
View File
@@ -33,14 +33,14 @@ function get_summary(coin, exchange, api_error_msg, cb) {
else {
try {
const summary = {
'high': parseFloat(tic_body.ticker.high),
'low': parseFloat(tic_body.ticker.low),
'volume': parseFloat(tic_body.ticker.amount),
'volume_btc': parseFloat(tic_body.ticker.volume),
'bid': parseFloat(order_body != null && order_body.bids != null && order_body.bids.length > 0 ? order_body.bids[0].price : 0),
'ask': parseFloat(order_body != null && order_body.asks != null && order_body.asks.length > 0 ? order_body.asks[0].price : 0),
'last': parseFloat(tic_body.ticker.last),
'change': parseFloat(tic_body.ticker.price_change_percent.toString().replace('%', ''))
'high': parseFloat(tic_body.ticker.high) || 0,
'low': parseFloat(tic_body.ticker.low) || 0,
'volume': parseFloat(tic_body.ticker.amount) || 0,
'volume_btc': parseFloat(tic_body.ticker.volume) || 0,
'bid': parseFloat(order_body != null && order_body.bids != null && order_body.bids.length > 0 ? order_body.bids[0].price : 0) || 0,
'ask': parseFloat(order_body != null && order_body.asks != null && order_body.asks.length > 0 ? order_body.asks[0].price : 0) || 0,
'last': parseFloat(tic_body.ticker.last) || 0,
'change': parseFloat(tic_body.ticker.price_change_percent.toString().replace('%', '')) || 0
};
return cb(null, summary);
@@ -74,8 +74,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.length; t++) {
trades.push({
ordertype: body[t].taker_type.toString().toUpperCase(),
price: parseFloat(body[t].price),
quantity: parseFloat(body[t].amount),
price: parseFloat(body[t].price) || 0,
quantity: parseFloat(body[t].amount) || 0,
timestamp: parseInt(body[t].created_at)
});
}
@@ -107,15 +107,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.bids.length; b++) {
buys.push({
price: parseFloat(body.bids[b][0]),
quantity: parseFloat(body.bids[b][1])
price: parseFloat(body.bids[b][0]) || 0,
quantity: parseFloat(body.bids[b][1]) || 0
});
}
for (let s = 0; s < body.asks.length; s++) {
sells.push({
price: parseFloat(body.asks[s][0]),
quantity: parseFloat(body.asks[s][1])
price: parseFloat(body.asks[s][0]) || 0,
quantity: parseFloat(body.asks[s][1]) || 0
});
}
@@ -148,10 +148,10 @@ function get_chartdata(coin, exchange, api_error_msg, cb) {
for (let c = 0; c < body.length; c++)
chartdata.push([
parseInt(body[c][0]) * 1000,
parseFloat(body[c][1]),
parseFloat(body[c][2]),
parseFloat(body[c][3]),
parseFloat(body[c][4])
parseFloat(body[c][1]) || 0,
parseFloat(body[c][2]) || 0,
parseFloat(body[c][3]) || 0,
parseFloat(body[c][4]) || 0
]);
return cb(null, chartdata);
+17 -17
View File
@@ -33,13 +33,13 @@ function get_summary(coin, exchange, api_error_msg, cb) {
else {
try {
const summary = {
'high': parseFloat(sum_body.high),
'low': parseFloat(sum_body.low),
'volume': parseFloat(sum_body.volume),
'bid': parseFloat(tic_body.bidRate),
'ask': parseFloat(tic_body.askRate),
'last': parseFloat(tic_body.lastTradeRate),
'change': parseFloat(sum_body.percentChange)
'high': parseFloat(sum_body.high) || 0,
'low': parseFloat(sum_body.low) || 0,
'volume': parseFloat(sum_body.volume) || 0,
'bid': parseFloat(tic_body.bidRate) || 0,
'ask': parseFloat(tic_body.askRate) || 0,
'last': parseFloat(tic_body.lastTradeRate) || 0,
'change': parseFloat(sum_body.percentChange) || 0
};
return cb(null, summary);
@@ -73,8 +73,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.length; t++) {
trades.push({
ordertype: body[t].takerSide,
price: parseFloat(body[t].rate),
quantity: parseFloat(body[t].quantity),
price: parseFloat(body[t].rate) || 0,
quantity: parseFloat(body[t].quantity) || 0,
timestamp: parseInt(new Date(body[t].executedAt).getTime() / 1000)
});
}
@@ -106,15 +106,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.bid.length; b++) {
buys.push({
price: parseFloat(body.bid[b].rate),
quantity: parseFloat(body.bid[b].quantity)
price: parseFloat(body.bid[b].rate) || 0,
quantity: parseFloat(body.bid[b].quantity) || 0
});
}
for (let s = 0; s < body.ask.length; s++) {
sells.push({
price: parseFloat(body.ask[s].rate),
quantity: parseFloat(body.ask[s].quantity)
price: parseFloat(body.ask[s].rate) || 0,
quantity: parseFloat(body.ask[s].quantity) || 0
});
}
@@ -149,10 +149,10 @@ function get_chartdata(coin, exchange, api_error_msg, cb) {
if (new Date(body[c].startsAt).getTime() / 1000 > start && (c % 3) == 0)
chartdata.push([
parseInt(new Date(body[c].startsAt).getTime()),
parseFloat(body[c].open),
parseFloat(body[c].high),
parseFloat(body[c].low),
parseFloat(body[c].close)
parseFloat(body[c].open) || 0,
parseFloat(body[c].high) || 0,
parseFloat(body[c].low) || 0,
parseFloat(body[c].close) || 0
]);
}
+16 -16
View File
@@ -22,12 +22,12 @@ function get_summary(coin, exchange, api_error_msg, bid, ask, cb) {
else {
try {
const summary = {
'high': parseFloat(body.data.high),
'low': parseFloat(body.data.low),
'volume': parseFloat(body.data.volume_24H),
'bid': parseFloat(bid),
'ask': parseFloat(ask),
'last': parseFloat(body.data.last)
'high': parseFloat(body.data.high) || 0,
'low': parseFloat(body.data.low) || 0,
'volume': parseFloat(body.data.volume_24H) || 0,
'bid': parseFloat(bid) || 0,
'ask': parseFloat(ask) || 0,
'last': parseFloat(body.data.last) || 0
};
return cb(null, summary);
@@ -58,8 +58,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.data.length; t++) {
trades.push({
ordertype: body.data[t].type,
price: parseFloat(body.data[t].rate),
quantity: parseFloat(body.data[t].volume),
price: parseFloat(body.data[t].rate) || 0,
quantity: parseFloat(body.data[t].volume) || 0,
timestamp: parseInt(body.data[t].timestamp)
});
}
@@ -91,15 +91,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.data.buy.length; b++) {
buys.push({
price: parseFloat(body.data.buy[b].rate),
quantity: parseFloat(body.data.buy[b].volume)
price: parseFloat(body.data.buy[b].rate) || 0,
quantity: parseFloat(body.data.buy[b].volume) || 0
});
}
for (let s = 0; s < body.data.sell.length; s++) {
sells.push({
price: parseFloat(body.data.sell[s].rate),
quantity: parseFloat(body.data.sell[s].volume)
price: parseFloat(body.data.sell[s].rate) || 0,
quantity: parseFloat(body.data.sell[s].volume) || 0
});
}
@@ -132,10 +132,10 @@ function get_chartdata(coin, exchange, api_error_msg, cb) {
if ((body[c].time * 1000) > start)
chartdata.push([
parseInt(body[c].time * 1000),
parseFloat(body[c].open),
parseFloat(body[c].high),
parseFloat(body[c].low),
parseFloat(body[c].close)
parseFloat(body[c].open) || 0,
parseFloat(body[c].high) || 0,
parseFloat(body[c].low) || 0,
parseFloat(body[c].close) || 0
]);
}
+17 -17
View File
@@ -7,7 +7,7 @@ const rateLimitLib = require('../ratelimit');
const rateLimit = new rateLimitLib.RateLimit(1, 2000, false);
function get_summary(coin, exchange, api_error_msg, cb) {
const req_url = base_url + '/ticker/' + coin;
const req_url = base_url + 'ticker/' + coin;
// pause for 2 seconds before continuing
rateLimit.schedule(function() {
@@ -22,14 +22,14 @@ function get_summary(coin, exchange, api_error_msg, cb) {
try {
const prefix = body[coin + '_' + exchange];
const summary = {
'high': parseFloat(prefix[0].high),
'low': parseFloat(prefix[0].low),
'volume': parseFloat(prefix[0].volume24h),
'volume_btc': parseFloat(prefix[0].volume24h_btc),
'bid': parseFloat(prefix[0].highestBuy),
'ask': parseFloat(prefix[0].lowestSell),
'last': parseFloat(prefix[0].last),
'change': parseFloat(prefix[0].percent_change_24h)
'high': parseFloat(prefix[0].high) || 0,
'low': parseFloat(prefix[0].low) || 0,
'volume': parseFloat(prefix[0].volume24h) || 0,
'volume_btc': parseFloat(prefix[0][`volume24h_${exchange.toLowerCase()}`]) || 0,
'bid': parseFloat(prefix[0].highestBuy) || 0,
'ask': parseFloat(prefix[0].lowestSell) || 0,
'last': parseFloat(prefix[0].last) || 0,
'change': parseFloat(prefix[0].percent_change_24h) || 0
};
return cb(null, summary);
@@ -42,7 +42,7 @@ function get_summary(coin, exchange, api_error_msg, cb) {
}
function get_trades(coin, exchange, api_error_msg, cb) {
const req_url = base_url + '/trades/' + coin + (exchange == 'LTC' ? '/LTC' : '');
const req_url = base_url + 'trades/' + coin + (exchange == 'LTC' ? '/LTC' : '');
// pause for 2 seconds before continuing
rateLimit.schedule(function() {
@@ -60,8 +60,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.length; t++) {
trades.push({
ordertype: body[t].type,
price: parseFloat(body[t].price),
quantity: parseFloat(body[t].total_coin),
price: parseFloat(body[t].price) || 0,
quantity: parseFloat(body[t].total_coin) || 0,
timestamp: parseInt(new Date(body[t].time.toString().replace(' ', 'T') + 'Z').getTime() / 1000)
});
}
@@ -76,7 +76,7 @@ function get_trades(coin, exchange, api_error_msg, cb) {
}
function get_orders(coin, exchange, api_error_msg, cb) {
const req_url = base_url + '/orderbook/' + coin + (exchange == 'LTC' ? '/LTC' : '');
const req_url = base_url + 'orderbook/' + coin + (exchange == 'LTC' ? '/LTC' : '');
// NOTE: no need to pause here because this is the first api call
request({uri: req_url, json: true}, function (error, response, body) {
@@ -93,15 +93,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.BUY.length; b++) {
buys.push({
price: parseFloat(body.BUY[b].price),
quantity: parseFloat(body.BUY[b].amount)
price: parseFloat(body.BUY[b].price) || 0,
quantity: parseFloat(body.BUY[b].amount) || 0
});
}
for (let s = 0; s < body.SELL.length; s++) {
sells.push({
price: parseFloat(body.SELL[s].price),
quantity: parseFloat(body.SELL[s].amount)
price: parseFloat(body.SELL[s].price) || 0,
quantity: parseFloat(body.SELL[s].amount) || 0
});
}
+17 -17
View File
@@ -21,13 +21,13 @@ function get_summary(coin, exchange, api_error_msg, cb) {
else {
try {
const summary = {
'high': parseFloat(body.high),
'low': parseFloat(body.low),
'volume': parseFloat(body.quantity),
'volume_btc': parseFloat(body.amount),
'bid': parseFloat(body.bid),
'ask': parseFloat(body.ask),
'change': parseFloat(body.dailyChange) * 100
'high': parseFloat(body.high) || 0,
'low': parseFloat(body.low) || 0,
'volume': parseFloat(body.quantity) || 0,
'volume_btc': parseFloat(body.amount) || 0,
'bid': parseFloat(body.bid) || 0,
'ask': parseFloat(body.ask) || 0,
'change': parseFloat(body.dailyChange || 0) * 100
};
return cb(null, summary);
@@ -58,8 +58,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.length; t++) {
trades.push({
ordertype: body[t].takerSide,
price: parseFloat(body[t].price),
quantity: parseFloat(body[t].quantity),
price: parseFloat(body[t].price) || 0,
quantity: parseFloat(body[t].quantity) || 0,
timestamp: parseInt(new Date(body[t].ts).getTime() / 1000)
});
}
@@ -91,15 +91,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.bids.length; b += 2) {
buys.push({
price: parseFloat(body.bids[b]),
quantity: parseFloat(body.bids[b + 1])
price: parseFloat(body.bids[b]) || 0,
quantity: parseFloat(body.bids[b + 1]) || 0
});
}
for (let s = 0; s < body.asks.length; s += 2) {
sells.push({
price: parseFloat(body.asks[s]),
quantity: parseFloat(body.asks[s + 1])
price: parseFloat(body.asks[s]) || 0,
quantity: parseFloat(body.asks[s + 1]) || 0
});
}
@@ -132,10 +132,10 @@ function get_chartdata(coin, exchange, api_error_msg, cb) {
for (let c = 0; c < body.length; c++)
chartdata.push([
parseInt(body[c][9]),
parseFloat(body[c][2]),
parseFloat(body[c][1]),
parseFloat(body[c][0]),
parseFloat(body[c][3])
parseFloat(body[c][2]) || 0,
parseFloat(body[c][1]) || 0,
parseFloat(body[c][0]) || 0,
parseFloat(body[c][3]) || 0
]);
return cb(null, chartdata);
+15 -15
View File
@@ -21,11 +21,11 @@ function get_summary(coin, exchange, api_error_msg, cb) {
else {
try {
const summary = {
'volume': parseFloat(body.Volume24Hr),
'bid': parseFloat(body.Bid),
'ask': parseFloat(body.Ask),
'last': parseFloat(body.Last),
'change': parseFloat(body.Variation24Hr)
'volume': parseFloat(body.Volume24Hr) || 0,
'bid': parseFloat(body.Bid) || 0,
'ask': parseFloat(body.Ask) || 0,
'last': parseFloat(body.Last) || 0,
'change': parseFloat(body.Variation24Hr) || 0
};
return cb(null, summary);
@@ -56,8 +56,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.length; t++) {
trades.push({
ordertype: body[t].Type,
price: parseFloat(body[t].Price),
quantity: parseFloat(body[t].Amount),
price: parseFloat(body[t].Price) || 0,
quantity: parseFloat(body[t].Amount) || 0,
timestamp: parseInt(body[t].At)
});
}
@@ -89,15 +89,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.BuyOrders.length; b++) {
buys.push({
price: parseFloat(body.BuyOrders[b].Price),
quantity: parseFloat(body.BuyOrders[b].Amount)
price: parseFloat(body.BuyOrders[b].Price) || 0,
quantity: parseFloat(body.BuyOrders[b].Amount) || 0
});
}
for (let s = 0; s < body.SellOrders.length; s++) {
sells.push({
price: parseFloat(body.SellOrders[s].Price),
quantity: parseFloat(body.SellOrders[s].Amount)
price: parseFloat(body.SellOrders[s].Price) || 0,
quantity: parseFloat(body.SellOrders[s].Amount) || 0
});
}
@@ -132,10 +132,10 @@ function get_chartdata(coin, exchange, api_error_msg, cb) {
if ((c % 3) == 0)
chartdata.push([
parseInt(new Date(body[c].Date.toString() + 'Z').getTime()),
parseFloat(body[c].PriceOpen),
parseFloat(body[c].PriceHigh),
parseFloat(body[c].PriceLow),
parseFloat(body[c].PriceClose)
parseFloat(body[c].PriceOpen) || 0,
parseFloat(body[c].PriceHigh) || 0,
parseFloat(body[c].PriceLow) || 0,
parseFloat(body[c].PriceClose) || 0
]);
}
+15 -15
View File
@@ -21,15 +21,15 @@ function get_summary(coin, exchange, api_error_msg, cb) {
else {
try {
const summary = {
'high': parseFloat(body.highPriceNumber),
'low': parseFloat(body.lowPriceNumber),
'volume': parseFloat(body.volumeNumber),
'volume_btc': parseFloat(body.volumeUsdNumber),
'bid': parseFloat(body.bestBidNumber),
'ask': parseFloat(body.bestAskNumber),
'last': parseFloat(body.lastPriceNumber),
'prev': parseFloat(body.yesterdayPriceNumber),
'change': parseFloat(body.changePercentNumber)
'high': parseFloat(body.highPriceNumber) || 0,
'low': parseFloat(body.lowPriceNumber) || 0,
'volume': parseFloat(body.volumeNumber) || 0,
'volume_btc': parseFloat(body.volumeUsdNumber) || 0,
'bid': parseFloat(body.bestBidNumber) || 0,
'ask': parseFloat(body.bestAskNumber) || 0,
'last': parseFloat(body.lastPriceNumber) || 0,
'prev': parseFloat(body.yesterdayPriceNumber) || 0,
'change': parseFloat(body.changePercentNumber) || 0
};
return cb(null, summary);
@@ -60,8 +60,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < body.length; t++) {
trades.push({
ordertype: body[t].type,
price: parseFloat(body[t].price),
quantity: parseFloat(body[t].base_volume),
price: parseFloat(body[t].price) || 0,
quantity: parseFloat(body[t].base_volume) || 0,
timestamp: parseInt(new Date(body[t].trade_timestamp).getTime() / 1000)
});
}
@@ -93,15 +93,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < body.bids.length; b++) {
buys.push({
price: parseFloat(body.bids[b].numberprice),
quantity: parseFloat(body.bids[b].quantity)
price: parseFloat(body.bids[b].numberprice) || 0,
quantity: parseFloat(body.bids[b].quantity) || 0
});
}
for (let s = 0; s < body.asks.length; s++) {
sells.push({
price: parseFloat(body.asks[s].numberprice),
quantity: parseFloat(body.asks[s].quantity)
price: parseFloat(body.asks[s].numberprice) || 0,
quantity: parseFloat(body.asks[s].quantity) || 0
});
}
+12 -12
View File
@@ -22,12 +22,12 @@ function get_summary(coin, exchange, api_error_msg, cb) {
try {
const prefix = body[coin + '_' + exchange];
const summary = {
'high': parseFloat(prefix.high),
'low': parseFloat(prefix.low),
'volume': parseFloat(prefix.vol),
'bid': parseFloat(prefix.buy),
'ask': parseFloat(prefix.sell),
'last': parseFloat(prefix.last)
'high': parseFloat(prefix.high) || 0,
'low': parseFloat(prefix.low) || 0,
'volume': parseFloat(prefix.vol) || 0,
'bid': parseFloat(prefix.buy) || 0,
'ask': parseFloat(prefix.sell) || 0,
'last': parseFloat(prefix.last) || 0
};
return cb(null, summary);
@@ -59,8 +59,8 @@ function get_trades(coin, exchange, api_error_msg, cb) {
for (let t = 0; t < prefix.length; t++) {
trades.push({
ordertype: (prefix[t].type.toLowerCase() == 'bid' ? 'BUY' : 'SELL'),
price: parseFloat(prefix[t].price),
quantity: parseFloat(prefix[t].amount),
price: parseFloat(prefix[t].price) || 0,
quantity: parseFloat(prefix[t].amount) || 0,
timestamp: parseInt(prefix[t].timestamp)
});
}
@@ -93,15 +93,15 @@ function get_orders(coin, exchange, api_error_msg, cb) {
for (let b = 0; b < prefix.bids.length; b++) {
buys.push({
price: parseFloat(prefix.bids[b][0]),
quantity: parseFloat(prefix.bids[b][1])
price: parseFloat(prefix.bids[b][0]) || 0,
quantity: parseFloat(prefix.bids[b][1]) || 0
});
}
for (let s = 0; s < prefix.asks.length; s++) {
sells.push({
price: parseFloat(prefix.asks[s][0]),
quantity: parseFloat(prefix.asks[s][1])
price: parseFloat(prefix.asks[s][0]) || 0,
quantity: parseFloat(prefix.asks[s][1]) || 0
});
}