fixparser-plugin-mcp 9.1.7-ff35b2c1 → 9.1.7-ff7241ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/MCPLocal.js +1315 -840
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +1315 -830
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +60 -12
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +56 -8
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +4 -5
- package/types/schemas/index.d.ts +0 -15
- package/types/schemas/schemas.d.ts +0 -168
- package/types/tools/index.d.ts +0 -17
- package/types/tools/marketData.d.ts +0 -40
- package/types/tools/order.d.ts +0 -12
- package/types/tools/parse.d.ts +0 -5
- package/types/tools/parseToJSON.d.ts +0 -5
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,767 +1,105 @@
|
|
|
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 {
|
|
4
|
+
import { Field, Fields, Messages } from "fixparser";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
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
|
-
]
|
|
208
|
-
},
|
|
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"
|
|
274
|
-
}
|
|
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"
|
|
316
|
-
}
|
|
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
|
|
365
|
-
}
|
|
366
|
-
]
|
|
367
|
-
},
|
|
368
|
-
options: {
|
|
369
|
-
responsive: true,
|
|
370
|
-
plugins: {
|
|
371
|
-
title: {
|
|
372
|
-
display: true,
|
|
373
|
-
text: `${symbol} Market Data`
|
|
374
|
-
}
|
|
375
|
-
},
|
|
376
|
-
scales: {
|
|
377
|
-
y: {
|
|
378
|
-
beginAtZero: false
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
chart.setConfig(config);
|
|
384
|
-
const imageBuffer = await chart.toBinary();
|
|
385
|
-
const base64 = imageBuffer.toString("base64");
|
|
386
|
-
return {
|
|
387
|
-
content: [
|
|
388
|
-
{
|
|
389
|
-
type: "image",
|
|
390
|
-
data: base64,
|
|
391
|
-
mimeType: "image/png",
|
|
392
|
-
metadata: {
|
|
393
|
-
width: 300,
|
|
394
|
-
height: 150
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
]
|
|
398
|
-
};
|
|
399
|
-
} catch (error) {
|
|
400
|
-
return {
|
|
401
|
-
content: [
|
|
402
|
-
{
|
|
403
|
-
type: "text",
|
|
404
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
405
|
-
uri: "getStockGraph"
|
|
406
|
-
}
|
|
407
|
-
],
|
|
408
|
-
isError: true
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
};
|
|
413
|
-
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
414
|
-
return async (args) => {
|
|
415
|
-
try {
|
|
416
|
-
const symbol = args.symbol;
|
|
417
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
418
|
-
if (priceHistory.length === 0) {
|
|
419
|
-
return {
|
|
420
|
-
content: [
|
|
421
|
-
{
|
|
422
|
-
type: "text",
|
|
423
|
-
text: `No price data available for ${symbol}`,
|
|
424
|
-
uri: "getStockPriceHistory"
|
|
425
|
-
}
|
|
426
|
-
]
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
return {
|
|
430
|
-
content: [
|
|
431
|
-
{
|
|
432
|
-
type: "text",
|
|
433
|
-
text: JSON.stringify(
|
|
434
|
-
{
|
|
435
|
-
symbol,
|
|
436
|
-
count: priceHistory.length,
|
|
437
|
-
data: priceHistory.map((point) => ({
|
|
438
|
-
timestamp: new Date(point.timestamp).toISOString(),
|
|
439
|
-
bid: point.bid,
|
|
440
|
-
offer: point.offer,
|
|
441
|
-
spread: point.spread,
|
|
442
|
-
volume: point.volume
|
|
443
|
-
}))
|
|
444
|
-
},
|
|
445
|
-
null,
|
|
446
|
-
2
|
|
447
|
-
),
|
|
448
|
-
uri: "getStockPriceHistory"
|
|
449
|
-
}
|
|
450
|
-
]
|
|
451
|
-
};
|
|
452
|
-
} catch (error) {
|
|
453
|
-
return {
|
|
454
|
-
content: [
|
|
455
|
-
{
|
|
456
|
-
type: "text",
|
|
457
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
458
|
-
uri: "getStockPriceHistory"
|
|
459
|
-
}
|
|
460
|
-
],
|
|
461
|
-
isError: true
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
};
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
// src/tools/order.ts
|
|
468
|
-
import { Field as Field2, Fields as Fields2, Messages as Messages2 } from "fixparser";
|
|
469
|
-
var ordTypeNames = {
|
|
470
|
-
"1": "Market",
|
|
471
|
-
"2": "Limit",
|
|
472
|
-
"3": "Stop",
|
|
473
|
-
"4": "StopLimit",
|
|
474
|
-
"5": "MarketOnClose",
|
|
475
|
-
"6": "WithOrWithout",
|
|
476
|
-
"7": "LimitOrBetter",
|
|
477
|
-
"8": "LimitWithOrWithout",
|
|
478
|
-
"9": "OnBasis",
|
|
479
|
-
A: "OnClose",
|
|
480
|
-
B: "LimitOnClose",
|
|
481
|
-
C: "ForexMarket",
|
|
482
|
-
D: "PreviouslyQuoted",
|
|
483
|
-
E: "PreviouslyIndicated",
|
|
484
|
-
F: "ForexLimit",
|
|
485
|
-
G: "ForexSwap",
|
|
486
|
-
H: "ForexPreviouslyQuoted",
|
|
487
|
-
I: "Funari",
|
|
488
|
-
J: "MarketIfTouched",
|
|
489
|
-
K: "MarketWithLeftOverAsLimit",
|
|
490
|
-
L: "PreviousFundValuationPoint",
|
|
491
|
-
M: "NextFundValuationPoint",
|
|
492
|
-
P: "Pegged",
|
|
493
|
-
Q: "CounterOrderSelection",
|
|
494
|
-
R: "StopOnBidOrOffer",
|
|
495
|
-
S: "StopLimitOnBidOrOffer"
|
|
496
|
-
};
|
|
497
|
-
var sideNames = {
|
|
498
|
-
"1": "Buy",
|
|
499
|
-
"2": "Sell",
|
|
500
|
-
"3": "BuyMinus",
|
|
501
|
-
"4": "SellPlus",
|
|
502
|
-
"5": "SellShort",
|
|
503
|
-
"6": "SellShortExempt",
|
|
504
|
-
"7": "Undisclosed",
|
|
505
|
-
"8": "Cross",
|
|
506
|
-
"9": "CrossShort",
|
|
507
|
-
A: "CrossShortExempt",
|
|
508
|
-
B: "AsDefined",
|
|
509
|
-
C: "Opposite",
|
|
510
|
-
D: "Subscribe",
|
|
511
|
-
E: "Redeem",
|
|
512
|
-
F: "Lend",
|
|
513
|
-
G: "Borrow",
|
|
514
|
-
H: "SellUndisclosed"
|
|
515
|
-
};
|
|
516
|
-
var timeInForceNames = {
|
|
517
|
-
"0": "Day",
|
|
518
|
-
"1": "GoodTillCancel",
|
|
519
|
-
"2": "AtTheOpening",
|
|
520
|
-
"3": "ImmediateOrCancel",
|
|
521
|
-
"4": "FillOrKill",
|
|
522
|
-
"5": "GoodTillCrossing",
|
|
523
|
-
"6": "GoodTillDate",
|
|
524
|
-
"7": "AtTheClose",
|
|
525
|
-
"8": "GoodThroughCrossing",
|
|
526
|
-
"9": "AtCrossing",
|
|
527
|
-
A: "GoodForTime",
|
|
528
|
-
B: "GoodForAuction",
|
|
529
|
-
C: "GoodForMonth"
|
|
530
|
-
};
|
|
531
|
-
var handlInstNames = {
|
|
532
|
-
"1": "AutomatedExecutionNoIntervention",
|
|
533
|
-
"2": "AutomatedExecutionInterventionOK",
|
|
534
|
-
"3": "ManualOrder"
|
|
535
|
-
};
|
|
536
|
-
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
537
|
-
return async (args) => {
|
|
538
|
-
try {
|
|
539
|
-
verifiedOrders.set(args.clOrdID, {
|
|
540
|
-
clOrdID: args.clOrdID,
|
|
541
|
-
handlInst: args.handlInst,
|
|
542
|
-
quantity: Number.parseFloat(String(args.quantity)),
|
|
543
|
-
price: Number.parseFloat(String(args.price)),
|
|
544
|
-
ordType: args.ordType,
|
|
545
|
-
side: args.side,
|
|
546
|
-
symbol: args.symbol,
|
|
547
|
-
timeInForce: args.timeInForce
|
|
548
|
-
});
|
|
549
|
-
return {
|
|
550
|
-
content: [
|
|
551
|
-
{
|
|
552
|
-
type: "text",
|
|
553
|
-
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
554
|
-
|
|
555
|
-
Parameters verified:
|
|
556
|
-
- ClOrdID: ${args.clOrdID}
|
|
557
|
-
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
558
|
-
- Quantity: ${args.quantity}
|
|
559
|
-
- Price: ${args.price}
|
|
560
|
-
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
561
|
-
- Side: ${args.side} (${sideNames[args.side]})
|
|
562
|
-
- Symbol: ${args.symbol}
|
|
563
|
-
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
564
|
-
|
|
565
|
-
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
566
|
-
uri: "verifyOrder"
|
|
567
|
-
}
|
|
568
|
-
]
|
|
569
|
-
};
|
|
570
|
-
} catch (error) {
|
|
571
|
-
return {
|
|
572
|
-
content: [
|
|
573
|
-
{
|
|
574
|
-
type: "text",
|
|
575
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
576
|
-
uri: "verifyOrder"
|
|
577
|
-
}
|
|
578
|
-
],
|
|
579
|
-
isError: true
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
};
|
|
584
|
-
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
585
|
-
return async (args) => {
|
|
586
|
-
try {
|
|
587
|
-
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
588
|
-
if (!verifiedOrder) {
|
|
589
|
-
return {
|
|
590
|
-
content: [
|
|
591
|
-
{
|
|
592
|
-
type: "text",
|
|
593
|
-
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
594
|
-
uri: "executeOrder"
|
|
595
|
-
}
|
|
596
|
-
],
|
|
597
|
-
isError: true
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
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) {
|
|
601
|
-
return {
|
|
602
|
-
content: [
|
|
603
|
-
{
|
|
604
|
-
type: "text",
|
|
605
|
-
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
606
|
-
uri: "executeOrder"
|
|
607
|
-
}
|
|
608
|
-
],
|
|
609
|
-
isError: true
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
const response = new Promise((resolve) => {
|
|
613
|
-
pendingRequests.set(args.clOrdID, resolve);
|
|
614
|
-
});
|
|
615
|
-
const order = parser.createMessage(
|
|
616
|
-
new Field2(Fields2.MsgType, Messages2.NewOrderSingle),
|
|
617
|
-
new Field2(Fields2.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
618
|
-
new Field2(Fields2.SenderCompID, parser.sender),
|
|
619
|
-
new Field2(Fields2.TargetCompID, parser.target),
|
|
620
|
-
new Field2(Fields2.SendingTime, parser.getTimestamp()),
|
|
621
|
-
new Field2(Fields2.ClOrdID, args.clOrdID),
|
|
622
|
-
new Field2(Fields2.Side, args.side),
|
|
623
|
-
new Field2(Fields2.Symbol, args.symbol),
|
|
624
|
-
new Field2(Fields2.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
625
|
-
new Field2(Fields2.Price, Number.parseFloat(String(args.price))),
|
|
626
|
-
new Field2(Fields2.OrdType, args.ordType),
|
|
627
|
-
new Field2(Fields2.HandlInst, args.handlInst),
|
|
628
|
-
new Field2(Fields2.TimeInForce, args.timeInForce),
|
|
629
|
-
new Field2(Fields2.TransactTime, parser.getTimestamp())
|
|
630
|
-
);
|
|
631
|
-
if (!parser.connected) {
|
|
632
|
-
return {
|
|
633
|
-
content: [
|
|
634
|
-
{
|
|
635
|
-
type: "text",
|
|
636
|
-
text: "Error: Not connected. Ignoring message.",
|
|
637
|
-
uri: "executeOrder"
|
|
638
|
-
}
|
|
639
|
-
],
|
|
640
|
-
isError: true
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
parser.send(order);
|
|
644
|
-
const fixData = await response;
|
|
645
|
-
verifiedOrders.delete(args.clOrdID);
|
|
646
|
-
return {
|
|
647
|
-
content: [
|
|
648
|
-
{
|
|
649
|
-
type: "text",
|
|
650
|
-
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())}`,
|
|
651
|
-
uri: "executeOrder"
|
|
652
|
-
}
|
|
653
|
-
]
|
|
654
|
-
};
|
|
655
|
-
} catch (error) {
|
|
656
|
-
return {
|
|
657
|
-
content: [
|
|
658
|
-
{
|
|
659
|
-
type: "text",
|
|
660
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
661
|
-
uri: "executeOrder"
|
|
662
|
-
}
|
|
663
|
-
],
|
|
664
|
-
isError: true
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
// src/tools/parse.ts
|
|
671
|
-
var createParseHandler = (parser) => {
|
|
672
|
-
return async (args) => {
|
|
673
|
-
try {
|
|
674
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
675
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
676
|
-
return {
|
|
677
|
-
content: [
|
|
678
|
-
{
|
|
679
|
-
type: "text",
|
|
680
|
-
text: "Error: Failed to parse FIX string",
|
|
681
|
-
uri: "parse"
|
|
682
|
-
}
|
|
683
|
-
],
|
|
684
|
-
isError: true
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
return {
|
|
688
|
-
content: [
|
|
689
|
-
{
|
|
690
|
-
type: "text",
|
|
691
|
-
text: `${parsedMessage[0].description}
|
|
692
|
-
${parsedMessage[0].messageTypeDescription}`,
|
|
693
|
-
uri: "parse"
|
|
694
|
-
}
|
|
695
|
-
]
|
|
696
|
-
};
|
|
697
|
-
} catch (error) {
|
|
698
|
-
return {
|
|
699
|
-
content: [
|
|
700
|
-
{
|
|
701
|
-
type: "text",
|
|
702
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
703
|
-
uri: "parse"
|
|
704
|
-
}
|
|
705
|
-
],
|
|
706
|
-
isError: true
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
// src/tools/parseToJSON.ts
|
|
713
|
-
var createParseToJSONHandler = (parser) => {
|
|
714
|
-
return async (args) => {
|
|
715
|
-
try {
|
|
716
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
717
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
718
|
-
return {
|
|
719
|
-
content: [
|
|
720
|
-
{
|
|
721
|
-
type: "text",
|
|
722
|
-
text: "Error: Failed to parse FIX string",
|
|
723
|
-
uri: "parseToJSON"
|
|
724
|
-
}
|
|
725
|
-
],
|
|
726
|
-
isError: true
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
return {
|
|
730
|
-
content: [
|
|
731
|
-
{
|
|
732
|
-
type: "text",
|
|
733
|
-
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
734
|
-
uri: "parseToJSON"
|
|
735
|
-
}
|
|
736
|
-
]
|
|
737
|
-
};
|
|
738
|
-
} catch (error) {
|
|
739
|
-
return {
|
|
740
|
-
content: [
|
|
741
|
-
{
|
|
742
|
-
type: "text",
|
|
743
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
744
|
-
uri: "parseToJSON"
|
|
745
|
-
}
|
|
746
|
-
],
|
|
747
|
-
isError: true
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
};
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
// src/tools/index.ts
|
|
754
|
-
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
755
|
-
parse: createParseHandler(parser),
|
|
756
|
-
parseToJSON: createParseToJSONHandler(parser),
|
|
757
|
-
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
758
|
-
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
759
|
-
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
760
|
-
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
761
|
-
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
6
|
+
var symbolSchema = z.object({
|
|
7
|
+
symbol: z.string()
|
|
8
|
+
});
|
|
9
|
+
var fixStringSchema = z.object({
|
|
10
|
+
fixString: z.string()
|
|
11
|
+
});
|
|
12
|
+
var orderSchema = z.object({
|
|
13
|
+
clOrdID: z.string(),
|
|
14
|
+
handlInst: z.enum(["1", "2", "3"]),
|
|
15
|
+
quantity: z.string(),
|
|
16
|
+
price: z.string(),
|
|
17
|
+
ordType: z.enum([
|
|
18
|
+
"1",
|
|
19
|
+
"2",
|
|
20
|
+
"3",
|
|
21
|
+
"4",
|
|
22
|
+
"5",
|
|
23
|
+
"6",
|
|
24
|
+
"7",
|
|
25
|
+
"8",
|
|
26
|
+
"9",
|
|
27
|
+
"A",
|
|
28
|
+
"B",
|
|
29
|
+
"C",
|
|
30
|
+
"D",
|
|
31
|
+
"E",
|
|
32
|
+
"F",
|
|
33
|
+
"G",
|
|
34
|
+
"H",
|
|
35
|
+
"I",
|
|
36
|
+
"J",
|
|
37
|
+
"K",
|
|
38
|
+
"L",
|
|
39
|
+
"M",
|
|
40
|
+
"P",
|
|
41
|
+
"Q",
|
|
42
|
+
"R",
|
|
43
|
+
"S"
|
|
44
|
+
]),
|
|
45
|
+
side: z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"]),
|
|
46
|
+
symbol: z.string(),
|
|
47
|
+
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"])
|
|
48
|
+
});
|
|
49
|
+
var marketDataRequestSchema = z.object({
|
|
50
|
+
mdUpdateType: z.enum(["0", "1"]),
|
|
51
|
+
symbols: z.array(z.string()),
|
|
52
|
+
mdReqID: z.string(),
|
|
53
|
+
subscriptionRequestType: z.enum(["0", "1", "2"]),
|
|
54
|
+
mdEntryTypes: z.array(
|
|
55
|
+
z.enum([
|
|
56
|
+
"0",
|
|
57
|
+
"1",
|
|
58
|
+
"2",
|
|
59
|
+
"3",
|
|
60
|
+
"4",
|
|
61
|
+
"5",
|
|
62
|
+
"6",
|
|
63
|
+
"7",
|
|
64
|
+
"8",
|
|
65
|
+
"9",
|
|
66
|
+
"A",
|
|
67
|
+
"B",
|
|
68
|
+
"C",
|
|
69
|
+
"D",
|
|
70
|
+
"E",
|
|
71
|
+
"F",
|
|
72
|
+
"G",
|
|
73
|
+
"H",
|
|
74
|
+
"J",
|
|
75
|
+
"K",
|
|
76
|
+
"L",
|
|
77
|
+
"M",
|
|
78
|
+
"N",
|
|
79
|
+
"O",
|
|
80
|
+
"P",
|
|
81
|
+
"Q",
|
|
82
|
+
"R",
|
|
83
|
+
"S",
|
|
84
|
+
"T",
|
|
85
|
+
"U",
|
|
86
|
+
"V",
|
|
87
|
+
"W",
|
|
88
|
+
"X",
|
|
89
|
+
"Y",
|
|
90
|
+
"Z",
|
|
91
|
+
"a",
|
|
92
|
+
"b",
|
|
93
|
+
"c",
|
|
94
|
+
"d",
|
|
95
|
+
"e",
|
|
96
|
+
"g",
|
|
97
|
+
"h",
|
|
98
|
+
"i",
|
|
99
|
+
"t"
|
|
100
|
+
])
|
|
101
|
+
)
|
|
762
102
|
});
|
|
763
|
-
|
|
764
|
-
// src/MCPLocal.ts
|
|
765
103
|
var MCPLocal = class {
|
|
766
104
|
parser;
|
|
767
105
|
server = new Server(
|
|
@@ -771,16 +109,176 @@ var MCPLocal = class {
|
|
|
771
109
|
},
|
|
772
110
|
{
|
|
773
111
|
capabilities: {
|
|
774
|
-
tools:
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
112
|
+
tools: {
|
|
113
|
+
parse: {
|
|
114
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
115
|
+
parameters: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
fixString: { type: "string" }
|
|
119
|
+
},
|
|
120
|
+
required: ["fixString"]
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
parseToJSON: {
|
|
124
|
+
description: "Parses a FIX message into JSON",
|
|
125
|
+
parameters: {
|
|
126
|
+
type: "object",
|
|
127
|
+
properties: {
|
|
128
|
+
fixString: { type: "string" }
|
|
129
|
+
},
|
|
130
|
+
required: ["fixString"]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
verifyOrder: {
|
|
134
|
+
description: "Verifies order parameters before execution",
|
|
135
|
+
parameters: {
|
|
136
|
+
type: "object",
|
|
137
|
+
properties: {
|
|
138
|
+
clOrdID: { type: "string" },
|
|
139
|
+
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
140
|
+
quantity: { type: "string" },
|
|
141
|
+
price: { type: "string" },
|
|
142
|
+
ordType: {
|
|
143
|
+
type: "string",
|
|
144
|
+
enum: [
|
|
145
|
+
"1",
|
|
146
|
+
"2",
|
|
147
|
+
"3",
|
|
148
|
+
"4",
|
|
149
|
+
"5",
|
|
150
|
+
"6",
|
|
151
|
+
"7",
|
|
152
|
+
"8",
|
|
153
|
+
"9",
|
|
154
|
+
"A",
|
|
155
|
+
"B",
|
|
156
|
+
"C",
|
|
157
|
+
"D",
|
|
158
|
+
"E",
|
|
159
|
+
"F",
|
|
160
|
+
"G",
|
|
161
|
+
"H",
|
|
162
|
+
"I",
|
|
163
|
+
"J",
|
|
164
|
+
"K",
|
|
165
|
+
"L",
|
|
166
|
+
"M",
|
|
167
|
+
"P",
|
|
168
|
+
"Q",
|
|
169
|
+
"R",
|
|
170
|
+
"S"
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
side: {
|
|
174
|
+
type: "string",
|
|
175
|
+
enum: [
|
|
176
|
+
"1",
|
|
177
|
+
"2",
|
|
178
|
+
"3",
|
|
179
|
+
"4",
|
|
180
|
+
"5",
|
|
181
|
+
"6",
|
|
182
|
+
"7",
|
|
183
|
+
"8",
|
|
184
|
+
"9",
|
|
185
|
+
"A",
|
|
186
|
+
"B",
|
|
187
|
+
"C",
|
|
188
|
+
"D",
|
|
189
|
+
"E",
|
|
190
|
+
"F",
|
|
191
|
+
"G",
|
|
192
|
+
"H"
|
|
193
|
+
]
|
|
194
|
+
},
|
|
195
|
+
symbol: { type: "string" },
|
|
196
|
+
timeInForce: {
|
|
197
|
+
type: "string",
|
|
198
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
required: [
|
|
202
|
+
"clOrdID",
|
|
203
|
+
"handlInst",
|
|
204
|
+
"quantity",
|
|
205
|
+
"price",
|
|
206
|
+
"ordType",
|
|
207
|
+
"side",
|
|
208
|
+
"symbol",
|
|
209
|
+
"timeInForce"
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
executeOrder: {
|
|
214
|
+
description: "Executes a verified order",
|
|
215
|
+
parameters: {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: {
|
|
218
|
+
clOrdID: { type: "string" },
|
|
219
|
+
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
220
|
+
quantity: { type: "string" },
|
|
221
|
+
price: { type: "string" },
|
|
222
|
+
ordType: { type: "string" },
|
|
223
|
+
side: { type: "string" },
|
|
224
|
+
symbol: { type: "string" },
|
|
225
|
+
timeInForce: { type: "string" }
|
|
226
|
+
},
|
|
227
|
+
required: [
|
|
228
|
+
"clOrdID",
|
|
229
|
+
"handlInst",
|
|
230
|
+
"quantity",
|
|
231
|
+
"price",
|
|
232
|
+
"ordType",
|
|
233
|
+
"side",
|
|
234
|
+
"symbol",
|
|
235
|
+
"timeInForce"
|
|
236
|
+
]
|
|
237
|
+
}
|
|
781
238
|
},
|
|
782
|
-
{
|
|
783
|
-
|
|
239
|
+
marketDataRequest: {
|
|
240
|
+
description: "Requests market data for specified symbols",
|
|
241
|
+
parameters: {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
mdUpdateType: { type: "string", enum: ["0", "1"] },
|
|
245
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
246
|
+
mdReqID: { type: "string" },
|
|
247
|
+
subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
|
|
248
|
+
mdEntryTypes: { type: "array", items: { type: "string" } }
|
|
249
|
+
},
|
|
250
|
+
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
resources: {
|
|
255
|
+
greeting: {
|
|
256
|
+
description: "A simple greeting resource",
|
|
257
|
+
uri: "greeting-resource"
|
|
258
|
+
},
|
|
259
|
+
stockGraph: {
|
|
260
|
+
description: "Generates a price chart for a given symbol",
|
|
261
|
+
uri: "stockGraph",
|
|
262
|
+
parameters: {
|
|
263
|
+
type: "object",
|
|
264
|
+
properties: {
|
|
265
|
+
symbol: { type: "string" }
|
|
266
|
+
},
|
|
267
|
+
required: ["symbol"]
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
stockPriceHistory: {
|
|
271
|
+
description: "Returns price history for a given symbol",
|
|
272
|
+
uri: "stockPriceHistory",
|
|
273
|
+
parameters: {
|
|
274
|
+
type: "object",
|
|
275
|
+
properties: {
|
|
276
|
+
symbol: { type: "string" }
|
|
277
|
+
},
|
|
278
|
+
required: ["symbol"]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
784
282
|
}
|
|
785
283
|
}
|
|
786
284
|
);
|
|
@@ -788,6 +286,7 @@ var MCPLocal = class {
|
|
|
788
286
|
onReady = void 0;
|
|
789
287
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
790
288
|
verifiedOrders = /* @__PURE__ */ new Map();
|
|
289
|
+
// Store market data prices with timestamps
|
|
791
290
|
marketDataPrices = /* @__PURE__ */ new Map();
|
|
792
291
|
MAX_PRICE_HISTORY = 1e5;
|
|
793
292
|
// Maximum number of price points to store per symbol
|
|
@@ -802,63 +301,42 @@ var MCPLocal = class {
|
|
|
802
301
|
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
803
302
|
});
|
|
804
303
|
const msgType = message.messageType;
|
|
805
|
-
if (msgType ===
|
|
304
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject || msgType === Messages.MarketDataIncrementalRefresh) {
|
|
806
305
|
this.parser?.logger.log({
|
|
807
306
|
level: "info",
|
|
808
307
|
message: `MCP Server handling message type: ${msgType}`
|
|
809
308
|
});
|
|
810
309
|
let id;
|
|
811
|
-
if (msgType ===
|
|
812
|
-
const symbol = message.getField(
|
|
813
|
-
const
|
|
814
|
-
const
|
|
815
|
-
const size = message.getField(Fields3.MDEntrySize);
|
|
816
|
-
const timestamp = message.getField(Fields3.MDEntryTime)?.value || Date.now();
|
|
310
|
+
if (msgType === Messages.MarketDataIncrementalRefresh || msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
311
|
+
const symbol = message.getField(Fields.Symbol);
|
|
312
|
+
const price = message.getField(Fields.MDEntryPx);
|
|
313
|
+
const timestamp = message.getField(Fields.MDEntryTime)?.value || Date.now();
|
|
817
314
|
if (symbol?.value && price?.value) {
|
|
818
315
|
const symbolStr = String(symbol.value);
|
|
819
316
|
const priceNum = Number(price.value);
|
|
820
|
-
const sizeNum = size?.value ? Number(size.value) : 0;
|
|
821
317
|
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
822
|
-
|
|
823
|
-
timestamp: 0,
|
|
824
|
-
bid: 0,
|
|
825
|
-
offer: 0,
|
|
826
|
-
spread: 0,
|
|
827
|
-
volume: 0
|
|
828
|
-
};
|
|
829
|
-
const newEntry = {
|
|
318
|
+
priceHistory.push({
|
|
830
319
|
timestamp: Number(timestamp),
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
spread: entryType?.value === MDEntryType2.Offer ? priceNum - lastEntry.bid : entryType?.value === MDEntryType2.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
|
|
834
|
-
volume: entryType?.value === MDEntryType2.TradeVolume ? sizeNum : lastEntry.volume
|
|
835
|
-
};
|
|
836
|
-
priceHistory.push(newEntry);
|
|
320
|
+
price: priceNum
|
|
321
|
+
});
|
|
837
322
|
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
838
323
|
priceHistory.shift();
|
|
839
324
|
}
|
|
840
325
|
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
841
326
|
this.parser?.logger.log({
|
|
842
327
|
level: "info",
|
|
843
|
-
message: `MCP Server added ${symbol}: ${
|
|
844
|
-
});
|
|
845
|
-
this.server.notification({
|
|
846
|
-
method: "priceUpdate",
|
|
847
|
-
params: {
|
|
848
|
-
symbol: symbolStr,
|
|
849
|
-
...newEntry
|
|
850
|
-
}
|
|
328
|
+
message: `MCP Server added ${symbol}: ${priceNum}`
|
|
851
329
|
});
|
|
852
330
|
}
|
|
853
331
|
}
|
|
854
|
-
if (msgType ===
|
|
855
|
-
const mdReqID = message.getField(
|
|
332
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
333
|
+
const mdReqID = message.getField(Fields.MDReqID);
|
|
856
334
|
if (mdReqID) id = String(mdReqID.value);
|
|
857
|
-
} else if (msgType ===
|
|
858
|
-
const clOrdID = message.getField(
|
|
335
|
+
} else if (msgType === Messages.ExecutionReport) {
|
|
336
|
+
const clOrdID = message.getField(Fields.ClOrdID);
|
|
859
337
|
if (clOrdID) id = String(clOrdID.value);
|
|
860
|
-
} else if (msgType ===
|
|
861
|
-
const refSeqNum = message.getField(
|
|
338
|
+
} else if (msgType === Messages.Reject) {
|
|
339
|
+
const refSeqNum = message.getField(Fields.RefSeqNum);
|
|
862
340
|
if (refSeqNum) id = String(refSeqNum.value);
|
|
863
341
|
}
|
|
864
342
|
if (id) {
|
|
@@ -883,57 +361,1064 @@ var MCPLocal = class {
|
|
|
883
361
|
if (!this.server) {
|
|
884
362
|
return;
|
|
885
363
|
}
|
|
364
|
+
this.server.setRequestHandler(
|
|
365
|
+
z.object({ method: z.literal("resources/list") }),
|
|
366
|
+
async (request, extra) => {
|
|
367
|
+
return {
|
|
368
|
+
resources: [
|
|
369
|
+
{
|
|
370
|
+
name: "greeting",
|
|
371
|
+
description: "A simple greeting resource",
|
|
372
|
+
uri: "greeting-resource"
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
name: "stockGraph",
|
|
376
|
+
description: "Generates a price chart for a given symbol",
|
|
377
|
+
uri: "stockGraph",
|
|
378
|
+
parameters: {
|
|
379
|
+
type: "object",
|
|
380
|
+
properties: {
|
|
381
|
+
symbol: { type: "string" }
|
|
382
|
+
},
|
|
383
|
+
required: ["symbol"]
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: "stockPriceHistory",
|
|
388
|
+
description: "Returns price history for a given symbol",
|
|
389
|
+
uri: "stockPriceHistory",
|
|
390
|
+
parameters: {
|
|
391
|
+
type: "object",
|
|
392
|
+
properties: {
|
|
393
|
+
symbol: { type: "string" }
|
|
394
|
+
},
|
|
395
|
+
required: ["symbol"]
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
]
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
);
|
|
886
402
|
this.server.setRequestHandler(
|
|
887
403
|
z.object({ method: z.literal("tools/list") }),
|
|
888
404
|
async (request, extra) => {
|
|
889
405
|
return {
|
|
890
|
-
tools:
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
406
|
+
tools: [
|
|
407
|
+
{
|
|
408
|
+
name: "parse",
|
|
409
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
410
|
+
inputSchema: {
|
|
411
|
+
type: "object",
|
|
412
|
+
properties: {
|
|
413
|
+
fixString: { type: "string" }
|
|
414
|
+
},
|
|
415
|
+
required: ["fixString"]
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
name: "parseToJSON",
|
|
420
|
+
description: "Parses a FIX message into JSON",
|
|
421
|
+
inputSchema: {
|
|
422
|
+
type: "object",
|
|
423
|
+
properties: {
|
|
424
|
+
fixString: { type: "string" }
|
|
425
|
+
},
|
|
426
|
+
required: ["fixString"]
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
name: "verifyOrder",
|
|
431
|
+
description: "Verifies order parameters before execution",
|
|
432
|
+
inputSchema: {
|
|
433
|
+
type: "object",
|
|
434
|
+
properties: {
|
|
435
|
+
clOrdID: { type: "string" },
|
|
436
|
+
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
437
|
+
quantity: { type: "string" },
|
|
438
|
+
price: { type: "string" },
|
|
439
|
+
ordType: {
|
|
440
|
+
type: "string",
|
|
441
|
+
enum: [
|
|
442
|
+
"1",
|
|
443
|
+
"2",
|
|
444
|
+
"3",
|
|
445
|
+
"4",
|
|
446
|
+
"5",
|
|
447
|
+
"6",
|
|
448
|
+
"7",
|
|
449
|
+
"8",
|
|
450
|
+
"9",
|
|
451
|
+
"A",
|
|
452
|
+
"B",
|
|
453
|
+
"C",
|
|
454
|
+
"D",
|
|
455
|
+
"E",
|
|
456
|
+
"F",
|
|
457
|
+
"G",
|
|
458
|
+
"H",
|
|
459
|
+
"I",
|
|
460
|
+
"J",
|
|
461
|
+
"K",
|
|
462
|
+
"L",
|
|
463
|
+
"M",
|
|
464
|
+
"P",
|
|
465
|
+
"Q",
|
|
466
|
+
"R",
|
|
467
|
+
"S"
|
|
468
|
+
]
|
|
469
|
+
},
|
|
470
|
+
side: {
|
|
471
|
+
type: "string",
|
|
472
|
+
enum: [
|
|
473
|
+
"1",
|
|
474
|
+
"2",
|
|
475
|
+
"3",
|
|
476
|
+
"4",
|
|
477
|
+
"5",
|
|
478
|
+
"6",
|
|
479
|
+
"7",
|
|
480
|
+
"8",
|
|
481
|
+
"9",
|
|
482
|
+
"A",
|
|
483
|
+
"B",
|
|
484
|
+
"C",
|
|
485
|
+
"D",
|
|
486
|
+
"E",
|
|
487
|
+
"F",
|
|
488
|
+
"G",
|
|
489
|
+
"H"
|
|
490
|
+
]
|
|
491
|
+
},
|
|
492
|
+
symbol: { type: "string" },
|
|
493
|
+
timeInForce: {
|
|
494
|
+
type: "string",
|
|
495
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
required: [
|
|
499
|
+
"clOrdID",
|
|
500
|
+
"handlInst",
|
|
501
|
+
"quantity",
|
|
502
|
+
"price",
|
|
503
|
+
"ordType",
|
|
504
|
+
"side",
|
|
505
|
+
"symbol",
|
|
506
|
+
"timeInForce"
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
name: "executeOrder",
|
|
512
|
+
description: "Executes a verified order",
|
|
513
|
+
inputSchema: {
|
|
514
|
+
type: "object",
|
|
515
|
+
properties: {
|
|
516
|
+
clOrdID: { type: "string" },
|
|
517
|
+
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
518
|
+
quantity: { type: "string" },
|
|
519
|
+
price: { type: "string" },
|
|
520
|
+
ordType: { type: "string" },
|
|
521
|
+
side: { type: "string" },
|
|
522
|
+
symbol: { type: "string" },
|
|
523
|
+
timeInForce: { type: "string" }
|
|
524
|
+
},
|
|
525
|
+
required: [
|
|
526
|
+
"clOrdID",
|
|
527
|
+
"handlInst",
|
|
528
|
+
"quantity",
|
|
529
|
+
"price",
|
|
530
|
+
"ordType",
|
|
531
|
+
"side",
|
|
532
|
+
"symbol",
|
|
533
|
+
"timeInForce"
|
|
534
|
+
]
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: "marketDataRequest",
|
|
539
|
+
description: "Requests market data for specified symbols",
|
|
540
|
+
inputSchema: {
|
|
541
|
+
type: "object",
|
|
542
|
+
properties: {
|
|
543
|
+
mdUpdateType: { type: "string", enum: ["0", "1"] },
|
|
544
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
545
|
+
mdReqID: { type: "string" },
|
|
546
|
+
subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
|
|
547
|
+
mdEntryTypes: { type: "array", items: { type: "string" } }
|
|
548
|
+
},
|
|
549
|
+
required: [
|
|
550
|
+
"mdUpdateType",
|
|
551
|
+
"symbols",
|
|
552
|
+
"mdReqID",
|
|
553
|
+
"subscriptionRequestType",
|
|
554
|
+
"mdEntryTypes"
|
|
555
|
+
]
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
]
|
|
895
559
|
};
|
|
896
560
|
}
|
|
897
561
|
);
|
|
898
562
|
this.server.setRequestHandler(
|
|
899
563
|
z.object({
|
|
900
|
-
method: z.literal("
|
|
564
|
+
method: z.literal("resources/read"),
|
|
901
565
|
params: z.object({
|
|
902
|
-
|
|
903
|
-
arguments: z.any(),
|
|
904
|
-
_meta: z.object({
|
|
905
|
-
progressToken: z.number()
|
|
906
|
-
}).optional()
|
|
566
|
+
uri: z.string()
|
|
907
567
|
})
|
|
908
568
|
}),
|
|
909
569
|
async (request, extra) => {
|
|
910
|
-
const {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
570
|
+
const { uri } = request.params;
|
|
571
|
+
switch (uri) {
|
|
572
|
+
case "greeting-resource":
|
|
573
|
+
return {
|
|
574
|
+
contents: [
|
|
575
|
+
{
|
|
576
|
+
type: "text",
|
|
577
|
+
text: "Hello, world!",
|
|
578
|
+
uri: "greeting-resource"
|
|
579
|
+
}
|
|
580
|
+
]
|
|
581
|
+
};
|
|
582
|
+
case "stockGraph":
|
|
583
|
+
return {
|
|
584
|
+
contents: [
|
|
585
|
+
{
|
|
586
|
+
type: "text",
|
|
587
|
+
text: "This resource requires a symbol parameter. Please use the stockGraph resource with a symbol parameter.",
|
|
588
|
+
uri: "stockGraph"
|
|
589
|
+
}
|
|
590
|
+
]
|
|
591
|
+
};
|
|
592
|
+
case "stockPriceHistory":
|
|
593
|
+
return {
|
|
594
|
+
contents: [
|
|
595
|
+
{
|
|
596
|
+
type: "text",
|
|
597
|
+
text: "This resource requires a symbol parameter. Please use the stockPriceHistory resource with a symbol parameter.",
|
|
598
|
+
uri: "stockPriceHistory"
|
|
599
|
+
}
|
|
600
|
+
]
|
|
601
|
+
};
|
|
602
|
+
default:
|
|
603
|
+
return {
|
|
604
|
+
contents: [
|
|
605
|
+
{
|
|
606
|
+
type: "text",
|
|
607
|
+
text: `Resource not found: ${uri}`,
|
|
608
|
+
uri
|
|
609
|
+
}
|
|
610
|
+
],
|
|
611
|
+
isError: true
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
);
|
|
616
|
+
this.server.setRequestHandler(
|
|
617
|
+
z.object({
|
|
618
|
+
method: z.literal("parse"),
|
|
619
|
+
params: fixStringSchema
|
|
620
|
+
}),
|
|
621
|
+
async (request, extra) => {
|
|
622
|
+
try {
|
|
623
|
+
const args = request.params;
|
|
624
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
625
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
626
|
+
return {
|
|
627
|
+
contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
628
|
+
isError: true
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
contents: [
|
|
633
|
+
{
|
|
634
|
+
type: "text",
|
|
635
|
+
text: `${parsedMessage[0].description}
|
|
636
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
637
|
+
}
|
|
638
|
+
]
|
|
639
|
+
};
|
|
640
|
+
} catch (error) {
|
|
641
|
+
return {
|
|
642
|
+
contents: [
|
|
643
|
+
{
|
|
644
|
+
type: "text",
|
|
645
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
646
|
+
}
|
|
647
|
+
],
|
|
648
|
+
isError: true
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
);
|
|
653
|
+
this.server.setRequestHandler(
|
|
654
|
+
z.object({
|
|
655
|
+
method: z.literal("parseToJSON"),
|
|
656
|
+
params: fixStringSchema
|
|
657
|
+
}),
|
|
658
|
+
async (request, extra) => {
|
|
659
|
+
try {
|
|
660
|
+
const args = request.params;
|
|
661
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
662
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
663
|
+
return {
|
|
664
|
+
contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
665
|
+
isError: true
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
contents: [
|
|
670
|
+
{
|
|
671
|
+
type: "text",
|
|
672
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
673
|
+
}
|
|
674
|
+
]
|
|
675
|
+
};
|
|
676
|
+
} catch (error) {
|
|
677
|
+
return {
|
|
678
|
+
contents: [
|
|
679
|
+
{
|
|
680
|
+
type: "text",
|
|
681
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
682
|
+
}
|
|
683
|
+
],
|
|
684
|
+
isError: true
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
);
|
|
689
|
+
this.server.setRequestHandler(
|
|
690
|
+
z.object({
|
|
691
|
+
method: z.literal("verifyOrder"),
|
|
692
|
+
params: orderSchema
|
|
693
|
+
}),
|
|
694
|
+
async (request, extra) => {
|
|
695
|
+
try {
|
|
696
|
+
const args = request.params;
|
|
697
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
698
|
+
clOrdID: args.clOrdID,
|
|
699
|
+
handlInst: args.handlInst,
|
|
700
|
+
quantity: Number.parseFloat(args.quantity),
|
|
701
|
+
price: Number.parseFloat(args.price),
|
|
702
|
+
ordType: args.ordType,
|
|
703
|
+
side: args.side,
|
|
704
|
+
symbol: args.symbol,
|
|
705
|
+
timeInForce: args.timeInForce
|
|
706
|
+
});
|
|
707
|
+
const ordTypeNames = {
|
|
708
|
+
"1": "Market",
|
|
709
|
+
"2": "Limit",
|
|
710
|
+
"3": "Stop",
|
|
711
|
+
"4": "StopLimit",
|
|
712
|
+
"5": "MarketOnClose",
|
|
713
|
+
"6": "WithOrWithout",
|
|
714
|
+
"7": "LimitOrBetter",
|
|
715
|
+
"8": "LimitWithOrWithout",
|
|
716
|
+
"9": "OnBasis",
|
|
717
|
+
A: "OnClose",
|
|
718
|
+
B: "LimitOnClose",
|
|
719
|
+
C: "ForexMarket",
|
|
720
|
+
D: "PreviouslyQuoted",
|
|
721
|
+
E: "PreviouslyIndicated",
|
|
722
|
+
F: "ForexLimit",
|
|
723
|
+
G: "ForexSwap",
|
|
724
|
+
H: "ForexPreviouslyQuoted",
|
|
725
|
+
I: "Funari",
|
|
726
|
+
J: "MarketIfTouched",
|
|
727
|
+
K: "MarketWithLeftOverAsLimit",
|
|
728
|
+
L: "PreviousFundValuationPoint",
|
|
729
|
+
M: "NextFundValuationPoint",
|
|
730
|
+
P: "Pegged",
|
|
731
|
+
Q: "CounterOrderSelection",
|
|
732
|
+
R: "StopOnBidOrOffer",
|
|
733
|
+
S: "StopLimitOnBidOrOffer"
|
|
734
|
+
};
|
|
735
|
+
const sideNames = {
|
|
736
|
+
"1": "Buy",
|
|
737
|
+
"2": "Sell",
|
|
738
|
+
"3": "BuyMinus",
|
|
739
|
+
"4": "SellPlus",
|
|
740
|
+
"5": "SellShort",
|
|
741
|
+
"6": "SellShortExempt",
|
|
742
|
+
"7": "Undisclosed",
|
|
743
|
+
"8": "Cross",
|
|
744
|
+
"9": "CrossShort",
|
|
745
|
+
A: "CrossShortExempt",
|
|
746
|
+
B: "AsDefined",
|
|
747
|
+
C: "Opposite",
|
|
748
|
+
D: "Subscribe",
|
|
749
|
+
E: "Redeem",
|
|
750
|
+
F: "Lend",
|
|
751
|
+
G: "Borrow",
|
|
752
|
+
H: "SellUndisclosed"
|
|
753
|
+
};
|
|
754
|
+
const timeInForceNames = {
|
|
755
|
+
"0": "Day",
|
|
756
|
+
"1": "GoodTillCancel",
|
|
757
|
+
"2": "AtTheOpening",
|
|
758
|
+
"3": "ImmediateOrCancel",
|
|
759
|
+
"4": "FillOrKill",
|
|
760
|
+
"5": "GoodTillCrossing",
|
|
761
|
+
"6": "GoodTillDate",
|
|
762
|
+
"7": "AtTheClose",
|
|
763
|
+
"8": "GoodThroughCrossing",
|
|
764
|
+
"9": "AtCrossing",
|
|
765
|
+
A: "GoodForTime",
|
|
766
|
+
B: "GoodForAuction",
|
|
767
|
+
C: "GoodForMonth"
|
|
768
|
+
};
|
|
769
|
+
const handlInstNames = {
|
|
770
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
771
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
772
|
+
"3": "ManualOrder"
|
|
773
|
+
};
|
|
774
|
+
return {
|
|
775
|
+
contents: [
|
|
776
|
+
{
|
|
777
|
+
type: "text",
|
|
778
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
779
|
+
|
|
780
|
+
Parameters verified:
|
|
781
|
+
- ClOrdID: ${args.clOrdID}
|
|
782
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
783
|
+
- Quantity: ${args.quantity}
|
|
784
|
+
- Price: ${args.price}
|
|
785
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
786
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
787
|
+
- Symbol: ${args.symbol}
|
|
788
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
789
|
+
|
|
790
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
791
|
+
}
|
|
792
|
+
]
|
|
793
|
+
};
|
|
794
|
+
} catch (error) {
|
|
795
|
+
return {
|
|
796
|
+
contents: [
|
|
797
|
+
{
|
|
798
|
+
type: "text",
|
|
799
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
800
|
+
}
|
|
801
|
+
],
|
|
802
|
+
isError: true
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
this.server.setRequestHandler(
|
|
808
|
+
z.object({
|
|
809
|
+
method: z.literal("executeOrder"),
|
|
810
|
+
params: orderSchema
|
|
811
|
+
}),
|
|
812
|
+
async (request, extra) => {
|
|
813
|
+
try {
|
|
814
|
+
const args = request.params;
|
|
815
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
816
|
+
if (!verifiedOrder) {
|
|
817
|
+
return {
|
|
818
|
+
contents: [
|
|
819
|
+
{
|
|
820
|
+
type: "text",
|
|
821
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
822
|
+
}
|
|
823
|
+
],
|
|
824
|
+
isError: true
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
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) {
|
|
828
|
+
return {
|
|
829
|
+
contents: [
|
|
830
|
+
{
|
|
831
|
+
type: "text",
|
|
832
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
833
|
+
}
|
|
834
|
+
],
|
|
835
|
+
isError: true
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
const response = new Promise((resolve) => {
|
|
839
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
840
|
+
});
|
|
841
|
+
const order = this.parser?.createMessage(
|
|
842
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
843
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
844
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
845
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
846
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
847
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
848
|
+
new Field(Fields.Side, args.side),
|
|
849
|
+
new Field(Fields.Symbol, args.symbol),
|
|
850
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
851
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
852
|
+
new Field(Fields.OrdType, args.ordType),
|
|
853
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
854
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
855
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
856
|
+
);
|
|
857
|
+
if (!this.parser?.connected) {
|
|
858
|
+
return {
|
|
859
|
+
contents: [
|
|
860
|
+
{
|
|
861
|
+
type: "text",
|
|
862
|
+
text: "Error: Not connected. Ignoring message."
|
|
863
|
+
}
|
|
864
|
+
],
|
|
865
|
+
isError: true
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
this.parser?.send(order);
|
|
869
|
+
const fixData = await response;
|
|
870
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
871
|
+
return {
|
|
872
|
+
contents: [
|
|
873
|
+
{
|
|
874
|
+
type: "text",
|
|
875
|
+
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())}`
|
|
876
|
+
}
|
|
877
|
+
]
|
|
878
|
+
};
|
|
879
|
+
} catch (error) {
|
|
880
|
+
return {
|
|
881
|
+
contents: [
|
|
882
|
+
{
|
|
883
|
+
type: "text",
|
|
884
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
885
|
+
}
|
|
886
|
+
],
|
|
887
|
+
isError: true
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
);
|
|
892
|
+
this.server.setRequestHandler(
|
|
893
|
+
z.object({
|
|
894
|
+
method: z.literal("marketDataRequest"),
|
|
895
|
+
params: marketDataRequestSchema
|
|
896
|
+
}),
|
|
897
|
+
async (request, extra) => {
|
|
898
|
+
try {
|
|
899
|
+
const args = request.params;
|
|
900
|
+
const response = new Promise((resolve) => {
|
|
901
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
902
|
+
});
|
|
903
|
+
const messageFields = [
|
|
904
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
905
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
906
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
907
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
908
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
909
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
910
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
911
|
+
new Field(Fields.MarketDepth, 0),
|
|
912
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
913
|
+
];
|
|
914
|
+
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
915
|
+
args.symbols.forEach((symbol) => {
|
|
916
|
+
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
917
|
+
});
|
|
918
|
+
messageFields.push(new Field(Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
919
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
920
|
+
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
921
|
+
});
|
|
922
|
+
const mdr = this.parser?.createMessage(...messageFields);
|
|
923
|
+
if (!this.parser?.connected) {
|
|
924
|
+
return {
|
|
925
|
+
contents: [
|
|
926
|
+
{
|
|
927
|
+
type: "text",
|
|
928
|
+
text: "Error: Not connected. Ignoring message."
|
|
929
|
+
}
|
|
930
|
+
],
|
|
931
|
+
isError: true
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
this.parser?.send(mdr);
|
|
935
|
+
const fixData = await response;
|
|
919
936
|
return {
|
|
920
|
-
|
|
937
|
+
contents: [
|
|
921
938
|
{
|
|
922
939
|
type: "text",
|
|
923
|
-
text: `
|
|
924
|
-
|
|
940
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
941
|
+
}
|
|
942
|
+
]
|
|
943
|
+
};
|
|
944
|
+
} catch (error) {
|
|
945
|
+
return {
|
|
946
|
+
contents: [
|
|
947
|
+
{
|
|
948
|
+
type: "text",
|
|
949
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
925
950
|
}
|
|
926
951
|
],
|
|
927
952
|
isError: true
|
|
928
953
|
};
|
|
929
954
|
}
|
|
930
|
-
|
|
955
|
+
}
|
|
956
|
+
);
|
|
957
|
+
this.server.setRequestHandler(
|
|
958
|
+
z.object({
|
|
959
|
+
method: z.literal("stockGraph"),
|
|
960
|
+
params: symbolSchema
|
|
961
|
+
}),
|
|
962
|
+
async (request, extra) => {
|
|
963
|
+
this.parser?.logger.log({
|
|
964
|
+
level: "info",
|
|
965
|
+
message: "MCP Server Resource called: stockGraph"
|
|
966
|
+
});
|
|
967
|
+
const args = request.params;
|
|
968
|
+
const symbol = args.symbol;
|
|
969
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
970
|
+
if (priceHistory.length === 0) {
|
|
971
|
+
return {
|
|
972
|
+
contents: [
|
|
973
|
+
{
|
|
974
|
+
type: "text",
|
|
975
|
+
text: `No price data available for ${symbol}`
|
|
976
|
+
}
|
|
977
|
+
]
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
const width = 600;
|
|
981
|
+
const height = 300;
|
|
982
|
+
const padding = 40;
|
|
983
|
+
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
984
|
+
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
985
|
+
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
986
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
987
|
+
const points = priceHistory.map((d, i) => {
|
|
988
|
+
const x = padding + i * xScale;
|
|
989
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
990
|
+
return `${x},${y}`;
|
|
991
|
+
}).join(" L ");
|
|
992
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
993
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
994
|
+
<!-- Background -->
|
|
995
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
996
|
+
|
|
997
|
+
<!-- Grid lines -->
|
|
998
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
999
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
1000
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
1001
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
1002
|
+
}).join("\n")}
|
|
1003
|
+
</g>
|
|
1004
|
+
|
|
1005
|
+
<!-- Price line -->
|
|
1006
|
+
<path d="M ${points}"
|
|
1007
|
+
fill="none"
|
|
1008
|
+
stroke="#007bff"
|
|
1009
|
+
stroke-width="2"/>
|
|
1010
|
+
|
|
1011
|
+
<!-- Data points -->
|
|
1012
|
+
${priceHistory.map((d, i) => {
|
|
1013
|
+
const x = padding + i * xScale;
|
|
1014
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
1015
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
1016
|
+
}).join("\n")}
|
|
1017
|
+
|
|
1018
|
+
<!-- Labels -->
|
|
1019
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
1020
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
1021
|
+
const x = padding + (width - 2 * padding) * i / 4;
|
|
1022
|
+
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
1023
|
+
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
1024
|
+
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
1025
|
+
}).join("\n")}
|
|
1026
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
1027
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
1028
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
1029
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
1030
|
+
}).join("\n")}
|
|
1031
|
+
</g>
|
|
1032
|
+
|
|
1033
|
+
<!-- Title -->
|
|
1034
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
1035
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
1036
|
+
text-anchor="middle" fill="#212529">
|
|
1037
|
+
${symbol} - Price Chart (${priceHistory.length} points)
|
|
1038
|
+
</text>
|
|
1039
|
+
</svg>`;
|
|
1040
|
+
return {
|
|
1041
|
+
contents: [
|
|
1042
|
+
{
|
|
1043
|
+
type: "text",
|
|
1044
|
+
text: svg
|
|
1045
|
+
}
|
|
1046
|
+
]
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
);
|
|
1050
|
+
this.server.setRequestHandler(
|
|
1051
|
+
z.object({
|
|
1052
|
+
method: z.literal("stockPriceHistory"),
|
|
1053
|
+
params: symbolSchema
|
|
1054
|
+
}),
|
|
1055
|
+
async (request, extra) => {
|
|
1056
|
+
this.parser?.logger.log({
|
|
1057
|
+
level: "info",
|
|
1058
|
+
message: "MCP Server Resource called: stockPriceHistory"
|
|
1059
|
+
});
|
|
1060
|
+
const args = request.params;
|
|
1061
|
+
const symbol = args.symbol;
|
|
1062
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
1063
|
+
if (priceHistory.length === 0) {
|
|
1064
|
+
return {
|
|
1065
|
+
contents: [
|
|
1066
|
+
{
|
|
1067
|
+
type: "text",
|
|
1068
|
+
text: `No price data available for ${symbol}`
|
|
1069
|
+
}
|
|
1070
|
+
]
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
931
1073
|
return {
|
|
932
|
-
|
|
933
|
-
|
|
1074
|
+
contents: [
|
|
1075
|
+
{
|
|
1076
|
+
type: "text",
|
|
1077
|
+
text: JSON.stringify(
|
|
1078
|
+
{
|
|
1079
|
+
symbol,
|
|
1080
|
+
count: priceHistory.length,
|
|
1081
|
+
prices: priceHistory.map((point) => ({
|
|
1082
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
1083
|
+
price: point.price
|
|
1084
|
+
}))
|
|
1085
|
+
},
|
|
1086
|
+
null,
|
|
1087
|
+
2
|
|
1088
|
+
)
|
|
1089
|
+
}
|
|
1090
|
+
]
|
|
934
1091
|
};
|
|
935
1092
|
}
|
|
936
1093
|
);
|
|
1094
|
+
this.server.setRequestHandler(
|
|
1095
|
+
z.object({
|
|
1096
|
+
method: z.literal("tools/call"),
|
|
1097
|
+
params: z.object({
|
|
1098
|
+
name: z.string(),
|
|
1099
|
+
arguments: z.record(z.any()),
|
|
1100
|
+
_meta: z.object({
|
|
1101
|
+
progressToken: z.number()
|
|
1102
|
+
}).optional()
|
|
1103
|
+
})
|
|
1104
|
+
}),
|
|
1105
|
+
async (request, extra) => {
|
|
1106
|
+
const { name, arguments: args } = request.params;
|
|
1107
|
+
switch (name) {
|
|
1108
|
+
case "parse":
|
|
1109
|
+
try {
|
|
1110
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
1111
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1112
|
+
return {
|
|
1113
|
+
contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
1114
|
+
isError: true
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
return {
|
|
1118
|
+
contents: [
|
|
1119
|
+
{
|
|
1120
|
+
type: "text",
|
|
1121
|
+
text: `${parsedMessage[0].description}
|
|
1122
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
1123
|
+
}
|
|
1124
|
+
]
|
|
1125
|
+
};
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
return {
|
|
1128
|
+
contents: [
|
|
1129
|
+
{
|
|
1130
|
+
type: "text",
|
|
1131
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
1132
|
+
}
|
|
1133
|
+
],
|
|
1134
|
+
isError: true
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
case "parseToJSON":
|
|
1138
|
+
try {
|
|
1139
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
1140
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1141
|
+
return {
|
|
1142
|
+
contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
1143
|
+
isError: true
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
contents: [
|
|
1148
|
+
{
|
|
1149
|
+
type: "text",
|
|
1150
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
1151
|
+
}
|
|
1152
|
+
]
|
|
1153
|
+
};
|
|
1154
|
+
} catch (error) {
|
|
1155
|
+
return {
|
|
1156
|
+
contents: [
|
|
1157
|
+
{
|
|
1158
|
+
type: "text",
|
|
1159
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
1160
|
+
}
|
|
1161
|
+
],
|
|
1162
|
+
isError: true
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
case "verifyOrder":
|
|
1166
|
+
try {
|
|
1167
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
1168
|
+
clOrdID: args.clOrdID,
|
|
1169
|
+
handlInst: args.handlInst,
|
|
1170
|
+
quantity: Number.parseFloat(args.quantity),
|
|
1171
|
+
price: Number.parseFloat(args.price),
|
|
1172
|
+
ordType: args.ordType,
|
|
1173
|
+
side: args.side,
|
|
1174
|
+
symbol: args.symbol,
|
|
1175
|
+
timeInForce: args.timeInForce
|
|
1176
|
+
});
|
|
1177
|
+
const ordTypeNames = {
|
|
1178
|
+
"1": "Market",
|
|
1179
|
+
"2": "Limit",
|
|
1180
|
+
"3": "Stop",
|
|
1181
|
+
"4": "StopLimit",
|
|
1182
|
+
"5": "MarketOnClose",
|
|
1183
|
+
"6": "WithOrWithout",
|
|
1184
|
+
"7": "LimitOrBetter",
|
|
1185
|
+
"8": "LimitWithOrWithout",
|
|
1186
|
+
"9": "OnBasis",
|
|
1187
|
+
A: "OnClose",
|
|
1188
|
+
B: "LimitOnClose",
|
|
1189
|
+
C: "ForexMarket",
|
|
1190
|
+
D: "PreviouslyQuoted",
|
|
1191
|
+
E: "PreviouslyIndicated",
|
|
1192
|
+
F: "ForexLimit",
|
|
1193
|
+
G: "ForexSwap",
|
|
1194
|
+
H: "ForexPreviouslyQuoted",
|
|
1195
|
+
I: "Funari",
|
|
1196
|
+
J: "MarketIfTouched",
|
|
1197
|
+
K: "MarketWithLeftOverAsLimit",
|
|
1198
|
+
L: "PreviousFundValuationPoint",
|
|
1199
|
+
M: "NextFundValuationPoint",
|
|
1200
|
+
P: "Pegged",
|
|
1201
|
+
Q: "CounterOrderSelection",
|
|
1202
|
+
R: "StopOnBidOrOffer",
|
|
1203
|
+
S: "StopLimitOnBidOrOffer"
|
|
1204
|
+
};
|
|
1205
|
+
const sideNames = {
|
|
1206
|
+
"1": "Buy",
|
|
1207
|
+
"2": "Sell",
|
|
1208
|
+
"3": "BuyMinus",
|
|
1209
|
+
"4": "SellPlus",
|
|
1210
|
+
"5": "SellShort",
|
|
1211
|
+
"6": "SellShortExempt",
|
|
1212
|
+
"7": "Undisclosed",
|
|
1213
|
+
"8": "Cross",
|
|
1214
|
+
"9": "CrossShort",
|
|
1215
|
+
A: "CrossShortExempt",
|
|
1216
|
+
B: "AsDefined",
|
|
1217
|
+
C: "Opposite",
|
|
1218
|
+
D: "Subscribe",
|
|
1219
|
+
E: "Redeem",
|
|
1220
|
+
F: "Lend",
|
|
1221
|
+
G: "Borrow",
|
|
1222
|
+
H: "SellUndisclosed"
|
|
1223
|
+
};
|
|
1224
|
+
const timeInForceNames = {
|
|
1225
|
+
"0": "Day",
|
|
1226
|
+
"1": "GoodTillCancel",
|
|
1227
|
+
"2": "AtTheOpening",
|
|
1228
|
+
"3": "ImmediateOrCancel",
|
|
1229
|
+
"4": "FillOrKill",
|
|
1230
|
+
"5": "GoodTillCrossing",
|
|
1231
|
+
"6": "GoodTillDate",
|
|
1232
|
+
"7": "AtTheClose",
|
|
1233
|
+
"8": "GoodThroughCrossing",
|
|
1234
|
+
"9": "AtCrossing",
|
|
1235
|
+
A: "GoodForTime",
|
|
1236
|
+
B: "GoodForAuction",
|
|
1237
|
+
C: "GoodForMonth"
|
|
1238
|
+
};
|
|
1239
|
+
const handlInstNames = {
|
|
1240
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
1241
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
1242
|
+
"3": "ManualOrder"
|
|
1243
|
+
};
|
|
1244
|
+
return {
|
|
1245
|
+
contents: [
|
|
1246
|
+
{
|
|
1247
|
+
type: "text",
|
|
1248
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
1249
|
+
|
|
1250
|
+
Parameters verified:
|
|
1251
|
+
- ClOrdID: ${args.clOrdID}
|
|
1252
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
1253
|
+
- Quantity: ${args.quantity}
|
|
1254
|
+
- Price: ${args.price}
|
|
1255
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
1256
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
1257
|
+
- Symbol: ${args.symbol}
|
|
1258
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
1259
|
+
|
|
1260
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
1261
|
+
}
|
|
1262
|
+
]
|
|
1263
|
+
};
|
|
1264
|
+
} catch (error) {
|
|
1265
|
+
return {
|
|
1266
|
+
contents: [
|
|
1267
|
+
{
|
|
1268
|
+
type: "text",
|
|
1269
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
1270
|
+
}
|
|
1271
|
+
],
|
|
1272
|
+
isError: true
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
case "executeOrder":
|
|
1276
|
+
try {
|
|
1277
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
1278
|
+
if (!verifiedOrder) {
|
|
1279
|
+
return {
|
|
1280
|
+
contents: [
|
|
1281
|
+
{
|
|
1282
|
+
type: "text",
|
|
1283
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
1284
|
+
}
|
|
1285
|
+
],
|
|
1286
|
+
isError: true
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
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) {
|
|
1290
|
+
return {
|
|
1291
|
+
contents: [
|
|
1292
|
+
{
|
|
1293
|
+
type: "text",
|
|
1294
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
1295
|
+
}
|
|
1296
|
+
],
|
|
1297
|
+
isError: true
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
const response = new Promise((resolve) => {
|
|
1301
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
1302
|
+
});
|
|
1303
|
+
const order = this.parser?.createMessage(
|
|
1304
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
1305
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1306
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1307
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1308
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1309
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
1310
|
+
new Field(Fields.Side, args.side),
|
|
1311
|
+
new Field(Fields.Symbol, args.symbol),
|
|
1312
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
1313
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
1314
|
+
new Field(Fields.OrdType, args.ordType),
|
|
1315
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
1316
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
1317
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
1318
|
+
);
|
|
1319
|
+
if (!this.parser?.connected) {
|
|
1320
|
+
return {
|
|
1321
|
+
contents: [
|
|
1322
|
+
{
|
|
1323
|
+
type: "text",
|
|
1324
|
+
text: "Error: Not connected. Ignoring message."
|
|
1325
|
+
}
|
|
1326
|
+
],
|
|
1327
|
+
isError: true
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
this.parser?.send(order);
|
|
1331
|
+
const fixData = await response;
|
|
1332
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
1333
|
+
return {
|
|
1334
|
+
contents: [
|
|
1335
|
+
{
|
|
1336
|
+
type: "text",
|
|
1337
|
+
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())}`
|
|
1338
|
+
}
|
|
1339
|
+
]
|
|
1340
|
+
};
|
|
1341
|
+
} catch (error) {
|
|
1342
|
+
return {
|
|
1343
|
+
contents: [
|
|
1344
|
+
{
|
|
1345
|
+
type: "text",
|
|
1346
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
1347
|
+
}
|
|
1348
|
+
],
|
|
1349
|
+
isError: true
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
case "marketDataRequest":
|
|
1353
|
+
try {
|
|
1354
|
+
const response = new Promise((resolve) => {
|
|
1355
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
1356
|
+
});
|
|
1357
|
+
const messageFields = [
|
|
1358
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
1359
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1360
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1361
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1362
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1363
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
1364
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
1365
|
+
new Field(Fields.MarketDepth, 0),
|
|
1366
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
1367
|
+
];
|
|
1368
|
+
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
1369
|
+
args.symbols.forEach((symbol) => {
|
|
1370
|
+
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
1371
|
+
});
|
|
1372
|
+
messageFields.push(new Field(Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
1373
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
1374
|
+
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
1375
|
+
});
|
|
1376
|
+
const mdr = this.parser?.createMessage(...messageFields);
|
|
1377
|
+
if (!this.parser?.connected) {
|
|
1378
|
+
return {
|
|
1379
|
+
contents: [
|
|
1380
|
+
{
|
|
1381
|
+
type: "text",
|
|
1382
|
+
text: "Error: Not connected. Ignoring message."
|
|
1383
|
+
}
|
|
1384
|
+
],
|
|
1385
|
+
isError: true
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
this.parser?.send(mdr);
|
|
1389
|
+
const fixData = await response;
|
|
1390
|
+
return {
|
|
1391
|
+
contents: [
|
|
1392
|
+
{
|
|
1393
|
+
type: "text",
|
|
1394
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
1395
|
+
}
|
|
1396
|
+
]
|
|
1397
|
+
};
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
return {
|
|
1400
|
+
contents: [
|
|
1401
|
+
{
|
|
1402
|
+
type: "text",
|
|
1403
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
1404
|
+
}
|
|
1405
|
+
],
|
|
1406
|
+
isError: true
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
default:
|
|
1410
|
+
return {
|
|
1411
|
+
contents: [
|
|
1412
|
+
{
|
|
1413
|
+
type: "text",
|
|
1414
|
+
text: `Tool not found: ${name}`
|
|
1415
|
+
}
|
|
1416
|
+
],
|
|
1417
|
+
isError: true
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
);
|
|
937
1422
|
process.on("SIGINT", async () => {
|
|
938
1423
|
await this.server.close();
|
|
939
1424
|
process.exit(0);
|