rcbp 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/bin/rcbp +2 -1
- data/lib/rcbp.rb +19 -5
- data/lib/rcbp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f99710604bba642f1fb7a21d381021805f688240
|
4
|
+
data.tar.gz: c3cdbf1584b737356cd07578a67f4d4e3dc20a72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34b6ae0a3c2e1b55b4b75dc9eb87bf9ff63132dffa5f3b460846645ff0c59454696f54bca014405184a46dd53f8c290c387ae1a37cd1947989e3c77d5cdb528c
|
7
|
+
data.tar.gz: f8daa2b1cd5d5e88205ae7396592ab62191eab392b4b95204cf0f9be9112b32422ced236da7bcddd38d9aa1e1bf3ee885c252cd80c8b62aa3f6af97efb160c86
|
data/README.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
|
-
# rcbp
|
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: " +
|
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
|
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
|
-
|
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
|
37
|
-
|
38
|
-
|
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