-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (122 loc) · 3.96 KB
/
Copy pathindex.js
File metadata and controls
140 lines (122 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* TradingView Agent — Main Entry Point
*
* Usage:
* import { agent, tv, pine } from 'tradingview-agent';
*
* Or via CLI:
* tva chat "analyze my chart"
* tva pine "write an RSI indicator"
* tva server # start browser UI
*/
// ── MCP Client (all 78 tools) ──
export {
connect,
disconnect,
callTool,
getTools,
health,
chart,
data,
pine as pineTools,
capture,
drawing,
alerts,
replay,
indicators,
watchlist,
ui,
batch,
} from './mcp/client.js';
// ── Claude Agent ──
export { agentTurn, agentChat } from './agent/claude.js';
// ── Pine Script ──
export { analyzeStatic, generateTemplate, developScript, analyzeDeep, backtestValidate, computeIndicators, extractParameters } from './pine/analyzer.js';
export { writePineScript, debugPineScript, explainPineScript } from './pine/writer.js';
export { TEMPLATES, getTemplate, listTemplates, searchTemplates } from './pine/templates.js';
// ── Pine Linter ──
export { lintPineScript, formatLintReport, detectsRepainting, auditStrategy, listRules } from './pine/linter.js';
// ── Strategy Builder ──
export { buildStrategy, buildPreset, listModules, STRATEGY_PRESETS } from './pine/strategy-builder.js';
// ── OakScript Local TA Engine ──
export { Series, BarData, taCore, ta, math, BacktestEngine } from './pine/oakscript.js';
// ── Charts / Lightweight Charts Plugins ──
export { generateChartHTML, generateMultiPaneHTML, generatePluginPine, listPlugins, CUSTOM_SERIES, DRAWING_PRIMITIVES } from './charts/plugins.js';
// ── Quantitative Research (institutional analytics) ──
export {
// returns
logReturns, pctReturns, cumulativeReturn, annualize,
// moments
mean, variance, stdev, skewness, kurtosis,
// risk-adjusted
sharpeRatio, sortinoRatio, calmarRatio, omegaRatio, informationRatio,
// drawdown
equityCurveFromReturns, maxDrawdown, underwaterCurve,
// VaR
historicalVaR, historicalCVaR, parametricVaR,
// time-series
autocorrelation, hurstExponent, halfLife, rollingBeta, rollingCorrelation,
// vol models
ewmaVolatility, realizedVolatility, garmanKlass,
// sizing
kellyFraction, volTargetSize, fixedFractional,
// portfolio
riskParityWeights, equalWeights, minVarianceWeights, covarianceMatrix, portfolioReturn,
// monte carlo
monteCarloBootstrap,
// regime + tearsheet
classifyRegime, performanceReport,
} from './pine/quant-research.js';
// ── Seamless TradingView Quant Tooling ──
export { quantReport, quantScan } from './tv/quant-report.js';
// ── Streaming / Monitoring ──
export { watchChart, scanSymbols, watchIndicator } from './agent/stream.js';
/**
* Quick-start: create a configured agent instance.
*
* @example
* const { chat } = createAgent();
* await chat("analyze my chart");
*/
export function createAgent(opts = {}) {
const history = [];
return {
/**
* Send a message to the agent and get a response.
*/
async chat(message) {
const { agentChat } = await import('./agent/claude.js');
const result = await agentChat(message, history);
history.push(...result.newMessages.slice(history.length));
return result;
},
/**
* Stream a message to the agent, yielding events.
*/
async *stream(message) {
const { agentTurn } = await import('./agent/claude.js');
const { connect } = await import('./mcp/client.js');
await connect();
const messages = [...history, { role: 'user', content: message }];
let fullText = '';
for await (const event of agentTurn(messages)) {
yield event;
if (event.type === 'text') fullText += event.text;
}
history.push({ role: 'user', content: message });
history.push({ role: 'assistant', content: fullText });
},
/**
* Clear conversation history.
*/
clearHistory() {
history.length = 0;
},
/**
* Get current history.
*/
getHistory() {
return [...history];
},
};
}