Watch Chris Learn!

Writings about the things I learn (Ruby / Haskell / Web / Other Stuff)

Ruby Oneliner to Get Current Bitcoin Price From Coinbase

This was a fun little hack. I wanted to be able to grab the current price off of the exchange I use (coinbase)

1
2
3
4
5
6
7
8
9
require 'json'
require 'open-uri'

JSON.parse(
      open("https://www.coinbase.com").
      each_line.grep(/window\.exchange/).
      first.sub(/.*?=/, '').sub(/;\n$/, '')
      )["btc_to_usd"]
# => "843.0"

Granted this will explode hard if their page ever changes. But who cares, took like 5 minutes to write.

Comments