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