nefertiti-node
Version:
ES module to work with Nefertiti crypto trade bot.
53 lines (46 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = pingHub;
var _axios = _interopRequireDefault(require("axios"));
var _variables = require("../functions/variables.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @function pingHub
* @description Ping the listen server to get all running bots
* @returns {JSON} Returns parsed JSON array of objects
* @example
* // Call the function and chain it with .then():
*
* pingHub().then((results) => {
* console.log(results, results.length);
* });
*
* // Return object example:
* [{
* port: 38701,
* command: 'sell',
* args: ['listen',...]
* },
* {
* port: 38702,
* command: 'buy',
* args: ['listen',...]
* }]
*/
async function pingHub() {
// eslint-disable-next-line no-console
console.log('Fetching bots from Nefertiti listen server...');
try {
const res = await _axios.default.get(`${_variables.nefertitiURL.hostname}:${_variables.nefertitiURL.port}${_variables.nefertitiURL.ping}`);
return res.data;
} catch (err) {
if (err.code === 'ECONNREFUSED') {
// eslint-disable-next-line operator-linebreak
const fetchErr = 'There was an error connecting to Nefertiti. This usually means the listen server has not started, or cannot be reached at 127.0.0.1:38700';
return new Error(fetchErr);
}
return new Error(`There was an error: ${err}`);
}
}