Skip to content

Commit

Permalink
commonjs -> ems and prettier format code
Browse files Browse the repository at this point in the history
  • Loading branch information
madnight committed May 16, 2021
1 parent 3cceb4a commit b794b0b
Show file tree
Hide file tree
Showing 14 changed files with 3,664 additions and 3,395 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.cjs
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",
},
}
20 changes: 0 additions & 20 deletions .eslintrc.js

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"semi": false
}
4 changes: 3 additions & 1 deletion COINS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# List of supported cryptocurrencies
# List of supported cryptocurrencies

Last update 2017/08

`bitcoin-chart-cli --list`

```
007 coin (007)
0x (ZRX)
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<a href="https://codeclimate.com/github/madnight/bitcoin-chart-cli/issues"><img src="https://codeclimate.com/github/madnight/bitcoin-chart-cli/badges/issue_count.svg?maxAge=2592000" alt="Issue Count" /></a>
<a href="https://snyk.io/test/github/madnight/bitcoin-chart-cli"><img src="https://snyk.io/test/github/madnight/bitcoin-chart-cli/badge.svg" alt="Known Vulnerabilities" /></a>
<a href="https://david-dm.org/madnight/bitcoin-chart-cli"><img src="https://img.shields.io/david/madnight/bitcoin-chart-cli?cacheSeconds=3600" alt="dependencies Status" /></a>
<br> <br>
<br> <br>

<img align="right" src="bitcoin-chart-cli.png" width="200">

Expand All @@ -20,8 +20,9 @@ mine [wallstreet](https://github.com/madnight/wallstreet), which provides inform
stocks instead of cryptocurrencies.

### Requirements
* node 8.0 or higher
* npm or yarn

- node 8.0 or higher
- npm or yarn

### Usage

Expand All @@ -47,6 +48,7 @@ bitcoin-chart-cli --coin XRP -ti RSI SMA BB EMA MACD
```

### Options

```bash
bitcoin-chart-cli --help

Expand All @@ -73,6 +75,7 @@ bitcoin-chart-cli --help
-ti, --technical-indicator <type...> add a technical indicator: RSI SMA BB EMA MACD
-h, --help display help for command
```

# Examples

![](https://i.imgur.com/8jXYkHc.png)
Expand All @@ -82,6 +85,7 @@ bitcoin-chart-cli
```

![](https://i.imgur.com/ijwaYXir.png)

```
Create terminal splits (tmux) with watch for live charts the unix way
watch -n 60 bitcoin-chart-cli --mins 30 --width 60
Expand Down Expand Up @@ -117,7 +121,6 @@ Rank Name Price MktCap Volume Change/24h

![image](https://user-images.githubusercontent.com/10064471/117548107-56bd4f80-b033-11eb-8f48-b16d2111cb0e.png)


```bash
Charts with technical indicators
bitcoin-chart-cli --coin XRP -ti RSI SMA BB EMA MACD
Expand Down
145 changes: 72 additions & 73 deletions index.js
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()
}
Loading

0 comments on commit b794b0b

Please sign in to comment.