fixparser-plugin-mcp 9.1.7-9eab5b4d → 9.1.7-a0e655a2
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 +596 -877
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +596 -867
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +46 -8
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +46 -8
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +4 -5
- package/types/MCPLocal.d.ts +0 -2
- package/types/schemas/index.d.ts +0 -30
- 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 -11
- package/types/tools/parse.d.ts +0 -5
- package/types/tools/parseToJSON.d.ts +0 -5
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,784 +1,20 @@
|
|
|
1
1
|
// src/MCPLocal.ts
|
|
2
|
-
import {
|
|
2
|
+
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Field, Fields, Messages } from "fixparser";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
// src/schemas/schemas.ts
|
|
8
|
-
var toolSchemas = {
|
|
9
|
-
parse: {
|
|
10
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
11
|
-
schema: {
|
|
12
|
-
type: "object",
|
|
13
|
-
properties: {
|
|
14
|
-
fixString: { type: "string" }
|
|
15
|
-
},
|
|
16
|
-
required: ["fixString"]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
parseToJSON: {
|
|
20
|
-
description: "Parses a FIX message into JSON",
|
|
21
|
-
schema: {
|
|
22
|
-
type: "object",
|
|
23
|
-
properties: {
|
|
24
|
-
fixString: { type: "string" }
|
|
25
|
-
},
|
|
26
|
-
required: ["fixString"]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
verifyOrder: {
|
|
30
|
-
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
31
|
-
schema: {
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: {
|
|
34
|
-
clOrdID: { type: "string" },
|
|
35
|
-
handlInst: {
|
|
36
|
-
type: "string",
|
|
37
|
-
enum: ["1", "2", "3"],
|
|
38
|
-
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
39
|
-
},
|
|
40
|
-
quantity: { type: "string" },
|
|
41
|
-
price: { type: "string" },
|
|
42
|
-
ordType: {
|
|
43
|
-
type: "string",
|
|
44
|
-
enum: [
|
|
45
|
-
"1",
|
|
46
|
-
"2",
|
|
47
|
-
"3",
|
|
48
|
-
"4",
|
|
49
|
-
"5",
|
|
50
|
-
"6",
|
|
51
|
-
"7",
|
|
52
|
-
"8",
|
|
53
|
-
"9",
|
|
54
|
-
"A",
|
|
55
|
-
"B",
|
|
56
|
-
"C",
|
|
57
|
-
"D",
|
|
58
|
-
"E",
|
|
59
|
-
"F",
|
|
60
|
-
"G",
|
|
61
|
-
"H",
|
|
62
|
-
"I",
|
|
63
|
-
"J",
|
|
64
|
-
"K",
|
|
65
|
-
"L",
|
|
66
|
-
"M",
|
|
67
|
-
"P",
|
|
68
|
-
"Q",
|
|
69
|
-
"R",
|
|
70
|
-
"S"
|
|
71
|
-
],
|
|
72
|
-
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"
|
|
73
|
-
},
|
|
74
|
-
side: {
|
|
75
|
-
type: "string",
|
|
76
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
77
|
-
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"
|
|
78
|
-
},
|
|
79
|
-
symbol: { type: "string" },
|
|
80
|
-
timeInForce: {
|
|
81
|
-
type: "string",
|
|
82
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
83
|
-
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"
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
executeOrder: {
|
|
90
|
-
description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
|
|
91
|
-
schema: {
|
|
92
|
-
type: "object",
|
|
93
|
-
properties: {
|
|
94
|
-
clOrdID: { type: "string" },
|
|
95
|
-
handlInst: {
|
|
96
|
-
type: "string",
|
|
97
|
-
enum: ["1", "2", "3"],
|
|
98
|
-
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
99
|
-
},
|
|
100
|
-
quantity: { type: "string" },
|
|
101
|
-
price: { type: "string" },
|
|
102
|
-
ordType: {
|
|
103
|
-
type: "string",
|
|
104
|
-
enum: [
|
|
105
|
-
"1",
|
|
106
|
-
"2",
|
|
107
|
-
"3",
|
|
108
|
-
"4",
|
|
109
|
-
"5",
|
|
110
|
-
"6",
|
|
111
|
-
"7",
|
|
112
|
-
"8",
|
|
113
|
-
"9",
|
|
114
|
-
"A",
|
|
115
|
-
"B",
|
|
116
|
-
"C",
|
|
117
|
-
"D",
|
|
118
|
-
"E",
|
|
119
|
-
"F",
|
|
120
|
-
"G",
|
|
121
|
-
"H",
|
|
122
|
-
"I",
|
|
123
|
-
"J",
|
|
124
|
-
"K",
|
|
125
|
-
"L",
|
|
126
|
-
"M",
|
|
127
|
-
"P",
|
|
128
|
-
"Q",
|
|
129
|
-
"R",
|
|
130
|
-
"S"
|
|
131
|
-
],
|
|
132
|
-
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"
|
|
133
|
-
},
|
|
134
|
-
side: {
|
|
135
|
-
type: "string",
|
|
136
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
137
|
-
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"
|
|
138
|
-
},
|
|
139
|
-
symbol: { type: "string" },
|
|
140
|
-
timeInForce: {
|
|
141
|
-
type: "string",
|
|
142
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
143
|
-
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"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
marketDataRequest: {
|
|
150
|
-
description: "Requests market data for specified symbols",
|
|
151
|
-
schema: {
|
|
152
|
-
type: "object",
|
|
153
|
-
properties: {
|
|
154
|
-
mdUpdateType: {
|
|
155
|
-
type: "string",
|
|
156
|
-
enum: ["0", "1"],
|
|
157
|
-
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
158
|
-
},
|
|
159
|
-
symbols: { type: "array", items: { type: "string" } },
|
|
160
|
-
mdReqID: { type: "string" },
|
|
161
|
-
subscriptionRequestType: {
|
|
162
|
-
type: "string",
|
|
163
|
-
enum: ["0", "1", "2"],
|
|
164
|
-
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
165
|
-
},
|
|
166
|
-
mdEntryTypes: {
|
|
167
|
-
type: "array",
|
|
168
|
-
items: {
|
|
169
|
-
type: "string",
|
|
170
|
-
enum: [
|
|
171
|
-
"0",
|
|
172
|
-
"1",
|
|
173
|
-
"2",
|
|
174
|
-
"3",
|
|
175
|
-
"4",
|
|
176
|
-
"5",
|
|
177
|
-
"6",
|
|
178
|
-
"7",
|
|
179
|
-
"8",
|
|
180
|
-
"9",
|
|
181
|
-
"A",
|
|
182
|
-
"B",
|
|
183
|
-
"C",
|
|
184
|
-
"D",
|
|
185
|
-
"E",
|
|
186
|
-
"F",
|
|
187
|
-
"G",
|
|
188
|
-
"H",
|
|
189
|
-
"I",
|
|
190
|
-
"J",
|
|
191
|
-
"K",
|
|
192
|
-
"L",
|
|
193
|
-
"M",
|
|
194
|
-
"N",
|
|
195
|
-
"O",
|
|
196
|
-
"P",
|
|
197
|
-
"Q",
|
|
198
|
-
"R",
|
|
199
|
-
"S",
|
|
200
|
-
"T",
|
|
201
|
-
"U",
|
|
202
|
-
"V",
|
|
203
|
-
"W",
|
|
204
|
-
"X",
|
|
205
|
-
"Y",
|
|
206
|
-
"Z"
|
|
207
|
-
]
|
|
208
|
-
},
|
|
209
|
-
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"
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
getStockGraph: {
|
|
216
|
-
description: "Generates a price chart for a given symbol",
|
|
217
|
-
schema: {
|
|
218
|
-
type: "object",
|
|
219
|
-
properties: {
|
|
220
|
-
symbol: { type: "string" }
|
|
221
|
-
},
|
|
222
|
-
required: ["symbol"]
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
getStockPriceHistory: {
|
|
226
|
-
description: "Returns price history for a given symbol",
|
|
227
|
-
schema: {
|
|
228
|
-
type: "object",
|
|
229
|
-
properties: {
|
|
230
|
-
symbol: { type: "string" }
|
|
231
|
-
},
|
|
232
|
-
required: ["symbol"]
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// src/tools/marketData.ts
|
|
238
|
-
import { Field, Fields, MDEntryType, Messages } from "fixparser";
|
|
239
|
-
import QuickChart from "quickchart-js";
|
|
240
|
-
var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
241
|
-
return async (args) => {
|
|
242
|
-
try {
|
|
243
|
-
const response = new Promise((resolve) => {
|
|
244
|
-
pendingRequests.set(args.mdReqID, resolve);
|
|
245
|
-
});
|
|
246
|
-
const entryTypes = args.mdEntryTypes || [MDEntryType.Bid, MDEntryType.Offer, MDEntryType.TradeVolume];
|
|
247
|
-
const messageFields = [
|
|
248
|
-
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
249
|
-
new Field(Fields.SenderCompID, parser.sender),
|
|
250
|
-
new Field(Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
251
|
-
new Field(Fields.TargetCompID, parser.target),
|
|
252
|
-
new Field(Fields.SendingTime, parser.getTimestamp()),
|
|
253
|
-
new Field(Fields.MDReqID, args.mdReqID),
|
|
254
|
-
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
255
|
-
new Field(Fields.MarketDepth, 0),
|
|
256
|
-
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
257
|
-
];
|
|
258
|
-
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
259
|
-
args.symbols.forEach((symbol) => {
|
|
260
|
-
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
261
|
-
});
|
|
262
|
-
messageFields.push(new Field(Fields.NoMDEntryTypes, entryTypes.length));
|
|
263
|
-
entryTypes.forEach((entryType) => {
|
|
264
|
-
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
265
|
-
});
|
|
266
|
-
const mdr = parser.createMessage(...messageFields);
|
|
267
|
-
if (!parser.connected) {
|
|
268
|
-
return {
|
|
269
|
-
content: [
|
|
270
|
-
{
|
|
271
|
-
type: "text",
|
|
272
|
-
text: "Error: Not connected. Ignoring message.",
|
|
273
|
-
uri: "marketDataRequest"
|
|
274
|
-
}
|
|
275
|
-
],
|
|
276
|
-
isError: true
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
parser.send(mdr);
|
|
280
|
-
const fixData = await response;
|
|
281
|
-
return {
|
|
282
|
-
content: [
|
|
283
|
-
{
|
|
284
|
-
type: "text",
|
|
285
|
-
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
286
|
-
uri: "marketDataRequest"
|
|
287
|
-
}
|
|
288
|
-
]
|
|
289
|
-
};
|
|
290
|
-
} catch (error) {
|
|
291
|
-
return {
|
|
292
|
-
content: [
|
|
293
|
-
{
|
|
294
|
-
type: "text",
|
|
295
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
296
|
-
uri: "marketDataRequest"
|
|
297
|
-
}
|
|
298
|
-
],
|
|
299
|
-
isError: true
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
305
|
-
return async (args) => {
|
|
306
|
-
try {
|
|
307
|
-
const symbol = args.symbol;
|
|
308
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
309
|
-
if (priceHistory.length === 0) {
|
|
310
|
-
return {
|
|
311
|
-
content: [
|
|
312
|
-
{
|
|
313
|
-
type: "text",
|
|
314
|
-
text: `No price data available for ${symbol}`,
|
|
315
|
-
uri: "getStockGraph"
|
|
316
|
-
}
|
|
317
|
-
]
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
const chart = new QuickChart();
|
|
321
|
-
chart.setWidth(600);
|
|
322
|
-
chart.setHeight(300);
|
|
323
|
-
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
324
|
-
const bidData = priceHistory.map((point) => point.bid);
|
|
325
|
-
const offerData = priceHistory.map((point) => point.offer);
|
|
326
|
-
const spreadData = priceHistory.map((point) => point.spread);
|
|
327
|
-
const volumeData = priceHistory.map((point) => point.volume);
|
|
328
|
-
const config = {
|
|
329
|
-
type: "line",
|
|
330
|
-
data: {
|
|
331
|
-
labels,
|
|
332
|
-
datasets: [
|
|
333
|
-
{
|
|
334
|
-
label: "Bid",
|
|
335
|
-
data: bidData,
|
|
336
|
-
borderColor: "#28a745",
|
|
337
|
-
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
338
|
-
fill: false,
|
|
339
|
-
tension: 0.4
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
label: "Offer",
|
|
343
|
-
data: offerData,
|
|
344
|
-
borderColor: "#dc3545",
|
|
345
|
-
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
346
|
-
fill: false,
|
|
347
|
-
tension: 0.4
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
label: "Spread",
|
|
351
|
-
data: spreadData,
|
|
352
|
-
borderColor: "#6c757d",
|
|
353
|
-
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
354
|
-
fill: false,
|
|
355
|
-
tension: 0.4
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
label: "Volume",
|
|
359
|
-
data: volumeData,
|
|
360
|
-
borderColor: "#007bff",
|
|
361
|
-
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
362
|
-
fill: true,
|
|
363
|
-
tension: 0.4
|
|
364
|
-
}
|
|
365
|
-
]
|
|
366
|
-
},
|
|
367
|
-
options: {
|
|
368
|
-
responsive: true,
|
|
369
|
-
plugins: {
|
|
370
|
-
title: {
|
|
371
|
-
display: true,
|
|
372
|
-
text: `${symbol} Market Data`
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
scales: {
|
|
376
|
-
y: {
|
|
377
|
-
beginAtZero: false
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
chart.setConfig(config);
|
|
383
|
-
const imageBuffer = await chart.toBinary();
|
|
384
|
-
const base64Image = imageBuffer.toString("base64");
|
|
385
|
-
return {
|
|
386
|
-
content: [
|
|
387
|
-
{
|
|
388
|
-
type: "image",
|
|
389
|
-
image: {
|
|
390
|
-
source: `data:image/png;base64,${base64Image}`
|
|
391
|
-
},
|
|
392
|
-
uri: "getStockGraph",
|
|
393
|
-
mimeType: "image/png"
|
|
394
|
-
}
|
|
395
|
-
]
|
|
396
|
-
};
|
|
397
|
-
} catch (error) {
|
|
398
|
-
return {
|
|
399
|
-
content: [
|
|
400
|
-
{
|
|
401
|
-
type: "text",
|
|
402
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
403
|
-
uri: "getStockGraph"
|
|
404
|
-
}
|
|
405
|
-
],
|
|
406
|
-
isError: true
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
};
|
|
411
|
-
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
412
|
-
return async (args) => {
|
|
413
|
-
try {
|
|
414
|
-
const symbol = args.symbol;
|
|
415
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
416
|
-
if (priceHistory.length === 0) {
|
|
417
|
-
return {
|
|
418
|
-
content: [
|
|
419
|
-
{
|
|
420
|
-
type: "text",
|
|
421
|
-
text: `No price data available for ${symbol}`,
|
|
422
|
-
uri: "getStockPriceHistory"
|
|
423
|
-
}
|
|
424
|
-
]
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
return {
|
|
428
|
-
content: [
|
|
429
|
-
{
|
|
430
|
-
type: "text",
|
|
431
|
-
text: JSON.stringify(
|
|
432
|
-
{
|
|
433
|
-
symbol,
|
|
434
|
-
count: priceHistory.length,
|
|
435
|
-
data: priceHistory.map((point) => ({
|
|
436
|
-
timestamp: new Date(point.timestamp).toISOString(),
|
|
437
|
-
bid: point.bid,
|
|
438
|
-
offer: point.offer,
|
|
439
|
-
spread: point.spread,
|
|
440
|
-
volume: point.volume
|
|
441
|
-
}))
|
|
442
|
-
},
|
|
443
|
-
null,
|
|
444
|
-
2
|
|
445
|
-
),
|
|
446
|
-
uri: "getStockPriceHistory"
|
|
447
|
-
}
|
|
448
|
-
]
|
|
449
|
-
};
|
|
450
|
-
} catch (error) {
|
|
451
|
-
return {
|
|
452
|
-
content: [
|
|
453
|
-
{
|
|
454
|
-
type: "text",
|
|
455
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
456
|
-
uri: "getStockPriceHistory"
|
|
457
|
-
}
|
|
458
|
-
],
|
|
459
|
-
isError: true
|
|
460
|
-
};
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
// src/tools/order.ts
|
|
466
|
-
import { Field as Field2, Fields as Fields2, Messages as Messages2 } from "fixparser";
|
|
467
|
-
var ordTypeNames = {
|
|
468
|
-
"1": "Market",
|
|
469
|
-
"2": "Limit",
|
|
470
|
-
"3": "Stop",
|
|
471
|
-
"4": "StopLimit",
|
|
472
|
-
"5": "MarketOnClose",
|
|
473
|
-
"6": "WithOrWithout",
|
|
474
|
-
"7": "LimitOrBetter",
|
|
475
|
-
"8": "LimitWithOrWithout",
|
|
476
|
-
"9": "OnBasis",
|
|
477
|
-
A: "OnClose",
|
|
478
|
-
B: "LimitOnClose",
|
|
479
|
-
C: "ForexMarket",
|
|
480
|
-
D: "PreviouslyQuoted",
|
|
481
|
-
E: "PreviouslyIndicated",
|
|
482
|
-
F: "ForexLimit",
|
|
483
|
-
G: "ForexSwap",
|
|
484
|
-
H: "ForexPreviouslyQuoted",
|
|
485
|
-
I: "Funari",
|
|
486
|
-
J: "MarketIfTouched",
|
|
487
|
-
K: "MarketWithLeftOverAsLimit",
|
|
488
|
-
L: "PreviousFundValuationPoint",
|
|
489
|
-
M: "NextFundValuationPoint",
|
|
490
|
-
P: "Pegged",
|
|
491
|
-
Q: "CounterOrderSelection",
|
|
492
|
-
R: "StopOnBidOrOffer",
|
|
493
|
-
S: "StopLimitOnBidOrOffer"
|
|
494
|
-
};
|
|
495
|
-
var sideNames = {
|
|
496
|
-
"1": "Buy",
|
|
497
|
-
"2": "Sell",
|
|
498
|
-
"3": "BuyMinus",
|
|
499
|
-
"4": "SellPlus",
|
|
500
|
-
"5": "SellShort",
|
|
501
|
-
"6": "SellShortExempt",
|
|
502
|
-
"7": "Undisclosed",
|
|
503
|
-
"8": "Cross",
|
|
504
|
-
"9": "CrossShort",
|
|
505
|
-
A: "CrossShortExempt",
|
|
506
|
-
B: "AsDefined",
|
|
507
|
-
C: "Opposite",
|
|
508
|
-
D: "Subscribe",
|
|
509
|
-
E: "Redeem",
|
|
510
|
-
F: "Lend",
|
|
511
|
-
G: "Borrow",
|
|
512
|
-
H: "SellUndisclosed"
|
|
513
|
-
};
|
|
514
|
-
var timeInForceNames = {
|
|
515
|
-
"0": "Day",
|
|
516
|
-
"1": "GoodTillCancel",
|
|
517
|
-
"2": "AtTheOpening",
|
|
518
|
-
"3": "ImmediateOrCancel",
|
|
519
|
-
"4": "FillOrKill",
|
|
520
|
-
"5": "GoodTillCrossing",
|
|
521
|
-
"6": "GoodTillDate",
|
|
522
|
-
"7": "AtTheClose",
|
|
523
|
-
"8": "GoodThroughCrossing",
|
|
524
|
-
"9": "AtCrossing",
|
|
525
|
-
A: "GoodForTime",
|
|
526
|
-
B: "GoodForAuction",
|
|
527
|
-
C: "GoodForMonth"
|
|
528
|
-
};
|
|
529
|
-
var handlInstNames = {
|
|
530
|
-
"1": "AutomatedExecutionNoIntervention",
|
|
531
|
-
"2": "AutomatedExecutionInterventionOK",
|
|
532
|
-
"3": "ManualOrder"
|
|
533
|
-
};
|
|
534
|
-
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
535
|
-
return async (args) => {
|
|
536
|
-
try {
|
|
537
|
-
verifiedOrders.set(args.clOrdID, {
|
|
538
|
-
clOrdID: args.clOrdID,
|
|
539
|
-
handlInst: args.handlInst,
|
|
540
|
-
quantity: Number.parseFloat(String(args.quantity)),
|
|
541
|
-
price: Number.parseFloat(String(args.price)),
|
|
542
|
-
ordType: args.ordType,
|
|
543
|
-
side: args.side,
|
|
544
|
-
symbol: args.symbol,
|
|
545
|
-
timeInForce: args.timeInForce
|
|
546
|
-
});
|
|
547
|
-
return {
|
|
548
|
-
content: [
|
|
549
|
-
{
|
|
550
|
-
type: "text",
|
|
551
|
-
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
552
|
-
|
|
553
|
-
Parameters verified:
|
|
554
|
-
- ClOrdID: ${args.clOrdID}
|
|
555
|
-
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
556
|
-
- Quantity: ${args.quantity}
|
|
557
|
-
- Price: ${args.price}
|
|
558
|
-
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
559
|
-
- Side: ${args.side} (${sideNames[args.side]})
|
|
560
|
-
- Symbol: ${args.symbol}
|
|
561
|
-
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
562
|
-
|
|
563
|
-
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
564
|
-
uri: "verifyOrder"
|
|
565
|
-
}
|
|
566
|
-
]
|
|
567
|
-
};
|
|
568
|
-
} catch (error) {
|
|
569
|
-
return {
|
|
570
|
-
content: [
|
|
571
|
-
{
|
|
572
|
-
type: "text",
|
|
573
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
574
|
-
uri: "verifyOrder"
|
|
575
|
-
}
|
|
576
|
-
],
|
|
577
|
-
isError: true
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
};
|
|
582
|
-
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
583
|
-
return async (args) => {
|
|
584
|
-
try {
|
|
585
|
-
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
586
|
-
if (!verifiedOrder) {
|
|
587
|
-
return {
|
|
588
|
-
content: [
|
|
589
|
-
{
|
|
590
|
-
type: "text",
|
|
591
|
-
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
592
|
-
uri: "executeOrder"
|
|
593
|
-
}
|
|
594
|
-
],
|
|
595
|
-
isError: true
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
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) {
|
|
599
|
-
return {
|
|
600
|
-
content: [
|
|
601
|
-
{
|
|
602
|
-
type: "text",
|
|
603
|
-
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
604
|
-
uri: "executeOrder"
|
|
605
|
-
}
|
|
606
|
-
],
|
|
607
|
-
isError: true
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
const response = new Promise((resolve) => {
|
|
611
|
-
pendingRequests.set(args.clOrdID, resolve);
|
|
612
|
-
});
|
|
613
|
-
const order = parser.createMessage(
|
|
614
|
-
new Field2(Fields2.MsgType, Messages2.NewOrderSingle),
|
|
615
|
-
new Field2(Fields2.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
616
|
-
new Field2(Fields2.SenderCompID, parser.sender),
|
|
617
|
-
new Field2(Fields2.TargetCompID, parser.target),
|
|
618
|
-
new Field2(Fields2.SendingTime, parser.getTimestamp()),
|
|
619
|
-
new Field2(Fields2.ClOrdID, args.clOrdID),
|
|
620
|
-
new Field2(Fields2.Side, args.side),
|
|
621
|
-
new Field2(Fields2.Symbol, args.symbol),
|
|
622
|
-
new Field2(Fields2.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
623
|
-
new Field2(Fields2.Price, Number.parseFloat(String(args.price))),
|
|
624
|
-
new Field2(Fields2.OrdType, args.ordType),
|
|
625
|
-
new Field2(Fields2.HandlInst, args.handlInst),
|
|
626
|
-
new Field2(Fields2.TimeInForce, args.timeInForce),
|
|
627
|
-
new Field2(Fields2.TransactTime, parser.getTimestamp())
|
|
628
|
-
);
|
|
629
|
-
if (!parser.connected) {
|
|
630
|
-
return {
|
|
631
|
-
content: [
|
|
632
|
-
{
|
|
633
|
-
type: "text",
|
|
634
|
-
text: "Error: Not connected. Ignoring message.",
|
|
635
|
-
uri: "executeOrder"
|
|
636
|
-
}
|
|
637
|
-
],
|
|
638
|
-
isError: true
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
parser.send(order);
|
|
642
|
-
const fixData = await response;
|
|
643
|
-
verifiedOrders.delete(args.clOrdID);
|
|
644
|
-
return {
|
|
645
|
-
content: [
|
|
646
|
-
{
|
|
647
|
-
type: "text",
|
|
648
|
-
text: fixData.messageType === Messages2.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
649
|
-
uri: "executeOrder"
|
|
650
|
-
}
|
|
651
|
-
]
|
|
652
|
-
};
|
|
653
|
-
} catch (error) {
|
|
654
|
-
return {
|
|
655
|
-
content: [
|
|
656
|
-
{
|
|
657
|
-
type: "text",
|
|
658
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
659
|
-
uri: "executeOrder"
|
|
660
|
-
}
|
|
661
|
-
],
|
|
662
|
-
isError: true
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
// src/tools/parse.ts
|
|
669
|
-
var createParseHandler = (parser) => {
|
|
670
|
-
return async (args) => {
|
|
671
|
-
try {
|
|
672
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
673
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
674
|
-
return {
|
|
675
|
-
content: [
|
|
676
|
-
{
|
|
677
|
-
type: "text",
|
|
678
|
-
text: "Error: Failed to parse FIX string",
|
|
679
|
-
uri: "parse"
|
|
680
|
-
}
|
|
681
|
-
],
|
|
682
|
-
isError: true
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
return {
|
|
686
|
-
content: [
|
|
687
|
-
{
|
|
688
|
-
type: "text",
|
|
689
|
-
text: `${parsedMessage[0].description}
|
|
690
|
-
${parsedMessage[0].messageTypeDescription}`,
|
|
691
|
-
uri: "parse"
|
|
692
|
-
}
|
|
693
|
-
]
|
|
694
|
-
};
|
|
695
|
-
} catch (error) {
|
|
696
|
-
return {
|
|
697
|
-
content: [
|
|
698
|
-
{
|
|
699
|
-
type: "text",
|
|
700
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
701
|
-
uri: "parse"
|
|
702
|
-
}
|
|
703
|
-
],
|
|
704
|
-
isError: true
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
// src/tools/parseToJSON.ts
|
|
711
|
-
var createParseToJSONHandler = (parser) => {
|
|
712
|
-
return async (args) => {
|
|
713
|
-
try {
|
|
714
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
715
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
716
|
-
return {
|
|
717
|
-
content: [
|
|
718
|
-
{
|
|
719
|
-
type: "text",
|
|
720
|
-
text: "Error: Failed to parse FIX string",
|
|
721
|
-
uri: "parseToJSON"
|
|
722
|
-
}
|
|
723
|
-
],
|
|
724
|
-
isError: true
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
return {
|
|
728
|
-
content: [
|
|
729
|
-
{
|
|
730
|
-
type: "text",
|
|
731
|
-
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
732
|
-
uri: "parseToJSON"
|
|
733
|
-
}
|
|
734
|
-
]
|
|
735
|
-
};
|
|
736
|
-
} catch (error) {
|
|
737
|
-
return {
|
|
738
|
-
content: [
|
|
739
|
-
{
|
|
740
|
-
type: "text",
|
|
741
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
742
|
-
uri: "parseToJSON"
|
|
743
|
-
}
|
|
744
|
-
],
|
|
745
|
-
isError: true
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
};
|
|
749
|
-
};
|
|
750
|
-
|
|
751
|
-
// src/tools/index.ts
|
|
752
|
-
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
753
|
-
parse: createParseHandler(parser),
|
|
754
|
-
parseToJSON: createParseToJSONHandler(parser),
|
|
755
|
-
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
756
|
-
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
757
|
-
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
758
|
-
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
759
|
-
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
// src/MCPLocal.ts
|
|
763
6
|
var MCPLocal = class {
|
|
764
7
|
parser;
|
|
765
|
-
server = new
|
|
8
|
+
server = new McpServer(
|
|
766
9
|
{
|
|
767
10
|
name: "fixparser",
|
|
768
11
|
version: "1.0.0"
|
|
769
12
|
},
|
|
770
13
|
{
|
|
771
14
|
capabilities: {
|
|
772
|
-
tools:
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
description,
|
|
776
|
-
parameters: schema
|
|
777
|
-
};
|
|
778
|
-
return acc;
|
|
779
|
-
},
|
|
780
|
-
{}
|
|
781
|
-
)
|
|
15
|
+
tools: {},
|
|
16
|
+
prompts: {},
|
|
17
|
+
resources: {}
|
|
782
18
|
}
|
|
783
19
|
}
|
|
784
20
|
);
|
|
@@ -786,77 +22,23 @@ var MCPLocal = class {
|
|
|
786
22
|
onReady = void 0;
|
|
787
23
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
788
24
|
verifiedOrders = /* @__PURE__ */ new Map();
|
|
789
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
790
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
791
|
-
// Maximum number of price points to store per symbol
|
|
792
25
|
constructor({ logger, onReady }) {
|
|
793
26
|
if (onReady) this.onReady = onReady;
|
|
794
27
|
}
|
|
795
28
|
async register(parser) {
|
|
796
29
|
this.parser = parser;
|
|
797
30
|
this.parser.addOnMessageCallback((message) => {
|
|
798
|
-
this.parser?.logger.log({
|
|
799
|
-
level: "info",
|
|
800
|
-
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
801
|
-
});
|
|
802
31
|
const msgType = message.messageType;
|
|
803
|
-
if (msgType ===
|
|
804
|
-
this.parser?.logger.log({
|
|
805
|
-
level: "info",
|
|
806
|
-
message: `MCP Server handling message type: ${msgType}`
|
|
807
|
-
});
|
|
32
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject) {
|
|
808
33
|
let id;
|
|
809
|
-
if (msgType ===
|
|
810
|
-
const
|
|
811
|
-
const entryType = message.getField(Fields3.MDEntryType);
|
|
812
|
-
const price = message.getField(Fields3.MDEntryPx);
|
|
813
|
-
const size = message.getField(Fields3.MDEntrySize);
|
|
814
|
-
const timestamp = message.getField(Fields3.MDEntryTime)?.value || Date.now();
|
|
815
|
-
if (symbol?.value && price?.value) {
|
|
816
|
-
const symbolStr = String(symbol.value);
|
|
817
|
-
const priceNum = Number(price.value);
|
|
818
|
-
const sizeNum = size?.value ? Number(size.value) : 0;
|
|
819
|
-
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
820
|
-
const lastEntry = priceHistory[priceHistory.length - 1] || {
|
|
821
|
-
timestamp: 0,
|
|
822
|
-
bid: 0,
|
|
823
|
-
offer: 0,
|
|
824
|
-
spread: 0,
|
|
825
|
-
volume: 0
|
|
826
|
-
};
|
|
827
|
-
const newEntry = {
|
|
828
|
-
timestamp: Number(timestamp),
|
|
829
|
-
bid: entryType?.value === MDEntryType2.Bid ? priceNum : lastEntry.bid,
|
|
830
|
-
offer: entryType?.value === MDEntryType2.Offer ? priceNum : lastEntry.offer,
|
|
831
|
-
spread: entryType?.value === MDEntryType2.Offer ? priceNum - lastEntry.bid : entryType?.value === MDEntryType2.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
|
|
832
|
-
volume: entryType?.value === MDEntryType2.TradeVolume ? sizeNum : lastEntry.volume
|
|
833
|
-
};
|
|
834
|
-
priceHistory.push(newEntry);
|
|
835
|
-
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
836
|
-
priceHistory.shift();
|
|
837
|
-
}
|
|
838
|
-
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
839
|
-
this.parser?.logger.log({
|
|
840
|
-
level: "info",
|
|
841
|
-
message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
|
|
842
|
-
});
|
|
843
|
-
this.server.notification({
|
|
844
|
-
method: "priceUpdate",
|
|
845
|
-
params: {
|
|
846
|
-
symbol: symbolStr,
|
|
847
|
-
...newEntry
|
|
848
|
-
}
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
if (msgType === Messages3.MarketDataSnapshotFullRefresh) {
|
|
853
|
-
const mdReqID = message.getField(Fields3.MDReqID);
|
|
34
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
35
|
+
const mdReqID = message.getField(Fields.MDReqID);
|
|
854
36
|
if (mdReqID) id = String(mdReqID.value);
|
|
855
|
-
} else if (msgType ===
|
|
856
|
-
const clOrdID = message.getField(
|
|
37
|
+
} else if (msgType === Messages.ExecutionReport) {
|
|
38
|
+
const clOrdID = message.getField(Fields.ClOrdID);
|
|
857
39
|
if (clOrdID) id = String(clOrdID.value);
|
|
858
|
-
} else if (msgType ===
|
|
859
|
-
const refSeqNum = message.getField(
|
|
40
|
+
} else if (msgType === Messages.Reject) {
|
|
41
|
+
const refSeqNum = message.getField(Fields.RefSeqNum);
|
|
860
42
|
if (refSeqNum) id = String(refSeqNum.value);
|
|
861
43
|
}
|
|
862
44
|
if (id) {
|
|
@@ -881,54 +63,601 @@ var MCPLocal = class {
|
|
|
881
63
|
if (!this.server) {
|
|
882
64
|
return;
|
|
883
65
|
}
|
|
884
|
-
this.server.
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
66
|
+
this.server.tool(
|
|
67
|
+
"parse",
|
|
68
|
+
"Parses a FIX message and describes it in plain language",
|
|
69
|
+
{
|
|
70
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
71
|
+
},
|
|
72
|
+
async (args) => {
|
|
73
|
+
try {
|
|
74
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
75
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
78
|
+
isError: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: `${parsedMessage[0].description}
|
|
86
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: "text",
|
|
95
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
isError: true
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
this.server.tool(
|
|
104
|
+
"parseToJSON",
|
|
105
|
+
"Parses a FIX message into JSON",
|
|
106
|
+
{
|
|
107
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
108
|
+
},
|
|
109
|
+
async (args) => {
|
|
110
|
+
try {
|
|
111
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
112
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
115
|
+
isError: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
return {
|
|
128
|
+
content: [
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
isError: true
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
this.server.tool(
|
|
140
|
+
"verifyOrder",
|
|
141
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
142
|
+
{
|
|
143
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
144
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
145
|
+
quantity: z.string().describe("Order quantity"),
|
|
146
|
+
price: z.string().describe("Order price"),
|
|
147
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
148
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
149
|
+
symbol: z.string().describe("Trading symbol"),
|
|
150
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
151
|
+
},
|
|
152
|
+
async (args) => {
|
|
153
|
+
try {
|
|
154
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
155
|
+
clOrdID: args.clOrdID,
|
|
156
|
+
handlInst: args.handlInst,
|
|
157
|
+
quantity: Number.parseFloat(args.quantity),
|
|
158
|
+
price: Number.parseFloat(args.price),
|
|
159
|
+
ordType: args.ordType,
|
|
160
|
+
side: args.side,
|
|
161
|
+
symbol: args.symbol,
|
|
162
|
+
timeInForce: args.timeInForce
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
type: "text",
|
|
168
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
169
|
+
|
|
170
|
+
Parameters verified:
|
|
171
|
+
- ClOrdID: ${args.clOrdID}
|
|
172
|
+
- HandlInst: ${args.handlInst}
|
|
173
|
+
- Quantity: ${args.quantity}
|
|
174
|
+
- Price: ${args.price}
|
|
175
|
+
- OrdType: ${args.ordType}
|
|
176
|
+
- Side: ${args.side}
|
|
177
|
+
- Symbol: ${args.symbol}
|
|
178
|
+
- TimeInForce: ${args.timeInForce}
|
|
179
|
+
|
|
180
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
};
|
|
184
|
+
} catch (error) {
|
|
185
|
+
return {
|
|
186
|
+
content: [
|
|
187
|
+
{
|
|
188
|
+
type: "text",
|
|
189
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
isError: true
|
|
193
|
+
};
|
|
194
|
+
}
|
|
894
195
|
}
|
|
895
196
|
);
|
|
896
|
-
this.server.
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
this.verifiedOrders
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
197
|
+
this.server.tool(
|
|
198
|
+
"executeOrder",
|
|
199
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
200
|
+
{
|
|
201
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
202
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
203
|
+
quantity: z.string().describe("Order quantity"),
|
|
204
|
+
price: z.string().describe("Order price"),
|
|
205
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
206
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
207
|
+
symbol: z.string().describe("Trading symbol"),
|
|
208
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
209
|
+
},
|
|
210
|
+
async (args) => {
|
|
211
|
+
try {
|
|
212
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
213
|
+
if (!verifiedOrder) {
|
|
214
|
+
return {
|
|
215
|
+
content: [
|
|
216
|
+
{
|
|
217
|
+
type: "text",
|
|
218
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
isError: true
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
|
|
225
|
+
return {
|
|
226
|
+
content: [
|
|
227
|
+
{
|
|
228
|
+
type: "text",
|
|
229
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
isError: true
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
const response = new Promise((resolve) => {
|
|
236
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
237
|
+
});
|
|
238
|
+
const order = this.parser?.createMessage(
|
|
239
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
240
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
241
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
242
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
243
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
244
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
245
|
+
new Field(Fields.Side, args.side),
|
|
246
|
+
new Field(Fields.Symbol, args.symbol),
|
|
247
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
248
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
249
|
+
new Field(Fields.OrdType, args.ordType),
|
|
250
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
251
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
252
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
253
|
+
);
|
|
254
|
+
if (!this.parser?.connected) {
|
|
255
|
+
return {
|
|
256
|
+
content: [
|
|
257
|
+
{
|
|
258
|
+
type: "text",
|
|
259
|
+
text: "Error: Not connected. Ignoring message."
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
isError: true
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
this.parser?.send(order);
|
|
266
|
+
const fixData = await response;
|
|
267
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
268
|
+
return {
|
|
269
|
+
content: [
|
|
270
|
+
{
|
|
271
|
+
type: "text",
|
|
272
|
+
text: fixData.messageType === Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
};
|
|
276
|
+
} catch (error) {
|
|
917
277
|
return {
|
|
918
278
|
content: [
|
|
919
279
|
{
|
|
920
280
|
type: "text",
|
|
921
|
-
text: `
|
|
922
|
-
uri: name
|
|
281
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
923
282
|
}
|
|
924
283
|
],
|
|
925
284
|
isError: true
|
|
926
285
|
};
|
|
927
286
|
}
|
|
928
|
-
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
this.server.tool(
|
|
290
|
+
"marketDataRequest",
|
|
291
|
+
"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
292
|
+
{
|
|
293
|
+
mdUpdateType: z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
294
|
+
symbol: z.string().describe("Trading symbol"),
|
|
295
|
+
mdReqID: z.string().describe("Market data request ID"),
|
|
296
|
+
subscriptionRequestType: z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
297
|
+
mdEntryType: z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
298
|
+
},
|
|
299
|
+
async (args) => {
|
|
300
|
+
try {
|
|
301
|
+
const response = new Promise((resolve) => {
|
|
302
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
303
|
+
});
|
|
304
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
305
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
306
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
307
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
308
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
309
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
310
|
+
new Field(Fields.MarketDepth, 0),
|
|
311
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType),
|
|
312
|
+
new Field(Fields.NoRelatedSym, 1),
|
|
313
|
+
new Field(Fields.Symbol, args.symbol),
|
|
314
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
315
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
316
|
+
new Field(Fields.NoMDEntryTypes, 1),
|
|
317
|
+
new Field(Fields.MDEntryType, args.mdEntryType)
|
|
318
|
+
);
|
|
319
|
+
if (!this.parser?.connected) {
|
|
320
|
+
return {
|
|
321
|
+
content: [
|
|
322
|
+
{
|
|
323
|
+
type: "text",
|
|
324
|
+
text: "Error: Not connected. Ignoring message."
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
isError: true
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
this.parser?.send(marketDataRequest);
|
|
331
|
+
const fixData = await response;
|
|
332
|
+
return {
|
|
333
|
+
content: [
|
|
334
|
+
{
|
|
335
|
+
type: "text",
|
|
336
|
+
text: `Market data for ${args.symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
};
|
|
340
|
+
} catch (error) {
|
|
341
|
+
return {
|
|
342
|
+
content: [
|
|
343
|
+
{
|
|
344
|
+
type: "text",
|
|
345
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
isError: true
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
this.server.prompt(
|
|
354
|
+
"parse",
|
|
355
|
+
"Parses a FIX message and describes it in plain language",
|
|
356
|
+
{
|
|
357
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
358
|
+
},
|
|
359
|
+
async (args) => {
|
|
360
|
+
return {
|
|
361
|
+
messages: [
|
|
362
|
+
{
|
|
363
|
+
role: "user",
|
|
364
|
+
content: {
|
|
365
|
+
type: "text",
|
|
366
|
+
text: `Please parse and explain this FIX message: ${args.fixString}`
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
]
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
);
|
|
373
|
+
this.server.prompt(
|
|
374
|
+
"parseToJSON",
|
|
375
|
+
"Parses a FIX message into JSON",
|
|
376
|
+
{
|
|
377
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
378
|
+
},
|
|
379
|
+
async (args) => {
|
|
380
|
+
return {
|
|
381
|
+
messages: [
|
|
382
|
+
{
|
|
383
|
+
role: "user",
|
|
384
|
+
content: {
|
|
385
|
+
type: "text",
|
|
386
|
+
text: `Please parse the FIX message to JSON: ${args.fixString}`
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
]
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
this.server.prompt(
|
|
394
|
+
"verifyOrder",
|
|
395
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
396
|
+
{
|
|
397
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
398
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
399
|
+
quantity: z.string().describe("Order quantity"),
|
|
400
|
+
price: z.string().describe("Order price"),
|
|
401
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
402
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
403
|
+
symbol: z.string().describe("Trading symbol"),
|
|
404
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
405
|
+
},
|
|
406
|
+
async (args) => {
|
|
929
407
|
return {
|
|
930
|
-
|
|
931
|
-
|
|
408
|
+
messages: [
|
|
409
|
+
{
|
|
410
|
+
role: "user",
|
|
411
|
+
content: {
|
|
412
|
+
type: "text",
|
|
413
|
+
text: [
|
|
414
|
+
"You are an AI assistant that helps users verify FIX New Order Single parameters.",
|
|
415
|
+
"This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.",
|
|
416
|
+
"",
|
|
417
|
+
"You must verify that all required fields are provided and valid:",
|
|
418
|
+
"- ClOrdID (Client Order ID)",
|
|
419
|
+
"- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
420
|
+
"- Quantity (Order quantity)",
|
|
421
|
+
"- Price (Order price)",
|
|
422
|
+
"- OrdType (1=Market, 2=Limit, 3=Stop)",
|
|
423
|
+
"- Side (1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed)",
|
|
424
|
+
"- Symbol (Trading symbol)",
|
|
425
|
+
"- TimeInForce (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",
|
|
426
|
+
"",
|
|
427
|
+
"Current parameters to verify:",
|
|
428
|
+
`- ClOrdID: ${args.clOrdID}`,
|
|
429
|
+
`- HandlInst: ${args.handlInst}`,
|
|
430
|
+
`- Quantity: ${args.quantity}`,
|
|
431
|
+
`- Price: ${args.price}`,
|
|
432
|
+
`- OrdType: ${args.ordType}`,
|
|
433
|
+
`- Side: ${args.side}`,
|
|
434
|
+
`- Symbol: ${args.symbol}`,
|
|
435
|
+
`- TimeInForce: ${args.timeInForce}`,
|
|
436
|
+
"",
|
|
437
|
+
"If all parameters are valid, respond with:",
|
|
438
|
+
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
439
|
+
"",
|
|
440
|
+
"Otherwise, list the missing or invalid ones.",
|
|
441
|
+
"",
|
|
442
|
+
"IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."
|
|
443
|
+
].join("\n")
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
]
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
this.server.prompt(
|
|
451
|
+
"executeOrder",
|
|
452
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
453
|
+
{
|
|
454
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
455
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
456
|
+
quantity: z.string().describe("Order quantity"),
|
|
457
|
+
price: z.string().describe("Order price"),
|
|
458
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
459
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
460
|
+
symbol: z.string().describe("Trading symbol"),
|
|
461
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
462
|
+
},
|
|
463
|
+
async (args) => {
|
|
464
|
+
return {
|
|
465
|
+
messages: [
|
|
466
|
+
{
|
|
467
|
+
role: "user",
|
|
468
|
+
content: {
|
|
469
|
+
type: "text",
|
|
470
|
+
text: [
|
|
471
|
+
"You are an AI assistant that helps users execute FIX New Order Single messages.",
|
|
472
|
+
"This is STEP 2 of 2 - EXECUTION. This will send the order to the market.",
|
|
473
|
+
"",
|
|
474
|
+
"IMPORTANT: This tool should only be called after successful verification of all parameters.",
|
|
475
|
+
"",
|
|
476
|
+
"Parameters to execute:",
|
|
477
|
+
`- ClOrdID: ${args.clOrdID}`,
|
|
478
|
+
`- HandlInst: ${args.handlInst}`,
|
|
479
|
+
`- Quantity: ${args.quantity}`,
|
|
480
|
+
`- Price: ${args.price}`,
|
|
481
|
+
`- OrdType: ${args.ordType}`,
|
|
482
|
+
`- Side: ${args.side}`,
|
|
483
|
+
`- Symbol: ${args.symbol}`,
|
|
484
|
+
`- TimeInForce: ${args.timeInForce}`,
|
|
485
|
+
"",
|
|
486
|
+
"IMPORTANT: The response will be either:",
|
|
487
|
+
"1. An Execution Report (MsgType=8) if the order was successfully placed",
|
|
488
|
+
"2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
|
|
489
|
+
].join("\n")
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
]
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
this.server.prompt(
|
|
497
|
+
"marketDataRequest",
|
|
498
|
+
"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
499
|
+
{
|
|
500
|
+
mdUpdateType: z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
501
|
+
symbol: z.string().describe("Trading symbol"),
|
|
502
|
+
mdReqID: z.string().describe("Market data request ID"),
|
|
503
|
+
subscriptionRequestType: z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
504
|
+
mdEntryType: z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
505
|
+
},
|
|
506
|
+
async (args) => {
|
|
507
|
+
return {
|
|
508
|
+
messages: [
|
|
509
|
+
{
|
|
510
|
+
role: "user",
|
|
511
|
+
content: {
|
|
512
|
+
type: "text",
|
|
513
|
+
text: [
|
|
514
|
+
"You are an AI assistant that helps users create FIX Market Data Request messages.",
|
|
515
|
+
"You must **first verify** that all required fields are provided:",
|
|
516
|
+
"- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
|
|
517
|
+
"- Symbol (Trading symbol)",
|
|
518
|
+
"- MDReqID (Market data request ID)",
|
|
519
|
+
"- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
520
|
+
"- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
521
|
+
"",
|
|
522
|
+
"Only when all fields are present and valid, respond with:",
|
|
523
|
+
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
524
|
+
"",
|
|
525
|
+
"Otherwise, list the missing or invalid ones.",
|
|
526
|
+
"",
|
|
527
|
+
"Do not create the FIX message until verification is complete.",
|
|
528
|
+
"",
|
|
529
|
+
"Current parameters:",
|
|
530
|
+
`- MDUpdateType: ${args.mdUpdateType}`,
|
|
531
|
+
`- Symbol: ${args.symbol}`,
|
|
532
|
+
`- MDReqID: ${args.mdReqID}`,
|
|
533
|
+
`- SubscriptionRequestType: ${args.subscriptionRequestType}`,
|
|
534
|
+
`- MDEntryType: ${args.mdEntryType}`
|
|
535
|
+
].join("\n")
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
]
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
this.server.resource(
|
|
543
|
+
"greeting-resource",
|
|
544
|
+
"https://example.com/greetings/default",
|
|
545
|
+
{ mimeType: "text/plain" },
|
|
546
|
+
async () => {
|
|
547
|
+
return {
|
|
548
|
+
contents: [
|
|
549
|
+
{
|
|
550
|
+
uri: "https://example.com/greetings/default",
|
|
551
|
+
text: "Hello, world!"
|
|
552
|
+
}
|
|
553
|
+
]
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
);
|
|
557
|
+
this.server.resource(
|
|
558
|
+
"greeting",
|
|
559
|
+
new ResourceTemplate("greeting://{name}", { list: void 0 }),
|
|
560
|
+
async (uri, { name }) => ({
|
|
561
|
+
contents: [
|
|
562
|
+
{
|
|
563
|
+
uri: uri.href,
|
|
564
|
+
text: `Hello, ${name}!`
|
|
565
|
+
}
|
|
566
|
+
]
|
|
567
|
+
})
|
|
568
|
+
);
|
|
569
|
+
this.server.resource(
|
|
570
|
+
"echo",
|
|
571
|
+
new ResourceTemplate("echo://{message}", { list: void 0 }),
|
|
572
|
+
async (uri, { message }) => ({
|
|
573
|
+
contents: [
|
|
574
|
+
{
|
|
575
|
+
uri: uri.href,
|
|
576
|
+
text: `Resource echo: ${message}`
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
})
|
|
580
|
+
);
|
|
581
|
+
this.server.resource(
|
|
582
|
+
"stockGraph",
|
|
583
|
+
new ResourceTemplate("stock://{symbol}", { list: void 0 }),
|
|
584
|
+
async (uri, variables) => {
|
|
585
|
+
const symbol = variables.symbol;
|
|
586
|
+
const data = [
|
|
587
|
+
{ time: "09:30", price: 150 },
|
|
588
|
+
{ time: "10:30", price: 152.5 },
|
|
589
|
+
{ time: "11:30", price: 151.75 },
|
|
590
|
+
{ time: "12:30", price: 153.25 },
|
|
591
|
+
{ time: "13:30", price: 154 },
|
|
592
|
+
{ time: "14:30", price: 153.5 },
|
|
593
|
+
{ time: "15:30", price: 155 },
|
|
594
|
+
{ time: "16:00", price: 154.75 }
|
|
595
|
+
];
|
|
596
|
+
const width = 600;
|
|
597
|
+
const height = 300;
|
|
598
|
+
const padding = 40;
|
|
599
|
+
const xScale = (width - 2 * padding) / (data.length - 1);
|
|
600
|
+
const yMin = Math.min(...data.map((d) => d.price));
|
|
601
|
+
const yMax = Math.max(...data.map((d) => d.price));
|
|
602
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
603
|
+
const points = data.map((d, i) => {
|
|
604
|
+
const x = padding + i * xScale;
|
|
605
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
606
|
+
return `${x},${y}`;
|
|
607
|
+
}).join(" L ");
|
|
608
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
609
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
610
|
+
<!-- Background -->
|
|
611
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
612
|
+
|
|
613
|
+
<!-- Grid lines -->
|
|
614
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
615
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
616
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
617
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
618
|
+
}).join("\n")}
|
|
619
|
+
</g>
|
|
620
|
+
|
|
621
|
+
<!-- Price line -->
|
|
622
|
+
<path d="M ${points}"
|
|
623
|
+
fill="none"
|
|
624
|
+
stroke="#007bff"
|
|
625
|
+
stroke-width="2"/>
|
|
626
|
+
|
|
627
|
+
<!-- Data points -->
|
|
628
|
+
${data.map((d, i) => {
|
|
629
|
+
const x = padding + i * xScale;
|
|
630
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
631
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
632
|
+
}).join("\n")}
|
|
633
|
+
|
|
634
|
+
<!-- Labels -->
|
|
635
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
636
|
+
${data.map((d, i) => {
|
|
637
|
+
const x = padding + i * xScale;
|
|
638
|
+
return `<text x="${x}" y="${height - padding + 20}" text-anchor="middle">${d.time}</text>`;
|
|
639
|
+
}).join("\n")}
|
|
640
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
641
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
642
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
643
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
644
|
+
}).join("\n")}
|
|
645
|
+
</g>
|
|
646
|
+
|
|
647
|
+
<!-- Title -->
|
|
648
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
649
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
650
|
+
text-anchor="middle" fill="#212529">
|
|
651
|
+
${symbol} - 1 Day Price Chart
|
|
652
|
+
</text>
|
|
653
|
+
</svg>`;
|
|
654
|
+
return {
|
|
655
|
+
contents: [
|
|
656
|
+
{
|
|
657
|
+
uri: uri.href,
|
|
658
|
+
text: svg
|
|
659
|
+
}
|
|
660
|
+
]
|
|
932
661
|
};
|
|
933
662
|
}
|
|
934
663
|
);
|