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