Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dolar tj and converter #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env node
#!/usr/bin/env NODE_NO_WARNINGS=1 node

// @ts-ignore
const trae = require('trae')

const args = process.argv.slice(2)

const { print } = require('./utils')

const URL = 'https://api.bluelytics.com.ar/v2/latest'
Expand All @@ -13,7 +15,7 @@ const main = () => {
.get(URL)
.then(({ data }) => {
const { oficial, blue } = data
print(oficial, blue)
print(oficial, blue, args[0], args[1])
})
.catch(console.error)
}
Expand Down
96 changes: 95 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 57 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const TYPES = {
blue: 'BLUE',
}

// CC conversion rate: Oficial + 30% (Impuesto PAIS) + 30% (Impuesto Ganancias)
const ccRate = 1.6;


const convert = (val) => val.toFixed(2)

const calculateOffset = (a, b) => ({
Expand All @@ -20,22 +24,71 @@ const printTable = (
console.log(`| ${type}\t\t |`)
console.log(`| ----------------- |`)
console.log(
`| Buy:\t ${offset.buy ? ' ' : ''}$ ${convert(val.value_buy)} |`,
`| Buy:\t ${offset.buy ? ' ' : ''}$ ${convert(val.value_buy)} |`,
)
console.log(
`| Sell:\t ${offset.sell ? ' ' : ''}$ ${convert(val.value_sell)} |`,
`| Sell:\t ${offset.sell ? ' ' : ''}$ ${convert(val.value_sell)} |`,
)
console.log(`| ----------------- |`)
console.log(
`| Avg:\t ${offset.avg ? ' ' : ''}$ ${convert(val.value_avg)} |`,

`| Avg:\t ${offset.avg ? ' ' : ''} $ ${convert(val.value_avg)} |`,
)
console.log(`|___________________|`)
if (type == 'REAL') {
console.log()
console.log(`|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|`)
console.log(`| TARJETA\t |`)
console.log(`| ----------------- |`)
console.log(`| \t${offset.avg ? ' ' : ''}$ ${convert(parseFloat(val.value_avg) * ccRate)} |`)
console.log(`|___________________|`)
}
}

const printConversion = (
val,
type,
amount,
operation
) => {

if(operation == '--to-usd') {
val.value_buy = amount / val.value_buy;
val.value_sell = amount / val.value_sell;
val.value_avg = amount / val.value_avg;
} else {
val.value_buy = val.value_buy * amount;
val.value_sell = val.value_sell * amount;
val.value_avg = val.value_avg * amount;
}

console.log(`${type} Buy:\t $ ${convert(val.value_buy)}`)
console.log(`${type} Sell:\t $ ${convert(val.value_sell)}`)
if (type == 'REAL') {
console.log()
console.log(`TARJETA:\t $ ${convert(parseFloat(val.value_sell) * ccRate)}`)
}
}

const print = (oficial, blue) => {
const print = (oficial, blue, amount = 0, operation = '--to-ars') => {
let message = `Convert ${amount} USD to ARS`;
if (operation == '--to-usd') {
message = `Convert ${amount} ARS to USD`;
}

printTable(oficial, TYPES.real, calculateOffset(oficial, blue))
console.log()
printTable(blue, TYPES.blue, calculateOffset(blue, oficial))
if (amount > 0) {
console.log()
console.log(message)
console.log(`-----------------------------`)
printConversion(oficial, TYPES.real, amount, operation)
console.log()
printConversion(blue, TYPES.blue, amount, operation)
console.log(`-----------------------------`)

}
}

module.exports = { print }