@pungoyal/kite-cli 0.1.1 → 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.
- package/README.md +113 -6
- package/dist/commands/alerts.d.ts +12 -0
- package/dist/commands/alerts.js +529 -0
- package/dist/commands/auth.js +104 -28
- package/dist/commands/config.js +56 -13
- package/dist/commands/profiles.d.ts +10 -0
- package/dist/commands/profiles.js +213 -0
- package/dist/commands/watch.js +1 -1
- package/dist/context.d.ts +6 -0
- package/dist/context.js +36 -18
- package/dist/core/api.d.ts +249 -42
- package/dist/core/api.js +100 -1
- package/dist/core/config.d.ts +77 -23
- package/dist/core/config.js +53 -21
- package/dist/core/credentials.d.ts +3 -2
- package/dist/core/credentials.js +13 -7
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.js +2 -2
- package/dist/core/paths.d.ts +9 -2
- package/dist/core/paths.js +12 -3
- package/dist/core/profiles.d.ts +78 -0
- package/dist/core/profiles.js +140 -0
- package/dist/core/schemas.d.ts +78 -5
- package/dist/core/schemas.js +55 -0
- package/dist/core/session.d.ts +3 -2
- package/dist/core/session.js +7 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/run.js +6 -0
- package/dist/safety.js +12 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/pungoyal/kite-cli/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/@pungoyal/kite-cli)
|
|
5
|
+
[](https://github.com/pungoyal/kite-cli/releases/latest)
|
|
5
6
|
[](https://nodejs.org)
|
|
6
|
-
[](LICENSE)
|
|
7
|
+
[](https://github.com/pungoyal/kite-cli/blob/main/LICENSE)
|
|
8
|
+
[](https://pungoyal.github.io/kite-cli/)
|
|
7
9
|
|
|
8
10
|
An **unofficial**, secure, scriptable command-line interface for the [Zerodha Kite Connect](https://kite.trade/docs/connect/v3/) API.
|
|
9
11
|
|
|
@@ -57,8 +59,12 @@ kite login --env sandbox
|
|
|
57
59
|
kite --env sandbox holdings
|
|
58
60
|
```
|
|
59
61
|
|
|
62
|
+
**Running more than one Zerodha account?** See [Multiple accounts](#multiple-accounts).
|
|
63
|
+
|
|
60
64
|
## Usage
|
|
61
65
|
|
|
66
|
+
The highlights are below; every command's full flag list is in [the command reference](https://pungoyal.github.io/kite-cli/commands).
|
|
67
|
+
|
|
62
68
|
### Portfolio
|
|
63
69
|
|
|
64
70
|
```bash
|
|
@@ -135,8 +141,29 @@ kite gtt place NSE:INFY --side SELL --quantity 10 \
|
|
|
135
141
|
--trigger 1400 --price 1395 \
|
|
136
142
|
--trigger 1700 --price 1695 # two-leg OCO
|
|
137
143
|
kite gtt delete <id>
|
|
144
|
+
|
|
145
|
+
kite alerts list # your price alerts
|
|
146
|
+
kite alerts create "INDICES:NIFTY 50" --operator above --value 27000
|
|
147
|
+
kite alerts get <uuid> # detail, incl. any attached order
|
|
148
|
+
kite alerts history <uuid> # when it has fired
|
|
149
|
+
kite alerts delete <uuid> [<uuid>...]
|
|
138
150
|
```
|
|
139
151
|
|
|
152
|
+
Alerts come in two kinds. A **simple** alert just notifies you when a price
|
|
153
|
+
condition is met — it moves no money, so the kill switch and value cap do not
|
|
154
|
+
apply. An **ATO** (Alert-Triggers-Order) alert places a real order when it fires,
|
|
155
|
+
so creating one goes through the same confirmation, value cap and kill switch as
|
|
156
|
+
`orders place`:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
kite alerts create NSE:INFY --operator below --value 1400 \
|
|
160
|
+
--type ato --side BUY --quantity 10 --order-type LIMIT --price 1400
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`--operator` accepts the raw symbols (`>=`, `<=`, `>`, `<`, `==`) or the aliases
|
|
164
|
+
`above`, `below`, `ge`, `le`, `gt`, `lt`, `eq`. Compare against another instrument
|
|
165
|
+
instead of a constant with `--rhs-instrument EXCHANGE:SYMBOL`.
|
|
166
|
+
|
|
140
167
|
Add `--dry-run` to any of these to see exactly what would be sent, without sending it.
|
|
141
168
|
|
|
142
169
|
### Scripting
|
|
@@ -169,9 +196,64 @@ kite whoami --json || kite login # exit code 3 means "no session"
|
|
|
169
196
|
|
|
170
197
|
`NO_COLOR` is honoured, and colour is disabled automatically when stdout is not a TTY.
|
|
171
198
|
|
|
199
|
+
## Multiple accounts
|
|
200
|
+
|
|
201
|
+
If you run more than one Zerodha account — your own, a family member's, an HUF — each
|
|
202
|
+
gets a named **profile** with its own Kite Connect app credentials and its own daily
|
|
203
|
+
session. Several accounts can be logged in at once; you choose which one a command
|
|
204
|
+
targets.
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
kite profiles add huf # register a profile (create its Kite app first)
|
|
208
|
+
kite --profile huf login # log in to it (prompts for that app's key + secret)
|
|
209
|
+
kite --profile huf holdings # run any command against it
|
|
210
|
+
kite profiles list # see every profile and its session status
|
|
211
|
+
kite profiles use huf # make it the default for commands without --profile
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`profiles add` can take the account's settings up front so `login` doesn't have to
|
|
215
|
+
prompt for them: `--api-key <key>`, `--env sandbox` (the profile's environment,
|
|
216
|
+
default `production`), and `--max-order-value <rupees>` (a per-profile cap). The API
|
|
217
|
+
secret is never a flag — `login` always prompts for it.
|
|
218
|
+
|
|
219
|
+
Selection is resolved fresh every run — there is no hidden "active account" that
|
|
220
|
+
persists silently between commands. The target is chosen by, in order:
|
|
221
|
+
|
|
222
|
+
1. `--profile <name>` on the command line
|
|
223
|
+
2. the `KITE_PROFILE` environment variable
|
|
224
|
+
3. the default set with `kite profiles use`
|
|
225
|
+
4. otherwise the `default` profile
|
|
226
|
+
|
|
227
|
+
`default` is your original single-account setup (nothing to migrate), and `sandbox`
|
|
228
|
+
is a reserved profile — `--env sandbox` is just shorthand for `--profile sandbox`.
|
|
229
|
+
|
|
230
|
+
Because targeting the wrong account is the costly mistake here, every money-moving
|
|
231
|
+
confirmation shows the **verified account** it will hit — the user id returned by
|
|
232
|
+
Kite, not just the label you chose:
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
Place BUY order
|
|
236
|
+
Account Priya Sharma (XY9876) · profile huf
|
|
237
|
+
Symbol NSE:INFY
|
|
238
|
+
…
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Safety caps are per profile, inheriting the global setting when unset (an omitted cap
|
|
242
|
+
never means "no cap"):
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
kite --profile huf config set trading.maxOrderValue 50000
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
For scripts and CI, `KITE_API_KEY` / `KITE_API_SECRET` / `KITE_ACCESS_TOKEN` still
|
|
249
|
+
supply credentials directly. As a safeguard, naming a profile explicitly while those
|
|
250
|
+
are set is refused rather than silently overridden.
|
|
251
|
+
|
|
252
|
+
→ Full reference, including credential storage precedence and per-profile inheritance: [the configuration reference](https://pungoyal.github.io/kite-cli/configuration).
|
|
253
|
+
|
|
172
254
|
## Safety
|
|
173
255
|
|
|
174
|
-
This tool spends real money, so the defaults are conservative.
|
|
256
|
+
This tool spends real money, so the defaults are conservative. → Full model, including the order-tag reconciliation flow and why cancels/converts are exempt from the value cap: [the safety model](https://pungoyal.github.io/kite-cli/safety).
|
|
175
257
|
|
|
176
258
|
**Confirmation.** Order commands render the resolved order — the actual instrument token, lot size, and computed value, not an echo of your flags — and wait for confirmation. That's deliberate: a flag echo can't catch "I typed the wrong symbol and it resolved to a different contract," which is the expensive mistake.
|
|
177
259
|
|
|
@@ -210,13 +292,13 @@ Automatic retries are restricted to `GET`/`HEAD` at the transport layer. `POST`,
|
|
|
210
292
|
|
|
211
293
|
Your API secret is never accepted as a command-line argument, because argv is visible to any local process via `ps` and lands in shell history. It's prompted for, or read from the environment.
|
|
212
294
|
|
|
213
|
-
**Redaction.** Access tokens are registered with a scrubber that runs over every log line, error message, and stack trace. The two paths that carry a token — the `Authorization` header and the WebSocket URL, where it's a query parameter — are covered explicitly and [tested](test/redact.test.ts).
|
|
295
|
+
**Redaction.** Access tokens are registered with a scrubber that runs over every log line, error message, and stack trace. The two paths that carry a token — the `Authorization` header and the WebSocket URL, where it's a query parameter — are covered explicitly and [tested](https://github.com/pungoyal/kite-cli/blob/main/test/redact.test.ts).
|
|
214
296
|
|
|
215
297
|
**TOTP.** This CLI will never ask for or store your 2FA seed. Storing it next to your API secret would collapse both authentication factors into one, which is exactly what the SEBI 2FA mandate exists to prevent. Login happens in your browser; the CLI only sees the resulting request token.
|
|
216
298
|
|
|
217
299
|
**Supply chain.** 10 direct runtime dependencies, most of them zero-dependency. Published from GitHub Actions via [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers/) with OIDC — no long-lived publish token exists. Provenance attestation is generated automatically; verify it with `npm audit signatures`. All CI actions are pinned to full commit SHAs, and dependency lifecycle scripts are disabled.
|
|
218
300
|
|
|
219
|
-
To report a vulnerability, see [SECURITY.md](SECURITY.md).
|
|
301
|
+
To report a vulnerability, see [SECURITY.md](https://github.com/pungoyal/kite-cli/blob/main/SECURITY.md).
|
|
220
302
|
|
|
221
303
|
## Configuration
|
|
222
304
|
|
|
@@ -238,6 +320,12 @@ kite config path
|
|
|
238
320
|
|
|
239
321
|
Config lives at `~/.config/kite/config.json` (`0600`). Override the location with `KITE_CONFIG_DIR`.
|
|
240
322
|
|
|
323
|
+
`trading.*`, `apiKey`, and `env` can be set per profile by adding `--profile <name>`
|
|
324
|
+
(see [Multiple accounts](#multiple-accounts)); the remaining keys are global. The
|
|
325
|
+
account this invocation resolves to is selected by `--profile` / `KITE_PROFILE`.
|
|
326
|
+
|
|
327
|
+
→ Every key and environment variable, with precedence: [the configuration reference](https://pungoyal.github.io/kite-cli/configuration).
|
|
328
|
+
|
|
241
329
|
## Things worth knowing about Kite
|
|
242
330
|
|
|
243
331
|
- **Sessions expire at 6:00 AM IST daily.** This is a regulatory requirement and there's no way around it — you log in once per trading day. Refresh tokens exist in the API but are only issued to exchange-approved platforms, not individual subscribers.
|
|
@@ -248,6 +336,25 @@ Config lives at `~/.config/kite/config.json` (`0600`). Override the location wit
|
|
|
248
336
|
- **Instruments are cached by `exchange:tradingsymbol`, never by token.** Exchanges reuse numeric instrument tokens after expiry, so a token-keyed cache silently resolves to the wrong contract after a rollover.
|
|
249
337
|
- **Mutual funds are read-only** over the API — placing MF orders requires a bank debit that has no API path.
|
|
250
338
|
|
|
339
|
+
→ Hit one of these? See [the troubleshooting guide](https://pungoyal.github.io/kite-cli/troubleshooting) for the symptom-first version.
|
|
340
|
+
|
|
341
|
+
## Documentation
|
|
342
|
+
|
|
343
|
+
This README covers installation and everyday usage. The full reference is a
|
|
344
|
+
searchable site at **[pungoyal.github.io/kite-cli](https://pungoyal.github.io/kite-cli/)**:
|
|
345
|
+
|
|
346
|
+
- [Safety model](https://pungoyal.github.io/kite-cli/safety) — the full layered safety model (kill
|
|
347
|
+
switch, value cap, confirmation escalation, order-tag reconciliation).
|
|
348
|
+
- [Configuration](https://pungoyal.github.io/kite-cli/configuration) — every config key and
|
|
349
|
+
environment variable, with precedence.
|
|
350
|
+
- [Troubleshooting](https://pungoyal.github.io/kite-cli/troubleshooting) — symptom-first fixes
|
|
351
|
+
for session expiry, rate limits, login issues, and more.
|
|
352
|
+
- [Command reference](https://pungoyal.github.io/kite-cli/commands) — full flag-by-flag reference for
|
|
353
|
+
every command, generated from `--help`.
|
|
354
|
+
- [Library API](https://pungoyal.github.io/kite-cli/api) — the library/programmatic API surface.
|
|
355
|
+
|
|
356
|
+
The same pages are browsable as Markdown in [`docs/`](https://github.com/pungoyal/kite-cli/tree/main/docs).
|
|
357
|
+
|
|
251
358
|
## Library use
|
|
252
359
|
|
|
253
360
|
The client is exported if you want it without the CLI:
|
|
@@ -279,7 +386,7 @@ npm run build
|
|
|
279
386
|
|
|
280
387
|
## Contributing
|
|
281
388
|
|
|
282
|
-
Bug reports, ideas, and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for the development workflow and the two non-negotiables (safety defaults and secret redaction), and [CHANGELOG.md](CHANGELOG.md) for release history. Security issues go through [SECURITY.md](SECURITY.md), never a public issue.
|
|
389
|
+
Bug reports, ideas, and pull requests are welcome. See [CONTRIBUTING.md](https://github.com/pungoyal/kite-cli/blob/main/CONTRIBUTING.md) for the development workflow and the two non-negotiables (safety defaults and secret redaction), and [CHANGELOG.md](https://github.com/pungoyal/kite-cli/blob/main/CHANGELOG.md) for release history. Security issues go through [SECURITY.md](https://github.com/pungoyal/kite-cli/blob/main/SECURITY.md), never a public issue.
|
|
283
390
|
|
|
284
391
|
## Disclaimer
|
|
285
392
|
|
|
@@ -289,4 +396,4 @@ Trading involves risk of financial loss. This software is provided as-is under t
|
|
|
289
396
|
|
|
290
397
|
## Licence
|
|
291
398
|
|
|
292
|
-
[MIT](LICENSE)
|
|
399
|
+
[MIT](https://github.com/pungoyal/kite-cli/blob/main/LICENSE)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CommandFactory } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Price alerts.
|
|
4
|
+
*
|
|
5
|
+
* Two shapes:
|
|
6
|
+
* simple — fires a notification when a condition (e.g. LTP >= 27000) is met.
|
|
7
|
+
* No order, no money moves; treated like a watchlist entry.
|
|
8
|
+
* ato — Alert-Triggers-Order: carries a basket that is placed as a real
|
|
9
|
+
* order when the alert fires. Creating one is order placement in
|
|
10
|
+
* disguise, so it gets the same safety treatment as `orders place`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const alertCommands: CommandFactory;
|