{"size": 1410, "ext": "js", "max_stars_repo_path": "lib/ping_pong/meta/process_params.js", "max_stars_repo_name": "avsek477/bfx-hf-algo", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/ping_pong/meta/process_params.js", "max_issues_repo_name": "avsek477/bfx-hf-algo", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/ping_pong/meta/process_params.js", "max_forks_repo_name": "avsek477/bfx-hf-algo", "max_forks_repo_forks_event_min_datetime": "2020-11-28T22:52:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-15T20:46:08.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 22.380952381, "max_line_length": 73, "alphanum_fraction": 0.6829787234}
'use strict'

const _isFinite = require('lodash/isFinite')

/**
 * Converts a raw parameters Object received from an UI into a parameters
 * Object which can be used by a PingPong instance for execution.
 *
 * Part of the `meta` handler section.
 *
 * @memberOf module:PingPong
 * @param {object} data - raw parameters from an UI
 * @returns {object} parameters - ready to be passed to a fresh instance
 */
const processParams = (data) => {
  const params = { ...data }

  if (params._symbol) {
    params.symbol = params._symbol
    delete params._symbol
  }

  if (!params._futures) {
    delete params.lev
  }

  if (_isFinite(params.cancelDelaySec)) {
    params.cancelDelay = params.cancelDelaySec * 1000
    delete params.cancelDelaySec
  }

  if (_isFinite(params.submitDelaySec)) {
    params.submitDelay = params.submitDelaySec * 1000
    delete params.submitDelaySec
  }

  if (!_isFinite(params.cancelDelay)) {
    params.cancelDelay = 1000
  }

  if (!_isFinite(params.submitDelay)) {
    params.submitDelay = 2000
  }

  if (!params.splitPingPongAmount) {
    params.pingAmount = params.amount
    params.pongAmount = params.amount
  }

  if (params.action) {
    if (params.action === 'Sell') {
      params.pingAmount = Number(params.pingAmount) * -1
      params.pongAmount = Number(params.pongAmount) * -1
    }

    delete params.action
  }

  return params
}

module.exports = processParams
