coincap 0.2.3 → 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
  SHA256:
3
- metadata.gz: 65af4f6edf23fd568e3318eb5ee35edcb8ea46b27372b1dc6f11895b8ba708e8
4
- data.tar.gz: 546d6841b22503e6b407c7e7dd6521100753d1e08d5232f0145d6ead92661dae
3
+ metadata.gz: 3804fc6897bedeab59d3433b78d966c9ead78b479ddda7fa68224dc82ab3269a
4
+ data.tar.gz: e1d4b18de106069036912318ae4fe7c5fab9bfa9eee8f2ec148933f6642a2061
5
5
  SHA512:
6
- metadata.gz: 6f19793fb77a993b65eb8a1b33b4a8bdfaa71279d7789c790b2e169a2c952c20043c7e3b75732b429c361a876770d851af22b4d66dc11f4cee921bce376f1957
7
- data.tar.gz: c0be274b07adf3b01240fefeb92d10db9d92135ec8d71a2a8de21c6e410563b8777ca1ae1bf4ebebf8a064a69f2bf7c363f52aab31fe8371d27f8f0e0d96dab0
6
+ metadata.gz: 8460be7cd7edce7958d0648e71703777f4330901a53b19cab7e461d88f86bbb42d4050bd87681e422e09d9a8f54ded167b5ef293a846e863e26f2b38efdccc55
7
+ data.tar.gz: 27d35e1375e21db51c987d76ac0404bb654cf4511d1e472ec8110bbfccc193219175aacd578797a0908a4f90952884bcf53957e059855e1452387277474b03dc
data/Gemfile CHANGED
@@ -13,3 +13,5 @@ group :test do
13
13
  gem 'minitest', '~> 5.18'
14
14
  gem 'rake', '~> 13.0'
15
15
  end
16
+
17
+ gem "websocket-client-simple", "~> 0.8.0"
data/Gemfile.lock CHANGED
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coincap (0.2.3)
4
+ coincap (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ event_emitter (0.2.6)
9
10
  json (2.6.3)
10
11
  minitest (5.20.0)
11
12
  net-http (0.3.2)
@@ -13,6 +14,10 @@ GEM
13
14
  openssl (3.2.0)
14
15
  rake (13.0.6)
15
16
  uri (0.12.2)
17
+ websocket (1.2.10)
18
+ websocket-client-simple (0.8.0)
19
+ event_emitter
20
+ websocket
16
21
 
17
22
  PLATFORMS
18
23
  x86_64-darwin-22
@@ -26,6 +31,7 @@ DEPENDENCIES
26
31
  openssl (~> 3.1)
27
32
  rake (~> 13.0)
28
33
  uri (~> 0.12.1)
34
+ websocket-client-simple (~> 0.8.0)
29
35
 
30
36
  BUNDLED WITH
31
- 2.4.20
37
+ 2.5.6
data/README.md CHANGED
@@ -20,7 +20,7 @@ Detailed information [here](https://docs.coincap.io/).
20
20
 
21
21
  ## Assets Price
22
22
  ```Ruby
23
- data = Coincap::AssetsPrice.cryptocurrencies
23
+ data = Coincap::Assets.list
24
24
  ```
25
25
  ```JSON
26
26
  {
@@ -45,7 +45,7 @@ data = Coincap::AssetsPrice.cryptocurrencies
45
45
  ```
46
46
 
47
47
  ```Ruby
48
- data = Coincap::AssetsPrice.cryptocurrency('bitcoin')
48
+ data = Coincap::Assets.single('bitcoin')
49
49
  ```
50
50
  ```JSON
51
51
  {
@@ -67,7 +67,15 @@ data = Coincap::AssetsPrice.cryptocurrency('bitcoin')
67
67
  ```
68
68
 
69
69
  ```Ruby
70
- data = Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)
70
+ data = Coincap::Assets.history('bitcoin', :one_minute)
71
+ ```
72
+ or
73
+ ```Ruby
74
+ data = Coincap::Assets.history_one_minute('bitcoin')
75
+ ```
76
+ and with timestamp
77
+ ```Ruby
78
+ data = Coincap::Assets.history_one_minute('bitcoin', 1530403200000, 1533581103627)
71
79
  ```
72
80
  ```JSON
73
81
  {
@@ -83,7 +91,7 @@ data = Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)
83
91
  ```
84
92
 
85
93
  ```Ruby
86
- data = Coincap::AssetsPrice.cryptocurrency_with_markets('bitcoin')
94
+ data = Coincap::Assets.markets('bitcoin')
87
95
  ```
88
96
  ```JSON
89
97
  {
@@ -8,7 +8,7 @@ module Coincap
8
8
  # meaning higher volume exchanges have more affect on this global price.
9
9
  # All values are translated into USD (United States Dollar)
10
10
  # and can be translated into other units of measurement through the /rates endpoint.
11
- module AssetsPrice
11
+ module Assets
12
12
  URI_API = "#{BASE_URI}#{VERSION_API}/assets"
13
13
 
14
14
  TIME_INTERVAL = {
@@ -49,9 +49,9 @@ module Coincap
49
49
  # @param [String] ids (nil) Query with multiple ids=bitcoin,ethereum,monero
50
50
  # @param [Integer] limit (nil) Max limit of 2000
51
51
  # @param [Integer] offset (nil) Offset
52
- # @return [String]
53
- def self.cryptocurrencies(search: nil, ids: nil, limit: nil, offset: nil)
54
- Helper.request_to_read_data(URI_API, search: search, ids: ids, limit: limit, offset: offset)
52
+ # @return [Hash]
53
+ def self.list(search: nil, ids: nil, limit: nil, offset: nil)
54
+ Helper.fetch_data(URI_API, search: search, ids: ids, limit: limit, offset: offset)
55
55
  end
56
56
 
57
57
  # Get single cryptocurrency
@@ -74,9 +74,9 @@ module Coincap
74
74
  # }
75
75
  #
76
76
  # @param asset_id [String] Asset id, for example, bitcoin
77
- # @return [String]
78
- def self.cryptocurrency(asset_id)
79
- Helper.request_to_read_data("#{URI_API}/#{asset_id}")
77
+ # @return [Hash]
78
+ def self.single(asset_id)
79
+ Helper.fetch_data("#{URI_API}/#{asset_id}")
80
80
  end
81
81
 
82
82
  # Get cryptocurrency history price
@@ -106,16 +106,20 @@ module Coincap
106
106
  # @param asset_id [String] Asset id, for example, bitcoin
107
107
  # @param interval [Symbol|String] Select one from the list of TIME_INTERVAL values
108
108
  # for example, a string 'm1' or a symbol :one_minute
109
- # @return [String]
110
- def self.cryptocurrency_history(asset_id, interval)
111
- Helper.request_to_read_data("#{URI_API}/#{asset_id}/history",
112
- interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval)
109
+ # @param start_at [Integer] Start time in milliseconds
110
+ # @param end_at [Integer] End time in milliseconds
111
+ # @return [Hash]
112
+ def self.history(asset_id, interval, start_at = nil, end_at = nil)
113
+ Helper.fetch_data("#{URI_API}/#{asset_id}/history",
114
+ interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval,
115
+ start: start_at,
116
+ end: end_at)
113
117
  end
114
118
 
115
119
  TIME_INTERVAL.each do |key, value|
116
120
  class_eval <<~RUBY
117
- def self.cryptocurrency_history_#{key}(asset_id)
118
- self.cryptocurrency_history(asset_id, '#{value}')
121
+ def self.history_#{key}(asset_id, start_at = nil, end_at = nil)
122
+ self.history(asset_id, '#{value}', start_at, end_at)
119
123
  end
120
124
  RUBY
121
125
  end
@@ -142,9 +146,9 @@ module Coincap
142
146
  # @param asset_id [String] Asset id, for example, bitcoin
143
147
  # @param limit [Integer] Max limit of 2000
144
148
  # @param offset [Integer] Offset
145
- # @return [String]
146
- def self.cryptocurrency_with_markets(asset_id, limit: nil, offset: nil)
147
- Helper.request_to_read_data("#{URI_API}/#{asset_id}/markets", limit: limit, offset: offset)
149
+ # @return [Hash]
150
+ def self.markets(asset_id, limit: nil, offset: nil)
151
+ Helper.fetch_data("#{URI_API}/#{asset_id}/markets", limit: limit, offset: offset)
148
152
  end
149
153
  end
150
154
  end
@@ -33,9 +33,9 @@ module Coincap
33
33
  # "timestamp": 1536605835421
34
34
  # }
35
35
  #
36
- # @return [String]
36
+ # @return [Hash]
37
37
  def self.list
38
- Helper.request_to_read_data(URI_API)
38
+ Helper.fetch_data(URI_API)
39
39
  end
40
40
 
41
41
  # Returns a single exchange.
@@ -56,9 +56,9 @@ module Coincap
56
56
  # }
57
57
  #
58
58
  # @param exchange_id [String] Search by exchange name, for example, kraken
59
- # @return [String]
59
+ # @return [Hash]
60
60
  def self.single(exchange_id)
61
- Helper.request_to_read_data("#{URI_API}/#{exchange_id}")
61
+ Helper.fetch_data("#{URI_API}/#{exchange_id}")
62
62
  end
63
63
  end
64
64
  end
@@ -16,9 +16,11 @@ module Coincap
16
16
  #
17
17
  # @param uri_string [String] String of the uri
18
18
  # @param queries_hash [Hash] Queries hash for the request
19
- # @return [String]
20
- def request_to_read_data(uri_string, **queries_hash)
21
- http_get build_uri(uri_string, **queries_hash)
19
+ # @return [Hash] Hash of the response
20
+ def fetch_data(uri_string, **queries_hash)
21
+ url = build_uri(uri_string, **queries_hash)
22
+ data = http_get url
23
+ JSON.parse data
22
24
  end
23
25
 
24
26
  private
@@ -0,0 +1,46 @@
1
+ require 'websocket-client-simple'
2
+
3
+ module Coincap
4
+ class LiveAssets
5
+ BASE_URI = 'wss://ws.coincap.io/prices?assets='
6
+
7
+ # Initialize the websocket
8
+ # @param assets [Array] List of assets
9
+ def initialize(assets = 'ALL')
10
+ @assets = assets
11
+ end
12
+
13
+ # Connect to the websocket
14
+ def connect
15
+ uri = "#{BASE_URI}#{@assets == 'ALL' ? @assets : @assets.join(',')}"
16
+ @ws = WebSocket::Client::Simple.connect(uri)
17
+ end
18
+
19
+ # Close the websocket
20
+ def disconnect
21
+ @ws.close
22
+ end
23
+
24
+ # When receive the price
25
+ def on_price(&on_message)
26
+ @ws.on :message do |event|
27
+ on_message.call(event.data)
28
+ end
29
+ end
30
+
31
+ # When open the websocket
32
+ def on_open(&on_open)
33
+ @ws.on :open, &on_open
34
+ end
35
+
36
+ # When close the websocket
37
+ def on_close(&on_close)
38
+ @ws.on :close, &on_close
39
+ end
40
+
41
+ # When error
42
+ def on_error(&on_error)
43
+ @ws.on :error, &on_error
44
+ end
45
+ end
46
+ end
@@ -44,9 +44,9 @@ module Coincap
44
44
  # @param asset_id (nil) [String] Returns all assets containing id (base and quote)
45
45
  # @param limit (nil) [Integer] Max limit of 2000
46
46
  # @param offset (nil) [Integer] The number of results to skip
47
- # @return [String]
47
+ # @return [Hash]
48
48
  def self.list(**options)
49
- Helper.request_to_read_data(URI_API,
49
+ Helper.fetch_data(URI_API,
50
50
  exchangeId: options[:exchange_id],
51
51
  baseSymbol: options[:base_symbol],
52
52
  quoteSymbol: options[:quote_symbol],
data/lib/coincap/rates.rb CHANGED
@@ -26,9 +26,9 @@ module Coincap
26
26
  # "timestamp": 1536347807471
27
27
  # }
28
28
  #
29
- # @return [String]
29
+ # @return [Hash]
30
30
  def self.list
31
- Helper.request_to_read_data(URI_API)
31
+ Helper.fetch_data(URI_API)
32
32
  end
33
33
 
34
34
  # Returns a single rate.
@@ -45,9 +45,9 @@ module Coincap
45
45
  # }
46
46
  #
47
47
  # @param asset_id [String] The asset id (bitcoin)
48
- # @return [String]
48
+ # @return [Hash]
49
49
  def self.single(asset_id)
50
- Helper.request_to_read_data("#{URI_API}/#{asset_id}")
50
+ Helper.fetch_data("#{URI_API}/#{asset_id}")
51
51
  end
52
52
  end
53
53
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Coincap
4
4
  MAJOR = 0
5
- MINOR = 2
6
- PATCH = 3
5
+ MINOR = 3
6
+ PATCH = 0
7
7
 
8
8
  private_constant :MAJOR, :MINOR, :PATCH
9
9
 
data/lib/coincap.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'coincap/version'
4
- require_relative 'coincap/assets_price'
3
+ require_relative 'coincap/assets'
4
+ require_relative 'coincap/exchanges'
5
5
  require_relative 'coincap/helper'
6
+ require_relative 'coincap/live_assets'
6
7
  require_relative 'coincap/markets'
7
8
  require_relative 'coincap/rates'
8
- require_relative 'coincap/exchanges'
9
+ require_relative 'coincap/version'
9
10
 
10
11
  # CoinCap 2.0 RESTful API is currently in production!
11
12
  # The CoinCap team is excited to offer you new endpoints and more clarity on pricing!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coincap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vitalii Bakun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-10 00:00:00.000000000 Z
11
+ date: 2024-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " CoinCap is a useful tool for real-time pricing and market activity
14
14
  for over 1,000 cryptocurrencies.\n"
@@ -24,11 +24,11 @@ files:
24
24
  - LICENSE.txt
25
25
  - README.md
26
26
  - Rakefile
27
- - coincap.gemspec
28
27
  - lib/coincap.rb
29
- - lib/coincap/assets_price.rb
28
+ - lib/coincap/assets.rb
30
29
  - lib/coincap/exchanges.rb
31
30
  - lib/coincap/helper.rb
31
+ - lib/coincap/live_assets.rb
32
32
  - lib/coincap/markets.rb
33
33
  - lib/coincap/rates.rb
34
34
  - lib/coincap/version.rb
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubygems_version: 3.4.20
56
+ rubygems_version: 3.5.6
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: CoinCap is a useful tool for real-time pricing and market activity for over
data/coincap.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/coincap/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'coincap'
7
- spec.version = Coincap::VERSION
8
- spec.authors = ['Vitalii Bakun']
9
- spec.email = ['crossdoh@gmail.com']
10
-
11
- spec.summary = 'CoinCap is a useful tool for real-time pricing and market activity for over 1,000 cryptocurrencies.'
12
- spec.description = <<-DESC
13
- CoinCap is a useful tool for real-time pricing and market activity for over 1,000 cryptocurrencies.
14
- DESC
15
- spec.license = 'MIT'
16
- spec.required_ruby_version = '>= 2.7.0'
17
-
18
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
-
20
- spec.metadata['source_code_uri'] = 'https://github.com/vitalii-bakun/coincap'
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(__dir__) do
25
- `git ls-files -z`.split("\x0").reject do |f|
26
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
- end
28
- end
29
- spec.bindir = 'exe'
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ['lib']
32
-
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
35
-
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
38
- end