{"size": 1274, "ext": "js", "max_stars_repo_path": "sortarray.js", "max_stars_repo_name": "Jamelle-Boose/json-to-csv", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "sortarray.js", "max_issues_repo_name": "Jamelle-Boose/json-to-csv", "max_issues_repo_issues_event_min_datetime": "2022-03-15T16:42:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T16:57:17.000Z", "max_forks_repo_path": "sortarray.js", "max_forks_repo_name": "Jamelle-Boose/json-to-csv", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 27.1063829787, "max_line_length": 79, "alphanum_fraction": 0.6420722135}
#!/usr/bin/env node

const fs = require("fs")
const dayjs = require("dayjs")
const { parse } = require("json2csv")

const [fileJSON, fileCSV] = process.argv.slice(2)

const json = fs.readFileSync(fileJSON, "utf8")
const parsed = JSON.parse(json)

const newData = parsed.map(item => {
  let watchlistName = `.${item.symbol}${dayjs(item.expiry).format("YY")}${
    item.expiryString.split("/")[0]
  }${item.expiryString.split("/")[1]}${item.optionType}${item.strike}`

  return {
    Time: item.timeString,
    Date: item.dateString,
    Symbol: item.symbol,
    Expiry: item.expiryString,
    Strike: item.strike,
    OTM: item.outOfMoney,
    Type: item.optionType === "C" ? "Call" : "Put",
    Spot: Math.round(item.spot * 100) / 100,
    Size: item.size,
    Price: Math.round(item.price * 100) / 100,
    Side: item.side === 3 ? "Above Ask" : item.side === 2 ? "Ask" : "Near Ask",
    IVol: Math.round(item.ivol * 1000) / 1000,
    Premium: item.premiumString,
    OrderType: item.type,
    Volume: item.volume,
    OI: item.oi,
    Section: item.section,
    Unusual: item.unusual,
    HighlyUnusual: item.highlyUnusual,
    WatchlistName: watchlistName,
  }
})

try {
  const csv = parse(newData)
  fs.writeFileSync(fileCSV, csv)
} catch (err) {
  console.error(err)
}
