@talocode/tradia 0.1.0 → 0.1.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/LICENSE +21 -0
  2. package/README.md +138 -46
  3. package/dist/auth.d.ts +8 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +36 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/billing.d.ts +14 -0
  8. package/dist/billing.d.ts.map +1 -0
  9. package/dist/billing.js +64 -0
  10. package/dist/billing.js.map +1 -0
  11. package/dist/cli.d.ts +3 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +269 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/client.d.ts +77 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +187 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/engine.d.ts +124 -0
  20. package/dist/engine.d.ts.map +1 -0
  21. package/dist/engine.js +474 -0
  22. package/dist/engine.js.map +1 -0
  23. package/dist/index.d.ts +10 -2
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +9 -602
  26. package/dist/index.js.map +1 -0
  27. package/dist/journal.d.ts +7 -0
  28. package/dist/journal.d.ts.map +1 -0
  29. package/dist/journal.js +84 -0
  30. package/dist/journal.js.map +1 -0
  31. package/dist/reporting.d.ts +10 -0
  32. package/dist/reporting.d.ts.map +1 -0
  33. package/dist/reporting.js +97 -0
  34. package/dist/reporting.js.map +1 -0
  35. package/dist/risk.d.ts +24 -0
  36. package/dist/risk.d.ts.map +1 -0
  37. package/dist/risk.js +162 -0
  38. package/dist/risk.js.map +1 -0
  39. package/dist/server.d.ts +4 -0
  40. package/dist/server.d.ts.map +1 -0
  41. package/dist/server.js +194 -0
  42. package/dist/server.js.map +1 -0
  43. package/dist/types.d.ts +238 -0
  44. package/dist/types.d.ts.map +1 -0
  45. package/dist/types.js +16 -0
  46. package/dist/types.js.map +1 -0
  47. package/package.json +41 -30
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdulmuiz Adeyemo
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.
package/README.md CHANGED
@@ -1,68 +1,160 @@
1
- # Tradia
1
+ # Tradia Agentic Trading OS
2
2
 
3
- Local-first trading intelligence for prop firm traders.
3
+ Agentic trading intelligence for trade proposals, risk checks, journals, performance reports and public accountability updates.
4
4
 
5
- ## Install
5
+ **⚠️ Not financial advice. Human review required before acting on any trade.**
6
6
 
7
- ```bash
8
- npx @talocode/tradia
9
- ```
7
+ ## Features
8
+
9
+ - **Proposal Mode** — Generate structured trade proposals with invalidation and risk
10
+ - **Risk Engine** — Position sizing, risk-reward, drawdown, exposure, revenge trading detection
11
+ - **Journal Mode** — Create trade journal entries with lessons and discipline scores
12
+ - **Performance Analysis** — Win rate, profit factor, expectancy, max drawdown, R-multiples
13
+ - **Backtest Simulation** — Equity curves, win rates, drawdown analysis
14
+ - **Public Accountability** — Generate public updates explaining trades and performance
15
+ - **Portfolio Reports** — Account-level performance summaries
16
+ - **CLI** — Full command-line interface for local usage
17
+ - **API Server** — REST API for hosted and local usage
18
+ - **SDK** — TypeScript client for Node.js applications
19
+ - **MCP Tools** — Model Context Protocol tools for AI agent integration
20
+
21
+ ## Supported Markets
22
+
23
+ `forex` · `crypto` · `stocks` · `indices` · `commodities` · `prop_firm_account` · `paper_account`
24
+
25
+ ## Supported Strategies
10
26
 
11
- Global install:
27
+ `liquidity_sweep` · `trend_continuation` · `breakout_retest` · `support_resistance` · `mean_reversion` · `momentum` · `news_avoidance` · `custom`
28
+
29
+ ## Installation
12
30
 
13
31
  ```bash
14
- npm install -g @talocode/tradia
15
- tradia
32
+ npm install @talocode/tradia
16
33
  ```
17
34
 
18
- ## First run
35
+ ## CLI Usage
19
36
 
20
37
  ```bash
21
- tradia init
22
- tradia import ./trades.csv
23
- tradia stats
24
- tradia review week
25
- ```
38
+ # Generate a trade proposal
39
+ tradia propose --symbol XAUUSD --market forex --strategy liquidity_sweep --balance 500 --risk 0.5 --entry 2365.5 --stop 2372 --target 2350
26
40
 
27
- ## Storage
41
+ # Check risk parameters
42
+ tradia risk --balance 500 --risk 0.5 --entry 2365.5 --stop 2372 --target 2350
28
43
 
29
- Tradia stores data locally in `~/.tradia/`:
44
+ # Journal a trade
45
+ tradia journal --file trade.json
30
46
 
31
- - `config.json`
32
- - `trades.json`
33
- - `rules.json`
34
- - `reports/`
47
+ # Run a backtest
48
+ tradia backtest --file trades.json --balance 500 --risk 0.5
35
49
 
36
- No secrets, telemetry, broker connections, or paid APIs are required.
50
+ # Generate a public accountability update
51
+ tradia public-update --file trade-result.json
52
+ ```
37
53
 
38
- ## CSV import
54
+ ## SDK Usage
39
55
 
40
- Tradia imports common broker CSV exports and normalizes them into a local trade journal. See `docs/CSV_IMPORT.md` for the supported column mapping and a sample file.
56
+ ```typescript
57
+ import { TradiaClient } from '@talocode/tradia'
41
58
 
42
- ## Commands
59
+ const tradia = new TradiaClient()
60
+
61
+ // Local mode (no API key required)
62
+ const proposal = await tradia.trade.propose({
63
+ market: 'forex',
64
+ symbol: 'XAUUSD',
65
+ accountBalance: 500,
66
+ riskPercent: 0.5,
67
+ strategy: 'liquidity_sweep',
68
+ entry: 2365.5,
69
+ stopLoss: 2372,
70
+ takeProfit: 2350,
71
+ })
72
+
73
+ console.log(proposal)
74
+ ```
75
+
76
+ ## API Server
43
77
 
44
78
  ```bash
45
- tradia
46
- tradia --version
47
- tradia --help
48
- tradia init
49
- tradia import ./trades.csv
50
- tradia trades list
51
- tradia stats
52
- tradia mistakes
53
- tradia risk
54
- tradia review week
55
- tradia plan tomorrow
56
- tradia rules set ftmo
57
- tradia rules status
58
- tradia doctor
79
+ # Start the server
80
+ PORT=3070 npx tradia-server
81
+
82
+ # Health check
83
+ curl http://localhost:3070/health
84
+
85
+ # Trade proposal
86
+ curl -X POST http://localhost:3070/v1/tradia/trade/propose \
87
+ -H 'Content-Type: application/json' \
88
+ -d '{
89
+ "symbol": "XAUUSD",
90
+ "market": "forex",
91
+ "accountBalance": 500,
92
+ "riskPercent": 0.5,
93
+ "entry": 2365.5,
94
+ "stopLoss": 2372,
95
+ "takeProfit": 2350
96
+ }'
59
97
  ```
60
98
 
61
- ## Limitations
99
+ ## API Routes
100
+
101
+ | Method | Path | Description | Credits |
102
+ |--------|------|-------------|---------|
103
+ | GET | `/health` | Health check | — |
104
+ | GET | `/v1/tradia/health` | Health check | — |
105
+ | POST | `/v1/tradia/agent/plan` | Generate agent plan | 40 |
106
+ | POST | `/v1/tradia/market/analyze` | Analyze market context | 30 |
107
+ | POST | `/v1/tradia/signal/evaluate` | Evaluate a signal | 30 |
108
+ | POST | `/v1/tradia/risk/check` | Check risk parameters | 20 |
109
+ | POST | `/v1/tradia/trade/propose` | Generate trade proposal | 40 |
110
+ | POST | `/v1/tradia/trade/journal` | Create journal entry | 25 |
111
+ | POST | `/v1/tradia/portfolio/report` | Portfolio report | 50 |
112
+ | POST | `/v1/tradia/performance/analyze` | Performance analysis | 35 |
113
+ | POST | `/v1/tradia/public-update/generate` | Public accountability update | 30 |
114
+ | POST | `/v1/tradia/backtest/simulate` | Backtest simulation | 60 |
115
+ | POST | `/v1/tradia/accountability/card` | Accountability card | 25 |
116
+ | POST | `/v1/tradia/export/markdown` | Export as markdown | 5 |
117
+ | POST | `/v1/tradia/export/json` | Export as JSON | 5 |
118
+
119
+ ## Talocode Cloud Usage
120
+
121
+ ```typescript
122
+ import { TradiaClient } from '@talocode/tradia'
123
+
124
+ const tradia = new TradiaClient({
125
+ apiKey: process.env.TALOCODE_API_KEY,
126
+ useCloud: true,
127
+ })
128
+
129
+ const proposal = await tradia.trade.propose({
130
+ market: 'forex',
131
+ symbol: 'XAUUSD',
132
+ accountBalance: 500,
133
+ riskPercent: 0.5,
134
+ strategy: 'liquidity_sweep',
135
+ entry: 2365.5,
136
+ stopLoss: 2372,
137
+ takeProfit: 2350,
138
+ })
139
+ ```
140
+
141
+ ## Safety Boundaries
142
+
143
+ Tradia v0.1 is **agentic trading intelligence**, not live autonomous execution.
144
+
145
+ - **No real trade execution** — v0.1 does not connect to any broker
146
+ - **No financial advice** — All outputs are educational analysis
147
+ - **No guaranteed profits** — Past performance does not guarantee future results
148
+ - **Human review required** — Every output requires human review before action
149
+ - **Proposal/simulation mode only** — No live order placement
150
+ - **Risk warnings included** — Every output includes risk disclaimers
151
+
152
+ ## Support
153
+
154
+ Open-source Talocode products are built and maintained by Abdulmuiz Adeyemo.
155
+
156
+ Sponsor the work: https://github.com/sponsors/Abdulmuiz44
157
+
158
+ ## License
62
159
 
63
- - CSV import first
64
- - No broker connection yet
65
- - No auto-trading
66
- - No financial advice
67
- - No paid APIs required
68
- - No cloud sync yet
160
+ MIT
package/dist/auth.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export interface AuthResult {
2
+ authenticated: boolean;
3
+ apiKey?: string;
4
+ reason?: string;
5
+ }
6
+ export declare function authenticateRequest(authHeader?: string | null, xApiKey?: string | null): AuthResult;
7
+ export declare function redactApiKey(key?: string): string;
8
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/tradia/auth.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CAuBnG;AAYD,wBAAgB,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAIjD"}
package/dist/auth.js ADDED
@@ -0,0 +1,36 @@
1
+ export function authenticateRequest(authHeader, xApiKey) {
2
+ if (process.env.TRADIA_ALLOW_LOCAL_UNAUTH === 'true' && !authHeader && !xApiKey) {
3
+ return { authenticated: true, reason: 'local_unauth_mode' };
4
+ }
5
+ const apiKey = extractApiKey(authHeader, xApiKey);
6
+ if (!apiKey) {
7
+ return { authenticated: false, reason: 'missing_api_key' };
8
+ }
9
+ if (process.env.TALOCODE_API_KEY && apiKey !== process.env.TALOCODE_API_KEY) {
10
+ return { authenticated: false, reason: 'invalid_api_key' };
11
+ }
12
+ if (!process.env.TALOCODE_API_KEY) {
13
+ if (process.env.TRADIA_ALLOW_LOCAL_UNAUTH === 'true') {
14
+ return { authenticated: true, reason: 'local_mode_with_key' };
15
+ }
16
+ return { authenticated: false, reason: 'no_api_key_configured' };
17
+ }
18
+ return { authenticated: true, apiKey };
19
+ }
20
+ function extractApiKey(authHeader, xApiKey) {
21
+ if (authHeader && authHeader.startsWith('Bearer ')) {
22
+ return authHeader.slice(7).trim();
23
+ }
24
+ if (xApiKey) {
25
+ return xApiKey.trim();
26
+ }
27
+ return undefined;
28
+ }
29
+ export function redactApiKey(key) {
30
+ if (!key)
31
+ return '(none)';
32
+ if (key.length <= 8)
33
+ return '****';
34
+ return key.slice(0, 4) + '****' + key.slice(-4);
35
+ }
36
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/tradia/auth.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,mBAAmB,CAAC,UAA0B,EAAE,OAAuB;IACrF,IAAI,OAAO,CAAC,GAAG,CAAC,yBAAyB,KAAK,MAAM,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,EAAE,CAAC;QAChF,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAA;IAC7D,CAAC;IAED,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IAEjD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAA;IAC5D,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC5E,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAA;IAC5D,CAAC;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAClC,IAAI,OAAO,CAAC,GAAG,CAAC,yBAAyB,KAAK,MAAM,EAAE,CAAC;YACrD,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAA;QAC/D,CAAC;QACD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAA;IAClE,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AACxC,CAAC;AAED,SAAS,aAAa,CAAC,UAA0B,EAAE,OAAuB;IACxE,IAAI,UAAU,IAAI,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACnD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACnC,CAAC;IACD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,IAAI,EAAE,CAAA;IACvB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,IAAI,CAAC,GAAG;QAAE,OAAO,QAAQ,CAAA;IACzB,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,MAAM,CAAA;IAClC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AACjD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { BillingAction } from './types.js';
2
+ export declare class TradiaBillingError extends Error {
3
+ statusCode: number;
4
+ code: string;
5
+ constructor(message: string, statusCode: number, code: string);
6
+ }
7
+ export interface BillingResult {
8
+ charged: boolean;
9
+ credits: number;
10
+ action: string;
11
+ remaining?: number;
12
+ }
13
+ export declare function chargeCredits(action: BillingAction): Promise<BillingResult>;
14
+ //# sourceMappingURL=billing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../src/tradia/billing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C,qBAAa,kBAAmB,SAAQ,KAAK;IAGlC,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,MAAM;gBAFnB,OAAO,EAAE,MAAM,EACR,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM;CAKtB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAyDjF"}
@@ -0,0 +1,64 @@
1
+ import { PRICING } from './types.js';
2
+ export class TradiaBillingError extends Error {
3
+ statusCode;
4
+ code;
5
+ constructor(message, statusCode, code) {
6
+ super(message);
7
+ this.statusCode = statusCode;
8
+ this.code = code;
9
+ this.name = 'TradiaBillingError';
10
+ }
11
+ }
12
+ export async function chargeCredits(action) {
13
+ const apiKey = process.env.TALOCODE_API_KEY;
14
+ const baseUrl = process.env.TALOCODE_BASE_URL || 'https://api.talocode.site';
15
+ if (!apiKey) {
16
+ if (process.env.TRADIA_ALLOW_LOCAL_UNAUTH === 'true') {
17
+ return { charged: false, credits: 0, action };
18
+ }
19
+ throw new TradiaBillingError('TALOCODE_API_KEY is required for hosted billing', 401, 'auth_error');
20
+ }
21
+ const credits = PRICING[action] || 0;
22
+ try {
23
+ const response = await fetch(`${baseUrl}/api/v1/cloud/usage/charge`, {
24
+ method: 'POST',
25
+ headers: {
26
+ 'Content-Type': 'application/json',
27
+ 'Authorization': `Bearer ${apiKey}`,
28
+ },
29
+ body: JSON.stringify({
30
+ product: 'tradia',
31
+ action,
32
+ credits,
33
+ }),
34
+ });
35
+ if (response.status === 401) {
36
+ throw new TradiaBillingError('Invalid or missing API key', 401, 'auth_error');
37
+ }
38
+ if (response.status === 402) {
39
+ let body = {};
40
+ try {
41
+ body = await response.json();
42
+ }
43
+ catch { }
44
+ const errBody = body.error;
45
+ throw new TradiaBillingError(errBody?.message || 'Insufficient credits', 402, 'insufficient_credits');
46
+ }
47
+ if (!response.ok) {
48
+ throw new TradiaBillingError('Billing service unavailable', 502, 'billing_unavailable');
49
+ }
50
+ const body = await response.json();
51
+ return {
52
+ charged: body?.charged === true,
53
+ credits,
54
+ action,
55
+ remaining: typeof body?.remaining === 'number' ? body.remaining : undefined,
56
+ };
57
+ }
58
+ catch (err) {
59
+ if (err instanceof TradiaBillingError)
60
+ throw err;
61
+ throw new TradiaBillingError('Billing service unavailable', 502, 'billing_unavailable');
62
+ }
63
+ }
64
+ //# sourceMappingURL=billing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"billing.js","sourceRoot":"","sources":["../src/tradia/billing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAGlC;IACA;IAHT,YACE,OAAe,EACR,UAAkB,EAClB,IAAY;QAEnB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAQ;QAGnB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;CACF;AASD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAqB;IACvD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAA;IAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,2BAA2B,CAAA;IAE5E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,IAAI,OAAO,CAAC,GAAG,CAAC,yBAAyB,KAAK,MAAM,EAAE,CAAC;YACrD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAA;QAC/C,CAAC;QACD,MAAM,IAAI,kBAAkB,CAAC,iDAAiD,EAAE,GAAG,EAAE,YAAY,CAAC,CAAA;IACpG,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAEpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,4BAA4B,EAAE;YACnE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,eAAe,EAAE,UAAU,MAAM,EAAE;aACpC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,QAAQ;gBACjB,MAAM;gBACN,OAAO;aACR,CAAC;SACH,CAAC,CAAA;QAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,kBAAkB,CAAC,4BAA4B,EAAE,GAAG,EAAE,YAAY,CAAC,CAAA;QAC/E,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,IAAI,IAAI,GAA4B,EAAE,CAAA;YACtC,IAAI,CAAC;gBAAC,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAA6B,CAAA;YAAC,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAA4C,CAAA;YACjE,MAAM,IAAI,kBAAkB,CACzB,OAAO,EAAE,OAAkB,IAAI,sBAAsB,EACtD,GAAG,EACH,sBAAsB,CACvB,CAAA;QACH,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,kBAAkB,CAAC,6BAA6B,EAAE,GAAG,EAAE,qBAAqB,CAAC,CAAA;QACzF,CAAC;QAEC,MAAM,IAAI,GAA4B,MAAM,QAAQ,CAAC,IAAI,EAA6B,CAAA;QACtF,OAAO;YACL,OAAO,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI;YAC/B,OAAO;YACP,MAAM;YACN,SAAS,EAAE,OAAO,IAAI,EAAE,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;SAC5E,CAAA;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,kBAAkB;YAAE,MAAM,GAAG,CAAA;QAChD,MAAM,IAAI,kBAAkB,CAAC,6BAA6B,EAAE,GAAG,EAAE,qBAAqB,CAAC,CAAA;IACzF,CAAC;AACH,CAAC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/tradia/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ import { TradiaClient } from './client.js';
5
+ import { checkRiskInternal } from './risk.js';
6
+ import { proposeTrade, simulateBacktest, journalTrade, generatePublicUpdate, generateAccountabilityCard } from './engine.js';
7
+ const VERSION = '0.1.0';
8
+ function printHelp() {
9
+ console.log(`
10
+ Tradia Agentic Trading OS v${VERSION}
11
+
12
+ Usage: tradia <command> [options]
13
+
14
+ Commands:
15
+ agent-plan Generate an agent trading plan
16
+ market-analyze Analyze market context
17
+ signal Evaluate a trading signal
18
+ risk Check risk parameters
19
+ propose Generate a trade proposal
20
+ journal Create a trade journal entry
21
+ performance Analyze trading performance
22
+ report Generate a portfolio report
23
+ public-update Generate a public accountability update
24
+ backtest Simulate backtest on historical trades
25
+ accountability Generate an accountability card
26
+ export-markdown Export data as markdown
27
+ export-json Export data as JSON
28
+ whoami Show current configuration
29
+ config Show current configuration
30
+ --help, -h Show this help message
31
+ --version, -v Show version
32
+
33
+ Global options:
34
+ --cloud Use hosted Talocode Cloud API (requires TALOCODE_API_KEY)
35
+ --output <file> Write output to file
36
+ --format <format> Output format: json (default) or markdown
37
+
38
+ Examples:
39
+ tradia propose --symbol XAUUSD --market forex --strategy liquidity_sweep --balance 500 --risk 0.5 --entry 2365.5 --stop 2372 --target 2350
40
+ tradia risk --balance 500 --risk 0.5 --entry 2365.5 --stop 2372 --target 2350
41
+ tradia journal --file trade.json
42
+ tradia backtest --file trades.json --balance 500 --risk 0.5
43
+
44
+ ⚠️ Not financial advice. Human review required before acting on any trade.
45
+ `.trim());
46
+ }
47
+ function printVersion() {
48
+ console.log(`tradia v${VERSION}`);
49
+ }
50
+ function parseArgs() {
51
+ const args = process.argv.slice(2);
52
+ const parsed = {};
53
+ for (let i = 0; i < args.length; i++) {
54
+ if (args[i].startsWith('--')) {
55
+ const key = args[i].slice(2);
56
+ if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
57
+ parsed[key] = args[i + 1];
58
+ i++;
59
+ }
60
+ else {
61
+ parsed[key] = true;
62
+ }
63
+ }
64
+ else if (args[i].startsWith('-') && !args[i].startsWith('--')) {
65
+ const shortOpts = { h: 'help', v: 'version' };
66
+ const key = shortOpts[args[i].slice(1)];
67
+ if (key)
68
+ parsed[key] = true;
69
+ }
70
+ }
71
+ return parsed;
72
+ }
73
+ function readJsonFile(filePath) {
74
+ const resolved = resolve(filePath);
75
+ if (!existsSync(resolved)) {
76
+ console.error(`File not found: ${filePath}`);
77
+ process.exit(1);
78
+ }
79
+ const content = readFileSync(resolved, 'utf-8');
80
+ return JSON.parse(content);
81
+ }
82
+ function outputResult(result, options) {
83
+ const format = options.format || 'json';
84
+ const outFile = options.output;
85
+ let output;
86
+ if (format === 'markdown') {
87
+ const r = result;
88
+ output = r?.result?.markdown || JSON.stringify(result, null, 2);
89
+ }
90
+ else {
91
+ output = JSON.stringify(result, null, 2);
92
+ }
93
+ if (outFile) {
94
+ writeFileSync(resolve(outFile), output, 'utf-8');
95
+ console.log(`Output written to ${outFile}`);
96
+ }
97
+ else {
98
+ console.log(output);
99
+ }
100
+ }
101
+ async function main() {
102
+ const [command] = process.argv.slice(2).filter(a => !a.startsWith('-'));
103
+ const options = parseArgs();
104
+ if (options.help) {
105
+ printHelp();
106
+ return;
107
+ }
108
+ if (options.version) {
109
+ printVersion();
110
+ return;
111
+ }
112
+ if (!command || command === 'help') {
113
+ printHelp();
114
+ return;
115
+ }
116
+ const useCloud = !!options.cloud || false;
117
+ const apiKey = process.env.TALOCODE_API_KEY;
118
+ const baseUrl = process.env.TALOCODE_BASE_URL || 'https://api.talocode.site';
119
+ const client = new TradiaClient({ apiKey, baseUrl, useCloud: useCloud && !!apiKey });
120
+ switch (command) {
121
+ case 'whoami':
122
+ case 'config': {
123
+ console.log(JSON.stringify({
124
+ version: VERSION,
125
+ apiKeyConfigured: !!process.env.TALOCODE_API_KEY,
126
+ apiKeyRedacted: process.env.TALOCODE_API_KEY ? process.env.TALOCODE_API_KEY.slice(0, 4) + '****' : null,
127
+ baseUrl: baseUrl,
128
+ localUnauth: process.env.TRADIA_ALLOW_LOCAL_UNAUTH === 'true',
129
+ cloudMode: useCloud,
130
+ }, null, 2));
131
+ break;
132
+ }
133
+ case 'agent-plan': {
134
+ const result = await client.agent.plan({
135
+ symbol: options.symbol || undefined,
136
+ strategy: options.strategy,
137
+ timeframe: options.timeframe,
138
+ marketContext: options.context || undefined,
139
+ riskPercent: options.risk ? parseFloat(options.risk) : undefined,
140
+ accountBalance: options.balance ? parseFloat(options.balance) : undefined,
141
+ mode: options.mode || 'proposal',
142
+ });
143
+ outputResult(result, options);
144
+ break;
145
+ }
146
+ case 'market-analyze': {
147
+ const result = await client.market.analyze({
148
+ symbol: options.symbol || 'XAUUSD',
149
+ timeframe: options.timeframe || '1h',
150
+ context: options.context || '',
151
+ });
152
+ outputResult(result, options);
153
+ break;
154
+ }
155
+ case 'signal': {
156
+ const result = await client.signal.evaluate({
157
+ symbol: options.symbol || 'XAUUSD',
158
+ strategy: options.strategy || 'custom',
159
+ context: options.context || '',
160
+ timeframe: options.timeframe || '1h',
161
+ });
162
+ outputResult(result, options);
163
+ break;
164
+ }
165
+ case 'risk': {
166
+ const balance = parseFloat(options.balance);
167
+ const riskPercent = parseFloat(options.risk);
168
+ const entry = parseFloat(options.entry);
169
+ const stop = parseFloat(options.stop);
170
+ const target = parseFloat(options.target);
171
+ if (isNaN(balance) || isNaN(riskPercent) || isNaN(entry) || isNaN(stop) || isNaN(target)) {
172
+ console.error('Usage: tradia risk --balance 500 --risk 0.5 --entry 2365.5 --stop 2372 --target 2350');
173
+ process.exit(1);
174
+ }
175
+ const result = checkRiskInternal({ accountBalance: balance, riskPercent, entry, stopLoss: stop, takeProfit: target });
176
+ outputResult({ result }, options);
177
+ break;
178
+ }
179
+ case 'propose': {
180
+ const symbol = options.symbol;
181
+ const market = options.market;
182
+ const strategy = options.strategy;
183
+ const balance = parseFloat(options.balance);
184
+ const riskPercent = parseFloat(options.risk);
185
+ const entry = parseFloat(options.entry);
186
+ const stop = parseFloat(options.stop);
187
+ const target = parseFloat(options.target);
188
+ const timeframe = options.timeframe;
189
+ if (!symbol || !market || isNaN(balance) || isNaN(riskPercent) || isNaN(entry) || isNaN(stop) || isNaN(target)) {
190
+ console.error('Usage: tradia propose --symbol XAUUSD --market forex --strategy liquidity_sweep --balance 500 --risk 0.5 --entry 2365.5 --stop 2372 --target 2350');
191
+ process.exit(1);
192
+ }
193
+ const result = proposeTrade({
194
+ symbol, market: market,
195
+ strategy, accountBalance: balance, riskPercent, entry, stopLoss: stop, takeProfit: target,
196
+ timeframe, marketContext: options.context || undefined, setupNotes: options.notes || undefined,
197
+ });
198
+ outputResult(result, options);
199
+ break;
200
+ }
201
+ case 'journal': {
202
+ const data = readJsonFile(options.file);
203
+ const result = journalTrade(data);
204
+ outputResult(result, options);
205
+ break;
206
+ }
207
+ case 'performance': {
208
+ const data = readJsonFile(options.file);
209
+ const trades = (data.trades || data);
210
+ const balance = parseFloat(options.balance) || data.startingBalance || 0;
211
+ const result = await client.performance.analyze({ trades, startingBalance: balance });
212
+ outputResult(result, options);
213
+ break;
214
+ }
215
+ case 'report': {
216
+ const data = readJsonFile(options.file);
217
+ const trades = (data.trades || data);
218
+ const balance = parseFloat(options.balance) || data.accountBalance || 0;
219
+ const result = await client.portfolio.report({ trades, accountBalance: balance });
220
+ outputResult(result, options);
221
+ break;
222
+ }
223
+ case 'public-update': {
224
+ const data = readJsonFile(options.file);
225
+ const result = generatePublicUpdate(data);
226
+ outputResult(result, options);
227
+ break;
228
+ }
229
+ case 'backtest': {
230
+ const data = readJsonFile(options.file);
231
+ const trades = (data.trades || data);
232
+ const balance = parseFloat(options.balance) || data.startingBalance || 1000;
233
+ const riskPercent = parseFloat(options.risk) || data.riskPercent || 0.5;
234
+ const result = simulateBacktest({ strategy: (data.strategy || 'custom'), trades, startingBalance: balance, riskPercent });
235
+ outputResult(result, options);
236
+ break;
237
+ }
238
+ case 'accountability': {
239
+ const data = readJsonFile(options.file);
240
+ const result = generateAccountabilityCard(data);
241
+ outputResult(result, options);
242
+ break;
243
+ }
244
+ case 'export-markdown': {
245
+ const data = readJsonFile(options.file);
246
+ const { exportMarkdown: exportMd } = await import('./engine');
247
+ const result = exportMd(data);
248
+ outputResult(result, options);
249
+ break;
250
+ }
251
+ case 'export-json': {
252
+ const data = readJsonFile(options.file);
253
+ const { exportJson: exportJ } = await import('./engine');
254
+ const result = exportJ(data);
255
+ outputResult(result, options);
256
+ break;
257
+ }
258
+ default: {
259
+ console.error(`Unknown command: ${command}`);
260
+ console.error('Run "tradia --help" for usage.');
261
+ process.exit(1);
262
+ }
263
+ }
264
+ }
265
+ main().catch((err) => {
266
+ console.error('Error:', err.message);
267
+ process.exit(1);
268
+ });
269
+ //# sourceMappingURL=cli.js.map