fixparser-plugin-mcp 9.1.6-da9cb1d7 → 9.1.7-03aa39bd
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 +1089 -0
- package/build/cjs/MCPLocal.js.map +7 -0
- package/build/cjs/MCPRemote.js +608 -0
- package/build/cjs/MCPRemote.js.map +7 -0
- package/build/esm/MCPLocal.mjs +1064 -0
- package/build/esm/MCPLocal.mjs.map +7 -0
- package/build/esm/MCPRemote.mjs +592 -0
- package/build/esm/MCPRemote.mjs.map +7 -0
- package/build-examples/cjs/example_mcp_local.js +51 -0
- package/build-examples/cjs/example_mcp_local.js.map +7 -0
- package/build-examples/esm/example_mcp_local.mjs +51 -0
- package/build-examples/esm/example_mcp_local.mjs.map +7 -0
- package/package.json +29 -15
- package/types/MCPLocal.d.ts +16 -0
- package/types/{MCPPlugin.d.ts → MCPRemote.d.ts} +1 -1
- package/types/PluginOptions.d.ts +6 -0
- package/types/index.d.ts +3 -1
- package/build/esm/MCPPlugin.mjs +0 -190634
- package/build/esm/MCPPlugin.mjs.map +0 -7
|
@@ -0,0 +1,1064 @@
|
|
|
1
|
+
// src/MCPLocal.ts
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { Field, Fields, Messages } from "fixparser";
|
|
5
|
+
import { z } from "zod";
|
|
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
|
+
)
|
|
99
|
+
});
|
|
100
|
+
var MCPLocal = class {
|
|
101
|
+
parser;
|
|
102
|
+
server = new Server(
|
|
103
|
+
{
|
|
104
|
+
name: "fixparser",
|
|
105
|
+
version: "1.0.0"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
capabilities: {
|
|
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
|
+
}
|
|
129
|
+
},
|
|
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
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
transport = new StdioServerTransport();
|
|
269
|
+
onReady = void 0;
|
|
270
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
271
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
272
|
+
// Store market data prices with timestamps
|
|
273
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
274
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
275
|
+
// Maximum number of price points to store per symbol
|
|
276
|
+
constructor({ logger, onReady }) {
|
|
277
|
+
if (onReady) this.onReady = onReady;
|
|
278
|
+
}
|
|
279
|
+
async register(parser) {
|
|
280
|
+
this.parser = parser;
|
|
281
|
+
this.parser.addOnMessageCallback((message) => {
|
|
282
|
+
this.parser?.logger.log({
|
|
283
|
+
level: "info",
|
|
284
|
+
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
285
|
+
});
|
|
286
|
+
const msgType = message.messageType;
|
|
287
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject || msgType === Messages.MarketDataIncrementalRefresh) {
|
|
288
|
+
this.parser?.logger.log({
|
|
289
|
+
level: "info",
|
|
290
|
+
message: `MCP Server handling message type: ${msgType}`
|
|
291
|
+
});
|
|
292
|
+
let id;
|
|
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();
|
|
297
|
+
if (symbol?.value && price?.value) {
|
|
298
|
+
const symbolStr = String(symbol.value);
|
|
299
|
+
const priceNum = Number(price.value);
|
|
300
|
+
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
301
|
+
priceHistory.push({
|
|
302
|
+
timestamp: Number(timestamp),
|
|
303
|
+
price: priceNum
|
|
304
|
+
});
|
|
305
|
+
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
306
|
+
priceHistory.shift();
|
|
307
|
+
}
|
|
308
|
+
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
309
|
+
this.parser?.logger.log({
|
|
310
|
+
level: "info",
|
|
311
|
+
message: `MCP Server added ${symbol}: ${priceNum}`
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
316
|
+
const mdReqID = message.getField(Fields.MDReqID);
|
|
317
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
318
|
+
} else if (msgType === Messages.ExecutionReport) {
|
|
319
|
+
const clOrdID = message.getField(Fields.ClOrdID);
|
|
320
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
321
|
+
} else if (msgType === Messages.Reject) {
|
|
322
|
+
const refSeqNum = message.getField(Fields.RefSeqNum);
|
|
323
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
324
|
+
}
|
|
325
|
+
if (id) {
|
|
326
|
+
const callback = this.pendingRequests.get(id);
|
|
327
|
+
if (callback) {
|
|
328
|
+
callback(message);
|
|
329
|
+
this.pendingRequests.delete(id);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
this.addWorkflows();
|
|
335
|
+
await this.server.connect(this.transport);
|
|
336
|
+
if (this.onReady) {
|
|
337
|
+
this.onReady();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
addWorkflows() {
|
|
341
|
+
if (!this.parser) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (!this.server) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
this.server.setRequestHandler(
|
|
348
|
+
z.object({ method: z.literal("resources/list") }),
|
|
349
|
+
async (request, extra) => {
|
|
350
|
+
return {
|
|
351
|
+
resources: [
|
|
352
|
+
{
|
|
353
|
+
name: "greeting",
|
|
354
|
+
description: "A simple greeting resource",
|
|
355
|
+
uri: "greeting-resource"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
name: "stockGraph",
|
|
359
|
+
description: "Generates a price chart for a given symbol",
|
|
360
|
+
uri: "stockGraph",
|
|
361
|
+
parameters: {
|
|
362
|
+
type: "object",
|
|
363
|
+
properties: {
|
|
364
|
+
symbol: { type: "string" }
|
|
365
|
+
},
|
|
366
|
+
required: ["symbol"]
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
name: "stockPriceHistory",
|
|
371
|
+
description: "Returns price history for a given symbol",
|
|
372
|
+
uri: "stockPriceHistory",
|
|
373
|
+
parameters: {
|
|
374
|
+
type: "object",
|
|
375
|
+
properties: {
|
|
376
|
+
symbol: { type: "string" }
|
|
377
|
+
},
|
|
378
|
+
required: ["symbol"]
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
]
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
this.server.setRequestHandler(
|
|
386
|
+
z.object({ method: z.literal("tools/list") }),
|
|
387
|
+
async (request, extra) => {
|
|
388
|
+
return {
|
|
389
|
+
tools: [
|
|
390
|
+
{
|
|
391
|
+
name: "parse",
|
|
392
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
393
|
+
inputSchema: {
|
|
394
|
+
type: "object",
|
|
395
|
+
properties: {
|
|
396
|
+
fixString: { type: "string" }
|
|
397
|
+
},
|
|
398
|
+
required: ["fixString"]
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
name: "parseToJSON",
|
|
403
|
+
description: "Parses a FIX message into JSON",
|
|
404
|
+
inputSchema: {
|
|
405
|
+
type: "object",
|
|
406
|
+
properties: {
|
|
407
|
+
fixString: { type: "string" }
|
|
408
|
+
},
|
|
409
|
+
required: ["fixString"]
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
name: "verifyOrder",
|
|
414
|
+
description: "Verifies order parameters before execution",
|
|
415
|
+
inputSchema: {
|
|
416
|
+
type: "object",
|
|
417
|
+
properties: {
|
|
418
|
+
clOrdID: { type: "string" },
|
|
419
|
+
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
420
|
+
quantity: { type: "string" },
|
|
421
|
+
price: { type: "string" },
|
|
422
|
+
ordType: {
|
|
423
|
+
type: "string",
|
|
424
|
+
enum: [
|
|
425
|
+
"1",
|
|
426
|
+
"2",
|
|
427
|
+
"3",
|
|
428
|
+
"4",
|
|
429
|
+
"5",
|
|
430
|
+
"6",
|
|
431
|
+
"7",
|
|
432
|
+
"8",
|
|
433
|
+
"9",
|
|
434
|
+
"A",
|
|
435
|
+
"B",
|
|
436
|
+
"C",
|
|
437
|
+
"D",
|
|
438
|
+
"E",
|
|
439
|
+
"F",
|
|
440
|
+
"G",
|
|
441
|
+
"H",
|
|
442
|
+
"I",
|
|
443
|
+
"J",
|
|
444
|
+
"K",
|
|
445
|
+
"L",
|
|
446
|
+
"M",
|
|
447
|
+
"P",
|
|
448
|
+
"Q",
|
|
449
|
+
"R",
|
|
450
|
+
"S"
|
|
451
|
+
]
|
|
452
|
+
},
|
|
453
|
+
side: {
|
|
454
|
+
type: "string",
|
|
455
|
+
enum: [
|
|
456
|
+
"1",
|
|
457
|
+
"2",
|
|
458
|
+
"3",
|
|
459
|
+
"4",
|
|
460
|
+
"5",
|
|
461
|
+
"6",
|
|
462
|
+
"7",
|
|
463
|
+
"8",
|
|
464
|
+
"9",
|
|
465
|
+
"A",
|
|
466
|
+
"B",
|
|
467
|
+
"C",
|
|
468
|
+
"D",
|
|
469
|
+
"E",
|
|
470
|
+
"F",
|
|
471
|
+
"G",
|
|
472
|
+
"H"
|
|
473
|
+
]
|
|
474
|
+
},
|
|
475
|
+
symbol: { type: "string" },
|
|
476
|
+
timeInForce: {
|
|
477
|
+
type: "string",
|
|
478
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
required: [
|
|
482
|
+
"clOrdID",
|
|
483
|
+
"handlInst",
|
|
484
|
+
"quantity",
|
|
485
|
+
"price",
|
|
486
|
+
"ordType",
|
|
487
|
+
"side",
|
|
488
|
+
"symbol",
|
|
489
|
+
"timeInForce"
|
|
490
|
+
]
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
name: "executeOrder",
|
|
495
|
+
description: "Executes a verified order",
|
|
496
|
+
inputSchema: {
|
|
497
|
+
type: "object",
|
|
498
|
+
properties: {
|
|
499
|
+
clOrdID: { type: "string" },
|
|
500
|
+
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
501
|
+
quantity: { type: "string" },
|
|
502
|
+
price: { type: "string" },
|
|
503
|
+
ordType: { type: "string" },
|
|
504
|
+
side: { type: "string" },
|
|
505
|
+
symbol: { type: "string" },
|
|
506
|
+
timeInForce: { type: "string" }
|
|
507
|
+
},
|
|
508
|
+
required: [
|
|
509
|
+
"clOrdID",
|
|
510
|
+
"handlInst",
|
|
511
|
+
"quantity",
|
|
512
|
+
"price",
|
|
513
|
+
"ordType",
|
|
514
|
+
"side",
|
|
515
|
+
"symbol",
|
|
516
|
+
"timeInForce"
|
|
517
|
+
]
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: "marketDataRequest",
|
|
522
|
+
description: "Requests market data for specified symbols",
|
|
523
|
+
inputSchema: {
|
|
524
|
+
type: "object",
|
|
525
|
+
properties: {
|
|
526
|
+
mdUpdateType: { type: "string", enum: ["0", "1"] },
|
|
527
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
528
|
+
mdReqID: { type: "string" },
|
|
529
|
+
subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
|
|
530
|
+
mdEntryTypes: { type: "array", items: { type: "string" } }
|
|
531
|
+
},
|
|
532
|
+
required: [
|
|
533
|
+
"mdUpdateType",
|
|
534
|
+
"symbols",
|
|
535
|
+
"mdReqID",
|
|
536
|
+
"subscriptionRequestType",
|
|
537
|
+
"mdEntryTypes"
|
|
538
|
+
]
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
]
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
);
|
|
545
|
+
this.server.setRequestHandler(
|
|
546
|
+
z.object({
|
|
547
|
+
method: z.literal("resources/read"),
|
|
548
|
+
params: z.object({
|
|
549
|
+
uri: z.string()
|
|
550
|
+
})
|
|
551
|
+
}),
|
|
552
|
+
async (request, extra) => {
|
|
553
|
+
const { uri } = request.params;
|
|
554
|
+
switch (uri) {
|
|
555
|
+
case "greeting-resource":
|
|
556
|
+
return {
|
|
557
|
+
contents: [
|
|
558
|
+
{
|
|
559
|
+
type: "text",
|
|
560
|
+
text: "Hello, world!",
|
|
561
|
+
uri: "greeting-resource"
|
|
562
|
+
}
|
|
563
|
+
]
|
|
564
|
+
};
|
|
565
|
+
case "stockGraph":
|
|
566
|
+
return {
|
|
567
|
+
contents: [
|
|
568
|
+
{
|
|
569
|
+
type: "text",
|
|
570
|
+
text: "This resource requires a symbol parameter. Please use the stockGraph/{symbol} resource.",
|
|
571
|
+
uri: "stockGraph"
|
|
572
|
+
}
|
|
573
|
+
]
|
|
574
|
+
};
|
|
575
|
+
case "stockPriceHistory":
|
|
576
|
+
return {
|
|
577
|
+
contents: [
|
|
578
|
+
{
|
|
579
|
+
type: "text",
|
|
580
|
+
text: "This resource requires a symbol parameter. Please use the stockPriceHistory/{symbol} resource.",
|
|
581
|
+
uri: "stockPriceHistory"
|
|
582
|
+
}
|
|
583
|
+
]
|
|
584
|
+
};
|
|
585
|
+
default:
|
|
586
|
+
if (uri.startsWith("stockGraph/")) {
|
|
587
|
+
const symbol = uri.split("/")[1];
|
|
588
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
589
|
+
if (priceHistory.length === 0) {
|
|
590
|
+
return {
|
|
591
|
+
contents: [
|
|
592
|
+
{
|
|
593
|
+
type: "text",
|
|
594
|
+
text: `No price data available for ${symbol}`
|
|
595
|
+
}
|
|
596
|
+
]
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
const width = 600;
|
|
600
|
+
const height = 300;
|
|
601
|
+
const padding = 40;
|
|
602
|
+
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
603
|
+
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
604
|
+
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
605
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
606
|
+
const points = priceHistory.map((d, i) => {
|
|
607
|
+
const x = padding + i * xScale;
|
|
608
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
609
|
+
return `${x},${y}`;
|
|
610
|
+
}).join(" L ");
|
|
611
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
612
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
613
|
+
<!-- Background -->
|
|
614
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
615
|
+
|
|
616
|
+
<!-- Grid lines -->
|
|
617
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
618
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
619
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
620
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
621
|
+
}).join("\n")}
|
|
622
|
+
</g>
|
|
623
|
+
|
|
624
|
+
<!-- Price line -->
|
|
625
|
+
<path d="M ${points}"
|
|
626
|
+
fill="none"
|
|
627
|
+
stroke="#007bff"
|
|
628
|
+
stroke-width="2"/>
|
|
629
|
+
|
|
630
|
+
<!-- Data points -->
|
|
631
|
+
${priceHistory.map((d, i) => {
|
|
632
|
+
const x = padding + i * xScale;
|
|
633
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
634
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
635
|
+
}).join("\n")}
|
|
636
|
+
|
|
637
|
+
<!-- Labels -->
|
|
638
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
639
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
640
|
+
const x = padding + (width - 2 * padding) * i / 4;
|
|
641
|
+
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
642
|
+
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
643
|
+
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
644
|
+
}).join("\n")}
|
|
645
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
646
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
647
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
648
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
649
|
+
}).join("\n")}
|
|
650
|
+
</g>
|
|
651
|
+
|
|
652
|
+
<!-- Title -->
|
|
653
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
654
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
655
|
+
text-anchor="middle" fill="#212529">
|
|
656
|
+
${symbol} - Price Chart (${priceHistory.length} points)
|
|
657
|
+
</text>
|
|
658
|
+
</svg>`;
|
|
659
|
+
return {
|
|
660
|
+
contents: [
|
|
661
|
+
{
|
|
662
|
+
type: "text",
|
|
663
|
+
text: svg
|
|
664
|
+
}
|
|
665
|
+
]
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if (uri.startsWith("stockPriceHistory/")) {
|
|
669
|
+
const symbol = uri.split("/")[1];
|
|
670
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
671
|
+
if (priceHistory.length === 0) {
|
|
672
|
+
return {
|
|
673
|
+
contents: [
|
|
674
|
+
{
|
|
675
|
+
type: "text",
|
|
676
|
+
text: `No price data available for ${symbol}`
|
|
677
|
+
}
|
|
678
|
+
]
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
contents: [
|
|
683
|
+
{
|
|
684
|
+
type: "text",
|
|
685
|
+
text: JSON.stringify(
|
|
686
|
+
{
|
|
687
|
+
symbol,
|
|
688
|
+
count: priceHistory.length,
|
|
689
|
+
prices: priceHistory.map((point) => ({
|
|
690
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
691
|
+
price: point.price
|
|
692
|
+
}))
|
|
693
|
+
},
|
|
694
|
+
null,
|
|
695
|
+
2
|
|
696
|
+
)
|
|
697
|
+
}
|
|
698
|
+
]
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
return {
|
|
702
|
+
contents: [
|
|
703
|
+
{
|
|
704
|
+
type: "text",
|
|
705
|
+
text: `Resource not found: ${uri}`,
|
|
706
|
+
uri
|
|
707
|
+
}
|
|
708
|
+
],
|
|
709
|
+
isError: true
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
);
|
|
714
|
+
this.server.setRequestHandler(
|
|
715
|
+
z.object({
|
|
716
|
+
method: z.literal("parse"),
|
|
717
|
+
params: fixStringSchema
|
|
718
|
+
}),
|
|
719
|
+
async (request, extra) => {
|
|
720
|
+
try {
|
|
721
|
+
const args = request.params;
|
|
722
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
723
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
724
|
+
return {
|
|
725
|
+
contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
726
|
+
isError: true
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
contents: [
|
|
731
|
+
{
|
|
732
|
+
type: "text",
|
|
733
|
+
text: `${parsedMessage[0].description}
|
|
734
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
735
|
+
}
|
|
736
|
+
]
|
|
737
|
+
};
|
|
738
|
+
} catch (error) {
|
|
739
|
+
return {
|
|
740
|
+
contents: [
|
|
741
|
+
{
|
|
742
|
+
type: "text",
|
|
743
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
744
|
+
}
|
|
745
|
+
],
|
|
746
|
+
isError: true
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
);
|
|
751
|
+
this.server.setRequestHandler(
|
|
752
|
+
z.object({
|
|
753
|
+
method: z.literal("parseToJSON"),
|
|
754
|
+
params: fixStringSchema
|
|
755
|
+
}),
|
|
756
|
+
async (request, extra) => {
|
|
757
|
+
try {
|
|
758
|
+
const args = request.params;
|
|
759
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
760
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
761
|
+
return {
|
|
762
|
+
contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
763
|
+
isError: true
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
return {
|
|
767
|
+
contents: [
|
|
768
|
+
{
|
|
769
|
+
type: "text",
|
|
770
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
771
|
+
}
|
|
772
|
+
]
|
|
773
|
+
};
|
|
774
|
+
} catch (error) {
|
|
775
|
+
return {
|
|
776
|
+
contents: [
|
|
777
|
+
{
|
|
778
|
+
type: "text",
|
|
779
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
780
|
+
}
|
|
781
|
+
],
|
|
782
|
+
isError: true
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
this.server.setRequestHandler(
|
|
788
|
+
z.object({
|
|
789
|
+
method: z.literal("verifyOrder"),
|
|
790
|
+
params: orderSchema
|
|
791
|
+
}),
|
|
792
|
+
async (request, extra) => {
|
|
793
|
+
try {
|
|
794
|
+
const args = request.params;
|
|
795
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
796
|
+
clOrdID: args.clOrdID,
|
|
797
|
+
handlInst: args.handlInst,
|
|
798
|
+
quantity: Number.parseFloat(args.quantity),
|
|
799
|
+
price: Number.parseFloat(args.price),
|
|
800
|
+
ordType: args.ordType,
|
|
801
|
+
side: args.side,
|
|
802
|
+
symbol: args.symbol,
|
|
803
|
+
timeInForce: args.timeInForce
|
|
804
|
+
});
|
|
805
|
+
const ordTypeNames = {
|
|
806
|
+
"1": "Market",
|
|
807
|
+
"2": "Limit",
|
|
808
|
+
"3": "Stop",
|
|
809
|
+
"4": "StopLimit",
|
|
810
|
+
"5": "MarketOnClose",
|
|
811
|
+
"6": "WithOrWithout",
|
|
812
|
+
"7": "LimitOrBetter",
|
|
813
|
+
"8": "LimitWithOrWithout",
|
|
814
|
+
"9": "OnBasis",
|
|
815
|
+
A: "OnClose",
|
|
816
|
+
B: "LimitOnClose",
|
|
817
|
+
C: "ForexMarket",
|
|
818
|
+
D: "PreviouslyQuoted",
|
|
819
|
+
E: "PreviouslyIndicated",
|
|
820
|
+
F: "ForexLimit",
|
|
821
|
+
G: "ForexSwap",
|
|
822
|
+
H: "ForexPreviouslyQuoted",
|
|
823
|
+
I: "Funari",
|
|
824
|
+
J: "MarketIfTouched",
|
|
825
|
+
K: "MarketWithLeftOverAsLimit",
|
|
826
|
+
L: "PreviousFundValuationPoint",
|
|
827
|
+
M: "NextFundValuationPoint",
|
|
828
|
+
P: "Pegged",
|
|
829
|
+
Q: "CounterOrderSelection",
|
|
830
|
+
R: "StopOnBidOrOffer",
|
|
831
|
+
S: "StopLimitOnBidOrOffer"
|
|
832
|
+
};
|
|
833
|
+
const sideNames = {
|
|
834
|
+
"1": "Buy",
|
|
835
|
+
"2": "Sell",
|
|
836
|
+
"3": "BuyMinus",
|
|
837
|
+
"4": "SellPlus",
|
|
838
|
+
"5": "SellShort",
|
|
839
|
+
"6": "SellShortExempt",
|
|
840
|
+
"7": "Undisclosed",
|
|
841
|
+
"8": "Cross",
|
|
842
|
+
"9": "CrossShort",
|
|
843
|
+
A: "CrossShortExempt",
|
|
844
|
+
B: "AsDefined",
|
|
845
|
+
C: "Opposite",
|
|
846
|
+
D: "Subscribe",
|
|
847
|
+
E: "Redeem",
|
|
848
|
+
F: "Lend",
|
|
849
|
+
G: "Borrow",
|
|
850
|
+
H: "SellUndisclosed"
|
|
851
|
+
};
|
|
852
|
+
const timeInForceNames = {
|
|
853
|
+
"0": "Day",
|
|
854
|
+
"1": "GoodTillCancel",
|
|
855
|
+
"2": "AtTheOpening",
|
|
856
|
+
"3": "ImmediateOrCancel",
|
|
857
|
+
"4": "FillOrKill",
|
|
858
|
+
"5": "GoodTillCrossing",
|
|
859
|
+
"6": "GoodTillDate",
|
|
860
|
+
"7": "AtTheClose",
|
|
861
|
+
"8": "GoodThroughCrossing",
|
|
862
|
+
"9": "AtCrossing",
|
|
863
|
+
A: "GoodForTime",
|
|
864
|
+
B: "GoodForAuction",
|
|
865
|
+
C: "GoodForMonth"
|
|
866
|
+
};
|
|
867
|
+
const handlInstNames = {
|
|
868
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
869
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
870
|
+
"3": "ManualOrder"
|
|
871
|
+
};
|
|
872
|
+
return {
|
|
873
|
+
contents: [
|
|
874
|
+
{
|
|
875
|
+
type: "text",
|
|
876
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
877
|
+
|
|
878
|
+
Parameters verified:
|
|
879
|
+
- ClOrdID: ${args.clOrdID}
|
|
880
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
881
|
+
- Quantity: ${args.quantity}
|
|
882
|
+
- Price: ${args.price}
|
|
883
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
884
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
885
|
+
- Symbol: ${args.symbol}
|
|
886
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
887
|
+
|
|
888
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
889
|
+
}
|
|
890
|
+
]
|
|
891
|
+
};
|
|
892
|
+
} catch (error) {
|
|
893
|
+
return {
|
|
894
|
+
contents: [
|
|
895
|
+
{
|
|
896
|
+
type: "text",
|
|
897
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
898
|
+
}
|
|
899
|
+
],
|
|
900
|
+
isError: true
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
);
|
|
905
|
+
this.server.setRequestHandler(
|
|
906
|
+
z.object({
|
|
907
|
+
method: z.literal("executeOrder"),
|
|
908
|
+
params: orderSchema
|
|
909
|
+
}),
|
|
910
|
+
async (request, extra) => {
|
|
911
|
+
try {
|
|
912
|
+
const args = request.params;
|
|
913
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
914
|
+
if (!verifiedOrder) {
|
|
915
|
+
return {
|
|
916
|
+
contents: [
|
|
917
|
+
{
|
|
918
|
+
type: "text",
|
|
919
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
920
|
+
}
|
|
921
|
+
],
|
|
922
|
+
isError: true
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
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) {
|
|
926
|
+
return {
|
|
927
|
+
contents: [
|
|
928
|
+
{
|
|
929
|
+
type: "text",
|
|
930
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
931
|
+
}
|
|
932
|
+
],
|
|
933
|
+
isError: true
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
const response = new Promise((resolve) => {
|
|
937
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
938
|
+
});
|
|
939
|
+
const order = this.parser?.createMessage(
|
|
940
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
941
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
942
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
943
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
944
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
945
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
946
|
+
new Field(Fields.Side, args.side),
|
|
947
|
+
new Field(Fields.Symbol, args.symbol),
|
|
948
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
949
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
950
|
+
new Field(Fields.OrdType, args.ordType),
|
|
951
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
952
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
953
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
954
|
+
);
|
|
955
|
+
if (!this.parser?.connected) {
|
|
956
|
+
return {
|
|
957
|
+
contents: [
|
|
958
|
+
{
|
|
959
|
+
type: "text",
|
|
960
|
+
text: "Error: Not connected. Ignoring message."
|
|
961
|
+
}
|
|
962
|
+
],
|
|
963
|
+
isError: true
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
this.parser?.send(order);
|
|
967
|
+
const fixData = await response;
|
|
968
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
969
|
+
return {
|
|
970
|
+
contents: [
|
|
971
|
+
{
|
|
972
|
+
type: "text",
|
|
973
|
+
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())}`
|
|
974
|
+
}
|
|
975
|
+
]
|
|
976
|
+
};
|
|
977
|
+
} catch (error) {
|
|
978
|
+
return {
|
|
979
|
+
contents: [
|
|
980
|
+
{
|
|
981
|
+
type: "text",
|
|
982
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
983
|
+
}
|
|
984
|
+
],
|
|
985
|
+
isError: true
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
);
|
|
990
|
+
this.server.setRequestHandler(
|
|
991
|
+
z.object({
|
|
992
|
+
method: z.literal("marketDataRequest"),
|
|
993
|
+
params: marketDataRequestSchema
|
|
994
|
+
}),
|
|
995
|
+
async (request, extra) => {
|
|
996
|
+
try {
|
|
997
|
+
const args = request.params;
|
|
998
|
+
const response = new Promise((resolve) => {
|
|
999
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
1000
|
+
});
|
|
1001
|
+
const messageFields = [
|
|
1002
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
1003
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1004
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1005
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1006
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1007
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
1008
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
1009
|
+
new Field(Fields.MarketDepth, 0),
|
|
1010
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
1011
|
+
];
|
|
1012
|
+
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
1013
|
+
args.symbols.forEach((symbol) => {
|
|
1014
|
+
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
1015
|
+
});
|
|
1016
|
+
messageFields.push(new Field(Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
1017
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
1018
|
+
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
1019
|
+
});
|
|
1020
|
+
const mdr = this.parser?.createMessage(...messageFields);
|
|
1021
|
+
if (!this.parser?.connected) {
|
|
1022
|
+
return {
|
|
1023
|
+
contents: [
|
|
1024
|
+
{
|
|
1025
|
+
type: "text",
|
|
1026
|
+
text: "Error: Not connected. Ignoring message."
|
|
1027
|
+
}
|
|
1028
|
+
],
|
|
1029
|
+
isError: true
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
this.parser?.send(mdr);
|
|
1033
|
+
const fixData = await response;
|
|
1034
|
+
return {
|
|
1035
|
+
contents: [
|
|
1036
|
+
{
|
|
1037
|
+
type: "text",
|
|
1038
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
1039
|
+
}
|
|
1040
|
+
]
|
|
1041
|
+
};
|
|
1042
|
+
} catch (error) {
|
|
1043
|
+
return {
|
|
1044
|
+
contents: [
|
|
1045
|
+
{
|
|
1046
|
+
type: "text",
|
|
1047
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
1048
|
+
}
|
|
1049
|
+
],
|
|
1050
|
+
isError: true
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
);
|
|
1055
|
+
process.on("SIGINT", async () => {
|
|
1056
|
+
await this.server.close();
|
|
1057
|
+
process.exit(0);
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
export {
|
|
1062
|
+
MCPLocal
|
|
1063
|
+
};
|
|
1064
|
+
//# sourceMappingURL=MCPLocal.mjs.map
|