fixparser-plugin-mcp 9.1.7-2924f547 → 9.1.7-2cd4ac1b
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/build/cjs/MCPLocal.js +105 -1446
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/cjs/MCPRemote.js +437 -2296
- package/build/cjs/MCPRemote.js.map +4 -4
- package/build/esm/MCPLocal.mjs +105 -1446
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build/esm/MCPRemote.mjs +444 -2284
- package/build/esm/MCPRemote.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +7 -9
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +7 -9
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +7 -7
- package/types/MCPLocal.d.ts +16 -0
- package/types/MCPRemote.d.ts +60 -0
- package/types/PluginOptions.d.ts +6 -0
- package/types/index.d.ts +3 -0
- package/types/schemas/index.d.ts +15 -0
- package/types/schemas/schemas.d.ts +168 -0
- package/types/tools/index.d.ts +17 -0
- package/types/tools/marketData.d.ts +40 -0
- package/types/tools/order.d.ts +12 -0
- package/types/tools/parse.d.ts +5 -0
- package/types/tools/parseToJSON.d.ts +5 -0
- package/build/cjs/index.js +0 -2593
- package/build/cjs/index.js.map +0 -7
- package/build/esm/index.mjs +0 -2555
- package/build/esm/index.mjs.map +0 -7
- package/build-examples/cjs/example_mcp_remote.js +0 -18
- package/build-examples/cjs/example_mcp_remote.js.map +0 -7
- package/build-examples/esm/example_mcp_remote.mjs +0 -18
- package/build-examples/esm/example_mcp_remote.mjs.map +0 -7
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,51 +1,9 @@
|
|
|
1
1
|
// src/MCPLocal.ts
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { Fields as Fields3, MDEntryType as MDEntryType2, Messages as Messages3 } from "fixparser";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
|
|
6
|
-
// src/MCPBase.ts
|
|
7
|
-
var MCPBase = class {
|
|
8
|
-
/**
|
|
9
|
-
* Optional logger instance for diagnostics and output.
|
|
10
|
-
* @protected
|
|
11
|
-
*/
|
|
12
|
-
logger;
|
|
13
|
-
/**
|
|
14
|
-
* FIXParser instance, set during plugin register().
|
|
15
|
-
* @protected
|
|
16
|
-
*/
|
|
17
|
-
parser;
|
|
18
|
-
/**
|
|
19
|
-
* Called when server is setup and listening.
|
|
20
|
-
* @protected
|
|
21
|
-
*/
|
|
22
|
-
onReady = void 0;
|
|
23
|
-
/**
|
|
24
|
-
* Map to store verified orders before execution
|
|
25
|
-
* @protected
|
|
26
|
-
*/
|
|
27
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Map to store pending market data requests
|
|
30
|
-
* @protected
|
|
31
|
-
*/
|
|
32
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
33
|
-
/**
|
|
34
|
-
* Map to store market data prices
|
|
35
|
-
* @protected
|
|
36
|
-
*/
|
|
37
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
38
|
-
/**
|
|
39
|
-
* Maximum number of price history entries to keep per symbol
|
|
40
|
-
* @protected
|
|
41
|
-
*/
|
|
42
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
43
|
-
constructor({ logger, onReady }) {
|
|
44
|
-
this.logger = logger;
|
|
45
|
-
this.onReady = onReady;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
7
|
// src/schemas/schemas.ts
|
|
50
8
|
var toolSchemas = {
|
|
51
9
|
parse: {
|
|
@@ -129,7 +87,7 @@ var toolSchemas = {
|
|
|
129
87
|
}
|
|
130
88
|
},
|
|
131
89
|
executeOrder: {
|
|
132
|
-
description: "Executes a verified order. verifyOrder must be called before executeOrder.",
|
|
90
|
+
description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
|
|
133
91
|
schema: {
|
|
134
92
|
type: "object",
|
|
135
93
|
properties: {
|
|
@@ -273,1071 +231,19 @@ var toolSchemas = {
|
|
|
273
231
|
},
|
|
274
232
|
required: ["symbol"]
|
|
275
233
|
}
|
|
276
|
-
},
|
|
277
|
-
technicalAnalysis: {
|
|
278
|
-
description: "Performs comprehensive technical analysis on market data for a given symbol, including indicators like SMA, EMA, RSI, Bollinger Bands, and trading signals",
|
|
279
|
-
schema: {
|
|
280
|
-
type: "object",
|
|
281
|
-
properties: {
|
|
282
|
-
symbol: {
|
|
283
|
-
type: "string",
|
|
284
|
-
description: "The trading symbol to analyze (e.g., AAPL, MSFT, EURUSD)"
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
required: ["symbol"]
|
|
288
|
-
}
|
|
289
234
|
}
|
|
290
235
|
};
|
|
291
236
|
|
|
292
|
-
// src/tools/analytics.ts
|
|
293
|
-
function sum(numbers) {
|
|
294
|
-
return numbers.reduce((acc, val) => acc + val, 0);
|
|
295
|
-
}
|
|
296
|
-
var TechnicalAnalyzer = class {
|
|
297
|
-
prices;
|
|
298
|
-
volumes;
|
|
299
|
-
highs;
|
|
300
|
-
lows;
|
|
301
|
-
constructor(data) {
|
|
302
|
-
this.prices = data.map((d) => d.trade > 0 ? d.trade : d.midPrice);
|
|
303
|
-
this.volumes = data.map((d) => d.volume);
|
|
304
|
-
this.highs = data.map((d) => d.tradingSessionHighPrice > 0 ? d.tradingSessionHighPrice : d.trade);
|
|
305
|
-
this.lows = data.map((d) => d.tradingSessionLowPrice > 0 ? d.tradingSessionLowPrice : d.trade);
|
|
306
|
-
}
|
|
307
|
-
// Calculate Simple Moving Average
|
|
308
|
-
calculateSMA(data, period) {
|
|
309
|
-
const sma = [];
|
|
310
|
-
for (let i = period - 1; i < data.length; i++) {
|
|
311
|
-
const sum2 = data.slice(i - period + 1, i + 1).reduce((a, b) => a + b, 0);
|
|
312
|
-
sma.push(sum2 / period);
|
|
313
|
-
}
|
|
314
|
-
return sma;
|
|
315
|
-
}
|
|
316
|
-
// Calculate Exponential Moving Average
|
|
317
|
-
calculateEMA(data, period) {
|
|
318
|
-
const multiplier = 2 / (period + 1);
|
|
319
|
-
const ema = [data[0]];
|
|
320
|
-
for (let i = 1; i < data.length; i++) {
|
|
321
|
-
ema.push(data[i] * multiplier + ema[i - 1] * (1 - multiplier));
|
|
322
|
-
}
|
|
323
|
-
return ema;
|
|
324
|
-
}
|
|
325
|
-
// Calculate RSI
|
|
326
|
-
calculateRSI(data, period = 14) {
|
|
327
|
-
if (data.length < period + 1) return [];
|
|
328
|
-
const changes = [];
|
|
329
|
-
for (let i = 1; i < data.length; i++) {
|
|
330
|
-
changes.push(data[i] - data[i - 1]);
|
|
331
|
-
}
|
|
332
|
-
const gains = changes.map((change) => change > 0 ? change : 0);
|
|
333
|
-
const losses = changes.map((change) => change < 0 ? Math.abs(change) : 0);
|
|
334
|
-
let avgGain = gains.slice(0, period).reduce((a, b) => a + b, 0) / period;
|
|
335
|
-
let avgLoss = losses.slice(0, period).reduce((a, b) => a + b, 0) / period;
|
|
336
|
-
const rsi = [];
|
|
337
|
-
for (let i = period; i < changes.length; i++) {
|
|
338
|
-
const rs = avgGain / avgLoss;
|
|
339
|
-
rsi.push(100 - 100 / (1 + rs));
|
|
340
|
-
avgGain = (avgGain * (period - 1) + gains[i]) / period;
|
|
341
|
-
avgLoss = (avgLoss * (period - 1) + losses[i]) / period;
|
|
342
|
-
}
|
|
343
|
-
return rsi;
|
|
344
|
-
}
|
|
345
|
-
// Calculate Bollinger Bands
|
|
346
|
-
calculateBollingerBands(data, period = 20, stdDev = 2) {
|
|
347
|
-
if (data.length < period) return [];
|
|
348
|
-
const sma = this.calculateSMA(data, period);
|
|
349
|
-
const bands = [];
|
|
350
|
-
for (let i = 0; i < sma.length; i++) {
|
|
351
|
-
const dataSlice = data.slice(i, i + period);
|
|
352
|
-
const mean = sma[i];
|
|
353
|
-
const variance = dataSlice.reduce((sum2, price) => sum2 + (price - mean) ** 2, 0) / period;
|
|
354
|
-
const standardDeviation = Math.sqrt(variance);
|
|
355
|
-
const upper = mean + standardDeviation * stdDev;
|
|
356
|
-
const lower = mean - standardDeviation * stdDev;
|
|
357
|
-
bands.push({
|
|
358
|
-
upper,
|
|
359
|
-
middle: mean,
|
|
360
|
-
lower,
|
|
361
|
-
bandwidth: (upper - lower) / mean * 100,
|
|
362
|
-
percentB: (data[i] - lower) / (upper - lower) * 100
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
return bands;
|
|
366
|
-
}
|
|
367
|
-
// Calculate maximum drawdown
|
|
368
|
-
calculateMaxDrawdown(prices) {
|
|
369
|
-
let maxPrice = prices[0];
|
|
370
|
-
let maxDrawdown = 0;
|
|
371
|
-
for (let i = 1; i < prices.length; i++) {
|
|
372
|
-
if (prices[i] > maxPrice) {
|
|
373
|
-
maxPrice = prices[i];
|
|
374
|
-
}
|
|
375
|
-
const drawdown = (maxPrice - prices[i]) / maxPrice;
|
|
376
|
-
if (drawdown > maxDrawdown) {
|
|
377
|
-
maxDrawdown = drawdown;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return maxDrawdown;
|
|
381
|
-
}
|
|
382
|
-
// Calculate Average True Range (ATR)
|
|
383
|
-
calculateAtr(prices, highs, lows, volumes) {
|
|
384
|
-
if (prices.length < 2) return [];
|
|
385
|
-
const trueRanges = [];
|
|
386
|
-
for (let i = 1; i < prices.length; i++) {
|
|
387
|
-
const high = highs[i] || prices[i];
|
|
388
|
-
const low = lows[i] || prices[i];
|
|
389
|
-
const prevClose = prices[i - 1];
|
|
390
|
-
const tr1 = high - low;
|
|
391
|
-
const tr2 = Math.abs(high - prevClose);
|
|
392
|
-
const tr3 = Math.abs(low - prevClose);
|
|
393
|
-
trueRanges.push(Math.max(tr1, tr2, tr3));
|
|
394
|
-
}
|
|
395
|
-
const atr = [];
|
|
396
|
-
if (trueRanges.length >= 14) {
|
|
397
|
-
let sum2 = trueRanges.slice(0, 14).reduce((a, b) => a + b, 0);
|
|
398
|
-
atr.push(sum2 / 14);
|
|
399
|
-
for (let i = 14; i < trueRanges.length; i++) {
|
|
400
|
-
sum2 = sum2 - trueRanges[i - 14] + trueRanges[i];
|
|
401
|
-
atr.push(sum2 / 14);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return atr;
|
|
405
|
-
}
|
|
406
|
-
// Calculate maximum consecutive losses
|
|
407
|
-
calculateMaxConsecutiveLosses(prices) {
|
|
408
|
-
let maxConsecutive = 0;
|
|
409
|
-
let currentConsecutive = 0;
|
|
410
|
-
for (let i = 1; i < prices.length; i++) {
|
|
411
|
-
if (prices[i] < prices[i - 1]) {
|
|
412
|
-
currentConsecutive++;
|
|
413
|
-
maxConsecutive = Math.max(maxConsecutive, currentConsecutive);
|
|
414
|
-
} else {
|
|
415
|
-
currentConsecutive = 0;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return maxConsecutive;
|
|
419
|
-
}
|
|
420
|
-
// Calculate win rate
|
|
421
|
-
calculateWinRate(prices) {
|
|
422
|
-
let wins = 0;
|
|
423
|
-
let total = 0;
|
|
424
|
-
for (let i = 1; i < prices.length; i++) {
|
|
425
|
-
if (prices[i] !== prices[i - 1]) {
|
|
426
|
-
total++;
|
|
427
|
-
if (prices[i] > prices[i - 1]) {
|
|
428
|
-
wins++;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return total > 0 ? wins / total : 0;
|
|
433
|
-
}
|
|
434
|
-
// Calculate profit factor
|
|
435
|
-
calculateProfitFactor(prices) {
|
|
436
|
-
let grossProfit = 0;
|
|
437
|
-
let grossLoss = 0;
|
|
438
|
-
for (let i = 1; i < prices.length; i++) {
|
|
439
|
-
const change = prices[i] - prices[i - 1];
|
|
440
|
-
if (change > 0) {
|
|
441
|
-
grossProfit += change;
|
|
442
|
-
} else {
|
|
443
|
-
grossLoss += Math.abs(change);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return grossLoss > 0 ? grossProfit / grossLoss : 0;
|
|
447
|
-
}
|
|
448
|
-
// Calculate Weighted Moving Average
|
|
449
|
-
calculateWma(data, period) {
|
|
450
|
-
const wma = [];
|
|
451
|
-
const weights = Array.from({ length: period }, (_, i) => i + 1);
|
|
452
|
-
const weightSum = weights.reduce((a, b) => a + b, 0);
|
|
453
|
-
for (let i = period - 1; i < data.length; i++) {
|
|
454
|
-
let weightedSum = 0;
|
|
455
|
-
for (let j = 0; j < period; j++) {
|
|
456
|
-
weightedSum += data[i - j] * weights[j];
|
|
457
|
-
}
|
|
458
|
-
wma.push(weightedSum / weightSum);
|
|
459
|
-
}
|
|
460
|
-
return wma;
|
|
461
|
-
}
|
|
462
|
-
// Calculate Volume Weighted Moving Average
|
|
463
|
-
calculateVwma(prices, period) {
|
|
464
|
-
const vwma = [];
|
|
465
|
-
for (let i = period - 1; i < prices.length; i++) {
|
|
466
|
-
let volumeSum = 0;
|
|
467
|
-
let priceVolumeSum = 0;
|
|
468
|
-
for (let j = 0; j < period; j++) {
|
|
469
|
-
const volume = this.volumes[i - j] || 1;
|
|
470
|
-
volumeSum += volume;
|
|
471
|
-
priceVolumeSum += prices[i - j] * volume;
|
|
472
|
-
}
|
|
473
|
-
vwma.push(priceVolumeSum / volumeSum);
|
|
474
|
-
}
|
|
475
|
-
return vwma;
|
|
476
|
-
}
|
|
477
|
-
// Calculate MACD
|
|
478
|
-
calculateMacd(prices) {
|
|
479
|
-
const ema12 = this.calculateEMA(prices, 12);
|
|
480
|
-
const ema26 = this.calculateEMA(prices, 26);
|
|
481
|
-
const macd = [];
|
|
482
|
-
for (let i = 0; i < Math.min(ema12.length, ema26.length); i++) {
|
|
483
|
-
const macdLine = ema12[i] - ema26[i];
|
|
484
|
-
macd.push({
|
|
485
|
-
macd: macdLine,
|
|
486
|
-
signal: 0,
|
|
487
|
-
// Would need to calculate signal line
|
|
488
|
-
histogram: 0
|
|
489
|
-
// Would need to calculate histogram
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
return macd;
|
|
493
|
-
}
|
|
494
|
-
// Calculate ADX
|
|
495
|
-
calculateAdx(prices, highs, lows) {
|
|
496
|
-
const adx = [];
|
|
497
|
-
for (let i = 14; i < prices.length; i++) {
|
|
498
|
-
adx.push(Math.random() * 50 + 25);
|
|
499
|
-
}
|
|
500
|
-
return adx;
|
|
501
|
-
}
|
|
502
|
-
// Calculate DMI
|
|
503
|
-
calculateDmi(prices, highs, lows) {
|
|
504
|
-
const dmi = [];
|
|
505
|
-
for (let i = 14; i < prices.length; i++) {
|
|
506
|
-
dmi.push({
|
|
507
|
-
plusDI: Math.random() * 50 + 25,
|
|
508
|
-
minusDI: Math.random() * 50 + 25,
|
|
509
|
-
adx: Math.random() * 50 + 25
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
return dmi;
|
|
513
|
-
}
|
|
514
|
-
// Calculate Ichimoku Cloud
|
|
515
|
-
calculateIchimoku(prices, highs, lows) {
|
|
516
|
-
const ichimoku = [];
|
|
517
|
-
for (let i = 26; i < prices.length; i++) {
|
|
518
|
-
ichimoku.push({
|
|
519
|
-
tenkan: prices[i],
|
|
520
|
-
kijun: prices[i],
|
|
521
|
-
senkouA: prices[i],
|
|
522
|
-
senkouB: prices[i],
|
|
523
|
-
chikou: prices[i]
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return ichimoku;
|
|
527
|
-
}
|
|
528
|
-
// Calculate Parabolic SAR
|
|
529
|
-
calculateParabolicSAR(prices, highs, lows) {
|
|
530
|
-
const sar = [];
|
|
531
|
-
for (let i = 0; i < prices.length; i++) {
|
|
532
|
-
sar.push(prices[i] * 0.98);
|
|
533
|
-
}
|
|
534
|
-
return sar;
|
|
535
|
-
}
|
|
536
|
-
// Calculate Stochastic
|
|
537
|
-
calculateStochastic(prices, highs, lows) {
|
|
538
|
-
const stochastic = [];
|
|
539
|
-
for (let i = 14; i < prices.length; i++) {
|
|
540
|
-
stochastic.push({
|
|
541
|
-
k: Math.random() * 100,
|
|
542
|
-
d: Math.random() * 100
|
|
543
|
-
});
|
|
544
|
-
}
|
|
545
|
-
return stochastic;
|
|
546
|
-
}
|
|
547
|
-
// Calculate CCI
|
|
548
|
-
calculateCci(prices, highs, lows) {
|
|
549
|
-
const cci = [];
|
|
550
|
-
for (let i = 20; i < prices.length; i++) {
|
|
551
|
-
cci.push(Math.random() * 200 - 100);
|
|
552
|
-
}
|
|
553
|
-
return cci;
|
|
554
|
-
}
|
|
555
|
-
// Calculate Rate of Change
|
|
556
|
-
calculateRoc(prices) {
|
|
557
|
-
const roc = [];
|
|
558
|
-
for (let i = 10; i < prices.length; i++) {
|
|
559
|
-
roc.push((prices[i] - prices[i - 10]) / prices[i - 10] * 100);
|
|
560
|
-
}
|
|
561
|
-
return roc;
|
|
562
|
-
}
|
|
563
|
-
// Calculate Williams %R
|
|
564
|
-
calculateWilliamsR(prices) {
|
|
565
|
-
const williamsR = [];
|
|
566
|
-
for (let i = 14; i < prices.length; i++) {
|
|
567
|
-
williamsR.push(Math.random() * 100 - 100);
|
|
568
|
-
}
|
|
569
|
-
return williamsR;
|
|
570
|
-
}
|
|
571
|
-
// Calculate Momentum
|
|
572
|
-
calculateMomentum(prices) {
|
|
573
|
-
const momentum = [];
|
|
574
|
-
for (let i = 10; i < prices.length; i++) {
|
|
575
|
-
momentum.push(prices[i] - prices[i - 10]);
|
|
576
|
-
}
|
|
577
|
-
return momentum;
|
|
578
|
-
}
|
|
579
|
-
// Calculate Keltner Channels
|
|
580
|
-
calculateKeltnerChannels(prices, highs, lows) {
|
|
581
|
-
const keltner = [];
|
|
582
|
-
for (let i = 20; i < prices.length; i++) {
|
|
583
|
-
keltner.push({
|
|
584
|
-
upper: prices[i] * 1.02,
|
|
585
|
-
middle: prices[i],
|
|
586
|
-
lower: prices[i] * 0.98
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
return keltner;
|
|
590
|
-
}
|
|
591
|
-
// Calculate Donchian Channels
|
|
592
|
-
calculateDonchianChannels(prices, highs, lows) {
|
|
593
|
-
const donchian = [];
|
|
594
|
-
for (let i = 20; i < prices.length; i++) {
|
|
595
|
-
const slice = prices.slice(i - 20, i);
|
|
596
|
-
donchian.push({
|
|
597
|
-
upper: Math.max(...slice),
|
|
598
|
-
middle: (Math.max(...slice) + Math.min(...slice)) / 2,
|
|
599
|
-
lower: Math.min(...slice)
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
return donchian;
|
|
603
|
-
}
|
|
604
|
-
// Calculate Chaikin Volatility
|
|
605
|
-
calculateChaikinVolatility(prices, highs, lows) {
|
|
606
|
-
const volatility = [];
|
|
607
|
-
for (let i = 10; i < prices.length; i++) {
|
|
608
|
-
volatility.push(Math.random() * 10);
|
|
609
|
-
}
|
|
610
|
-
return volatility;
|
|
611
|
-
}
|
|
612
|
-
// Calculate On Balance Volume
|
|
613
|
-
calculateObv(volumes) {
|
|
614
|
-
const obv = [volumes[0]];
|
|
615
|
-
for (let i = 1; i < volumes.length; i++) {
|
|
616
|
-
obv.push(obv[i - 1] + volumes[i]);
|
|
617
|
-
}
|
|
618
|
-
return obv;
|
|
619
|
-
}
|
|
620
|
-
// Calculate Chaikin Money Flow
|
|
621
|
-
calculateCmf(prices, highs, lows, volumes) {
|
|
622
|
-
const cmf = [];
|
|
623
|
-
for (let i = 20; i < prices.length; i++) {
|
|
624
|
-
cmf.push(Math.random() * 2 - 1);
|
|
625
|
-
}
|
|
626
|
-
return cmf;
|
|
627
|
-
}
|
|
628
|
-
// Calculate Accumulation/Distribution Line
|
|
629
|
-
calculateAdl(prices) {
|
|
630
|
-
const adl = [0];
|
|
631
|
-
for (let i = 1; i < prices.length; i++) {
|
|
632
|
-
adl.push(adl[i - 1] + (prices[i] - prices[i - 1]));
|
|
633
|
-
}
|
|
634
|
-
return adl;
|
|
635
|
-
}
|
|
636
|
-
// Calculate Volume Rate of Change
|
|
637
|
-
calculateVolumeROC(prices) {
|
|
638
|
-
const volumeROC = [];
|
|
639
|
-
for (let i = 10; i < this.volumes.length; i++) {
|
|
640
|
-
volumeROC.push((this.volumes[i] - this.volumes[i - 10]) / this.volumes[i - 10] * 100);
|
|
641
|
-
}
|
|
642
|
-
return volumeROC;
|
|
643
|
-
}
|
|
644
|
-
// Calculate Money Flow Index
|
|
645
|
-
calculateMfi(prices, highs, lows, volumes) {
|
|
646
|
-
const mfi = [];
|
|
647
|
-
for (let i = 14; i < prices.length; i++) {
|
|
648
|
-
mfi.push(Math.random() * 100);
|
|
649
|
-
}
|
|
650
|
-
return mfi;
|
|
651
|
-
}
|
|
652
|
-
// Calculate VWAP
|
|
653
|
-
calculateVwap(prices, volumes) {
|
|
654
|
-
const vwap = [];
|
|
655
|
-
let cumulativePV = 0;
|
|
656
|
-
let cumulativeVolume = 0;
|
|
657
|
-
for (let i = 0; i < prices.length; i++) {
|
|
658
|
-
cumulativePV += prices[i] * (volumes[i] || 1);
|
|
659
|
-
cumulativeVolume += volumes[i] || 1;
|
|
660
|
-
vwap.push(cumulativePV / cumulativeVolume);
|
|
661
|
-
}
|
|
662
|
-
return vwap;
|
|
663
|
-
}
|
|
664
|
-
// Calculate Pivot Points
|
|
665
|
-
calculatePivotPoints(prices) {
|
|
666
|
-
const pivotPoints = [];
|
|
667
|
-
for (let i = 0; i < prices.length; i++) {
|
|
668
|
-
const pp = prices[i];
|
|
669
|
-
pivotPoints.push({
|
|
670
|
-
pp,
|
|
671
|
-
r1: pp * 1.01,
|
|
672
|
-
r2: pp * 1.02,
|
|
673
|
-
r3: pp * 1.03,
|
|
674
|
-
s1: pp * 0.99,
|
|
675
|
-
s2: pp * 0.98,
|
|
676
|
-
s3: pp * 0.97
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
return pivotPoints;
|
|
680
|
-
}
|
|
681
|
-
// Calculate Fibonacci Levels
|
|
682
|
-
calculateFibonacciLevels(prices) {
|
|
683
|
-
const fibonacci = [];
|
|
684
|
-
for (let i = 0; i < prices.length; i++) {
|
|
685
|
-
const price = prices[i];
|
|
686
|
-
fibonacci.push({
|
|
687
|
-
retracement: {
|
|
688
|
-
level0: price,
|
|
689
|
-
level236: price * 0.764,
|
|
690
|
-
level382: price * 0.618,
|
|
691
|
-
level500: price * 0.5,
|
|
692
|
-
level618: price * 0.382,
|
|
693
|
-
level786: price * 0.214,
|
|
694
|
-
level100: price * 0
|
|
695
|
-
},
|
|
696
|
-
extension: {
|
|
697
|
-
level1272: price * 1.272,
|
|
698
|
-
level1618: price * 1.618,
|
|
699
|
-
level2618: price * 2.618,
|
|
700
|
-
level4236: price * 4.236
|
|
701
|
-
}
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
return fibonacci;
|
|
705
|
-
}
|
|
706
|
-
// Calculate Gann Levels
|
|
707
|
-
calculateGannLevels(prices) {
|
|
708
|
-
const gannLevels = [];
|
|
709
|
-
for (let i = 0; i < prices.length; i++) {
|
|
710
|
-
gannLevels.push(prices[i] * (1 + i * 0.01));
|
|
711
|
-
}
|
|
712
|
-
return gannLevels;
|
|
713
|
-
}
|
|
714
|
-
// Calculate Elliott Wave
|
|
715
|
-
calculateElliottWave(prices) {
|
|
716
|
-
const elliottWave = [];
|
|
717
|
-
for (let i = 0; i < prices.length; i++) {
|
|
718
|
-
elliottWave.push({
|
|
719
|
-
waves: [prices[i]],
|
|
720
|
-
currentWave: 1,
|
|
721
|
-
wavePosition: 0.5
|
|
722
|
-
});
|
|
723
|
-
}
|
|
724
|
-
return elliottWave;
|
|
725
|
-
}
|
|
726
|
-
// Calculate Harmonic Patterns
|
|
727
|
-
calculateHarmonicPatterns(prices) {
|
|
728
|
-
const harmonicPatterns = [];
|
|
729
|
-
for (let i = 0; i < prices.length; i++) {
|
|
730
|
-
harmonicPatterns.push({
|
|
731
|
-
type: "Gartley",
|
|
732
|
-
completion: 0.618,
|
|
733
|
-
target: prices[i] * 1.1,
|
|
734
|
-
stopLoss: prices[i] * 0.9
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
return harmonicPatterns;
|
|
738
|
-
}
|
|
739
|
-
// Calculate Position Size
|
|
740
|
-
calculatePositionSize(currentPrice, targetEntry, stopLoss) {
|
|
741
|
-
const riskPerShare = Math.abs(targetEntry - stopLoss);
|
|
742
|
-
return riskPerShare > 0 ? 100 / riskPerShare : 1;
|
|
743
|
-
}
|
|
744
|
-
// Calculate Confidence
|
|
745
|
-
calculateConfidence(signals) {
|
|
746
|
-
return Math.min(signals.length * 10, 100);
|
|
747
|
-
}
|
|
748
|
-
// Calculate Risk Level
|
|
749
|
-
calculateRiskLevel(volatility) {
|
|
750
|
-
if (volatility < 20) return "LOW";
|
|
751
|
-
if (volatility < 40) return "MEDIUM";
|
|
752
|
-
return "HIGH";
|
|
753
|
-
}
|
|
754
|
-
// Calculate Z-Score
|
|
755
|
-
calculateZScore(currentPrice, startPrice, avgVolume) {
|
|
756
|
-
return (currentPrice - startPrice) / (startPrice * 0.1);
|
|
757
|
-
}
|
|
758
|
-
// Calculate Ornstein-Uhlenbeck
|
|
759
|
-
calculateOrnsteinUhlenbeck(currentPrice, startPrice, avgVolume) {
|
|
760
|
-
return {
|
|
761
|
-
mean: startPrice,
|
|
762
|
-
speed: 0.1,
|
|
763
|
-
volatility: avgVolume * 0.01,
|
|
764
|
-
currentValue: currentPrice
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
// Calculate Kalman Filter
|
|
768
|
-
calculateKalmanFilter(currentPrice, startPrice, avgVolume) {
|
|
769
|
-
return {
|
|
770
|
-
state: currentPrice,
|
|
771
|
-
covariance: avgVolume * 1e-3,
|
|
772
|
-
gain: 0.5
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
// Calculate ARIMA
|
|
776
|
-
calculateArima(currentPrice, startPrice, avgVolume) {
|
|
777
|
-
return {
|
|
778
|
-
forecast: [currentPrice * 1.01, currentPrice * 1.02],
|
|
779
|
-
residuals: [0, 0],
|
|
780
|
-
aic: 100
|
|
781
|
-
};
|
|
782
|
-
}
|
|
783
|
-
// Calculate GARCH
|
|
784
|
-
calculateGarch(currentPrice, startPrice, avgVolume) {
|
|
785
|
-
return {
|
|
786
|
-
volatility: avgVolume * 0.01,
|
|
787
|
-
persistence: 0.9,
|
|
788
|
-
meanReversion: 0.1
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
// Calculate Hilbert Transform
|
|
792
|
-
calculateHilbertTransform(currentPrice, startPrice, avgVolume) {
|
|
793
|
-
return {
|
|
794
|
-
analytic: [currentPrice],
|
|
795
|
-
phase: [0],
|
|
796
|
-
amplitude: [currentPrice]
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
// Calculate Wavelet Transform
|
|
800
|
-
calculateWaveletTransform(currentPrice, startPrice, avgVolume) {
|
|
801
|
-
return {
|
|
802
|
-
coefficients: [currentPrice],
|
|
803
|
-
scales: [1]
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
// Calculate Black-Scholes
|
|
807
|
-
calculateBlackScholes(currentPrice, startPrice, avgVolume) {
|
|
808
|
-
const S = currentPrice;
|
|
809
|
-
const K = startPrice;
|
|
810
|
-
const T = 1;
|
|
811
|
-
const r = 0.05;
|
|
812
|
-
const sigma = avgVolume * 0.01;
|
|
813
|
-
const d1 = (Math.log(S / K) + (r + sigma * sigma / 2) * T) / (sigma * Math.sqrt(T));
|
|
814
|
-
const d2 = d1 - sigma * Math.sqrt(T);
|
|
815
|
-
const callPrice = S * this.normalCDF(d1) - K * Math.exp(-r * T) * this.normalCDF(d2);
|
|
816
|
-
const putPrice = K * Math.exp(-r * T) * this.normalCDF(-d2) - S * this.normalCDF(-d1);
|
|
817
|
-
return {
|
|
818
|
-
callPrice,
|
|
819
|
-
putPrice,
|
|
820
|
-
delta: this.normalCDF(d1),
|
|
821
|
-
gamma: this.normalPDF(d1) / (S * sigma * Math.sqrt(T)),
|
|
822
|
-
theta: -S * this.normalPDF(d1) * sigma / (2 * Math.sqrt(T)) - r * K * Math.exp(-r * T) * this.normalCDF(d2),
|
|
823
|
-
vega: S * Math.sqrt(T) * this.normalPDF(d1),
|
|
824
|
-
rho: K * T * Math.exp(-r * T) * this.normalCDF(d2)
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
// Normal CDF approximation
|
|
828
|
-
normalCDF(x) {
|
|
829
|
-
return 0.5 * (1 + this.erf(x / Math.sqrt(2)));
|
|
830
|
-
}
|
|
831
|
-
// Normal PDF
|
|
832
|
-
normalPDF(x) {
|
|
833
|
-
return Math.exp(-x * x / 2) / Math.sqrt(2 * Math.PI);
|
|
834
|
-
}
|
|
835
|
-
// Error function approximation
|
|
836
|
-
erf(x) {
|
|
837
|
-
const a1 = 0.254829592;
|
|
838
|
-
const a2 = -0.284496736;
|
|
839
|
-
const a3 = 1.421413741;
|
|
840
|
-
const a4 = -1.453152027;
|
|
841
|
-
const a5 = 1.061405429;
|
|
842
|
-
const p = 0.3275911;
|
|
843
|
-
const sign = x >= 0 ? 1 : -1;
|
|
844
|
-
const absX = Math.abs(x);
|
|
845
|
-
const t = 1 / (1 + p * absX);
|
|
846
|
-
const y = 1 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-absX * absX);
|
|
847
|
-
return sign * y;
|
|
848
|
-
}
|
|
849
|
-
// Calculate price changes for volatility
|
|
850
|
-
calculatePriceChanges() {
|
|
851
|
-
const changes = [];
|
|
852
|
-
for (let i = 1; i < this.prices.length; i++) {
|
|
853
|
-
changes.push((this.prices[i] - this.prices[i - 1]) / this.prices[i - 1]);
|
|
854
|
-
}
|
|
855
|
-
return changes;
|
|
856
|
-
}
|
|
857
|
-
// Generate comprehensive market analysis
|
|
858
|
-
analyze() {
|
|
859
|
-
const currentPrice = this.prices[this.prices.length - 1];
|
|
860
|
-
const startPrice = this.prices[0];
|
|
861
|
-
const sessionHigh = Math.max(...this.highs);
|
|
862
|
-
const sessionLow = Math.min(...this.lows);
|
|
863
|
-
const totalVolume = sum(this.volumes);
|
|
864
|
-
const avgVolume = totalVolume / this.volumes.length;
|
|
865
|
-
const priceChanges = this.calculatePriceChanges();
|
|
866
|
-
const volatility = priceChanges.length > 0 ? Math.sqrt(
|
|
867
|
-
priceChanges.reduce((sum2, change) => sum2 + change ** 2, 0) / priceChanges.length
|
|
868
|
-
) * Math.sqrt(252) * 100 : 0;
|
|
869
|
-
const sessionReturn = (currentPrice - startPrice) / startPrice * 100;
|
|
870
|
-
const pricePosition = (currentPrice - sessionLow) / (sessionHigh - sessionLow) * 100;
|
|
871
|
-
const trueVWAP = this.prices.reduce((sum2, price, i) => sum2 + price * this.volumes[i], 0) / totalVolume;
|
|
872
|
-
const momentum5 = this.prices.length > 5 ? (currentPrice - this.prices[Math.max(0, this.prices.length - 6)]) / this.prices[Math.max(0, this.prices.length - 6)] * 100 : 0;
|
|
873
|
-
const momentum10 = this.prices.length > 10 ? (currentPrice - this.prices[Math.max(0, this.prices.length - 11)]) / this.prices[Math.max(0, this.prices.length - 11)] * 100 : 0;
|
|
874
|
-
const maxDrawdown = this.calculateMaxDrawdown(this.prices);
|
|
875
|
-
const atrValues = this.calculateAtr(this.prices, this.highs, this.lows, this.volumes);
|
|
876
|
-
const atr = atrValues.length > 0 ? atrValues[atrValues.length - 1] : 0;
|
|
877
|
-
const impliedVolatility = volatility;
|
|
878
|
-
const realizedVolatility = volatility;
|
|
879
|
-
const sharpeRatio = sessionReturn / volatility;
|
|
880
|
-
const sortinoRatio = sessionReturn / realizedVolatility;
|
|
881
|
-
const calmarRatio = sessionReturn / maxDrawdown;
|
|
882
|
-
const maxConsecutiveLosses = this.calculateMaxConsecutiveLosses(this.prices);
|
|
883
|
-
const winRate = this.calculateWinRate(this.prices);
|
|
884
|
-
const profitFactor = this.calculateProfitFactor(this.prices);
|
|
885
|
-
return {
|
|
886
|
-
currentPrice,
|
|
887
|
-
startPrice,
|
|
888
|
-
sessionHigh,
|
|
889
|
-
sessionLow,
|
|
890
|
-
totalVolume,
|
|
891
|
-
avgVolume,
|
|
892
|
-
volatility,
|
|
893
|
-
sessionReturn,
|
|
894
|
-
pricePosition,
|
|
895
|
-
trueVWAP,
|
|
896
|
-
momentum5,
|
|
897
|
-
momentum10,
|
|
898
|
-
maxDrawdown,
|
|
899
|
-
atr,
|
|
900
|
-
impliedVolatility,
|
|
901
|
-
realizedVolatility,
|
|
902
|
-
sharpeRatio,
|
|
903
|
-
sortinoRatio,
|
|
904
|
-
calmarRatio,
|
|
905
|
-
maxConsecutiveLosses,
|
|
906
|
-
winRate,
|
|
907
|
-
profitFactor
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
// Generate technical indicators
|
|
911
|
-
getTechnicalIndicators() {
|
|
912
|
-
return {
|
|
913
|
-
sma5: this.calculateSMA(this.prices, 5),
|
|
914
|
-
sma10: this.calculateSMA(this.prices, 10),
|
|
915
|
-
sma20: this.calculateSMA(this.prices, 20),
|
|
916
|
-
sma50: this.calculateSMA(this.prices, 50),
|
|
917
|
-
sma200: this.calculateSMA(this.prices, 200),
|
|
918
|
-
ema8: this.calculateEMA(this.prices, 8),
|
|
919
|
-
ema12: this.calculateEMA(this.prices, 12),
|
|
920
|
-
ema21: this.calculateEMA(this.prices, 21),
|
|
921
|
-
ema26: this.calculateEMA(this.prices, 26),
|
|
922
|
-
wma20: this.calculateWma(this.prices, 20),
|
|
923
|
-
vwma20: this.calculateVwma(this.prices, 20),
|
|
924
|
-
macd: this.calculateMacd(this.prices),
|
|
925
|
-
adx: this.calculateAdx(this.prices, this.highs, this.lows),
|
|
926
|
-
dmi: this.calculateDmi(this.prices, this.highs, this.lows),
|
|
927
|
-
ichimoku: this.calculateIchimoku(this.prices, this.highs, this.lows),
|
|
928
|
-
parabolicSAR: this.calculateParabolicSAR(this.prices, this.highs, this.lows),
|
|
929
|
-
rsi: this.calculateRSI(this.prices, 14),
|
|
930
|
-
stochastic: this.calculateStochastic(this.prices, this.highs, this.lows),
|
|
931
|
-
cci: this.calculateCci(this.prices, this.highs, this.lows),
|
|
932
|
-
roc: this.calculateRoc(this.prices),
|
|
933
|
-
williamsR: this.calculateWilliamsR(this.prices),
|
|
934
|
-
momentum: this.calculateMomentum(this.prices),
|
|
935
|
-
bollinger: this.calculateBollingerBands(this.prices, 20, 2),
|
|
936
|
-
atr: this.calculateAtr(this.prices, this.highs, this.lows, this.volumes),
|
|
937
|
-
keltner: this.calculateKeltnerChannels(this.prices, this.highs, this.lows),
|
|
938
|
-
donchian: this.calculateDonchianChannels(this.prices, this.highs, this.lows),
|
|
939
|
-
chaikinVolatility: this.calculateChaikinVolatility(this.prices, this.highs, this.lows),
|
|
940
|
-
obv: this.calculateObv(this.volumes),
|
|
941
|
-
cmf: this.calculateCmf(this.prices, this.highs, this.lows, this.volumes),
|
|
942
|
-
adl: this.calculateAdl(this.prices),
|
|
943
|
-
volumeROC: this.calculateVolumeROC(this.prices),
|
|
944
|
-
mfi: this.calculateMfi(this.prices, this.highs, this.lows, this.volumes),
|
|
945
|
-
vwap: this.calculateVwap(this.prices, this.volumes),
|
|
946
|
-
pivotPoints: this.calculatePivotPoints(this.prices),
|
|
947
|
-
fibonacci: this.calculateFibonacciLevels(this.prices),
|
|
948
|
-
gannLevels: this.calculateGannLevels(this.prices),
|
|
949
|
-
elliottWave: this.calculateElliottWave(this.prices),
|
|
950
|
-
harmonicPatterns: this.calculateHarmonicPatterns(this.prices)
|
|
951
|
-
};
|
|
952
|
-
}
|
|
953
|
-
// Generate trading signals
|
|
954
|
-
generateSignals() {
|
|
955
|
-
const analysis = this.analyze();
|
|
956
|
-
let bullishSignals = 0;
|
|
957
|
-
let bearishSignals = 0;
|
|
958
|
-
const signals = [];
|
|
959
|
-
if (analysis.currentPrice > analysis.trueVWAP) {
|
|
960
|
-
signals.push(
|
|
961
|
-
`\u2713 BULLISH: Price above VWAP (+${((analysis.currentPrice - analysis.trueVWAP) / analysis.trueVWAP * 100).toFixed(2)}%)`
|
|
962
|
-
);
|
|
963
|
-
bullishSignals++;
|
|
964
|
-
} else {
|
|
965
|
-
signals.push(
|
|
966
|
-
`\u2717 BEARISH: Price below VWAP (${((analysis.currentPrice - analysis.trueVWAP) / analysis.trueVWAP * 100).toFixed(2)}%)`
|
|
967
|
-
);
|
|
968
|
-
bearishSignals++;
|
|
969
|
-
}
|
|
970
|
-
if (analysis.momentum5 > 0 && analysis.momentum10 > 0) {
|
|
971
|
-
signals.push("\u2713 BULLISH: Positive momentum on both timeframes");
|
|
972
|
-
bullishSignals++;
|
|
973
|
-
} else if (analysis.momentum5 < 0 && analysis.momentum10 < 0) {
|
|
974
|
-
signals.push("\u2717 BEARISH: Negative momentum on both timeframes");
|
|
975
|
-
bearishSignals++;
|
|
976
|
-
} else {
|
|
977
|
-
signals.push("\u25D0 MIXED: Conflicting momentum signals");
|
|
978
|
-
}
|
|
979
|
-
const currentVolume = this.volumes[this.volumes.length - 1];
|
|
980
|
-
const volumeRatio = currentVolume / analysis.avgVolume;
|
|
981
|
-
if (volumeRatio > 1.2 && analysis.sessionReturn > 0) {
|
|
982
|
-
signals.push("\u2713 BULLISH: Above-average volume supporting upward move");
|
|
983
|
-
bullishSignals++;
|
|
984
|
-
} else if (volumeRatio > 1.2 && analysis.sessionReturn < 0) {
|
|
985
|
-
signals.push("\u2717 BEARISH: Above-average volume supporting downward move");
|
|
986
|
-
bearishSignals++;
|
|
987
|
-
} else {
|
|
988
|
-
signals.push("\u25D0 NEUTRAL: Volume not providing clear direction");
|
|
989
|
-
}
|
|
990
|
-
if (analysis.pricePosition > 65 && analysis.volatility > 30) {
|
|
991
|
-
signals.push("\u2717 BEARISH: High in range with elevated volatility - reversal risk");
|
|
992
|
-
bearishSignals++;
|
|
993
|
-
} else if (analysis.pricePosition < 35 && analysis.volatility > 30) {
|
|
994
|
-
signals.push("\u2713 BULLISH: Low in range with volatility - potential bounce");
|
|
995
|
-
bullishSignals++;
|
|
996
|
-
} else {
|
|
997
|
-
signals.push("\u25D0 NEUTRAL: Price position and volatility not extreme");
|
|
998
|
-
}
|
|
999
|
-
return { bullishSignals, bearishSignals, signals };
|
|
1000
|
-
}
|
|
1001
|
-
// Generate comprehensive JSON analysis
|
|
1002
|
-
generateJSONAnalysis(symbol) {
|
|
1003
|
-
const analysis = this.analyze();
|
|
1004
|
-
const indicators = this.getTechnicalIndicators();
|
|
1005
|
-
const signals = this.generateSignals();
|
|
1006
|
-
const currentSMA5 = indicators.sma5.length > 0 ? indicators.sma5[indicators.sma5.length - 1] : null;
|
|
1007
|
-
const currentSMA10 = indicators.sma10.length > 0 ? indicators.sma10[indicators.sma10.length - 1] : null;
|
|
1008
|
-
const currentSMA20 = indicators.sma20.length > 0 ? indicators.sma20[indicators.sma20.length - 1] : null;
|
|
1009
|
-
const currentSMA50 = indicators.sma50.length > 0 ? indicators.sma50[indicators.sma50.length - 1] : null;
|
|
1010
|
-
const currentSMA200 = indicators.sma200.length > 0 ? indicators.sma200[indicators.sma200.length - 1] : null;
|
|
1011
|
-
const currentEMA8 = indicators.ema8[indicators.ema8.length - 1];
|
|
1012
|
-
const currentEMA12 = indicators.ema12[indicators.ema12.length - 1];
|
|
1013
|
-
const currentEMA21 = indicators.ema21[indicators.ema21.length - 1];
|
|
1014
|
-
const currentEMA26 = indicators.ema26[indicators.ema26.length - 1];
|
|
1015
|
-
const currentWMA20 = indicators.wma20.length > 0 ? indicators.wma20[indicators.wma20.length - 1] : null;
|
|
1016
|
-
const currentVWMA20 = indicators.vwma20.length > 0 ? indicators.vwma20[indicators.vwma20.length - 1] : null;
|
|
1017
|
-
const currentMACD = indicators.macd.length > 0 ? indicators.macd[indicators.macd.length - 1] : null;
|
|
1018
|
-
const currentADX = indicators.adx.length > 0 ? indicators.adx[indicators.adx.length - 1] : null;
|
|
1019
|
-
const currentDMI = indicators.dmi.length > 0 ? indicators.dmi[indicators.dmi.length - 1] : null;
|
|
1020
|
-
const currentIchimoku = indicators.ichimoku.length > 0 ? indicators.ichimoku[indicators.ichimoku.length - 1] : null;
|
|
1021
|
-
const currentParabolicSAR = indicators.parabolicSAR.length > 0 ? indicators.parabolicSAR[indicators.parabolicSAR.length - 1] : null;
|
|
1022
|
-
const currentRSI = indicators.rsi.length > 0 ? indicators.rsi[indicators.rsi.length - 1] : null;
|
|
1023
|
-
const currentStochastic = indicators.stochastic.length > 0 ? indicators.stochastic[indicators.stochastic.length - 1] : null;
|
|
1024
|
-
const currentCCI = indicators.cci.length > 0 ? indicators.cci[indicators.cci.length - 1] : null;
|
|
1025
|
-
const currentROC = indicators.roc.length > 0 ? indicators.roc[indicators.roc.length - 1] : null;
|
|
1026
|
-
const currentWilliamsR = indicators.williamsR.length > 0 ? indicators.williamsR[indicators.williamsR.length - 1] : null;
|
|
1027
|
-
const currentMomentum = indicators.momentum.length > 0 ? indicators.momentum[indicators.momentum.length - 1] : null;
|
|
1028
|
-
const currentBB = indicators.bollinger.length > 0 ? indicators.bollinger[indicators.bollinger.length - 1] : null;
|
|
1029
|
-
const currentAtr = indicators.atr.length > 0 ? indicators.atr[indicators.atr.length - 1] : null;
|
|
1030
|
-
const currentKeltner = indicators.keltner.length > 0 ? indicators.keltner[indicators.keltner.length - 1] : null;
|
|
1031
|
-
const currentDonchian = indicators.donchian.length > 0 ? indicators.donchian[indicators.donchian.length - 1] : null;
|
|
1032
|
-
const currentChaikinVolatility = indicators.chaikinVolatility.length > 0 ? indicators.chaikinVolatility[indicators.chaikinVolatility.length - 1] : null;
|
|
1033
|
-
const currentObv = indicators.obv.length > 0 ? indicators.obv[indicators.obv.length - 1] : null;
|
|
1034
|
-
const currentCmf = indicators.cmf.length > 0 ? indicators.cmf[indicators.cmf.length - 1] : null;
|
|
1035
|
-
const currentAdl = indicators.adl.length > 0 ? indicators.adl[indicators.adl.length - 1] : null;
|
|
1036
|
-
const currentVolumeROC = indicators.volumeROC.length > 0 ? indicators.volumeROC[indicators.volumeROC.length - 1] : null;
|
|
1037
|
-
const currentMfi = indicators.mfi.length > 0 ? indicators.mfi[indicators.mfi.length - 1] : null;
|
|
1038
|
-
const currentVwap = indicators.vwap.length > 0 ? indicators.vwap[indicators.vwap.length - 1] : null;
|
|
1039
|
-
const currentPivotPoints = indicators.pivotPoints.length > 0 ? indicators.pivotPoints[indicators.pivotPoints.length - 1] : null;
|
|
1040
|
-
const currentFibonacci = indicators.fibonacci.length > 0 ? indicators.fibonacci[indicators.fibonacci.length - 1] : null;
|
|
1041
|
-
const currentGannLevels = indicators.gannLevels.length > 0 ? indicators.gannLevels : [];
|
|
1042
|
-
const currentElliottWave = indicators.elliottWave.length > 0 ? indicators.elliottWave[indicators.elliottWave.length - 1] : null;
|
|
1043
|
-
const currentHarmonicPatterns = indicators.harmonicPatterns.length > 0 ? indicators.harmonicPatterns : [];
|
|
1044
|
-
const currentVolume = this.volumes[this.volumes.length - 1];
|
|
1045
|
-
const volumeRatio = currentVolume / analysis.avgVolume;
|
|
1046
|
-
const currentDrawdown = (analysis.sessionHigh - analysis.currentPrice) / analysis.sessionHigh * 100;
|
|
1047
|
-
const rangeWidth = (analysis.sessionHigh - analysis.sessionLow) / analysis.sessionLow * 100;
|
|
1048
|
-
const priceVsVWAP = (analysis.currentPrice - analysis.trueVWAP) / analysis.trueVWAP * 100;
|
|
1049
|
-
const totalScore = signals.bullishSignals - signals.bearishSignals;
|
|
1050
|
-
const overallSignal = totalScore > 0 ? "BULLISH_BIAS" : totalScore < 0 ? "BEARISH_BIAS" : "NEUTRAL";
|
|
1051
|
-
const targetEntry = Math.max(analysis.sessionLow * 1.005, analysis.trueVWAP * 0.998);
|
|
1052
|
-
const stopLoss = analysis.sessionLow * 0.995;
|
|
1053
|
-
const profitTarget = analysis.sessionHigh * 0.995;
|
|
1054
|
-
const riskRewardRatio = (profitTarget - analysis.currentPrice) / (analysis.currentPrice - stopLoss);
|
|
1055
|
-
const positionSize = this.calculatePositionSize(analysis.currentPrice, targetEntry, stopLoss);
|
|
1056
|
-
const maxRisk = positionSize * (targetEntry - stopLoss);
|
|
1057
|
-
return {
|
|
1058
|
-
symbol,
|
|
1059
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1060
|
-
marketStructure: {
|
|
1061
|
-
currentPrice: analysis.currentPrice,
|
|
1062
|
-
startPrice: analysis.startPrice,
|
|
1063
|
-
sessionHigh: analysis.sessionHigh,
|
|
1064
|
-
sessionLow: analysis.sessionLow,
|
|
1065
|
-
rangeWidth,
|
|
1066
|
-
totalVolume: analysis.totalVolume,
|
|
1067
|
-
sessionPerformance: analysis.sessionReturn,
|
|
1068
|
-
positionInRange: analysis.pricePosition
|
|
1069
|
-
},
|
|
1070
|
-
volatility: {
|
|
1071
|
-
impliedVolatility: analysis.impliedVolatility,
|
|
1072
|
-
realizedVolatility: analysis.realizedVolatility,
|
|
1073
|
-
atr: analysis.atr,
|
|
1074
|
-
maxDrawdown: analysis.maxDrawdown * 100,
|
|
1075
|
-
currentDrawdown
|
|
1076
|
-
},
|
|
1077
|
-
technicalIndicators: {
|
|
1078
|
-
sma5: currentSMA5,
|
|
1079
|
-
sma10: currentSMA10,
|
|
1080
|
-
sma20: currentSMA20,
|
|
1081
|
-
sma50: currentSMA50,
|
|
1082
|
-
sma200: currentSMA200,
|
|
1083
|
-
ema8: currentEMA8,
|
|
1084
|
-
ema12: currentEMA12,
|
|
1085
|
-
ema21: currentEMA21,
|
|
1086
|
-
ema26: currentEMA26,
|
|
1087
|
-
wma20: currentWMA20,
|
|
1088
|
-
vwma20: currentVWMA20,
|
|
1089
|
-
macd: currentMACD,
|
|
1090
|
-
adx: currentADX,
|
|
1091
|
-
dmi: currentDMI,
|
|
1092
|
-
ichimoku: currentIchimoku,
|
|
1093
|
-
parabolicSAR: currentParabolicSAR,
|
|
1094
|
-
rsi: currentRSI,
|
|
1095
|
-
stochastic: currentStochastic,
|
|
1096
|
-
cci: currentCCI,
|
|
1097
|
-
roc: currentROC,
|
|
1098
|
-
williamsR: currentWilliamsR,
|
|
1099
|
-
momentum: currentMomentum,
|
|
1100
|
-
bollingerBands: currentBB ? {
|
|
1101
|
-
upper: currentBB.upper,
|
|
1102
|
-
middle: currentBB.middle,
|
|
1103
|
-
lower: currentBB.lower,
|
|
1104
|
-
bandwidth: currentBB.bandwidth,
|
|
1105
|
-
percentB: currentBB.percentB
|
|
1106
|
-
} : null,
|
|
1107
|
-
atr: currentAtr,
|
|
1108
|
-
keltnerChannels: currentKeltner ? {
|
|
1109
|
-
upper: currentKeltner.upper,
|
|
1110
|
-
middle: currentKeltner.middle,
|
|
1111
|
-
lower: currentKeltner.lower
|
|
1112
|
-
} : null,
|
|
1113
|
-
donchianChannels: currentDonchian ? {
|
|
1114
|
-
upper: currentDonchian.upper,
|
|
1115
|
-
middle: currentDonchian.middle,
|
|
1116
|
-
lower: currentDonchian.lower
|
|
1117
|
-
} : null,
|
|
1118
|
-
chaikinVolatility: currentChaikinVolatility,
|
|
1119
|
-
obv: currentObv,
|
|
1120
|
-
cmf: currentCmf,
|
|
1121
|
-
adl: currentAdl,
|
|
1122
|
-
volumeROC: currentVolumeROC,
|
|
1123
|
-
mfi: currentMfi,
|
|
1124
|
-
vwap: currentVwap
|
|
1125
|
-
},
|
|
1126
|
-
volumeAnalysis: {
|
|
1127
|
-
currentVolume,
|
|
1128
|
-
averageVolume: Math.round(analysis.avgVolume),
|
|
1129
|
-
volumeRatio,
|
|
1130
|
-
trueVWAP: analysis.trueVWAP,
|
|
1131
|
-
priceVsVWAP,
|
|
1132
|
-
obv: currentObv,
|
|
1133
|
-
cmf: currentCmf,
|
|
1134
|
-
mfi: currentMfi
|
|
1135
|
-
},
|
|
1136
|
-
momentum: {
|
|
1137
|
-
momentum5: analysis.momentum5,
|
|
1138
|
-
momentum10: analysis.momentum10,
|
|
1139
|
-
sessionROC: analysis.sessionReturn,
|
|
1140
|
-
rsi: currentRSI,
|
|
1141
|
-
stochastic: currentStochastic,
|
|
1142
|
-
cci: currentCCI
|
|
1143
|
-
},
|
|
1144
|
-
supportResistance: {
|
|
1145
|
-
pivotPoints: currentPivotPoints,
|
|
1146
|
-
fibonacci: currentFibonacci,
|
|
1147
|
-
gannLevels: currentGannLevels,
|
|
1148
|
-
elliottWave: currentElliottWave,
|
|
1149
|
-
harmonicPatterns: currentHarmonicPatterns
|
|
1150
|
-
},
|
|
1151
|
-
tradingSignals: {
|
|
1152
|
-
...signals,
|
|
1153
|
-
overallSignal,
|
|
1154
|
-
signalScore: totalScore,
|
|
1155
|
-
confidence: this.calculateConfidence(signals.signals),
|
|
1156
|
-
riskLevel: this.calculateRiskLevel(analysis.volatility)
|
|
1157
|
-
},
|
|
1158
|
-
statisticalModels: {
|
|
1159
|
-
zScore: this.calculateZScore(analysis.currentPrice, analysis.startPrice, analysis.avgVolume),
|
|
1160
|
-
ornsteinUhlenbeck: this.calculateOrnsteinUhlenbeck(
|
|
1161
|
-
analysis.currentPrice,
|
|
1162
|
-
analysis.startPrice,
|
|
1163
|
-
analysis.avgVolume
|
|
1164
|
-
),
|
|
1165
|
-
kalmanFilter: this.calculateKalmanFilter(
|
|
1166
|
-
analysis.currentPrice,
|
|
1167
|
-
analysis.startPrice,
|
|
1168
|
-
analysis.avgVolume
|
|
1169
|
-
),
|
|
1170
|
-
arima: this.calculateArima(analysis.currentPrice, analysis.startPrice, analysis.avgVolume),
|
|
1171
|
-
garch: this.calculateGarch(analysis.currentPrice, analysis.startPrice, analysis.avgVolume),
|
|
1172
|
-
hilbertTransform: this.calculateHilbertTransform(
|
|
1173
|
-
analysis.currentPrice,
|
|
1174
|
-
analysis.startPrice,
|
|
1175
|
-
analysis.avgVolume
|
|
1176
|
-
),
|
|
1177
|
-
waveletTransform: this.calculateWaveletTransform(
|
|
1178
|
-
analysis.currentPrice,
|
|
1179
|
-
analysis.startPrice,
|
|
1180
|
-
analysis.avgVolume
|
|
1181
|
-
)
|
|
1182
|
-
},
|
|
1183
|
-
optionsAnalysis: (() => {
|
|
1184
|
-
const blackScholes = this.calculateBlackScholes(
|
|
1185
|
-
analysis.currentPrice,
|
|
1186
|
-
analysis.startPrice,
|
|
1187
|
-
analysis.avgVolume
|
|
1188
|
-
);
|
|
1189
|
-
if (!blackScholes) return null;
|
|
1190
|
-
return {
|
|
1191
|
-
blackScholes,
|
|
1192
|
-
impliedVolatility: analysis.impliedVolatility,
|
|
1193
|
-
delta: blackScholes.delta,
|
|
1194
|
-
gamma: blackScholes.gamma,
|
|
1195
|
-
theta: blackScholes.theta,
|
|
1196
|
-
vega: blackScholes.vega,
|
|
1197
|
-
rho: blackScholes.rho,
|
|
1198
|
-
greeks: {
|
|
1199
|
-
delta: blackScholes.delta,
|
|
1200
|
-
gamma: blackScholes.gamma,
|
|
1201
|
-
theta: blackScholes.theta,
|
|
1202
|
-
vega: blackScholes.vega,
|
|
1203
|
-
rho: blackScholes.rho
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
})(),
|
|
1207
|
-
riskManagement: {
|
|
1208
|
-
targetEntry,
|
|
1209
|
-
stopLoss,
|
|
1210
|
-
profitTarget,
|
|
1211
|
-
riskRewardRatio,
|
|
1212
|
-
positionSize,
|
|
1213
|
-
maxRisk
|
|
1214
|
-
},
|
|
1215
|
-
performance: {
|
|
1216
|
-
sharpeRatio: analysis.sharpeRatio,
|
|
1217
|
-
sortinoRatio: analysis.sortinoRatio,
|
|
1218
|
-
calmarRatio: analysis.calmarRatio,
|
|
1219
|
-
maxDrawdown: analysis.maxDrawdown * 100,
|
|
1220
|
-
winRate: analysis.winRate,
|
|
1221
|
-
profitFactor: analysis.profitFactor,
|
|
1222
|
-
totalReturn: analysis.sessionReturn,
|
|
1223
|
-
volatility: analysis.volatility
|
|
1224
|
-
}
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
};
|
|
1228
|
-
var createTechnicalAnalysisHandler = (marketDataPrices) => {
|
|
1229
|
-
return async (args) => {
|
|
1230
|
-
try {
|
|
1231
|
-
const symbol = args.symbol;
|
|
1232
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
1233
|
-
if (priceHistory.length === 0) {
|
|
1234
|
-
return {
|
|
1235
|
-
content: [
|
|
1236
|
-
{
|
|
1237
|
-
type: "text",
|
|
1238
|
-
text: `No price data available for ${symbol}. Please request market data first.`,
|
|
1239
|
-
uri: "technicalAnalysis"
|
|
1240
|
-
}
|
|
1241
|
-
]
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
const hasValidData = priceHistory.every(
|
|
1245
|
-
(entry) => typeof entry.trade === "number" && !Number.isNaN(entry.trade) && typeof entry.midPrice === "number" && !Number.isNaN(entry.midPrice)
|
|
1246
|
-
);
|
|
1247
|
-
if (!hasValidData) {
|
|
1248
|
-
throw new Error("Invalid market data");
|
|
1249
|
-
}
|
|
1250
|
-
const analyzer = new TechnicalAnalyzer(priceHistory);
|
|
1251
|
-
const analysis = analyzer.generateJSONAnalysis(symbol);
|
|
1252
|
-
return {
|
|
1253
|
-
content: [
|
|
1254
|
-
{
|
|
1255
|
-
type: "text",
|
|
1256
|
-
text: `Technical Analysis for ${symbol}:
|
|
1257
|
-
|
|
1258
|
-
${JSON.stringify(analysis, null, 2)}`,
|
|
1259
|
-
uri: "technicalAnalysis"
|
|
1260
|
-
}
|
|
1261
|
-
]
|
|
1262
|
-
};
|
|
1263
|
-
} catch (error) {
|
|
1264
|
-
return {
|
|
1265
|
-
content: [
|
|
1266
|
-
{
|
|
1267
|
-
type: "text",
|
|
1268
|
-
text: `Error performing technical analysis: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1269
|
-
uri: "technicalAnalysis"
|
|
1270
|
-
}
|
|
1271
|
-
],
|
|
1272
|
-
isError: true
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
};
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
237
|
// src/tools/marketData.ts
|
|
1279
238
|
import { Field, Fields, MDEntryType, Messages } from "fixparser";
|
|
1280
239
|
import QuickChart from "quickchart-js";
|
|
1281
240
|
var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
1282
241
|
return async (args) => {
|
|
1283
242
|
try {
|
|
1284
|
-
parser.logger.log({
|
|
1285
|
-
level: "info",
|
|
1286
|
-
message: `Sending market data request for symbols: ${args.symbols.join(", ")}`
|
|
1287
|
-
});
|
|
1288
243
|
const response = new Promise((resolve) => {
|
|
1289
244
|
pendingRequests.set(args.mdReqID, resolve);
|
|
1290
|
-
parser.logger.log({
|
|
1291
|
-
level: "info",
|
|
1292
|
-
message: `Registered callback for market data request ID: ${args.mdReqID}`
|
|
1293
|
-
});
|
|
1294
245
|
});
|
|
1295
|
-
const entryTypes = args.mdEntryTypes || [
|
|
1296
|
-
MDEntryType.Bid,
|
|
1297
|
-
MDEntryType.Offer,
|
|
1298
|
-
MDEntryType.Trade,
|
|
1299
|
-
MDEntryType.IndexValue,
|
|
1300
|
-
MDEntryType.OpeningPrice,
|
|
1301
|
-
MDEntryType.ClosingPrice,
|
|
1302
|
-
MDEntryType.SettlementPrice,
|
|
1303
|
-
MDEntryType.TradingSessionHighPrice,
|
|
1304
|
-
MDEntryType.TradingSessionLowPrice,
|
|
1305
|
-
MDEntryType.VWAP,
|
|
1306
|
-
MDEntryType.Imbalance,
|
|
1307
|
-
MDEntryType.TradeVolume,
|
|
1308
|
-
MDEntryType.OpenInterest,
|
|
1309
|
-
MDEntryType.CompositeUnderlyingPrice,
|
|
1310
|
-
MDEntryType.SimulatedSellPrice,
|
|
1311
|
-
MDEntryType.SimulatedBuyPrice,
|
|
1312
|
-
MDEntryType.MarginRate,
|
|
1313
|
-
MDEntryType.MidPrice,
|
|
1314
|
-
MDEntryType.EmptyBook,
|
|
1315
|
-
MDEntryType.SettleHighPrice,
|
|
1316
|
-
MDEntryType.SettleLowPrice,
|
|
1317
|
-
MDEntryType.PriorSettlePrice,
|
|
1318
|
-
MDEntryType.SessionHighBid,
|
|
1319
|
-
MDEntryType.SessionLowOffer,
|
|
1320
|
-
MDEntryType.EarlyPrices,
|
|
1321
|
-
MDEntryType.AuctionClearingPrice,
|
|
1322
|
-
MDEntryType.SwapValueFactor,
|
|
1323
|
-
MDEntryType.DailyValueAdjustmentForLongPositions,
|
|
1324
|
-
MDEntryType.CumulativeValueAdjustmentForLongPositions,
|
|
1325
|
-
MDEntryType.DailyValueAdjustmentForShortPositions,
|
|
1326
|
-
MDEntryType.CumulativeValueAdjustmentForShortPositions,
|
|
1327
|
-
MDEntryType.FixingPrice,
|
|
1328
|
-
MDEntryType.CashRate,
|
|
1329
|
-
MDEntryType.RecoveryRate,
|
|
1330
|
-
MDEntryType.RecoveryRateForLong,
|
|
1331
|
-
MDEntryType.RecoveryRateForShort,
|
|
1332
|
-
MDEntryType.MarketBid,
|
|
1333
|
-
MDEntryType.MarketOffer,
|
|
1334
|
-
MDEntryType.ShortSaleMinPrice,
|
|
1335
|
-
MDEntryType.PreviousClosingPrice,
|
|
1336
|
-
MDEntryType.ThresholdLimitPriceBanding,
|
|
1337
|
-
MDEntryType.DailyFinancingValue,
|
|
1338
|
-
MDEntryType.AccruedFinancingValue,
|
|
1339
|
-
MDEntryType.TWAP
|
|
1340
|
-
];
|
|
246
|
+
const entryTypes = args.mdEntryTypes || [MDEntryType.Bid, MDEntryType.Offer, MDEntryType.TradeVolume];
|
|
1341
247
|
const messageFields = [
|
|
1342
248
|
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
1343
249
|
new Field(Fields.SenderCompID, parser.sender),
|
|
@@ -1359,10 +265,6 @@ var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
|
1359
265
|
});
|
|
1360
266
|
const mdr = parser.createMessage(...messageFields);
|
|
1361
267
|
if (!parser.connected) {
|
|
1362
|
-
parser.logger.log({
|
|
1363
|
-
level: "error",
|
|
1364
|
-
message: "Not connected. Cannot send market data request."
|
|
1365
|
-
});
|
|
1366
268
|
return {
|
|
1367
269
|
content: [
|
|
1368
270
|
{
|
|
@@ -1374,16 +276,8 @@ var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
|
1374
276
|
isError: true
|
|
1375
277
|
};
|
|
1376
278
|
}
|
|
1377
|
-
parser.logger.log({
|
|
1378
|
-
level: "info",
|
|
1379
|
-
message: `Sending market data request message: ${JSON.stringify(mdr?.toFIXJSON())}`
|
|
1380
|
-
});
|
|
1381
279
|
parser.send(mdr);
|
|
1382
280
|
const fixData = await response;
|
|
1383
|
-
parser.logger.log({
|
|
1384
|
-
level: "info",
|
|
1385
|
-
message: `Received market data response for request ID: ${args.mdReqID}`
|
|
1386
|
-
});
|
|
1387
281
|
return {
|
|
1388
282
|
content: [
|
|
1389
283
|
{
|
|
@@ -1424,17 +318,14 @@ var createGetStockGraphHandler = (marketDataPrices) => {
|
|
|
1424
318
|
};
|
|
1425
319
|
}
|
|
1426
320
|
const chart = new QuickChart();
|
|
1427
|
-
chart.setWidth(
|
|
1428
|
-
chart.setHeight(
|
|
321
|
+
chart.setWidth(300);
|
|
322
|
+
chart.setHeight(150);
|
|
1429
323
|
chart.setBackgroundColor("transparent");
|
|
1430
324
|
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
1431
325
|
const bidData = priceHistory.map((point) => point.bid);
|
|
1432
326
|
const offerData = priceHistory.map((point) => point.offer);
|
|
1433
327
|
const spreadData = priceHistory.map((point) => point.spread);
|
|
1434
328
|
const volumeData = priceHistory.map((point) => point.volume);
|
|
1435
|
-
const tradeData = priceHistory.map((point) => point.trade);
|
|
1436
|
-
const vwapData = priceHistory.map((point) => point.vwap);
|
|
1437
|
-
const twapData = priceHistory.map((point) => point.twap);
|
|
1438
329
|
const config = {
|
|
1439
330
|
type: "line",
|
|
1440
331
|
data: {
|
|
@@ -1464,30 +355,6 @@ var createGetStockGraphHandler = (marketDataPrices) => {
|
|
|
1464
355
|
fill: false,
|
|
1465
356
|
tension: 0.4
|
|
1466
357
|
},
|
|
1467
|
-
{
|
|
1468
|
-
label: "Trade",
|
|
1469
|
-
data: tradeData,
|
|
1470
|
-
borderColor: "#ffc107",
|
|
1471
|
-
backgroundColor: "rgba(255, 193, 7, 0.1)",
|
|
1472
|
-
fill: false,
|
|
1473
|
-
tension: 0.4
|
|
1474
|
-
},
|
|
1475
|
-
{
|
|
1476
|
-
label: "VWAP",
|
|
1477
|
-
data: vwapData,
|
|
1478
|
-
borderColor: "#17a2b8",
|
|
1479
|
-
backgroundColor: "rgba(23, 162, 184, 0.1)",
|
|
1480
|
-
fill: false,
|
|
1481
|
-
tension: 0.4
|
|
1482
|
-
},
|
|
1483
|
-
{
|
|
1484
|
-
label: "TWAP",
|
|
1485
|
-
data: twapData,
|
|
1486
|
-
borderColor: "#6610f2",
|
|
1487
|
-
backgroundColor: "rgba(102, 16, 242, 0.1)",
|
|
1488
|
-
fill: false,
|
|
1489
|
-
tension: 0.4
|
|
1490
|
-
},
|
|
1491
358
|
{
|
|
1492
359
|
label: "Volume",
|
|
1493
360
|
data: volumeData,
|
|
@@ -1523,7 +390,7 @@ var createGetStockGraphHandler = (marketDataPrices) => {
|
|
|
1523
390
|
resource: {
|
|
1524
391
|
uri: "resource://graph",
|
|
1525
392
|
mimeType: "image/png",
|
|
1526
|
-
blob: base64
|
|
393
|
+
blob: `image/png;base64,${base64}`
|
|
1527
394
|
}
|
|
1528
395
|
}
|
|
1529
396
|
]
|
|
@@ -1533,7 +400,7 @@ var createGetStockGraphHandler = (marketDataPrices) => {
|
|
|
1533
400
|
content: [
|
|
1534
401
|
{
|
|
1535
402
|
type: "text",
|
|
1536
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to generate
|
|
403
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
1537
404
|
uri: "getStockGraph"
|
|
1538
405
|
}
|
|
1539
406
|
],
|
|
@@ -1571,48 +438,7 @@ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
|
1571
438
|
bid: point.bid,
|
|
1572
439
|
offer: point.offer,
|
|
1573
440
|
spread: point.spread,
|
|
1574
|
-
volume: point.volume
|
|
1575
|
-
trade: point.trade,
|
|
1576
|
-
indexValue: point.indexValue,
|
|
1577
|
-
openingPrice: point.openingPrice,
|
|
1578
|
-
closingPrice: point.closingPrice,
|
|
1579
|
-
settlementPrice: point.settlementPrice,
|
|
1580
|
-
tradingSessionHighPrice: point.tradingSessionHighPrice,
|
|
1581
|
-
tradingSessionLowPrice: point.tradingSessionLowPrice,
|
|
1582
|
-
vwap: point.vwap,
|
|
1583
|
-
imbalance: point.imbalance,
|
|
1584
|
-
openInterest: point.openInterest,
|
|
1585
|
-
compositeUnderlyingPrice: point.compositeUnderlyingPrice,
|
|
1586
|
-
simulatedSellPrice: point.simulatedSellPrice,
|
|
1587
|
-
simulatedBuyPrice: point.simulatedBuyPrice,
|
|
1588
|
-
marginRate: point.marginRate,
|
|
1589
|
-
midPrice: point.midPrice,
|
|
1590
|
-
emptyBook: point.emptyBook,
|
|
1591
|
-
settleHighPrice: point.settleHighPrice,
|
|
1592
|
-
settleLowPrice: point.settleLowPrice,
|
|
1593
|
-
priorSettlePrice: point.priorSettlePrice,
|
|
1594
|
-
sessionHighBid: point.sessionHighBid,
|
|
1595
|
-
sessionLowOffer: point.sessionLowOffer,
|
|
1596
|
-
earlyPrices: point.earlyPrices,
|
|
1597
|
-
auctionClearingPrice: point.auctionClearingPrice,
|
|
1598
|
-
swapValueFactor: point.swapValueFactor,
|
|
1599
|
-
dailyValueAdjustmentForLongPositions: point.dailyValueAdjustmentForLongPositions,
|
|
1600
|
-
cumulativeValueAdjustmentForLongPositions: point.cumulativeValueAdjustmentForLongPositions,
|
|
1601
|
-
dailyValueAdjustmentForShortPositions: point.dailyValueAdjustmentForShortPositions,
|
|
1602
|
-
cumulativeValueAdjustmentForShortPositions: point.cumulativeValueAdjustmentForShortPositions,
|
|
1603
|
-
fixingPrice: point.fixingPrice,
|
|
1604
|
-
cashRate: point.cashRate,
|
|
1605
|
-
recoveryRate: point.recoveryRate,
|
|
1606
|
-
recoveryRateForLong: point.recoveryRateForLong,
|
|
1607
|
-
recoveryRateForShort: point.recoveryRateForShort,
|
|
1608
|
-
marketBid: point.marketBid,
|
|
1609
|
-
marketOffer: point.marketOffer,
|
|
1610
|
-
shortSaleMinPrice: point.shortSaleMinPrice,
|
|
1611
|
-
previousClosingPrice: point.previousClosingPrice,
|
|
1612
|
-
thresholdLimitPriceBanding: point.thresholdLimitPriceBanding,
|
|
1613
|
-
dailyFinancingValue: point.dailyFinancingValue,
|
|
1614
|
-
accruedFinancingValue: point.accruedFinancingValue,
|
|
1615
|
-
twap: point.twap
|
|
441
|
+
volume: point.volume
|
|
1616
442
|
}))
|
|
1617
443
|
},
|
|
1618
444
|
null,
|
|
@@ -1627,7 +453,7 @@ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
|
1627
453
|
content: [
|
|
1628
454
|
{
|
|
1629
455
|
type: "text",
|
|
1630
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to get price history"}`,
|
|
456
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
1631
457
|
uri: "getStockPriceHistory"
|
|
1632
458
|
}
|
|
1633
459
|
],
|
|
@@ -1735,7 +561,7 @@ Parameters verified:
|
|
|
1735
561
|
- Symbol: ${args.symbol}
|
|
1736
562
|
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
1737
563
|
|
|
1738
|
-
To execute this order, call the executeOrder tool with these exact same parameters
|
|
564
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
1739
565
|
uri: "verifyOrder"
|
|
1740
566
|
}
|
|
1741
567
|
]
|
|
@@ -1931,259 +757,12 @@ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPri
|
|
|
1931
757
|
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
1932
758
|
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
1933
759
|
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
1934
|
-
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
1935
|
-
technicalAnalysis: createTechnicalAnalysisHandler(marketDataPrices)
|
|
760
|
+
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
1936
761
|
});
|
|
1937
762
|
|
|
1938
|
-
// src/utils/messageHandler.ts
|
|
1939
|
-
import { Fields as Fields3, MDEntryType as MDEntryType2, Messages as Messages3 } from "fixparser";
|
|
1940
|
-
function getEnumValue(enumObj, name) {
|
|
1941
|
-
return enumObj[name] || name;
|
|
1942
|
-
}
|
|
1943
|
-
function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
|
|
1944
|
-
const msgType = message.messageType;
|
|
1945
|
-
if (msgType === Messages3.MarketDataSnapshotFullRefresh || msgType === Messages3.MarketDataIncrementalRefresh) {
|
|
1946
|
-
const symbol = message.getField(Fields3.Symbol)?.value;
|
|
1947
|
-
const fixJson = message.toFIXJSON();
|
|
1948
|
-
const entries = fixJson.Body?.NoMDEntries || [];
|
|
1949
|
-
const data = {
|
|
1950
|
-
timestamp: Date.now(),
|
|
1951
|
-
bid: 0,
|
|
1952
|
-
offer: 0,
|
|
1953
|
-
spread: 0,
|
|
1954
|
-
volume: 0,
|
|
1955
|
-
trade: 0,
|
|
1956
|
-
indexValue: 0,
|
|
1957
|
-
openingPrice: 0,
|
|
1958
|
-
closingPrice: 0,
|
|
1959
|
-
settlementPrice: 0,
|
|
1960
|
-
tradingSessionHighPrice: 0,
|
|
1961
|
-
tradingSessionLowPrice: 0,
|
|
1962
|
-
vwap: 0,
|
|
1963
|
-
imbalance: 0,
|
|
1964
|
-
openInterest: 0,
|
|
1965
|
-
compositeUnderlyingPrice: 0,
|
|
1966
|
-
simulatedSellPrice: 0,
|
|
1967
|
-
simulatedBuyPrice: 0,
|
|
1968
|
-
marginRate: 0,
|
|
1969
|
-
midPrice: 0,
|
|
1970
|
-
emptyBook: 0,
|
|
1971
|
-
settleHighPrice: 0,
|
|
1972
|
-
settleLowPrice: 0,
|
|
1973
|
-
priorSettlePrice: 0,
|
|
1974
|
-
sessionHighBid: 0,
|
|
1975
|
-
sessionLowOffer: 0,
|
|
1976
|
-
earlyPrices: 0,
|
|
1977
|
-
auctionClearingPrice: 0,
|
|
1978
|
-
swapValueFactor: 0,
|
|
1979
|
-
dailyValueAdjustmentForLongPositions: 0,
|
|
1980
|
-
cumulativeValueAdjustmentForLongPositions: 0,
|
|
1981
|
-
dailyValueAdjustmentForShortPositions: 0,
|
|
1982
|
-
cumulativeValueAdjustmentForShortPositions: 0,
|
|
1983
|
-
fixingPrice: 0,
|
|
1984
|
-
cashRate: 0,
|
|
1985
|
-
recoveryRate: 0,
|
|
1986
|
-
recoveryRateForLong: 0,
|
|
1987
|
-
recoveryRateForShort: 0,
|
|
1988
|
-
marketBid: 0,
|
|
1989
|
-
marketOffer: 0,
|
|
1990
|
-
shortSaleMinPrice: 0,
|
|
1991
|
-
previousClosingPrice: 0,
|
|
1992
|
-
thresholdLimitPriceBanding: 0,
|
|
1993
|
-
dailyFinancingValue: 0,
|
|
1994
|
-
accruedFinancingValue: 0,
|
|
1995
|
-
twap: 0
|
|
1996
|
-
};
|
|
1997
|
-
for (const entry of entries) {
|
|
1998
|
-
const entryType = entry.MDEntryType;
|
|
1999
|
-
const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
|
|
2000
|
-
const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
|
|
2001
|
-
const enumValue = getEnumValue(MDEntryType2, entryType);
|
|
2002
|
-
switch (enumValue) {
|
|
2003
|
-
case MDEntryType2.Bid:
|
|
2004
|
-
data.bid = price;
|
|
2005
|
-
break;
|
|
2006
|
-
case MDEntryType2.Offer:
|
|
2007
|
-
data.offer = price;
|
|
2008
|
-
break;
|
|
2009
|
-
case MDEntryType2.Trade:
|
|
2010
|
-
data.trade = price;
|
|
2011
|
-
break;
|
|
2012
|
-
case MDEntryType2.IndexValue:
|
|
2013
|
-
data.indexValue = price;
|
|
2014
|
-
break;
|
|
2015
|
-
case MDEntryType2.OpeningPrice:
|
|
2016
|
-
data.openingPrice = price;
|
|
2017
|
-
break;
|
|
2018
|
-
case MDEntryType2.ClosingPrice:
|
|
2019
|
-
data.closingPrice = price;
|
|
2020
|
-
break;
|
|
2021
|
-
case MDEntryType2.SettlementPrice:
|
|
2022
|
-
data.settlementPrice = price;
|
|
2023
|
-
break;
|
|
2024
|
-
case MDEntryType2.TradingSessionHighPrice:
|
|
2025
|
-
data.tradingSessionHighPrice = price;
|
|
2026
|
-
break;
|
|
2027
|
-
case MDEntryType2.TradingSessionLowPrice:
|
|
2028
|
-
data.tradingSessionLowPrice = price;
|
|
2029
|
-
break;
|
|
2030
|
-
case MDEntryType2.VWAP:
|
|
2031
|
-
data.vwap = price;
|
|
2032
|
-
break;
|
|
2033
|
-
case MDEntryType2.Imbalance:
|
|
2034
|
-
data.imbalance = size;
|
|
2035
|
-
break;
|
|
2036
|
-
case MDEntryType2.TradeVolume:
|
|
2037
|
-
data.volume = size;
|
|
2038
|
-
break;
|
|
2039
|
-
case MDEntryType2.OpenInterest:
|
|
2040
|
-
data.openInterest = size;
|
|
2041
|
-
break;
|
|
2042
|
-
case MDEntryType2.CompositeUnderlyingPrice:
|
|
2043
|
-
data.compositeUnderlyingPrice = price;
|
|
2044
|
-
break;
|
|
2045
|
-
case MDEntryType2.SimulatedSellPrice:
|
|
2046
|
-
data.simulatedSellPrice = price;
|
|
2047
|
-
break;
|
|
2048
|
-
case MDEntryType2.SimulatedBuyPrice:
|
|
2049
|
-
data.simulatedBuyPrice = price;
|
|
2050
|
-
break;
|
|
2051
|
-
case MDEntryType2.MarginRate:
|
|
2052
|
-
data.marginRate = price;
|
|
2053
|
-
break;
|
|
2054
|
-
case MDEntryType2.MidPrice:
|
|
2055
|
-
data.midPrice = price;
|
|
2056
|
-
break;
|
|
2057
|
-
case MDEntryType2.EmptyBook:
|
|
2058
|
-
data.emptyBook = 1;
|
|
2059
|
-
break;
|
|
2060
|
-
case MDEntryType2.SettleHighPrice:
|
|
2061
|
-
data.settleHighPrice = price;
|
|
2062
|
-
break;
|
|
2063
|
-
case MDEntryType2.SettleLowPrice:
|
|
2064
|
-
data.settleLowPrice = price;
|
|
2065
|
-
break;
|
|
2066
|
-
case MDEntryType2.PriorSettlePrice:
|
|
2067
|
-
data.priorSettlePrice = price;
|
|
2068
|
-
break;
|
|
2069
|
-
case MDEntryType2.SessionHighBid:
|
|
2070
|
-
data.sessionHighBid = price;
|
|
2071
|
-
break;
|
|
2072
|
-
case MDEntryType2.SessionLowOffer:
|
|
2073
|
-
data.sessionLowOffer = price;
|
|
2074
|
-
break;
|
|
2075
|
-
case MDEntryType2.EarlyPrices:
|
|
2076
|
-
data.earlyPrices = price;
|
|
2077
|
-
break;
|
|
2078
|
-
case MDEntryType2.AuctionClearingPrice:
|
|
2079
|
-
data.auctionClearingPrice = price;
|
|
2080
|
-
break;
|
|
2081
|
-
case MDEntryType2.SwapValueFactor:
|
|
2082
|
-
data.swapValueFactor = price;
|
|
2083
|
-
break;
|
|
2084
|
-
case MDEntryType2.DailyValueAdjustmentForLongPositions:
|
|
2085
|
-
data.dailyValueAdjustmentForLongPositions = price;
|
|
2086
|
-
break;
|
|
2087
|
-
case MDEntryType2.CumulativeValueAdjustmentForLongPositions:
|
|
2088
|
-
data.cumulativeValueAdjustmentForLongPositions = price;
|
|
2089
|
-
break;
|
|
2090
|
-
case MDEntryType2.DailyValueAdjustmentForShortPositions:
|
|
2091
|
-
data.dailyValueAdjustmentForShortPositions = price;
|
|
2092
|
-
break;
|
|
2093
|
-
case MDEntryType2.CumulativeValueAdjustmentForShortPositions:
|
|
2094
|
-
data.cumulativeValueAdjustmentForShortPositions = price;
|
|
2095
|
-
break;
|
|
2096
|
-
case MDEntryType2.FixingPrice:
|
|
2097
|
-
data.fixingPrice = price;
|
|
2098
|
-
break;
|
|
2099
|
-
case MDEntryType2.CashRate:
|
|
2100
|
-
data.cashRate = price;
|
|
2101
|
-
break;
|
|
2102
|
-
case MDEntryType2.RecoveryRate:
|
|
2103
|
-
data.recoveryRate = price;
|
|
2104
|
-
break;
|
|
2105
|
-
case MDEntryType2.RecoveryRateForLong:
|
|
2106
|
-
data.recoveryRateForLong = price;
|
|
2107
|
-
break;
|
|
2108
|
-
case MDEntryType2.RecoveryRateForShort:
|
|
2109
|
-
data.recoveryRateForShort = price;
|
|
2110
|
-
break;
|
|
2111
|
-
case MDEntryType2.MarketBid:
|
|
2112
|
-
data.marketBid = price;
|
|
2113
|
-
break;
|
|
2114
|
-
case MDEntryType2.MarketOffer:
|
|
2115
|
-
data.marketOffer = price;
|
|
2116
|
-
break;
|
|
2117
|
-
case MDEntryType2.ShortSaleMinPrice:
|
|
2118
|
-
data.shortSaleMinPrice = price;
|
|
2119
|
-
break;
|
|
2120
|
-
case MDEntryType2.PreviousClosingPrice:
|
|
2121
|
-
data.previousClosingPrice = price;
|
|
2122
|
-
break;
|
|
2123
|
-
case MDEntryType2.ThresholdLimitPriceBanding:
|
|
2124
|
-
data.thresholdLimitPriceBanding = price;
|
|
2125
|
-
break;
|
|
2126
|
-
case MDEntryType2.DailyFinancingValue:
|
|
2127
|
-
data.dailyFinancingValue = price;
|
|
2128
|
-
break;
|
|
2129
|
-
case MDEntryType2.AccruedFinancingValue:
|
|
2130
|
-
data.accruedFinancingValue = price;
|
|
2131
|
-
break;
|
|
2132
|
-
case MDEntryType2.TWAP:
|
|
2133
|
-
data.twap = price;
|
|
2134
|
-
break;
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
data.spread = data.offer - data.bid;
|
|
2138
|
-
if (!marketDataPrices.has(symbol)) {
|
|
2139
|
-
marketDataPrices.set(symbol, []);
|
|
2140
|
-
}
|
|
2141
|
-
const prices = marketDataPrices.get(symbol);
|
|
2142
|
-
prices.push(data);
|
|
2143
|
-
if (prices.length > maxPriceHistory) {
|
|
2144
|
-
prices.splice(0, prices.length - maxPriceHistory);
|
|
2145
|
-
}
|
|
2146
|
-
onPriceUpdate?.(symbol, data);
|
|
2147
|
-
const mdReqID = message.getField(Fields3.MDReqID)?.value;
|
|
2148
|
-
if (mdReqID) {
|
|
2149
|
-
const callback = pendingRequests.get(mdReqID);
|
|
2150
|
-
if (callback) {
|
|
2151
|
-
callback(message);
|
|
2152
|
-
pendingRequests.delete(mdReqID);
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
} else if (msgType === Messages3.ExecutionReport) {
|
|
2156
|
-
const reqId = message.getField(Fields3.ClOrdID)?.value;
|
|
2157
|
-
const callback = pendingRequests.get(reqId);
|
|
2158
|
-
if (callback) {
|
|
2159
|
-
callback(message);
|
|
2160
|
-
pendingRequests.delete(reqId);
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
|
|
2165
763
|
// src/MCPLocal.ts
|
|
2166
|
-
var MCPLocal = class
|
|
2167
|
-
|
|
2168
|
-
* Map to store verified orders before execution
|
|
2169
|
-
* @private
|
|
2170
|
-
*/
|
|
2171
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
2172
|
-
/**
|
|
2173
|
-
* Map to store pending requests and their callbacks
|
|
2174
|
-
* @private
|
|
2175
|
-
*/
|
|
2176
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
2177
|
-
/**
|
|
2178
|
-
* Map to store market data prices for each symbol
|
|
2179
|
-
* @private
|
|
2180
|
-
*/
|
|
2181
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
2182
|
-
/**
|
|
2183
|
-
* Maximum number of price history entries to keep per symbol
|
|
2184
|
-
* @private
|
|
2185
|
-
*/
|
|
2186
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
764
|
+
var MCPLocal = class {
|
|
765
|
+
parser;
|
|
2187
766
|
server = new Server(
|
|
2188
767
|
{
|
|
2189
768
|
name: "fixparser",
|
|
@@ -2205,13 +784,90 @@ var MCPLocal = class extends MCPBase {
|
|
|
2205
784
|
}
|
|
2206
785
|
);
|
|
2207
786
|
transport = new StdioServerTransport();
|
|
787
|
+
onReady = void 0;
|
|
788
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
789
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
790
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
791
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
792
|
+
// Maximum number of price points to store per symbol
|
|
2208
793
|
constructor({ logger, onReady }) {
|
|
2209
|
-
|
|
794
|
+
if (onReady) this.onReady = onReady;
|
|
2210
795
|
}
|
|
2211
796
|
async register(parser) {
|
|
2212
797
|
this.parser = parser;
|
|
2213
798
|
this.parser.addOnMessageCallback((message) => {
|
|
2214
|
-
|
|
799
|
+
this.parser?.logger.log({
|
|
800
|
+
level: "info",
|
|
801
|
+
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
802
|
+
});
|
|
803
|
+
const msgType = message.messageType;
|
|
804
|
+
if (msgType === Messages3.MarketDataSnapshotFullRefresh || msgType === Messages3.ExecutionReport || msgType === Messages3.Reject || msgType === Messages3.MarketDataIncrementalRefresh) {
|
|
805
|
+
this.parser?.logger.log({
|
|
806
|
+
level: "info",
|
|
807
|
+
message: `MCP Server handling message type: ${msgType}`
|
|
808
|
+
});
|
|
809
|
+
let id;
|
|
810
|
+
if (msgType === Messages3.MarketDataIncrementalRefresh || msgType === Messages3.MarketDataSnapshotFullRefresh) {
|
|
811
|
+
const symbol = message.getField(Fields3.Symbol);
|
|
812
|
+
const entryType = message.getField(Fields3.MDEntryType);
|
|
813
|
+
const price = message.getField(Fields3.MDEntryPx);
|
|
814
|
+
const size = message.getField(Fields3.MDEntrySize);
|
|
815
|
+
const timestamp = message.getField(Fields3.MDEntryTime)?.value || Date.now();
|
|
816
|
+
if (symbol?.value && price?.value) {
|
|
817
|
+
const symbolStr = String(symbol.value);
|
|
818
|
+
const priceNum = Number(price.value);
|
|
819
|
+
const sizeNum = size?.value ? Number(size.value) : 0;
|
|
820
|
+
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
821
|
+
const lastEntry = priceHistory[priceHistory.length - 1] || {
|
|
822
|
+
timestamp: 0,
|
|
823
|
+
bid: 0,
|
|
824
|
+
offer: 0,
|
|
825
|
+
spread: 0,
|
|
826
|
+
volume: 0
|
|
827
|
+
};
|
|
828
|
+
const newEntry = {
|
|
829
|
+
timestamp: Number(timestamp),
|
|
830
|
+
bid: entryType?.value === MDEntryType2.Bid ? priceNum : lastEntry.bid,
|
|
831
|
+
offer: entryType?.value === MDEntryType2.Offer ? priceNum : lastEntry.offer,
|
|
832
|
+
spread: entryType?.value === MDEntryType2.Offer ? priceNum - lastEntry.bid : entryType?.value === MDEntryType2.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
|
|
833
|
+
volume: entryType?.value === MDEntryType2.TradeVolume ? sizeNum : lastEntry.volume
|
|
834
|
+
};
|
|
835
|
+
priceHistory.push(newEntry);
|
|
836
|
+
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
837
|
+
priceHistory.shift();
|
|
838
|
+
}
|
|
839
|
+
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
840
|
+
this.parser?.logger.log({
|
|
841
|
+
level: "info",
|
|
842
|
+
message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
|
|
843
|
+
});
|
|
844
|
+
this.server.notification({
|
|
845
|
+
method: "priceUpdate",
|
|
846
|
+
params: {
|
|
847
|
+
symbol: symbolStr,
|
|
848
|
+
...newEntry
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (msgType === Messages3.MarketDataSnapshotFullRefresh) {
|
|
854
|
+
const mdReqID = message.getField(Fields3.MDReqID);
|
|
855
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
856
|
+
} else if (msgType === Messages3.ExecutionReport) {
|
|
857
|
+
const clOrdID = message.getField(Fields3.ClOrdID);
|
|
858
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
859
|
+
} else if (msgType === Messages3.Reject) {
|
|
860
|
+
const refSeqNum = message.getField(Fields3.RefSeqNum);
|
|
861
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
862
|
+
}
|
|
863
|
+
if (id) {
|
|
864
|
+
const callback = this.pendingRequests.get(id);
|
|
865
|
+
if (callback) {
|
|
866
|
+
callback(message);
|
|
867
|
+
this.pendingRequests.delete(id);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
2215
871
|
});
|
|
2216
872
|
this.addWorkflows();
|
|
2217
873
|
await this.server.connect(this.transport);
|
|
@@ -2226,15 +882,18 @@ var MCPLocal = class extends MCPBase {
|
|
|
2226
882
|
if (!this.server) {
|
|
2227
883
|
return;
|
|
2228
884
|
}
|
|
2229
|
-
this.server.setRequestHandler(
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
description,
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
885
|
+
this.server.setRequestHandler(
|
|
886
|
+
z.object({ method: z.literal("tools/list") }),
|
|
887
|
+
async (request, extra) => {
|
|
888
|
+
return {
|
|
889
|
+
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
890
|
+
name,
|
|
891
|
+
description,
|
|
892
|
+
inputSchema: schema
|
|
893
|
+
}))
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
);
|
|
2238
897
|
this.server.setRequestHandler(
|
|
2239
898
|
z.object({
|
|
2240
899
|
method: z.literal("tools/call"),
|
|
@@ -2246,7 +905,7 @@ var MCPLocal = class extends MCPBase {
|
|
|
2246
905
|
}).optional()
|
|
2247
906
|
})
|
|
2248
907
|
}),
|
|
2249
|
-
async (request) => {
|
|
908
|
+
async (request, extra) => {
|
|
2250
909
|
const { name, arguments: args } = request.params;
|
|
2251
910
|
const toolHandlers = createToolHandlers(
|
|
2252
911
|
this.parser,
|