glassnode 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0fd053158af0fc3f9a4e289826502475c0a9196398b20fc77cf2addb1616b62b
4
+ data.tar.gz: 98b0b04000c07d8935956bd316ac13e95cd10feedddb5c2dbc090a70e46cf433
5
+ SHA512:
6
+ metadata.gz: 84d70fbace8516476928b2282ecd72f68f334d88400633d8e9486a016943d44d7538905725b737382f2f2305ecb5983aa11f8a3b5fb532b7bdccd895331b107a
7
+ data.tar.gz: 04b730a45eaf88401db34a6f43b78cd418112612d17137f321180bfd89e299acde0125c33339cf715365d3aedb762c0998b6221f4ee47ede536db941a2c8a1af
data/lib/errors.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'faraday'
2
+
3
+ module Glassnode
4
+ class ClientError < Exception; end
5
+ class ParamsError < ClientError; end
6
+ class InvalidAuthKeyError < ClientError; end
7
+ class BlockMissingError < ParamsError; end
8
+ class ServerError < Exception; end # Error reported back by Glassnode server
9
+ class ConnectionClosed < Exception; end
10
+ class BadRequestError < ServerError; end
11
+ class NotFoundError < ServerError; end
12
+ class ForbiddenError < ServerError; end
13
+ class UnauthorizedError < ServerError; end
14
+ class InternalServerError < ServerError; end
15
+
16
+ class CustomErrors < Faraday::Response::Middleware
17
+ def on_complete(env)
18
+ case env[:status]
19
+ when 400
20
+ raise BadRequestError, env.body['message']
21
+ when 401
22
+ raise UnauthorizedError, env.body['message']
23
+ when 403
24
+ raise ForbiddenError, env.body['message']
25
+ when 404
26
+ raise NotFoundError, env.url
27
+ when 500
28
+ raise InternalServerError, env.body
29
+ else
30
+ super
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/glassnode.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'uri'
2
+ require 'base64'
3
+ require 'openssl'
4
+ require 'faraday'
5
+ require 'json'
6
+ require 'faraday_middleware'
7
+ require 'dotenv/load'
8
+
9
+ require_relative './errors'
10
+ require_relative './rest/v1'
11
+ require_relative './rest/v2'
@@ -0,0 +1,39 @@
1
+ require 'faraday_adapter_socks'
2
+
3
+ module Glassnode
4
+ module RESTClient
5
+ def check_params(params, allowed_params)
6
+ if (params.keys - allowed_params).empty?
7
+ return params
8
+ else
9
+ raise Glassnode::ParamsError
10
+ end
11
+ end
12
+
13
+ private
14
+ def rest_connection
15
+ @conn ||= new_rest_connection
16
+ end
17
+
18
+ def new_rest_connection
19
+ Faraday.new(url: config[:api_endpoint], proxy: config[:proxy]) do |conn|
20
+ conn.use Glassnode::CustomErrors
21
+ conn.response :logger, Logger.new(STDOUT), bodies: true if config[:debug_connection]
22
+ conn.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
23
+ conn.adapter :net_http_socks
24
+ end
25
+ end
26
+
27
+ def authenticated_get(url, params: {})
28
+ headers = {'Content-Type' => 'application/json', 'X-Api-Key' => config[:api_key]}
29
+ rest_connection.get(url, params, headers) do |req|
30
+ req.options.timeout = config[:rest_timeout]
31
+ req.options.open_timeout = config[:rest_open_timeout]
32
+ end
33
+ end
34
+
35
+ def valid_key?
36
+ !! (config[:api_key])
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,356 @@
1
+ module Glassnode
2
+ module RESTv1Addresses
3
+
4
+ #Tier: 3
5
+ #Params
6
+ # a: asset symbol
7
+ # c: ["NATIVE"]
8
+ # i: ["10m", "1h", "24h", "1w", "1month"]
9
+ def sending_to_exchanges_count(params={})
10
+ authenticated_get("metrics/addresses/sending_to_exchanges_count", params: params).body
11
+ end
12
+
13
+ #Tier: 3
14
+ #Params
15
+ # a: asset symbol
16
+ # c: ["NATIVE"]
17
+ # i: ["10m", "1h", "24h", "1w", "1month"]
18
+ def receiving_from_exchanges_count(params={})
19
+ authenticated_get("metrics/addresses/receiving_from_exchanges_count", params: params).body
20
+ end
21
+
22
+ #Tier: 1
23
+ #Params
24
+ # a: asset symbol
25
+ # c: ["NATIVE"]
26
+ # i: ["1h", "24h", "10m", "1w", "1month"]
27
+ def count(params={})
28
+ authenticated_get("metrics/addresses/count", params: params).body
29
+ end
30
+
31
+ #Tier: 1
32
+ #Params
33
+ # a: asset symbol
34
+ # c: ["NATIVE"]
35
+ # i: ["1h", "24h", "10m", "1w", "1month"]
36
+ def sending_count(params={})
37
+ authenticated_get("metrics/addresses/sending_count", params: params).body
38
+ end
39
+
40
+ #Tier: 1
41
+ #Params
42
+ # a: asset symbol
43
+ # c: ["NATIVE"]
44
+ # i: ["1h", "24h", "10m", "1w", "1month"]
45
+ def receiving_count(params={})
46
+ authenticated_get("metrics/addresses/receiving_count", params: params).body
47
+ end
48
+
49
+ #Tier: 1
50
+ #Params
51
+ # a: asset symbol
52
+ # c: ["NATIVE"]
53
+ # i: ["1h", "24h", "10m", "1w", "1month"]
54
+ def active_count(params={})
55
+ authenticated_get("metrics/addresses/active_count", params: params).body
56
+ end
57
+
58
+ #Tier: 1
59
+ #Params
60
+ # a: asset symbol
61
+ # c: ["NATIVE"]
62
+ # i: ["1h", "24h", "10m", "1w", "1month"]
63
+ def new_non_zero_count(params={})
64
+ authenticated_get("metrics/addresses/new_non_zero_count", params: params).body
65
+ end
66
+
67
+ #Tier: 3
68
+ #Params
69
+ # a: asset symbol
70
+ # c: ["NATIVE"]
71
+ # i: ["24h"]
72
+ def accumulation_count(params={})
73
+ authenticated_get("metrics/addresses/accumulation_count", params: params).body
74
+ end
75
+
76
+ #Tier: 3
77
+ #Params
78
+ # a: asset symbol
79
+ # c: ["NATIVE", "USD"]
80
+ # i: ["24h"]
81
+ def accumulation_balance(params={})
82
+ authenticated_get("metrics/addresses/accumulation_balance", params: params).body
83
+ end
84
+
85
+ #Tier: 2
86
+ #Params
87
+ # a: asset symbol
88
+ # c: ["NATIVE"]
89
+ # i: ["1h", "24h"]
90
+ def non_zero_count(params={})
91
+ authenticated_get("metrics/addresses/non_zero_count", params: params).body
92
+ end
93
+
94
+ #Tier: 2
95
+ #Params
96
+ # a: asset symbol
97
+ # c: ["NATIVE"]
98
+ # i: ["1h", "24h", "10m"]
99
+ def min_point_zero_1_count(params={})
100
+ authenticated_get("metrics/addresses/min_point_zero_1_count", params: params).body
101
+ end
102
+
103
+ #Tier: 2
104
+ #Params
105
+ # a: asset symbol
106
+ # c: ["NATIVE"]
107
+ # i: ["1h", "24h", "10m"]
108
+ def min_point_1_count(params={})
109
+ authenticated_get("metrics/addresses/min_point_1_count", params: params).body
110
+ end
111
+
112
+ #Tier: 2
113
+ #Params
114
+ # a: asset symbol
115
+ # c: ["NATIVE"]
116
+ # i: ["1h", "24h", "10m"]
117
+ def min_1_count(params={})
118
+ authenticated_get("metrics/addresses/min_1_count", params: params).body
119
+ end
120
+
121
+ #Tier: 2
122
+ #Params
123
+ # a: asset symbol
124
+ # c: ["NATIVE"]
125
+ # i: ["1h", "24h", "10m"]
126
+ def min_10_count(params={})
127
+ authenticated_get("metrics/addresses/min_10_count", params: params).body
128
+ end
129
+
130
+ #Tier: 2
131
+ #Params
132
+ # a: asset symbol
133
+ # c: ["NATIVE"]
134
+ # i: ["1h", "24h", "10m"]
135
+ def min_100_count(params={})
136
+ authenticated_get("metrics/addresses/min_100_count", params: params).body
137
+ end
138
+
139
+ #Tier: 2
140
+ #Params
141
+ # a: asset symbol
142
+ # c: ["NATIVE"]
143
+ # i: ["1h", "24h", "10m"]
144
+ def min_1k_count(params={})
145
+ authenticated_get("metrics/addresses/min_1k_count", params: params).body
146
+ end
147
+
148
+ #Tier: 2
149
+ #Params
150
+ # a: asset symbol
151
+ # c: ["NATIVE"]
152
+ # i: ["1h", "24h", "10m"]
153
+ def min_10k_count(params={})
154
+ authenticated_get("metrics/addresses/min_10k_count", params: params).body
155
+ end
156
+
157
+ #Tier: 2
158
+ #Params
159
+ # a: asset symbol
160
+ # c: ["NATIVE"]
161
+ # i: ["1h", "24h", "10m"]
162
+ def min_32_count(params={})
163
+ authenticated_get("metrics/addresses/min_32_count", params: params).body
164
+ end
165
+
166
+ #Tier: 3
167
+ #Params
168
+ # a: asset symbol
169
+ # c: ["NATIVE", "USD"]
170
+ # i: ["1h", "24h", "10m"]
171
+ def supply_balance_less_0001(params={})
172
+ authenticated_get("metrics/addresses/supply_balance_less_0001", params: params).body
173
+ end
174
+
175
+ #Tier: 3
176
+ #Params
177
+ # a: asset symbol
178
+ # c: ["NATIVE", "USD"]
179
+ # i: ["1h", "24h", "10m"]
180
+ def supply_balance_0001_001(params={})
181
+ authenticated_get("metrics/addresses/supply_balance_0001_001", params: params).body
182
+ end
183
+
184
+ #Tier: 3
185
+ #Params
186
+ # a: asset symbol
187
+ # c: ["NATIVE", "USD"]
188
+ # i: ["1h", "24h", "10m"]
189
+ def supply_balance_001_01(params={})
190
+ authenticated_get("metrics/addresses/supply_balance_001_01", params: params).body
191
+ end
192
+
193
+ #Tier: 3
194
+ #Params
195
+ # a: asset symbol
196
+ # c: ["NATIVE", "USD"]
197
+ # i: ["1h", "24h", "10m"]
198
+ def supply_balance_01_1(params={})
199
+ authenticated_get("metrics/addresses/supply_balance_01_1", params: params).body
200
+ end
201
+
202
+ #Tier: 3
203
+ #Params
204
+ # a: asset symbol
205
+ # c: ["NATIVE", "USD"]
206
+ # i: ["1h", "24h", "10m"]
207
+ def supply_balance_1_10(params={})
208
+ authenticated_get("metrics/addresses/supply_balance_1_10", params: params).body
209
+ end
210
+
211
+ #Tier: 3
212
+ #Params
213
+ # a: asset symbol
214
+ # c: ["NATIVE", "USD"]
215
+ # i: ["1h", "24h", "10m"]
216
+ def supply_balance_10_100(params={})
217
+ authenticated_get("metrics/addresses/supply_balance_10_100", params: params).body
218
+ end
219
+
220
+ #Tier: 3
221
+ #Params
222
+ # a: asset symbol
223
+ # c: ["NATIVE", "USD"]
224
+ # i: ["1h", "24h", "10m"]
225
+ def supply_balance_100_1k(params={})
226
+ authenticated_get("metrics/addresses/supply_balance_100_1k", params: params).body
227
+ end
228
+
229
+ #Tier: 3
230
+ #Params
231
+ # a: asset symbol
232
+ # c: ["NATIVE", "USD"]
233
+ # i: ["1h", "24h", "10m"]
234
+ def supply_balance_1k_10k(params={})
235
+ authenticated_get("metrics/addresses/supply_balance_1k_10k", params: params).body
236
+ end
237
+
238
+ #Tier: 3
239
+ #Params
240
+ # a: asset symbol
241
+ # c: ["NATIVE", "USD"]
242
+ # i: ["1h", "24h", "10m"]
243
+ def supply_balance_10k_100k(params={})
244
+ authenticated_get("metrics/addresses/supply_balance_10k_100k", params: params).body
245
+ end
246
+
247
+ #Tier: 3
248
+ #Params
249
+ # a: asset symbol
250
+ # c: ["NATIVE", "USD"]
251
+ # i: ["1h", "24h", "10m"]
252
+ def supply_balance_more_100k(params={})
253
+ authenticated_get("metrics/addresses/supply_balance_more_100k", params: params).body
254
+ end
255
+
256
+ #Tier: 3
257
+ #Params
258
+ # a: asset symbol
259
+ # c: ["NATIVE"]
260
+ # i: ["24h"]
261
+ def supply_distribution_relative(params={})
262
+ authenticated_get("metrics/addresses/supply_distribution_relative", params: params).body
263
+ end
264
+
265
+ #Tier: 3
266
+ #Params
267
+ # a: asset symbol
268
+ # c: ["NATIVE"]
269
+ # i: ["24h"]
270
+ def min_1_usd_count(params={})
271
+ authenticated_get("metrics/addresses/min_1_usd_count", params: params).body
272
+ end
273
+
274
+ #Tier: 3
275
+ #Params
276
+ # a: asset symbol
277
+ # c: ["NATIVE"]
278
+ # i: ["24h"]
279
+ def min_10_usd_count(params={})
280
+ authenticated_get("metrics/addresses/min_10_usd_count", params: params).body
281
+ end
282
+
283
+ #Tier: 3
284
+ #Params
285
+ # a: asset symbol
286
+ # c: ["NATIVE"]
287
+ # i: ["24h"]
288
+ def min_100_usd_count(params={})
289
+ authenticated_get("metrics/addresses/min_100_usd_count", params: params).body
290
+ end
291
+
292
+ #Tier: 3
293
+ #Params
294
+ # a: asset symbol
295
+ # c: ["NATIVE"]
296
+ # i: ["24h"]
297
+ def min_1k_usd_count(params={})
298
+ authenticated_get("metrics/addresses/min_1k_usd_count", params: params).body
299
+ end
300
+
301
+ #Tier: 3
302
+ #Params
303
+ # a: asset symbol
304
+ # c: ["NATIVE"]
305
+ # i: ["24h"]
306
+ def min_10k_usd_count(params={})
307
+ authenticated_get("metrics/addresses/min_10k_usd_count", params: params).body
308
+ end
309
+
310
+ #Tier: 3
311
+ #Params
312
+ # a: asset symbol
313
+ # c: ["NATIVE"]
314
+ # i: ["24h"]
315
+ def min_100k_usd_count(params={})
316
+ authenticated_get("metrics/addresses/min_100k_usd_count", params: params).body
317
+ end
318
+
319
+ #Tier: 3
320
+ #Params
321
+ # a: asset symbol
322
+ # c: ["NATIVE"]
323
+ # i: ["24h"]
324
+ def min_1m_usd_count(params={})
325
+ authenticated_get("metrics/addresses/min_1m_usd_count", params: params).body
326
+ end
327
+
328
+ #Tier: 3
329
+ #Params
330
+ # a: asset symbol
331
+ # c: ["NATIVE"]
332
+ # i: ["1h", "24h"]
333
+ def profit_count(params={})
334
+ authenticated_get("metrics/addresses/profit_count", params: params).body
335
+ end
336
+
337
+ #Tier: 3
338
+ #Params
339
+ # a: asset symbol
340
+ # c: ["NATIVE"]
341
+ # i: ["1h", "24h"]
342
+ def loss_count(params={})
343
+ authenticated_get("metrics/addresses/loss_count", params: params).body
344
+ end
345
+
346
+ #Tier: 3
347
+ #Params
348
+ # a: asset symbol
349
+ # c: ["NATIVE"]
350
+ # i: ["1h", "24h"]
351
+ def profit_relative(params={})
352
+ authenticated_get("metrics/addresses/profit_relative", params: params).body
353
+ end
354
+
355
+ end
356
+ end
@@ -0,0 +1,10 @@
1
+ module Glassnode
2
+ module RESTv1Assets
3
+
4
+ #Tier: 3
5
+ def get_assets
6
+ authenticated_get("metrics/assets")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,167 @@
1
+ module Glassnode
2
+ module RESTv1Blockchain
3
+
4
+ #Tier: 1
5
+ #Params
6
+ # a: asset symbol
7
+ # c: ["NATIVE"]
8
+ # i: ["1h", "24h", "10m", "1w", "1month"]
9
+ def utxo_count(params={})
10
+ authenticated_get("metrics/blockchain/utxo_count", params: params).body
11
+ end
12
+
13
+ #Tier: 1
14
+ #Params
15
+ # a: asset symbol
16
+ # c: ["NATIVE"]
17
+ # i: ["1h", "24h", "10m", "1w", "1month"]
18
+ def utxo_created_count(params={})
19
+ authenticated_get("metrics/blockchain/utxo_created_count", params: params).body
20
+ end
21
+
22
+ #Tier: 1
23
+ #Params
24
+ # a: asset symbol
25
+ # c: ["NATIVE"]
26
+ # i: ["1h", "24h", "10m", "1w", "1month"]
27
+ def utxo_spent_count(params={})
28
+ authenticated_get("metrics/blockchain/utxo_spent_count", params: params).body
29
+ end
30
+
31
+ #Tier: 1
32
+ #Params
33
+ # a: asset symbol
34
+ # c: ["NATIVE", "USD"]
35
+ # i: ["1h", "24h", "10m", "1w", "1month"]
36
+ def utxo_created_value_sum(params={})
37
+ authenticated_get("metrics/blockchain/utxo_created_value_sum", params: params).body
38
+ end
39
+
40
+ #Tier: 1
41
+ #Params
42
+ # a: asset symbol
43
+ # c: ["NATIVE", "USD"]
44
+ # i: ["1h", "24h", "10m", "1w", "1month"]
45
+ def utxo_spent_value_sum(params={})
46
+ authenticated_get("metrics/blockchain/utxo_spent_value_sum", params: params).body
47
+ end
48
+
49
+ #Tier: 1
50
+ #Params
51
+ # a: asset symbol
52
+ # c: ["NATIVE", "USD"]
53
+ # i: ["1h", "24h", "10m", "1w", "1month"]
54
+ def utxo_created_value_mean(params={})
55
+ authenticated_get("metrics/blockchain/utxo_created_value_mean", params: params).body
56
+ end
57
+
58
+ #Tier: 1
59
+ #Params
60
+ # a: asset symbol
61
+ # c: ["NATIVE", "USD"]
62
+ # i: ["1h", "24h", "10m", "1w", "1month"]
63
+ def utxo_spent_value_mean(params={})
64
+ authenticated_get("metrics/blockchain/utxo_spent_value_mean", params: params).body
65
+ end
66
+
67
+ #Tier: 1
68
+ #Params
69
+ # a: asset symbol
70
+ # c: ["NATIVE", "USD"]
71
+ # i: ["1h", "24h", "10m", "1w", "1month"]
72
+ def utxo_created_value_median(params={})
73
+ authenticated_get("metrics/blockchain/utxo_created_value_median", params: params).body
74
+ end
75
+
76
+ #Tier: 1
77
+ #Params
78
+ # a: asset symbol
79
+ # c: ["NATIVE", "USD"]
80
+ # i: ["1h", "24h", "10m", "1w", "1month"]
81
+ def utxo_spent_value_median(params={})
82
+ authenticated_get("metrics/blockchain/utxo_spent_value_median", params: params).body
83
+ end
84
+
85
+ #Tier: 2
86
+ #Params
87
+ # a: asset symbol
88
+ # c: ["NATIVE"]
89
+ # i: ["1h", "24h"]
90
+ def utxo_profit_count(params={})
91
+ authenticated_get("metrics/blockchain/utxo_profit_count", params: params).body
92
+ end
93
+
94
+ #Tier: 2
95
+ #Params
96
+ # a: asset symbol
97
+ # c: ["NATIVE"]
98
+ # i: ["1h", "24h"]
99
+ def utxo_loss_count(params={})
100
+ authenticated_get("metrics/blockchain/utxo_loss_count", params: params).body
101
+ end
102
+
103
+ #Tier: 2
104
+ #Params
105
+ # a: asset symbol
106
+ # c: ["NATIVE"]
107
+ # i: ["1h", "24h"]
108
+ def utxo_profit_relative(params={})
109
+ authenticated_get("metrics/blockchain/utxo_profit_relative", params: params).body
110
+ end
111
+
112
+ #Tier: 1
113
+ #Params
114
+ # a: asset symbol
115
+ # c: ["NATIVE"]
116
+ # i: ["1h", "24h", "10m", "1w", "1month"]
117
+ def block_height(params={})
118
+ authenticated_get("metrics/blockchain/block_height", params: params).body
119
+ end
120
+
121
+ #Tier: 1
122
+ #Params
123
+ # a: asset symbol
124
+ # c: ["NATIVE"]
125
+ # i: ["1h", "24h", "10m", "1w", "1month"]
126
+ def block_count(params={})
127
+ authenticated_get("metrics/blockchain/block_count", params: params).body
128
+ end
129
+
130
+ #Tier: 1
131
+ #Params
132
+ # a: asset symbol
133
+ # c: ["NATIVE"]
134
+ # i: ["1h", "24h", "10m", "1w", "1month"]
135
+ def block_interval_mean(params={})
136
+ authenticated_get("metrics/blockchain/block_interval_mean", params: params).body
137
+ end
138
+
139
+ #Tier: 1
140
+ #Params
141
+ # a: asset symbol
142
+ # c: ["NATIVE"]
143
+ # i: ["1h", "24h", "10m", "1w", "1month"]
144
+ def block_interval_median(params={})
145
+ authenticated_get("metrics/blockchain/block_interval_median", params: params).body
146
+ end
147
+
148
+ #Tier: 1
149
+ #Params
150
+ # a: asset symbol
151
+ # c: ["NATIVE"]
152
+ # i: ["1h", "24h", "10m", "1w", "1month"]
153
+ def block_size_mean(params={})
154
+ authenticated_get("metrics/blockchain/block_size_mean", params: params).body
155
+ end
156
+
157
+ #Tier: 1
158
+ #Params
159
+ # a: asset symbol
160
+ # c: ["NATIVE"]
161
+ # i: ["1h", "24h", "10m", "1w", "1month"]
162
+ def block_size_sum(params={})
163
+ authenticated_get("metrics/blockchain/block_size_sum", params: params).body
164
+ end
165
+
166
+ end
167
+ end
@@ -0,0 +1,14 @@
1
+ module Glassnode
2
+ module RESTv1Defi
3
+
4
+ #Tier: 2
5
+ #Params
6
+ # a: asset symbol
7
+ # c: ["USD"]
8
+ # i: ["24h"]
9
+ def total_value_locked(params={})
10
+ authenticated_get("metrics/defi/total_value_locked", params: params).body
11
+ end
12
+
13
+ end
14
+ end