Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: Coinmon – Check Bitcoin Prices in Terminal (github.com/bichenkk)
68 points by bichenkk on Nov 20, 2017 | hide | past | favorite | 70 comments


    $ coinmon() {
    >     curl "https://api.coinmarketcap.com/v1/ticker/?convert=$1" | jq ".[0] .price_$1"
    > }

    $ coinmon eur
    "6988.4723188"
In case you don't want to install 61 packages [1] :)

I don't know when/where nodejs development went wrong, but there's definitely something wrong.

[1] http://npm.anvaka.com/#/view/2d/coinmon


You are so right. When I saw the link I thought: "That could be fun, lets take a look how it displays the data". But when I saw that it uses node.js I thought "Oh my god, who had this brilliant idea to write it with node"...

Hey guys, please use rust, golang, haskell or whatever you like, but please do not use nodejs to write CLI tools.

And I am not one of the guys who is against JS in general. In fact, I like building PWAs and other JS heavy apps/websites a lot. But there are so many tools do a better job at building cli programs.


I don't get the hate here, Node works great for CLI tools.

Easy and quick install, supports colors and icons in the terminal, has several easy and useful table libraries to choose from, and it runs plenty fast enough for it's use case.

What benefits would rust, golang, haskell, or whatever you like provide over node in this situation?


I wouldn't call it hate. It is more like 'wtf, please don't do that' ;-)

Actually, you can write cli tools with js, it's just that in most cases it is not a good choice. There are some reasonable cli tools which can be written in js e.g. js dev-tools like rollup, gulp, grunt, etc. But I would not consider Coinmon a js dev-tool ;-)

When you say 'Easy and quick install' thats not completely true. First of all it assumes that you have a js package manager installed already (npm/yarn), which is not preinstalled on most OS. So yes, nowadays thats not too much of a hassle. But from a package manager perspective npm itself is a disease as it does not integrate with the system package manager so your system is not completely up to date after you told your package manager to update all package. Instead you have to start npm to let it run its own updates. Sometimes even that is not as simple as it could be because frontend-devs tend to advise to install npm packages locally (within a project) instead of globally (once per system).

I think we could continue this discussion for a while as there are many more arguments to be evaluated (not everything about npm is bad), but ultimately we will find out, that other languages would be a better fit for such tools.

Again, my initial commment was meant as 'advice' and not as 'hate'. Yes I know, nobody asked for advice ;-)


Also a NodeJS fan in general, but prefer to install/develop cli's with golang instead of node just because you get a compiled, static binary that works cross-platform. Faster for users to install, less bloaty and works on all platforms without any dependencies.


I personally usually use Python, Bash, or C, but there is a utility for packaging NodeJS tools into executables. I think it does some tree-shaking as well. Disclaimer: I haven't used it, so I'm not sure of the results. But it is possible.

https://www.npmjs.com/package/pkg

edit: For the curious -- Just tried on a really simple script that just takes one argument and writes it with some text to STDOUT and it still came to 35MB. So it must package a bunch of Node with it. I won't be leaving my go-to's for it anytime soon unless usability and development speed necessitate it. Going to have to go with the, best to not use NodeJS for general cmd-line utils outside of the NodeJS environment. The one perk is that it will, by default, output executables for Linux, macOS, and Windows.

Source:

    (function() {
    'use strict';

      function main(_string) {
        console.log(`${_string} was read from STDIN.`);
      }

      main(process.argv[2]);

    }());
Output file:

    35088858 Nov 20 11:36 index-linux
    35717043 Nov 20 11:36 index-macos
    23137020 Nov 20 11:36 index-win.exe


Thats because PKG is including the Node runtime in the binaries, this way users don't have to install Node itself to run them.

I'm using it myself and besides the fat binaries and the fact that you have to write Javascript, it is really good. (Working on replacing this daemon with Go ASAP)

Edit: just read your last line, I'm kinda stating the obvious here.


I'm quite confident that "whatever you like" does not benefit versus NodeJS anyway.

And of course you should write cli tools with whatever you feel comfortable.

If you want them to be well-received by everyone, well that's a different topic.


Node is fine, and I don't agree with the hate, but Rust and Go would both give you a single binary that just runs everywhere. Not everyone already has Node installed.


I get what adtac said, but, "not use node for cli tools?" Come on, so if I only know JavaScript and I want to build a cli tool for personal use that can later open source, shouldn't do it because the language?

That's not the hacker mentality, you can write a cli tool with JavaScript, Python, Lua, etc., make it work and there's nothing wrong with it. If you want to go full deep into cli tooling, then you start to looking into other languages that can fit into your new requirements.


Thanks a lot for the comment. This is actually a practice work when I was reading this https://developer.atlassian.com/blog/2015/11/scripting-with-...

Which language (rust, golang, haskell) do you think it is more fitting? I am new to writing things running on command line @@


Very nice, thank you!

I'm not much into APIs or JS (CBA with auth tokens etc either) so I often forget the sheer power of jq.

I prefer to output the curl data 2>/dev/null so there's less noise and the data could be parsed further. I also want to default to eur, with the option of say usd. Finally, I want the currency to be shown as $2 and I want it uppercase.

I ended up with:

  coinmon() {
      local currency=$1
      case "$currency" in "") currency="eur";; esac
      data=`curl "https://api.coinmarketcap.com/v1/ticker/?convert=$currency" 2>/dev/null | jq ".[0] .price_$currency" | cut -d \" -f 2`
      echo "$data ${currency^^} "
  }
(Sorry for the scrollbar here on HN.)

One could also use tosheets [1] to put $data in spreadsheet or perhaps use something like gnuplot. One could also round $data to say 2 numbers behind the comma (or well, dot is being used in this case) to get a more human readable amount. This could also be implemented like df -h creates human readable output (see man df).

[1] https://news.ycombinator.com/item?id=15722108


That was my reaction to:

    npm install
Nah, i'm alright mate.


I prefer

    curl -s "https://api.coinmarketcap.com/v1/ticker/?convert=$1" |
	jq ".[0] .price_$1" | sed 's/\"//g'
for silent curl and no quotes in output. Unfortunately, this does add a third dependency to the script.


Indeed.. I'll probably write a Nim version as I prefer a single binary and not rely on having a JVM, Node, Python etc.. VM and associated libraries pre-installed.


I think its fair to rely on Python for Linux Distros. Ubuntu/Debian/Redhat all bundle python with the distro.

Where-as the JVM & Nodejs are generally seperate packages.

Java 9 though, allows you to ship zero-dep golang style binaries [1].

https://steveperkins.com/using-java-9-modularization-to-ship...


Nim beginner here. I wanted to see if I was capable of making an equivalent program in Nim. I'm still a bit confused about some of Nim's conventions and idioms, mostly revolving around when to use objects vs. ref objects, and how to properly construct an object. Care to take a look at my code and give me some pointers (heh)?

https://gist.github.com/anonymous/1e3d7045de67f59c676135fead...


>I don't know when/where nodejs development went wrong, but there's definitely something wrong.

Probably when they decided that every function and almost every statement and boolean check needed to be its own separate package with its own build system and test framework.


What's up with that API? Why is it a list of objects rather than an object of {"coin-id": {values}}? The way they return things, you have to walk the entire list to find the currency you're interested in.


Not necessarily the whole list though ;)


Here's a simple Python script with no dependencies other than the stdlib (adjust to taste):

https://www.pastery.net/jnscrh/


Now that's what I call a refactor! :D ty


and curl did not have dependencies?

The installation of coinmon and all its deps is faster, as i can your post.

But you are right, it uses incredible 33 MB of my disk space, so i now have only 300000 MB left. OMG doomed!


You're missing my point: nodejs is really not a suitable candidate for tiny CLI programs like this. If the author is just learning node, there's nothing wrong with it, of course.

In any case, the bash one-liner is just an alternative :)

Also, this kind of "it uses just 33 MB" culture is exactly what's wrong with node: 33 MB is small enough, but what about real programs? Would you still freely add trivial dependencies? This would get unwieldy very fast. There's also the security aspect that comes with relying on 61 dependencies. What if one of the dependencies is compromised (as it happened recently)?


And if we had exabyte drives, would there be nothing suspect about a CLI utility taking petabytes? Are we not engineers / programmers?


Last week I listened to an interview with a man that has written some books on Bitcoin and other crypto currencies and in it he stated that he lives as much of his life on bitcoin as possible. He asks to be paid in bitcoin, he pays his employees in bitcoin, and generally uses it wherever possible.

I was thinking about this and to somebody like that, it must seem like the USD is crashing. If bitcoin is your currency, then deflation is happening everywhere! Does he look at the housing market and marvel how everything is now around 80% less expensive than it was at the start of the year?


If it's from @aantonop on The Kevin Rose Show (which I just got done listening to myself) he did mention that until the volatility comes down, prices can't be pegged to the Bitcoin (or many cryptocurrencies for that matter).

Example: At the moment of me writing this, let's say I wanted to be paid $50/hour for to develop a website. That is my desired value for my work. It's value today will large in part be the same next week, month, maybe even year. That would be 0.006086BTC. If I were to list that as my asking price instead of the less volatile $50, next week I could very quickly price myself out of the competition, surely goes the same next year (either direction). I continuously re-evaluate the the BTC asking rate based on the exchanged value to me. One day though, that won't be the case. Once the market stabilizes and dips and gains are less than 5% over the year, I can expect this to be unchanging and start valuing directly in BTC.

He mentions it in the podcast that several countries with highly volatile national currencies actually use a more stable currency (such as USD) to list an asking price for a good, but are actually paid in the their currency's exchanged value to that amount. (I'm still looking for a reference to such occurrence).

Although the value of what he was paid in yesterday has gone up (Got $5 worth of bitcoin yesterday, now worth $6) the cost of the product he buys tomorrow will inevitably go down (0.00075 today, 0.00060 tomorrow).


Sounds like Andreas Antonopoulos. https://antonopoulos.com


By the way, what is up with Bitcoin? Why did it rise 10x this year?


Because I haven't had any money in it for most of the year.

The couple of times I did have money in it -- for up to two months at a time -- it either fell slightly overall or stayed fairly flat. As soon as I sold, it jumped back up again.

I'm currently accepting offers from Bitcoin investors to prevent me from buying back in again.


The trick with Bitcoin is to do fuck all. Buy and forget. Come back in 10 yrs.


I would really like to read a well-researched answer to this question. I've heard various theories around instability in Puerto Rico, and people using it to move money out of China. I have no idea if there's any evidence to support those theories.

I really want to understand some of the economics behind the value of a Bitcoin. Some people say that it's actually worthless, but that can't be true. It lets people move practically unlimited amounts of money anywhere in the world for a relatively small fee. It also provides immutable data that can be used to verify records.

I actually spent this weekend adding blockchain verification to my document generation service [1]. It was actually pretty amazing to look at a Bitcoin transaction [2], and realize that this data has so much authenticity and permanence. Not only does it guarantee that my document existed at a certain point in time, but that hash will probably be preserved in the blockchain for the rest of human history.

That one bitcoin transaction cost a lot of money (0.000846 BTC, or $6.95 USD), but it verifies a large number of records by using a merkle tree. [3]

I have no idea how these fees relate to the fiat price, but that must be one factor. Also the price of electricity around the world. There's a lot of speculation and "tulip mania" too, but even if you ignore all of that, I think it's a very interesting thing to research.

[1] https://formapi.io/

[2] https://live.blockcypher.com/btc/tx/4dc1ef829128355fdbbf3afb...

[3] https://chainpoint.org/


The fee size is relative to the amount of competition to get transactions into the next block. Because the block size has been capped at 1MB, not every transaction in the preceding 10 minutes will fit. So miners sort by the fees attached to the transactions when selecting them. (I think the block size is supposed to be increased to 2MB shortly, if it hasn't already.)


yesterday I did a transaction in one 10 minute block with a fee of $0.70


As an outsider looking in, it seems like every time something negative happens to BTC, if the ramifications weren't as bad as everyone was expecting the market resurges twofold.

In the case of this year, there was the major shenanigans with the hard fork from just BTC to BTC / BCH, as well as some heightened cryptocurrency crackdowns in China.


Because Bitcoin holders, psychologically (not politically!) are like Trump supporters before the election.

The more negativity/naysers there are, the more stubbornly they continue to hold to prove the elite financial world they are wrong.


Higher general awareness would be my guess? Regular-money people start to invest. Too bad it only works as an investment and not something useful (considering how much energy is wasted on it).


It would be cool if all those miners were also solving a puzzle that incidentally would help cure some disease, or figure out how to beat the speed of light.


Or figure out how to make faster DRAM. (Cuckoo Cycle algorithm.) Incidentally, faster than light communication might increase speed of memory, right?


A lot of people are using it for payments.


For other currencies, sure. But minority of moved value would be used to pay for goods/services. Also, isn't the fee extremely high right now?


It's around 10 dollars. A lot of retailers offer a discount (because each credit card transaction costs them 5%).

If your purchase is high enough it makes sense. Would not make sense for micro transactions


not true currently


It’s in no small part due to massive ICO events where spin-off coins with no utility and no actual value generate millions and millions of dollars in imaginary value through pump and dump schemes, because there’s no realistic way to short sell them and everyone involved has a vested interest in the price rising.



https://bitinfocharts.com/comparison/bitcoin-transactions.ht...

Massive transaction growth, a proxy for user adoption, since the Dec. 2013 crash. That lead to steady growth until this spring when Core's no block increase ever policy stunted adoption but by then the bubble had already started to form. you are seeing a bunch of clueless new folks fomo into the crypto space right now. I would be surprised if we aren't entering the blow off top phase. There was just a ~50% movement in a matter of a week. Bitcoin Cash is probably the true Bitcoin long term that is where I'm moving my money.

* Also significant unease over USDT Tether scheme among the wider community could lead to a second Gox like situation


More or less continuous increase in demand along with constant supply.


Dont ask questions - just buy more!!! (which is also the answer)


Simple: institutional validation. CME is just the beginning.

Big players with billions are now just waiting for the right time to jump in. We’re at that time.


Because it emulates gold somewhat, scarcity ( not much BTC left ) and a high demand.


It's been doing that for years.


Looks cool. Live updating would make it even better.

I've reported a very minor bug that I'm experiencing: https://github.com/bichenkk/coinmon/issues/1


You could use `watch -n 1 coinmon`.


That's true (with `--color`). An alternative way would be to connect to one of the various websocket APIs that stream pricing data, might be a bit friendlier than constant polling... but that'd be quite a lot of work!


Just made a tool for you to check bitcoin prices on terminal for fun!


Good stuff! Works nicely.


I was bored, so I decided to make a Nim equivalent using only the standard library. Turned out to be exactly 55 lines https://gist.github.com/anonymous/1e3d7045de67f59c676135fead...


Awesome stuff :D I'm founder of https://bitbank.nz

I would love to see someone build something based on the live crypto forecast data we have,

I'm happy for you to reverse engineer/use the same api that our frontend uses, we also have a firebase API so people can subscribe to live updates,

Let me know your email if your from HN and ill give you some free time to use the platform :)

We also have a referral program where you can make .003btc each paying user.

Thanks!


Here's my almost pure Python equivalent [1].

[1] https://github.com/SeanDS/cryptoquote


Idea: Show bitcoin prices in terms of my hour's worth!

    $ coinmon -c X EUR/month
    You have to work Y hours for a bitcoin!
I think this aligns just a little bit more with the idealistic view of BTC. Next step would be getting paid in BTC, and then, getting a fixed amount of BTC.


Not sure why you're being downvoted (maybe offtopic I guess?) but this is how I view pretty much all transactions I do. If I buy a fancy craft beer in a bar for £5 then that's not £5 to me but "X minutes" depending on where I'm working. I've also been comparing "time to earn X for Y bitcoin" when I purchase on gdax to give me a sense of relative grounding.


I wrote something similar with Go a while back which is configured via a json file and runs in the terminal https://github.com/markustenghamn/golang-cryptotracker


This is cool. It would be nice if it live updated.


Awesome work! I'll no longer have to keep a browser tab with coinmarketcap open.


Hi can you explain this in plain English please?


> 61 packages

That is truly disgusting. WTF are we doing?


Nice work, I like it!!


why?


How else would you check Bitcoin prices?

Launch a whole web browser and visit a random site?


I have these in my zshrc

btc='echo "Btc(usd): $"$(curl -sL https://api.coinmarketcap.com/v1/ticker/bitcoin/ | jq ".[0].price_usd" | cut -d\" -f2 )'

eth='echo "Eth(usd): $"$(curl -sL https://api.coinmarketcap.com/v1/ticker/ethereum/ | jq ".[0].price_usd" | cut -d\" -f2 )'




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: