-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commonjs -> ems and prettier format code
- Loading branch information
Showing
14 changed files
with
3,664 additions
and
3,395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
browser: true, | ||
commonjs: true, | ||
es6: true, | ||
}, | ||
extends: "eslint:recommended", | ||
globals: { | ||
Atomics: "readonly", | ||
SharedArrayBuffer: "readonly", | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: "module" | ||
}, | ||
rules: { | ||
"linebreak-style": ["error", "unix"], | ||
"no-unused-vars": "off", | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"semi": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,89 @@ | ||
#!/usr/bin/env node | ||
|
||
const args = require("./src/arguments.js"); | ||
const asciichart = require("asciichart"); | ||
const moment = require("moment"); | ||
const { map, flow, sortBy, toLower } = require("lodash/fp"); | ||
const { trim, pad, max, min } = require("lodash/fp"); | ||
const { currency, showCoinList, topList } = require("./src/arguments.js"); | ||
const { CryptoCompareAPI } = require("./src/CryptoCompareAPI.js"); | ||
const { print, normalize, time, interpolate } = require("./src/utils.js"); | ||
const { printTopList } = require("./src/toplist.js"); | ||
const { | ||
printTechIndicatorChart, | ||
getTechIndicator, | ||
getTechIndicatorColors, | ||
} = require("./src/technical-indicator.js"); | ||
import args from "./src/arguments.js" | ||
import asciichart from "asciichart" | ||
import moment from "moment" | ||
import lodash from "lodash/fp.js" | ||
import { CryptoCompareAPI } from "./src/CryptoCompareAPI.js" | ||
import { print, normalize, time, interpolate } from "./src/utils.js" | ||
import { printTopList } from "./src/toplist.js" | ||
import { | ||
printTechIndicatorChart, | ||
getTechIndicator, | ||
getTechIndicatorColors, | ||
} from "./src/technical-indicator.js" | ||
|
||
const { map, flow, sortBy, toLower, trim, pad, max, min } = lodash | ||
|
||
const printCoins = async () => | ||
flow( | ||
map(trim), | ||
sortBy(toLower), | ||
map(print) | ||
)(await CryptoCompareAPI.fetchCoinList()); | ||
flow( | ||
map(trim), | ||
sortBy(toLower), | ||
map(print) | ||
)(await CryptoCompareAPI.fetchCoinList()) | ||
|
||
const getMinRange = (max, min) => { | ||
if (max - min > args.minRange) return []; | ||
const dist = max - min; | ||
const range = args.minRange / 2 - dist / 2; | ||
return [max + range, min - range]; | ||
}; | ||
if (max - min > args.minRange) return [] | ||
const dist = max - min | ||
const range = args.minRange / 2 - dist / 2 | ||
return [max + range, min - range] | ||
} | ||
|
||
const main = async () => { | ||
const [timePast, timeName, timeApi] = time(); | ||
const past = moment() | ||
.subtract(timePast, timeName) | ||
.format("YYYY-MM-DD hh:mm a"); | ||
const [timePast, timeName, timeApi] = time() | ||
const past = moment() | ||
.subtract(timePast, timeName) | ||
.format("YYYY-MM-DD hh:mm a") | ||
|
||
const fullHistroy = await CryptoCompareAPI.fetchCoinHistory( | ||
timeApi, | ||
args.coin, | ||
currency, | ||
timePast | ||
); | ||
const fullHistroy = await CryptoCompareAPI.fetchCoinHistory( | ||
timeApi, | ||
args.coin, | ||
args.currency, | ||
timePast | ||
) | ||
|
||
const history = interpolate(fullHistroy); | ||
const value = await CryptoCompareAPI.fetchCoinPrice(args.coin, currency); | ||
const history = interpolate(fullHistroy) | ||
const value = await CryptoCompareAPI.fetchCoinPrice(args.coin, args.currency) | ||
|
||
const baseLegend = `\t ${args.coin} last ${timePast} ${timeName}`; | ||
const now = `. Now: ${value[currency]} ${currency}`; | ||
const legend = baseLegend + ` since ${past}` + now; | ||
const smallLegend = baseLegend + now; | ||
const baseLegend = `\t ${args.coin} last ${timePast} ${timeName}` | ||
const now = `. Now: ${value[args.currency]} ${args.currency}` | ||
const legend = baseLegend + ` since ${past}` + now | ||
const smallLegend = baseLegend + now | ||
|
||
const fixed = normalize(max(history)); | ||
const fixedHist = map((x) => x.toFixed(fixed))(history).map(Number); | ||
const padding = pad(2 + max(fixedHist).toString().length)(""); | ||
const [maxH, minH] = getMinRange(max(fixedHist), min(fixedHist)); | ||
const chart = getTechIndicator(fullHistroy).concat([fixedHist]); | ||
try { | ||
print( | ||
asciichart.plot(chart, { | ||
height: args.maxHeight, | ||
max: args.minRange ? maxH : args.max, | ||
min: args.minRange ? minH : args.min, | ||
padding: padding, | ||
colors: getTechIndicatorColors(), | ||
format: (x) => | ||
(padding + x.toFixed(fixed)).slice(-padding.length), | ||
}) | ||
); | ||
} catch (e) { | ||
console.log( | ||
"Couldn't plot chart. Please try different width or height settings." | ||
); | ||
process.exit(1); | ||
} | ||
const fixed = normalize(max(history)) | ||
const fixedHist = map((x) => x.toFixed(fixed))(history).map(Number) | ||
const padding = pad(2 + max(fixedHist).toString().length)("") | ||
const [maxH, minH] = getMinRange(max(fixedHist), min(fixedHist)) | ||
const chart = getTechIndicator(fullHistroy).concat([fixedHist]) | ||
try { | ||
print( | ||
asciichart.plot(chart, { | ||
height: args.maxHeight, | ||
max: args.minRange ? maxH : args.max, | ||
min: args.minRange ? minH : args.min, | ||
padding: padding, | ||
colors: getTechIndicatorColors(), | ||
format: (x) => (padding + x.toFixed(fixed)).slice(-padding.length), | ||
}) | ||
) | ||
} catch (e) { | ||
console.log( | ||
"Couldn't plot chart. Please try different width or height settings." | ||
) | ||
process.exit(1) | ||
} | ||
|
||
if (args.maxWidth > 40 && !args.disableLegend) { | ||
print(args.maxWidth < 65 ? smallLegend : legend); | ||
} | ||
if (args.maxWidth > 40 && !args.disableLegend) { | ||
print(args.maxWidth < 65 ? smallLegend : legend) | ||
} | ||
|
||
printTechIndicatorChart(fullHistroy, padding); | ||
}; | ||
printTechIndicatorChart(fullHistroy, padding) | ||
} | ||
|
||
if (showCoinList) { | ||
printCoins(); | ||
} else if (topList) { | ||
printTopList(); | ||
if (args.showCoinList) { | ||
printCoins() | ||
} else if (args.topList) { | ||
printTopList() | ||
} else { | ||
main(); | ||
main() | ||
} |
Oops, something went wrong.