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