kaleido-cli 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+ """CLI configuration management commands."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Annotated
6
+
7
+ import typer
8
+
9
+ from kaleido_cli.config import (
10
+ _KEY_ALIASES,
11
+ CONFIG_FILE,
12
+ DEFAULT_API_URL,
13
+ DEFAULT_NETWORK,
14
+ CliConfig,
15
+ load_config,
16
+ save_config,
17
+ set_config_key,
18
+ )
19
+ from kaleido_cli.output import (
20
+ is_json_mode,
21
+ output_model,
22
+ print_error,
23
+ print_info,
24
+ print_json,
25
+ print_success,
26
+ )
27
+
28
+ config_app = typer.Typer(
29
+ no_args_is_help=True,
30
+ rich_markup_mode="rich",
31
+ help=(
32
+ "Manage CLI configuration stored in [green]~/.kaleido/config.json[/green].\n\n"
33
+ "[bold]Config keys[/bold]\n\n"
34
+ " [green]node-url[/green] URL of your RGB Lightning Node (default: http://localhost:3001)\n"
35
+ f" [green]api-url[/green] Kaleidoswap maker API URL (default: {DEFAULT_API_URL})\n"
36
+ f" [green]network[/green] Bitcoin network (default: {DEFAULT_NETWORK})\n"
37
+ " [green]spawn-dir[/green] Directory for node environments (default: ~/.kaleido)\n"
38
+ ),
39
+ )
40
+
41
+
42
+ @config_app.command("show")
43
+ def config_show() -> None:
44
+ """Display current CLI configuration."""
45
+ config = load_config()
46
+ if is_json_mode():
47
+ print_json(config.to_dict())
48
+ return
49
+ output_model(
50
+ {
51
+ "path": str(CONFIG_FILE),
52
+ "api_url": config.api_url,
53
+ "node_url": config.node_url,
54
+ "network": config.network,
55
+ "spawn_dir": config.spawn_dir or "(default: ~/.kaleido)",
56
+ },
57
+ title=f"Config ({CONFIG_FILE})",
58
+ )
59
+
60
+
61
+ @config_app.command(
62
+ "set",
63
+ epilog=(
64
+ "[bold]Examples[/bold]\n\n"
65
+ " [cyan]kaleido config set node-url http://localhost:3001[/cyan]\n"
66
+ f" [cyan]kaleido config set api-url {DEFAULT_API_URL}[/cyan]\n"
67
+ " [cyan]kaleido config set network mutinynet[/cyan]\n"
68
+ " [cyan]kaleido config set spawn-dir ~/kaleido-nodes[/cyan]"
69
+ ),
70
+ )
71
+ def config_set(
72
+ key: Annotated[
73
+ str,
74
+ typer.Argument(help=f"Config key to update. Valid keys: {list(_KEY_ALIASES)}"),
75
+ ],
76
+ value: Annotated[str, typer.Argument(help="New value to set.")],
77
+ ) -> None:
78
+ """Set a configuration value."""
79
+ try:
80
+ set_config_key(key, value)
81
+ print_success(f"Set {key} = {value}")
82
+ except KeyError as e:
83
+ print_error(str(e))
84
+ raise typer.Exit(1)
85
+
86
+
87
+ @config_app.command(
88
+ "reset",
89
+ epilog=(
90
+ " [cyan]kaleido config reset[/cyan] Interactive confirmation\n"
91
+ " [cyan]kaleido config reset --yes[/cyan] Skip confirmation"
92
+ ),
93
+ )
94
+ def config_reset(
95
+ yes: Annotated[bool, typer.Option("--yes", "-y", help="Skip the confirmation prompt.")] = False,
96
+ ) -> None:
97
+ """Reset all configuration to defaults."""
98
+ if not yes:
99
+ confirmed = typer.confirm("Reset all config to defaults?")
100
+ if not confirmed:
101
+ print_info("Aborted.")
102
+ raise typer.Exit(0)
103
+ save_config(CliConfig())
104
+ print_success("Config reset to defaults.")
105
+
106
+
107
+ @config_app.command(
108
+ "path",
109
+ epilog=" [cyan]kaleido config path[/cyan] Print the path; useful for scripts: $(kaleido config path)",
110
+ )
111
+ def config_path() -> None:
112
+ """Print the path to the config file."""
113
+ print_info(str(CONFIG_FILE))
@@ -0,0 +1,241 @@
1
+ """Market data commands — assets, pairs, quotes."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ from typing import Annotated
7
+
8
+ import typer
9
+
10
+ from kaleido_cli.context import get_client
11
+ from kaleido_cli.output import (
12
+ is_json_mode,
13
+ output_collection,
14
+ output_model,
15
+ print_error,
16
+ print_json,
17
+ )
18
+ from kaleido_cli.utils.errors import raise_cli_error
19
+ from kaleido_cli.utils.pairs import (
20
+ canonical_pair,
21
+ resolve_trading_pair,
22
+ )
23
+ from kaleido_cli.utils.prompts import resolve_pair
24
+ from kaleido_cli.utils.quotes import resolve_and_fetch_quote
25
+
26
+ market_app = typer.Typer(
27
+ no_args_is_help=True,
28
+ rich_markup_mode="rich",
29
+ help="Query Kaleidoswap market data — assets, trading pairs, quotes, and maker info.",
30
+ )
31
+
32
+
33
+ @market_app.command(
34
+ "assets",
35
+ epilog=(
36
+ " [cyan]kaleido market assets[/cyan] Table view\n"
37
+ " [cyan]kaleido --json market assets[/cyan] Raw JSON"
38
+ ),
39
+ )
40
+ def market_assets() -> None:
41
+ """List all tradeable assets on Kaleidoswap."""
42
+ asyncio.run(_market_assets())
43
+
44
+
45
+ async def _market_assets() -> None:
46
+ try:
47
+ client = get_client()
48
+ resp = await client.maker.list_assets()
49
+ if is_json_mode():
50
+ print_json(resp.model_dump())
51
+ return
52
+ output_collection(
53
+ "Tradeable Assets",
54
+ [a.model_dump() for a in (resp.assets or [])],
55
+ item_title="Asset — {index}",
56
+ )
57
+ except Exception as e:
58
+ raise_cli_error(e)
59
+
60
+
61
+ @market_app.command("pairs")
62
+ def market_pairs() -> None:
63
+ """List all available trading pairs."""
64
+ asyncio.run(_market_pairs())
65
+
66
+
67
+ async def _market_pairs() -> None:
68
+ try:
69
+ client = get_client()
70
+ resp = await client.maker.list_pairs()
71
+ if is_json_mode():
72
+ print_json(resp.model_dump())
73
+ return
74
+ items = []
75
+ for p in resp.pairs or []:
76
+ items.append(
77
+ {
78
+ "pair": f"{p.base.ticker}/{p.quote.ticker}",
79
+ "base": p.base.model_dump() if hasattr(p.base, "model_dump") else p.base,
80
+ "quote": p.quote.model_dump() if hasattr(p.quote, "model_dump") else p.quote,
81
+ "routes": p.routes,
82
+ "routes_count": len(p.routes or []),
83
+ "is_active": p.is_active,
84
+ }
85
+ )
86
+ output_collection("Trading Pairs", items, item_title="Pair — {index}")
87
+ except Exception as e:
88
+ raise_cli_error(e)
89
+
90
+
91
+ @market_app.command(
92
+ "quote",
93
+ epilog=(
94
+ "[bold]Examples[/bold]\n\n"
95
+ " Quote: send BTC via Lightning, receive USDT via RGB Lightning:\n"
96
+ " [cyan]kaleido market quote BTC/USDT --from-amount 0.001[/cyan]\n\n"
97
+ " Quote with explicit layers:\n"
98
+ " [cyan]kaleido market quote BTC/USDT --from-amount 0.001 --from-layer BTC_LN --to-layer RGB_LN[/cyan]\n\n"
99
+ " Quote how much BTC is needed to receive 500 USDT:\n"
100
+ " [cyan]kaleido market quote BTC/USDT --to-amount 500 --from-layer BTC_LN --to-layer RGB_LN[/cyan]\n\n"
101
+ "[bold]Available layers[/bold]: [green]BTC_LN[/green] [green]RGB_LN[/green] [green]BTC_ONCHAIN[/green]\n"
102
+ "[dim]Use 'kaleido market pairs' to see available pair tickers.[/dim]"
103
+ ),
104
+ )
105
+ def market_quote(
106
+ pair: Annotated[
107
+ str | None,
108
+ typer.Argument(
109
+ help="Trading pair in [green]BASE/QUOTE[/green] format, e.g. [green]BTC/USDT[/green]."
110
+ ),
111
+ ] = None,
112
+ from_amount: Annotated[
113
+ str | None,
114
+ typer.Option(
115
+ "--from-amount",
116
+ help="Amount to send in display units. Provide this OR --to-amount.",
117
+ ),
118
+ ] = None,
119
+ to_amount: Annotated[
120
+ str | None,
121
+ typer.Option(
122
+ "--to-amount",
123
+ help="Amount to receive in display units. Provide this OR --from-amount.",
124
+ ),
125
+ ] = None,
126
+ from_layer: Annotated[
127
+ str | None,
128
+ typer.Option(
129
+ "--from-layer",
130
+ help="Source layer: [green]BTC_LN[/green], [green]RGB_LN[/green], [green]BTC_ONCHAIN[/green]. Defaults from the requested pair direction.",
131
+ ),
132
+ ] = None,
133
+ to_layer: Annotated[
134
+ str | None,
135
+ typer.Option(
136
+ "--to-layer",
137
+ help="Destination layer: [green]BTC_LN[/green], [green]RGB_LN[/green], [green]BTC_ONCHAIN[/green]. Defaults from the requested pair direction.",
138
+ ),
139
+ ] = None,
140
+ ) -> None:
141
+ """Get a swap quote for a trading pair."""
142
+ asyncio.run(
143
+ _market_quote(
144
+ pair,
145
+ from_amount,
146
+ to_amount,
147
+ from_layer,
148
+ to_layer,
149
+ )
150
+ )
151
+
152
+
153
+ async def _market_quote(
154
+ pair: str | None,
155
+ from_amount: str | None,
156
+ to_amount: str | None,
157
+ from_layer: str | None,
158
+ to_layer: str | None,
159
+ ) -> None:
160
+ try:
161
+ client = get_client()
162
+ resolved_quote = await resolve_and_fetch_quote(
163
+ client,
164
+ pair=pair,
165
+ from_amount=from_amount,
166
+ to_amount=to_amount,
167
+ from_layer=from_layer,
168
+ to_layer=to_layer,
169
+ )
170
+ quote = resolved_quote.quote
171
+
172
+ if is_json_mode():
173
+ print_json(quote.model_dump())
174
+ return
175
+
176
+ output_model(quote, title=f"Quote — {resolved_quote.inputs.pair}")
177
+ except typer.Exit:
178
+ raise
179
+ except Exception as e:
180
+ raise_cli_error(e)
181
+
182
+
183
+ @market_app.command("info")
184
+ def market_info() -> None:
185
+ """Show Kaleidoswap maker node information."""
186
+ asyncio.run(_market_info())
187
+
188
+
189
+ async def _market_info() -> None:
190
+ try:
191
+ client = get_client()
192
+ info = await client.maker.get_swap_node_info()
193
+ if is_json_mode():
194
+ print_json(info.model_dump())
195
+ else:
196
+ output_model(info, title="Maker Node Info")
197
+ except Exception as e:
198
+ raise_cli_error(e)
199
+
200
+
201
+ @market_app.command(
202
+ "routes",
203
+ epilog=(
204
+ "[bold]Examples[/bold]\n\n"
205
+ " List routes for BTC/USDT:\n"
206
+ " [cyan]kaleido market routes BTC/USDT[/cyan]\n\n"
207
+ " Raw JSON:\n"
208
+ " [cyan]kaleido --json market routes BTC/USDT[/cyan]"
209
+ ),
210
+ )
211
+ def market_routes(
212
+ pair: Annotated[
213
+ str | None,
214
+ typer.Argument(help="Trading pair in BASE/QUOTE format, e.g. BTC/USDT."),
215
+ ] = None,
216
+ ) -> None:
217
+ """List available swap routes for a trading pair."""
218
+ asyncio.run(_market_routes(resolve_pair(pair)))
219
+
220
+
221
+ async def _market_routes(pair: str) -> None:
222
+ try:
223
+ client = get_client()
224
+ resolved_pair = resolve_trading_pair((await client.maker.list_pairs()).pairs, pair)
225
+ if not resolved_pair:
226
+ print_error(
227
+ f"Pair {pair!r} not found. Use 'kaleido market pairs' to list available pairs."
228
+ )
229
+ raise typer.Exit(1)
230
+ matched_pair, _ = resolved_pair
231
+ routes = await client.maker.get_pair_routes(canonical_pair(matched_pair))
232
+ if is_json_mode():
233
+ print_json([r.model_dump() for r in routes])
234
+ return
235
+ output_collection(
236
+ f"Routes — {pair.upper()}",
237
+ [r.model_dump() for r in routes],
238
+ item_title=f"Route — {pair.upper()} #{{index}}",
239
+ )
240
+ except Exception as e:
241
+ raise_cli_error(e)