cryptocoin_fanboi 0.6.0 → 0.7.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: 5b9ac014b2f7cc7558b843bf2b7d7361263be34b3436048d574eeb2924fe0f6a
4
- data.tar.gz: 6c7353c942ff0e1f52cd505fcdac863101c1cb831c01062ead4d88cf94ac5fb8
3
+ metadata.gz: 1bfc95bacb5c4990d5e1c0dda661b8ce3208e300379c87b52f6e1e69e7581edb
4
+ data.tar.gz: 190711504307d779f0180a6e7122693290c6233b0ea2e652362cb262b40880c5
5
5
  SHA512:
6
- metadata.gz: 9d8820c768ed1b33ffcfdd54b249c6072d9bc6be4775b1c4d8a707f9a5f7386c13e04d426a183acfe14ecdedf372cd1045411b9fe9e25771426f2804293d875e
7
- data.tar.gz: 131381228b4bc43b45acfad712e50eb8a119f3e7d179bbd6478dba70411be294d9d1379afb1c335c28b777b8efd25237d350eb0c949602d9005d5e0329339911
6
+ metadata.gz: 4a569183a1bb366c18fae986cd2f182a9208ca51277eda22d4c6b0b5d71574ce8e51f2014d3120728b662afb2081808bb5341ff7b73062fde653031ca6c6e8b0
7
+ data.tar.gz: 41cd0bf2b9d4c883022c5d00102236cea7f3edc50f2c776f7db792a6d8d5988fae63a10fb192e3b8feccc5514239a4061987005465ccf87a6466bead4231c65e
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -11,7 +11,21 @@ require 'rxfhelper'
11
11
  require 'rexle'
12
12
  require 'kramdown'
13
13
  require 'justexchangerates'
14
-
14
+ require 'coinquery'
15
+
16
+ # 02-May 2021 ----
17
+ #
18
+ # public methods tested:
19
+ #
20
+ # * this_day
21
+ # * this_hour
22
+ # * this_week
23
+ # * this_month
24
+ # * past_60d
25
+ # * past_90d
26
+
27
+ # note: In order to use this gem you will need at least a
28
+ # valid "basic plan" Coinmarket API key.
15
29
 
16
30
  =begin
17
31
 
@@ -70,6 +84,8 @@ class CryptocoinFanboi
70
84
  @colored, @debug, @filepath = colored, debug, filepath
71
85
  @exchangerate_key, @cmc_apikey = exchangerate_key, cmc_apikey
72
86
 
87
+ @cq = CoinQuery.new(dym: false, timeout: 7, debug: debug)
88
+
73
89
  @watch= watch.map(&:upcase)
74
90
  @ignore = ignore.map(&:upcase)
75
91
 
@@ -77,16 +93,24 @@ class CryptocoinFanboi
77
93
  #@fields = %w(rank name price_usd price_btc percent_change_1h
78
94
  # percent_change_24h percent_change_7d percent_change_year)
79
95
 
80
-
81
- @fields = %w(price percent_change_1h percent_change_24h percent_change_7d)
96
+ pct_fields = %w(1h 24h 7d 30d 60d 90d).map {|x| 'percent_change_' + x}
97
+ @fields = %w(price) + pct_fields
82
98
 
83
99
  @year = Time.now.year
84
100
  #@labels = %w(Rank Name USD BTC) + ['% 1hr:', '% 24hr:',
85
101
  # '% 1 week:', '% ' + @year.to_s + ':']
86
102
  @labels = %w(Rank Name USD) + ['% 1hr:', '% 24hr:',
87
- '% 1 week:']
88
- coins = fetch_coinlist()
103
+ '% 7d:','% 30d:','% 60d:','% 90d:']
104
+
105
+ puts 'about to fetch coinlist'.info if @debug
106
+ @coins = coins = fetch_coinlist()
107
+ puts 'coinlist fetched'.info if @debug
108
+
109
+ # The following code is commented out because it's non-essential to
110
+ # returning the current coin prices. It was intended to show yearly
111
+ # percentage returns
89
112
 
113
+ =begin
90
114
  # check for the local cache file containing a record of currency
91
115
  # prices from the start of the year
92
116
 
@@ -125,7 +149,7 @@ class CryptocoinFanboi
125
149
  puts '@growth: ' + @growth.inspect if @debug
126
150
 
127
151
  @coins = add_year_growth coins
128
-
152
+ =end
129
153
 
130
154
  end
131
155
 
@@ -239,13 +263,13 @@ class CryptocoinFanboi
239
263
  date = if raw_date.is_a? Date then
240
264
  raw_date.strftime("%Y%m%d")
241
265
  else
242
- Chronic.parse(raw_date.gsub('-',' ')).strftime("%Y%m%d")
266
+ Chronic.parse(raw_date.gsub('-',' ')).strftime("%d%m%Y")
243
267
  end
244
268
  puts 'date: ' + date.inspect if @debug
245
269
 
246
270
  # if date is today then return today's price
247
271
 
248
- if date == Date.today.strftime("%Y%m%d")
272
+ if date == Date.today.strftime("%d%m%Y")
249
273
  puts 'same day' if @debug
250
274
  return self.coin(coin).quote['USD']['price'].to_f
251
275
  end
@@ -261,11 +285,12 @@ class CryptocoinFanboi
261
285
  puts 'date: ' + date.inspect
262
286
  end
263
287
 
264
- a = Coinmarketcap.get_historical_price(coin.gsub(/ /,'-'), date, date)
265
- puts 'a: ' + a.inspect if @debug
266
-
267
- r = a.any? ? a.first[:close] : self.coin(coin).quote['USD']['price'].to_f
288
+ #a = Coinmarketcap.get_historical_price(coin.gsub(/ /,'-'), date, date)
289
+ #puts 'a: ' + a.inspect if @debug
268
290
 
291
+ #r = a.any? ? a.first[:close] : self.coin(coin).quote['USD']['price'].to_f
292
+ price = @cq.historical_price coin, date
293
+ r = price ? price.to_f : self.coin(coin).quote['USD']['price'].to_f
269
294
  @history_prices[coin] ||= {}
270
295
  @history_prices[coin][date] = r
271
296
  File.write @historic_prices_file, @history_prices.to_yaml
@@ -279,6 +304,21 @@ class CryptocoinFanboi
279
304
 
280
305
  end
281
306
 
307
+ def past_60d(limit: 5, markdown: false, rank: :top)
308
+
309
+ coins = sort_coins('60d', limit: limit, rank: rank)
310
+ build_table coins, markdown: markdown
311
+
312
+ end
313
+
314
+ def past_90d(limit: 5, markdown: false, rank: :top)
315
+
316
+ coins = sort_coins('90d', limit: limit, rank: rank)
317
+ build_table coins, markdown: markdown
318
+
319
+ end
320
+
321
+
282
322
  def prices_this_year(coin)
283
323
 
284
324
  (Date.parse('1 Jan')..Date.today).map do |date|
@@ -305,13 +345,26 @@ class CryptocoinFanboi
305
345
  #
306
346
  def this_week(limit: 5, markdown: false, rank: :top)
307
347
 
308
- coins = sort_coins(limit: limit, rank: rank)
348
+ coins = sort_coins('7d', limit: limit, rank: rank)
309
349
  build_table coins, markdown: markdown
310
350
 
311
351
  end
312
352
 
313
353
  alias week this_week
314
354
 
355
+ # View the coins with the largest gains this week (past 7 days)
356
+ #
357
+ def this_month(limit: 5, markdown: false, rank: :top)
358
+
359
+ puts 'inside this_mponth'.info if @debug
360
+ coins = sort_coins('30d', limit: limit, rank: rank)
361
+ build_table coins, markdown: markdown
362
+
363
+ end
364
+
365
+ alias month this_month
366
+
367
+
315
368
  # View the coins with the largest gains this
316
369
  # year (since the start of the year)
317
370
  #
@@ -361,7 +414,7 @@ class CryptocoinFanboi
361
414
  puts ('coin: ' + coin.inspect).debug if @debug
362
415
  a2 = %w(cmc_rank name).map {|x| coin[x]}
363
416
  puts 'a2: ' + a2.inspect
364
- a3 = @fields.map {|x| coin['quote']['USD'][x] }
417
+ a3 = @fields.map {|x| coin['quote']['USD'][x].to_f.round(2) }
365
418
  puts 'a3: ' + a3.inspect
366
419
  a2 + a3
367
420
  end
@@ -412,8 +465,8 @@ class CryptocoinFanboi
412
465
  puts 'labels: ' + labels.inspect
413
466
  end
414
467
 
415
- s = TableFormatter.new(source: source, labels: labels, markdown: markdown)\
416
- .display
468
+ s = TableFormatter.new(source: source, labels: labels, divider: '|',
469
+ markdown: markdown).display
417
470
 
418
471
  return s if @colored == false or markdown
419
472
 
@@ -423,8 +476,9 @@ class CryptocoinFanboi
423
476
 
424
477
  fields = line.split('|')
425
478
 
426
- a2 = fields[5..-2].map {|x| c(x) }
427
- (fields[0..4] + a2 + ["\n"]).join('|')
479
+ a2 = fields[4..-2].map {|x| c(x) }
480
+ puts 'at: ' + a2.inspect if @debug
481
+ (fields[0..3] + a2 + ["\n"]).join('|')
428
482
 
429
483
  end
430
484
 
@@ -455,20 +509,22 @@ class CryptocoinFanboi
455
509
 
456
510
  coins.inject({}) do |r, coin|
457
511
 
458
- day1 = @year.to_s + '0101'
512
+ day1 = '01-01-' + @year.to_s
459
513
  puts 'coin: ' + coin.name.inspect if @debug
460
514
 
461
515
  begin
462
516
 
463
- a = Coinmarketcap.get_historical_price(coin.name.gsub(/ /,'-'),
464
- day1, day1)
517
+ #a = Coinmarketcap.get_historical_price(coin.name.gsub(/ /,'-'),
518
+ # day1, day1)
519
+ price = @cq.historical_price coin.symbol, day1
520
+
465
521
  rescue
466
522
  puts 'warning : ' + coin.name.inspect + ' ' + ($!).inspect
467
523
  end
468
524
 
469
- if a and a.any? then
525
+ if price then
470
526
 
471
- r.merge({coin.name => a[0][:close].to_f})
527
+ r.merge({coin.name => price.to_f})
472
528
  else
473
529
  r
474
530
  end
@@ -508,9 +564,14 @@ class CryptocoinFanboi
508
564
 
509
565
  def sort_coins(period='7d', limit: 5, rank: :top)
510
566
 
511
- a = @coins.sort_by {|x| -x['percent_change_' + period].to_f}
567
+ puts 'sorting coins ...'.info if @debug
568
+ puts '@coins[0]: ' + @coins[0].inspect
569
+
570
+ a = @coins.sort_by {|x| -x.quote['USD']['percent_change_' + period].to_f}
512
571
  a.reverse! if rank == :bottom
513
- a.take(limit).map {|coin| @fields.map {|key| coin[key] }}
572
+ a.take(limit).map do |coin|
573
+ [coin.cmc_rank, coin.name] + @fields.map {|key| coin.quote['USD'][key].round(2) }
574
+ end
514
575
 
515
576
  end
516
577
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cryptocoin_fanboi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -11,31 +11,31 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwNTI1MjEwNjMwWhcN
15
- MjAwNTI0MjEwNjMwWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQ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UcGtLqhChxBY9LnKZQPPyWuuw0t4
35
- rf70OqfIBGSc7l8KgCsJdPq9sfGaqkwP5aJtKCMWYTPzHZ26Gl9HxOQDR/bfMZbt
36
- jporVuRIHCzaaXjuFOXEPBUx
28
+ BgkqhkiG9w0BAQsFAAOCAYEAHqoUl4+Eb0XXSoSN2kn4FK0+lwCWzvsw1no8VVvz
29
+ X4Yzcxpx076sR97xax4S6++nOnULXp0U1dh5ohHbwN96soWUbtCUGc0ATI27BWMd
30
+ rGe6jvur7Aoc2RpOYF32gOcZGScHQnvptyKFA+iV2fLeC7X1EkP9zRa8FxBatbbq
31
+ Irrofi01zMrPy2GMtbmaBDQwyEvw10Mj4zPEFRO9HchS3Ufb0XzAjf0p+XYG6GOs
32
+ HNE6h7xQL14l/H74Nj6JQksFew5MwO45kkCaenQXOt6+OaoFayyp6MXjyHXsR6k/
33
+ X3MsM9Yluc0zjhjipc6i3lyqN/OyMy3RTbi25iTPeIFyl4n0F5OR1y+DXy2ZN6Xb
34
+ jMyolu6Fvw4RyX+8S7/yxACBenRqrBgjoRfardaubu7lhZAt9mRjKApWpRnTm4pX
35
+ 8apOj5Vc5mSZcvmZkImt0L0+RfWgzVjyK6LWXmWC0fkURO1c8pu+DEn2QI5HEKpD
36
+ zda3SGyo8CEr8HOwCV4H0aAY
37
37
  -----END CERTIFICATE-----
38
- date: 2019-05-25 00:00:00.000000000 Z
38
+ date: 2021-05-02 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: colored
@@ -57,46 +57,6 @@ dependencies:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: '1.2'
60
- - !ruby/object:Gem::Dependency
61
- name: chronic
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '0.10'
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.10.2
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '0.10'
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: 0.10.2
80
- - !ruby/object:Gem::Dependency
81
- name: coinmarketcap
82
- requirement: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 0.3.0
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.3'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 0.3.0
97
- - - "~>"
98
- - !ruby/object:Gem::Version
99
- version: '0.3'
100
60
  - !ruby/object:Gem::Dependency
101
61
  name: coinmarketcap_lite
102
62
  requirement: !ruby/object:Gem::Requirement
@@ -137,26 +97,6 @@ dependencies:
137
97
  - - "~>"
138
98
  - !ruby/object:Gem::Version
139
99
  version: '0.7'
140
- - !ruby/object:Gem::Dependency
141
- name: rexle
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - "~>"
145
- - !ruby/object:Gem::Version
146
- version: '1.5'
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- version: 1.5.1
150
- type: :runtime
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - "~>"
155
- - !ruby/object:Gem::Version
156
- version: '1.5'
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: 1.5.1
160
100
  - !ruby/object:Gem::Dependency
161
101
  name: kramdown
162
102
  requirement: !ruby/object:Gem::Requirement
@@ -197,8 +137,28 @@ dependencies:
197
137
  - - ">="
198
138
  - !ruby/object:Gem::Version
199
139
  version: 0.3.4
140
+ - !ruby/object:Gem::Dependency
141
+ name: coinquery
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: 0.2.0
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '0.2'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: 0.2.0
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.2'
200
160
  description:
201
- email: james@jamesrobertson.eu
161
+ email: digital.robertson@gmail.com
202
162
  executables: []
203
163
  extensions: []
204
164
  extra_rdoc_files: []
@@ -223,7 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
183
  - !ruby/object:Gem::Version
224
184
  version: '0'
225
185
  requirements: []
226
- rubygems_version: 3.0.1
186
+ rubyforge_project:
187
+ rubygems_version: 2.7.10
227
188
  signing_key:
228
189
  specification_version: 4
229
190
  summary: A coinmarketcap wrapper which makes it convenient to display the top 5 cryptocurrencies
metadata.gz.sig CHANGED
Binary file