bitcoin_ticker 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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +9 -0
- data/README.md +113 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/bitcoin_ticker.gemspec +25 -0
- data/lib/bitcoin_ticker.rb +6 -0
- data/lib/bitcoin_ticker/client.rb +47 -0
- data/lib/bitcoin_ticker/errors.rb +5 -0
- data/lib/bitcoin_ticker/exchange.rb +34 -0
- data/lib/bitcoin_ticker/exchanges/bitbay.rb +43 -0
- data/lib/bitcoin_ticker/exchanges/bitcurex.rb +43 -0
- data/lib/bitcoin_ticker/exchanges/bitmarket.rb +21 -0
- data/lib/bitcoin_ticker/exchanges/bitmarket24.rb +21 -0
- data/lib/bitcoin_ticker/exchanges/bitmaszyna.rb +43 -0
- data/lib/bitcoin_ticker/exchanges/bitstamp.rb +21 -0
- data/lib/bitcoin_ticker/exchanges/btce.rb +45 -0
- data/lib/bitcoin_ticker/exchanges/nevbit.rb +43 -0
- data/lib/bitcoin_ticker/rate.rb +26 -0
- data/lib/bitcoin_ticker/version.rb +3 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 131f64686a314a599b1d1aeec8dbfd9ced658d86
|
4
|
+
data.tar.gz: 3d91ab3d3f68bf110bae5f2f1318557f5a86a58d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de4efd993073dda6b4acd9b2b611cb7802832e04e6ede037189234e9b1f5557b7b1b365a4fe027811151839183dcae6f141f9693f33236ce80b5a04c116cff95
|
7
|
+
data.tar.gz: 19d7c9779473e244bbb6dfd811337fc58400f6bc41d2e1c0bf1fb4b4733b6650cfea98b28e430830e4414b218abd57e596690f65b3e3cb3d2b402a9a6853ce74
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# BitcoinTicker
|
2
|
+
|
3
|
+
[](https://travis-ci.org/tradziej/BitcoinTicker)
|
4
|
+
|
5
|
+
Wrapper for cryptocurrency (e.g. Bitcoin, Litecoin) price tickers.
|
6
|
+
|
7
|
+
Currently gem support following exchanges:
|
8
|
+
* BitBay (https://bitbay.net/)
|
9
|
+
|
10
|
+
| ticker | bitcurrency | currency |
|
11
|
+
|-------------------------------------------------------|-------------|---------------|
|
12
|
+
| BitcoinTicker::Bitbay.ticker(:bitcurrency, :currency) | BTC, LTC | PLN, USD, EUR |
|
13
|
+
|
14
|
+
* Bitcurex (https://bitcurex.com/)
|
15
|
+
|
16
|
+
| ticker | bitcurrency | currency |
|
17
|
+
|---------------------------------------------------------|-------------|---------------|
|
18
|
+
| BitcoinTicker::Bitcurex.ticker(:bitcurrency, :currency) | BTC, LTC | PLN, USD, EUR |
|
19
|
+
|
20
|
+
* BitMarket (https://www.bitmarket.pl/)
|
21
|
+
|
22
|
+
| ticker | bitcurrency | currency |
|
23
|
+
|----------------------------------------------------------|-------------|----------|
|
24
|
+
| BitcoinTicker::Bitmarket.ticker(:bitcurrency, :currency) | BTC, LTC | PLN |
|
25
|
+
|
26
|
+
* BitMarket24 (https://www.bitmarket24.pl/)
|
27
|
+
|
28
|
+
| ticker | bitcurrency | currency |
|
29
|
+
|------------------------------------------------------------|-------------|----------|
|
30
|
+
| BitcoinTicker::Bitmarket24.ticker(:bitcurrency, :currency) | BTC, LTC | PLN |
|
31
|
+
|
32
|
+
* bitmaszyna.pl (https://bitmaszyna.pl/)
|
33
|
+
|
34
|
+
| ticker | bitcurrency | currency |
|
35
|
+
|-----------------------------------------------------------|-------------|----------|
|
36
|
+
| BitcoinTicker::Bitmaszyna.ticker(:bitcurrency, :currency) | BTC, LTC | PLN |
|
37
|
+
|
38
|
+
* Bitstamp (https://www.bitstamp.net/)
|
39
|
+
|
40
|
+
| ticker | bitcurrency | currency |
|
41
|
+
|---------------------------------------------------------|-------------|----------|
|
42
|
+
| BitcoinTicker::Bitstamp.ticker(:bitcurrency, :currency) | BTC | USD |
|
43
|
+
|
44
|
+
* BTC-e (https://btc-e.com/)
|
45
|
+
|
46
|
+
| ticker | bitcurrency | currency |
|
47
|
+
|-----------------------------------------------------|-------------|---------------|
|
48
|
+
| BitcoinTicker::Btce.ticker(:bitcurrency, :currency) | BTC, LTC | USD, EUR, GBP |
|
49
|
+
|
50
|
+
* nevbit (https://nevbit.com/)
|
51
|
+
|
52
|
+
| ticker | bitcurrency | currency |
|
53
|
+
|-------------------------------------------------------|-------------|---------------|
|
54
|
+
| BitcoinTicker::Nevbit.ticker(:bitcurrency, :currency) | BTC, LTC | USD, EUR, GBP |
|
55
|
+
|
56
|
+
## Installation
|
57
|
+
|
58
|
+
Add this line to your application's Gemfile:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'bitcoin_ticker'
|
62
|
+
```
|
63
|
+
|
64
|
+
And then execute:
|
65
|
+
|
66
|
+
$ bundle
|
67
|
+
|
68
|
+
Or install it yourself as:
|
69
|
+
|
70
|
+
$ gem install bitcoin_ticker
|
71
|
+
|
72
|
+
## Usage
|
73
|
+
|
74
|
+
Fetch prices from the each exchange, e.g.
|
75
|
+
|
76
|
+
exchange = BitcoinTicker::Bitstamp.ticker(:btc, :usd)
|
77
|
+
#<BitcoinTicker::Rate:0x007fe10215c558
|
78
|
+
@ask=226.48,
|
79
|
+
@bid=226.3,
|
80
|
+
@bitcurrency=:btc,
|
81
|
+
@currency=:usd,
|
82
|
+
@high=226.99,
|
83
|
+
@last=226.5,
|
84
|
+
@low=221.81,
|
85
|
+
@timestamp=1430340454.0,
|
86
|
+
@volume=8873.2263,
|
87
|
+
@vwap=224.73>
|
88
|
+
|
89
|
+
Get rate attributes:
|
90
|
+
|
91
|
+
puts exchange.bitcurrency
|
92
|
+
puts exchange.currency
|
93
|
+
puts exchange.last
|
94
|
+
puts exchange.high
|
95
|
+
puts exchange.low
|
96
|
+
puts exchange.vwap
|
97
|
+
puts exchange.volume
|
98
|
+
puts exchange.bid
|
99
|
+
puts exchange.ask
|
100
|
+
|
101
|
+
## Development
|
102
|
+
|
103
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
104
|
+
|
105
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
1. Fork it ( https://github.com/[my-github-username]/bitcoin_ticker/fork )
|
110
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
111
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
112
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
113
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bitcoin_ticker"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bitcoin_ticker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bitcoin_ticker"
|
8
|
+
spec.version = BitcoinTicker::VERSION
|
9
|
+
spec.authors = ["Tomasz Radziejewski"]
|
10
|
+
spec.email = ["tomasz@radziejewski.pl"]
|
11
|
+
|
12
|
+
spec.description = %q{Wrapper for cryptocurrency (e.g. Bitcoin, Litecoin) price tickers.}
|
13
|
+
spec.summary = spec.description
|
14
|
+
spec.homepage = "https://github.com/tradziej/BitcoinTicker"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'openssl'
|
3
|
+
require 'uri'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module BitcoinTicker
|
8
|
+
class Client
|
9
|
+
def initialize(endpoint)
|
10
|
+
@uri = URI.parse(endpoint)
|
11
|
+
|
12
|
+
http
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(path)
|
16
|
+
response = request(path)
|
17
|
+
|
18
|
+
case response.code.to_i
|
19
|
+
when 200, 201
|
20
|
+
body = response.body ? JSON.parse(response.body, symbolize_names: true) : ""
|
21
|
+
OpenStruct.new(code: response.code, body: body)
|
22
|
+
when (400..499)
|
23
|
+
fail 'client error'
|
24
|
+
when (500..599)
|
25
|
+
fail 'server error'
|
26
|
+
end
|
27
|
+
rescue JSON::ParserError
|
28
|
+
response
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def http
|
33
|
+
@http ||= begin
|
34
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
35
|
+
http.use_ssl = @uri.scheme == 'https'
|
36
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
37
|
+
http
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def request(path)
|
42
|
+
request = Net::HTTP::Get.new(path)
|
43
|
+
|
44
|
+
@http.request(request)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
module Exchange
|
3
|
+
def ticker(bitcurrency, currency)
|
4
|
+
ensure_supported_bitcurrency(bitcurrency)
|
5
|
+
ensure_supported_currency(currency)
|
6
|
+
|
7
|
+
@bitcurrency = bitcurrency
|
8
|
+
@currency = currency
|
9
|
+
|
10
|
+
get_rate
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def get_rate
|
15
|
+
client = BitcoinTicker::Client.new(link)
|
16
|
+
|
17
|
+
response = client.get(ticker_endpoint)
|
18
|
+
|
19
|
+
BitcoinTicker::Rate.new(@bitcurrency, @currency, response[:body])
|
20
|
+
end
|
21
|
+
|
22
|
+
def ensure_supported_bitcurrency(bitcurrency)
|
23
|
+
unless self::SUPPORTED_BITCURRENCIES.include?(bitcurrency)
|
24
|
+
fail BitcoinTicker::UnsupportedBitcurrency, "#{bitcurrency} is not supported"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def ensure_supported_currency(currency)
|
29
|
+
unless self::SUPPORTED_CURRENCIES.include?(currency)
|
30
|
+
fail BitcoinTicker::UnsupportedCurrency, "#{currency} is not supported"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Bitbay
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc ltc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(pln usd eur)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"BitBay"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://bitbay.net/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/API/Public/#{@bitcurrency}#{@currency}/ticker.json"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
|
21
|
+
def self.get_rate
|
22
|
+
client = BitcoinTicker::Client.new(link)
|
23
|
+
|
24
|
+
response = client.get(ticker_endpoint)
|
25
|
+
|
26
|
+
BitcoinTicker::Rate.new(@bitcurrency, @currency, normalize_api_response(response[:body]))
|
27
|
+
end
|
28
|
+
private_class_method :get_rate
|
29
|
+
|
30
|
+
def self.normalize_api_response hash
|
31
|
+
{
|
32
|
+
last: hash[:last],
|
33
|
+
high: hash[:max],
|
34
|
+
low: hash[:min],
|
35
|
+
vwap: hash[:vwap],
|
36
|
+
volume: hash[:volume],
|
37
|
+
bid: hash[:bid],
|
38
|
+
ask: hash[:ask]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
private_class_method :normalize_api_response
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Bitcurex
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(pln eur usd)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"Bitcurex"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://bitcurex.com/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/api/#{@currency}/ticker.json"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
|
21
|
+
def self.get_rate
|
22
|
+
client = BitcoinTicker::Client.new(link)
|
23
|
+
|
24
|
+
response = client.get(ticker_endpoint)
|
25
|
+
|
26
|
+
BitcoinTicker::Rate.new(@bitcurrency, @currency, normalize_api_response(response[:body]))
|
27
|
+
end
|
28
|
+
private_class_method :get_rate
|
29
|
+
|
30
|
+
def self.normalize_api_response hash
|
31
|
+
{
|
32
|
+
last: hash[:last_tx_price_h],
|
33
|
+
high: hash[:highest_tx_price_h],
|
34
|
+
low: hash[:lowest_tx_price_h],
|
35
|
+
vwap: nil,
|
36
|
+
volume: hash[:total_volume_h],
|
37
|
+
bid: hash[:best_bid_h],
|
38
|
+
ask: hash[:best_ask_h]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
private_class_method :normalize_api_response
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Bitmarket
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc ltc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(pln)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"BitMarket"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://www.bitmarket.pl/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/json/#{@bitcurrency.upcase}#{@currency.upcase}/ticker.json"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Bitmarket24
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc ltc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(pln)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"BitMarket24"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://www.bitmarket24.pl/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/api/#{@bitcurrency.upcase}_#{@currency.upcase}/status.json"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Bitmaszyna
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc ltc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(pln)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"bitmaszyna.pl"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://bitmaszyna.pl/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/api/#{@bitcurrency.upcase}#{@currency.upcase}/ticker.json"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
|
21
|
+
def self.get_rate
|
22
|
+
client = BitcoinTicker::Client.new(link)
|
23
|
+
|
24
|
+
response = client.get(ticker_endpoint)
|
25
|
+
|
26
|
+
BitcoinTicker::Rate.new(@bitcurrency, @currency, normalize_api_response(response[:body]))
|
27
|
+
end
|
28
|
+
private_class_method :get_rate
|
29
|
+
|
30
|
+
def self.normalize_api_response hash
|
31
|
+
{
|
32
|
+
last: hash[:last],
|
33
|
+
high: hash[:high],
|
34
|
+
low: hash[:low],
|
35
|
+
vwap: hash[:vwap],
|
36
|
+
volume: hash[:volume1],
|
37
|
+
bid: hash[:bid],
|
38
|
+
ask: hash[:ask]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
private_class_method :normalize_api_response
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Bitstamp
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(usd)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"Bitstamp"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://www.bitstamp.net/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/api/ticker/"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Btce
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc ltc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(usd eur gbp)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"BTC-e"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://btc-e.com/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/api/3/ticker/#{@bitcurrency}_#{@currency}"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
|
21
|
+
def self.get_rate
|
22
|
+
client = BitcoinTicker::Client.new(link)
|
23
|
+
|
24
|
+
response = client.get(ticker_endpoint)
|
25
|
+
|
26
|
+
BitcoinTicker::Rate.new(@bitcurrency, @currency, normalize_api_response(response[:body]))
|
27
|
+
end
|
28
|
+
private_class_method :get_rate
|
29
|
+
|
30
|
+
def self.normalize_api_response hash
|
31
|
+
pair_name_sym = "#{@bitcurrency}_#{@currency}".to_sym
|
32
|
+
|
33
|
+
{
|
34
|
+
last: hash[pair_name_sym][:last],
|
35
|
+
high: hash[pair_name_sym][:high],
|
36
|
+
low: hash[pair_name_sym][:low],
|
37
|
+
vwap: nil,
|
38
|
+
volume: hash[pair_name_sym][:vol],
|
39
|
+
bid: hash[pair_name_sym][:buy],
|
40
|
+
ask: hash[pair_name_sym][:sell]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
private_class_method :normalize_api_response
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Nevbit
|
3
|
+
extend Exchange
|
4
|
+
|
5
|
+
SUPPORTED_BITCURRENCIES = %i(btc ltc)
|
6
|
+
SUPPORTED_CURRENCIES = %i(pln)
|
7
|
+
|
8
|
+
def self.name
|
9
|
+
"nevbit"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.link
|
13
|
+
"https://nevbit.com/"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.ticker_endpoint
|
17
|
+
"/data/#{@bitcurrency}#{@currency}/ticker.json"
|
18
|
+
end
|
19
|
+
private_class_method :ticker_endpoint
|
20
|
+
|
21
|
+
def self.get_rate
|
22
|
+
client = BitcoinTicker::Client.new(link)
|
23
|
+
|
24
|
+
response = client.get(ticker_endpoint)
|
25
|
+
|
26
|
+
BitcoinTicker::Rate.new(@bitcurrency, @currency, normalize_api_response(response[:body]))
|
27
|
+
end
|
28
|
+
private_class_method :get_rate
|
29
|
+
|
30
|
+
def self.normalize_api_response hash
|
31
|
+
{
|
32
|
+
last: hash[:last],
|
33
|
+
high: hash[:high],
|
34
|
+
low: hash[:low],
|
35
|
+
vwap: hash[:vwap],
|
36
|
+
volume: hash[:vol],
|
37
|
+
bid: hash[:buy],
|
38
|
+
ask: hash[:sell]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
private_class_method :normalize_api_response
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module BitcoinTicker
|
2
|
+
class Rate
|
3
|
+
attr_reader :bitcurrency, :currency, :last, :high, :low, :vwap, :volume, :bid, :ask
|
4
|
+
|
5
|
+
def initialize(bitcurrency, currency, rate_hash)
|
6
|
+
@bitcurrency = bitcurrency
|
7
|
+
@currency = currency
|
8
|
+
|
9
|
+
rate_hash.each do |key, value|
|
10
|
+
instance_variable_set("@#{key}", normalize_value(value))
|
11
|
+
end
|
12
|
+
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def normalize_value(value)
|
18
|
+
case value
|
19
|
+
when String, Numeric
|
20
|
+
sprintf('%.4f', value).to_f
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitcoin_ticker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomasz Radziejewski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Wrapper for cryptocurrency (e.g. Bitcoin, Litecoin) price tickers.
|
56
|
+
email:
|
57
|
+
- tomasz@radziejewski.pl
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- bitcoin_ticker.gemspec
|
71
|
+
- lib/bitcoin_ticker.rb
|
72
|
+
- lib/bitcoin_ticker/client.rb
|
73
|
+
- lib/bitcoin_ticker/errors.rb
|
74
|
+
- lib/bitcoin_ticker/exchange.rb
|
75
|
+
- lib/bitcoin_ticker/exchanges/bitbay.rb
|
76
|
+
- lib/bitcoin_ticker/exchanges/bitcurex.rb
|
77
|
+
- lib/bitcoin_ticker/exchanges/bitmarket.rb
|
78
|
+
- lib/bitcoin_ticker/exchanges/bitmarket24.rb
|
79
|
+
- lib/bitcoin_ticker/exchanges/bitmaszyna.rb
|
80
|
+
- lib/bitcoin_ticker/exchanges/bitstamp.rb
|
81
|
+
- lib/bitcoin_ticker/exchanges/btce.rb
|
82
|
+
- lib/bitcoin_ticker/exchanges/nevbit.rb
|
83
|
+
- lib/bitcoin_ticker/rate.rb
|
84
|
+
- lib/bitcoin_ticker/version.rb
|
85
|
+
homepage: https://github.com/tradziej/BitcoinTicker
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Wrapper for cryptocurrency (e.g. Bitcoin, Litecoin) price tickers.
|
109
|
+
test_files: []
|