coincap 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +8 -2
- data/README.md +12 -4
- data/lib/coincap/{assets_price.rb → assets.rb} +20 -16
- data/lib/coincap/exchanges.rb +4 -4
- data/lib/coincap/helper.rb +5 -3
- data/lib/coincap/live_assets.rb +46 -0
- data/lib/coincap/markets.rb +2 -2
- data/lib/coincap/rates.rb +4 -4
- data/lib/coincap/version.rb +2 -2
- data/lib/coincap.rb +4 -3
- metadata +5 -5
- data/coincap.gemspec +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3804fc6897bedeab59d3433b78d966c9ead78b479ddda7fa68224dc82ab3269a
|
4
|
+
data.tar.gz: e1d4b18de106069036912318ae4fe7c5fab9bfa9eee8f2ec148933f6642a2061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8460be7cd7edce7958d0648e71703777f4330901a53b19cab7e461d88f86bbb42d4050bd87681e422e09d9a8f54ded167b5ef293a846e863e26f2b38efdccc55
|
7
|
+
data.tar.gz: 27d35e1375e21db51c987d76ac0404bb654cf4511d1e472ec8110bbfccc193219175aacd578797a0908a4f90952884bcf53957e059855e1452387277474b03dc
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
coincap (0.
|
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.
|
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::
|
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::
|
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::
|
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::
|
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
|
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 [
|
53
|
-
def self.
|
54
|
-
Helper.
|
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 [
|
78
|
-
def self.
|
79
|
-
Helper.
|
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
|
-
# @
|
110
|
-
|
111
|
-
|
112
|
-
|
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.
|
118
|
-
self.
|
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 [
|
146
|
-
def self.
|
147
|
-
Helper.
|
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
|
data/lib/coincap/exchanges.rb
CHANGED
@@ -33,9 +33,9 @@ module Coincap
|
|
33
33
|
# "timestamp": 1536605835421
|
34
34
|
# }
|
35
35
|
#
|
36
|
-
# @return [
|
36
|
+
# @return [Hash]
|
37
37
|
def self.list
|
38
|
-
Helper.
|
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 [
|
59
|
+
# @return [Hash]
|
60
60
|
def self.single(exchange_id)
|
61
|
-
Helper.
|
61
|
+
Helper.fetch_data("#{URI_API}/#{exchange_id}")
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/lib/coincap/helper.rb
CHANGED
@@ -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 [
|
20
|
-
def
|
21
|
-
|
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
|
data/lib/coincap/markets.rb
CHANGED
@@ -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 [
|
47
|
+
# @return [Hash]
|
48
48
|
def self.list(**options)
|
49
|
-
Helper.
|
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 [
|
29
|
+
# @return [Hash]
|
30
30
|
def self.list
|
31
|
-
Helper.
|
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 [
|
48
|
+
# @return [Hash]
|
49
49
|
def self.single(asset_id)
|
50
|
-
Helper.
|
50
|
+
Helper.fetch_data("#{URI_API}/#{asset_id}")
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/lib/coincap/version.rb
CHANGED
data/lib/coincap.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'coincap/
|
4
|
-
require_relative 'coincap/
|
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/
|
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.
|
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:
|
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/
|
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.
|
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
|