fixparser-plugin-mcp 9.1.7-e016b83b → 9.1.7-e7f944da

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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/MCPLocal.ts
@@ -25,179 +35,785 @@ __export(MCPLocal_exports, {
25
35
  module.exports = __toCommonJS(MCPLocal_exports);
26
36
  var import_server = require("@modelcontextprotocol/sdk/server/index.js");
27
37
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
28
- var import_fixparser = require("fixparser");
38
+ var import_fixparser3 = require("fixparser");
29
39
  var import_zod = require("zod");
30
- var MCPLocal = class {
31
- parser;
32
- server = new import_server.Server(
33
- {
34
- name: "fixparser",
35
- version: "1.0.0"
36
- },
37
- {
38
- capabilities: {
39
- tools: {
40
- parse: {
41
- description: "Parses a FIX message and describes it in plain language",
42
- parameters: {
43
- type: "object",
44
- properties: {
45
- fixString: { type: "string" }
46
- },
47
- required: ["fixString"]
48
- }
40
+
41
+ // src/schemas/schemas.ts
42
+ var toolSchemas = {
43
+ parse: {
44
+ description: "Parses a FIX message and describes it in plain language",
45
+ schema: {
46
+ type: "object",
47
+ properties: {
48
+ fixString: { type: "string" }
49
+ },
50
+ required: ["fixString"]
51
+ }
52
+ },
53
+ parseToJSON: {
54
+ description: "Parses a FIX message into JSON",
55
+ schema: {
56
+ type: "object",
57
+ properties: {
58
+ fixString: { type: "string" }
59
+ },
60
+ required: ["fixString"]
61
+ }
62
+ },
63
+ verifyOrder: {
64
+ description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
65
+ schema: {
66
+ type: "object",
67
+ properties: {
68
+ clOrdID: { type: "string" },
69
+ handlInst: {
70
+ type: "string",
71
+ enum: ["1", "2", "3"],
72
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
73
+ },
74
+ quantity: { type: "string" },
75
+ price: { type: "string" },
76
+ ordType: {
77
+ type: "string",
78
+ enum: [
79
+ "1",
80
+ "2",
81
+ "3",
82
+ "4",
83
+ "5",
84
+ "6",
85
+ "7",
86
+ "8",
87
+ "9",
88
+ "A",
89
+ "B",
90
+ "C",
91
+ "D",
92
+ "E",
93
+ "F",
94
+ "G",
95
+ "H",
96
+ "I",
97
+ "J",
98
+ "K",
99
+ "L",
100
+ "M",
101
+ "P",
102
+ "Q",
103
+ "R",
104
+ "S"
105
+ ],
106
+ description: "Order Type: 1=Market, 2=Limit, 3=Stop, 4=StopLimit, 5=MarketOnClose, 6=WithOrWithout, 7=LimitOrBetter, 8=LimitWithOrWithout, 9=OnBasis, A=OnClose, B=LimitOnClose, C=ForexMarket, D=PreviouslyQuoted, E=PreviouslyIndicated, F=ForexLimit, G=ForexSwap, H=ForexPreviouslyQuoted, I=Funari, J=MarketIfTouched, K=MarketWithLeftOverAsLimit, L=PreviousFundValuationPoint, M=NextFundValuationPoint, P=Pegged, Q=CounterOrderSelection, R=StopOnBidOrOffer, S=StopLimitOnBidOrOffer"
107
+ },
108
+ side: {
109
+ type: "string",
110
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
111
+ description: "Side: 1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed"
112
+ },
113
+ symbol: { type: "string" },
114
+ timeInForce: {
115
+ type: "string",
116
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
117
+ description: "Time In Force: 0=Day, 1=GoodTillCancel, 2=AtTheOpening, 3=ImmediateOrCancel, 4=FillOrKill, 5=GoodTillCrossing, 6=GoodTillDate, 7=AtTheClose, 8=GoodThroughCrossing, 9=AtCrossing, A=GoodForTime, B=GoodForAuction, C=GoodForMonth"
118
+ }
119
+ },
120
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
121
+ }
122
+ },
123
+ executeOrder: {
124
+ description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
125
+ schema: {
126
+ type: "object",
127
+ properties: {
128
+ clOrdID: { type: "string" },
129
+ handlInst: {
130
+ type: "string",
131
+ enum: ["1", "2", "3"],
132
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
133
+ },
134
+ quantity: { type: "string" },
135
+ price: { type: "string" },
136
+ ordType: {
137
+ type: "string",
138
+ enum: [
139
+ "1",
140
+ "2",
141
+ "3",
142
+ "4",
143
+ "5",
144
+ "6",
145
+ "7",
146
+ "8",
147
+ "9",
148
+ "A",
149
+ "B",
150
+ "C",
151
+ "D",
152
+ "E",
153
+ "F",
154
+ "G",
155
+ "H",
156
+ "I",
157
+ "J",
158
+ "K",
159
+ "L",
160
+ "M",
161
+ "P",
162
+ "Q",
163
+ "R",
164
+ "S"
165
+ ],
166
+ description: "Order Type: 1=Market, 2=Limit, 3=Stop, 4=StopLimit, 5=MarketOnClose, 6=WithOrWithout, 7=LimitOrBetter, 8=LimitWithOrWithout, 9=OnBasis, A=OnClose, B=LimitOnClose, C=ForexMarket, D=PreviouslyQuoted, E=PreviouslyIndicated, F=ForexLimit, G=ForexSwap, H=ForexPreviouslyQuoted, I=Funari, J=MarketIfTouched, K=MarketWithLeftOverAsLimit, L=PreviousFundValuationPoint, M=NextFundValuationPoint, P=Pegged, Q=CounterOrderSelection, R=StopOnBidOrOffer, S=StopLimitOnBidOrOffer"
167
+ },
168
+ side: {
169
+ type: "string",
170
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
171
+ description: "Side: 1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed"
172
+ },
173
+ symbol: { type: "string" },
174
+ timeInForce: {
175
+ type: "string",
176
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
177
+ description: "Time In Force: 0=Day, 1=GoodTillCancel, 2=AtTheOpening, 3=ImmediateOrCancel, 4=FillOrKill, 5=GoodTillCrossing, 6=GoodTillDate, 7=AtTheClose, 8=GoodThroughCrossing, 9=AtCrossing, A=GoodForTime, B=GoodForAuction, C=GoodForMonth"
178
+ }
179
+ },
180
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
181
+ }
182
+ },
183
+ marketDataRequest: {
184
+ description: "Requests market data for specified symbols",
185
+ schema: {
186
+ type: "object",
187
+ properties: {
188
+ mdUpdateType: {
189
+ type: "string",
190
+ enum: ["0", "1"],
191
+ description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
192
+ },
193
+ symbols: { type: "array", items: { type: "string" } },
194
+ mdReqID: { type: "string" },
195
+ subscriptionRequestType: {
196
+ type: "string",
197
+ enum: ["0", "1", "2"],
198
+ description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
199
+ },
200
+ mdEntryTypes: {
201
+ type: "array",
202
+ items: {
203
+ type: "string",
204
+ enum: [
205
+ "0",
206
+ "1",
207
+ "2",
208
+ "3",
209
+ "4",
210
+ "5",
211
+ "6",
212
+ "7",
213
+ "8",
214
+ "9",
215
+ "A",
216
+ "B",
217
+ "C",
218
+ "D",
219
+ "E",
220
+ "F",
221
+ "G",
222
+ "H",
223
+ "I",
224
+ "J",
225
+ "K",
226
+ "L",
227
+ "M",
228
+ "N",
229
+ "O",
230
+ "P",
231
+ "Q",
232
+ "R",
233
+ "S",
234
+ "T",
235
+ "U",
236
+ "V",
237
+ "W",
238
+ "X",
239
+ "Y",
240
+ "Z"
241
+ ]
49
242
  },
50
- parseToJSON: {
51
- description: "Parses a FIX message into JSON",
52
- parameters: {
53
- type: "object",
54
- properties: {
55
- fixString: { type: "string" }
56
- },
57
- required: ["fixString"]
243
+ description: "Market Data Entry Types: 0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price, 5=Closing Price, 6=Settlement Price, 7=High Price, 8=Low Price, 9=Trade Volume, A=Open Interest, B=Simulated Sell Price, C=Simulated Buy Price, D=Empty Book, E=Session High Bid, F=Session Low Offer, G=Fixing Price, H=Electronic Volume, I=Threshold Limits and Price Band Variation, J=Clearing Price, K=Open Interest Change, L=Last Trade Price, M=Last Trade Volume, N=Last Trade Time, O=Last Trade Tick, P=Last Trade Exchange, Q=Last Trade ID, R=Last Trade Side, S=Last Trade Price Change, T=Last Trade Price Change Percent, U=Last Trade Price Change Basis Points, V=Last Trade Price Change Points, W=Last Trade Price Change Ticks, X=Last Trade Price Change Ticks Percent, Y=Last Trade Price Change Ticks Basis Points, Z=Last Trade Price Change Ticks Points"
244
+ }
245
+ },
246
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
247
+ }
248
+ },
249
+ getStockGraph: {
250
+ description: "Generates a price chart for a given symbol",
251
+ schema: {
252
+ type: "object",
253
+ properties: {
254
+ symbol: { type: "string" }
255
+ },
256
+ required: ["symbol"]
257
+ }
258
+ },
259
+ getStockPriceHistory: {
260
+ description: "Returns price history for a given symbol",
261
+ schema: {
262
+ type: "object",
263
+ properties: {
264
+ symbol: { type: "string" }
265
+ },
266
+ required: ["symbol"]
267
+ }
268
+ }
269
+ };
270
+
271
+ // src/tools/marketData.ts
272
+ var import_fixparser = require("fixparser");
273
+ var import_quickchart_js = __toESM(require("quickchart-js"), 1);
274
+ var createMarketDataRequestHandler = (parser, pendingRequests) => {
275
+ return async (args) => {
276
+ try {
277
+ const response = new Promise((resolve) => {
278
+ pendingRequests.set(args.mdReqID, resolve);
279
+ });
280
+ const entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
281
+ const messageFields = [
282
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
283
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
284
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
285
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
286
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
287
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
288
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
289
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
290
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
291
+ ];
292
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
293
+ args.symbols.forEach((symbol) => {
294
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
295
+ });
296
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
297
+ entryTypes.forEach((entryType) => {
298
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
299
+ });
300
+ const mdr = parser.createMessage(...messageFields);
301
+ if (!parser.connected) {
302
+ return {
303
+ content: [
304
+ {
305
+ type: "text",
306
+ text: "Error: Not connected. Ignoring message.",
307
+ uri: "marketDataRequest"
58
308
  }
59
- },
60
- verifyOrder: {
61
- description: "Verifies order parameters before execution",
62
- parameters: {
63
- type: "object",
64
- properties: {
65
- clOrdID: { type: "string" },
66
- handlInst: { type: "string", enum: ["1", "2", "3"] },
67
- quantity: { type: "string" },
68
- price: { type: "string" },
69
- ordType: {
70
- type: "string",
71
- enum: [
72
- "1",
73
- "2",
74
- "3",
75
- "4",
76
- "5",
77
- "6",
78
- "7",
79
- "8",
80
- "9",
81
- "A",
82
- "B",
83
- "C",
84
- "D",
85
- "E",
86
- "F",
87
- "G",
88
- "H",
89
- "I",
90
- "J",
91
- "K",
92
- "L",
93
- "M",
94
- "P",
95
- "Q",
96
- "R",
97
- "S"
98
- ]
99
- },
100
- side: {
101
- type: "string",
102
- enum: [
103
- "1",
104
- "2",
105
- "3",
106
- "4",
107
- "5",
108
- "6",
109
- "7",
110
- "8",
111
- "9",
112
- "A",
113
- "B",
114
- "C",
115
- "D",
116
- "E",
117
- "F",
118
- "G",
119
- "H"
120
- ]
121
- },
122
- symbol: { type: "string" },
123
- timeInForce: {
124
- type: "string",
125
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
126
- }
127
- },
128
- required: [
129
- "clOrdID",
130
- "handlInst",
131
- "quantity",
132
- "price",
133
- "ordType",
134
- "side",
135
- "symbol",
136
- "timeInForce"
137
- ]
309
+ ],
310
+ isError: true
311
+ };
312
+ }
313
+ parser.send(mdr);
314
+ const fixData = await response;
315
+ return {
316
+ content: [
317
+ {
318
+ type: "text",
319
+ text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
320
+ uri: "marketDataRequest"
321
+ }
322
+ ]
323
+ };
324
+ } catch (error) {
325
+ return {
326
+ content: [
327
+ {
328
+ type: "text",
329
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
330
+ uri: "marketDataRequest"
331
+ }
332
+ ],
333
+ isError: true
334
+ };
335
+ }
336
+ };
337
+ };
338
+ var createGetStockGraphHandler = (marketDataPrices) => {
339
+ return async (args) => {
340
+ try {
341
+ const symbol = args.symbol;
342
+ const priceHistory = marketDataPrices.get(symbol) || [];
343
+ if (priceHistory.length === 0) {
344
+ return {
345
+ content: [
346
+ {
347
+ type: "text",
348
+ text: `No price data available for ${symbol}`,
349
+ uri: "getStockGraph"
138
350
  }
139
- },
140
- executeOrder: {
141
- description: "Executes a verified order",
142
- parameters: {
143
- type: "object",
144
- properties: {
145
- clOrdID: { type: "string" },
146
- handlInst: { type: "string", enum: ["1", "2", "3"] },
147
- quantity: { type: "string" },
148
- price: { type: "string" },
149
- ordType: { type: "string" },
150
- side: { type: "string" },
151
- symbol: { type: "string" },
152
- timeInForce: { type: "string" }
153
- },
154
- required: [
155
- "clOrdID",
156
- "handlInst",
157
- "quantity",
158
- "price",
159
- "ordType",
160
- "side",
161
- "symbol",
162
- "timeInForce"
163
- ]
351
+ ]
352
+ };
353
+ }
354
+ const chart = new import_quickchart_js.default();
355
+ chart.setWidth(300);
356
+ chart.setHeight(150);
357
+ chart.setBackgroundColor("transparent");
358
+ const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
359
+ const bidData = priceHistory.map((point) => point.bid);
360
+ const offerData = priceHistory.map((point) => point.offer);
361
+ const spreadData = priceHistory.map((point) => point.spread);
362
+ const volumeData = priceHistory.map((point) => point.volume);
363
+ const config = {
364
+ type: "line",
365
+ data: {
366
+ labels,
367
+ datasets: [
368
+ {
369
+ label: "Bid",
370
+ data: bidData,
371
+ borderColor: "#28a745",
372
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
373
+ fill: false,
374
+ tension: 0.4
375
+ },
376
+ {
377
+ label: "Offer",
378
+ data: offerData,
379
+ borderColor: "#dc3545",
380
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
381
+ fill: false,
382
+ tension: 0.4
383
+ },
384
+ {
385
+ label: "Spread",
386
+ data: spreadData,
387
+ borderColor: "#6c757d",
388
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
389
+ fill: false,
390
+ tension: 0.4
391
+ },
392
+ {
393
+ label: "Volume",
394
+ data: volumeData,
395
+ borderColor: "#007bff",
396
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
397
+ fill: true,
398
+ tension: 0.4
164
399
  }
165
- },
166
- marketDataRequest: {
167
- description: "Requests market data for specified symbols",
168
- parameters: {
169
- type: "object",
170
- properties: {
171
- mdUpdateType: { type: "string", enum: ["0", "1"] },
172
- symbols: { type: "array", items: { type: "string" } },
173
- mdReqID: { type: "string" },
174
- subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
175
- mdEntryTypes: { type: "array", items: { type: "string" } }
176
- },
177
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
400
+ ]
401
+ },
402
+ options: {
403
+ responsive: true,
404
+ plugins: {
405
+ title: {
406
+ display: true,
407
+ text: `${symbol} Market Data`
178
408
  }
179
409
  },
180
- getStockGraph: {
181
- description: "Generates a price chart for a given symbol",
182
- parameters: {
183
- type: "object",
184
- properties: {
185
- symbol: { type: "string" }
186
- },
187
- required: ["symbol"]
410
+ scales: {
411
+ y: {
412
+ beginAtZero: false
188
413
  }
189
- },
190
- getStockPriceHistory: {
191
- description: "Returns price history for a given symbol",
192
- parameters: {
193
- type: "object",
194
- properties: {
195
- symbol: { type: "string" }
414
+ }
415
+ }
416
+ };
417
+ chart.setConfig(config);
418
+ const imageBuffer = await chart.toBinary();
419
+ const base64 = Buffer.from(imageBuffer).toString("base64");
420
+ return {
421
+ content: [
422
+ {
423
+ type: "resource",
424
+ resource: {
425
+ uri: "resource://graph",
426
+ mimeType: "image/png",
427
+ blob: base64
428
+ }
429
+ }
430
+ ]
431
+ };
432
+ } catch (error) {
433
+ return {
434
+ content: [
435
+ {
436
+ type: "text",
437
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
438
+ uri: "getStockGraph"
439
+ }
440
+ ],
441
+ isError: true
442
+ };
443
+ }
444
+ };
445
+ };
446
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
447
+ return async (args) => {
448
+ try {
449
+ const symbol = args.symbol;
450
+ const priceHistory = marketDataPrices.get(symbol) || [];
451
+ if (priceHistory.length === 0) {
452
+ return {
453
+ content: [
454
+ {
455
+ type: "text",
456
+ text: `No price data available for ${symbol}`,
457
+ uri: "getStockPriceHistory"
458
+ }
459
+ ]
460
+ };
461
+ }
462
+ return {
463
+ content: [
464
+ {
465
+ type: "text",
466
+ text: JSON.stringify(
467
+ {
468
+ symbol,
469
+ count: priceHistory.length,
470
+ data: priceHistory.map((point) => ({
471
+ timestamp: new Date(point.timestamp).toISOString(),
472
+ bid: point.bid,
473
+ offer: point.offer,
474
+ spread: point.spread,
475
+ volume: point.volume
476
+ }))
196
477
  },
197
- required: ["symbol"]
478
+ null,
479
+ 2
480
+ ),
481
+ uri: "getStockPriceHistory"
482
+ }
483
+ ]
484
+ };
485
+ } catch (error) {
486
+ return {
487
+ content: [
488
+ {
489
+ type: "text",
490
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
491
+ uri: "getStockPriceHistory"
492
+ }
493
+ ],
494
+ isError: true
495
+ };
496
+ }
497
+ };
498
+ };
499
+
500
+ // src/tools/order.ts
501
+ var import_fixparser2 = require("fixparser");
502
+ var ordTypeNames = {
503
+ "1": "Market",
504
+ "2": "Limit",
505
+ "3": "Stop",
506
+ "4": "StopLimit",
507
+ "5": "MarketOnClose",
508
+ "6": "WithOrWithout",
509
+ "7": "LimitOrBetter",
510
+ "8": "LimitWithOrWithout",
511
+ "9": "OnBasis",
512
+ A: "OnClose",
513
+ B: "LimitOnClose",
514
+ C: "ForexMarket",
515
+ D: "PreviouslyQuoted",
516
+ E: "PreviouslyIndicated",
517
+ F: "ForexLimit",
518
+ G: "ForexSwap",
519
+ H: "ForexPreviouslyQuoted",
520
+ I: "Funari",
521
+ J: "MarketIfTouched",
522
+ K: "MarketWithLeftOverAsLimit",
523
+ L: "PreviousFundValuationPoint",
524
+ M: "NextFundValuationPoint",
525
+ P: "Pegged",
526
+ Q: "CounterOrderSelection",
527
+ R: "StopOnBidOrOffer",
528
+ S: "StopLimitOnBidOrOffer"
529
+ };
530
+ var sideNames = {
531
+ "1": "Buy",
532
+ "2": "Sell",
533
+ "3": "BuyMinus",
534
+ "4": "SellPlus",
535
+ "5": "SellShort",
536
+ "6": "SellShortExempt",
537
+ "7": "Undisclosed",
538
+ "8": "Cross",
539
+ "9": "CrossShort",
540
+ A: "CrossShortExempt",
541
+ B: "AsDefined",
542
+ C: "Opposite",
543
+ D: "Subscribe",
544
+ E: "Redeem",
545
+ F: "Lend",
546
+ G: "Borrow",
547
+ H: "SellUndisclosed"
548
+ };
549
+ var timeInForceNames = {
550
+ "0": "Day",
551
+ "1": "GoodTillCancel",
552
+ "2": "AtTheOpening",
553
+ "3": "ImmediateOrCancel",
554
+ "4": "FillOrKill",
555
+ "5": "GoodTillCrossing",
556
+ "6": "GoodTillDate",
557
+ "7": "AtTheClose",
558
+ "8": "GoodThroughCrossing",
559
+ "9": "AtCrossing",
560
+ A: "GoodForTime",
561
+ B: "GoodForAuction",
562
+ C: "GoodForMonth"
563
+ };
564
+ var handlInstNames = {
565
+ "1": "AutomatedExecutionNoIntervention",
566
+ "2": "AutomatedExecutionInterventionOK",
567
+ "3": "ManualOrder"
568
+ };
569
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
570
+ return async (args) => {
571
+ try {
572
+ verifiedOrders.set(args.clOrdID, {
573
+ clOrdID: args.clOrdID,
574
+ handlInst: args.handlInst,
575
+ quantity: Number.parseFloat(String(args.quantity)),
576
+ price: Number.parseFloat(String(args.price)),
577
+ ordType: args.ordType,
578
+ side: args.side,
579
+ symbol: args.symbol,
580
+ timeInForce: args.timeInForce
581
+ });
582
+ return {
583
+ content: [
584
+ {
585
+ type: "text",
586
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
587
+
588
+ Parameters verified:
589
+ - ClOrdID: ${args.clOrdID}
590
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
591
+ - Quantity: ${args.quantity}
592
+ - Price: ${args.price}
593
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
594
+ - Side: ${args.side} (${sideNames[args.side]})
595
+ - Symbol: ${args.symbol}
596
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
597
+
598
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
599
+ uri: "verifyOrder"
600
+ }
601
+ ]
602
+ };
603
+ } catch (error) {
604
+ return {
605
+ content: [
606
+ {
607
+ type: "text",
608
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
609
+ uri: "verifyOrder"
610
+ }
611
+ ],
612
+ isError: true
613
+ };
614
+ }
615
+ };
616
+ };
617
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
618
+ return async (args) => {
619
+ try {
620
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
621
+ if (!verifiedOrder) {
622
+ return {
623
+ content: [
624
+ {
625
+ type: "text",
626
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
627
+ uri: "executeOrder"
198
628
  }
629
+ ],
630
+ isError: true
631
+ };
632
+ }
633
+ if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(String(args.quantity)) || verifiedOrder.price !== Number.parseFloat(String(args.price)) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
634
+ return {
635
+ content: [
636
+ {
637
+ type: "text",
638
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
639
+ uri: "executeOrder"
640
+ }
641
+ ],
642
+ isError: true
643
+ };
644
+ }
645
+ const response = new Promise((resolve) => {
646
+ pendingRequests.set(args.clOrdID, resolve);
647
+ });
648
+ const order = parser.createMessage(
649
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
650
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
651
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
652
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
653
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
654
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
655
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
656
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
657
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
658
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
659
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
660
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
661
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
662
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
663
+ );
664
+ if (!parser.connected) {
665
+ return {
666
+ content: [
667
+ {
668
+ type: "text",
669
+ text: "Error: Not connected. Ignoring message.",
670
+ uri: "executeOrder"
671
+ }
672
+ ],
673
+ isError: true
674
+ };
675
+ }
676
+ parser.send(order);
677
+ const fixData = await response;
678
+ verifiedOrders.delete(args.clOrdID);
679
+ return {
680
+ content: [
681
+ {
682
+ type: "text",
683
+ text: fixData.messageType === import_fixparser2.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
684
+ uri: "executeOrder"
199
685
  }
200
- }
686
+ ]
687
+ };
688
+ } catch (error) {
689
+ return {
690
+ content: [
691
+ {
692
+ type: "text",
693
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
694
+ uri: "executeOrder"
695
+ }
696
+ ],
697
+ isError: true
698
+ };
699
+ }
700
+ };
701
+ };
702
+
703
+ // src/tools/parse.ts
704
+ var createParseHandler = (parser) => {
705
+ return async (args) => {
706
+ try {
707
+ const parsedMessage = parser.parse(args.fixString);
708
+ if (!parsedMessage || parsedMessage.length === 0) {
709
+ return {
710
+ content: [
711
+ {
712
+ type: "text",
713
+ text: "Error: Failed to parse FIX string",
714
+ uri: "parse"
715
+ }
716
+ ],
717
+ isError: true
718
+ };
719
+ }
720
+ return {
721
+ content: [
722
+ {
723
+ type: "text",
724
+ text: `${parsedMessage[0].description}
725
+ ${parsedMessage[0].messageTypeDescription}`,
726
+ uri: "parse"
727
+ }
728
+ ]
729
+ };
730
+ } catch (error) {
731
+ return {
732
+ content: [
733
+ {
734
+ type: "text",
735
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
736
+ uri: "parse"
737
+ }
738
+ ],
739
+ isError: true
740
+ };
741
+ }
742
+ };
743
+ };
744
+
745
+ // src/tools/parseToJSON.ts
746
+ var createParseToJSONHandler = (parser) => {
747
+ return async (args) => {
748
+ try {
749
+ const parsedMessage = parser.parse(args.fixString);
750
+ if (!parsedMessage || parsedMessage.length === 0) {
751
+ return {
752
+ content: [
753
+ {
754
+ type: "text",
755
+ text: "Error: Failed to parse FIX string",
756
+ uri: "parseToJSON"
757
+ }
758
+ ],
759
+ isError: true
760
+ };
761
+ }
762
+ return {
763
+ content: [
764
+ {
765
+ type: "text",
766
+ text: `${parsedMessage[0].toFIXJSON()}`,
767
+ uri: "parseToJSON"
768
+ }
769
+ ]
770
+ };
771
+ } catch (error) {
772
+ return {
773
+ content: [
774
+ {
775
+ type: "text",
776
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
777
+ uri: "parseToJSON"
778
+ }
779
+ ],
780
+ isError: true
781
+ };
782
+ }
783
+ };
784
+ };
785
+
786
+ // src/tools/index.ts
787
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
788
+ parse: createParseHandler(parser),
789
+ parseToJSON: createParseToJSONHandler(parser),
790
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
791
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
792
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
793
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
794
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
795
+ });
796
+
797
+ // src/MCPLocal.ts
798
+ var MCPLocal = class {
799
+ parser;
800
+ server = new import_server.Server(
801
+ {
802
+ name: "fixparser",
803
+ version: "1.0.0"
804
+ },
805
+ {
806
+ capabilities: {
807
+ tools: Object.entries(toolSchemas).reduce(
808
+ (acc, [name, { description, schema }]) => {
809
+ acc[name] = {
810
+ description,
811
+ parameters: schema
812
+ };
813
+ return acc;
814
+ },
815
+ {}
816
+ )
201
817
  }
202
818
  }
203
819
  );
@@ -205,7 +821,6 @@ var MCPLocal = class {
205
821
  onReady = void 0;
206
822
  pendingRequests = /* @__PURE__ */ new Map();
207
823
  verifiedOrders = /* @__PURE__ */ new Map();
208
- // Store market data prices with timestamps
209
824
  marketDataPrices = /* @__PURE__ */ new Map();
210
825
  MAX_PRICE_HISTORY = 1e5;
211
826
  // Maximum number of price points to store per symbol
@@ -220,50 +835,63 @@ var MCPLocal = class {
220
835
  message: `MCP Server received message: ${message.messageType}: ${message.description}`
221
836
  });
222
837
  const msgType = message.messageType;
223
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
838
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
224
839
  this.parser?.logger.log({
225
840
  level: "info",
226
841
  message: `MCP Server handling message type: ${msgType}`
227
842
  });
228
843
  let id;
229
- if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
230
- const symbol = message.getField(import_fixparser.Fields.Symbol);
231
- const price = message.getField(import_fixparser.Fields.MDEntryPx);
232
- const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
844
+ if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
845
+ const symbol = message.getField(import_fixparser3.Fields.Symbol);
846
+ const entryType = message.getField(import_fixparser3.Fields.MDEntryType);
847
+ const price = message.getField(import_fixparser3.Fields.MDEntryPx);
848
+ const size = message.getField(import_fixparser3.Fields.MDEntrySize);
849
+ const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
233
850
  if (symbol?.value && price?.value) {
234
851
  const symbolStr = String(symbol.value);
235
852
  const priceNum = Number(price.value);
853
+ const sizeNum = size?.value ? Number(size.value) : 0;
236
854
  const priceHistory = this.marketDataPrices.get(symbolStr) || [];
237
- priceHistory.push({
855
+ const lastEntry = priceHistory[priceHistory.length - 1] || {
856
+ timestamp: 0,
857
+ bid: 0,
858
+ offer: 0,
859
+ spread: 0,
860
+ volume: 0
861
+ };
862
+ const newEntry = {
238
863
  timestamp: Number(timestamp),
239
- price: priceNum
240
- });
864
+ bid: entryType?.value === import_fixparser3.MDEntryType.Bid ? priceNum : lastEntry.bid,
865
+ offer: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum : lastEntry.offer,
866
+ spread: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum - lastEntry.bid : entryType?.value === import_fixparser3.MDEntryType.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
867
+ volume: entryType?.value === import_fixparser3.MDEntryType.TradeVolume ? sizeNum : lastEntry.volume
868
+ };
869
+ priceHistory.push(newEntry);
241
870
  if (priceHistory.length > this.MAX_PRICE_HISTORY) {
242
871
  priceHistory.shift();
243
872
  }
244
873
  this.marketDataPrices.set(symbolStr, priceHistory);
245
874
  this.parser?.logger.log({
246
875
  level: "info",
247
- message: `MCP Server added ${symbol}: ${priceNum}`
876
+ message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
248
877
  });
249
878
  this.server.notification({
250
879
  method: "priceUpdate",
251
880
  params: {
252
881
  symbol: symbolStr,
253
- price: priceNum,
254
- timestamp: Number(timestamp)
882
+ ...newEntry
255
883
  }
256
884
  });
257
885
  }
258
886
  }
259
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
260
- const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
887
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
888
+ const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
261
889
  if (mdReqID) id = String(mdReqID.value);
262
- } else if (msgType === import_fixparser.Messages.ExecutionReport) {
263
- const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
890
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
891
+ const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
264
892
  if (clOrdID) id = String(clOrdID.value);
265
- } else if (msgType === import_fixparser.Messages.Reject) {
266
- const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
893
+ } else if (msgType === import_fixparser3.Messages.Reject) {
894
+ const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
267
895
  if (refSeqNum) id = String(refSeqNum.value);
268
896
  }
269
897
  if (id) {
@@ -292,181 +920,11 @@ var MCPLocal = class {
292
920
  import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
293
921
  async (request, extra) => {
294
922
  return {
295
- tools: [
296
- {
297
- name: "parse",
298
- description: "Parses a FIX message and describes it in plain language",
299
- inputSchema: {
300
- type: "object",
301
- properties: {
302
- fixString: { type: "string" }
303
- },
304
- required: ["fixString"]
305
- }
306
- },
307
- {
308
- name: "parseToJSON",
309
- description: "Parses a FIX message into JSON",
310
- inputSchema: {
311
- type: "object",
312
- properties: {
313
- fixString: { type: "string" }
314
- },
315
- required: ["fixString"]
316
- }
317
- },
318
- {
319
- name: "verifyOrder",
320
- description: "Verifies order parameters before execution",
321
- inputSchema: {
322
- type: "object",
323
- properties: {
324
- clOrdID: { type: "string" },
325
- handlInst: { type: "string", enum: ["1", "2", "3"] },
326
- quantity: { type: "string" },
327
- price: { type: "string" },
328
- ordType: {
329
- type: "string",
330
- enum: [
331
- "1",
332
- "2",
333
- "3",
334
- "4",
335
- "5",
336
- "6",
337
- "7",
338
- "8",
339
- "9",
340
- "A",
341
- "B",
342
- "C",
343
- "D",
344
- "E",
345
- "F",
346
- "G",
347
- "H",
348
- "I",
349
- "J",
350
- "K",
351
- "L",
352
- "M",
353
- "P",
354
- "Q",
355
- "R",
356
- "S"
357
- ]
358
- },
359
- side: {
360
- type: "string",
361
- enum: [
362
- "1",
363
- "2",
364
- "3",
365
- "4",
366
- "5",
367
- "6",
368
- "7",
369
- "8",
370
- "9",
371
- "A",
372
- "B",
373
- "C",
374
- "D",
375
- "E",
376
- "F",
377
- "G",
378
- "H"
379
- ]
380
- },
381
- symbol: { type: "string" },
382
- timeInForce: {
383
- type: "string",
384
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
385
- }
386
- },
387
- required: [
388
- "clOrdID",
389
- "handlInst",
390
- "quantity",
391
- "price",
392
- "ordType",
393
- "side",
394
- "symbol",
395
- "timeInForce"
396
- ]
397
- }
398
- },
399
- {
400
- name: "executeOrder",
401
- description: "Executes a verified order",
402
- inputSchema: {
403
- type: "object",
404
- properties: {
405
- clOrdID: { type: "string" },
406
- handlInst: { type: "string", enum: ["1", "2", "3"] },
407
- quantity: { type: "string" },
408
- price: { type: "string" },
409
- ordType: { type: "string" },
410
- side: { type: "string" },
411
- symbol: { type: "string" },
412
- timeInForce: { type: "string" }
413
- },
414
- required: [
415
- "clOrdID",
416
- "handlInst",
417
- "quantity",
418
- "price",
419
- "ordType",
420
- "side",
421
- "symbol",
422
- "timeInForce"
423
- ]
424
- }
425
- },
426
- {
427
- name: "marketDataRequest",
428
- description: "Requests market data for specified symbols",
429
- inputSchema: {
430
- type: "object",
431
- properties: {
432
- mdUpdateType: { type: "string", enum: ["0", "1"] },
433
- symbols: { type: "array", items: { type: "string" } },
434
- mdReqID: { type: "string" },
435
- subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
436
- mdEntryTypes: { type: "array", items: { type: "string" } }
437
- },
438
- required: [
439
- "mdUpdateType",
440
- "symbols",
441
- "mdReqID",
442
- "subscriptionRequestType",
443
- "mdEntryTypes"
444
- ]
445
- }
446
- },
447
- {
448
- name: "getStockGraph",
449
- description: "Generates a price chart for a given symbol",
450
- inputSchema: {
451
- type: "object",
452
- properties: {
453
- symbol: { type: "string" }
454
- },
455
- required: ["symbol"]
456
- }
457
- },
458
- {
459
- name: "getStockPriceHistory",
460
- description: "Returns price history for a given symbol",
461
- inputSchema: {
462
- type: "object",
463
- properties: {
464
- symbol: { type: "string" }
465
- },
466
- required: ["symbol"]
467
- }
468
- }
469
- ]
923
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
924
+ name,
925
+ description,
926
+ inputSchema: schema
927
+ }))
470
928
  };
471
929
  }
472
930
  );
@@ -483,489 +941,30 @@ var MCPLocal = class {
483
941
  }),
484
942
  async (request, extra) => {
485
943
  const { name, arguments: args } = request.params;
486
- switch (name) {
487
- case "parse":
488
- try {
489
- const parsedMessage = this.parser?.parse(args.fixString);
490
- if (!parsedMessage || parsedMessage.length === 0) {
491
- return {
492
- contents: [
493
- {
494
- type: "text",
495
- text: "Error: Failed to parse FIX string",
496
- uri: "parse"
497
- }
498
- ],
499
- isError: true
500
- };
501
- }
502
- return {
503
- contents: [
504
- {
505
- type: "text",
506
- text: `${parsedMessage[0].description}
507
- ${parsedMessage[0].messageTypeDescription}`,
508
- uri: "parse"
509
- }
510
- ]
511
- };
512
- } catch (error) {
513
- return {
514
- contents: [
515
- {
516
- type: "text",
517
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
518
- uri: "parse"
519
- }
520
- ],
521
- isError: true
522
- };
523
- }
524
- case "parseToJSON":
525
- try {
526
- const parsedMessage = this.parser?.parse(args.fixString);
527
- if (!parsedMessage || parsedMessage.length === 0) {
528
- return {
529
- contents: [
530
- {
531
- type: "text",
532
- text: "Error: Failed to parse FIX string",
533
- uri: "parseToJSON"
534
- }
535
- ],
536
- isError: true
537
- };
944
+ const toolHandlers = createToolHandlers(
945
+ this.parser,
946
+ this.verifiedOrders,
947
+ this.pendingRequests,
948
+ this.marketDataPrices
949
+ );
950
+ const handler = toolHandlers[name];
951
+ if (!handler) {
952
+ return {
953
+ content: [
954
+ {
955
+ type: "text",
956
+ text: `Tool not found: ${name}`,
957
+ uri: name
538
958
  }
539
- return {
540
- contents: [
541
- {
542
- type: "text",
543
- text: `${parsedMessage[0].toFIXJSON()}`,
544
- uri: "parseToJSON"
545
- }
546
- ]
547
- };
548
- } catch (error) {
549
- return {
550
- contents: [
551
- {
552
- type: "text",
553
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
554
- uri: "parseToJSON"
555
- }
556
- ],
557
- isError: true
558
- };
559
- }
560
- case "verifyOrder":
561
- try {
562
- this.verifiedOrders.set(args.clOrdID, {
563
- clOrdID: args.clOrdID,
564
- handlInst: args.handlInst,
565
- quantity: Number.parseFloat(args.quantity),
566
- price: Number.parseFloat(args.price),
567
- ordType: args.ordType,
568
- side: args.side,
569
- symbol: args.symbol,
570
- timeInForce: args.timeInForce
571
- });
572
- const ordTypeNames = {
573
- "1": "Market",
574
- "2": "Limit",
575
- "3": "Stop",
576
- "4": "StopLimit",
577
- "5": "MarketOnClose",
578
- "6": "WithOrWithout",
579
- "7": "LimitOrBetter",
580
- "8": "LimitWithOrWithout",
581
- "9": "OnBasis",
582
- A: "OnClose",
583
- B: "LimitOnClose",
584
- C: "ForexMarket",
585
- D: "PreviouslyQuoted",
586
- E: "PreviouslyIndicated",
587
- F: "ForexLimit",
588
- G: "ForexSwap",
589
- H: "ForexPreviouslyQuoted",
590
- I: "Funari",
591
- J: "MarketIfTouched",
592
- K: "MarketWithLeftOverAsLimit",
593
- L: "PreviousFundValuationPoint",
594
- M: "NextFundValuationPoint",
595
- P: "Pegged",
596
- Q: "CounterOrderSelection",
597
- R: "StopOnBidOrOffer",
598
- S: "StopLimitOnBidOrOffer"
599
- };
600
- const sideNames = {
601
- "1": "Buy",
602
- "2": "Sell",
603
- "3": "BuyMinus",
604
- "4": "SellPlus",
605
- "5": "SellShort",
606
- "6": "SellShortExempt",
607
- "7": "Undisclosed",
608
- "8": "Cross",
609
- "9": "CrossShort",
610
- A: "CrossShortExempt",
611
- B: "AsDefined",
612
- C: "Opposite",
613
- D: "Subscribe",
614
- E: "Redeem",
615
- F: "Lend",
616
- G: "Borrow",
617
- H: "SellUndisclosed"
618
- };
619
- const timeInForceNames = {
620
- "0": "Day",
621
- "1": "GoodTillCancel",
622
- "2": "AtTheOpening",
623
- "3": "ImmediateOrCancel",
624
- "4": "FillOrKill",
625
- "5": "GoodTillCrossing",
626
- "6": "GoodTillDate",
627
- "7": "AtTheClose",
628
- "8": "GoodThroughCrossing",
629
- "9": "AtCrossing",
630
- A: "GoodForTime",
631
- B: "GoodForAuction",
632
- C: "GoodForMonth"
633
- };
634
- const handlInstNames = {
635
- "1": "AutomatedExecutionNoIntervention",
636
- "2": "AutomatedExecutionInterventionOK",
637
- "3": "ManualOrder"
638
- };
639
- return {
640
- contents: [
641
- {
642
- type: "text",
643
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
644
-
645
- Parameters verified:
646
- - ClOrdID: ${args.clOrdID}
647
- - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
648
- - Quantity: ${args.quantity}
649
- - Price: ${args.price}
650
- - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
651
- - Side: ${args.side} (${sideNames[args.side]})
652
- - Symbol: ${args.symbol}
653
- - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
654
-
655
- To execute this order, call the executeOrder tool with these exact same parameters.`,
656
- uri: "verifyOrder"
657
- }
658
- ]
659
- };
660
- } catch (error) {
661
- return {
662
- contents: [
663
- {
664
- type: "text",
665
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
666
- uri: "verifyOrder"
667
- }
668
- ],
669
- isError: true
670
- };
671
- }
672
- case "executeOrder":
673
- try {
674
- const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
675
- if (!verifiedOrder) {
676
- return {
677
- contents: [
678
- {
679
- type: "text",
680
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
681
- uri: "executeOrder"
682
- }
683
- ],
684
- isError: true
685
- };
686
- }
687
- if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
688
- return {
689
- contents: [
690
- {
691
- type: "text",
692
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
693
- uri: "executeOrder"
694
- }
695
- ],
696
- isError: true
697
- };
698
- }
699
- const response = new Promise((resolve) => {
700
- this.pendingRequests.set(args.clOrdID, resolve);
701
- });
702
- const order = this.parser?.createMessage(
703
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
704
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
705
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
706
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
707
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
708
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
709
- new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
710
- new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
711
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
712
- new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
713
- new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
714
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
715
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
716
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
717
- );
718
- if (!this.parser?.connected) {
719
- return {
720
- contents: [
721
- {
722
- type: "text",
723
- text: "Error: Not connected. Ignoring message.",
724
- uri: "executeOrder"
725
- }
726
- ],
727
- isError: true
728
- };
729
- }
730
- this.parser?.send(order);
731
- const fixData = await response;
732
- this.verifiedOrders.delete(args.clOrdID);
733
- return {
734
- contents: [
735
- {
736
- type: "text",
737
- text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
738
- uri: "executeOrder"
739
- }
740
- ]
741
- };
742
- } catch (error) {
743
- return {
744
- contents: [
745
- {
746
- type: "text",
747
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
748
- uri: "executeOrder"
749
- }
750
- ],
751
- isError: true
752
- };
753
- }
754
- case "marketDataRequest":
755
- try {
756
- const response = new Promise((resolve) => {
757
- this.pendingRequests.set(args.mdReqID, resolve);
758
- });
759
- const messageFields = [
760
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
761
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
762
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
763
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
764
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
765
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
766
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
767
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
768
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
769
- ];
770
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
771
- args.symbols.forEach((symbol) => {
772
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
773
- });
774
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
775
- args.mdEntryTypes.forEach((entryType) => {
776
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
777
- });
778
- const mdr = this.parser?.createMessage(...messageFields);
779
- if (!this.parser?.connected) {
780
- return {
781
- contents: [
782
- {
783
- type: "text",
784
- text: "Error: Not connected. Ignoring message.",
785
- uri: "marketDataRequest"
786
- }
787
- ],
788
- isError: true
789
- };
790
- }
791
- this.parser?.send(mdr);
792
- const fixData = await response;
793
- return {
794
- contents: [
795
- {
796
- type: "text",
797
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
798
- uri: "marketDataRequest"
799
- }
800
- ]
801
- };
802
- } catch (error) {
803
- return {
804
- contents: [
805
- {
806
- type: "text",
807
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
808
- uri: "marketDataRequest"
809
- }
810
- ],
811
- isError: true
812
- };
813
- }
814
- case "getStockGraph":
815
- try {
816
- const symbol = args.symbol;
817
- const priceHistory = this.marketDataPrices.get(symbol) || [];
818
- if (priceHistory.length === 0) {
819
- return {
820
- contents: [
821
- {
822
- type: "text",
823
- text: `No price data available for ${symbol}`,
824
- uri: "getStockGraph"
825
- }
826
- ]
827
- };
828
- }
829
- const width = 600;
830
- const height = 300;
831
- const padding = 40;
832
- const xScale = (width - 2 * padding) / (priceHistory.length - 1);
833
- const yMin = Math.min(...priceHistory.map((d) => d.price));
834
- const yMax = Math.max(...priceHistory.map((d) => d.price));
835
- const yScale = (height - 2 * padding) / (yMax - yMin);
836
- const points = priceHistory.map((d, i) => {
837
- const x = padding + i * xScale;
838
- const y = height - padding - (d.price - yMin) * yScale;
839
- return `${x},${y}`;
840
- }).join(" L ");
841
- const svg = `<?xml version="1.0" encoding="UTF-8"?>
842
- <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
843
- <!-- Background -->
844
- <rect width="100%" height="100%" fill="#f8f9fa"/>
845
-
846
- <!-- Grid lines -->
847
- <g stroke="#e9ecef" stroke-width="1">
848
- ${Array.from({ length: 5 }, (_, i) => {
849
- const y = padding + (height - 2 * padding) * i / 4;
850
- return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
851
- }).join("\n")}
852
- </g>
853
-
854
- <!-- Price line -->
855
- <path d="M ${points}"
856
- fill="none"
857
- stroke="#007bff"
858
- stroke-width="2"/>
859
-
860
- <!-- Data points -->
861
- ${priceHistory.map((d, i) => {
862
- const x = padding + i * xScale;
863
- const y = height - padding - (d.price - yMin) * yScale;
864
- return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
865
- }).join("\n")}
866
-
867
- <!-- Labels -->
868
- <g font-family="Arial" font-size="12" fill="#495057">
869
- ${Array.from({ length: 5 }, (_, i) => {
870
- const x = padding + (width - 2 * padding) * i / 4;
871
- const index = Math.floor((priceHistory.length - 1) * i / 4);
872
- const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
873
- return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
874
- }).join("\n")}
875
- ${Array.from({ length: 5 }, (_, i) => {
876
- const y = padding + (height - 2 * padding) * i / 4;
877
- const price = yMax - (yMax - yMin) * i / 4;
878
- return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
879
- }).join("\n")}
880
- </g>
881
-
882
- <!-- Title -->
883
- <text x="${width / 2}" y="${padding / 2}"
884
- font-family="Arial" font-size="16" font-weight="bold"
885
- text-anchor="middle" fill="#212529">
886
- ${symbol} - Price Chart (${priceHistory.length} points)
887
- </text>
888
- </svg>`;
889
- return {
890
- contents: [
891
- {
892
- type: "text",
893
- text: svg,
894
- uri: "getStockGraph"
895
- }
896
- ]
897
- };
898
- } catch (error) {
899
- return {
900
- contents: [
901
- {
902
- type: "text",
903
- text: `Error: ${error instanceof Error ? error.message : "Failed to generate stock graph"}`,
904
- uri: "getStockGraph"
905
- }
906
- ],
907
- isError: true
908
- };
909
- }
910
- case "getStockPriceHistory":
911
- try {
912
- const symbol = args.symbol;
913
- const priceHistory = this.marketDataPrices.get(symbol) || [];
914
- if (priceHistory.length === 0) {
915
- return {
916
- contents: [
917
- {
918
- type: "text",
919
- text: `No price data available for ${symbol}`,
920
- uri: "getStockPriceHistory"
921
- }
922
- ]
923
- };
924
- }
925
- return {
926
- contents: [
927
- {
928
- type: "text",
929
- text: JSON.stringify(
930
- {
931
- symbol,
932
- count: priceHistory.length,
933
- prices: priceHistory.map((point) => ({
934
- timestamp: new Date(point.timestamp).toISOString(),
935
- price: point.price
936
- }))
937
- },
938
- null,
939
- 2
940
- ),
941
- uri: "getStockPriceHistory"
942
- }
943
- ]
944
- };
945
- } catch (error) {
946
- return {
947
- contents: [
948
- {
949
- type: "text",
950
- text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
951
- uri: "getStockPriceHistory"
952
- }
953
- ],
954
- isError: true
955
- };
956
- }
957
- default:
958
- return {
959
- contents: [
960
- {
961
- type: "text",
962
- text: `Tool not found: ${name}`,
963
- uri: name
964
- }
965
- ],
966
- isError: true
967
- };
959
+ ],
960
+ isError: true
961
+ };
968
962
  }
963
+ const result = await handler(args);
964
+ return {
965
+ content: result.content,
966
+ isError: result.isError
967
+ };
969
968
  }
970
969
  );
971
970
  process.on("SIGINT", async () => {