Browse Source

mmnode-ticker: minor cleanups

The MMGen Project 1 month ago
parent
commit
2647fa1fe3
3 changed files with 20 additions and 16 deletions
  1. 16 14
      mmgen_node_tools/Ticker.py
  2. 2 2
      mmgen_node_tools/main_ticker.py
  3. 2 0
      test/cmdtest_d/misc.py

+ 16 - 14
mmgen_node_tools/Ticker.py

@@ -43,10 +43,10 @@ percent_cols = {
 
 
 sp = namedtuple('sort_parameter', ['key', 'sort_dfl', 'desc'])
 sp = namedtuple('sort_parameter', ['key', 'sort_dfl', 'desc'])
 sort_params = {
 sort_params = {
-	'd': sp('percent_change_24h', 0.0,        '1-day % change'),
-	'w': sp('percent_change_7d',  0.0,        '1-week % change'),
-	'm': sp('percent_change_30d', 0.0,        '1-month % change'),
-	'y': sp('percent_change_1y',  0.0,        '1-year % change'),
+	'd': sp('percent_change_24h', 0.0,        '1-day percent change'),
+	'w': sp('percent_change_7d',  0.0,        '1-week percent change'),
+	'm': sp('percent_change_30d', 0.0,        '1-month percent change'),
+	'y': sp('percent_change_1y',  0.0,        '1-year percent change'),
 	'p': sp('price_usd',          Decimal(0), 'asset price'),
 	'p': sp('price_usd',          Decimal(0), 'asset price'),
 	'c': sp('market_cap',         0,          'market cap')}
 	'c': sp('market_cap',         0,          'market cap')}
 
 
@@ -1025,8 +1025,8 @@ class Ticker:
 			if cfg.asset_range:
 			if cfg.asset_range:
 				yield from process_rows(self.rows['asset_list'])
 				yield from process_rows(self.rows['asset_list'])
 			else:
 			else:
-				for rows in self.rows.values():
-					if rows:
+				for group, rows in self.rows.items():
+					if rows and group not in self.hidden_groups:
 						yield from process_rows(rows)
 						yield from process_rows(rows)
 
 
 			yield '-' * self.hl_wid
 			yield '-' * self.hl_wid
@@ -1082,8 +1082,10 @@ class Ticker:
 
 
 		def fmt_row(self, d, amt=None, amt_fmt=None):
 		def fmt_row(self, d, amt=None, amt_fmt=None):
 
 
-			def fmt_pct(n):
-				return gray('     --') if n is None else (red, green)[n>=0](f'{n:+7.2f}')
+			def fmt_pct(d, key, wid=7):
+				if (n := d.get(key)) is None:
+					return gray('     --')
+				return (red, green)[n>=0](f'{n:+{wid}.2f}')
 
 
 			p = self.prices[d['id']]
 			p = self.prices[d['id']]
 
 
@@ -1096,10 +1098,10 @@ class Ticker:
 				idx = int(d['rank']) if cfg.asset_range else None,
 				idx = int(d['rank']) if cfg.asset_range else None,
 				mcap = d.get('market_cap') / 1_000_000_000 if cfg.asset_range else None,
 				mcap = d.get('market_cap') / 1_000_000_000 if cfg.asset_range else None,
 				lbl = self.create_label(d['id']) if cfg.name_labels else d['symbol'],
 				lbl = self.create_label(d['id']) if cfg.name_labels else d['symbol'],
-				pc1 = fmt_pct(d.get('percent_change_7d')),
-				pc2 = fmt_pct(d.get('percent_change_24h')),
-				pc3 = fmt_pct(d.get('percent_change_1y')),
-				pc4 = fmt_pct(d.get('percent_change_30d')),
+				pc1 = fmt_pct(d, 'percent_change_7d'),
+				pc2 = fmt_pct(d, 'percent_change_24h'),
+				pc3 = fmt_pct(d, 'percent_change_1y', wid=8),
+				pc4 = fmt_pct(d, 'percent_change_30d'),
 				upd = d.get('last_updated_fmt'),
 				upd = d.get('last_updated_fmt'),
 				amt = amt_fmt,
 				amt = amt_fmt,
 				**{k.replace('-', '_'): v * (1 if amt is None else amt) for k, v in p.items()})
 				**{k.replace('-', '_'): v * (1 if amt is None else amt) for k, v in p.items()})
@@ -1117,7 +1119,7 @@ class Ticker:
 
 
 			col_fs_data = {
 			col_fs_data = {
 				'label':       fd(f'{{lbl:{self.col1_wid}}}', f'{{lbl:{self.col1_wid}}}', self.col1_wid),
 				'label':       fd(f'{{lbl:{self.col1_wid}}}', f'{{lbl:{self.col1_wid}}}', self.col1_wid),
-				'pct1y':       fd(' {pc3:7}', ' {pc3:7}', 8),
+				'pct1y':       fd(' {pc3:8}', ' {pc3:8}', 9),
 				'pct1m':       fd(' {pc4:7}', ' {pc4:7}', 8),
 				'pct1m':       fd(' {pc4:7}', ' {pc4:7}', 8),
 				'pct1w':       fd(' {pc1:7}', ' {pc1:7}', 8),
 				'pct1w':       fd(' {pc1:7}', ' {pc1:7}', 8),
 				'pct1d':       fd(' {pc2:7}', ' {pc2:7}', 8),
 				'pct1d':       fd(' {pc2:7}', ' {pc2:7}', 8),
@@ -1169,7 +1171,7 @@ class Ticker:
 				mcap = 'MarketCap(B)',
 				mcap = 'MarketCap(B)',
 				pc1 = ' CHG_7d',
 				pc1 = ' CHG_7d',
 				pc2 = 'CHG_24h',
 				pc2 = 'CHG_24h',
-				pc3 = 'CHG_1y',
+				pc3 = '  CHG_1y',
 				pc4 = 'CHG_30d',
 				pc4 = 'CHG_30d',
 				upd = 'UPDATED',
 				upd = 'UPDATED',
 				amt = '         AMOUNT',
 				amt = '         AMOUNT',

+ 2 - 2
mmgen_node_tools/main_ticker.py

@@ -40,10 +40,10 @@ opts_data = {
                       used to supply a USD exchange rate for missing assets.
                       used to supply a USD exchange rate for missing assets.
 -C, --cached-data     Use cached data from previous network query instead of
 -C, --cached-data     Use cached data from previous network query instead of
                       live data from server
                       live data from server
--D, --cachedir=D      Read and write cached JSON data to directory ‘D’
-                      instead of ‘~/{dfl_cachedir}’
 -d, --download=D      Retrieve and cache asset data ‘D’ from network (valid
 -d, --download=D      Retrieve and cache asset data ‘D’ from network (valid
                       options: {ds})
                       options: {ds})
+-D, --cachedir=D      Read and write cached JSON data to directory ‘D’
+                      instead of ‘~/{dfl_cachedir}’
 -e, --add-precision=N Add ‘N’ digits of precision to columns
 -e, --add-precision=N Add ‘N’ digits of precision to columns
 -E, --elapsed         Show elapsed time in UPDATED column (see --update-time)
 -E, --elapsed         Show elapsed time in UPDATED column (see --update-time)
 -F, --portfolio       Display portfolio data
 -F, --portfolio       Display portfolio data

+ 2 - 0
test/cmdtest_d/misc.py

@@ -133,6 +133,7 @@ class CmdTestScripts(CmdTestBase):
 			cached_data = True,
 			cached_data = True,
 			add_opts    = [],
 			add_opts    = [],
 			use_proxy   = True,
 			use_proxy   = True,
+			no_msg      = False,
 			exit_val    = None):
 			exit_val    = None):
 		t = self.spawn(
 		t = self.spawn(
 			'mmnode-ticker',
 			'mmnode-ticker',
@@ -141,6 +142,7 @@ class CmdTestScripts(CmdTestBase):
 			+ (['--proxy=http://asdfzxcv:32459'] if use_proxy else [])
 			+ (['--proxy=http://asdfzxcv:32459'] if use_proxy else [])
 			+ add_opts
 			+ add_opts
 			+ args,
 			+ args,
+			no_msg = no_msg,
 			exit_val = exit_val)
 			exit_val = exit_val)
 		if expect_list:
 		if expect_list:
 			t.match_expect_list(expect_list)
 			t.match_expect_list(expect_list)