fixparser-plugin-mcp 9.1.7-b2f9f891 → 9.1.7-b386e09a
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 +843 -822
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +833 -822
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +8 -43
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +8 -43
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +5 -4
- package/types/schemas/index.d.ts +15 -0
- package/types/schemas/schemas.d.ts +168 -0
- package/types/tools/index.d.ts +17 -0
- package/types/tools/marketData.d.ts +40 -0
- package/types/tools/order.d.ts +12 -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,187 +35,786 @@ __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
|
-
|
|
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
|
+
]
|
|
49
242
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
243
|
+
description: "Market Data Entry Types: 0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price, 5=Closing Price, 6=Settlement Price, 7=High Price, 8=Low Price, 9=Trade Volume, A=Open Interest, B=Simulated Sell Price, C=Simulated Buy Price, D=Empty Book, E=Session High Bid, F=Session Low Offer, G=Fixing Price, H=Electronic Volume, I=Threshold Limits and Price Band Variation, J=Clearing Price, K=Open Interest Change, L=Last Trade Price, M=Last Trade Volume, N=Last Trade Time, O=Last Trade Tick, P=Last Trade Exchange, Q=Last Trade ID, R=Last Trade Side, S=Last Trade Price Change, T=Last Trade Price Change Percent, U=Last Trade Price Change Basis Points, V=Last Trade Price Change Points, W=Last Trade Price Change Ticks, X=Last Trade Price Change Ticks Percent, Y=Last Trade Price Change Ticks Basis Points, Z=Last Trade Price Change Ticks Points"
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
getStockGraph: {
|
|
250
|
+
description: "Generates a price chart for a given symbol",
|
|
251
|
+
schema: {
|
|
252
|
+
type: "object",
|
|
253
|
+
properties: {
|
|
254
|
+
symbol: { type: "string" }
|
|
255
|
+
},
|
|
256
|
+
required: ["symbol"]
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
getStockPriceHistory: {
|
|
260
|
+
description: "Returns price history for a given symbol",
|
|
261
|
+
schema: {
|
|
262
|
+
type: "object",
|
|
263
|
+
properties: {
|
|
264
|
+
symbol: { type: "string" }
|
|
265
|
+
},
|
|
266
|
+
required: ["symbol"]
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/tools/marketData.ts
|
|
272
|
+
var import_fixparser = require("fixparser");
|
|
273
|
+
var import_quickchart_js = __toESM(require("quickchart-js"), 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 entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
|
|
281
|
+
const messageFields = [
|
|
282
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
283
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
|
|
284
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
285
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
|
|
286
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
|
|
287
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
288
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
289
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
290
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
291
|
+
];
|
|
292
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
293
|
+
args.symbols.forEach((symbol) => {
|
|
294
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
295
|
+
});
|
|
296
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
|
|
297
|
+
entryTypes.forEach((entryType) => {
|
|
298
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
299
|
+
});
|
|
300
|
+
const mdr = parser.createMessage(...messageFields);
|
|
301
|
+
if (!parser.connected) {
|
|
302
|
+
return {
|
|
303
|
+
content: [
|
|
304
|
+
{
|
|
305
|
+
type: "text",
|
|
306
|
+
text: "Error: Not connected. Ignoring message.",
|
|
307
|
+
uri: "marketDataRequest"
|
|
58
308
|
}
|
|
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
|
-
side: {
|
|
101
|
-
type: "string",
|
|
102
|
-
enum: [
|
|
103
|
-
"1",
|
|
104
|
-
"2",
|
|
105
|
-
"3",
|
|
106
|
-
"4",
|
|
107
|
-
"5",
|
|
108
|
-
"6",
|
|
109
|
-
"7",
|
|
110
|
-
"8",
|
|
111
|
-
"9",
|
|
112
|
-
"A",
|
|
113
|
-
"B",
|
|
114
|
-
"C",
|
|
115
|
-
"D",
|
|
116
|
-
"E",
|
|
117
|
-
"F",
|
|
118
|
-
"G",
|
|
119
|
-
"H"
|
|
120
|
-
]
|
|
121
|
-
},
|
|
122
|
-
symbol: { type: "string" },
|
|
123
|
-
timeInForce: {
|
|
124
|
-
type: "string",
|
|
125
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
required: [
|
|
129
|
-
"clOrdID",
|
|
130
|
-
"handlInst",
|
|
131
|
-
"quantity",
|
|
132
|
-
"price",
|
|
133
|
-
"ordType",
|
|
134
|
-
"side",
|
|
135
|
-
"symbol",
|
|
136
|
-
"timeInForce"
|
|
137
|
-
]
|
|
309
|
+
],
|
|
310
|
+
isError: true
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
parser.send(mdr);
|
|
314
|
+
const fixData = await response;
|
|
315
|
+
return {
|
|
316
|
+
content: [
|
|
317
|
+
{
|
|
318
|
+
type: "text",
|
|
319
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
320
|
+
uri: "marketDataRequest"
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
};
|
|
324
|
+
} catch (error) {
|
|
325
|
+
return {
|
|
326
|
+
content: [
|
|
327
|
+
{
|
|
328
|
+
type: "text",
|
|
329
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
330
|
+
uri: "marketDataRequest"
|
|
331
|
+
}
|
|
332
|
+
],
|
|
333
|
+
isError: true
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
339
|
+
return async (args) => {
|
|
340
|
+
try {
|
|
341
|
+
const symbol = args.symbol;
|
|
342
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
343
|
+
if (priceHistory.length === 0) {
|
|
344
|
+
return {
|
|
345
|
+
content: [
|
|
346
|
+
{
|
|
347
|
+
type: "text",
|
|
348
|
+
text: `No price data available for ${symbol}`,
|
|
349
|
+
uri: "getStockGraph"
|
|
138
350
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
351
|
+
]
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const chart = new import_quickchart_js.default();
|
|
355
|
+
chart.setWidth(300);
|
|
356
|
+
chart.setHeight(150);
|
|
357
|
+
chart.setBackgroundColor("transparent");
|
|
358
|
+
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
359
|
+
const bidData = priceHistory.map((point) => point.bid);
|
|
360
|
+
const offerData = priceHistory.map((point) => point.offer);
|
|
361
|
+
const spreadData = priceHistory.map((point) => point.spread);
|
|
362
|
+
const volumeData = priceHistory.map((point) => point.volume);
|
|
363
|
+
const config = {
|
|
364
|
+
type: "line",
|
|
365
|
+
data: {
|
|
366
|
+
labels,
|
|
367
|
+
datasets: [
|
|
368
|
+
{
|
|
369
|
+
label: "Bid",
|
|
370
|
+
data: bidData,
|
|
371
|
+
borderColor: "#28a745",
|
|
372
|
+
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
373
|
+
fill: false,
|
|
374
|
+
tension: 0.4
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
label: "Offer",
|
|
378
|
+
data: offerData,
|
|
379
|
+
borderColor: "#dc3545",
|
|
380
|
+
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
381
|
+
fill: false,
|
|
382
|
+
tension: 0.4
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
label: "Spread",
|
|
386
|
+
data: spreadData,
|
|
387
|
+
borderColor: "#6c757d",
|
|
388
|
+
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
389
|
+
fill: false,
|
|
390
|
+
tension: 0.4
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
label: "Volume",
|
|
394
|
+
data: volumeData,
|
|
395
|
+
borderColor: "#007bff",
|
|
396
|
+
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
397
|
+
fill: true,
|
|
398
|
+
tension: 0.4
|
|
399
|
+
}
|
|
400
|
+
]
|
|
401
|
+
},
|
|
402
|
+
options: {
|
|
403
|
+
responsive: true,
|
|
404
|
+
plugins: {
|
|
405
|
+
title: {
|
|
406
|
+
display: true,
|
|
407
|
+
text: `${symbol} Market Data`
|
|
164
408
|
}
|
|
165
409
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
type: "object",
|
|
170
|
-
properties: {
|
|
171
|
-
mdUpdateType: { type: "string", enum: ["0", "1"] },
|
|
172
|
-
symbols: { type: "array", items: { type: "string" } },
|
|
173
|
-
mdReqID: { type: "string" },
|
|
174
|
-
subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
|
|
175
|
-
mdEntryTypes: { type: "array", items: { type: "string" } }
|
|
176
|
-
},
|
|
177
|
-
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
|
|
410
|
+
scales: {
|
|
411
|
+
y: {
|
|
412
|
+
beginAtZero: false
|
|
178
413
|
}
|
|
179
414
|
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
required: ["symbol"]
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
chart.setConfig(config);
|
|
418
|
+
const imageBuffer = await chart.toBinary();
|
|
419
|
+
const base64Image = imageBuffer.toString("base64");
|
|
420
|
+
return {
|
|
421
|
+
content: [
|
|
422
|
+
{
|
|
423
|
+
type: "image",
|
|
424
|
+
data: `image/png;base64, ${base64Image}`,
|
|
425
|
+
mimeType: "image/png",
|
|
426
|
+
metadata: {
|
|
427
|
+
width: 300,
|
|
428
|
+
height: 150
|
|
195
429
|
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
430
|
+
}
|
|
431
|
+
]
|
|
432
|
+
};
|
|
433
|
+
} catch (error) {
|
|
434
|
+
return {
|
|
435
|
+
content: [
|
|
436
|
+
{
|
|
437
|
+
type: "text",
|
|
438
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
439
|
+
uri: "getStockGraph"
|
|
440
|
+
}
|
|
441
|
+
],
|
|
442
|
+
isError: true
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
};
|
|
447
|
+
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
448
|
+
return async (args) => {
|
|
449
|
+
try {
|
|
450
|
+
const symbol = args.symbol;
|
|
451
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
452
|
+
if (priceHistory.length === 0) {
|
|
453
|
+
return {
|
|
454
|
+
content: [
|
|
455
|
+
{
|
|
456
|
+
type: "text",
|
|
457
|
+
text: `No price data available for ${symbol}`,
|
|
458
|
+
uri: "getStockPriceHistory"
|
|
459
|
+
}
|
|
460
|
+
]
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
return {
|
|
464
|
+
content: [
|
|
465
|
+
{
|
|
466
|
+
type: "text",
|
|
467
|
+
text: JSON.stringify(
|
|
468
|
+
{
|
|
469
|
+
symbol,
|
|
470
|
+
count: priceHistory.length,
|
|
471
|
+
data: priceHistory.map((point) => ({
|
|
472
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
473
|
+
bid: point.bid,
|
|
474
|
+
offer: point.offer,
|
|
475
|
+
spread: point.spread,
|
|
476
|
+
volume: point.volume
|
|
477
|
+
}))
|
|
204
478
|
},
|
|
205
|
-
|
|
479
|
+
null,
|
|
480
|
+
2
|
|
481
|
+
),
|
|
482
|
+
uri: "getStockPriceHistory"
|
|
483
|
+
}
|
|
484
|
+
]
|
|
485
|
+
};
|
|
486
|
+
} catch (error) {
|
|
487
|
+
return {
|
|
488
|
+
content: [
|
|
489
|
+
{
|
|
490
|
+
type: "text",
|
|
491
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
492
|
+
uri: "getStockPriceHistory"
|
|
493
|
+
}
|
|
494
|
+
],
|
|
495
|
+
isError: true
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/tools/order.ts
|
|
502
|
+
var import_fixparser2 = require("fixparser");
|
|
503
|
+
var ordTypeNames = {
|
|
504
|
+
"1": "Market",
|
|
505
|
+
"2": "Limit",
|
|
506
|
+
"3": "Stop",
|
|
507
|
+
"4": "StopLimit",
|
|
508
|
+
"5": "MarketOnClose",
|
|
509
|
+
"6": "WithOrWithout",
|
|
510
|
+
"7": "LimitOrBetter",
|
|
511
|
+
"8": "LimitWithOrWithout",
|
|
512
|
+
"9": "OnBasis",
|
|
513
|
+
A: "OnClose",
|
|
514
|
+
B: "LimitOnClose",
|
|
515
|
+
C: "ForexMarket",
|
|
516
|
+
D: "PreviouslyQuoted",
|
|
517
|
+
E: "PreviouslyIndicated",
|
|
518
|
+
F: "ForexLimit",
|
|
519
|
+
G: "ForexSwap",
|
|
520
|
+
H: "ForexPreviouslyQuoted",
|
|
521
|
+
I: "Funari",
|
|
522
|
+
J: "MarketIfTouched",
|
|
523
|
+
K: "MarketWithLeftOverAsLimit",
|
|
524
|
+
L: "PreviousFundValuationPoint",
|
|
525
|
+
M: "NextFundValuationPoint",
|
|
526
|
+
P: "Pegged",
|
|
527
|
+
Q: "CounterOrderSelection",
|
|
528
|
+
R: "StopOnBidOrOffer",
|
|
529
|
+
S: "StopLimitOnBidOrOffer"
|
|
530
|
+
};
|
|
531
|
+
var sideNames = {
|
|
532
|
+
"1": "Buy",
|
|
533
|
+
"2": "Sell",
|
|
534
|
+
"3": "BuyMinus",
|
|
535
|
+
"4": "SellPlus",
|
|
536
|
+
"5": "SellShort",
|
|
537
|
+
"6": "SellShortExempt",
|
|
538
|
+
"7": "Undisclosed",
|
|
539
|
+
"8": "Cross",
|
|
540
|
+
"9": "CrossShort",
|
|
541
|
+
A: "CrossShortExempt",
|
|
542
|
+
B: "AsDefined",
|
|
543
|
+
C: "Opposite",
|
|
544
|
+
D: "Subscribe",
|
|
545
|
+
E: "Redeem",
|
|
546
|
+
F: "Lend",
|
|
547
|
+
G: "Borrow",
|
|
548
|
+
H: "SellUndisclosed"
|
|
549
|
+
};
|
|
550
|
+
var timeInForceNames = {
|
|
551
|
+
"0": "Day",
|
|
552
|
+
"1": "GoodTillCancel",
|
|
553
|
+
"2": "AtTheOpening",
|
|
554
|
+
"3": "ImmediateOrCancel",
|
|
555
|
+
"4": "FillOrKill",
|
|
556
|
+
"5": "GoodTillCrossing",
|
|
557
|
+
"6": "GoodTillDate",
|
|
558
|
+
"7": "AtTheClose",
|
|
559
|
+
"8": "GoodThroughCrossing",
|
|
560
|
+
"9": "AtCrossing",
|
|
561
|
+
A: "GoodForTime",
|
|
562
|
+
B: "GoodForAuction",
|
|
563
|
+
C: "GoodForMonth"
|
|
564
|
+
};
|
|
565
|
+
var handlInstNames = {
|
|
566
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
567
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
568
|
+
"3": "ManualOrder"
|
|
569
|
+
};
|
|
570
|
+
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
571
|
+
return async (args) => {
|
|
572
|
+
try {
|
|
573
|
+
verifiedOrders.set(args.clOrdID, {
|
|
574
|
+
clOrdID: args.clOrdID,
|
|
575
|
+
handlInst: args.handlInst,
|
|
576
|
+
quantity: Number.parseFloat(String(args.quantity)),
|
|
577
|
+
price: Number.parseFloat(String(args.price)),
|
|
578
|
+
ordType: args.ordType,
|
|
579
|
+
side: args.side,
|
|
580
|
+
symbol: args.symbol,
|
|
581
|
+
timeInForce: args.timeInForce
|
|
582
|
+
});
|
|
583
|
+
return {
|
|
584
|
+
content: [
|
|
585
|
+
{
|
|
586
|
+
type: "text",
|
|
587
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
588
|
+
|
|
589
|
+
Parameters verified:
|
|
590
|
+
- ClOrdID: ${args.clOrdID}
|
|
591
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
592
|
+
- Quantity: ${args.quantity}
|
|
593
|
+
- Price: ${args.price}
|
|
594
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
595
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
596
|
+
- Symbol: ${args.symbol}
|
|
597
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
598
|
+
|
|
599
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
600
|
+
uri: "verifyOrder"
|
|
601
|
+
}
|
|
602
|
+
]
|
|
603
|
+
};
|
|
604
|
+
} catch (error) {
|
|
605
|
+
return {
|
|
606
|
+
content: [
|
|
607
|
+
{
|
|
608
|
+
type: "text",
|
|
609
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
610
|
+
uri: "verifyOrder"
|
|
611
|
+
}
|
|
612
|
+
],
|
|
613
|
+
isError: true
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
};
|
|
618
|
+
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
619
|
+
return async (args) => {
|
|
620
|
+
try {
|
|
621
|
+
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
622
|
+
if (!verifiedOrder) {
|
|
623
|
+
return {
|
|
624
|
+
content: [
|
|
625
|
+
{
|
|
626
|
+
type: "text",
|
|
627
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
628
|
+
uri: "executeOrder"
|
|
206
629
|
}
|
|
630
|
+
],
|
|
631
|
+
isError: true
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
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) {
|
|
635
|
+
return {
|
|
636
|
+
content: [
|
|
637
|
+
{
|
|
638
|
+
type: "text",
|
|
639
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
640
|
+
uri: "executeOrder"
|
|
641
|
+
}
|
|
642
|
+
],
|
|
643
|
+
isError: true
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
const response = new Promise((resolve) => {
|
|
647
|
+
pendingRequests.set(args.clOrdID, resolve);
|
|
648
|
+
});
|
|
649
|
+
const order = parser.createMessage(
|
|
650
|
+
new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
|
|
651
|
+
new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
652
|
+
new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
|
|
653
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
|
|
654
|
+
new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
|
|
655
|
+
new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
|
|
656
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
|
|
657
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
|
|
658
|
+
new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
659
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
|
|
660
|
+
new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
|
|
661
|
+
new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
|
|
662
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
|
|
663
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
|
|
664
|
+
);
|
|
665
|
+
if (!parser.connected) {
|
|
666
|
+
return {
|
|
667
|
+
content: [
|
|
668
|
+
{
|
|
669
|
+
type: "text",
|
|
670
|
+
text: "Error: Not connected. Ignoring message.",
|
|
671
|
+
uri: "executeOrder"
|
|
672
|
+
}
|
|
673
|
+
],
|
|
674
|
+
isError: true
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
parser.send(order);
|
|
678
|
+
const fixData = await response;
|
|
679
|
+
verifiedOrders.delete(args.clOrdID);
|
|
680
|
+
return {
|
|
681
|
+
content: [
|
|
682
|
+
{
|
|
683
|
+
type: "text",
|
|
684
|
+
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())}`,
|
|
685
|
+
uri: "executeOrder"
|
|
207
686
|
}
|
|
208
|
-
|
|
687
|
+
]
|
|
688
|
+
};
|
|
689
|
+
} catch (error) {
|
|
690
|
+
return {
|
|
691
|
+
content: [
|
|
692
|
+
{
|
|
693
|
+
type: "text",
|
|
694
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
695
|
+
uri: "executeOrder"
|
|
696
|
+
}
|
|
697
|
+
],
|
|
698
|
+
isError: true
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// src/tools/parse.ts
|
|
705
|
+
var createParseHandler = (parser) => {
|
|
706
|
+
return async (args) => {
|
|
707
|
+
try {
|
|
708
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
709
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
710
|
+
return {
|
|
711
|
+
content: [
|
|
712
|
+
{
|
|
713
|
+
type: "text",
|
|
714
|
+
text: "Error: Failed to parse FIX string",
|
|
715
|
+
uri: "parse"
|
|
716
|
+
}
|
|
717
|
+
],
|
|
718
|
+
isError: true
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
content: [
|
|
723
|
+
{
|
|
724
|
+
type: "text",
|
|
725
|
+
text: `${parsedMessage[0].description}
|
|
726
|
+
${parsedMessage[0].messageTypeDescription}`,
|
|
727
|
+
uri: "parse"
|
|
728
|
+
}
|
|
729
|
+
]
|
|
730
|
+
};
|
|
731
|
+
} catch (error) {
|
|
732
|
+
return {
|
|
733
|
+
content: [
|
|
734
|
+
{
|
|
735
|
+
type: "text",
|
|
736
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
737
|
+
uri: "parse"
|
|
738
|
+
}
|
|
739
|
+
],
|
|
740
|
+
isError: true
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
// src/tools/parseToJSON.ts
|
|
747
|
+
var createParseToJSONHandler = (parser) => {
|
|
748
|
+
return async (args) => {
|
|
749
|
+
try {
|
|
750
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
751
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
752
|
+
return {
|
|
753
|
+
content: [
|
|
754
|
+
{
|
|
755
|
+
type: "text",
|
|
756
|
+
text: "Error: Failed to parse FIX string",
|
|
757
|
+
uri: "parseToJSON"
|
|
758
|
+
}
|
|
759
|
+
],
|
|
760
|
+
isError: true
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
return {
|
|
764
|
+
content: [
|
|
765
|
+
{
|
|
766
|
+
type: "text",
|
|
767
|
+
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
768
|
+
uri: "parseToJSON"
|
|
769
|
+
}
|
|
770
|
+
]
|
|
771
|
+
};
|
|
772
|
+
} catch (error) {
|
|
773
|
+
return {
|
|
774
|
+
content: [
|
|
775
|
+
{
|
|
776
|
+
type: "text",
|
|
777
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
778
|
+
uri: "parseToJSON"
|
|
779
|
+
}
|
|
780
|
+
],
|
|
781
|
+
isError: true
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
};
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
// src/tools/index.ts
|
|
788
|
+
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
789
|
+
parse: createParseHandler(parser),
|
|
790
|
+
parseToJSON: createParseToJSONHandler(parser),
|
|
791
|
+
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
792
|
+
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
793
|
+
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
794
|
+
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
795
|
+
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// src/MCPLocal.ts
|
|
799
|
+
var MCPLocal = class {
|
|
800
|
+
parser;
|
|
801
|
+
server = new import_server.Server(
|
|
802
|
+
{
|
|
803
|
+
name: "fixparser",
|
|
804
|
+
version: "1.0.0"
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
capabilities: {
|
|
808
|
+
tools: Object.entries(toolSchemas).reduce(
|
|
809
|
+
(acc, [name, { description, schema }]) => {
|
|
810
|
+
acc[name] = {
|
|
811
|
+
description,
|
|
812
|
+
parameters: schema
|
|
813
|
+
};
|
|
814
|
+
return acc;
|
|
815
|
+
},
|
|
816
|
+
{}
|
|
817
|
+
)
|
|
209
818
|
}
|
|
210
819
|
}
|
|
211
820
|
);
|
|
@@ -213,7 +822,6 @@ var MCPLocal = class {
|
|
|
213
822
|
onReady = void 0;
|
|
214
823
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
215
824
|
verifiedOrders = /* @__PURE__ */ new Map();
|
|
216
|
-
// Store market data prices with timestamps
|
|
217
825
|
marketDataPrices = /* @__PURE__ */ new Map();
|
|
218
826
|
MAX_PRICE_HISTORY = 1e5;
|
|
219
827
|
// Maximum number of price points to store per symbol
|
|
@@ -228,42 +836,63 @@ var MCPLocal = class {
|
|
|
228
836
|
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
229
837
|
});
|
|
230
838
|
const msgType = message.messageType;
|
|
231
|
-
if (msgType ===
|
|
839
|
+
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
|
|
232
840
|
this.parser?.logger.log({
|
|
233
841
|
level: "info",
|
|
234
842
|
message: `MCP Server handling message type: ${msgType}`
|
|
235
843
|
});
|
|
236
844
|
let id;
|
|
237
|
-
if (msgType ===
|
|
238
|
-
const symbol = message.getField(
|
|
239
|
-
const
|
|
240
|
-
const
|
|
845
|
+
if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
|
|
846
|
+
const symbol = message.getField(import_fixparser3.Fields.Symbol);
|
|
847
|
+
const entryType = message.getField(import_fixparser3.Fields.MDEntryType);
|
|
848
|
+
const price = message.getField(import_fixparser3.Fields.MDEntryPx);
|
|
849
|
+
const size = message.getField(import_fixparser3.Fields.MDEntrySize);
|
|
850
|
+
const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
|
|
241
851
|
if (symbol?.value && price?.value) {
|
|
242
852
|
const symbolStr = String(symbol.value);
|
|
243
853
|
const priceNum = Number(price.value);
|
|
854
|
+
const sizeNum = size?.value ? Number(size.value) : 0;
|
|
244
855
|
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
245
|
-
priceHistory.
|
|
856
|
+
const lastEntry = priceHistory[priceHistory.length - 1] || {
|
|
857
|
+
timestamp: 0,
|
|
858
|
+
bid: 0,
|
|
859
|
+
offer: 0,
|
|
860
|
+
spread: 0,
|
|
861
|
+
volume: 0
|
|
862
|
+
};
|
|
863
|
+
const newEntry = {
|
|
246
864
|
timestamp: Number(timestamp),
|
|
247
|
-
|
|
248
|
-
|
|
865
|
+
bid: entryType?.value === import_fixparser3.MDEntryType.Bid ? priceNum : lastEntry.bid,
|
|
866
|
+
offer: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum : lastEntry.offer,
|
|
867
|
+
spread: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum - lastEntry.bid : entryType?.value === import_fixparser3.MDEntryType.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
|
|
868
|
+
volume: entryType?.value === import_fixparser3.MDEntryType.TradeVolume ? sizeNum : lastEntry.volume
|
|
869
|
+
};
|
|
870
|
+
priceHistory.push(newEntry);
|
|
249
871
|
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
250
872
|
priceHistory.shift();
|
|
251
873
|
}
|
|
252
874
|
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
253
875
|
this.parser?.logger.log({
|
|
254
876
|
level: "info",
|
|
255
|
-
message: `MCP Server added ${symbol}: ${
|
|
877
|
+
message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
|
|
878
|
+
});
|
|
879
|
+
this.server.notification({
|
|
880
|
+
method: "priceUpdate",
|
|
881
|
+
params: {
|
|
882
|
+
symbol: symbolStr,
|
|
883
|
+
...newEntry
|
|
884
|
+
}
|
|
256
885
|
});
|
|
257
886
|
}
|
|
258
887
|
}
|
|
259
|
-
if (msgType ===
|
|
260
|
-
const mdReqID = message.getField(
|
|
888
|
+
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
|
|
889
|
+
const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
|
|
261
890
|
if (mdReqID) id = String(mdReqID.value);
|
|
262
|
-
} else if (msgType ===
|
|
263
|
-
const clOrdID = message.getField(
|
|
891
|
+
} else if (msgType === import_fixparser3.Messages.ExecutionReport) {
|
|
892
|
+
const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
|
|
264
893
|
if (clOrdID) id = String(clOrdID.value);
|
|
265
|
-
} else if (msgType ===
|
|
266
|
-
const refSeqNum = message.getField(
|
|
894
|
+
} else if (msgType === import_fixparser3.Messages.Reject) {
|
|
895
|
+
const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
|
|
267
896
|
if (refSeqNum) id = String(refSeqNum.value);
|
|
268
897
|
}
|
|
269
898
|
if (id) {
|
|
@@ -288,662 +917,54 @@ var MCPLocal = class {
|
|
|
288
917
|
if (!this.server) {
|
|
289
918
|
return;
|
|
290
919
|
}
|
|
291
|
-
this.server.setRequestHandler(
|
|
292
|
-
import_zod.z.object({ method: import_zod.z.literal("resources/list") }),
|
|
293
|
-
async (request, extra) => {
|
|
294
|
-
return {
|
|
295
|
-
resources: [
|
|
296
|
-
{
|
|
297
|
-
name: "greeting",
|
|
298
|
-
description: "A simple greeting resource",
|
|
299
|
-
uri: "greeting-resource"
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
name: "stockGraph",
|
|
303
|
-
description: "Generates a price chart for a given symbol",
|
|
304
|
-
uri: "stockGraph",
|
|
305
|
-
parameters: {
|
|
306
|
-
type: "object",
|
|
307
|
-
properties: {
|
|
308
|
-
symbol: { type: "string" }
|
|
309
|
-
},
|
|
310
|
-
required: ["symbol"]
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
name: "stockPriceHistory",
|
|
315
|
-
description: "Returns price history for a given symbol",
|
|
316
|
-
uri: "stockPriceHistory",
|
|
317
|
-
parameters: {
|
|
318
|
-
type: "object",
|
|
319
|
-
properties: {
|
|
320
|
-
symbol: { type: "string" }
|
|
321
|
-
},
|
|
322
|
-
required: ["symbol"]
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
]
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
);
|
|
329
920
|
this.server.setRequestHandler(
|
|
330
921
|
import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
|
|
331
922
|
async (request, extra) => {
|
|
332
923
|
return {
|
|
333
|
-
tools: [
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
type: "object",
|
|
339
|
-
properties: {
|
|
340
|
-
fixString: { type: "string" }
|
|
341
|
-
},
|
|
342
|
-
required: ["fixString"]
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
{
|
|
346
|
-
name: "parseToJSON",
|
|
347
|
-
description: "Parses a FIX message into JSON",
|
|
348
|
-
parameters: {
|
|
349
|
-
type: "object",
|
|
350
|
-
properties: {
|
|
351
|
-
fixString: { type: "string" }
|
|
352
|
-
},
|
|
353
|
-
required: ["fixString"]
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
name: "verifyOrder",
|
|
358
|
-
description: "Verifies order parameters before execution",
|
|
359
|
-
parameters: {
|
|
360
|
-
type: "object",
|
|
361
|
-
properties: {
|
|
362
|
-
clOrdID: { type: "string" },
|
|
363
|
-
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
364
|
-
quantity: { type: "string" },
|
|
365
|
-
price: { type: "string" },
|
|
366
|
-
ordType: {
|
|
367
|
-
type: "string",
|
|
368
|
-
enum: [
|
|
369
|
-
"1",
|
|
370
|
-
"2",
|
|
371
|
-
"3",
|
|
372
|
-
"4",
|
|
373
|
-
"5",
|
|
374
|
-
"6",
|
|
375
|
-
"7",
|
|
376
|
-
"8",
|
|
377
|
-
"9",
|
|
378
|
-
"A",
|
|
379
|
-
"B",
|
|
380
|
-
"C",
|
|
381
|
-
"D",
|
|
382
|
-
"E",
|
|
383
|
-
"F",
|
|
384
|
-
"G",
|
|
385
|
-
"H",
|
|
386
|
-
"I",
|
|
387
|
-
"J",
|
|
388
|
-
"K",
|
|
389
|
-
"L",
|
|
390
|
-
"M",
|
|
391
|
-
"P",
|
|
392
|
-
"Q",
|
|
393
|
-
"R",
|
|
394
|
-
"S"
|
|
395
|
-
]
|
|
396
|
-
},
|
|
397
|
-
side: {
|
|
398
|
-
type: "string",
|
|
399
|
-
enum: [
|
|
400
|
-
"1",
|
|
401
|
-
"2",
|
|
402
|
-
"3",
|
|
403
|
-
"4",
|
|
404
|
-
"5",
|
|
405
|
-
"6",
|
|
406
|
-
"7",
|
|
407
|
-
"8",
|
|
408
|
-
"9",
|
|
409
|
-
"A",
|
|
410
|
-
"B",
|
|
411
|
-
"C",
|
|
412
|
-
"D",
|
|
413
|
-
"E",
|
|
414
|
-
"F",
|
|
415
|
-
"G",
|
|
416
|
-
"H"
|
|
417
|
-
]
|
|
418
|
-
},
|
|
419
|
-
symbol: { type: "string" },
|
|
420
|
-
timeInForce: {
|
|
421
|
-
type: "string",
|
|
422
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
|
|
423
|
-
}
|
|
424
|
-
},
|
|
425
|
-
required: [
|
|
426
|
-
"clOrdID",
|
|
427
|
-
"handlInst",
|
|
428
|
-
"quantity",
|
|
429
|
-
"price",
|
|
430
|
-
"ordType",
|
|
431
|
-
"side",
|
|
432
|
-
"symbol",
|
|
433
|
-
"timeInForce"
|
|
434
|
-
]
|
|
435
|
-
}
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
name: "executeOrder",
|
|
439
|
-
description: "Executes a verified order",
|
|
440
|
-
parameters: {
|
|
441
|
-
type: "object",
|
|
442
|
-
properties: {
|
|
443
|
-
clOrdID: { type: "string" },
|
|
444
|
-
handlInst: { type: "string", enum: ["1", "2", "3"] },
|
|
445
|
-
quantity: { type: "string" },
|
|
446
|
-
price: { type: "string" },
|
|
447
|
-
ordType: { type: "string" },
|
|
448
|
-
side: { type: "string" },
|
|
449
|
-
symbol: { type: "string" },
|
|
450
|
-
timeInForce: { type: "string" }
|
|
451
|
-
},
|
|
452
|
-
required: [
|
|
453
|
-
"clOrdID",
|
|
454
|
-
"handlInst",
|
|
455
|
-
"quantity",
|
|
456
|
-
"price",
|
|
457
|
-
"ordType",
|
|
458
|
-
"side",
|
|
459
|
-
"symbol",
|
|
460
|
-
"timeInForce"
|
|
461
|
-
]
|
|
462
|
-
}
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
name: "marketDataRequest",
|
|
466
|
-
description: "Requests market data for specified symbols",
|
|
467
|
-
parameters: {
|
|
468
|
-
type: "object",
|
|
469
|
-
properties: {
|
|
470
|
-
mdUpdateType: { type: "string", enum: ["0", "1"] },
|
|
471
|
-
symbols: { type: "array", items: { type: "string" } },
|
|
472
|
-
mdReqID: { type: "string" },
|
|
473
|
-
subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
|
|
474
|
-
mdEntryTypes: { type: "array", items: { type: "string" } }
|
|
475
|
-
},
|
|
476
|
-
required: [
|
|
477
|
-
"mdUpdateType",
|
|
478
|
-
"symbols",
|
|
479
|
-
"mdReqID",
|
|
480
|
-
"subscriptionRequestType",
|
|
481
|
-
"mdEntryTypes"
|
|
482
|
-
]
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
]
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
);
|
|
489
|
-
this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("parse") }), async (request, extra) => {
|
|
490
|
-
try {
|
|
491
|
-
const args = request.params;
|
|
492
|
-
const parsedMessage = this.parser?.parse(args.fixString);
|
|
493
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
494
|
-
return {
|
|
495
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
496
|
-
isError: true
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
return {
|
|
500
|
-
content: [
|
|
501
|
-
{
|
|
502
|
-
type: "text",
|
|
503
|
-
text: `${parsedMessage[0].description}
|
|
504
|
-
${parsedMessage[0].messageTypeDescription}`
|
|
505
|
-
}
|
|
506
|
-
]
|
|
924
|
+
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
925
|
+
name,
|
|
926
|
+
description,
|
|
927
|
+
inputSchema: schema
|
|
928
|
+
}))
|
|
507
929
|
};
|
|
508
|
-
} catch (error) {
|
|
509
|
-
return {
|
|
510
|
-
content: [
|
|
511
|
-
{
|
|
512
|
-
type: "text",
|
|
513
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
514
|
-
}
|
|
515
|
-
],
|
|
516
|
-
isError: true
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
});
|
|
520
|
-
this.server.setRequestHandler(
|
|
521
|
-
import_zod.z.object({ method: import_zod.z.literal("parseToJSON") }),
|
|
522
|
-
async (request, extra) => {
|
|
523
|
-
try {
|
|
524
|
-
const args = request.params;
|
|
525
|
-
const parsedMessage = this.parser?.parse(args.fixString);
|
|
526
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
527
|
-
return {
|
|
528
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
529
|
-
isError: true
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
return {
|
|
533
|
-
content: [
|
|
534
|
-
{
|
|
535
|
-
type: "text",
|
|
536
|
-
text: `${parsedMessage[0].toFIXJSON()}`
|
|
537
|
-
}
|
|
538
|
-
]
|
|
539
|
-
};
|
|
540
|
-
} catch (error) {
|
|
541
|
-
return {
|
|
542
|
-
content: [
|
|
543
|
-
{
|
|
544
|
-
type: "text",
|
|
545
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
546
|
-
}
|
|
547
|
-
],
|
|
548
|
-
isError: true
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
);
|
|
553
|
-
this.server.setRequestHandler(
|
|
554
|
-
import_zod.z.object({ method: import_zod.z.literal("verifyOrder") }),
|
|
555
|
-
async (request, extra) => {
|
|
556
|
-
try {
|
|
557
|
-
const args = request.params;
|
|
558
|
-
this.verifiedOrders.set(args.clOrdID, {
|
|
559
|
-
clOrdID: args.clOrdID,
|
|
560
|
-
handlInst: args.handlInst,
|
|
561
|
-
quantity: Number.parseFloat(args.quantity),
|
|
562
|
-
price: Number.parseFloat(args.price),
|
|
563
|
-
ordType: args.ordType,
|
|
564
|
-
side: args.side,
|
|
565
|
-
symbol: args.symbol,
|
|
566
|
-
timeInForce: args.timeInForce
|
|
567
|
-
});
|
|
568
|
-
const ordTypeNames = {
|
|
569
|
-
"1": "Market",
|
|
570
|
-
"2": "Limit",
|
|
571
|
-
"3": "Stop",
|
|
572
|
-
"4": "StopLimit",
|
|
573
|
-
"5": "MarketOnClose",
|
|
574
|
-
"6": "WithOrWithout",
|
|
575
|
-
"7": "LimitOrBetter",
|
|
576
|
-
"8": "LimitWithOrWithout",
|
|
577
|
-
"9": "OnBasis",
|
|
578
|
-
A: "OnClose",
|
|
579
|
-
B: "LimitOnClose",
|
|
580
|
-
C: "ForexMarket",
|
|
581
|
-
D: "PreviouslyQuoted",
|
|
582
|
-
E: "PreviouslyIndicated",
|
|
583
|
-
F: "ForexLimit",
|
|
584
|
-
G: "ForexSwap",
|
|
585
|
-
H: "ForexPreviouslyQuoted",
|
|
586
|
-
I: "Funari",
|
|
587
|
-
J: "MarketIfTouched",
|
|
588
|
-
K: "MarketWithLeftOverAsLimit",
|
|
589
|
-
L: "PreviousFundValuationPoint",
|
|
590
|
-
M: "NextFundValuationPoint",
|
|
591
|
-
P: "Pegged",
|
|
592
|
-
Q: "CounterOrderSelection",
|
|
593
|
-
R: "StopOnBidOrOffer",
|
|
594
|
-
S: "StopLimitOnBidOrOffer"
|
|
595
|
-
};
|
|
596
|
-
const sideNames = {
|
|
597
|
-
"1": "Buy",
|
|
598
|
-
"2": "Sell",
|
|
599
|
-
"3": "BuyMinus",
|
|
600
|
-
"4": "SellPlus",
|
|
601
|
-
"5": "SellShort",
|
|
602
|
-
"6": "SellShortExempt",
|
|
603
|
-
"7": "Undisclosed",
|
|
604
|
-
"8": "Cross",
|
|
605
|
-
"9": "CrossShort",
|
|
606
|
-
A: "CrossShortExempt",
|
|
607
|
-
B: "AsDefined",
|
|
608
|
-
C: "Opposite",
|
|
609
|
-
D: "Subscribe",
|
|
610
|
-
E: "Redeem",
|
|
611
|
-
F: "Lend",
|
|
612
|
-
G: "Borrow",
|
|
613
|
-
H: "SellUndisclosed"
|
|
614
|
-
};
|
|
615
|
-
const timeInForceNames = {
|
|
616
|
-
"0": "Day",
|
|
617
|
-
"1": "GoodTillCancel",
|
|
618
|
-
"2": "AtTheOpening",
|
|
619
|
-
"3": "ImmediateOrCancel",
|
|
620
|
-
"4": "FillOrKill",
|
|
621
|
-
"5": "GoodTillCrossing",
|
|
622
|
-
"6": "GoodTillDate",
|
|
623
|
-
"7": "AtTheClose",
|
|
624
|
-
"8": "GoodThroughCrossing",
|
|
625
|
-
"9": "AtCrossing",
|
|
626
|
-
A: "GoodForTime",
|
|
627
|
-
B: "GoodForAuction",
|
|
628
|
-
C: "GoodForMonth"
|
|
629
|
-
};
|
|
630
|
-
const handlInstNames = {
|
|
631
|
-
"1": "AutomatedExecutionNoIntervention",
|
|
632
|
-
"2": "AutomatedExecutionInterventionOK",
|
|
633
|
-
"3": "ManualOrder"
|
|
634
|
-
};
|
|
635
|
-
return {
|
|
636
|
-
content: [
|
|
637
|
-
{
|
|
638
|
-
type: "text",
|
|
639
|
-
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
640
|
-
|
|
641
|
-
Parameters verified:
|
|
642
|
-
- ClOrdID: ${args.clOrdID}
|
|
643
|
-
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
644
|
-
- Quantity: ${args.quantity}
|
|
645
|
-
- Price: ${args.price}
|
|
646
|
-
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
647
|
-
- Side: ${args.side} (${sideNames[args.side]})
|
|
648
|
-
- Symbol: ${args.symbol}
|
|
649
|
-
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
650
|
-
|
|
651
|
-
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
652
|
-
}
|
|
653
|
-
]
|
|
654
|
-
};
|
|
655
|
-
} catch (error) {
|
|
656
|
-
return {
|
|
657
|
-
content: [
|
|
658
|
-
{
|
|
659
|
-
type: "text",
|
|
660
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
661
|
-
}
|
|
662
|
-
],
|
|
663
|
-
isError: true
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
930
|
}
|
|
667
931
|
);
|
|
668
932
|
this.server.setRequestHandler(
|
|
669
|
-
import_zod.z.object({
|
|
933
|
+
import_zod.z.object({
|
|
934
|
+
method: import_zod.z.literal("tools/call"),
|
|
935
|
+
params: import_zod.z.object({
|
|
936
|
+
name: import_zod.z.string(),
|
|
937
|
+
arguments: import_zod.z.any(),
|
|
938
|
+
_meta: import_zod.z.object({
|
|
939
|
+
progressToken: import_zod.z.number()
|
|
940
|
+
}).optional()
|
|
941
|
+
})
|
|
942
|
+
}),
|
|
670
943
|
async (request, extra) => {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
681
|
-
],
|
|
682
|
-
isError: true
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
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) {
|
|
686
|
-
return {
|
|
687
|
-
content: [
|
|
688
|
-
{
|
|
689
|
-
type: "text",
|
|
690
|
-
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
691
|
-
}
|
|
692
|
-
],
|
|
693
|
-
isError: true
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
const response = new Promise((resolve) => {
|
|
697
|
-
this.pendingRequests.set(args.clOrdID, resolve);
|
|
698
|
-
});
|
|
699
|
-
const order = this.parser?.createMessage(
|
|
700
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
701
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
702
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
703
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
704
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
705
|
-
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
|
|
706
|
-
new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
|
|
707
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
|
|
708
|
-
new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
709
|
-
new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
|
|
710
|
-
new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
|
|
711
|
-
new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
|
|
712
|
-
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
|
|
713
|
-
new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
|
|
714
|
-
);
|
|
715
|
-
if (!this.parser?.connected) {
|
|
716
|
-
return {
|
|
717
|
-
content: [
|
|
718
|
-
{
|
|
719
|
-
type: "text",
|
|
720
|
-
text: "Error: Not connected. Ignoring message."
|
|
721
|
-
}
|
|
722
|
-
],
|
|
723
|
-
isError: true
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
this.parser?.send(order);
|
|
727
|
-
const fixData = await response;
|
|
728
|
-
this.verifiedOrders.delete(args.clOrdID);
|
|
729
|
-
return {
|
|
730
|
-
content: [
|
|
731
|
-
{
|
|
732
|
-
type: "text",
|
|
733
|
-
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())}`
|
|
734
|
-
}
|
|
735
|
-
]
|
|
736
|
-
};
|
|
737
|
-
} catch (error) {
|
|
738
|
-
return {
|
|
739
|
-
content: [
|
|
740
|
-
{
|
|
741
|
-
type: "text",
|
|
742
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
743
|
-
}
|
|
744
|
-
],
|
|
745
|
-
isError: true
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
);
|
|
750
|
-
this.server.setRequestHandler(
|
|
751
|
-
import_zod.z.object({ method: import_zod.z.literal("marketDataRequest") }),
|
|
752
|
-
async (request, extra) => {
|
|
753
|
-
try {
|
|
754
|
-
const args = request.params;
|
|
755
|
-
const response = new Promise((resolve) => {
|
|
756
|
-
this.pendingRequests.set(args.mdReqID, resolve);
|
|
757
|
-
});
|
|
758
|
-
const messageFields = [
|
|
759
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
760
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
761
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
762
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
763
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
764
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
765
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
766
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
767
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
768
|
-
];
|
|
769
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
770
|
-
args.symbols.forEach((symbol) => {
|
|
771
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
772
|
-
});
|
|
773
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
774
|
-
args.mdEntryTypes.forEach((entryType) => {
|
|
775
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
776
|
-
});
|
|
777
|
-
const mdr = this.parser?.createMessage(...messageFields);
|
|
778
|
-
if (!this.parser?.connected) {
|
|
779
|
-
return {
|
|
780
|
-
content: [
|
|
781
|
-
{
|
|
782
|
-
type: "text",
|
|
783
|
-
text: "Error: Not connected. Ignoring message."
|
|
784
|
-
}
|
|
785
|
-
],
|
|
786
|
-
isError: true
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
this.parser?.send(mdr);
|
|
790
|
-
const fixData = await response;
|
|
791
|
-
return {
|
|
792
|
-
content: [
|
|
793
|
-
{
|
|
794
|
-
type: "text",
|
|
795
|
-
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
796
|
-
}
|
|
797
|
-
]
|
|
798
|
-
};
|
|
799
|
-
} catch (error) {
|
|
944
|
+
const { name, arguments: args } = request.params;
|
|
945
|
+
const toolHandlers = createToolHandlers(
|
|
946
|
+
this.parser,
|
|
947
|
+
this.verifiedOrders,
|
|
948
|
+
this.pendingRequests,
|
|
949
|
+
this.marketDataPrices
|
|
950
|
+
);
|
|
951
|
+
const handler = toolHandlers[name];
|
|
952
|
+
if (!handler) {
|
|
800
953
|
return {
|
|
801
954
|
content: [
|
|
802
955
|
{
|
|
803
956
|
type: "text",
|
|
804
|
-
text: `
|
|
957
|
+
text: `Tool not found: ${name}`,
|
|
958
|
+
uri: name
|
|
805
959
|
}
|
|
806
960
|
],
|
|
807
961
|
isError: true
|
|
808
962
|
};
|
|
809
963
|
}
|
|
810
|
-
|
|
811
|
-
);
|
|
812
|
-
this.server.setRequestHandler(
|
|
813
|
-
import_zod.z.object({ method: import_zod.z.literal("greeting-resource") }),
|
|
814
|
-
async (request, extra) => {
|
|
815
|
-
this.parser?.logger.log({
|
|
816
|
-
level: "info",
|
|
817
|
-
message: "MCP Server Resource called: greeting-resource"
|
|
818
|
-
});
|
|
819
|
-
return {
|
|
820
|
-
content: [
|
|
821
|
-
{
|
|
822
|
-
type: "text",
|
|
823
|
-
text: "Hello, world!"
|
|
824
|
-
}
|
|
825
|
-
]
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
);
|
|
829
|
-
this.server.setRequestHandler(
|
|
830
|
-
import_zod.z.object({ method: import_zod.z.literal("stockGraph") }),
|
|
831
|
-
async (request, extra) => {
|
|
832
|
-
this.parser?.logger.log({
|
|
833
|
-
level: "info",
|
|
834
|
-
message: "MCP Server Resource called: stockGraph"
|
|
835
|
-
});
|
|
836
|
-
const args = request.params;
|
|
837
|
-
const symbol = args.symbol;
|
|
838
|
-
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
839
|
-
if (priceHistory.length === 0) {
|
|
840
|
-
return {
|
|
841
|
-
content: [
|
|
842
|
-
{
|
|
843
|
-
type: "text",
|
|
844
|
-
text: `No price data available for ${symbol}`
|
|
845
|
-
}
|
|
846
|
-
]
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
const width = 600;
|
|
850
|
-
const height = 300;
|
|
851
|
-
const padding = 40;
|
|
852
|
-
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
853
|
-
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
854
|
-
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
855
|
-
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
856
|
-
const points = priceHistory.map((d, i) => {
|
|
857
|
-
const x = padding + i * xScale;
|
|
858
|
-
const y = height - padding - (d.price - yMin) * yScale;
|
|
859
|
-
return `${x},${y}`;
|
|
860
|
-
}).join(" L ");
|
|
861
|
-
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
862
|
-
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
863
|
-
<!-- Background -->
|
|
864
|
-
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
865
|
-
|
|
866
|
-
<!-- Grid lines -->
|
|
867
|
-
<g stroke="#e9ecef" stroke-width="1">
|
|
868
|
-
${Array.from({ length: 5 }, (_, i) => {
|
|
869
|
-
const y = padding + (height - 2 * padding) * i / 4;
|
|
870
|
-
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
871
|
-
}).join("\n")}
|
|
872
|
-
</g>
|
|
873
|
-
|
|
874
|
-
<!-- Price line -->
|
|
875
|
-
<path d="M ${points}"
|
|
876
|
-
fill="none"
|
|
877
|
-
stroke="#007bff"
|
|
878
|
-
stroke-width="2"/>
|
|
879
|
-
|
|
880
|
-
<!-- Data points -->
|
|
881
|
-
${priceHistory.map((d, i) => {
|
|
882
|
-
const x = padding + i * xScale;
|
|
883
|
-
const y = height - padding - (d.price - yMin) * yScale;
|
|
884
|
-
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
885
|
-
}).join("\n")}
|
|
886
|
-
|
|
887
|
-
<!-- Labels -->
|
|
888
|
-
<g font-family="Arial" font-size="12" fill="#495057">
|
|
889
|
-
${Array.from({ length: 5 }, (_, i) => {
|
|
890
|
-
const x = padding + (width - 2 * padding) * i / 4;
|
|
891
|
-
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
892
|
-
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
893
|
-
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
894
|
-
}).join("\n")}
|
|
895
|
-
${Array.from({ length: 5 }, (_, i) => {
|
|
896
|
-
const y = padding + (height - 2 * padding) * i / 4;
|
|
897
|
-
const price = yMax - (yMax - yMin) * i / 4;
|
|
898
|
-
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
899
|
-
}).join("\n")}
|
|
900
|
-
</g>
|
|
901
|
-
|
|
902
|
-
<!-- Title -->
|
|
903
|
-
<text x="${width / 2}" y="${padding / 2}"
|
|
904
|
-
font-family="Arial" font-size="16" font-weight="bold"
|
|
905
|
-
text-anchor="middle" fill="#212529">
|
|
906
|
-
${symbol} - Price Chart (${priceHistory.length} points)
|
|
907
|
-
</text>
|
|
908
|
-
</svg>`;
|
|
909
|
-
return {
|
|
910
|
-
content: [
|
|
911
|
-
{
|
|
912
|
-
type: "text",
|
|
913
|
-
text: svg
|
|
914
|
-
}
|
|
915
|
-
]
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
);
|
|
919
|
-
this.server.setRequestHandler(
|
|
920
|
-
import_zod.z.object({ method: import_zod.z.literal("stockPriceHistory") }),
|
|
921
|
-
async (request, extra) => {
|
|
922
|
-
this.parser?.logger.log({
|
|
923
|
-
level: "info",
|
|
924
|
-
message: "MCP Server Resource called: stockPriceHistory"
|
|
925
|
-
});
|
|
926
|
-
const args = request.params;
|
|
927
|
-
const symbol = args.symbol;
|
|
928
|
-
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
964
|
+
const result = await handler(args);
|
|
929
965
|
return {
|
|
930
|
-
content:
|
|
931
|
-
|
|
932
|
-
type: "text",
|
|
933
|
-
text: JSON.stringify(
|
|
934
|
-
{
|
|
935
|
-
symbol,
|
|
936
|
-
count: priceHistory.length,
|
|
937
|
-
prices: priceHistory.map((point) => ({
|
|
938
|
-
timestamp: new Date(point.timestamp).toISOString(),
|
|
939
|
-
price: point.price
|
|
940
|
-
}))
|
|
941
|
-
},
|
|
942
|
-
null,
|
|
943
|
-
2
|
|
944
|
-
)
|
|
945
|
-
}
|
|
946
|
-
]
|
|
966
|
+
content: result.content,
|
|
967
|
+
isError: result.isError
|
|
947
968
|
};
|
|
948
969
|
}
|
|
949
970
|
);
|