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