cryptocompare 0.6.0 → 0.8.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: d00d76f9c9a92203e67633a4d76831db01273259
4
- data.tar.gz: c9bd0a4255153b1f2760021c9e7f654cb4dfaa3c
3
+ metadata.gz: 5904d15aafe69b345265133262f61f2644155957
4
+ data.tar.gz: 2e2aefc132bc419487894755aec41b4abf695fd3
5
5
  SHA512:
6
- metadata.gz: 906225c0c70ffec0e8ccfdafad3be6808c39720dc06277a38f14097ea94c53ccd8779e06f2fc53a668a903dff228bfdbbfb1168a9b6249bc90d48c7082fc3266
7
- data.tar.gz: ac27297ecb113ee31a83eb1767a47e6be39fc9f3b348c58bc8ce9c399a8a7c06f625831d1aa2515e6c995226b927a13ac11ac9454d550483435557eb2315e8b6
6
+ metadata.gz: 0ab351322c5f2a7044c451fb580d90bcb7e560de42c78d0c6df6d5104784256e2fca5b0a2fc94698ef9e1cd3fe0792e65aa8a1a67379a11f91697c5d4b017487
7
+ data.tar.gz: e8b84aa64788c9810f1ba7668497811f8c29c4c8df01c1d5b37bfd905e3e3627165adc87efeb68c65efc4a62ca7024e0356702482797cd37b2572ae66485d370
@@ -3,3 +3,9 @@ language: ruby
3
3
  rvm:
4
4
  - 2.0.0
5
5
  before_install: gem install bundler -v 1.12.5
6
+ addons:
7
+ code_climate:
8
+ repo_token: 69656235648d9fc861fdb7a11a06cf1481e3aae42c8381873f1b72341bdeac6c
9
+ # regular test configuration
10
+ after_success:
11
+ - bundle exec codeclimate-test-reporter
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cryptocompare.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "simplecov"
8
+ gem "codeclimate-test-reporter", "~> 1.0.0"
9
+ end
data/README.md CHANGED
@@ -67,7 +67,7 @@ Convert multiple cryptocurrencies to multiple fiat.
67
67
 
68
68
  ```ruby
69
69
  Cryptocompare::Price.find(['BTC','ETH', 'LTC'], ['USD', 'EUR', 'CNY'])
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}}
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}}
71
71
  ```
72
72
 
73
73
  Convert multiple fiat to multiple cryptocurrencies.
@@ -249,6 +249,51 @@ Cryptocompare::HistoMinute.find('BTC', 'USD')
249
249
  # }
250
250
  ```
251
251
 
252
+ ### HistoHour
253
+
254
+ Get open, high, low, close, volumefrom and volumeto from the each hour historical data. It uses BTC conversion if data is not available because the coin is not trading in the specified currency.
255
+
256
+ **Examples:**
257
+
258
+ Find historical data by hour for BTC to USD.
259
+
260
+ ```ruby
261
+ Cryptocompare::HistoHour.find('BTC', 'USD')
262
+ # => {
263
+ # Response: "Success",
264
+ # Type: 100,
265
+ # Aggregated: false,
266
+ # Data: [
267
+ # {
268
+ # time: 1502259120,
269
+ # close: 3396.44,
270
+ # high: 3397.63,
271
+ # low: 3396.34,
272
+ # open: 3397.39,
273
+ # volumefrom: 98.2,
274
+ # volumeto: 335485
275
+ # },
276
+ # {
277
+ # time: 1502259300,
278
+ # close: 3396.86,
279
+ # high: 3396.94,
280
+ # low: 3396.44,
281
+ # open: 3396.44,
282
+ # volumefrom: 16.581031,
283
+ # volumeto: 56637.869999999995
284
+ # },
285
+ # ...
286
+ # ],
287
+ # TimeTo: 1503248400,
288
+ # TimeFrom: 1502643600,
289
+ # FirstValueInArray: true,
290
+ # ConversionType: {
291
+ # type: "direct",
292
+ # conversionSymbol: ""
293
+ # }
294
+ # }
295
+ ```
296
+
252
297
  ## Supported Exchanges
253
298
 
254
299
  * BTC38
@@ -0,0 +1,12 @@
1
+ # Mapping of cryptocompare gem parameters to CryptoCompare API query parameters
2
+ agg: aggregate
3
+ all_data: allData
4
+ e: e
5
+ from_sym: fsym
6
+ from_syms: fsyms
7
+ limit: limit
8
+ tc: tryConversion
9
+ to_sym: tsym
10
+ to_syms: tsyms
11
+ to_ts: toTs
12
+ ts: ts
@@ -1,10 +1,10 @@
1
1
  require_relative "cryptocompare/version"
2
2
  require_relative "cryptocompare/coin_snapshot"
3
- require_relative "cryptocompare/histo_day"
4
3
  require_relative "cryptocompare/histo_hour"
5
4
  require_relative "cryptocompare/histo_minute"
6
5
  require_relative "cryptocompare/price"
7
6
  require_relative "cryptocompare/price_historical"
7
+ require_relative "cryptocompare/helpers/query_param_helper"
8
8
  require_relative "cryptocompare/top_pairs"
9
9
 
10
10
  module Cryptocompare
@@ -78,7 +78,12 @@ module Cryptocompare
78
78
  # }
79
79
  # }
80
80
  def self.find(from_sym, to_sym)
81
- full_path = API_URL + "?fsym=#{from_sym}&tsym=#{to_sym}"
81
+ params = {
82
+ 'from_sym' => from_sym,
83
+ 'to_sym' => to_sym
84
+ }
85
+
86
+ full_path = QueryParamHelper.set_query_params(API_URL, params)
82
87
  api_resp = Faraday.get(full_path)
83
88
  JSON.parse(api_resp.body)
84
89
  end
@@ -1,12 +1,14 @@
1
1
  require 'yaml'
2
2
 
3
3
  # Helper module for exchange names.
4
- module ExchangeNameHelper
5
- EXCHANGES = YAML::load_file(File.join(__dir__, '../../../config/exchanges.yml'))
4
+ module Cryptocompare
5
+ module ExchangeNameHelper
6
+ EXCHANGES = YAML::load_file(File.join(__dir__, '../../../config/exchanges.yml'))
6
7
 
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
8
+ # Helper method to overcome case-sensitive exchange name enforced by the API.
9
+ # If no supported exchange mapping is found, it will try user's input.
10
+ def self.set_exchange(exchange)
11
+ EXCHANGES[exchange.upcase] || exchange
12
+ end
11
13
  end
12
14
  end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+ require_relative 'exchange_name_helper'
3
+
4
+ # Helper module for setting query params.
5
+ module Cryptocompare
6
+ module QueryParamHelper
7
+ QUERY_PARAM_MAPPING = YAML::load_file(File.join(__dir__, '../../../config/query_param_mapping.yml'))
8
+
9
+ # Appends query parameters to path
10
+ def self.set_query_params(path, opts)
11
+ path + "?#{to_query(opts)}"
12
+ end
13
+
14
+ # Helper method to parse parameters and build query parameters
15
+ def self.to_query(opts)
16
+ opts.collect do |key, value|
17
+ value = ExchangeNameHelper.set_exchange(value) if key == 'e'
18
+ "#{QUERY_PARAM_MAPPING[key]}=#{value}"
19
+ end.sort * '&'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,82 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Cryptocompare
5
+ module HistoHour
6
+ API_URL = 'https://min-api.cryptocompare.com/data/histohour'
7
+
8
+ # Get open, high, low, close, volumefrom and volumeto from the each hour
9
+ # historical data. It uses BTC conversion if data is not available because
10
+ # the coin is not trading in the specified currency.
11
+ #
12
+ # ==== Parameters
13
+ #
14
+ # * +from_sym+ [String] - (required) currency symbol (ex: 'BTC', 'ETH', 'LTC', 'USD', 'EUR', 'CNY')
15
+ # * +to_syms+ [String, Array] - (required) currency symbol(s) (ex: 'USD', 'EUR', 'CNY', 'USD', 'EUR', 'CNY')
16
+ # * +opts+ [Hash] - (optional) options hash
17
+ #
18
+ # ==== Options
19
+ #
20
+ # * +e+ [String] - (optional) name of exchange (ex: 'Coinbase','Poloniex') Default: CCCAGG.
21
+ # * +limit+ [Integer] - (optional) limit. Default 168. Max 2000. Must be positive integer. Returns limit + 1 data points.
22
+ # * +agg+ [Integer] - (optional) number of data points to aggregate. Default 1.
23
+ # * +to_ts+ [Integer] - (optional) timestamp. Use the timestamp option to set a historical start point. By default, it gets historical data for the past several hours.
24
+ # * +tc+ [Boolean] - (optional) try conversion. Default true. If the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion.
25
+ #
26
+ # ==== Returns
27
+ #
28
+ # [Hash] Returns a hash containing data as an array of hashes containing
29
+ # info such as open, high, low, close, volumefrom and volumeto for
30
+ # each hour.
31
+ #
32
+ # ==== Examples
33
+ #
34
+ # Cryptocompare::HistoHour.find('BTC', 'USD')
35
+ #
36
+ # Sample response
37
+ #
38
+ # {
39
+ # Response: "Success",
40
+ # Type: 100,
41
+ # Aggregated: false,
42
+ # Data: [
43
+ # {
44
+ # time: 1502643600,
45
+ # close: 3998.47,
46
+ # high: 4069.8,
47
+ # low: 3982.5,
48
+ # open: 4059.28,
49
+ # volumefrom: 5087.23,
50
+ # volumeto: 20453919.02
51
+ # },
52
+ # {
53
+ # time: 1502647200,
54
+ # close: 4061.5,
55
+ # high: 4074.57,
56
+ # low: 3998.47,
57
+ # open: 3998.47,
58
+ # volumefrom: 3839.78,
59
+ # volumeto: 15606476.19
60
+ # },
61
+ # ...
62
+ # ],
63
+ # TimeTo: 1503248400,
64
+ # TimeFrom: 1502643600,
65
+ # FirstValueInArray: true,
66
+ # ConversionType: {
67
+ # type: "direct",
68
+ # conversionSymbol: ""
69
+ # }
70
+ # }
71
+ def self.find(from_sym, to_sym, opts = {})
72
+ params = {
73
+ 'from_sym' => from_sym,
74
+ 'to_sym' => to_sym
75
+ }.merge!(opts)
76
+
77
+ full_path = QueryParamHelper.set_query_params(API_URL, params)
78
+ api_resp = Faraday.get(full_path)
79
+ JSON.parse(api_resp.body)
80
+ end
81
+ end
82
+ end
@@ -1,11 +1,8 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
- require_relative 'helpers/exchange_name_helper'
4
3
 
5
4
  module Cryptocompare
6
5
  module HistoMinute
7
- extend ExchangeNameHelper
8
-
9
6
  API_URL = 'https://min-api.cryptocompare.com/data/histominute'
10
7
 
11
8
  # Get open, high, low, close, volumefrom and volumeto for each minute of
@@ -39,6 +36,8 @@ module Cryptocompare
39
36
  #
40
37
  # Cryptocompare::HistoMinute.find('BTC', 'USD')
41
38
  #
39
+ # Sample response
40
+ #
42
41
  # {
43
42
  # Response: "Success",
44
43
  # Type: 100,
@@ -73,28 +72,12 @@ module Cryptocompare
73
72
  # }
74
73
  # }
75
74
  def self.find(from_sym, to_sym, opts = {})
76
- full_path = API_URL + "?fsym=#{from_sym}&tsym=#{to_sym}"
77
-
78
- if (exchange = opts['e'])
79
- full_path += "&e=#{ExchangeNameHelper.set_exchange(exchange)}"
80
- end
81
-
82
- if (limit = opts['limit'])
83
- full_path += "&limit=#{limit}"
84
- end
85
-
86
- if (agg = opts['agg'])
87
- full_path += "&aggregate=#{agg}"
88
- end
89
-
90
- if (to_ts = opts['to_ts'])
91
- full_path += "&toTs=#{to_ts}"
92
- end
93
-
94
- if (opts['tc'] == false)
95
- full_path += "&tryConversion=false"
96
- end
75
+ params = {
76
+ 'from_sym' => from_sym,
77
+ 'to_sym' => to_sym
78
+ }.merge!(opts)
97
79
 
80
+ full_path = QueryParamHelper.set_query_params(API_URL, params)
98
81
  api_resp = Faraday.get(full_path)
99
82
  JSON.parse(api_resp.body)
100
83
  end
@@ -1,11 +1,8 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
- require_relative 'helpers/exchange_name_helper'
4
3
 
5
4
  module Cryptocompare
6
5
  module Price
7
- extend ExchangeNameHelper
8
-
9
6
  API_URL = 'https://min-api.cryptocompare.com/data/pricemulti'
10
7
 
11
8
  # Finds the currency price(s) of a given currency symbol. Really fast,
@@ -62,12 +59,12 @@ module Cryptocompare
62
59
  # Cryptocompare::Price.find('DASH', 'USD', {'e' => 'Kraken'})
63
60
  # #=> {"DASH"=>{"USD"=>152.4}}
64
61
  def self.find(from_syms, to_syms, opts = {})
65
- fsyms = Array(from_syms).join(',')
66
- tsyms = Array(to_syms).join(',')
67
- full_path = API_URL + "?fsyms=#{fsyms}&tsyms=#{tsyms}"
68
- if (exchange = opts['e'])
69
- full_path += "&e=#{ExchangeNameHelper.set_exchange(exchange)}"
70
- end
62
+ params = {
63
+ 'from_syms' => Array(from_syms).join(','),
64
+ 'to_syms' => Array(to_syms).join(',')
65
+ }.merge!(opts)
66
+
67
+ full_path = QueryParamHelper.set_query_params(API_URL, params)
71
68
  api_resp = Faraday.get(full_path)
72
69
  JSON.parse(api_resp.body)
73
70
  end
@@ -44,9 +44,12 @@ module Cryptocompare
44
44
  # Cryptocompare::PriceHistorical.find('ETH', ['BTC', 'USD', 'EUR'], {'ts' => '1452680400'})
45
45
  # #=> {"ETH"=>{"BTC"=>0.08006, "USD"=>225.93, "EUR"=>194.24}}
46
46
  def self.find(from_sym, to_syms, opts = {})
47
- tsyms = Array(to_syms).join(',')
48
- full_path = API_URL + "?fsym=#{from_sym}&tsyms=#{tsyms}"
49
- full_path += "&ts=#{opts['ts']}" if opts['ts']
47
+ params = {
48
+ 'from_sym' => from_sym,
49
+ 'to_syms' => Array(to_syms).join(',')
50
+ }.merge!(opts)
51
+
52
+ full_path = QueryParamHelper.set_query_params(API_URL, params)
50
53
  api_resp = Faraday.get(full_path)
51
54
  JSON.parse(api_resp.body)
52
55
  end
@@ -52,8 +52,11 @@ module Cryptocompare
52
52
  # ]
53
53
  # }
54
54
  def self.find(from_sym, opts = {})
55
- full_path = API_URL + "?fsym=#{from_sym}"
56
- full_path += "&limit=#{opts['limit']}" if opts['limit']
55
+ params = {
56
+ 'from_sym' => from_sym
57
+ }.merge!(opts)
58
+
59
+ full_path = QueryParamHelper.set_query_params(API_URL, params)
57
60
  api_resp = Faraday.get(full_path)
58
61
  JSON.parse(api_resp.body)
59
62
  end
@@ -1,3 +1,3 @@
1
1
  module Cryptocompare
2
- VERSION = "0.6.0"
2
+ VERSION = "0.8.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.6.0
4
+ version: 0.8.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-08-14 00:00:00.000000000 Z
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,10 +125,13 @@ files:
125
125
  - bin/console
126
126
  - bin/setup
127
127
  - config/exchanges.yml
128
+ - config/query_param_mapping.yml
128
129
  - cryptocompare.gemspec
129
130
  - lib/cryptocompare.rb
130
131
  - lib/cryptocompare/coin_snapshot.rb
131
132
  - lib/cryptocompare/helpers/exchange_name_helper.rb
133
+ - lib/cryptocompare/helpers/query_param_helper.rb
134
+ - lib/cryptocompare/histo_hour.rb
132
135
  - lib/cryptocompare/histo_minute.rb
133
136
  - lib/cryptocompare/price.rb
134
137
  - lib/cryptocompare/price_historical.rb
@@ -155,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
158
  version: '0'
156
159
  requirements: []
157
160
  rubyforge_project:
158
- rubygems_version: 2.0.14.1
161
+ rubygems_version: 2.4.8
159
162
  signing_key:
160
163
  specification_version: 4
161
164
  summary: A Ruby gem for communicating with the CryptoCompare API