Skip to content

Commit 3b7025d

Browse files
committed
Added JSON output support
1 parent 92f54f3 commit 3b7025d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

bittensor_cli/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5055,6 +5055,8 @@ def subnets_price(
50555055
if json_output and html_output:
50565056
print_error("Cannot specify both `--json-output` and `--html`")
50575057
return
5058+
self.verbosity_handler(quiet=quiet, verbose=verbose, json_output=json_output)
5059+
50585060
subtensor = self.initialize_chain(network)
50595061
non_archives = ["finney", "latent-lite", "subvortex"]
50605062
if not current_only and subtensor.network in non_archives + [
@@ -5067,7 +5069,6 @@ def subnets_price(
50675069
)
50685070
return False
50695071

5070-
self.verbosity_handler(quiet=quiet, verbose=verbose, json_output=json_output)
50715072
if netuids:
50725073
netuids = parse_to_list(
50735074
netuids,

bittensor_cli/src/commands/subnets/price.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ async def price(
9393
subnet_data = _process_current_subnet_data(
9494
all_subnet_info, netuids, all_netuids
9595
)
96-
_generate_cli_output_current(subnet_data)
96+
if json_output:
97+
json_console.print(json.dumps(_generate_json_output(subnet_data)))
98+
else:
99+
_generate_cli_output_current(subnet_data)
97100

98101

99102
def _process_current_subnet_data(subnet_infos: list[DynamicInfo], netuids, all_netuids):
@@ -117,7 +120,7 @@ def _process_current_subnet_data(subnet_infos: list[DynamicInfo], netuids, all_n
117120
else:
118121
subnet_info = subnet_infos[0]
119122
stats = {
120-
"current_price": subnet_info.price,
123+
"current_price": subnet_info.price.tao,
121124
"supply": subnet_info.alpha_in.tao + subnet_info.alpha_out.tao,
122125
"market_cap": subnet_info.price.tao
123126
* (subnet_info.alpha_in.tao + subnet_info.alpha_out.tao),
@@ -686,13 +689,13 @@ def _generate_cli_output_current(subnet_data):
686689
console.print(
687690
f"\n[{COLOR_PALETTE.G.SYM}]Subnet {netuid} - {stats['symbol']} "
688691
f"[cyan]{stats['name']}[/cyan][/{COLOR_PALETTE.G.SYM}]\n"
689-
f"Current: [blue]{stats['current_price'].tao:.6f}{stats['symbol']}[/blue]\n"
692+
f"Current: [blue]{stats['current_price']:.6f}{stats['symbol']}[/blue]\n"
690693
)
691694
else:
692695
console.print(
693696
f"\n[{COLOR_PALETTE.G.SYM}]Subnet {netuid} - {stats['symbol']} "
694697
f"[cyan]{stats['name']}[/cyan][/{COLOR_PALETTE.G.SYM}]\n"
695-
f"Current: [blue]{stats['symbol']} {stats['current_price'].tao:.6f}[/blue]\n"
698+
f"Current: [blue]{stats['symbol']} {stats['current_price']:.6f}[/blue]\n"
696699
)
697700

698701
if netuid != 0:

0 commit comments

Comments
 (0)