cryptocompare 0.2.0 → 0.3.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 +40 -8
- data/lib/cryptocompare.rb +2 -1
- data/lib/cryptocompare/price.rb +25 -26
- data/lib/cryptocompare/price_historical.rb +47 -0
- data/lib/cryptocompare/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4a7c86c44eb915bc9b55686b677cd0345deeb9
|
4
|
+
data.tar.gz: 6e83e131f26c3dc32811ef29760df2275418dc93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39f93ad0cb72542b9c456b0088dce7338415608dd8551a05eeb6075ade76b02fd41cf8e6ab3444dcf5be3867fb0dca6516f16407d5c915ab80f209d56dab2cef
|
7
|
+
data.tar.gz: c86d6af2d8e1e8847a3bfd90326e36c9aa32e18f7ab1e445f4e5fadc3c9bd0c109ac7ece61ee12ee3d84ccba01d56a25d5525ad6ecdf6addfb5d19a6b56bd9a5
|
data/README.md
CHANGED
@@ -29,56 +29,88 @@ To use Cryptocompare, just require it like so:
|
|
29
29
|
require 'cryptocompare'
|
30
30
|
```
|
31
31
|
|
32
|
-
|
32
|
+
### Price
|
33
33
|
|
34
|
-
|
34
|
+
Finds the currency price(s) of a given currency symbol. Really fast, 20-60 ms. Cached each 10 seconds.
|
35
|
+
|
36
|
+
**Examples:**
|
37
|
+
|
38
|
+
Convert cryptocurrency to fiat.
|
35
39
|
|
36
40
|
```ruby
|
37
41
|
Cryptocompare::Price.find('BTC', 'USD')
|
38
42
|
# => {"BTC"=>{"USD"=>2594.07}}
|
39
43
|
```
|
40
44
|
|
41
|
-
|
45
|
+
Convert fiat to cryptocurrency.
|
42
46
|
|
43
47
|
```ruby
|
44
48
|
Cryptocompare::Price.find('USD', 'BTC')
|
45
49
|
# => {"USD"=>{"BTC"=>0.0004176}}
|
46
50
|
```
|
47
|
-
|
51
|
+
|
52
|
+
Convert cryptocurrency to cryptocurrency.
|
48
53
|
|
49
54
|
```ruby
|
50
55
|
Cryptocompare::Price.find('BTC', 'ETH')
|
51
56
|
# =>{"BTC"=>{"ETH"=>9.29}}
|
52
57
|
```
|
53
58
|
|
54
|
-
|
59
|
+
Convert fiat to fiat.
|
55
60
|
|
56
61
|
```ruby
|
57
62
|
Cryptocompare::Price.find('USD', 'EUR')
|
58
63
|
# => {"USD"=>{"EUR"=>0.8772}}
|
59
64
|
```
|
60
65
|
|
61
|
-
|
66
|
+
Convert multiple cryptocurrencies to multiple fiat.
|
62
67
|
|
63
68
|
```ruby
|
64
69
|
Cryptocompare::Price.find(['BTC','ETH', 'LTC'], ['USD', 'EUR', 'CNY'])
|
65
70
|
# => {"BTC"=>{"USD"=>2501.61, "EUR"=>2197.04, "CNY"=>17329.48}, "ETH"=>{"USD"=>236.59, "EUR"=>209.39, "CNY"=>1655.15}, "LTC"=>{"USD"=>45.74, "EUR"=>40.33, "CNY"=>310.5}}
|
66
71
|
```
|
67
72
|
|
68
|
-
|
73
|
+
Convert multiple fiat to multiple cryptocurrencies.
|
69
74
|
|
70
75
|
```ruby
|
71
76
|
Cryptocompare::Price.find(['USD', 'EUR'], ['BTC','ETH', 'LTC'])
|
72
77
|
# => {"USD"=>{"BTC"=>0.0003996, "ETH"=>0.004238, "LTC"=>0.02184}, "EUR"=>{"BTC"=>0.0004548, "ETH"=>0.00477, "LTC"=>0.0248}}
|
73
78
|
```
|
74
79
|
|
75
|
-
|
80
|
+
Convert prices based on exchange.
|
76
81
|
|
77
82
|
```ruby
|
78
83
|
Cryptocompare::Price.find('DASH', 'USD', {'e' => 'Kraken'})
|
79
84
|
# => {"DASH"=>{"USD"=>152.4}}
|
80
85
|
```
|
81
86
|
|
87
|
+
### PriceHistorical
|
88
|
+
|
89
|
+
Finds the price of any cryptocurrency in any other currency that you need at a given timestamp. The price comes from the daily info - so it would be the price at the end of the day GMT based on the requested timestamp. If the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. Tries to get direct trading pair data, if there is none or it is more than 30 days before the ts requested, it uses BTC conversion. If the opposite pair trades we invert it (eg.: BTC-XMR)
|
90
|
+
|
91
|
+
**Examples:**
|
92
|
+
|
93
|
+
Find historical price of cryptocurrency.
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Cryptocompare::PriceHistorical.find('ETH', 'USD')
|
97
|
+
# => {"ETH"=>{"USD"=>225.93}}
|
98
|
+
```
|
99
|
+
|
100
|
+
Find historical price of cryptocurrency at a given timestamp.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Cryptocompare::PriceHistorical.find('ETH', 'USD', {'ts' => 1452680400})
|
104
|
+
# => {"ETH"=>{"USD"=>223.2}}
|
105
|
+
```
|
106
|
+
|
107
|
+
Find historical price of cryptocurrency in many currencies at a given timestamp.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
Cryptocompare::PriceHistorical.find('ETH', ['BTC', 'USD', 'EUR'], {'ts' => '1452680400')
|
111
|
+
# => {"ETH"=>{"BTC"=>0.08006, "USD"=>225.93, "EUR"=>194.24}}
|
112
|
+
```
|
113
|
+
|
82
114
|
## Supported Exchanges
|
83
115
|
|
84
116
|
* BTC38
|
data/lib/cryptocompare.rb
CHANGED
data/lib/cryptocompare/price.rb
CHANGED
@@ -3,53 +3,52 @@ require 'json'
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module Cryptocompare
|
6
|
-
API_URL = 'https://min-api.cryptocompare.com/data/pricemulti'
|
7
6
|
EXCHANGES = YAML::load_file(File.join(__dir__, '../../config/exchanges.yml'))
|
8
7
|
|
9
8
|
module Price
|
10
|
-
|
9
|
+
API_URL = 'https://min-api.cryptocompare.com/data/pricemulti'
|
10
|
+
|
11
|
+
# Finds the currency price(s) of a given currency symbol. Really fast,
|
12
|
+
# 20-60 ms. Cached each 10 seconds.
|
11
13
|
#
|
12
14
|
# Params:
|
13
15
|
# from_syms [String, Array] - currency symbols (ex: 'BTC', 'ETH', 'LTC', 'USD', 'EUR', 'CNY')
|
14
16
|
# to_syms [String, Array] - currency symbols (ex: 'USD', 'EUR', 'CNY', 'USD', 'EUR', 'CNY')
|
15
|
-
# opts [Hash]
|
16
|
-
# opts[e] [String]
|
17
|
+
# opts [Hash] - options hash
|
18
|
+
# opts[e] [String] - name of exchange (ex: 'Coinbase','Poloniex') Default: CCCAGG.
|
17
19
|
#
|
18
20
|
# Returns:
|
19
21
|
# [Hash] Hash with currency prices
|
20
22
|
#
|
21
23
|
# Examples:
|
22
|
-
# 1. Cryptocurrency to Fiat
|
23
24
|
#
|
24
|
-
#
|
25
|
-
#
|
25
|
+
# Convert cryptocurrency to fiat.
|
26
|
+
#
|
27
|
+
# Cryptocompare::Price.find('BTC', 'USD') #=> {"BTC"=>{"USD"=>2594.07}}
|
28
|
+
#
|
29
|
+
# Convert fiat to cryptocurrency.
|
30
|
+
#
|
31
|
+
# Cryptocompare::Price.find('USD', 'BTC') #=> {"USD"=>{"BTC"=>0.0004176}}
|
32
|
+
#
|
33
|
+
# Convert cryptocurrency to cryptocurrency.
|
34
|
+
#
|
35
|
+
# Cryptocompare::Price.find('BTC', 'ETH') #=>{"BTC"=>{"ETH"=>9.29}}
|
26
36
|
#
|
27
|
-
#
|
37
|
+
# Convert fiat to fiat.
|
28
38
|
#
|
29
|
-
#
|
30
|
-
# => {"USD"=>{"BTC"=>0.0004176}}
|
39
|
+
# Cryptocompare::Price.find('USD', 'EUR') #=> {"USD"=>{"EUR"=>0.8772}}
|
31
40
|
#
|
32
|
-
#
|
41
|
+
# Convert multiple cryptocurrencies to multiple fiat.
|
33
42
|
#
|
34
|
-
#
|
35
|
-
# =>{"BTC"=>{"ETH"=>9.29}}
|
43
|
+
# Cryptocompare::Price.find(['BTC','ETH', 'LTC'], ['USD', 'EUR', 'CNY']) #=> {"BTC"=>{"USD"=>2501.61, "EUR"=>2197.04, "CNY"=>17329.48}, "ETH"=>{"USD"=>236.59, "EUR"=>209.39, "CNY"=>1655.15}, "LTC"=>{"USD"=>45.74, "EUR"=>40.33, "CNY"=>310.5}}
|
36
44
|
#
|
37
|
-
#
|
38
|
-
# Cryptocompare::Price.find('USD', 'EUR')
|
39
|
-
# => {"USD"=>{"EUR"=>0.8772}}
|
45
|
+
# Convert multiple fiat to multiple cryptocurrencies.
|
40
46
|
#
|
41
|
-
#
|
42
|
-
# Cryptocompare::Price.find(['BTC','ETH', 'LTC'], ['USD', 'EUR', 'CNY'])
|
43
|
-
# => {"BTC"=>{"USD"=>2501.61, "EUR"=>2197.04, "CNY"=>17329.48}, "ETH"=>{"USD"=>236.59, "EUR"=>209.39, "CNY"=>1655.15}, "LTC"=>{"USD"=>45.74, "EUR"=>40.33, "CNY"=>310.5}}
|
47
|
+
# Cryptocompare::Price.find(['USD', 'EUR'], ['BTC','ETH', 'LTC']) #=> {"USD"=>{"BTC"=>0.0003996, "ETH"=>0.004238, "LTC"=>0.02184}, "EUR"=>{"BTC"=>0.0004548, "ETH"=>0.00477, "LTC"=>0.0248}}
|
44
48
|
#
|
45
|
-
#
|
46
|
-
# Cryptocompare::Price.find(['USD', 'EUR'], ['BTC','ETH', 'LTC'])
|
47
|
-
# => {"USD"=>{"BTC"=>0.0003996, "ETH"=>0.004238, "LTC"=>0.02184}, "EUR"=>{"BTC"=>0.0004548, "ETH"=>0.00477, "LTC"=>0.0248}}
|
49
|
+
# Find prices based on exchange.
|
48
50
|
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
# Cryptocompare::Price.find('DASH', 'USD', {'e' => 'Kraken'})
|
52
|
-
# # => {"DASH"=>{"USD"=>152.4}}
|
51
|
+
# Cryptocompare::Price.find('DASH', 'USD', {'e' => 'Kraken'}) #=> {"DASH"=>{"USD"=>152.4}}
|
53
52
|
def self.find(from_syms, to_syms, opts = {})
|
54
53
|
fsyms = Array(from_syms).join(',')
|
55
54
|
tsyms = Array(to_syms).join(',')
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Cryptocompare
|
6
|
+
module PriceHistorical
|
7
|
+
API_URL = 'https://min-api.cryptocompare.com/data/pricehistorical'
|
8
|
+
|
9
|
+
# Finds the price of any cryptocurrency in any other currency that you need
|
10
|
+
# at a given timestamp. The price comes from the daily info - so it would be
|
11
|
+
# the price at the end of the day GMT based on the requested timestamp. If
|
12
|
+
# the crypto does not trade directly into the toSymbol requested, BTC will
|
13
|
+
# be used for conversion. Tries to get direct trading pair data, if there is
|
14
|
+
# none or it is more than 30 days before the ts requested, it uses BTC
|
15
|
+
# conversion. If the opposite pair trades we invert it (eg.: BTC-XMR)
|
16
|
+
#
|
17
|
+
# Params:
|
18
|
+
# from_sym [String] - (required) currency symbol (ex: 'BTC', 'ETH', 'LTC', 'USD', 'EUR', 'CNY')
|
19
|
+
# to_syms [String, Array] - (required) currency symbol(s) (ex: 'USD', 'EUR', 'CNY', 'USD', 'EUR', 'CNY')
|
20
|
+
# opts [Hash] - (optional) options hash
|
21
|
+
# opts[ts] [String, Integer] - (optional) timestamp
|
22
|
+
#
|
23
|
+
# Returns:
|
24
|
+
# [Hash] Hash with currency prices
|
25
|
+
#
|
26
|
+
# Examples:
|
27
|
+
#
|
28
|
+
# Find historical price of cryptocurrency.
|
29
|
+
#
|
30
|
+
# Cryptocompare::PriceHistorical.find('ETH', 'USD') #=> {"ETH"=>{"USD"=>225.93}}
|
31
|
+
#
|
32
|
+
# Find historical price of cryptocurrency at a given timestamp.
|
33
|
+
#
|
34
|
+
# Cryptocompare::PriceHistorical.find('ETH', 'USD', {'ts' => 1452680400}) #=> {"ETH"=>{"USD"=>223.2}}
|
35
|
+
#
|
36
|
+
# Find historical price of cryptocurrency in many currencies at a given timestamp.
|
37
|
+
#
|
38
|
+
# Cryptocompare::PriceHistorical.find('ETH', ['BTC', 'USD', 'EUR'], {'ts' => '1452680400') #=> {"ETH"=>{"BTC"=>0.08006, "USD"=>225.93, "EUR"=>194.24}}
|
39
|
+
def self.find(from_sym, to_syms, opts = {})
|
40
|
+
tsyms = Array(to_syms).join(',')
|
41
|
+
full_path = API_URL + "?fsym=#{from_sym}&tsyms=#{tsyms}"
|
42
|
+
full_path += "&ts=#{opts['ts']}" if opts['ts']
|
43
|
+
api_resp = Faraday.get(full_path)
|
44
|
+
JSON.parse(api_resp.body)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptocompare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander David Pan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- cryptocompare.gemspec
|
129
129
|
- lib/cryptocompare.rb
|
130
130
|
- lib/cryptocompare/price.rb
|
131
|
+
- lib/cryptocompare/price_historical.rb
|
131
132
|
- lib/cryptocompare/version.rb
|
132
133
|
homepage: https://github.com/alexanderdavidpan/cryptocompare
|
133
134
|
licenses:
|