text: const { Requester, Validator } = require('@chainlink/external-adapter')
  const { util } = require('@chainlink/ea-bootstrap')
  
  const customError = (data) => {
    return data.status === 'ERROR'
  }
  
  const customParams = {
    base: ['base', 'from'],
    quote: ['quote', 'to'],
    endpoint: false,
    amount: false,
    precision: false,
  }
  
  const execute = (input, callback) => {
    const validator = new Validator(input, customParams)
    if (validator.error) return callback(validator.error.statusCode, validator.errored)
  
    const jobRunID = validator.validated.id
    const endpoint = validator.validated.data.endpoint || 'conversion'
    const from = validator.validated.data.base.toUpperCase()
    const to = validator.validated.data.quote.toUpperCase()
    const url = `https://api.polygon.io/v1/${endpoint}/${from}/${to}`
    const amount = validator.validated.data.amount || 1
    const precision = validator.validated.data.precision || 4
    const apikey = util.getRandomRequiredEnv('API_KEY')
  
    const params = {
      amount,
      precision,
      apikey,
    }
  
    const config = {
      url,
      params,
    }
  
    Requester.request(config, customError)
      .then((response) => {
        response.data.result = Requester.validateResultNumber(response.data, ['converted'])
        callback(response.status, Requester.success(jobRunID, response))
      })
      .catch((error) => callback(500, Requester.errored(jobRunID, error)))
  }
  
  module.exports.execute = execute
  