o2-cli 0.1.0__tar.gz

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.
Files changed (36) hide show
  1. o2_cli-0.1.0/LICENSE +21 -0
  2. o2_cli-0.1.0/PKG-INFO +141 -0
  3. o2_cli-0.1.0/README.md +111 -0
  4. o2_cli-0.1.0/o2_cli/__init__.py +30 -0
  5. o2_cli-0.1.0/o2_cli/__main__.py +6 -0
  6. o2_cli-0.1.0/o2_cli/cli.py +94 -0
  7. o2_cli-0.1.0/o2_cli/client.py +307 -0
  8. o2_cli-0.1.0/o2_cli/commands/__init__.py +1 -0
  9. o2_cli-0.1.0/o2_cli/commands/_helpers.py +65 -0
  10. o2_cli-0.1.0/o2_cli/commands/account.py +46 -0
  11. o2_cli-0.1.0/o2_cli/commands/admin.py +147 -0
  12. o2_cli-0.1.0/o2_cli/commands/auth.py +140 -0
  13. o2_cli-0.1.0/o2_cli/commands/balance.py +64 -0
  14. o2_cli-0.1.0/o2_cli/commands/deposits.py +89 -0
  15. o2_cli-0.1.0/o2_cli/commands/fees.py +73 -0
  16. o2_cli-0.1.0/o2_cli/commands/markets.py +129 -0
  17. o2_cli-0.1.0/o2_cli/commands/mm.py +182 -0
  18. o2_cli-0.1.0/o2_cli/commands/notifications.py +136 -0
  19. o2_cli-0.1.0/o2_cli/commands/orders.py +331 -0
  20. o2_cli-0.1.0/o2_cli/commands/positions.py +158 -0
  21. o2_cli-0.1.0/o2_cli/commands/settings.py +129 -0
  22. o2_cli-0.1.0/o2_cli/commands/setup_cmd.py +78 -0
  23. o2_cli-0.1.0/o2_cli/commands/trades.py +86 -0
  24. o2_cli-0.1.0/o2_cli/commands/withdrawals.py +175 -0
  25. o2_cli-0.1.0/o2_cli/config.py +87 -0
  26. o2_cli-0.1.0/o2_cli/exceptions.py +31 -0
  27. o2_cli-0.1.0/o2_cli/output.py +224 -0
  28. o2_cli-0.1.0/o2_cli/setup.py +561 -0
  29. o2_cli-0.1.0/o2_cli.egg-info/PKG-INFO +141 -0
  30. o2_cli-0.1.0/o2_cli.egg-info/SOURCES.txt +34 -0
  31. o2_cli-0.1.0/o2_cli.egg-info/dependency_links.txt +1 -0
  32. o2_cli-0.1.0/o2_cli.egg-info/entry_points.txt +2 -0
  33. o2_cli-0.1.0/o2_cli.egg-info/requires.txt +11 -0
  34. o2_cli-0.1.0/o2_cli.egg-info/top_level.txt +1 -0
  35. o2_cli-0.1.0/pyproject.toml +52 -0
  36. o2_cli-0.1.0/setup.cfg +4 -0
o2_cli-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dylan Wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
o2_cli-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,141 @@
1
+ Metadata-Version: 2.4
2
+ Name: o2-cli
3
+ Version: 0.1.0
4
+ Summary: CLI for O2 DEX Trading Platform
5
+ Author: Dylan Wu
6
+ License-Expression: MIT
7
+ Keywords: cli,trading,dex,lighter,o2
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Office/Business :: Financial :: Investment
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: typer[all]>=0.9.0
20
+ Requires-Dist: rich>=13.0.0
21
+ Requires-Dist: httpx>=0.25.0
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Dist: prompt-toolkit>=3.0.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
26
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
27
+ Requires-Dist: respx>=0.20.0; extra == "dev"
28
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # O2 CLI
32
+
33
+ Command-line interface for [O2 DEX](https://github.com/dylanwu19850222/lighter-dex) Trading Platform.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install o2-cli
39
+ ```
40
+
41
+ ## Quick Start
42
+
43
+ ```bash
44
+ # Login (dev environment)
45
+ o2 auth test-login
46
+
47
+ # View markets (public, no login needed)
48
+ o2 --json markets list
49
+
50
+ # Check balance
51
+ o2 --json balance show
52
+
53
+ # Place a market order (long 0.001 BTC)
54
+ o2 --json orders create -m 1 -s long -t market -a 0.001
55
+
56
+ # View positions
57
+ o2 --json positions list
58
+ ```
59
+
60
+ ## Vibe Coding Tool Setup
61
+
62
+ After installing, run the setup wizard to install skill files for your AI coding tool:
63
+
64
+ ```bash
65
+ # Interactive wizard
66
+ o2 setup
67
+
68
+ # Non-interactive
69
+ o2 setup --tool claude-code --scope global
70
+ o2 setup --tool cursor --scope project
71
+
72
+ # Update all installed tools
73
+ o2 setup --update
74
+ ```
75
+
76
+ Supported tools: **Claude Code**, **Cursor**, **Codex (OpenAI)**, **Windsurf**, **Cline**, **Trae**
77
+
78
+ ## Key Rules
79
+
80
+ 1. `--json` must come before the subcommand: `o2 --json balance show` (not `o2 balance show --json`)
81
+ 2. Public commands (no login): `markets list`, `fees rates`
82
+ 3. Other commands require `o2 auth test-login` first
83
+ 4. Exit codes: 0 = success, 1 = error
84
+
85
+ ## Commands
86
+
87
+ | Group | Commands | Auth Required |
88
+ |-------|----------|---------------|
89
+ | `auth` | `test-login`, `me`, `session` | No (login) |
90
+ | `markets` | `list`, `orderbook`, `candles`, `trades` | No |
91
+ | `fees` | `rates`, `estimate` | No |
92
+ | `balance` | `show`, `history` | Yes |
93
+ | `orders` | `create`, `list`, `cancel`, `cancel-all`, `modify`, `batch` | Yes |
94
+ | `positions` | `list`, `market`, `close`, `risk` | Yes |
95
+ | `trades` | `list`, `summary` | Yes |
96
+ | `deposits` | `address`, `history` | Yes |
97
+ | `withdrawals` | `create`, `status`, `cancel`, `list` | Yes |
98
+ | `settings` | `get`, `leverage`, `margin-mode` | Yes |
99
+ | `notifications` | `list`, `unread`, `read` | Yes |
100
+ | `account` | `overview` | Yes |
101
+ | `mm` | `status`, `start`, `stop`, `stats`, `orders` | API Key |
102
+ | `admin` | `gas-status`, `proxy-list`, `api-keys`, `reconcile` | Admin JWT |
103
+ | `setup` | wizard, `--tool`, `--update`, `--status` | No |
104
+
105
+ ## Configuration
106
+
107
+ Config file: `~/.o2/config.yaml`
108
+
109
+ ```yaml
110
+ active_profile: default
111
+ profiles:
112
+ default:
113
+ api_url: http://localhost:8000/api/v1
114
+ timeout: 30
115
+ auth_type: jwt
116
+ token: eyJ... # auto-saved
117
+ ```
118
+
119
+ Override at runtime:
120
+ ```bash
121
+ o2 --profile production --json balance show
122
+ o2 --api-url https://api.example.com/api/v1 --json markets list
123
+ ```
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ git clone https://github.com/dylanwu19850222/o2-cli.git
129
+ cd o2-cli
130
+ pip install -e ".[dev]"
131
+
132
+ # Run tests
133
+ pytest
134
+
135
+ # Lint
136
+ ruff check o2_cli/
137
+ ```
138
+
139
+ ## License
140
+
141
+ MIT
o2_cli-0.1.0/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # O2 CLI
2
+
3
+ Command-line interface for [O2 DEX](https://github.com/dylanwu19850222/lighter-dex) Trading Platform.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install o2-cli
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # Login (dev environment)
15
+ o2 auth test-login
16
+
17
+ # View markets (public, no login needed)
18
+ o2 --json markets list
19
+
20
+ # Check balance
21
+ o2 --json balance show
22
+
23
+ # Place a market order (long 0.001 BTC)
24
+ o2 --json orders create -m 1 -s long -t market -a 0.001
25
+
26
+ # View positions
27
+ o2 --json positions list
28
+ ```
29
+
30
+ ## Vibe Coding Tool Setup
31
+
32
+ After installing, run the setup wizard to install skill files for your AI coding tool:
33
+
34
+ ```bash
35
+ # Interactive wizard
36
+ o2 setup
37
+
38
+ # Non-interactive
39
+ o2 setup --tool claude-code --scope global
40
+ o2 setup --tool cursor --scope project
41
+
42
+ # Update all installed tools
43
+ o2 setup --update
44
+ ```
45
+
46
+ Supported tools: **Claude Code**, **Cursor**, **Codex (OpenAI)**, **Windsurf**, **Cline**, **Trae**
47
+
48
+ ## Key Rules
49
+
50
+ 1. `--json` must come before the subcommand: `o2 --json balance show` (not `o2 balance show --json`)
51
+ 2. Public commands (no login): `markets list`, `fees rates`
52
+ 3. Other commands require `o2 auth test-login` first
53
+ 4. Exit codes: 0 = success, 1 = error
54
+
55
+ ## Commands
56
+
57
+ | Group | Commands | Auth Required |
58
+ |-------|----------|---------------|
59
+ | `auth` | `test-login`, `me`, `session` | No (login) |
60
+ | `markets` | `list`, `orderbook`, `candles`, `trades` | No |
61
+ | `fees` | `rates`, `estimate` | No |
62
+ | `balance` | `show`, `history` | Yes |
63
+ | `orders` | `create`, `list`, `cancel`, `cancel-all`, `modify`, `batch` | Yes |
64
+ | `positions` | `list`, `market`, `close`, `risk` | Yes |
65
+ | `trades` | `list`, `summary` | Yes |
66
+ | `deposits` | `address`, `history` | Yes |
67
+ | `withdrawals` | `create`, `status`, `cancel`, `list` | Yes |
68
+ | `settings` | `get`, `leverage`, `margin-mode` | Yes |
69
+ | `notifications` | `list`, `unread`, `read` | Yes |
70
+ | `account` | `overview` | Yes |
71
+ | `mm` | `status`, `start`, `stop`, `stats`, `orders` | API Key |
72
+ | `admin` | `gas-status`, `proxy-list`, `api-keys`, `reconcile` | Admin JWT |
73
+ | `setup` | wizard, `--tool`, `--update`, `--status` | No |
74
+
75
+ ## Configuration
76
+
77
+ Config file: `~/.o2/config.yaml`
78
+
79
+ ```yaml
80
+ active_profile: default
81
+ profiles:
82
+ default:
83
+ api_url: http://localhost:8000/api/v1
84
+ timeout: 30
85
+ auth_type: jwt
86
+ token: eyJ... # auto-saved
87
+ ```
88
+
89
+ Override at runtime:
90
+ ```bash
91
+ o2 --profile production --json balance show
92
+ o2 --api-url https://api.example.com/api/v1 --json markets list
93
+ ```
94
+
95
+ ## Development
96
+
97
+ ```bash
98
+ git clone https://github.com/dylanwu19850222/o2-cli.git
99
+ cd o2-cli
100
+ pip install -e ".[dev]"
101
+
102
+ # Run tests
103
+ pytest
104
+
105
+ # Lint
106
+ ruff check o2_cli/
107
+ ```
108
+
109
+ ## License
110
+
111
+ MIT
@@ -0,0 +1,30 @@
1
+ """O2 CLI - Command-line interface for O2 DEX Trading Platform."""
2
+
3
+ from pathlib import Path
4
+
5
+ __version__ = "0.1.0"
6
+
7
+
8
+ def ensure_skill_installed() -> bool:
9
+ """自动安装 Claude Code Skill 到 ~/.claude/skills/o2-cli/。
10
+
11
+ 首次运行 o2 命令时检查并安装。不覆盖已有文件(用户可能自定义过)。
12
+
13
+ Returns:
14
+ True 如果 skill 已存在或刚安装成功,False 如果安装失败。
15
+ """
16
+ skill_dir = Path.home() / ".claude" / "skills" / "o2-cli"
17
+ skill_file = skill_dir / "SKILL.md"
18
+
19
+ if skill_file.exists():
20
+ return True
21
+
22
+ try:
23
+ from o2_cli.setup import SKILL_CONTENT
24
+
25
+ skill_dir.mkdir(parents=True, exist_ok=True)
26
+ skill_file.write_text(SKILL_CONTENT, encoding="utf-8")
27
+ return True
28
+ except OSError:
29
+ # 权限不足或其他 IO 错误,静默失败不影响 CLI 使用
30
+ return False
@@ -0,0 +1,6 @@
1
+ """Support `python -m o2_cli`."""
2
+
3
+ from o2_cli.cli import app
4
+
5
+ if __name__ == "__main__":
6
+ app()
@@ -0,0 +1,94 @@
1
+ """O2 CLI root - Typer application with global options."""
2
+
3
+ import asyncio
4
+ import typing as t
5
+ from typing import Optional
6
+
7
+ import typer
8
+
9
+ from o2_cli import __version__, ensure_skill_installed
10
+
11
+ app = typer.Typer(
12
+ name="o2",
13
+ help="O2 DEX Trading Platform CLI",
14
+ no_args_is_help=True,
15
+ rich_markup_mode="rich",
16
+ )
17
+
18
+
19
+ def version_callback(value: bool):
20
+ if value:
21
+ typer.echo(f"o2-cli version {__version__}")
22
+ raise typer.Exit()
23
+
24
+
25
+ @app.callback()
26
+ def main(
27
+ json_output: bool = typer.Option(False, "--json", help="Output raw JSON"),
28
+ config: Optional[str] = typer.Option(None, "--config", help="Config file path"),
29
+ profile: Optional[str] = typer.Option(None, "--profile", help="Config profile"),
30
+ api_url: Optional[str] = typer.Option(None, "--api-url", help="Override API URL"),
31
+ timeout: float = typer.Option(30.0, "--timeout", help="HTTP timeout in seconds"),
32
+ verbose: bool = typer.Option(False, "-v", "--verbose", help="Verbose logging"),
33
+ version: bool = typer.Option(False, "--version", callback=version_callback, is_eager=True),
34
+ ):
35
+ """O2 DEX Trading Platform CLI."""
36
+ # Auto-install Claude Code skill on first run
37
+ ensure_skill_installed()
38
+ # Store global state for commands to access
39
+ app.state = {
40
+ "json_output": json_output,
41
+ "config_path": config,
42
+ "profile": profile,
43
+ "api_url": api_url,
44
+ "timeout": timeout,
45
+ "verbose": verbose,
46
+ }
47
+
48
+
49
+ def get_state() -> dict:
50
+ """Get global CLI state."""
51
+ return getattr(app, "state", {
52
+ "json_output": False,
53
+ "config_path": None,
54
+ "profile": None,
55
+ "api_url": None,
56
+ "timeout": 30.0,
57
+ "verbose": False,
58
+ })
59
+
60
+
61
+ # Register command groups
62
+ from o2_cli.commands import ( # noqa: E402
63
+ auth,
64
+ balance,
65
+ orders,
66
+ positions,
67
+ markets,
68
+ trades,
69
+ fees,
70
+ deposits,
71
+ withdrawals,
72
+ settings,
73
+ notifications,
74
+ account,
75
+ admin,
76
+ mm,
77
+ setup_cmd,
78
+ )
79
+
80
+ app.add_typer(auth.app, name="auth", help="Authentication")
81
+ app.add_typer(balance.app, name="balance", help="Balance queries")
82
+ app.add_typer(orders.app, name="orders", help="Order management")
83
+ app.add_typer(positions.app, name="positions", help="Position management")
84
+ app.add_typer(markets.app, name="markets", help="Market data")
85
+ app.add_typer(trades.app, name="trades", help="Trade history")
86
+ app.add_typer(fees.app, name="fees", help="Fee information")
87
+ app.add_typer(deposits.app, name="deposits", help="Deposit management")
88
+ app.add_typer(withdrawals.app, name="withdrawals", help="Withdrawal management")
89
+ app.add_typer(settings.app, name="settings", help="User settings")
90
+ app.add_typer(notifications.app, name="notifications", help="Notifications")
91
+ app.add_typer(account.app, name="account", help="Account overview")
92
+ app.add_typer(admin.app, name="admin", help="Admin operations")
93
+ app.add_typer(mm.app, name="mm", help="Market maker control")
94
+ app.add_typer(setup_cmd.app, name="setup", help="Setup for vibe coding tools")