@quantbrasil/cli 0.1.0-beta.1 → 0.1.0-beta.11
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 +64 -11
- package/dist/cli/client.js +4 -0
- package/dist/cli/index.d.ts +14 -4
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +72 -14
- package/dist/cli/prompt.d.ts +1 -0
- package/dist/cli/prompt.d.ts.map +1 -1
- package/dist/cli/prompt.js +17 -0
- package/dist/cli/skills.d.ts +9 -0
- package/dist/cli/skills.d.ts.map +1 -1
- package/dist/cli/skills.js +68 -4
- package/dist/commands/auth.d.ts +18 -0
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +49 -0
- package/dist/commands/cointegration.d.ts +52 -0
- package/dist/commands/cointegration.d.ts.map +1 -0
- package/dist/commands/cointegration.js +118 -0
- package/dist/commands/market.d.ts +1 -0
- package/dist/commands/market.d.ts.map +1 -1
- package/dist/commands/market.js +17 -1
- package/dist/commands/portfolios.d.ts +148 -8
- package/dist/commands/portfolios.d.ts.map +1 -1
- package/dist/commands/portfolios.js +557 -55
- package/dist/commands/rankings.d.ts +82 -0
- package/dist/commands/rankings.d.ts.map +1 -0
- package/dist/commands/rankings.js +235 -0
- package/dist/commands/screening.d.ts +120 -0
- package/dist/commands/screening.d.ts.map +1 -0
- package/dist/commands/screening.js +361 -0
- package/dist/commands/skills.js +7 -7
- package/dist/commands/update.d.ts +23 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +209 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/vendor/core/capabilities/cointegration.d.ts +52 -0
- package/dist/vendor/core/capabilities/cointegration.d.ts.map +1 -0
- package/dist/vendor/core/capabilities/cointegration.js +63 -0
- package/dist/vendor/core/capabilities/index.d.ts +3 -1
- package/dist/vendor/core/capabilities/index.d.ts.map +1 -1
- package/dist/vendor/core/capabilities/index.js +3 -1
- package/dist/vendor/core/capabilities/market.d.ts +9 -1
- package/dist/vendor/core/capabilities/market.d.ts.map +1 -1
- package/dist/vendor/core/capabilities/market.js +10 -0
- package/dist/vendor/core/capabilities/portfolios.d.ts +452 -56
- package/dist/vendor/core/capabilities/portfolios.d.ts.map +1 -1
- package/dist/vendor/core/capabilities/portfolios.js +434 -116
- package/dist/vendor/core/capabilities/rankings.d.ts +83 -0
- package/dist/vendor/core/capabilities/rankings.d.ts.map +1 -0
- package/dist/vendor/core/capabilities/rankings.js +96 -0
- package/dist/vendor/core/capabilities/registry.d.ts +1380 -414
- package/dist/vendor/core/capabilities/registry.d.ts.map +1 -1
- package/dist/vendor/core/capabilities/registry.js +6 -2
- package/dist/vendor/core/capabilities/screening.d.ts +136 -0
- package/dist/vendor/core/capabilities/screening.d.ts.map +1 -0
- package/dist/vendor/core/capabilities/screening.js +155 -0
- package/dist/vendor/core/capabilities/types.d.ts +1 -1
- package/dist/vendor/core/capabilities/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/skills/quantbrasil/SKILL.md +31 -11
- package/skills/quantbrasil/references/cli.md +112 -19
- package/skills/quantbrasil/references/cointegration.md +40 -0
- package/skills/quantbrasil/references/costs.md +10 -4
- package/skills/quantbrasil/references/errors.md +16 -5
- package/skills/quantbrasil/references/portfolios.md +114 -0
- package/skills/quantbrasil/references/quality-eval-queries.json +147 -0
- package/skills/quantbrasil/references/rankings.md +64 -0
- package/skills/quantbrasil/references/screening.md +212 -0
- package/skills/quantbrasil/references/unsupported.md +9 -2
- package/skills/quantbrasil/references/workflows.md +117 -23
- package/dist/commands/analytics.d.ts +0 -131
- package/dist/commands/analytics.d.ts.map +0 -1
- package/dist/commands/analytics.js +0 -291
- package/dist/vendor/core/capabilities/analytics.d.ts +0 -187
- package/dist/vendor/core/capabilities/analytics.d.ts.map +0 -1
- package/dist/vendor/core/capabilities/analytics.js +0 -214
package/README.md
CHANGED
|
@@ -29,7 +29,9 @@ that file only exists inside this package.
|
|
|
29
29
|
```bash
|
|
30
30
|
# from monorepo/packages/cli
|
|
31
31
|
node ./bin/quantbrasil.js auth login --api-key qb_live_<id>.<secret>
|
|
32
|
+
node ./bin/quantbrasil.js whoami
|
|
32
33
|
node ./bin/quantbrasil.js skills install --all
|
|
34
|
+
node ./bin/quantbrasil.js update
|
|
33
35
|
node ./bin/quantbrasil.js --status
|
|
34
36
|
node ./bin/quantbrasil.js auth logout
|
|
35
37
|
```
|
|
@@ -48,6 +50,7 @@ compatible local or staging backend.
|
|
|
48
50
|
```bash
|
|
49
51
|
quantbrasil market assets
|
|
50
52
|
quantbrasil market assets --type B3
|
|
53
|
+
quantbrasil market assets --search BTC
|
|
51
54
|
quantbrasil market assets --json
|
|
52
55
|
quantbrasil market price PETR4
|
|
53
56
|
quantbrasil market price PETR4 --date 2026-04-10
|
|
@@ -55,16 +58,60 @@ quantbrasil market price PETR4 --json
|
|
|
55
58
|
quantbrasil assets overview PETR4 --sections price,performance
|
|
56
59
|
quantbrasil assets overview PETR4 --sections price,technicals
|
|
57
60
|
quantbrasil assets overview PETR4 --sections price,fundamentals --json
|
|
58
|
-
quantbrasil
|
|
59
|
-
quantbrasil
|
|
60
|
-
quantbrasil
|
|
61
|
-
quantbrasil
|
|
62
|
-
quantbrasil
|
|
63
|
-
quantbrasil
|
|
64
|
-
quantbrasil
|
|
65
|
-
quantbrasil
|
|
66
|
-
quantbrasil
|
|
67
|
-
quantbrasil
|
|
61
|
+
quantbrasil watchlists list
|
|
62
|
+
quantbrasil watchlists get 93
|
|
63
|
+
quantbrasil watchlists create "Dividendos"
|
|
64
|
+
quantbrasil watchlists add-assets 93 PETR4 VALE3
|
|
65
|
+
quantbrasil holdings list
|
|
66
|
+
quantbrasil holdings get 182
|
|
67
|
+
quantbrasil holdings create "Longo Prazo"
|
|
68
|
+
quantbrasil holdings create "Longo Prazo" --target PETR4:50 --target VALE3:50
|
|
69
|
+
quantbrasil holdings create "Carteira Real" --mode position
|
|
70
|
+
quantbrasil holdings set-targets 182 PETR4:50 VALE3:50
|
|
71
|
+
quantbrasil holdings set-positions 182 PRIO3:1600 BTC-USD:0.25 QQQ:10
|
|
72
|
+
quantbrasil holdings historical-return 182 --from 2025-01-01 --to 2026-01-01
|
|
73
|
+
quantbrasil holdings historical-return 182 --period 1y
|
|
74
|
+
quantbrasil holdings beta 182 --years 3
|
|
75
|
+
quantbrasil holdings var 182 --years 1 --confidence 95
|
|
76
|
+
quantbrasil rankings list
|
|
77
|
+
quantbrasil rankings current --system momentum-90d --top 20
|
|
78
|
+
quantbrasil rankings current --system magic-formula --top 10
|
|
79
|
+
quantbrasil rankings current --system low-risk --top 30
|
|
80
|
+
quantbrasil rankings current --id 123 --top 20
|
|
81
|
+
quantbrasil screening universes
|
|
82
|
+
quantbrasil screening indicators
|
|
83
|
+
quantbrasil screening run --system acoes-mais-liquidas --query-file ./screening.json
|
|
84
|
+
quantbrasil screening run --watchlist 93 --query-file ./screening.json --limit 25
|
|
85
|
+
cat ./screening.json | quantbrasil screening run --holding 182 --query-file -
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Example `screening.json`:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"query": {
|
|
93
|
+
"comparison": {
|
|
94
|
+
"left": {
|
|
95
|
+
"indicator": {
|
|
96
|
+
"name": "RSI",
|
|
97
|
+
"timeframe": "D1",
|
|
98
|
+
"offset": 0,
|
|
99
|
+
"params": {
|
|
100
|
+
"period": 14
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"operator": "lt",
|
|
105
|
+
"right": {
|
|
106
|
+
"constant": {
|
|
107
|
+
"value": 30
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"limit": 50,
|
|
113
|
+
"sort": "ticker"
|
|
114
|
+
}
|
|
68
115
|
```
|
|
69
116
|
|
|
70
117
|
## Local config
|
|
@@ -104,8 +151,14 @@ quantbrasil init
|
|
|
104
151
|
quantbrasil --status
|
|
105
152
|
quantbrasil auth login --api-key qb_live_<id>.<secret>
|
|
106
153
|
quantbrasil skills install --all
|
|
154
|
+
quantbrasil update
|
|
107
155
|
```
|
|
108
156
|
|
|
157
|
+
`quantbrasil update` checks the current global package against
|
|
158
|
+
`@quantbrasil/cli@beta`, checks whether the bundled skill is missing or stale,
|
|
159
|
+
shows the planned actions, and asks for confirmation before updating. Use
|
|
160
|
+
`quantbrasil update --yes` only in noninteractive automation.
|
|
161
|
+
|
|
109
162
|
## Publishing
|
|
110
163
|
|
|
111
164
|
Publish from `monorepo/packages/cli`. The package build vendors the private
|
|
@@ -183,7 +236,7 @@ For commands that expose `--json`, failures are written to stderr as JSON:
|
|
|
183
236
|
"category": "auth",
|
|
184
237
|
"exit_code": 1,
|
|
185
238
|
"status": 401,
|
|
186
|
-
"path": "/api/desk/tools/
|
|
239
|
+
"path": "/api/desk/tools/watchlist/list",
|
|
187
240
|
"request_id": "req_..."
|
|
188
241
|
}
|
|
189
242
|
}
|
package/dist/cli/client.js
CHANGED
|
@@ -80,6 +80,7 @@ function resolveErrorDetail(payload) {
|
|
|
80
80
|
}
|
|
81
81
|
const detail = payload.detail;
|
|
82
82
|
const message = payload.message;
|
|
83
|
+
const error = payload.error;
|
|
83
84
|
if (typeof detail === "string" && detail.trim()) {
|
|
84
85
|
return detail;
|
|
85
86
|
}
|
|
@@ -94,6 +95,9 @@ function resolveErrorDetail(payload) {
|
|
|
94
95
|
if (typeof message === "string" && message.trim()) {
|
|
95
96
|
return message;
|
|
96
97
|
}
|
|
98
|
+
if (typeof error === "string" && error.trim()) {
|
|
99
|
+
return error;
|
|
100
|
+
}
|
|
97
101
|
return null;
|
|
98
102
|
}
|
|
99
103
|
function formatValidationDetail(value) {
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -1,30 +1,40 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { type CapabilitiesCommandIO, runCapabilitiesCommand } from "../commands/capabilities.js";
|
|
3
|
+
import { runCointegrationPairCommand } from "../commands/cointegration.js";
|
|
3
4
|
import { runMarketAssetsCommand, runMarketPriceCommand } from "../commands/market.js";
|
|
4
5
|
import { runInitCommand } from "../commands/init.js";
|
|
5
|
-
import {
|
|
6
|
+
import { runHoldingCreateCommand, runHoldingBetaCommand, runHoldingGetCommand, runHoldingHistoricalReturnCommand, runHoldingListCommand, runHoldingRenameCommand, runHoldingSetPositionsCommand, runHoldingSetTargetsCommand, runHoldingVarCommand, runWatchlistAddAssetsCommand, runWatchlistCreateCommand, runWatchlistGetCommand, runWatchlistListCommand, runWatchlistRemoveAssetsCommand, runWatchlistRenameCommand } from "../commands/portfolios.js";
|
|
7
|
+
import { runRankingsCurrentCommand, runRankingsListCommand } from "../commands/rankings.js";
|
|
8
|
+
import { runScreeningIndicatorsCommand, runScreeningRunCommand, runScreeningUniversesCommand } from "../commands/screening.js";
|
|
6
9
|
import { runSkillsInstallCommand } from "../commands/skills.js";
|
|
7
10
|
import { runStatusCommand } from "../commands/status.js";
|
|
11
|
+
import { runUpdateCommand, type UpdateCommandRunner } from "../commands/update.js";
|
|
8
12
|
import { type TerminalWriter } from "./terminal.js";
|
|
9
13
|
export interface CliProgramOptions {
|
|
10
14
|
io?: CapabilitiesCommandIO;
|
|
11
15
|
env?: NodeJS.ProcessEnv;
|
|
12
16
|
fetch?: typeof fetch;
|
|
13
17
|
prompt?: (promptLabel: string) => Promise<string>;
|
|
18
|
+
now?: Date;
|
|
14
19
|
stderr?: TerminalWriter;
|
|
15
20
|
suppressCommanderErrors?: boolean;
|
|
21
|
+
updateCommandRunner?: UpdateCommandRunner;
|
|
22
|
+
currentVersion?: string;
|
|
16
23
|
}
|
|
17
24
|
export interface CliRunOptions extends CliProgramOptions {
|
|
18
25
|
stderr?: TerminalWriter;
|
|
19
26
|
}
|
|
20
27
|
export declare function createCliProgram(options?: CliProgramOptions): Command;
|
|
21
28
|
export declare function run(argv?: string[], options?: CliRunOptions): Promise<void>;
|
|
22
|
-
export {
|
|
23
|
-
export { runAuthLoginCommand, runAuthLogoutCommand } from "../commands/auth.js";
|
|
29
|
+
export { runAuthLoginCommand, runAuthLogoutCommand, runAuthWhoamiCommand, } from "../commands/auth.js";
|
|
24
30
|
export { runAssetOverviewCommand } from "../commands/assets.js";
|
|
25
31
|
export { runCapabilitiesCommand, runStatusCommand };
|
|
26
32
|
export { runInitCommand };
|
|
27
33
|
export { runMarketAssetsCommand, runMarketPriceCommand };
|
|
28
|
-
export {
|
|
34
|
+
export { runRankingsCurrentCommand, runRankingsListCommand };
|
|
35
|
+
export { runCointegrationPairCommand };
|
|
36
|
+
export { runScreeningIndicatorsCommand, runScreeningRunCommand, runScreeningUniversesCommand, };
|
|
37
|
+
export { runHoldingBetaCommand, runHoldingCreateCommand, runHoldingGetCommand, runHoldingHistoricalReturnCommand, runHoldingListCommand, runHoldingRenameCommand, runHoldingSetPositionsCommand, runHoldingSetTargetsCommand, runHoldingVarCommand, runWatchlistAddAssetsCommand, runWatchlistCreateCommand, runWatchlistGetCommand, runWatchlistListCommand, runWatchlistRemoveAssetsCommand, runWatchlistRenameCommand, };
|
|
29
38
|
export { runSkillsInstallCommand };
|
|
39
|
+
export { runUpdateCommand };
|
|
30
40
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cli/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"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"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { Command } from "commander";
|
|
2
|
-
import { registerAnalyticsCommands, } from "../commands/analytics.js";
|
|
3
3
|
import { registerAssetsCommands, } from "../commands/assets.js";
|
|
4
|
-
import { registerAuthCommands, } from "../commands/auth.js";
|
|
4
|
+
import { registerAuthCommands, runAuthWhoamiCommand, } from "../commands/auth.js";
|
|
5
5
|
import { registerCapabilitiesCommand, runCapabilitiesCommand, } from "../commands/capabilities.js";
|
|
6
|
+
import { registerCointegrationCommands, runCointegrationPairCommand, } from "../commands/cointegration.js";
|
|
6
7
|
import { registerMarketCommands, runMarketAssetsCommand, runMarketPriceCommand, } from "../commands/market.js";
|
|
7
8
|
import { registerInitCommand, runInitCommand, } from "../commands/init.js";
|
|
8
|
-
import { registerPortfoliosCommands,
|
|
9
|
+
import { registerPortfoliosCommands, runHoldingCreateCommand, runHoldingBetaCommand, runHoldingGetCommand, runHoldingHistoricalReturnCommand, runHoldingListCommand, runHoldingRenameCommand, runHoldingSetPositionsCommand, runHoldingSetTargetsCommand, runHoldingVarCommand, runWatchlistAddAssetsCommand, runWatchlistCreateCommand, runWatchlistGetCommand, runWatchlistListCommand, runWatchlistRemoveAssetsCommand, runWatchlistRenameCommand, } from "../commands/portfolios.js";
|
|
10
|
+
import { registerRankingsCommands, runRankingsCurrentCommand, runRankingsListCommand, } from "../commands/rankings.js";
|
|
11
|
+
import { registerScreeningCommands, runScreeningIndicatorsCommand, runScreeningRunCommand, runScreeningUniversesCommand, } from "../commands/screening.js";
|
|
9
12
|
import { registerSkillsCommands, runSkillsInstallCommand, } from "../commands/skills.js";
|
|
10
13
|
import { registerStatusFlag, runStatusCommand, } from "../commands/status.js";
|
|
14
|
+
import { registerUpdateCommand, runUpdateCommand, } from "../commands/update.js";
|
|
11
15
|
import { buildCliErrorPayload, formatCliErrorMessage, normalizeCliError, shouldEmitJsonError, } from "./errors.js";
|
|
12
16
|
import { styleErrorMessage } from "./terminal.js";
|
|
17
|
+
const requirePackage = createRequire(import.meta.url);
|
|
18
|
+
const cliPackageJson = requirePackage("../../package.json");
|
|
19
|
+
const CLI_VERSION = cliPackageJson.version ?? "0.0.0";
|
|
13
20
|
export function createCliProgram(options = {}) {
|
|
14
21
|
const program = new Command();
|
|
15
22
|
const authContext = {
|
|
@@ -22,11 +29,6 @@ export function createCliProgram(options = {}) {
|
|
|
22
29
|
env: options.env,
|
|
23
30
|
fetch: options.fetch,
|
|
24
31
|
};
|
|
25
|
-
const analyticsContext = {
|
|
26
|
-
io: options.io,
|
|
27
|
-
env: options.env,
|
|
28
|
-
fetch: options.fetch,
|
|
29
|
-
};
|
|
30
32
|
const marketContext = {
|
|
31
33
|
io: options.io,
|
|
32
34
|
env: options.env,
|
|
@@ -42,6 +44,22 @@ export function createCliProgram(options = {}) {
|
|
|
42
44
|
io: options.io,
|
|
43
45
|
env: options.env,
|
|
44
46
|
fetch: options.fetch,
|
|
47
|
+
now: options.now,
|
|
48
|
+
};
|
|
49
|
+
const rankingsContext = {
|
|
50
|
+
io: options.io,
|
|
51
|
+
env: options.env,
|
|
52
|
+
fetch: options.fetch,
|
|
53
|
+
};
|
|
54
|
+
const cointegrationContext = {
|
|
55
|
+
io: options.io,
|
|
56
|
+
env: options.env,
|
|
57
|
+
fetch: options.fetch,
|
|
58
|
+
};
|
|
59
|
+
const screeningContext = {
|
|
60
|
+
io: options.io,
|
|
61
|
+
env: options.env,
|
|
62
|
+
fetch: options.fetch,
|
|
45
63
|
};
|
|
46
64
|
const skillsContext = {
|
|
47
65
|
io: options.io,
|
|
@@ -51,25 +69,46 @@ export function createCliProgram(options = {}) {
|
|
|
51
69
|
io: options.io,
|
|
52
70
|
env: options.env,
|
|
53
71
|
};
|
|
72
|
+
const updateContext = {
|
|
73
|
+
io: options.io,
|
|
74
|
+
env: options.env,
|
|
75
|
+
prompt: options.prompt,
|
|
76
|
+
commandRunner: options.updateCommandRunner,
|
|
77
|
+
currentVersion: options.currentVersion ?? CLI_VERSION,
|
|
78
|
+
};
|
|
54
79
|
program
|
|
55
80
|
.name("quantbrasil")
|
|
56
|
-
.description("
|
|
57
|
-
.version(
|
|
81
|
+
.description("CLI pública do QuantBrasil para operações determinísticas")
|
|
82
|
+
.version(CLI_VERSION)
|
|
83
|
+
.helpOption("-h, --help", "Exibe ajuda do comando")
|
|
58
84
|
.exitOverride()
|
|
59
85
|
.showHelpAfterError()
|
|
60
86
|
.showSuggestionAfterError();
|
|
61
87
|
configureCommanderOutput(program, options);
|
|
62
88
|
registerCapabilitiesCommand(program, options.io);
|
|
63
89
|
registerAuthCommands(program, authContext);
|
|
90
|
+
registerWhoamiCommand(program, authContext);
|
|
64
91
|
registerAssetsCommands(program, assetsContext);
|
|
65
|
-
registerAnalyticsCommands(program, analyticsContext);
|
|
66
92
|
registerInitCommand(program, initContext);
|
|
67
93
|
registerMarketCommands(program, marketContext);
|
|
68
94
|
registerPortfoliosCommands(program, portfoliosContext);
|
|
95
|
+
registerRankingsCommands(program, rankingsContext);
|
|
96
|
+
registerCointegrationCommands(program, cointegrationContext);
|
|
97
|
+
registerScreeningCommands(program, screeningContext);
|
|
69
98
|
registerSkillsCommands(program, skillsContext);
|
|
99
|
+
registerUpdateCommand(program, updateContext);
|
|
70
100
|
registerStatusFlag(program, statusContext);
|
|
71
101
|
return program;
|
|
72
102
|
}
|
|
103
|
+
function registerWhoamiCommand(program, context) {
|
|
104
|
+
program
|
|
105
|
+
.command("whoami")
|
|
106
|
+
.description("Show the authenticated QuantBrasil user")
|
|
107
|
+
.option("--json", "Show JSON output")
|
|
108
|
+
.action(async (options) => {
|
|
109
|
+
await runAuthWhoamiCommand(options, context);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
73
112
|
export async function run(argv = process.argv, options = {}) {
|
|
74
113
|
const emitJsonError = shouldEmitJsonError(argv);
|
|
75
114
|
const program = createCliProgram({
|
|
@@ -82,6 +121,9 @@ export async function run(argv = process.argv, options = {}) {
|
|
|
82
121
|
await program.parseAsync(argv);
|
|
83
122
|
}
|
|
84
123
|
catch (error) {
|
|
124
|
+
if (isCommanderDisplayExit(error)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
85
127
|
const cliError = normalizeCliError(error);
|
|
86
128
|
if (emitJsonError) {
|
|
87
129
|
stderr.write(`${JSON.stringify(buildCliErrorPayload(cliError), null, 2)}\n`);
|
|
@@ -93,8 +135,12 @@ export async function run(argv = process.argv, options = {}) {
|
|
|
93
135
|
}
|
|
94
136
|
}
|
|
95
137
|
function configureCommanderOutput(program, options) {
|
|
138
|
+
const stdout = options.io?.stdout ?? process.stdout;
|
|
96
139
|
const stderr = options.stderr ?? process.stderr;
|
|
97
140
|
program.configureOutput({
|
|
141
|
+
writeOut: chunk => {
|
|
142
|
+
stdout.write(chunk);
|
|
143
|
+
},
|
|
98
144
|
writeErr: chunk => {
|
|
99
145
|
if (!options.suppressCommanderErrors) {
|
|
100
146
|
stderr.write(chunk);
|
|
@@ -102,11 +148,23 @@ function configureCommanderOutput(program, options) {
|
|
|
102
148
|
},
|
|
103
149
|
});
|
|
104
150
|
}
|
|
105
|
-
|
|
106
|
-
|
|
151
|
+
function isCommanderDisplayExit(error) {
|
|
152
|
+
if (!(error instanceof Error) ||
|
|
153
|
+
!("code" in error) ||
|
|
154
|
+
typeof error.code !== "string") {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return (error.code === "commander.helpDisplayed" ||
|
|
158
|
+
error.code === "commander.version");
|
|
159
|
+
}
|
|
160
|
+
export { runAuthLoginCommand, runAuthLogoutCommand, runAuthWhoamiCommand, } from "../commands/auth.js";
|
|
107
161
|
export { runAssetOverviewCommand } from "../commands/assets.js";
|
|
108
162
|
export { runCapabilitiesCommand, runStatusCommand };
|
|
109
163
|
export { runInitCommand };
|
|
110
164
|
export { runMarketAssetsCommand, runMarketPriceCommand };
|
|
111
|
-
export {
|
|
165
|
+
export { runRankingsCurrentCommand, runRankingsListCommand };
|
|
166
|
+
export { runCointegrationPairCommand };
|
|
167
|
+
export { runScreeningIndicatorsCommand, runScreeningRunCommand, runScreeningUniversesCommand, };
|
|
168
|
+
export { runHoldingBetaCommand, runHoldingCreateCommand, runHoldingGetCommand, runHoldingHistoricalReturnCommand, runHoldingListCommand, runHoldingRenameCommand, runHoldingSetPositionsCommand, runHoldingSetTargetsCommand, runHoldingVarCommand, runWatchlistAddAssetsCommand, runWatchlistCreateCommand, runWatchlistGetCommand, runWatchlistListCommand, runWatchlistRemoveAssetsCommand, runWatchlistRenameCommand, };
|
|
112
169
|
export { runSkillsInstallCommand };
|
|
170
|
+
export { runUpdateCommand };
|
package/dist/cli/prompt.d.ts
CHANGED
package/dist/cli/prompt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/cli/prompt.ts"],"names":[],"mappings":"AAyBA,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwB1E"}
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/cli/prompt.ts"],"names":[],"mappings":"AAyBA,wBAAsB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwB1E;AAED,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAmBlB"}
|
package/dist/cli/prompt.js
CHANGED
|
@@ -38,3 +38,20 @@ export async function promptForSecret(promptLabel) {
|
|
|
38
38
|
readline.close();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
export async function promptForConfirmation(promptLabel) {
|
|
42
|
+
if (!input.isTTY || !output.isTTY) {
|
|
43
|
+
throw createCliConfigError("Confirmação interativa requer um TTY. Use --yes para aplicar a atualização.");
|
|
44
|
+
}
|
|
45
|
+
const readline = createInterface({
|
|
46
|
+
input,
|
|
47
|
+
output,
|
|
48
|
+
terminal: true,
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const answer = await readline.question(promptLabel);
|
|
52
|
+
return ["s", "sim", "y", "yes"].includes(answer.trim().toLowerCase());
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
readline.close();
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/cli/skills.d.ts
CHANGED
|
@@ -20,7 +20,16 @@ export interface SkillInstallResult {
|
|
|
20
20
|
installed: InstalledSkillTarget[];
|
|
21
21
|
skipped: SkippedSkillTarget[];
|
|
22
22
|
}
|
|
23
|
+
export type SkillInstallStatus = "current" | "missing" | "stale" | "skipped";
|
|
24
|
+
export interface SkillInstallTargetStatus extends SkillInstallTarget {
|
|
25
|
+
status: SkillInstallStatus;
|
|
26
|
+
}
|
|
27
|
+
export interface SkillInstallState {
|
|
28
|
+
targets: SkillInstallTargetStatus[];
|
|
29
|
+
needsInstall: boolean;
|
|
30
|
+
}
|
|
23
31
|
export declare function installBundledSkillEverywhere(env?: NodeJS.ProcessEnv): Promise<SkillInstallResult>;
|
|
32
|
+
export declare function getBundledSkillInstallState(env?: NodeJS.ProcessEnv): Promise<SkillInstallState>;
|
|
24
33
|
export declare function resolveSkillInstallTargets(env?: NodeJS.ProcessEnv): SkillInstallTarget[];
|
|
25
34
|
export declare function resolveBundledSkillSourcePath(): string;
|
|
26
35
|
//# sourceMappingURL=skills.d.ts.map
|
package/dist/cli/skills.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/cli/skills.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/cli/skills.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,sBAAsB,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnE,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,sBAAsB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,sBAAsB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,sBAAsB,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,OAAO,EAAE,kBAAkB,EAAE,CAAC;CAC/B;AAED,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAE7E,MAAM,WAAW,wBAAyB,SAAQ,kBAAkB;IAClE,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,wBAAwB,EAAE,CAAC;IACpC,YAAY,EAAE,OAAO,CAAC;CACvB;AAcD,wBAAsB,6BAA6B,CACjD,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAAC,kBAAkB,CAAC,CAmD7B;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,OAAO,CAAC,iBAAiB,CAAC,CA0C5B;AAED,wBAAgB,0BAA0B,CACxC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,kBAAkB,EAAE,CAetB;AAED,wBAAgB,6BAA6B,IAAI,MAAM,CAEtD"}
|
package/dist/cli/skills.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { access, cp, mkdir, readdir, readFile, rm } from "node:fs/promises";
|
|
2
3
|
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -45,13 +46,46 @@ export async function installBundledSkillEverywhere(env = process.env) {
|
|
|
45
46
|
}
|
|
46
47
|
if (installed.length === 0) {
|
|
47
48
|
const checkedRoots = targets.map(target => target.rootDir).join(", ");
|
|
48
|
-
throw createCliConfigError(`
|
|
49
|
+
throw createCliConfigError(`Nenhum cliente de agente compatível detectado. Verificados: ${checkedRoots}.`);
|
|
49
50
|
}
|
|
50
51
|
return {
|
|
51
52
|
installed,
|
|
52
53
|
skipped,
|
|
53
54
|
};
|
|
54
55
|
}
|
|
56
|
+
export async function getBundledSkillInstallState(env = process.env) {
|
|
57
|
+
const bundledSkillPath = resolveBundledSkillSourcePath();
|
|
58
|
+
await assertBundledSkillExists(bundledSkillPath);
|
|
59
|
+
const bundledHash = await hashDirectory(bundledSkillPath);
|
|
60
|
+
const targets = [];
|
|
61
|
+
for (const target of resolveSkillInstallTargets(env)) {
|
|
62
|
+
if (target.id !== AGENT_SKILLS_CONVENTION_ID &&
|
|
63
|
+
!(await pathExists(target.rootDir))) {
|
|
64
|
+
targets.push({
|
|
65
|
+
...target,
|
|
66
|
+
status: "skipped",
|
|
67
|
+
});
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (!(await pathExists(join(target.installDir, "SKILL.md")))) {
|
|
71
|
+
targets.push({
|
|
72
|
+
...target,
|
|
73
|
+
status: "missing",
|
|
74
|
+
});
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
targets.push({
|
|
78
|
+
...target,
|
|
79
|
+
status: (await hashDirectory(target.installDir)) === bundledHash
|
|
80
|
+
? "current"
|
|
81
|
+
: "stale",
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
targets,
|
|
86
|
+
needsInstall: targets.some(target => target.status === "missing" || target.status === "stale"),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
55
89
|
export function resolveSkillInstallTargets(env = process.env) {
|
|
56
90
|
const home = resolveCliHomeDirectory(env);
|
|
57
91
|
return SUPPORTED_SKILL_CLIENTS.map(client => {
|
|
@@ -74,12 +108,42 @@ async function assertBundledSkillExists(skillPath) {
|
|
|
74
108
|
if (await pathExists(skillEntryPath)) {
|
|
75
109
|
return;
|
|
76
110
|
}
|
|
77
|
-
throw createCliConfigError(`
|
|
111
|
+
throw createCliConfigError(`Skill QuantBrasil empacotada não encontrada em ${skillEntryPath}. Reinstale o pacote da CLI.`);
|
|
112
|
+
}
|
|
113
|
+
async function hashDirectory(directory) {
|
|
114
|
+
const hash = createHash("sha256");
|
|
115
|
+
const files = await collectDirectoryFiles(directory);
|
|
116
|
+
for (const file of files) {
|
|
117
|
+
hash.update(file.relativePath);
|
|
118
|
+
hash.update("\0");
|
|
119
|
+
hash.update(await readFile(file.fullPath));
|
|
120
|
+
hash.update("\0");
|
|
121
|
+
}
|
|
122
|
+
return hash.digest("hex");
|
|
123
|
+
}
|
|
124
|
+
async function collectDirectoryFiles(current, relativePrefix = "") {
|
|
125
|
+
const entries = await readdir(current, { withFileTypes: true });
|
|
126
|
+
const sortedEntries = entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
127
|
+
const files = [];
|
|
128
|
+
for (const entry of sortedEntries) {
|
|
129
|
+
const fullPath = join(current, entry.name);
|
|
130
|
+
const relativePath = relativePrefix
|
|
131
|
+
? `${relativePrefix}/${entry.name}`
|
|
132
|
+
: entry.name;
|
|
133
|
+
if (entry.isDirectory()) {
|
|
134
|
+
files.push(...(await collectDirectoryFiles(fullPath, relativePath)));
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (entry.isFile()) {
|
|
138
|
+
files.push({ fullPath, relativePath });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return files;
|
|
78
142
|
}
|
|
79
143
|
function resolveCliHomeDirectory(env) {
|
|
80
144
|
const home = env.HOME?.trim() || homedir();
|
|
81
145
|
if (!home) {
|
|
82
|
-
throw createCliConfigError("
|
|
146
|
+
throw createCliConfigError("Não foi possível resolver o diretório HOME para instalar a skill.");
|
|
83
147
|
}
|
|
84
148
|
return home;
|
|
85
149
|
}
|
package/dist/commands/auth.d.ts
CHANGED
|
@@ -11,7 +11,25 @@ export interface AuthCommandContext {
|
|
|
11
11
|
export interface AuthLoginCommandOptions {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
}
|
|
14
|
+
export interface AuthWhoamiCommandOptions {
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface AuthWhoamiOutput {
|
|
18
|
+
ok: true;
|
|
19
|
+
user_id: number;
|
|
20
|
+
email: string;
|
|
21
|
+
name: string;
|
|
22
|
+
is_premium: boolean;
|
|
23
|
+
auth_source: "env" | "config";
|
|
24
|
+
api_key: {
|
|
25
|
+
id: number;
|
|
26
|
+
name: string;
|
|
27
|
+
key_prefix: string;
|
|
28
|
+
scopes: string[];
|
|
29
|
+
};
|
|
30
|
+
}
|
|
14
31
|
export declare function registerAuthCommands(program: Command, context?: AuthCommandContext): void;
|
|
15
32
|
export declare function runAuthLoginCommand(options: AuthLoginCommandOptions, context?: AuthCommandContext): Promise<void>;
|
|
16
33
|
export declare function runAuthLogoutCommand(context?: AuthCommandContext): Promise<void>;
|
|
34
|
+
export declare function runAuthWhoamiCommand(options?: AuthWhoamiCommandOptions, context?: AuthCommandContext): Promise<void>;
|
|
17
35
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9E,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,aAAa,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,IAAI,CAAC;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC9B,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;CACH;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,kBAAuB,GAC/B,IAAI,CA2BN;AAED,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,uBAAuB,EAChC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,wBAA6B,EACtC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CA6Bf"}
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { verifyCliApiKey } from "../cli/auth.js";
|
|
2
|
+
import { resolveRequiredCliAuth } from "../cli/client.js";
|
|
2
3
|
import { clearCliStoredAuth, saveCliApiKey } from "../cli/config.js";
|
|
3
4
|
import { createTerminalTheme } from "../cli/terminal.js";
|
|
4
5
|
export function registerAuthCommands(program, context = {}) {
|
|
@@ -18,6 +19,13 @@ export function registerAuthCommands(program, context = {}) {
|
|
|
18
19
|
.action(async () => {
|
|
19
20
|
await runAuthLogoutCommand(context);
|
|
20
21
|
});
|
|
22
|
+
authCommand
|
|
23
|
+
.command("whoami")
|
|
24
|
+
.description("Show the authenticated QuantBrasil user")
|
|
25
|
+
.option("--json", "Show JSON output")
|
|
26
|
+
.action(async (options) => {
|
|
27
|
+
await runAuthWhoamiCommand(options, context);
|
|
28
|
+
});
|
|
21
29
|
}
|
|
22
30
|
export async function runAuthLoginCommand(options, context = {}) {
|
|
23
31
|
const stdout = getStdout(context);
|
|
@@ -43,6 +51,47 @@ export async function runAuthLogoutCommand(context = {}) {
|
|
|
43
51
|
}
|
|
44
52
|
stdout.write(`${theme.dim(`No local API key was stored at ${configPath}.`)}\n`);
|
|
45
53
|
}
|
|
54
|
+
export async function runAuthWhoamiCommand(options = {}, context = {}) {
|
|
55
|
+
const stdout = getStdout(context);
|
|
56
|
+
const theme = createTerminalTheme(stdout, context.env ?? process.env);
|
|
57
|
+
const auth = await resolveRequiredCliAuth(context.env ?? process.env);
|
|
58
|
+
const verifiedAuth = await verifyCliApiKey(auth.apiKey, {
|
|
59
|
+
env: context.env,
|
|
60
|
+
fetch: context.fetch,
|
|
61
|
+
});
|
|
62
|
+
const output = {
|
|
63
|
+
ok: true,
|
|
64
|
+
user_id: verifiedAuth.userId,
|
|
65
|
+
email: verifiedAuth.email,
|
|
66
|
+
name: verifiedAuth.name,
|
|
67
|
+
is_premium: verifiedAuth.isPremium,
|
|
68
|
+
auth_source: auth.source,
|
|
69
|
+
api_key: {
|
|
70
|
+
id: verifiedAuth.apiKey.id,
|
|
71
|
+
name: verifiedAuth.apiKey.name,
|
|
72
|
+
key_prefix: verifiedAuth.apiKey.keyPrefix,
|
|
73
|
+
scopes: verifiedAuth.apiKey.scopes,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
if (options.json) {
|
|
77
|
+
stdout.write(`${JSON.stringify(output, null, 2)}\n`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
stdout.write(`${formatAuthWhoamiHuman(output, theme)}\n`);
|
|
81
|
+
}
|
|
82
|
+
function formatAuthWhoamiHuman(data, theme) {
|
|
83
|
+
const source = data.auth_source === "env" ? "QUANTBRASIL_API_KEY" : "local config";
|
|
84
|
+
return [
|
|
85
|
+
theme.label("QuantBrasil user"),
|
|
86
|
+
"",
|
|
87
|
+
`${theme.label("Email:")} ${theme.bold(data.email)}`,
|
|
88
|
+
`${theme.label("Name:")} ${data.name}`,
|
|
89
|
+
`${theme.label("User ID:")} ${data.user_id}`,
|
|
90
|
+
`${theme.label("Premium:")} ${data.is_premium ? "yes" : "no"}`,
|
|
91
|
+
`${theme.label("API key:")} ${data.api_key.name} ${theme.dim(`(${data.api_key.key_prefix})`)}`,
|
|
92
|
+
`${theme.label("Auth source:")} ${source}`,
|
|
93
|
+
].join("\n");
|
|
94
|
+
}
|
|
46
95
|
function getStdout(context) {
|
|
47
96
|
return context.io?.stdout ?? process.stdout;
|
|
48
97
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { JsonValue } from "../vendor/core/index.js";
|
|
3
|
+
import { type CliInvokeContext } from "../cli/client.js";
|
|
4
|
+
import { type TerminalWriter } from "../cli/terminal.js";
|
|
5
|
+
export interface CointegrationCommandIO {
|
|
6
|
+
stdout: TerminalWriter;
|
|
7
|
+
}
|
|
8
|
+
export interface CointegrationPairCommandOptions {
|
|
9
|
+
window?: string;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface CointegrationZScorePoint {
|
|
13
|
+
[key: string]: JsonValue;
|
|
14
|
+
date: string;
|
|
15
|
+
zscore: number | null;
|
|
16
|
+
}
|
|
17
|
+
export interface CointegrationBetaPoint {
|
|
18
|
+
[key: string]: JsonValue;
|
|
19
|
+
date: string;
|
|
20
|
+
slope: number | null;
|
|
21
|
+
}
|
|
22
|
+
export interface CointegrationPairResponse {
|
|
23
|
+
[key: string]: JsonValue;
|
|
24
|
+
ok: boolean;
|
|
25
|
+
summary_markdown: string;
|
|
26
|
+
base_asset: string;
|
|
27
|
+
comparison_asset: string;
|
|
28
|
+
window: number;
|
|
29
|
+
beta: number | null;
|
|
30
|
+
beta_std: number | null;
|
|
31
|
+
beta_mean: number | null;
|
|
32
|
+
beta_volatility: number | null;
|
|
33
|
+
adf: number | null;
|
|
34
|
+
p_value: number | null;
|
|
35
|
+
confidence: number | null;
|
|
36
|
+
halflife: number | null;
|
|
37
|
+
critical_values: Record<string, number>;
|
|
38
|
+
zscore_series: CointegrationZScorePoint[];
|
|
39
|
+
beta_series: CointegrationBetaPoint[];
|
|
40
|
+
}
|
|
41
|
+
export interface CointegrationCommandContext extends CliInvokeContext {
|
|
42
|
+
io?: CointegrationCommandIO;
|
|
43
|
+
}
|
|
44
|
+
type JsonRecord = {
|
|
45
|
+
[key: string]: JsonValue;
|
|
46
|
+
};
|
|
47
|
+
export declare function registerCointegrationCommands(program: Command, context?: CointegrationCommandContext): void;
|
|
48
|
+
export declare function runCointegrationPairCommand(baseAsset: string, comparisonAsset: string, options: CointegrationPairCommandOptions, context?: CointegrationCommandContext): Promise<void>;
|
|
49
|
+
export declare function buildCointegrationPairInput(baseAsset: string, comparisonAsset: string, options: CointegrationPairCommandOptions): JsonRecord;
|
|
50
|
+
export declare function formatCointegrationPairHuman(data: CointegrationPairResponse, theme?: import("../cli/terminal.js").TerminalTheme): string;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=cointegration.d.ts.map
|