desic-okx-agent 0.1.9 → 0.2.1

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 (47) hide show
  1. package/README.en.md +273 -0
  2. package/README.md +155 -175
  3. package/dist/account/private-websocket.d.ts +1 -0
  4. package/dist/account/private-websocket.js +27 -2
  5. package/dist/account/private-websocket.js.map +1 -1
  6. package/dist/cli/doctor.d.ts +14 -0
  7. package/dist/cli/doctor.js +133 -0
  8. package/dist/cli/doctor.js.map +1 -0
  9. package/dist/cli/index.js +186 -10
  10. package/dist/cli/index.js.map +1 -1
  11. package/dist/cli/prompts.d.ts +1 -0
  12. package/dist/cli/prompts.js +6 -0
  13. package/dist/cli/prompts.js.map +1 -1
  14. package/dist/cli/render.d.ts +8 -0
  15. package/dist/cli/render.js +73 -0
  16. package/dist/cli/render.js.map +1 -0
  17. package/dist/market/store.d.ts +1 -0
  18. package/dist/market/store.js +24 -0
  19. package/dist/market/store.js.map +1 -1
  20. package/dist/market/websocket.d.ts +1 -0
  21. package/dist/market/websocket.js +13 -0
  22. package/dist/market/websocket.js.map +1 -1
  23. package/dist/runtime/client.d.ts +1 -0
  24. package/dist/runtime/client.js +46 -2
  25. package/dist/runtime/client.js.map +1 -1
  26. package/dist/runtime/server.js +21 -2
  27. package/dist/runtime/server.js.map +1 -1
  28. package/dist/setup/installer.d.ts +21 -0
  29. package/dist/setup/installer.js +113 -27
  30. package/dist/setup/installer.js.map +1 -1
  31. package/dist/setup/wizard.d.ts +3 -0
  32. package/dist/setup/wizard.js +131 -3
  33. package/dist/setup/wizard.js.map +1 -1
  34. package/dist/storage/database.d.ts +2 -0
  35. package/dist/storage/database.js +23 -0
  36. package/dist/storage/database.js.map +1 -1
  37. package/dist/tools/catalog.js +1 -1
  38. package/dist/tools/catalog.js.map +1 -1
  39. package/dist/tools/help.d.ts +10 -0
  40. package/dist/tools/help.js +79 -0
  41. package/dist/tools/help.js.map +1 -0
  42. package/dist/update/service.d.ts +10 -0
  43. package/dist/update/service.js +104 -0
  44. package/dist/update/service.js.map +1 -0
  45. package/package.json +2 -1
  46. package/skills/okx-news-intelligence/SKILL.md +2 -0
  47. package/skills/okx-smart-money-analysis/SKILL.md +2 -0
package/README.en.md ADDED
@@ -0,0 +1,273 @@
1
+ # Desic OKX Agent
2
+
3
+ [简体中文](README.md) | [English](README.en.md)
4
+
5
+ An independent local OKX Runtime, MCP server, CLI, and reusable agent Skills for Codex, Claude Code, and other MCP clients.
6
+
7
+ > [!IMPORTANT]
8
+ > Desic OKX Agent is an independent community project. It is not affiliated with, endorsed by, or an official product of OKX.
9
+
10
+ ## Installation
11
+
12
+ Requires Node.js 22.12 or newer and network access to OKX, either directly or through an HTTP/HTTPS proxy.
13
+
14
+ First-time installation uses two commands:
15
+
16
+ ```bash
17
+ npm install --global desic-okx-agent
18
+ desic-okx setup
19
+ ```
20
+
21
+ The commands serve different purposes:
22
+
23
+ 1. `npm install` installs the `desic-okx` program.
24
+ 2. `desic-okx setup` connects AI clients, installs Skills, checks the network, and offers to configure an OKX API account.
25
+
26
+ Run `setup` once after the initial installation. Normal upgrades do not require it again. Run it again only to add an AI client, repair configuration, or change proxy settings.
27
+
28
+ Restart the selected AI clients after setup, then verify the installation:
29
+
30
+ ```bash
31
+ desic-okx doctor
32
+ ```
33
+
34
+ ## What setup does
35
+
36
+ The interactive guide:
37
+
38
+ 1. Lets you select Codex, Claude Code, Cursor, VS Code / GitHub Copilot, Cline, or all clients.
39
+ 2. Registers the `desic-okx` MCP server without replacing existing MCP entries.
40
+ 3. Installs all seven bundled Skills for Codex and Claude Code.
41
+ 4. Checks OKX REST and WebSocket connectivity and guides you through testing and saving an HTTP proxy when needed.
42
+ 5. Explains which features require an API key and lets you configure one now or skip it.
43
+ 6. Masks credential input, verifies the account with OKX, and saves it only after successful verification.
44
+
45
+ An API account is optional. Public market and derivatives tools remain available when you skip this step. Configure an account later with:
46
+
47
+ ```bash
48
+ desic-okx account add
49
+ ```
50
+
51
+ For automation, select clients without opening the interactive guide. Non-interactive setup never requests or saves API credentials:
52
+
53
+ ```bash
54
+ desic-okx setup --targets codex --yes
55
+ desic-okx setup --targets codex,claude-code --yes
56
+ desic-okx setup --all --yes
57
+ desic-okx setup --targets codex --yes --skip-network-check
58
+ ```
59
+
60
+ ## Configure an OKX API account
61
+
62
+ Create an API key in the official OKX website or app. Live and Demo Trading accounts use keys for their respective environments, so select the matching `live` or `demo` environment in the guide.
63
+
64
+ Grant only the permissions needed for your use case:
65
+
66
+ | Capability | API key required | Requirement |
67
+ | --- | --- | --- |
68
+ | Public market data, candles, books, derivatives analysis | No | None |
69
+ | Balances, positions, orders, fills, and risk summaries | Yes | Read permission |
70
+ | Remote News and Smart Money | Yes | A `live` account; read permission is sufficient |
71
+ | Place, amend, cancel, close, and leverage operations | Yes | Trade permission on the OKX API key |
72
+
73
+ This project has no withdrawal, deposit, transfer, asset-movement, or API-key-management tools. Those permissions are not needed. Test trading workflows with an OKX Demo account first, and configure an IP allowlist in OKX according to your security policy.
74
+
75
+ Add an account interactively:
76
+
77
+ ```bash
78
+ desic-okx account add --name demo --environment demo
79
+ desic-okx account add --name main --environment live
80
+ ```
81
+
82
+ API Key, Secret Key, and Passphrase input is hidden. `account add` verifies the credentials with OKX before writing them; failed verification saves nothing. Credentials are stored in `config.json` under the system configuration directory, with Unix permissions set to `0600`:
83
+
84
+ ```bash
85
+ desic-okx config-path
86
+ ```
87
+
88
+ Environment variables can override an account with the same name:
89
+
90
+ ```text
91
+ OKX_ACCOUNT
92
+ OKX_API_KEY
93
+ OKX_API_SECRET
94
+ OKX_API_PASSPHRASE
95
+ OKX_ENVIRONMENT=demo|live
96
+ ```
97
+
98
+ All three credential variables must be provided together. Trading availability is determined entirely by the permissions assigned to the API key in OKX.
99
+
100
+ ## Ask an AI to install it
101
+
102
+ Paste this prompt into Codex, Claude Code, Cursor, VS Code / GitHub Copilot, or Cline. Replace `codex` with `claude-code`, `cursor`, `vscode`, `cline`, or `all` as appropriate.
103
+
104
+ ```text
105
+ Install Desic OKX Agent for me:
106
+ 1. Confirm Node.js is version 22.12 or newer.
107
+ 2. Run npm install --global desic-okx-agent.
108
+ 3. Run desic-okx setup --targets codex --yes.
109
+ 4. Run desic-okx doctor to verify MCP, Skills, and OKX connectivity.
110
+ 5. Never ask me to send an API Key, Secret, or Passphrase in chat.
111
+ 6. Confirm that public tools are ready. If I need account, News, Smart Money, or trading features, guide me to run desic-okx account add in my own terminal and enter credentials into its hidden prompts.
112
+ ```
113
+
114
+ ## Quick start
115
+
116
+ Public market data does not require an account:
117
+
118
+ ```bash
119
+ desic-okx call market_get_ticker --json '{"instId":"BTC-USDT-SWAP"}'
120
+ desic-okx call market_get_decision_snapshot --json '{"instId":"BTC-USDT-SWAP","bar":"1m"}'
121
+ ```
122
+
123
+ The Runtime starts automatically on the first MCP or CLI call. Running `desic-okx start` manually is normally unnecessary.
124
+
125
+ Useful commands:
126
+
127
+ ```bash
128
+ desic-okx status
129
+ desic-okx doctor
130
+ desic-okx tools
131
+ desic-okx tool market_get_decision_snapshot
132
+ desic-okx account list
133
+ desic-okx update --check
134
+ ```
135
+
136
+ `status` reports Runtime version, uptime, proxy route, WebSocket state, subscriptions and data ages, accounts, and database state. `doctor` actively checks installation, network, SQLite, market data, accounts, MCP clients, and Skills. Both support `--json`.
137
+
138
+ ## Main capabilities
139
+
140
+ - A shared singleton Runtime reused by multiple MCP and CLI clients
141
+ - In-memory ticker, order book, trades, candles, funding, mark price, and open-interest data
142
+ - Time-aligned decision snapshots with freshness, exchange timestamps, and consistency metadata
143
+ - Public market data, indicators, scanning, and public derivatives analysis
144
+ - Account balances, positions, orders, fills, bills, and risk summaries
145
+ - Ordinary orders, algo orders, leverage, amend, cancel, and close-position operations
146
+ - Experimental News and Smart Money capabilities with SQLite history fallback
147
+ - SQLite WAL persistence for closed candles, intelligence history, derived events, and execution records
148
+
149
+ ## Skills
150
+
151
+ `desic-okx setup` automatically installs these for Codex and Claude Code:
152
+
153
+ - `okx-market-analysis`
154
+ - `okx-derivatives-analysis`
155
+ - `okx-news-intelligence`
156
+ - `okx-smart-money-analysis`
157
+ - `okx-account-analysis`
158
+ - `okx-trading`
159
+ - `trading-philosophy`
160
+
161
+ Skills are synchronized after upgrades. You can also inspect or synchronize them manually; modified copies are backed up first:
162
+
163
+ ```bash
164
+ desic-okx skills status
165
+ desic-okx skills sync
166
+ desic-okx skills sync --targets codex --dry-run
167
+ ```
168
+
169
+ ## Account management
170
+
171
+ ```bash
172
+ desic-okx account list
173
+ desic-okx account verify --name main
174
+ desic-okx account verify --all
175
+ desic-okx account set-default main
176
+ desic-okx account rename main primary
177
+ desic-okx account edit primary
178
+ desic-okx account remove primary
179
+ ```
180
+
181
+ `account add` and `account edit` verify credentials before writing the configuration. Tool parameters accept account aliases only, never API Key, Secret, or Passphrase values.
182
+
183
+ ## Tool help
184
+
185
+ ```bash
186
+ desic-okx tools
187
+ desic-okx tool news_search
188
+ desic-okx tool trade_place_order
189
+ desic-okx tool trade_place_order --json
190
+ ```
191
+
192
+ Help includes purpose, account requirements, input schema, and a runnable call example. Remote News and Smart Money interfaces are experimental. Upstream compatibility failures return `CAPABILITY_UNAVAILABLE` without disabling market, account, or trading modules.
193
+
194
+ ## Proxy
195
+
196
+ REST and public, business, and private WebSocket connections use the same proxy resolution order:
197
+
198
+ 1. `proxy.url` in `config.json`
199
+ 2. `HTTPS_PROXY`, `HTTP_PROXY`, or `ALL_PROXY`, with `NO_PROXY` support
200
+ 3. The enabled Windows or macOS HTTP/HTTPS system proxy
201
+ 4. Direct connection
202
+
203
+ Only HTTP and HTTPS proxy URLs are supported. PAC-only and SOCKS-only environments need an HTTP proxy endpoint. Example:
204
+
205
+ ```json
206
+ {
207
+ "proxy": {
208
+ "url": "http://127.0.0.1:7890"
209
+ }
210
+ }
211
+ ```
212
+
213
+ Stop the Runtime after changing configuration:
214
+
215
+ ```bash
216
+ desic-okx stop
217
+ ```
218
+
219
+ ## Update
220
+
221
+ ```bash
222
+ desic-okx update --check
223
+ desic-okx update
224
+ desic-okx update --yes
225
+ ```
226
+
227
+ The updater checks the official npm registry, stops the Runtime, waits for Windows to release the native SQLite module, installs the global update, synchronizes installed Skills, and runs Doctor. A newer CLI or MCP adapter also replaces an older running Runtime automatically.
228
+
229
+ ## Manual client setup
230
+
231
+ `desic-okx setup` is recommended. To register only the MCP server:
232
+
233
+ ```bash
234
+ codex mcp add desic-okx -- desic-okx mcp
235
+ claude mcp add --transport stdio --scope user desic-okx -- desic-okx mcp
236
+ ```
237
+
238
+ Manual Codex configuration:
239
+
240
+ ```toml
241
+ [mcp_servers.desic-okx]
242
+ command = "desic-okx"
243
+ args = ["mcp"]
244
+ ```
245
+
246
+ ## Development from source
247
+
248
+ ```bash
249
+ git clone https://github.com/xiazhi88/desic-okx-agent.git
250
+ cd desic-okx-agent
251
+ npm ci
252
+ npm run check
253
+ npm link
254
+ ```
255
+
256
+ The check pipeline includes TypeScript type checking, unit tests, Skill validation, sensitive-information scanning, a production build, and an MCP transport smoke test. Normal tests never submit orders; real trading end-to-end tests are restricted to OKX Demo.
257
+
258
+ ## Runtime behavior
259
+
260
+ - The Runtime binds a random `127.0.0.1` port and stores its PID, port, and access token in private state files.
261
+ - It prewarms `BTC-USDT-SWAP` and `ETH-USDT-SWAP`; other instruments are subscribed on demand and released after 15 idle minutes.
262
+ - Hot data is returned from memory. Cold or stale data is backfilled by REST.
263
+ - WebSockets reconnect automatically; the order book is rebuilt after sequence or checksum failures.
264
+ - `market_get_decision_snapshot` aligns components and reports their maximum time skew. Trading prechecks reject inconsistent snapshots.
265
+ - Trading writes use a stable `executionKey`. Ambiguous or timed-out writes query remote state before any retry.
266
+
267
+ Trading software can cause financial loss. This project provides no investment advice and makes no guarantee of execution results.
268
+
269
+ ## Status and license
270
+
271
+ This is pre-release software at version `0.2.1`. OKX Demo trading should be validated in the target network environment before a `1.0.0` release.
272
+
273
+ MIT License. See `LICENSE`. OKX and related marks belong to their respective owners.