cointools 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +22 -0
- data/bin/bitbay-price +49 -0
- data/lib/cointools.rb +1 -0
- data/lib/cointools/bitbay.rb +63 -0
- data/lib/cointools/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0219538fd4877d6e1ad63fa85d08bbb0acb478d7'
|
4
|
+
data.tar.gz: 9d88ae1fb52ac943bb8558d061b3f5cdccabc5bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f565cae695326dbe75e7d492a0da2dd5fd85709319c0a02426f03e0dc0d87a53c23e4412c92572099dfcd3d3154b0ce949f339b191ad49c25f7eb636b9f02c
|
7
|
+
data.tar.gz: 5f4018479cc8ccb897efc04b4c6ab66c86f7c801a2416c5202d13a9aa0783e4f215273709eac013e56cd1420a50fb4cdc052e6dbf1adb65b27485f8ac52fba8e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -107,6 +107,28 @@ puts "ETH: #{eth.converted_price} EUR"
|
|
107
107
|
```
|
108
108
|
|
109
109
|
|
110
|
+
## [BitBay](https://bitbay.net)
|
111
|
+
|
112
|
+
Returns ticker prices directly from the BitBay exchange, only current coin prices. Specify market name as coin symbol + currency.
|
113
|
+
|
114
|
+
```
|
115
|
+
bitbay-price btcusd
|
116
|
+
```
|
117
|
+
|
118
|
+
In code:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
require 'cointools' # or 'cointools/bitbay'
|
122
|
+
bitbay = CoinTools::BitBay.new
|
123
|
+
|
124
|
+
ltc = bitbay.get_price('ltcusd')
|
125
|
+
puts "LTC: #{ltc.price} USD"
|
126
|
+
|
127
|
+
btg = bitbay.get_price('btgbtc')
|
128
|
+
puts "BTG: #{btg.price} BTC"
|
129
|
+
```
|
130
|
+
|
131
|
+
|
110
132
|
## Credits & contributing
|
111
133
|
|
112
134
|
Copyright © 2018 [Kuba Suder](https://mackuba.eu). Licensed under [MIT License](http://opensource.org/licenses/MIT).
|
data/bin/bitbay-price
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'cointools'
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'time'
|
8
|
+
|
9
|
+
def print_help
|
10
|
+
puts "Usage: #{$PROGRAM_NAME} <market> [-v/--verbose]"
|
11
|
+
puts " e.g.: #{$PROGRAM_NAME} btcusd"
|
12
|
+
end
|
13
|
+
|
14
|
+
verbose = false
|
15
|
+
|
16
|
+
OptionParser.new do |opts|
|
17
|
+
opts.on('-v', '--verbose') { verbose = true }
|
18
|
+
|
19
|
+
opts.on('-h', '--help') do
|
20
|
+
print_help
|
21
|
+
exit 0
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.parse!
|
25
|
+
end
|
26
|
+
|
27
|
+
if ARGV.length != 1
|
28
|
+
print_help
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
market = ARGV[0].downcase
|
33
|
+
|
34
|
+
begin
|
35
|
+
result = CoinTools::BitBay.new.get_price(market)
|
36
|
+
|
37
|
+
if verbose
|
38
|
+
puts "#{market.upcase} @ #{Time.now} ==> #{result.price}"
|
39
|
+
puts
|
40
|
+
else
|
41
|
+
puts result.price
|
42
|
+
end
|
43
|
+
rescue CoinTools::BitBay::ErrorResponseException => e
|
44
|
+
$stderr.puts "Error: #{e}"
|
45
|
+
exit 2
|
46
|
+
rescue CoinTools::BitBay::BadRequestException => e
|
47
|
+
$stderr.puts "Error: Incorrect market name (#{e})"
|
48
|
+
exit 3
|
49
|
+
end
|
data/lib/cointools.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'version'
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module CoinTools
|
8
|
+
class BitBay
|
9
|
+
BASE_URL = "https://bitbay.net/API/Public"
|
10
|
+
USER_AGENT = "cointools/#{CoinTools::VERSION}"
|
11
|
+
|
12
|
+
DataPoint = Struct.new(:price, :time)
|
13
|
+
|
14
|
+
class InvalidResponseException < StandardError
|
15
|
+
attr_reader :response
|
16
|
+
|
17
|
+
def initialize(response)
|
18
|
+
super("#{response.code} #{response.message}")
|
19
|
+
@response = response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class BadRequestException < InvalidResponseException
|
24
|
+
end
|
25
|
+
|
26
|
+
class ErrorResponseException < StandardError
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_price(market)
|
30
|
+
url = URI("#{BASE_URL}/#{market}/ticker.json")
|
31
|
+
|
32
|
+
response = make_request(url)
|
33
|
+
|
34
|
+
case response
|
35
|
+
when Net::HTTPSuccess
|
36
|
+
json = JSON.load(response.body)
|
37
|
+
|
38
|
+
if json['code']
|
39
|
+
raise ErrorResponseException.new("#{json['code']} #{json['message']}")
|
40
|
+
end
|
41
|
+
|
42
|
+
price = json['last']
|
43
|
+
|
44
|
+
return DataPoint.new(price, nil)
|
45
|
+
when Net::HTTPBadRequest
|
46
|
+
raise BadRequestException.new(response)
|
47
|
+
else
|
48
|
+
raise InvalidResponseException.new(response)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def make_request(url)
|
55
|
+
Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
56
|
+
request = Net::HTTP::Get.new(url)
|
57
|
+
request['User-Agent'] = USER_AGENT
|
58
|
+
|
59
|
+
http.request(request)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/cointools/version.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cointools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Suder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
15
15
|
- jakub.suder@gmail.com
|
16
16
|
executables:
|
17
|
+
- bitbay-price
|
17
18
|
- cryptowatch
|
18
19
|
- coinmcap
|
19
20
|
extensions: []
|
@@ -22,9 +23,11 @@ files:
|
|
22
23
|
- CHANGELOG.md
|
23
24
|
- MIT-LICENSE.txt
|
24
25
|
- README.md
|
26
|
+
- bin/bitbay-price
|
25
27
|
- bin/coinmcap
|
26
28
|
- bin/cryptowatch
|
27
29
|
- lib/cointools.rb
|
30
|
+
- lib/cointools/bitbay.rb
|
28
31
|
- lib/cointools/coinmarketcap.rb
|
29
32
|
- lib/cointools/cryptowatch.rb
|
30
33
|
- lib/cointools/version.rb
|