cryptocompare 0.4.0 → 0.5.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: d20e62b88d867db1cbca707672c55176fc66517a
4
- data.tar.gz: ba8adf2091a559f4df530a0fac701335aa50bae6
3
+ metadata.gz: 3ac9166226c481cf02e4943f7ff9d340fad3102d
4
+ data.tar.gz: 2bed9e8d7c43a11b55bef587e08d3b505911154d
5
5
  SHA512:
6
- metadata.gz: 6341cad1ddd37cf355fac24ce4c61b37d7d75017b8b242f1fecf133e5f7ff2164c7178e21cbb4160cbab0acf12cbb124d1e4a77cb417cea5bf06b3f35593ef37
7
- data.tar.gz: 47a2e9f163e8bb860911e00403c345147c5f07676b92dbfcfd79cba61d88e97ce6eeac6aae81d3387229c8500ce69224eca66787504378ed8cb24bc1e4cc65d9
6
+ metadata.gz: ddf5f8016df804ec197f96604609b615e1773bb61f4c3334e33400ce6d32bc4f48ab6030a4b01ceabd788024628d94593ba935728eaa7df935de34dccab95333
7
+ data.tar.gz: 0bb7317bf99b124a0f0944e5365cfbbaf20526c195f94b7a8feb3451f4c6b9947909867721b622e06c691a6bd71b86582f4709d022f06d7bf80e6d100adc904f
data/README.md CHANGED
@@ -172,6 +172,38 @@ Cryptocompare::CoinSnapshot.find('BTC', 'USD')
172
172
  # }
173
173
  ```
174
174
 
175
+ ### TopPairs
176
+
177
+ Get top pairs by volume for a currency (always uses aggregated data). The number of pairs you get is the minimum of the limit you set (default 5) and the total number of pairs available.
178
+
179
+ **Examples:**
180
+
181
+ Find top pairs by trading volume for a given currency.
182
+
183
+ ```ruby
184
+ Cryptocompare::TopPairs.find('ETH')
185
+ # => {
186
+ # Response: "Success",
187
+ # Data: [
188
+ # {
189
+ # exchange: "CCCAGG",
190
+ # fromSymbol: "ETH",
191
+ # toSymbol: "USD",
192
+ # volume24h: 1310705.3005027298,
193
+ # volume24hTo: 288031723.3503975
194
+ # },
195
+ # {
196
+ # exchange: "CCCAGG",
197
+ # fromSymbol: "ETH",
198
+ # toSymbol: "BTC",
199
+ # volume24h: 978200.2198323006,
200
+ # volume24hTo: 77883.06190085363
201
+ # },
202
+ # ...
203
+ # ]
204
+ # }
205
+ ```
206
+
175
207
  ## Supported Exchanges
176
208
 
177
209
  * BTC38
@@ -2,6 +2,7 @@ require_relative "cryptocompare/version"
2
2
  require_relative "cryptocompare/coin_snapshot"
3
3
  require_relative "cryptocompare/price"
4
4
  require_relative "cryptocompare/price_historical"
5
+ require_relative "cryptocompare/top_pairs"
5
6
 
6
7
  module Cryptocompare
7
8
  end
@@ -1,6 +1,5 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
- require 'yaml'
4
3
 
5
4
  module Cryptocompare
6
5
  module CoinSnapshot
@@ -0,0 +1,12 @@
1
+ require 'yaml'
2
+
3
+ # Helper module for exchange names.
4
+ module ExchangeNameHelper
5
+ EXCHANGES = YAML::load_file(File.join(__dir__, '../../../config/exchanges.yml'))
6
+
7
+ # Helper method to overcome case-sensitive exchange name enforced by the API.
8
+ # If no supported exchange mapping is found, it will try user's input.
9
+ def self.set_exchange(exchange)
10
+ EXCHANGES[exchange.upcase] || exchange
11
+ end
12
+ end
@@ -1,11 +1,11 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
- require 'yaml'
3
+ require_relative 'helpers/exchange_name_helper'
4
4
 
5
5
  module Cryptocompare
6
- EXCHANGES = YAML::load_file(File.join(__dir__, '../../config/exchanges.yml'))
7
-
8
6
  module Price
7
+ extend ExchangeNameHelper
8
+
9
9
  API_URL = 'https://min-api.cryptocompare.com/data/pricemulti'
10
10
 
11
11
  # Finds the currency price(s) of a given currency symbol. Really fast,
@@ -62,17 +62,11 @@ module Cryptocompare
62
62
  fsyms = Array(from_syms).join(',')
63
63
  tsyms = Array(to_syms).join(',')
64
64
  full_path = API_URL + "?fsyms=#{fsyms}&tsyms=#{tsyms}"
65
- full_path += "&e=#{set_exchange(opts['e'])}" if opts['e']
65
+ if (exchange = opts['e'])
66
+ full_path += "&e=#{ExchangeNameHelper.set_exchange(exchange)}"
67
+ end
66
68
  api_resp = Faraday.get(full_path)
67
69
  JSON.parse(api_resp.body)
68
70
  end
69
-
70
- private
71
-
72
- # Helper method to overcome case-sensitive exchange name enforced by the API.
73
- # If no supported exchange mapping is found, it will try user's input.
74
- def self.set_exchange(exchange)
75
- EXCHANGES[exchange.upcase] || exchange
76
- end
77
71
  end
78
72
  end
@@ -1,6 +1,5 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
- require 'yaml'
4
3
 
5
4
  module Cryptocompare
6
5
  module PriceHistorical
@@ -0,0 +1,59 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Cryptocompare
5
+ module TopPairs
6
+ API_URL = 'https://min-api.cryptocompare.com/data/top/pairs'
7
+
8
+ # Get top pairs by volume for a currency (always uses aggregated data).
9
+ # The number of pairs you get is the minimum of the limit you set
10
+ # (default 5) and the total number of pairs available.
11
+ #
12
+ # ==== Parameters
13
+ #
14
+ # * +from_sym+ [String] - (required) currency symbol (ex: 'BTC', 'ETH', 'LTC', 'USD', 'EUR', 'CNY')
15
+ # * +opts+ [Hash] - (optional) options hash
16
+ #
17
+ # ==== Options
18
+ # * +limit+ [Integer] - (optional) limit. Default 5. Max 2000.
19
+ #
20
+ # ==== Returns
21
+ # [Hash] Returns a hash containing data as an array of hashes containing
22
+ # info about top-traded pairs.
23
+ #
24
+ # ==== Examples
25
+ #
26
+ # Find top pairs by trading volume for a given currency.
27
+ #
28
+ # Cryptocompare::TopPairs.find('ETH')
29
+ #
30
+ # Sample response
31
+ #
32
+ # {
33
+ # Response: "Success",
34
+ # Data: [
35
+ # {
36
+ # exchange: "CCCAGG",
37
+ # fromSymbol: "ETH",
38
+ # toSymbol: "USD",
39
+ # volume24h: 1310705.3005027298,
40
+ # volume24hTo: 288031723.3503975
41
+ # },
42
+ # {
43
+ # exchange: "CCCAGG",
44
+ # fromSymbol: "ETH",
45
+ # toSymbol: "BTC",
46
+ # volume24h: 978200.2198323006,
47
+ # volume24hTo: 77883.06190085363
48
+ # },
49
+ # ...
50
+ # ]
51
+ # }
52
+ def self.find(from_sym, opts = {})
53
+ full_path = API_URL + "?fsym=#{from_sym}"
54
+ full_path += "&limit=#{opts['limit']}" if opts['limit']
55
+ api_resp = Faraday.get(full_path)
56
+ JSON.parse(api_resp.body)
57
+ end
58
+ end
59
+ end
@@ -1,3 +1,3 @@
1
1
  module Cryptocompare
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.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.4.0
4
+ version: 0.5.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-31 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,8 +128,10 @@ files:
128
128
  - cryptocompare.gemspec
129
129
  - lib/cryptocompare.rb
130
130
  - lib/cryptocompare/coin_snapshot.rb
131
+ - lib/cryptocompare/helpers/exchange_name_helper.rb
131
132
  - lib/cryptocompare/price.rb
132
133
  - lib/cryptocompare/price_historical.rb
134
+ - lib/cryptocompare/top_pairs.rb
133
135
  - lib/cryptocompare/version.rb
134
136
  homepage: https://github.com/alexanderdavidpan/cryptocompare
135
137
  licenses: