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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58a7edd2c27081e3d18bd5a9c5f55bd4d6188ed1
4
- data.tar.gz: 4d975e8065f816ebd0a4fd29a8fabcf01d62cb52
3
+ metadata.gz: 3d4a7c86c44eb915bc9b55686b677cd0345deeb9
4
+ data.tar.gz: 6e83e131f26c3dc32811ef29760df2275418dc93
5
5
  SHA512:
6
- metadata.gz: 407a2341f2489649265710af467979b09646cf1c3180c24e6fe69a535b7cc078571b8d40f74cd561d00a41f3e6d32c2a4d1d0de4406d2d9aeef3d071b23b5594
7
- data.tar.gz: 2355645467ebc2f6f5f09ea8bbc484f553a3c72f2fc5dbac5c30583308164c8d2a9082bf6c078841016f3ca6fd9732c87f65a40f482e9f60e91f075258302ca7
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
- Examples:
32
+ ### Price
33
33
 
34
- 1. Cryptocurrency to Fiat
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
- 2. Fiat to Cryptocurrency
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
- 3. Cryptocurrency to Cryptocurrency
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
- 4. Fiat to Fiat
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
- 5. Multiple cryptocurrencies to multiple fiat
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
- 6. Multiple fiat to multiple cryptocurrencies
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
- 7. Find prices based on exchange
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
@@ -1,5 +1,6 @@
1
- require "cryptocompare/version"
1
+ require_relative "cryptocompare/version"
2
2
  require_relative "cryptocompare/price"
3
+ require_relative "cryptocompare/price_historical"
3
4
 
4
5
  module Cryptocompare
5
6
  end
@@ -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
- # Finds the currency price(s) of a given currency symbol
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] - Options hash
16
- # opts[e] [String] - name of exchange (ex: 'Coinbase','Poloniex') Default: CCCAGG.
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
- # Cryptocompare::Price.find('BTC', 'USD')
25
- # => {"BTC"=>{"USD"=>2594.07}}
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
- # 2. Fiat to Cryptocurrency
37
+ # Convert fiat to fiat.
28
38
  #
29
- # Cryptocompare::Price.find('USD', 'BTC')
30
- # => {"USD"=>{"BTC"=>0.0004176}}
39
+ # Cryptocompare::Price.find('USD', 'EUR') #=> {"USD"=>{"EUR"=>0.8772}}
31
40
  #
32
- # 3. Cryptocurrency to Cryptocurrency
41
+ # Convert multiple cryptocurrencies to multiple fiat.
33
42
  #
34
- # Cryptocompare::Price.find('BTC', 'ETH')
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
- # 4. Fiat to Fiat
38
- # Cryptocompare::Price.find('USD', 'EUR')
39
- # => {"USD"=>{"EUR"=>0.8772}}
45
+ # Convert multiple fiat to multiple cryptocurrencies.
40
46
  #
41
- # 5. Multiple cryptocurrencies to multiple fiat
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
- # 6. Multiple fiat to multiple cryptocurrencies
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
- # 7. Find prices based on exchange
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
@@ -1,3 +1,3 @@
1
1
  module Cryptocompare
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  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.2.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-17 00:00:00.000000000 Z
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: