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