coincap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +30 -0
- data/README.md +214 -0
- data/Rakefile +12 -0
- data/lib/coincap/assets_price.rb +135 -0
- data/lib/coincap/exchanges.rb +64 -0
- data/lib/coincap/helper.rb +41 -0
- data/lib/coincap/markets.rb +64 -0
- data/lib/coincap/rates.rb +53 -0
- data/lib/coincap/version.rb +5 -0
- data/lib/coincap.rb +39 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 400102f77c2de8996aed21a75f3dd351998cceb7fe88130814474dce51ddef33
|
4
|
+
data.tar.gz: d1cf37117aeb04e4d956fdbd0c4de56d9dc93537e3672e0ca2016ffeedb370d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57971399dfeb1d52affcb456202ced30853b1d21f2adc6812fc6a68105833c4445f8c7d1c1848f1930befe1d914ab42000da101204e034b9fe84e42cf385805f
|
7
|
+
data.tar.gz: 340c5c6cbaeacd4990955e51faed298b93ebbbffc80cb4944887cc61bf68d1a7219fdf3fd34eaef5affd17be3867216e8b7ebe0d8ab24f1861069434917232dc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
coincap (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
json (2.6.3)
|
10
|
+
minitest (5.18.0)
|
11
|
+
net-http (0.3.2)
|
12
|
+
uri
|
13
|
+
openssl (3.1.0)
|
14
|
+
rake (13.0.6)
|
15
|
+
uri (0.12.1)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
x86_64-linux
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
coincap!
|
22
|
+
json
|
23
|
+
minitest
|
24
|
+
net-http
|
25
|
+
openssl
|
26
|
+
rake
|
27
|
+
uri
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
2.4.10
|
data/README.md
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
# coincap
|
2
|
+
CoinCap is a useful tool for real-time pricing and market activity for over 1,000 cryptocurrencies. By collecting exchange data from thousands of markets, we are able to offer transparent and accurate data on asset price and availability.
|
3
|
+
|
4
|
+
If you want to add 'api key' or change 'accept encoding', just call the 'configure' method.
|
5
|
+
|
6
|
+
No API Key: 200 requests per minute
|
7
|
+
API Key: 500 requests per minute
|
8
|
+
|
9
|
+
Generate API KEY [here](https://coincap.io/api-key).
|
10
|
+
|
11
|
+
```Ruby
|
12
|
+
Coincap.configure do |config|
|
13
|
+
config.api_key = 'XXXXXXXXXXXXXXXXXXXXX'
|
14
|
+
config.accept_encoding = 'deflate' # Default gzip
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
Detailed information [here](https://docs.coincap.io/).
|
19
|
+
|
20
|
+
## Assets Price
|
21
|
+
```Ruby
|
22
|
+
data = Coincap::AssetsPrice.cryptocurrencies
|
23
|
+
```
|
24
|
+
```JSON
|
25
|
+
{
|
26
|
+
"data": [
|
27
|
+
{
|
28
|
+
"id": "bitcoin",
|
29
|
+
"rank": "1",
|
30
|
+
"symbol": "BTC",
|
31
|
+
"name": "Bitcoin",
|
32
|
+
"supply": "17193925.0000000000000000",
|
33
|
+
"maxSupply": "21000000.0000000000000000",
|
34
|
+
"marketCapUsd": "119150835874.4699281625807300",
|
35
|
+
"volumeUsd24Hr": "2927959461.1750323310959460",
|
36
|
+
"priceUsd": "6929.8217756835584756",
|
37
|
+
"changePercent24Hr": "-0.8101417214350335",
|
38
|
+
"vwap24Hr": "7175.0663247679233209"
|
39
|
+
},
|
40
|
+
...
|
41
|
+
],
|
42
|
+
"timestamp": 1533581088278
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
```Ruby
|
47
|
+
data = Coincap::AssetsPrice.cryptocurrency('bitcoin')
|
48
|
+
```
|
49
|
+
```JSON
|
50
|
+
{
|
51
|
+
"data": {
|
52
|
+
"id": "bitcoin",
|
53
|
+
"rank": "1",
|
54
|
+
"symbol": "BTC",
|
55
|
+
"name": "Bitcoin",
|
56
|
+
"supply": "17193925.0000000000000000",
|
57
|
+
"maxSupply": "21000000.0000000000000000",
|
58
|
+
"marketCapUsd": "119179791817.6740161068269075",
|
59
|
+
"volumeUsd24Hr": "2928356777.6066665425687196",
|
60
|
+
"priceUsd": "6931.5058555666618359",
|
61
|
+
"changePercent24Hr": "-0.8101417214350335",
|
62
|
+
"vwap24Hr": "7175.0663247679233209"
|
63
|
+
},
|
64
|
+
"timestamp": 1533581098863
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
68
|
+
```Ruby
|
69
|
+
data = Coincap::AssetsPrice.cryptocurrency_history('bitcoin', :one_minute)
|
70
|
+
```
|
71
|
+
```JSON
|
72
|
+
{
|
73
|
+
"data": [
|
74
|
+
{
|
75
|
+
"priceUsd": "6379.3997635993342453",
|
76
|
+
"time": 1530403200000
|
77
|
+
},
|
78
|
+
...
|
79
|
+
],
|
80
|
+
"timestamp": 1533581103627
|
81
|
+
}
|
82
|
+
```
|
83
|
+
|
84
|
+
```Ruby
|
85
|
+
data = Coincap::AssetsPrice.cryptocurrency_with_markets('bitcoin')
|
86
|
+
```
|
87
|
+
```JSON
|
88
|
+
{
|
89
|
+
"data": [
|
90
|
+
{
|
91
|
+
"exchangeId": "Binance",
|
92
|
+
"baseId": "bitcoin",
|
93
|
+
"quoteId": "tether",
|
94
|
+
"baseSymbol": "BTC",
|
95
|
+
"quoteSymbol": "USDT",
|
96
|
+
"volumeUsd24Hr": "277775213.1923032624064566",
|
97
|
+
"priceUsd": "6263.8645034633024446",
|
98
|
+
"volumePercent": "7.4239157877678087"
|
99
|
+
},
|
100
|
+
...
|
101
|
+
],
|
102
|
+
"timestamp": 1539289444052
|
103
|
+
}
|
104
|
+
```
|
105
|
+
|
106
|
+
## Rates
|
107
|
+
```Ruby
|
108
|
+
data = Coincap::Rates.list
|
109
|
+
```
|
110
|
+
```JSON
|
111
|
+
{
|
112
|
+
"data": [
|
113
|
+
{
|
114
|
+
"id": "barbadian-dollar",
|
115
|
+
"symbol": "BBD",
|
116
|
+
"currencySymbol": "$",
|
117
|
+
"type": "fiat",
|
118
|
+
"rateUsd": "0.5000000000000000"
|
119
|
+
},
|
120
|
+
...
|
121
|
+
],
|
122
|
+
"timestamp": 1536347807471
|
123
|
+
}
|
124
|
+
```
|
125
|
+
|
126
|
+
```Ruby
|
127
|
+
data = Coincap::Rates.single('bitcoin')
|
128
|
+
```
|
129
|
+
```JSON
|
130
|
+
{
|
131
|
+
"data": [
|
132
|
+
{
|
133
|
+
"id": "barbadian-dollar",
|
134
|
+
"symbol": "BBD",
|
135
|
+
"currencySymbol": "$",
|
136
|
+
"type": "fiat",
|
137
|
+
"rateUsd": "0.5000000000000000"
|
138
|
+
},
|
139
|
+
...
|
140
|
+
],
|
141
|
+
"timestamp": 1536347807471
|
142
|
+
}
|
143
|
+
```
|
144
|
+
|
145
|
+
## Exchanges
|
146
|
+
```Ruby
|
147
|
+
data = Coincap::Exchanges.list
|
148
|
+
```
|
149
|
+
```JSON
|
150
|
+
{
|
151
|
+
"data": [
|
152
|
+
{
|
153
|
+
"id": "okex",
|
154
|
+
"name": "Okex",
|
155
|
+
"rank": "1",
|
156
|
+
"percentTotalVolume": "21.379485735166293542000000000000000000",
|
157
|
+
"volumeUsd": "616465445.1646260280799955",
|
158
|
+
"tradingPairs": "22",
|
159
|
+
"socket": false,
|
160
|
+
"exchangeUrl": "https://www.okex.com/",
|
161
|
+
"updated": 1536343139514
|
162
|
+
},
|
163
|
+
...
|
164
|
+
],
|
165
|
+
"timestamp": 1536605835421
|
166
|
+
}
|
167
|
+
```
|
168
|
+
|
169
|
+
```Ruby
|
170
|
+
data = Coincap::Exchanges.single
|
171
|
+
```
|
172
|
+
```JSON
|
173
|
+
{
|
174
|
+
"data": {
|
175
|
+
"id": "kraken",
|
176
|
+
"name": "Kraken",
|
177
|
+
"rank": "4",
|
178
|
+
"percentTotalVolume": "2.946801735133553120000000000000000000",
|
179
|
+
"volumeUsd": "84969370.4499608426167365",
|
180
|
+
"tradingPairs": "52",
|
181
|
+
"socket": false,
|
182
|
+
"exchangeUrl": "https://kraken.com",
|
183
|
+
"updated": 1536343139468
|
184
|
+
},
|
185
|
+
"timestamp": 1536605874069
|
186
|
+
}
|
187
|
+
```
|
188
|
+
|
189
|
+
## Markets
|
190
|
+
```Ruby
|
191
|
+
data = Coincap::Markets.list
|
192
|
+
```
|
193
|
+
```JSON
|
194
|
+
{
|
195
|
+
"data": [
|
196
|
+
{
|
197
|
+
"exchangeId": "bitstamp",
|
198
|
+
"rank": "1",
|
199
|
+
"baseSymbol": "BTC",
|
200
|
+
"baseId": "bitcoin",
|
201
|
+
"quoteSymbol": "USD",
|
202
|
+
"quoteId": "united-states-dollar",
|
203
|
+
"priceQuote": "6927.3300000000000000",
|
204
|
+
"priceUsd": "6927.3300000000000000",
|
205
|
+
"volumeUsd24Hr": "43341291.9576547008000000",
|
206
|
+
"percentExchangeVolume": "67.2199253376108585",
|
207
|
+
"tradesCount24Hr": "420721",
|
208
|
+
"updated": 1533581033590
|
209
|
+
},
|
210
|
+
...
|
211
|
+
],
|
212
|
+
"timestamp": 1533581173350
|
213
|
+
}
|
214
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
module Coincap
|
6
|
+
# The asset price is a volume-weighted average calculated by collecting ticker data from exchanges.
|
7
|
+
# Each exchange contributes to this price in relation to their volume,
|
8
|
+
# meaning higher volume exchanges have more affect on this global price.
|
9
|
+
# All values are translated into USD (United States Dollar)
|
10
|
+
# and can be translated into other units of measurement through the /rates endpoint.
|
11
|
+
module AssetsPrice
|
12
|
+
URI_API = 'https://api.coincap.io/v2/assets'
|
13
|
+
|
14
|
+
TIME_INTERVAL = {
|
15
|
+
one_minute: 'm1',
|
16
|
+
five_minutes: 'm5',
|
17
|
+
fifteen_minutes: 'm15',
|
18
|
+
thirty_minutes: 'm30',
|
19
|
+
one_hour: 'h1',
|
20
|
+
two_hours: 'h2',
|
21
|
+
six_hours: 'h6',
|
22
|
+
twelve_hours: 'h12',
|
23
|
+
one_day: 'd1'
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
# Get all cryptocurrencies
|
27
|
+
#
|
28
|
+
# {
|
29
|
+
# "data": [
|
30
|
+
# {
|
31
|
+
# "id": "bitcoin",
|
32
|
+
# "rank": "1",
|
33
|
+
# "symbol": "BTC",
|
34
|
+
# "name": "Bitcoin",
|
35
|
+
# "supply": "17193925.0000000000000000",
|
36
|
+
# "maxSupply": "21000000.0000000000000000",
|
37
|
+
# "marketCapUsd": "119150835874.4699281625807300",
|
38
|
+
# "volumeUsd24Hr": "2927959461.1750323310959460",
|
39
|
+
# "priceUsd": "6929.8217756835584756",
|
40
|
+
# "changePercent24Hr": "-0.8101417214350335",
|
41
|
+
# "vwap24Hr": "7175.0663247679233209"
|
42
|
+
# },
|
43
|
+
# ...
|
44
|
+
# ],
|
45
|
+
# "timestamp": 1533581088278
|
46
|
+
# }
|
47
|
+
#
|
48
|
+
# @param [Hash] options
|
49
|
+
# @option options [String] :search (nil) Search by asset id (bitcoin) or symbol (BTC)
|
50
|
+
# @option options [String] :ids (nil) Query with multiple ids=bitcoin,ethereum,monero
|
51
|
+
# @option options [Integer] :limit (nil) Max limit of 2000
|
52
|
+
# @option options [Integer] :offset (nil) Offset
|
53
|
+
# @return [Hash]
|
54
|
+
def self.cryptocurrencies(**options)
|
55
|
+
quries = {
|
56
|
+
'search': options[:search],
|
57
|
+
'ids': options[:ids],
|
58
|
+
'limit': options[:limit],
|
59
|
+
'offset': options[:offset]
|
60
|
+
}
|
61
|
+
Helper.request_to_read_data(URI_API, **quries)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get single cryptocurrency
|
65
|
+
#
|
66
|
+
# {
|
67
|
+
# "data": {
|
68
|
+
# "id": "bitcoin",
|
69
|
+
# "rank": "1",
|
70
|
+
# "symbol": "BTC",
|
71
|
+
# "name": "Bitcoin",
|
72
|
+
# "supply": "17193925.0000000000000000",
|
73
|
+
# "maxSupply": "21000000.0000000000000000",
|
74
|
+
# "marketCapUsd": "119179791817.6740161068269075",
|
75
|
+
# "volumeUsd24Hr": "2928356777.6066665425687196",
|
76
|
+
# "priceUsd": "6931.5058555666618359",
|
77
|
+
# "changePercent24Hr": "-0.8101417214350335",
|
78
|
+
# "vwap24Hr": "7175.0663247679233209"
|
79
|
+
# },
|
80
|
+
# "timestamp": 1533581098863
|
81
|
+
# }
|
82
|
+
#
|
83
|
+
# @param [String] asset_id Asset id, for example, bitcoin
|
84
|
+
# @return [Hash]
|
85
|
+
def self.cryptocurrency(asset_id)
|
86
|
+
Helper.request_to_read_data("#{URI_API}/#{asset_id}")
|
87
|
+
end
|
88
|
+
|
89
|
+
# Get cryptocurrency history price
|
90
|
+
#
|
91
|
+
# {
|
92
|
+
# "data": [
|
93
|
+
# {
|
94
|
+
# "priceUsd": "6379.3997635993342453",
|
95
|
+
# "time": 1530403200000
|
96
|
+
# },
|
97
|
+
# ...
|
98
|
+
# ],
|
99
|
+
# "timestamp": 1533581103627
|
100
|
+
# }
|
101
|
+
#
|
102
|
+
# @param [String] asset_id Asset id, for example, bitcoin
|
103
|
+
# @param [Symbol] interval Select one from the list m1,m5,m15,m30,h1,h2,h6,h12,d1, for example, m1 or write a symbol, for example, :one_minute
|
104
|
+
def self.cryptocurrency_history(asset_id, interval)
|
105
|
+
Helper.request_to_read_data("#{URI_API}/#{asset_id}/history",
|
106
|
+
interval: interval.is_a?(Symbol) ? TIME_INTERVAL[interval] : interval)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Get price cryptocurrency with markets
|
110
|
+
#
|
111
|
+
# {
|
112
|
+
# "data": [
|
113
|
+
# {
|
114
|
+
# "exchangeId": "Binance",
|
115
|
+
# "baseId": "bitcoin",
|
116
|
+
# "quoteId": "tether",
|
117
|
+
# "baseSymbol": "BTC",
|
118
|
+
# "quoteSymbol": "USDT",
|
119
|
+
# "volumeUsd24Hr": "277775213.1923032624064566",
|
120
|
+
# "priceUsd": "6263.8645034633024446",
|
121
|
+
# "volumePercent": "7.4239157877678087"
|
122
|
+
# },
|
123
|
+
# ...
|
124
|
+
# ],
|
125
|
+
# "timestamp": 1539289444052
|
126
|
+
# }
|
127
|
+
#
|
128
|
+
# @param [String] asset_id Asset id, for example, bitcoin
|
129
|
+
# @param [Integer] limit Max limit of 2000
|
130
|
+
# @param [Integer] offset Offset
|
131
|
+
def self.cryptocurrency_with_markets(asset_id, limit: nil, offset: nil)
|
132
|
+
Helper.request_to_read_data("#{URI_API}/#{asset_id}/markets", limit: limit, offset: offset)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
module Coincap
|
6
|
+
# The /exchanges endpoint offers an understanding into the where cryptocurrency
|
7
|
+
# is being exchanged and offers high-level information on those exchanges.
|
8
|
+
#
|
9
|
+
# CoinCap strives to provide transparency in the recency of our exchange data.
|
10
|
+
#
|
11
|
+
# For that purpose you will find an "updated" key for each exchange.
|
12
|
+
# For more details into coin pairs and volume, see the /markets endpoint.
|
13
|
+
module Exchanges
|
14
|
+
URI_API = 'https://api.coincap.io/v2/exchanges'
|
15
|
+
|
16
|
+
# Returns a list of all exchanges.
|
17
|
+
#
|
18
|
+
# {
|
19
|
+
# "data": [
|
20
|
+
# {
|
21
|
+
# "id": "okex",
|
22
|
+
# "name": "Okex",
|
23
|
+
# "rank": "1",
|
24
|
+
# "percentTotalVolume": "21.379485735166293542000000000000000000",
|
25
|
+
# "volumeUsd": "616465445.1646260280799955",
|
26
|
+
# "tradingPairs": "22",
|
27
|
+
# "socket": false,
|
28
|
+
# "exchangeUrl": "https://www.okex.com/",
|
29
|
+
# "updated": 1536343139514
|
30
|
+
# },
|
31
|
+
# ...
|
32
|
+
# ],
|
33
|
+
# "timestamp": 1536605835421
|
34
|
+
# }
|
35
|
+
#
|
36
|
+
# @return [Hash]
|
37
|
+
def self.list
|
38
|
+
Helper.request_to_read_data(URI_API)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns a single exchange.
|
42
|
+
#
|
43
|
+
# {
|
44
|
+
# "data": {
|
45
|
+
# "id": "kraken",
|
46
|
+
# "name": "Kraken",
|
47
|
+
# "rank": "4",
|
48
|
+
# "percentTotalVolume": "2.946801735133553120000000000000000000",
|
49
|
+
# "volumeUsd": "84969370.4499608426167365",
|
50
|
+
# "tradingPairs": "52",
|
51
|
+
# "socket": false,
|
52
|
+
# "exchangeUrl": "https://kraken.com",
|
53
|
+
# "updated": 1536343139468
|
54
|
+
# },
|
55
|
+
# "timestamp": 1536605874069
|
56
|
+
# }
|
57
|
+
#
|
58
|
+
# @param exchange_id [String]
|
59
|
+
# @return [Hash]
|
60
|
+
def self.single(exchange_id)
|
61
|
+
Helper.request_to_read_data("#{URI_API}/#{exchange_id}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
require 'openssl'
|
7
|
+
|
8
|
+
module Coincap
|
9
|
+
# Helper module
|
10
|
+
module Helper
|
11
|
+
def self.request_to_read_data(uri_string, **queries_hash)
|
12
|
+
uri = convert_hash_to_uri(uri_string, **queries_hash)
|
13
|
+
|
14
|
+
data_str = http_get(uri)
|
15
|
+
|
16
|
+
JSON.parse(data_str)
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
private
|
21
|
+
|
22
|
+
def http_get(uri)
|
23
|
+
config = Coincap.instance_variable_get(:@config)
|
24
|
+
|
25
|
+
headers = {
|
26
|
+
'Accept-Encoding': config.accept_encoding,
|
27
|
+
'Authorization': config.api_key.nil? ? nil : "Bearer #{config.api_key}"
|
28
|
+
}
|
29
|
+
|
30
|
+
headers.compact!
|
31
|
+
|
32
|
+
Net::HTTP.get(uri, headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def convert_hash_to_uri(uri, **queries_hash)
|
36
|
+
queries_str = queries_hash.compact.map { |key, value| "#{key}=#{value}" }.join('&')
|
37
|
+
URI("#{uri}#{queries_str.empty? ? '' : "?#{queries_str}"}")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
module Coincap
|
6
|
+
# Take a closer look into exchanges with the /markets endpoint.
|
7
|
+
# Similar to the /exchanges endpoint, we strive to offer transparency into how real-time
|
8
|
+
# our data is with a key identifying when the market was last updated.
|
9
|
+
# For a historical view on how a market has performed, see the /candles endpoint.
|
10
|
+
# All market data represents actual trades processed, orders on an exchange are not represented.
|
11
|
+
# Data received from individual markets is used to calculate the current price of an asset.
|
12
|
+
module Markets
|
13
|
+
URI_API = 'https://api.coincap.io/v2/markets'
|
14
|
+
|
15
|
+
# Returns a list of all markets.
|
16
|
+
#
|
17
|
+
# {
|
18
|
+
# "data": [
|
19
|
+
# {
|
20
|
+
# "exchangeId": "bitstamp",
|
21
|
+
# "rank": "1",
|
22
|
+
# "baseSymbol": "BTC",
|
23
|
+
# "baseId": "bitcoin",
|
24
|
+
# "quoteSymbol": "USD",
|
25
|
+
# "quoteId": "united-states-dollar",
|
26
|
+
# "priceQuote": "6927.3300000000000000",
|
27
|
+
# "priceUsd": "6927.3300000000000000",
|
28
|
+
# "volumeUsd24Hr": "43341291.9576547008000000",
|
29
|
+
# "percentExchangeVolume": "67.2199253376108585",
|
30
|
+
# "tradesCount24Hr": "420721",
|
31
|
+
# "updated": 1533581033590
|
32
|
+
# },
|
33
|
+
# ...
|
34
|
+
# ],
|
35
|
+
# "timestamp": 1533581173350
|
36
|
+
# }
|
37
|
+
#
|
38
|
+
# @param options [Hash] options for the request
|
39
|
+
# @option options [String] :exchange_id (nil) Search by exchange id (e.g. 'binance')
|
40
|
+
# @option options [String] :base_symbol (nil) Returns all containing the base symbol
|
41
|
+
# @option options [String] :quote_symbol (nil) Returns all containing the quote symbol
|
42
|
+
# @option options [String] :base_id (nil) Returns all containing the base id
|
43
|
+
# @option options [String] :quote_id (nil) Returns all containing the quote id
|
44
|
+
# @option options [String] :asset_symbol (nil) Returns all assets containing symbol (base and quote)
|
45
|
+
# @option options [String] :asset_id (nil) Returns all assets containing id (base and quote)
|
46
|
+
# @option options [Integer] :limit (nil) Max limit of 2000
|
47
|
+
# @option options [Integer] :offset (nil) The number of results to skip
|
48
|
+
# @return [Hash]
|
49
|
+
def self.list(**options)
|
50
|
+
queries = {
|
51
|
+
'exchangeId': options[:exchange_id],
|
52
|
+
'baseSymbol': options[:base_symbol],
|
53
|
+
'quoteSymbol': options[:quote_symbol],
|
54
|
+
'baseId': options[:base_id],
|
55
|
+
'quoteId': options[:quote_id],
|
56
|
+
'assetSymbol': options[:asset_symbol],
|
57
|
+
'assetId': options[:asset_id],
|
58
|
+
'limit': options[:limit],
|
59
|
+
'offset': options[:offset]
|
60
|
+
}
|
61
|
+
Helper.request_to_read_data(URI_API, **queries)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
module Coincap
|
6
|
+
# All prices on the CoinCap API are standardized in USD (United States Dollar).
|
7
|
+
# To make translating to other values easy, CoinCap now offers a Rates endpoint.
|
8
|
+
# We offer fiat and top cryptocurrency translated rates.
|
9
|
+
# Fiat rates are available through OpenExchangeRates.org.
|
10
|
+
module Rates
|
11
|
+
URI_API = 'https://api.coincap.io/v2/rates'
|
12
|
+
|
13
|
+
# Returns a list of all rates.
|
14
|
+
#
|
15
|
+
# {
|
16
|
+
# "data": [
|
17
|
+
# {
|
18
|
+
# "id": "barbadian-dollar",
|
19
|
+
# "symbol": "BBD",
|
20
|
+
# "currencySymbol": "$",
|
21
|
+
# "type": "fiat",
|
22
|
+
# "rateUsd": "0.5000000000000000"
|
23
|
+
# },
|
24
|
+
# ...
|
25
|
+
# ],
|
26
|
+
# "timestamp": 1536347807471
|
27
|
+
# }
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
def self.list
|
31
|
+
Helper.request_to_read_data(URI_API)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns a single rate.
|
35
|
+
#
|
36
|
+
# {
|
37
|
+
# "data": {
|
38
|
+
# "id": "bitcoin",
|
39
|
+
# "symbol": "BTC",
|
40
|
+
# "currencySymbol": "₿",
|
41
|
+
# "type": "crypto",
|
42
|
+
# "rateUsd": "6444.3132749056076909"
|
43
|
+
# },
|
44
|
+
# "timestamp": 1536347871542
|
45
|
+
# }
|
46
|
+
#
|
47
|
+
# @param asset_id [String] The asset id (bitcoin)
|
48
|
+
# @return [Hash]
|
49
|
+
def self.single(asset_id)
|
50
|
+
Helper.request_to_read_data("#{URI_API}/#{asset_id}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/coincap.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'coincap/version'
|
4
|
+
require_relative 'coincap/assets_price'
|
5
|
+
require_relative 'coincap/helper'
|
6
|
+
require_relative 'coincap/markets'
|
7
|
+
require_relative 'coincap/rates'
|
8
|
+
require_relative 'coincap/exchanges'
|
9
|
+
|
10
|
+
# CoinCap 2.0 RESTful API is currently in production!
|
11
|
+
# The CoinCap team is excited to offer you new endpoints and more clarity on pricing!
|
12
|
+
# CoinCap 2.0 launched on September 26, 2018.
|
13
|
+
# Please let us know what you like, what you would hope to see, or any bugs/changes that you'd like to document.
|
14
|
+
# The easiest way to submit feedback to our team is to fill out a support ticket here.
|
15
|
+
# The old CoinCap API is deprecated and was shut down on March 1, 2019.
|
16
|
+
# For any issues with transitioning from the old CoinCap API to the new,
|
17
|
+
# please submit feedback via the zendesk link above!
|
18
|
+
module Coincap
|
19
|
+
# Configuration class for Coincap
|
20
|
+
class Configuration
|
21
|
+
# @return [String] The API key to use for all requests.
|
22
|
+
attr_accessor :api_key
|
23
|
+
# @return [String] The accept encoding to use for all requests. Select 'gzip' or 'deflate'. Defaults to 'gzip'.
|
24
|
+
attr_accessor :accept_encoding
|
25
|
+
|
26
|
+
def initialize(api_key = nil, accept_encoding = 'gzip')
|
27
|
+
@api_key = api_key
|
28
|
+
@accept_encoding = accept_encoding
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
@config = Configuration.new
|
33
|
+
|
34
|
+
def self.configure
|
35
|
+
# @yield [Coincap::Configuration]
|
36
|
+
yield @config
|
37
|
+
@config.accept_encoding
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coincap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cosmic-1
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: CoinCap is a useful tool for real-time pricing and market activity for
|
14
|
+
over 1,000 cryptocurrencies.
|
15
|
+
email:
|
16
|
+
- crossdoh@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/coincap.rb
|
26
|
+
- lib/coincap/assets_price.rb
|
27
|
+
- lib/coincap/exchanges.rb
|
28
|
+
- lib/coincap/helper.rb
|
29
|
+
- lib/coincap/markets.rb
|
30
|
+
- lib/coincap/rates.rb
|
31
|
+
- lib/coincap/version.rb
|
32
|
+
homepage:
|
33
|
+
licenses: []
|
34
|
+
metadata:
|
35
|
+
allowed_push_host: https://rubygems.org
|
36
|
+
source_code_uri: https://github.com/Cosmic-1/coincap
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.6.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.4.10
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: CoinCap is a useful tool for real-time pricing and market activity for over
|
56
|
+
1,000 cryptocurrencies.
|
57
|
+
test_files: []
|