fixparser-plugin-mcp 9.1.7-b8fd1147 → 9.1.7-bb684c39

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.
@@ -23,183 +23,13 @@ __export(MCPLocal_exports, {
23
23
  MCPLocal: () => MCPLocal
24
24
  });
25
25
  module.exports = __toCommonJS(MCPLocal_exports);
26
- var import_server = require("@modelcontextprotocol/sdk/server/index.js");
26
+ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
27
27
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
28
- var import_types = require("@modelcontextprotocol/sdk/types.js");
29
28
  var import_fixparser = require("fixparser");
30
- var parseInputSchema = {
31
- type: "object",
32
- properties: {
33
- fixString: {
34
- type: "string",
35
- description: "FIX message string to parse"
36
- }
37
- },
38
- required: ["fixString"]
39
- };
40
- var parseToJSONInputSchema = {
41
- type: "object",
42
- properties: {
43
- fixString: {
44
- type: "string",
45
- description: "FIX message string to parse"
46
- }
47
- },
48
- required: ["fixString"]
49
- };
50
- var newOrderSingleInputSchema = {
51
- type: "object",
52
- properties: {
53
- clOrdID: {
54
- type: "string",
55
- description: "Client Order ID"
56
- },
57
- handlInst: {
58
- type: "string",
59
- enum: ["1", "2", "3"],
60
- default: import_fixparser.HandlInst.AutomatedExecutionNoIntervention,
61
- description: 'Handling instruction (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention)'
62
- },
63
- quantity: {
64
- type: "number",
65
- description: "Order quantity"
66
- },
67
- price: {
68
- type: "number",
69
- description: "Order price"
70
- },
71
- ordType: {
72
- type: "string",
73
- enum: [
74
- "1",
75
- "2",
76
- "3",
77
- "4",
78
- "5",
79
- "6",
80
- "7",
81
- "8",
82
- "9",
83
- "A",
84
- "B",
85
- "C",
86
- "D",
87
- "E",
88
- "F",
89
- "G",
90
- "H",
91
- "I",
92
- "J",
93
- "K",
94
- "L",
95
- "M",
96
- "P",
97
- "Q",
98
- "R",
99
- "S"
100
- ],
101
- default: import_fixparser.OrdType.Market,
102
- description: 'Order type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Market, "2" for Limit, "3" for Stop)'
103
- },
104
- side: {
105
- type: "string",
106
- enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
107
- description: 'Order side (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Buy, "2" for Sell, "3" for BuyMinus, "4" for SellPlus, "5" for SellShort, "6" for SellShortExempt, "7" for Undisclosed, "8" for Cross, "9" for CrossShort, "A" for CrossShortExempt, "B" for AsDefined, "C" for Opposite, "D" for Subscribe, "E" for Redeem, "F" for Lend, "G" for Borrow, "H" for SellUndisclosed)'
108
- },
109
- symbol: {
110
- type: "string",
111
- description: "Trading symbol"
112
- },
113
- timeInForce: {
114
- type: "string",
115
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
116
- default: import_fixparser.TimeInForce.Day,
117
- description: 'Time in force (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Day, "1" for Good Till Cancel, "2" for At Opening, "3" for Immediate or Cancel, "4" for Fill or Kill, "5" for Good Till Crossing, "6" for Good Till Date)'
118
- }
119
- },
120
- required: ["clOrdID", "quantity", "price", "side", "symbol"]
121
- };
122
- var marketDataRequestInputSchema = {
123
- type: "object",
124
- properties: {
125
- mdUpdateType: {
126
- type: "string",
127
- enum: ["0", "1"],
128
- default: "0",
129
- description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
130
- },
131
- symbol: {
132
- type: "string",
133
- description: "Trading symbol"
134
- },
135
- mdReqID: {
136
- type: "string",
137
- description: "Market data request ID"
138
- },
139
- subscriptionRequestType: {
140
- type: "string",
141
- enum: ["0", "1", "2"],
142
- default: import_fixparser.SubscriptionRequestType.SnapshotAndUpdates,
143
- description: 'Subscription request type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe)'
144
- },
145
- mdEntryType: {
146
- type: "string",
147
- enum: [
148
- "0",
149
- "1",
150
- "2",
151
- "3",
152
- "4",
153
- "5",
154
- "6",
155
- "7",
156
- "8",
157
- "9",
158
- "A",
159
- "B",
160
- "C",
161
- "D",
162
- "E",
163
- "F",
164
- "G",
165
- "H",
166
- "J",
167
- "K",
168
- "L",
169
- "M",
170
- "N",
171
- "O",
172
- "P",
173
- "Q",
174
- "S",
175
- "R",
176
- "T",
177
- "U",
178
- "V",
179
- "W",
180
- "X",
181
- "Y",
182
- "Z",
183
- "a",
184
- "b",
185
- "c",
186
- "d",
187
- "e",
188
- "g",
189
- "h",
190
- "i",
191
- "t"
192
- ],
193
- default: import_fixparser.MDEntryType.Bid,
194
- description: 'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'
195
- }
196
- },
197
- required: ["symbol", "mdReqID"]
198
- };
29
+ var import_zod = require("zod");
199
30
  var MCPLocal = class {
200
- logger;
201
31
  parser;
202
- server = new import_server.Server(
32
+ server = new import_mcp.McpServer(
203
33
  {
204
34
  name: "fixparser",
205
35
  version: "1.0.0"
@@ -215,29 +45,31 @@ var MCPLocal = class {
215
45
  transport = new import_stdio.StdioServerTransport();
216
46
  onReady = void 0;
217
47
  pendingRequests = /* @__PURE__ */ new Map();
48
+ verifiedOrders = /* @__PURE__ */ new Map();
218
49
  constructor({ logger, onReady }) {
219
- if (logger && !logger.silent) {
220
- this.logger = logger;
221
- }
222
50
  if (onReady) this.onReady = onReady;
223
51
  }
224
52
  async register(parser) {
225
53
  this.parser = parser;
226
- if (parser.logger && !parser.logger.silent) {
227
- this.logger = parser.logger;
228
- }
229
54
  this.parser.addOnMessageCallback((message) => {
230
55
  const msgType = message.messageType;
231
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport) {
232
- const idField = msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh ? message.getField(import_fixparser.Fields.MDReqID) : message.getField(import_fixparser.Fields.ClOrdID);
233
- if (idField) {
234
- const id = idField.value;
235
- if (typeof id === "string" || typeof id === "number") {
236
- const callback = this.pendingRequests.get(String(id));
237
- if (callback) {
238
- callback(message);
239
- this.pendingRequests.delete(String(id));
240
- }
56
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject) {
57
+ let id;
58
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
59
+ const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
60
+ if (mdReqID) id = String(mdReqID.value);
61
+ } else if (msgType === import_fixparser.Messages.ExecutionReport) {
62
+ const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
63
+ if (clOrdID) id = String(clOrdID.value);
64
+ } else if (msgType === import_fixparser.Messages.Reject) {
65
+ const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
66
+ if (refSeqNum) id = String(refSeqNum.value);
67
+ }
68
+ if (id) {
69
+ const callback = this.pendingRequests.get(id);
70
+ if (callback) {
71
+ callback(message);
72
+ this.pendingRequests.delete(id);
241
73
  }
242
74
  }
243
75
  }
@@ -250,460 +82,570 @@ var MCPLocal = class {
250
82
  }
251
83
  addWorkflows() {
252
84
  if (!this.parser) {
253
- this.logger?.log({
254
- level: "error",
255
- message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
256
- });
257
85
  return;
258
86
  }
259
87
  if (!this.server) {
260
- this.logger?.log({
261
- level: "error",
262
- message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
263
- });
264
88
  return;
265
89
  }
266
- const validateArgs = (args, schema) => {
267
- const result = {};
268
- for (const [key, propSchema] of Object.entries(schema.properties || {})) {
269
- const prop = propSchema;
270
- const value = args?.[key];
271
- if (prop.required && (value === void 0 || value === null)) {
272
- throw new Error(`Required property '${key}' is missing`);
273
- }
274
- if (value !== void 0) {
275
- result[key] = value;
276
- } else if (prop.default !== void 0) {
277
- result[key] = prop.default;
278
- }
279
- }
280
- return result;
281
- };
282
- this.server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
283
- return {
284
- resources: []
285
- };
286
- });
287
- this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
288
- return {
289
- tools: [
290
- {
291
- name: "parse",
292
- description: "Parses a FIX message and describes it in plain language",
293
- inputSchema: parseInputSchema
294
- },
295
- {
296
- name: "parseToJSON",
297
- description: "Parses a FIX message into JSON",
298
- inputSchema: parseToJSONInputSchema
299
- },
300
- {
301
- name: "newOrderSingle",
302
- description: "Creates and sends a New Order Single",
303
- inputSchema: newOrderSingleInputSchema
304
- },
305
- {
306
- name: "marketDataRequest",
307
- description: "Sends a request for Market Data with the given symbol",
308
- inputSchema: marketDataRequestInputSchema
309
- }
310
- ]
311
- };
312
- });
313
- this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
314
- const { name, arguments: args } = request.params;
315
- switch (name) {
316
- case "parse": {
317
- try {
318
- const { fixString } = validateArgs(args, parseInputSchema);
319
- const parsedMessage = this.parser?.parse(fixString);
320
- if (!parsedMessage || parsedMessage.length === 0) {
321
- return {
322
- isError: true,
323
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
324
- };
325
- }
326
- return {
327
- content: [
328
- {
329
- type: "text",
330
- text: `${parsedMessage[0].description}
331
- ${parsedMessage[0].messageTypeDescription}`
332
- }
333
- ]
334
- };
335
- } catch (error) {
90
+ this.server.tool(
91
+ "parse",
92
+ "Parses a FIX message and describes it in plain language",
93
+ {
94
+ fixString: import_zod.z.string().describe("FIX message string to parse")
95
+ },
96
+ async (args) => {
97
+ try {
98
+ const parsedMessage = this.parser?.parse(args.fixString);
99
+ if (!parsedMessage || parsedMessage.length === 0) {
336
100
  return {
337
- isError: true,
338
- content: [
339
- {
340
- type: "text",
341
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
342
- }
343
- ]
101
+ content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
102
+ isError: true
344
103
  };
345
104
  }
105
+ return {
106
+ content: [
107
+ {
108
+ type: "text",
109
+ text: `${parsedMessage[0].description}
110
+ ${parsedMessage[0].messageTypeDescription}`
111
+ }
112
+ ]
113
+ };
114
+ } catch (error) {
115
+ return {
116
+ content: [
117
+ {
118
+ type: "text",
119
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
120
+ }
121
+ ],
122
+ isError: true
123
+ };
346
124
  }
347
- case "parseToJSON": {
348
- try {
349
- const { fixString } = validateArgs(args, parseToJSONInputSchema);
350
- const parsedMessage = this.parser?.parse(fixString);
351
- if (!parsedMessage || parsedMessage.length === 0) {
352
- return {
353
- isError: true,
354
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
355
- };
356
- }
357
- return {
358
- content: [
359
- {
360
- type: "text",
361
- text: `${parsedMessage[0].toFIXJSON()}`
362
- }
363
- ]
364
- };
365
- } catch (error) {
125
+ }
126
+ );
127
+ this.server.tool(
128
+ "parseToJSON",
129
+ "Parses a FIX message into JSON",
130
+ {
131
+ fixString: import_zod.z.string().describe("FIX message string to parse")
132
+ },
133
+ async (args) => {
134
+ try {
135
+ const parsedMessage = this.parser?.parse(args.fixString);
136
+ if (!parsedMessage || parsedMessage.length === 0) {
366
137
  return {
367
- isError: true,
368
- content: [
369
- {
370
- type: "text",
371
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
372
- }
373
- ]
138
+ content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
139
+ isError: true
374
140
  };
375
141
  }
142
+ return {
143
+ content: [
144
+ {
145
+ type: "text",
146
+ text: `${parsedMessage[0].toFIXJSON()}`
147
+ }
148
+ ]
149
+ };
150
+ } catch (error) {
151
+ return {
152
+ content: [
153
+ {
154
+ type: "text",
155
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
156
+ }
157
+ ],
158
+ isError: true
159
+ };
376
160
  }
377
- case "newOrderSingle": {
378
- try {
379
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
380
- const response = new Promise((resolve) => {
381
- this.pendingRequests.set(clOrdID, resolve);
382
- });
383
- const order = this.parser?.createMessage(
384
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
385
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
386
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
387
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
388
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
389
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
390
- new import_fixparser.Field(import_fixparser.Fields.Side, side),
391
- new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
392
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
393
- new import_fixparser.Field(import_fixparser.Fields.Price, price),
394
- new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
395
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
396
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
397
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
398
- );
399
- if (!this.parser?.connected) {
400
- this.logger?.log({
401
- level: "error",
402
- message: "FIXParser (MCP): -- Not connected. Ignoring message."
403
- });
404
- return {
405
- isError: true,
406
- content: [
407
- {
408
- type: "text",
409
- text: "Error: Not connected. Ignoring message."
410
- }
411
- ]
412
- };
413
- }
414
- this.parser?.send(order);
415
- this.logger?.log({
416
- level: "info",
417
- message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
418
- });
419
- const fixData = await response;
420
- return {
421
- content: [
422
- {
423
- type: "text",
424
- text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
425
- }
426
- ]
427
- };
428
- } catch (error) {
161
+ }
162
+ );
163
+ this.server.tool(
164
+ "verifyOrder",
165
+ "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
166
+ {
167
+ clOrdID: import_zod.z.string().describe("Client Order ID"),
168
+ handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
169
+ quantity: import_zod.z.string().describe("Order quantity"),
170
+ price: import_zod.z.string().describe("Order price"),
171
+ ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
172
+ side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
173
+ symbol: import_zod.z.string().describe("Trading symbol"),
174
+ timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
175
+ },
176
+ async (args) => {
177
+ try {
178
+ this.verifiedOrders.set(args.clOrdID, {
179
+ clOrdID: args.clOrdID,
180
+ handlInst: args.handlInst,
181
+ quantity: Number.parseFloat(args.quantity),
182
+ price: Number.parseFloat(args.price),
183
+ ordType: args.ordType,
184
+ side: args.side,
185
+ symbol: args.symbol,
186
+ timeInForce: args.timeInForce
187
+ });
188
+ return {
189
+ content: [
190
+ {
191
+ type: "text",
192
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
193
+
194
+ Parameters verified:
195
+ - ClOrdID: ${args.clOrdID}
196
+ - HandlInst: ${args.handlInst}
197
+ - Quantity: ${args.quantity}
198
+ - Price: ${args.price}
199
+ - OrdType: ${args.ordType}
200
+ - Side: ${args.side}
201
+ - Symbol: ${args.symbol}
202
+ - TimeInForce: ${args.timeInForce}
203
+
204
+ To execute this order, call the executeOrder tool with these exact same parameters.`
205
+ }
206
+ ]
207
+ };
208
+ } catch (error) {
209
+ return {
210
+ content: [
211
+ {
212
+ type: "text",
213
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
214
+ }
215
+ ],
216
+ isError: true
217
+ };
218
+ }
219
+ }
220
+ );
221
+ this.server.tool(
222
+ "executeOrder",
223
+ "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
224
+ {
225
+ clOrdID: import_zod.z.string().describe("Client Order ID"),
226
+ handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
227
+ quantity: import_zod.z.string().describe("Order quantity"),
228
+ price: import_zod.z.string().describe("Order price"),
229
+ ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
230
+ side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
231
+ symbol: import_zod.z.string().describe("Trading symbol"),
232
+ timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
233
+ },
234
+ async (args) => {
235
+ try {
236
+ const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
237
+ if (!verifiedOrder) {
429
238
  return {
430
- isError: true,
431
239
  content: [
432
240
  {
433
241
  type: "text",
434
- text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
242
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
435
243
  }
436
- ]
244
+ ],
245
+ isError: true
437
246
  };
438
247
  }
439
- }
440
- case "marketDataRequest": {
441
- try {
442
- const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
443
- args,
444
- marketDataRequestInputSchema
445
- );
446
- const response = new Promise((resolve) => {
447
- this.pendingRequests.set(mdReqID, resolve);
448
- });
449
- const marketDataRequest = this.parser?.createMessage(
450
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
451
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
452
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
453
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
454
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
455
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
456
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
457
- new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
458
- new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
459
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
460
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
461
- new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
462
- new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
463
- );
464
- if (!this.parser?.connected) {
465
- this.logger?.log({
466
- level: "error",
467
- message: "FIXParser (MCP): -- Not connected. Ignoring message."
468
- });
469
- return {
470
- isError: true,
471
- content: [
472
- {
473
- type: "text",
474
- text: "Error: Not connected. Ignoring message."
475
- }
476
- ]
477
- };
478
- }
479
- this.parser?.send(marketDataRequest);
480
- this.logger?.log({
481
- level: "info",
482
- message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
483
- });
484
- const fixData = await response;
248
+ 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) {
485
249
  return {
486
250
  content: [
487
251
  {
488
252
  type: "text",
489
- text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
253
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
490
254
  }
491
- ]
255
+ ],
256
+ isError: true
492
257
  };
493
- } catch (error) {
258
+ }
259
+ const response = new Promise((resolve) => {
260
+ this.pendingRequests.set(args.clOrdID, resolve);
261
+ });
262
+ const order = this.parser?.createMessage(
263
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
264
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
265
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
266
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
267
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
268
+ new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
269
+ new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
270
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
271
+ new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
272
+ new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
273
+ new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
274
+ new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
275
+ new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
276
+ new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
277
+ );
278
+ if (!this.parser?.connected) {
494
279
  return {
495
- isError: true,
496
280
  content: [
497
281
  {
498
282
  type: "text",
499
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
283
+ text: "Error: Not connected. Ignoring message."
500
284
  }
501
- ]
285
+ ],
286
+ isError: true
502
287
  };
503
288
  }
504
- }
505
- default:
506
- throw new Error(`Unknown tool: ${name}`);
507
- }
508
- });
509
- this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
510
- return {
511
- prompts: [
512
- {
513
- name: "parse",
514
- description: "Parses a FIX message and describes it in plain language",
515
- arguments: [
516
- {
517
- name: "fixString",
518
- description: "FIX message string to parse",
519
- required: true
520
- }
521
- ]
522
- },
523
- {
524
- name: "parseToJSON",
525
- description: "Parses a FIX message into JSON",
526
- arguments: [
527
- {
528
- name: "fixString",
529
- description: "FIX message string to parse",
530
- required: true
531
- }
532
- ]
533
- },
534
- {
535
- name: "newOrderSingle",
536
- description: "Creates and sends a New Order Single",
537
- arguments: [
538
- {
539
- name: "clOrdID",
540
- description: "Client Order ID",
541
- required: true
542
- },
543
- {
544
- name: "handlInst",
545
- description: "Handling instruction",
546
- required: false
547
- },
548
- {
549
- name: "quantity",
550
- description: "Order quantity",
551
- required: true
552
- },
553
- {
554
- name: "price",
555
- description: "Order price",
556
- required: true
557
- },
558
- {
559
- name: "ordType",
560
- description: "Order type",
561
- required: false
562
- },
563
- {
564
- name: "side",
565
- description: "Order 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)",
566
- required: true
567
- },
568
- {
569
- name: "symbol",
570
- description: "Trading symbol",
571
- required: true
572
- },
573
- {
574
- name: "timeInForce",
575
- description: "Time in force",
576
- required: false
577
- }
578
- ]
579
- },
580
- {
581
- name: "marketDataRequest",
582
- description: "Sends a request for Market Data with the given symbol",
583
- arguments: [
584
- {
585
- name: "mdUpdateType",
586
- description: "Market data update type",
587
- required: false
588
- },
589
- {
590
- name: "symbol",
591
- description: "Trading symbol",
592
- required: true
593
- },
594
- {
595
- name: "mdReqID",
596
- description: "Market data request ID",
597
- required: true
598
- },
599
- {
600
- name: "subscriptionRequestType",
601
- description: "Subscription request type",
602
- required: false
603
- },
604
- {
605
- name: "mdEntryType",
606
- description: "Market data entry type",
607
- required: false
608
- }
609
- ]
610
- }
611
- ]
612
- };
613
- });
614
- this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
615
- const { name, arguments: args } = request.params;
616
- switch (name) {
617
- case "parse": {
618
- const fixString = args?.fixString || "";
289
+ this.parser?.send(order);
290
+ const fixData = await response;
291
+ this.verifiedOrders.delete(args.clOrdID);
619
292
  return {
620
- messages: [
293
+ content: [
621
294
  {
622
- role: "user",
623
- content: {
624
- type: "text",
625
- text: `Please parse and explain this FIX message: ${fixString}`
626
- }
295
+ type: "text",
296
+ text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
627
297
  }
628
298
  ]
629
299
  };
630
- }
631
- case "parseToJSON": {
632
- const fixString = args?.fixString || "";
300
+ } catch (error) {
633
301
  return {
634
- messages: [
302
+ content: [
635
303
  {
636
- role: "user",
637
- content: {
638
- type: "text",
639
- text: `Please parse the FIX message to JSON: ${fixString}`
640
- }
304
+ type: "text",
305
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
641
306
  }
642
- ]
307
+ ],
308
+ isError: true
643
309
  };
644
310
  }
645
- case "newOrderSingle": {
646
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
647
- return {
648
- messages: [
649
- {
650
- role: "user",
651
- content: {
311
+ }
312
+ );
313
+ this.server.tool(
314
+ "marketDataRequest",
315
+ "Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
316
+ {
317
+ mdUpdateType: import_zod.z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
318
+ symbol: import_zod.z.string().describe("Trading symbol"),
319
+ mdReqID: import_zod.z.string().describe("Market data request ID"),
320
+ subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
321
+ mdEntryType: import_zod.z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
322
+ },
323
+ async (args) => {
324
+ try {
325
+ const response = new Promise((resolve) => {
326
+ this.pendingRequests.set(args.mdReqID, resolve);
327
+ });
328
+ const marketDataRequest = this.parser?.createMessage(
329
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
330
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
331
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
332
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
333
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
334
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
335
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType),
336
+ new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
337
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
338
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
339
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
340
+ new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
341
+ new import_fixparser.Field(import_fixparser.Fields.MDEntryType, args.mdEntryType)
342
+ );
343
+ if (!this.parser?.connected) {
344
+ return {
345
+ content: [
346
+ {
652
347
  type: "text",
653
- text: [
654
- "Create a New Order Single FIX message with the following parameters:",
655
- `- ClOrdID: ${clOrdID}`,
656
- `- HandlInst: ${handlInst ?? "3"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Manual, '2' for Automated, '3' for AutomatedNoIntervention)`,
657
- `- Quantity: ${quantity}`,
658
- `- Price: ${price}`,
659
- `- OrdType: ${ordType ?? "1"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Market, '2' for Limit, '3' for Stop)`,
660
- `- Side: ${side} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Buy, '2' for Sell)`,
661
- `- Symbol: ${symbol}`,
662
- `- TimeInForce: ${timeInForce ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Day, '1' for Good Till Cancel, '2' for At Opening, '3' for Immediate or Cancel, '4' for Fill or Kill, '5' for Good Till Crossing, '6' for Good Till Date)`,
663
- "",
664
- "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
665
- "",
666
- 'Note: For the Side parameter, always use the numeric/alphabetic value (e.g., "1" for Buy, "2" for Sell) as defined in the FIX protocol, not the descriptive name.',
667
- 'Note: For the HandlInst parameter, always use the numeric/alphabetic value (e.g., "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention) as defined in the FIX protocol, not the descriptive name.',
668
- 'Note: For the OrdType parameter, always use the numeric/alphabetic value (e.g., "1" for Market, "2" for Limit, "3" for Stop) as defined in the FIX protocol, not the descriptive name.',
669
- 'Note: For the TimeInForce parameter, always use the numeric/alphabetic value (e.g., "0" for Day, "1" for Good Till Cancel, "2" for At Opening) as defined in the FIX protocol, not the descriptive name.'
670
- ].join("\n")
348
+ text: "Error: Not connected. Ignoring message."
671
349
  }
350
+ ],
351
+ isError: true
352
+ };
353
+ }
354
+ this.parser?.send(marketDataRequest);
355
+ const fixData = await response;
356
+ return {
357
+ content: [
358
+ {
359
+ type: "text",
360
+ text: `Market data for ${args.symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
672
361
  }
673
362
  ]
674
363
  };
675
- }
676
- case "marketDataRequest": {
677
- const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
364
+ } catch (error) {
678
365
  return {
679
- messages: [
366
+ content: [
680
367
  {
681
- role: "user",
682
- content: {
683
- type: "text",
684
- text: [
685
- "Create a Market Data Request FIX message with the following parameters:",
686
- `- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
687
- `- Symbol: ${symbol}`,
688
- `- MDReqID: ${mdReqID}`,
689
- `- SubscriptionRequestType: ${subscriptionRequestType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Snapshot + Updates, '1' for Snapshot, '2' for Unsubscribe)`,
690
- `- MDEntryType: ${mdEntryType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Bid, '1' for Offer, '2' for Trade, '3' for Index Value, '4' for Opening Price)`,
691
- "",
692
- "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
693
- "",
694
- 'Note: For the MDUpdateType parameter, always use the numeric/alphabetic value (e.g., "0" for FullRefresh, "1" for IncrementalRefresh) as defined in the FIX protocol, not the descriptive name.',
695
- 'Note: For the SubscriptionRequestType parameter, always use the numeric/alphabetic value (e.g., "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe) as defined in the FIX protocol, not the descriptive name.',
696
- 'Note: For the MDEntryType parameter, always use the numeric/alphabetic value (e.g., "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price) as defined in the FIX protocol, not the descriptive name.'
697
- ].join("\n")
698
- }
368
+ type: "text",
369
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
699
370
  }
700
- ]
371
+ ],
372
+ isError: true
701
373
  };
702
374
  }
703
- default:
704
- throw new Error(`Unknown prompt: ${name}`);
705
375
  }
706
- });
376
+ );
377
+ this.server.prompt(
378
+ "parse",
379
+ "Parses a FIX message and describes it in plain language",
380
+ {
381
+ fixString: import_zod.z.string().describe("FIX message string to parse")
382
+ },
383
+ async (args) => {
384
+ return {
385
+ messages: [
386
+ {
387
+ role: "user",
388
+ content: {
389
+ type: "text",
390
+ text: `Please parse and explain this FIX message: ${args.fixString}`
391
+ }
392
+ }
393
+ ]
394
+ };
395
+ }
396
+ );
397
+ this.server.prompt(
398
+ "parseToJSON",
399
+ "Parses a FIX message into JSON",
400
+ {
401
+ fixString: import_zod.z.string().describe("FIX message string to parse")
402
+ },
403
+ async (args) => {
404
+ return {
405
+ messages: [
406
+ {
407
+ role: "user",
408
+ content: {
409
+ type: "text",
410
+ text: `Please parse the FIX message to JSON: ${args.fixString}`
411
+ }
412
+ }
413
+ ]
414
+ };
415
+ }
416
+ );
417
+ this.server.prompt(
418
+ "verifyOrder",
419
+ "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
420
+ {
421
+ clOrdID: import_zod.z.string().describe("Client Order ID"),
422
+ handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
423
+ quantity: import_zod.z.string().describe("Order quantity"),
424
+ price: import_zod.z.string().describe("Order price"),
425
+ ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
426
+ side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
427
+ symbol: import_zod.z.string().describe("Trading symbol"),
428
+ timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
429
+ },
430
+ async (args) => {
431
+ return {
432
+ messages: [
433
+ {
434
+ role: "user",
435
+ content: {
436
+ type: "text",
437
+ text: [
438
+ "You are an AI assistant that helps users verify FIX New Order Single parameters.",
439
+ "This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.",
440
+ "",
441
+ "You must verify that all required fields are provided and valid:",
442
+ "- ClOrdID (Client Order ID)",
443
+ "- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
444
+ "- Quantity (Order quantity)",
445
+ "- Price (Order price)",
446
+ "- OrdType (1=Market, 2=Limit, 3=Stop)",
447
+ "- 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)",
448
+ "- Symbol (Trading symbol)",
449
+ "- TimeInForce (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",
450
+ "",
451
+ "Current parameters to verify:",
452
+ `- ClOrdID: ${args.clOrdID}`,
453
+ `- HandlInst: ${args.handlInst}`,
454
+ `- Quantity: ${args.quantity}`,
455
+ `- Price: ${args.price}`,
456
+ `- OrdType: ${args.ordType}`,
457
+ `- Side: ${args.side}`,
458
+ `- Symbol: ${args.symbol}`,
459
+ `- TimeInForce: ${args.timeInForce}`,
460
+ "",
461
+ "If all parameters are valid, respond with:",
462
+ "`VERIFICATION: All parameters valid. Ready to proceed.`",
463
+ "",
464
+ "Otherwise, list the missing or invalid ones.",
465
+ "",
466
+ "IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."
467
+ ].join("\n")
468
+ }
469
+ }
470
+ ]
471
+ };
472
+ }
473
+ );
474
+ this.server.prompt(
475
+ "executeOrder",
476
+ "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
477
+ {
478
+ clOrdID: import_zod.z.string().describe("Client Order ID"),
479
+ handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
480
+ quantity: import_zod.z.string().describe("Order quantity"),
481
+ price: import_zod.z.string().describe("Order price"),
482
+ ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
483
+ side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
484
+ symbol: import_zod.z.string().describe("Trading symbol"),
485
+ timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
486
+ },
487
+ async (args) => {
488
+ return {
489
+ messages: [
490
+ {
491
+ role: "user",
492
+ content: {
493
+ type: "text",
494
+ text: [
495
+ "You are an AI assistant that helps users execute FIX New Order Single messages.",
496
+ "This is STEP 2 of 2 - EXECUTION. This will send the order to the market.",
497
+ "",
498
+ "IMPORTANT: This tool should only be called after successful verification of all parameters.",
499
+ "",
500
+ "Parameters to execute:",
501
+ `- ClOrdID: ${args.clOrdID}`,
502
+ `- HandlInst: ${args.handlInst}`,
503
+ `- Quantity: ${args.quantity}`,
504
+ `- Price: ${args.price}`,
505
+ `- OrdType: ${args.ordType}`,
506
+ `- Side: ${args.side}`,
507
+ `- Symbol: ${args.symbol}`,
508
+ `- TimeInForce: ${args.timeInForce}`,
509
+ "",
510
+ "IMPORTANT: The response will be either:",
511
+ "1. An Execution Report (MsgType=8) if the order was successfully placed",
512
+ "2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
513
+ ].join("\n")
514
+ }
515
+ }
516
+ ]
517
+ };
518
+ }
519
+ );
520
+ this.server.prompt(
521
+ "marketDataRequest",
522
+ "Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
523
+ {
524
+ mdUpdateType: import_zod.z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
525
+ symbol: import_zod.z.string().describe("Trading symbol"),
526
+ mdReqID: import_zod.z.string().describe("Market data request ID"),
527
+ subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
528
+ mdEntryType: import_zod.z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
529
+ },
530
+ async (args) => {
531
+ return {
532
+ messages: [
533
+ {
534
+ role: "user",
535
+ content: {
536
+ type: "text",
537
+ text: [
538
+ "You are an AI assistant that helps users create FIX Market Data Request messages.",
539
+ "You must **first verify** that all required fields are provided:",
540
+ "- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
541
+ "- Symbol (Trading symbol)",
542
+ "- MDReqID (Market data request ID)",
543
+ "- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
544
+ "- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
545
+ "",
546
+ "Only when all fields are present and valid, respond with:",
547
+ "`VERIFICATION: All parameters valid. Ready to proceed.`",
548
+ "",
549
+ "Otherwise, list the missing or invalid ones.",
550
+ "",
551
+ "Do not create the FIX message until verification is complete.",
552
+ "",
553
+ "Current parameters:",
554
+ `- MDUpdateType: ${args.mdUpdateType}`,
555
+ `- Symbol: ${args.symbol}`,
556
+ `- MDReqID: ${args.mdReqID}`,
557
+ `- SubscriptionRequestType: ${args.subscriptionRequestType}`,
558
+ `- MDEntryType: ${args.mdEntryType}`
559
+ ].join("\n")
560
+ }
561
+ }
562
+ ]
563
+ };
564
+ }
565
+ );
566
+ this.server.resource(
567
+ "stockGraph",
568
+ new import_mcp.ResourceTemplate("stock://{symbol}", { list: void 0 }),
569
+ async (uri, variables) => {
570
+ const symbol = variables.symbol;
571
+ const data = [
572
+ { time: "09:30", price: 150 },
573
+ { time: "10:30", price: 152.5 },
574
+ { time: "11:30", price: 151.75 },
575
+ { time: "12:30", price: 153.25 },
576
+ { time: "13:30", price: 154 },
577
+ { time: "14:30", price: 153.5 },
578
+ { time: "15:30", price: 155 },
579
+ { time: "16:00", price: 154.75 }
580
+ ];
581
+ const width = 600;
582
+ const height = 300;
583
+ const padding = 40;
584
+ const xScale = (width - 2 * padding) / (data.length - 1);
585
+ const yMin = Math.min(...data.map((d) => d.price));
586
+ const yMax = Math.max(...data.map((d) => d.price));
587
+ const yScale = (height - 2 * padding) / (yMax - yMin);
588
+ const points = data.map((d, i) => {
589
+ const x = padding + i * xScale;
590
+ const y = height - padding - (d.price - yMin) * yScale;
591
+ return `${x},${y}`;
592
+ }).join(" L ");
593
+ const svg = `<?xml version="1.0" encoding="UTF-8"?>
594
+ <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
595
+ <!-- Background -->
596
+ <rect width="100%" height="100%" fill="#f8f9fa"/>
597
+
598
+ <!-- Grid lines -->
599
+ <g stroke="#e9ecef" stroke-width="1">
600
+ ${Array.from({ length: 5 }, (_, i) => {
601
+ const y = padding + (height - 2 * padding) * i / 4;
602
+ return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
603
+ }).join("\n")}
604
+ </g>
605
+
606
+ <!-- Price line -->
607
+ <path d="M ${points}"
608
+ fill="none"
609
+ stroke="#007bff"
610
+ stroke-width="2"/>
611
+
612
+ <!-- Data points -->
613
+ ${data.map((d, i) => {
614
+ const x = padding + i * xScale;
615
+ const y = height - padding - (d.price - yMin) * yScale;
616
+ return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
617
+ }).join("\n")}
618
+
619
+ <!-- Labels -->
620
+ <g font-family="Arial" font-size="12" fill="#495057">
621
+ ${data.map((d, i) => {
622
+ const x = padding + i * xScale;
623
+ return `<text x="${x}" y="${height - padding + 20}" text-anchor="middle">${d.time}</text>`;
624
+ }).join("\n")}
625
+ ${Array.from({ length: 5 }, (_, i) => {
626
+ const y = padding + (height - 2 * padding) * i / 4;
627
+ const price = yMax - (yMax - yMin) * i / 4;
628
+ return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
629
+ }).join("\n")}
630
+ </g>
631
+
632
+ <!-- Title -->
633
+ <text x="${width / 2}" y="${padding / 2}"
634
+ font-family="Arial" font-size="16" font-weight="bold"
635
+ text-anchor="middle" fill="#212529">
636
+ ${symbol} - 1 Day Price Chart
637
+ </text>
638
+ </svg>`;
639
+ return {
640
+ contents: [
641
+ {
642
+ uri: uri.href,
643
+ text: svg
644
+ }
645
+ ]
646
+ };
647
+ }
648
+ );
707
649
  process.on("SIGINT", async () => {
708
650
  await this.server.close();
709
651
  process.exit(0);