btcl 0.0.1
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.
- checksums.yaml +7 -0
- data/bin/btcl +2 -0
- data/lib/btcl.rb +131 -0
- metadata +61 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 34b08a9acf5c4b9e503f507139543913205ef1d1
|
|
4
|
+
data.tar.gz: bf98882fa645e44e48d1244a626e337dbf340583
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8ac1870cc0435c7ffbf3c1cfde90a06883670ce0510f96f306f60059d4811b3aa116aceccf76b827c8ed611038ebebd9edaf4d348f3d966fab5b01c10d9e06eb
|
|
7
|
+
data.tar.gz: 0bce9ba4a8d024ab042560469dfcfc12b2935e618d71c9600d8baf6226cc333a9755cf1a0edffa4ae2590f7bad1989ae9b345ee5a9eff1183f1703d56d3b744e
|
data/bin/btcl
ADDED
data/lib/btcl.rb
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require "optparse"
|
|
3
|
+
require "open-uri"
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require "json"
|
|
6
|
+
require 'text-table'
|
|
7
|
+
|
|
8
|
+
$top = {
|
|
9
|
+
"BTC CHINA" => "btcnCNY",
|
|
10
|
+
"Mt. Gox USA" => "mtgoxUSD",
|
|
11
|
+
"BitStamp" => "bitstampUSD",
|
|
12
|
+
"btc-e" => "btceUSD",
|
|
13
|
+
"Mt.Gox EUROPE" => "mtgoxEUR",
|
|
14
|
+
"Mt.Gox JAPAN" => "mtgoxJPY",
|
|
15
|
+
"bitcoin.de" => "btcdeEUR",
|
|
16
|
+
"Bitcurex" => "bitcurexPLN",
|
|
17
|
+
"Canadian Virtual Exchange" => "virtexCAD",
|
|
18
|
+
"Mt.Gox UK" => "mtgoxGBP"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
table = Text::Table.new :horizontal_padding => 1,
|
|
22
|
+
:vertical_boundary => '-',
|
|
23
|
+
:horizontal_boundary => '|',
|
|
24
|
+
:boundary_intersection => '-'
|
|
25
|
+
|
|
26
|
+
def getTop(url)
|
|
27
|
+
exchanges = []
|
|
28
|
+
names = []
|
|
29
|
+
begin
|
|
30
|
+
open(url) do |d|
|
|
31
|
+
json = JSON.parse(d.read)
|
|
32
|
+
$top.each do |k, v|
|
|
33
|
+
json.each do |a|
|
|
34
|
+
if a.has_value?(v)
|
|
35
|
+
exchanges << a
|
|
36
|
+
names << k
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
return true, exchanges, names
|
|
42
|
+
end
|
|
43
|
+
rescue SocketError => e
|
|
44
|
+
return false, "bity Error: Could not connect to bitcoincharts API."
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def getEx(url, symbol)
|
|
50
|
+
begin
|
|
51
|
+
open(url) do |d|
|
|
52
|
+
json = JSON.parse(d.read)
|
|
53
|
+
json.each do |a|
|
|
54
|
+
a.each do |k, v|
|
|
55
|
+
if k == "symbol" and v == symbol
|
|
56
|
+
return true, a
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
return false, "bity Error: Symbol not found in bitcoin API."
|
|
61
|
+
end
|
|
62
|
+
rescue SocketError => e
|
|
63
|
+
return false, "bity Error: Could not connect to bitcoincharts API."
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
options = {}
|
|
69
|
+
|
|
70
|
+
OptionParser.new do |opt|
|
|
71
|
+
opt.banner = "Usage: btcl <SYMBOL> [options]"
|
|
72
|
+
opt.separator ""
|
|
73
|
+
opt.separator "Exchange Symbols:"
|
|
74
|
+
opt.separator "\tView all symbols at http://bitcoincharts.com/markets/"
|
|
75
|
+
opt.separator "\t*Popular markets below*"
|
|
76
|
+
opt.separator ""
|
|
77
|
+
opt.separator "\tmtgoxUSD - Mt.Gox USA"
|
|
78
|
+
opt.separator "\tbtcnCHY - BTC CHINA"
|
|
79
|
+
opt.separator "\tbitstampUSD - BitStamp USA"
|
|
80
|
+
opt.separator "\tbtceUSD - btc-e USA"
|
|
81
|
+
opt.separator "\tmtgoxEUR - Mt.Gox EUROPE"
|
|
82
|
+
opt.separator "\tmtgoxJPY - Mt.Gox JAPAN"
|
|
83
|
+
opt.separator "\tbtcdeEUR - bitcoin.de"
|
|
84
|
+
opt.separator "\tbitcurexPLN - Bitcurex"
|
|
85
|
+
opt.separator "\tvirtexCAD - Canadian Virtual Exchange"
|
|
86
|
+
opt.separator "\tmtgoxGBP - Mt.Gox UK"
|
|
87
|
+
opt.separator ""
|
|
88
|
+
opt.separator "Options"
|
|
89
|
+
opt.separator " -h, --help: See this screen"
|
|
90
|
+
|
|
91
|
+
opt.on("-v", "--[no-]verbose", "Get information verbosely.") do |v|
|
|
92
|
+
options[:verbose] = v
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end.parse!
|
|
96
|
+
|
|
97
|
+
case ARGV[0]
|
|
98
|
+
when nil
|
|
99
|
+
info = getTop("http://api.bitcoincharts.com/v1/markets.json")
|
|
100
|
+
if options[:verbose]
|
|
101
|
+
puts "bity Error: There's no verbose option for the top exchanges."
|
|
102
|
+
Process.exit(0)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
if info[0] == false
|
|
106
|
+
puts info[1]
|
|
107
|
+
else
|
|
108
|
+
table.head = ["Exchange", "Price"]
|
|
109
|
+
info[1].each_with_index do |quote, i|
|
|
110
|
+
message = "%s" % quote["ask"]
|
|
111
|
+
verbose_message = "high :: %s\t\tlow :: %s\nask :: %s\t\tbid :: %s\nclose :: %s\t\t\tavg :: %s" % [quote["high"], quote["low"], quote["ask"], quote["bid"], quote["close"], quote["avg"]]
|
|
112
|
+
table.rows << [info[2][i], message]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
puts table.to_s
|
|
116
|
+
end
|
|
117
|
+
else
|
|
118
|
+
info = getEx("http://api.bitcoincharts.com/v1/markets.json", ARGV[0])
|
|
119
|
+
if info[0] == false
|
|
120
|
+
puts info[1]
|
|
121
|
+
elsif info[0] == true
|
|
122
|
+
quote = info[1]
|
|
123
|
+
message = "%s" % quote["ask"]
|
|
124
|
+
table.rows = [["high", quote["high"].to_s],["low", quote["low"]], ["ask", quote["ask"]], ["bid", quote["bid"]], ["close", quote["close"]], ["avg", quote["avg"]] ]
|
|
125
|
+
if options[:verbose]
|
|
126
|
+
puts table.to_s
|
|
127
|
+
else
|
|
128
|
+
puts message
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: btcl
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jared Wright
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: text-table
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: Follow Bitcoin markets from your terminal. btcl is a Bitcoin Market Price
|
|
28
|
+
Client that uses bitcoin markets api to retrieve real-time data.
|
|
29
|
+
email: jawerty210@gmail.com
|
|
30
|
+
executables:
|
|
31
|
+
- btcl
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- lib/btcl.rb
|
|
36
|
+
- bin/btcl
|
|
37
|
+
homepage: https://github.com/jawerty/btcl
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata: {}
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - '>='
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 1.8.5
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubyforge_project: btcl
|
|
57
|
+
rubygems_version: 2.0.3
|
|
58
|
+
signing_key:
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: A cli for retrieving prices from Bitcoin exchanges.
|
|
61
|
+
test_files: []
|