UNPKG

nefertiti-node

Version:

ES module to work with Nefertiti crypto trade bot.

53 lines (46 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = pingBot; var _axios = _interopRequireDefault(require("axios")); var _variables = require("../functions/variables.js"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @function pingBot * @description Request information for a specific bot * * @param {string|number} port The port that the bot is running on. * @returns {JSON} Returns a JSON object * * @example * // Call the function and chain it with .then(): * * pingBot(38701).then((results)=>{console.log(results)}) * * // or await it * * const sellBot = await pingBot(38701) * * // Return object example: * { * port: 38701, * command: 'sell', * args: [ 'listen',...] * } */ async function pingBot(port) { // eslint-disable-next-line no-console console.log(`Fetching bot ${port} from Nefertiti listen server...`); try { const res = await _axios.default.get(`${_variables.nefertitiURL.hostname}:${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}`); } }