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