rcbp 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -1
  3. data/bin/rcbp +2 -1
  4. data/lib/rcbp.rb +19 -5
  5. data/lib/rcbp/version.rb +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f3feb2501f215fd9e7d814c0a1bff7a6b9fd92c
4
- data.tar.gz: 4ec1ab92e3f51bc2514db40b2154231efe11510d
3
+ metadata.gz: f99710604bba642f1fb7a21d381021805f688240
4
+ data.tar.gz: c3cdbf1584b737356cd07578a67f4d4e3dc20a72
5
5
  SHA512:
6
- metadata.gz: d238ac1207362358a00c945545866f03fba67ff5ef8de67e7b87de4d57b3b2837c10cedaedc2f3f9b58f3c867075df84cd0cacf74a33a9eb4182042416c89989
7
- data.tar.gz: 43ae74b486ce04a7842478907676384bf83b09f1b2be6161822e4e8a806275eca0bbf1a5cab818ccc22703ce90d1a495c98a909333b3bd6905cc7ff2bd719a34
6
+ metadata.gz: 34b6ae0a3c2e1b55b4b75dc9eb87bf9ff63132dffa5f3b460846645ff0c59454696f54bca014405184a46dd53f8c290c387ae1a37cd1947989e3c77d5cdb528c
7
+ data.tar.gz: f8daa2b1cd5d5e88205ae7396592ab62191eab392b4b95204cf0f9be9112b32422ced236da7bcddd38d9aa1e1bf3ee885c252cd80c8b62aa3f6af97efb160c86
data/README.md CHANGED
@@ -1,6 +1,27 @@
1
- # rcbp – Simple Ruby CLI for fetching prices from Coinbase
1
+ # rcbp
2
+ Simple ruby CLI for fetching prices from Coinbase
2
3
 
3
4
  This is a personal project for learning Ruby. It fetches current BTC/USD prices from Coinbase through its json API.
4
5
  It is inspired by [btcl](https://github.com/jawerty/btcl), which lets you retrieve market prices from *bitcoincharts*.
6
+ ```
7
+ $ rcbp
5
8
 
9
+ Current prices on Coinbase:
10
+ (22:44:11)
11
+
12
+ ---
13
+
14
+ Spot: 264.25 USD
15
+ Buy: 267.24 USD
16
+ Sell: 261.77 USD
17
+
18
+ ```
19
+
20
+ ## Install
21
+ Install via rubygems
22
+ ```
23
+ $ gem install rcbp
24
+ ```
25
+
26
+ ## Usage
6
27
  `rcbp` lists spot, buy and sell prices. You can access the different prices through `rcbp spot`, `rcbp buy` and `rcbp sell`.
data/bin/rcbp CHANGED
@@ -9,9 +9,10 @@ class RCBP < Thor
9
9
  puts "\nCurrent prices on Coinbase:\n"\
10
10
  "(#{time})\n\n"\
11
11
  "---\n\n"\
12
- "Spot: " + blue(getSpotPrice) + "\n"\
12
+ "Spot: " + setColor(getSpotPrice) + "\n"\
13
13
  "Buy: #{getBuyPrice}\n"\
14
14
  "Sell: #{getSellPrice}\n\n"
15
+ getHistoricalPrice
15
16
  end
16
17
 
17
18
  desc "spot", "Get the spot price"
data/lib/rcbp.rb CHANGED
@@ -2,6 +2,8 @@ require "open-uri"
2
2
  require 'net/http'
3
3
  require "json"
4
4
  require "thor"
5
+ require "csv"
6
+ require "rcbp/version"
5
7
 
6
8
  def getPrice(url)
7
9
  amount = String.new
@@ -13,7 +15,7 @@ def getPrice(url)
13
15
  currency = json["currency"]
14
16
  end
15
17
 
16
- return "#{amount} #{currency}"
18
+ return amount
17
19
  end
18
20
 
19
21
  def getSpotPrice
@@ -28,12 +30,24 @@ def getSellPrice
28
30
  return getPrice("https://api.coinbase.com/v1/prices/sell?qty=1")
29
31
  end
30
32
 
31
- # Text in der Console färben
33
+ def getHistoricalPrice
34
+ csv = String.new
35
+ open("https://api.coinbase.com/v1/prices/historical") do |d|
36
+ csv = CSV.parse(d.read, :col_sep => ",", :headers => "false")
37
+ return csv[200][1]
38
+ end
39
+ end
40
+
32
41
  def colorize(text, color_code)
33
42
  "\e[#{color_code}m#{text}\e[0m"
34
43
  end
35
44
 
36
- def red(text); colorize(text, 31); end
37
- def green(text); colorize(text, 32); end
38
- def blue(text); colorize(text, 34); end
45
+ def setColor(text)
46
+ # If price went down, set text to red and vice versa to green
47
+ if getHistoricalPrice.to_f >= getSpotPrice.to_f
48
+ colorize(text, 31)
49
+ else
50
+ colorize(text, 32)
51
+ end
52
+ end
39
53
 
data/lib/rcbp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rcbp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcbp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Weggen