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