fixparser-plugin-mcp 9.1.7-c415bb75 → 9.1.7-c5ae06ce
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 +458 -1150
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/cjs/MCPRemote.js +435 -1262
- package/build/cjs/MCPRemote.js.map +4 -4
- package/build/esm/MCPLocal.mjs +458 -1140
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build/esm/MCPRemote.mjs +444 -1252
- package/build/esm/MCPRemote.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +47 -12
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +43 -8
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +8 -9
- package/types/MCPLocal.d.ts +9 -25
- package/types/MCPRemote.d.ts +27 -25
- package/build/cjs/index.js +0 -1561
- package/build/cjs/index.js.map +0 -7
- package/build/esm/index.mjs +0 -1523
- package/build/esm/index.mjs.map +0 -7
- package/build-examples/cjs/example_mcp_remote.js +0 -16
- package/build-examples/cjs/example_mcp_remote.js.map +0 -7
- package/build-examples/esm/example_mcp_remote.mjs +0 -16
- package/build-examples/esm/example_mcp_remote.mjs.map +0 -7
- package/types/MCPBase.d.ts +0 -49
- package/types/schemas/index.d.ts +0 -15
- package/types/schemas/marketData.d.ts +0 -48
- package/types/schemas/schemas.d.ts +0 -168
- package/types/tools/index.d.ts +0 -17
- package/types/tools/marketData.d.ts +0 -40
- package/types/tools/order.d.ts +0 -12
- package/types/tools/parse.d.ts +0 -5
- package/types/tools/parseToJSON.d.ts +0 -5
- package/types/utils/messageHandler.d.ts +0 -12
package/build/cjs/MCPRemote.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/MCPRemote.ts
|
|
@@ -39,1124 +29,29 @@ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
39
29
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
40
30
|
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
41
31
|
var import_zod = require("zod");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var
|
|
32
|
+
var import_fixparser = require("fixparser");
|
|
33
|
+
var transports = {};
|
|
34
|
+
var MCPRemote = class {
|
|
35
|
+
/**
|
|
36
|
+
* Port number the server will listen on.
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
port;
|
|
45
40
|
/**
|
|
46
41
|
* Optional logger instance for diagnostics and output.
|
|
47
|
-
* @
|
|
42
|
+
* @private
|
|
48
43
|
*/
|
|
49
44
|
logger;
|
|
50
45
|
/**
|
|
51
46
|
* FIXParser instance, set during plugin register().
|
|
52
|
-
* @protected
|
|
53
|
-
*/
|
|
54
|
-
parser;
|
|
55
|
-
/**
|
|
56
|
-
* Called when server is setup and listening.
|
|
57
|
-
* @protected
|
|
58
|
-
*/
|
|
59
|
-
onReady = void 0;
|
|
60
|
-
/**
|
|
61
|
-
* Map to store verified orders before execution
|
|
62
|
-
* @protected
|
|
63
|
-
*/
|
|
64
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
65
|
-
/**
|
|
66
|
-
* Map to store pending market data requests
|
|
67
|
-
* @protected
|
|
68
|
-
*/
|
|
69
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
70
|
-
/**
|
|
71
|
-
* Map to store market data prices
|
|
72
|
-
* @protected
|
|
73
|
-
*/
|
|
74
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
75
|
-
/**
|
|
76
|
-
* Maximum number of price history entries to keep per symbol
|
|
77
|
-
* @protected
|
|
78
|
-
*/
|
|
79
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
80
|
-
constructor({ logger, onReady }) {
|
|
81
|
-
this.logger = logger;
|
|
82
|
-
this.onReady = onReady;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// src/schemas/schemas.ts
|
|
87
|
-
var toolSchemas = {
|
|
88
|
-
parse: {
|
|
89
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
90
|
-
schema: {
|
|
91
|
-
type: "object",
|
|
92
|
-
properties: {
|
|
93
|
-
fixString: { type: "string" }
|
|
94
|
-
},
|
|
95
|
-
required: ["fixString"]
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
parseToJSON: {
|
|
99
|
-
description: "Parses a FIX message into JSON",
|
|
100
|
-
schema: {
|
|
101
|
-
type: "object",
|
|
102
|
-
properties: {
|
|
103
|
-
fixString: { type: "string" }
|
|
104
|
-
},
|
|
105
|
-
required: ["fixString"]
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
verifyOrder: {
|
|
109
|
-
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
110
|
-
schema: {
|
|
111
|
-
type: "object",
|
|
112
|
-
properties: {
|
|
113
|
-
clOrdID: { type: "string" },
|
|
114
|
-
handlInst: {
|
|
115
|
-
type: "string",
|
|
116
|
-
enum: ["1", "2", "3"],
|
|
117
|
-
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
118
|
-
},
|
|
119
|
-
quantity: { type: "string" },
|
|
120
|
-
price: { type: "string" },
|
|
121
|
-
ordType: {
|
|
122
|
-
type: "string",
|
|
123
|
-
enum: [
|
|
124
|
-
"1",
|
|
125
|
-
"2",
|
|
126
|
-
"3",
|
|
127
|
-
"4",
|
|
128
|
-
"5",
|
|
129
|
-
"6",
|
|
130
|
-
"7",
|
|
131
|
-
"8",
|
|
132
|
-
"9",
|
|
133
|
-
"A",
|
|
134
|
-
"B",
|
|
135
|
-
"C",
|
|
136
|
-
"D",
|
|
137
|
-
"E",
|
|
138
|
-
"F",
|
|
139
|
-
"G",
|
|
140
|
-
"H",
|
|
141
|
-
"I",
|
|
142
|
-
"J",
|
|
143
|
-
"K",
|
|
144
|
-
"L",
|
|
145
|
-
"M",
|
|
146
|
-
"P",
|
|
147
|
-
"Q",
|
|
148
|
-
"R",
|
|
149
|
-
"S"
|
|
150
|
-
],
|
|
151
|
-
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"
|
|
152
|
-
},
|
|
153
|
-
side: {
|
|
154
|
-
type: "string",
|
|
155
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
156
|
-
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"
|
|
157
|
-
},
|
|
158
|
-
symbol: { type: "string" },
|
|
159
|
-
timeInForce: {
|
|
160
|
-
type: "string",
|
|
161
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
162
|
-
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"
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
executeOrder: {
|
|
169
|
-
description: "Executes a verified order. verifyOrder must be called before executeOrder.",
|
|
170
|
-
schema: {
|
|
171
|
-
type: "object",
|
|
172
|
-
properties: {
|
|
173
|
-
clOrdID: { type: "string" },
|
|
174
|
-
handlInst: {
|
|
175
|
-
type: "string",
|
|
176
|
-
enum: ["1", "2", "3"],
|
|
177
|
-
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
178
|
-
},
|
|
179
|
-
quantity: { type: "string" },
|
|
180
|
-
price: { type: "string" },
|
|
181
|
-
ordType: {
|
|
182
|
-
type: "string",
|
|
183
|
-
enum: [
|
|
184
|
-
"1",
|
|
185
|
-
"2",
|
|
186
|
-
"3",
|
|
187
|
-
"4",
|
|
188
|
-
"5",
|
|
189
|
-
"6",
|
|
190
|
-
"7",
|
|
191
|
-
"8",
|
|
192
|
-
"9",
|
|
193
|
-
"A",
|
|
194
|
-
"B",
|
|
195
|
-
"C",
|
|
196
|
-
"D",
|
|
197
|
-
"E",
|
|
198
|
-
"F",
|
|
199
|
-
"G",
|
|
200
|
-
"H",
|
|
201
|
-
"I",
|
|
202
|
-
"J",
|
|
203
|
-
"K",
|
|
204
|
-
"L",
|
|
205
|
-
"M",
|
|
206
|
-
"P",
|
|
207
|
-
"Q",
|
|
208
|
-
"R",
|
|
209
|
-
"S"
|
|
210
|
-
],
|
|
211
|
-
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"
|
|
212
|
-
},
|
|
213
|
-
side: {
|
|
214
|
-
type: "string",
|
|
215
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
216
|
-
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"
|
|
217
|
-
},
|
|
218
|
-
symbol: { type: "string" },
|
|
219
|
-
timeInForce: {
|
|
220
|
-
type: "string",
|
|
221
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
222
|
-
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"
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
marketDataRequest: {
|
|
229
|
-
description: "Requests market data for specified symbols",
|
|
230
|
-
schema: {
|
|
231
|
-
type: "object",
|
|
232
|
-
properties: {
|
|
233
|
-
mdUpdateType: {
|
|
234
|
-
type: "string",
|
|
235
|
-
enum: ["0", "1"],
|
|
236
|
-
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
237
|
-
},
|
|
238
|
-
symbols: { type: "array", items: { type: "string" } },
|
|
239
|
-
mdReqID: { type: "string" },
|
|
240
|
-
subscriptionRequestType: {
|
|
241
|
-
type: "string",
|
|
242
|
-
enum: ["0", "1", "2"],
|
|
243
|
-
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
244
|
-
},
|
|
245
|
-
mdEntryTypes: {
|
|
246
|
-
type: "array",
|
|
247
|
-
items: {
|
|
248
|
-
type: "string",
|
|
249
|
-
enum: [
|
|
250
|
-
"0",
|
|
251
|
-
"1",
|
|
252
|
-
"2",
|
|
253
|
-
"3",
|
|
254
|
-
"4",
|
|
255
|
-
"5",
|
|
256
|
-
"6",
|
|
257
|
-
"7",
|
|
258
|
-
"8",
|
|
259
|
-
"9",
|
|
260
|
-
"A",
|
|
261
|
-
"B",
|
|
262
|
-
"C",
|
|
263
|
-
"D",
|
|
264
|
-
"E",
|
|
265
|
-
"F",
|
|
266
|
-
"G",
|
|
267
|
-
"H",
|
|
268
|
-
"I",
|
|
269
|
-
"J",
|
|
270
|
-
"K",
|
|
271
|
-
"L",
|
|
272
|
-
"M",
|
|
273
|
-
"N",
|
|
274
|
-
"O",
|
|
275
|
-
"P",
|
|
276
|
-
"Q",
|
|
277
|
-
"R",
|
|
278
|
-
"S",
|
|
279
|
-
"T",
|
|
280
|
-
"U",
|
|
281
|
-
"V",
|
|
282
|
-
"W",
|
|
283
|
-
"X",
|
|
284
|
-
"Y",
|
|
285
|
-
"Z"
|
|
286
|
-
]
|
|
287
|
-
},
|
|
288
|
-
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"
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
getStockGraph: {
|
|
295
|
-
description: "Generates a price chart for a given symbol",
|
|
296
|
-
schema: {
|
|
297
|
-
type: "object",
|
|
298
|
-
properties: {
|
|
299
|
-
symbol: { type: "string" }
|
|
300
|
-
},
|
|
301
|
-
required: ["symbol"]
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
getStockPriceHistory: {
|
|
305
|
-
description: "Returns price history for a given symbol",
|
|
306
|
-
schema: {
|
|
307
|
-
type: "object",
|
|
308
|
-
properties: {
|
|
309
|
-
symbol: { type: "string" }
|
|
310
|
-
},
|
|
311
|
-
required: ["symbol"]
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// src/tools/marketData.ts
|
|
317
|
-
var import_fixparser = require("fixparser");
|
|
318
|
-
var import_quickchart_js = __toESM(require("quickchart-js"), 1);
|
|
319
|
-
var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
320
|
-
return async (args) => {
|
|
321
|
-
try {
|
|
322
|
-
const response = new Promise((resolve) => {
|
|
323
|
-
pendingRequests.set(args.mdReqID, resolve);
|
|
324
|
-
});
|
|
325
|
-
const entryTypes = args.mdEntryTypes || [
|
|
326
|
-
import_fixparser.MDEntryType.Bid,
|
|
327
|
-
import_fixparser.MDEntryType.Offer,
|
|
328
|
-
import_fixparser.MDEntryType.Trade,
|
|
329
|
-
import_fixparser.MDEntryType.IndexValue,
|
|
330
|
-
import_fixparser.MDEntryType.OpeningPrice,
|
|
331
|
-
import_fixparser.MDEntryType.ClosingPrice,
|
|
332
|
-
import_fixparser.MDEntryType.SettlementPrice,
|
|
333
|
-
import_fixparser.MDEntryType.TradingSessionHighPrice,
|
|
334
|
-
import_fixparser.MDEntryType.TradingSessionLowPrice,
|
|
335
|
-
import_fixparser.MDEntryType.VWAP,
|
|
336
|
-
import_fixparser.MDEntryType.Imbalance,
|
|
337
|
-
import_fixparser.MDEntryType.TradeVolume,
|
|
338
|
-
import_fixparser.MDEntryType.OpenInterest,
|
|
339
|
-
import_fixparser.MDEntryType.CompositeUnderlyingPrice,
|
|
340
|
-
import_fixparser.MDEntryType.SimulatedSellPrice,
|
|
341
|
-
import_fixparser.MDEntryType.SimulatedBuyPrice,
|
|
342
|
-
import_fixparser.MDEntryType.MarginRate,
|
|
343
|
-
import_fixparser.MDEntryType.MidPrice,
|
|
344
|
-
import_fixparser.MDEntryType.EmptyBook,
|
|
345
|
-
import_fixparser.MDEntryType.SettleHighPrice,
|
|
346
|
-
import_fixparser.MDEntryType.SettleLowPrice,
|
|
347
|
-
import_fixparser.MDEntryType.PriorSettlePrice,
|
|
348
|
-
import_fixparser.MDEntryType.SessionHighBid,
|
|
349
|
-
import_fixparser.MDEntryType.SessionLowOffer,
|
|
350
|
-
import_fixparser.MDEntryType.EarlyPrices,
|
|
351
|
-
import_fixparser.MDEntryType.AuctionClearingPrice,
|
|
352
|
-
import_fixparser.MDEntryType.SwapValueFactor,
|
|
353
|
-
import_fixparser.MDEntryType.DailyValueAdjustmentForLongPositions,
|
|
354
|
-
import_fixparser.MDEntryType.CumulativeValueAdjustmentForLongPositions,
|
|
355
|
-
import_fixparser.MDEntryType.DailyValueAdjustmentForShortPositions,
|
|
356
|
-
import_fixparser.MDEntryType.CumulativeValueAdjustmentForShortPositions,
|
|
357
|
-
import_fixparser.MDEntryType.FixingPrice,
|
|
358
|
-
import_fixparser.MDEntryType.CashRate,
|
|
359
|
-
import_fixparser.MDEntryType.RecoveryRate,
|
|
360
|
-
import_fixparser.MDEntryType.RecoveryRateForLong,
|
|
361
|
-
import_fixparser.MDEntryType.RecoveryRateForShort,
|
|
362
|
-
import_fixparser.MDEntryType.MarketBid,
|
|
363
|
-
import_fixparser.MDEntryType.MarketOffer,
|
|
364
|
-
import_fixparser.MDEntryType.ShortSaleMinPrice,
|
|
365
|
-
import_fixparser.MDEntryType.PreviousClosingPrice,
|
|
366
|
-
import_fixparser.MDEntryType.ThresholdLimitPriceBanding,
|
|
367
|
-
import_fixparser.MDEntryType.DailyFinancingValue,
|
|
368
|
-
import_fixparser.MDEntryType.AccruedFinancingValue,
|
|
369
|
-
import_fixparser.MDEntryType.TWAP
|
|
370
|
-
];
|
|
371
|
-
const messageFields = [
|
|
372
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
373
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
|
|
374
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
375
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
|
|
376
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
|
|
377
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
378
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
379
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
380
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
381
|
-
];
|
|
382
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
383
|
-
args.symbols.forEach((symbol) => {
|
|
384
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
385
|
-
});
|
|
386
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
|
|
387
|
-
entryTypes.forEach((entryType) => {
|
|
388
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
389
|
-
});
|
|
390
|
-
const mdr = parser.createMessage(...messageFields);
|
|
391
|
-
if (!parser.connected) {
|
|
392
|
-
return {
|
|
393
|
-
content: [
|
|
394
|
-
{
|
|
395
|
-
type: "text",
|
|
396
|
-
text: "Error: Not connected. Ignoring message.",
|
|
397
|
-
uri: "marketDataRequest"
|
|
398
|
-
}
|
|
399
|
-
],
|
|
400
|
-
isError: true
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
parser.send(mdr);
|
|
404
|
-
const fixData = await response;
|
|
405
|
-
return {
|
|
406
|
-
content: [
|
|
407
|
-
{
|
|
408
|
-
type: "text",
|
|
409
|
-
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
410
|
-
uri: "marketDataRequest"
|
|
411
|
-
}
|
|
412
|
-
]
|
|
413
|
-
};
|
|
414
|
-
} catch (error) {
|
|
415
|
-
return {
|
|
416
|
-
content: [
|
|
417
|
-
{
|
|
418
|
-
type: "text",
|
|
419
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
420
|
-
uri: "marketDataRequest"
|
|
421
|
-
}
|
|
422
|
-
],
|
|
423
|
-
isError: true
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
};
|
|
428
|
-
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
429
|
-
return async (args) => {
|
|
430
|
-
try {
|
|
431
|
-
const symbol = args.symbol;
|
|
432
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
433
|
-
if (priceHistory.length === 0) {
|
|
434
|
-
return {
|
|
435
|
-
content: [
|
|
436
|
-
{
|
|
437
|
-
type: "text",
|
|
438
|
-
text: `No price data available for ${symbol}`,
|
|
439
|
-
uri: "getStockGraph"
|
|
440
|
-
}
|
|
441
|
-
]
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
const chart = new import_quickchart_js.default();
|
|
445
|
-
chart.setWidth(1200);
|
|
446
|
-
chart.setHeight(600);
|
|
447
|
-
chart.setBackgroundColor("transparent");
|
|
448
|
-
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
449
|
-
const bidData = priceHistory.map((point) => point.bid);
|
|
450
|
-
const offerData = priceHistory.map((point) => point.offer);
|
|
451
|
-
const spreadData = priceHistory.map((point) => point.spread);
|
|
452
|
-
const volumeData = priceHistory.map((point) => point.volume);
|
|
453
|
-
const config = {
|
|
454
|
-
type: "line",
|
|
455
|
-
data: {
|
|
456
|
-
labels,
|
|
457
|
-
datasets: [
|
|
458
|
-
{
|
|
459
|
-
label: "Bid",
|
|
460
|
-
data: bidData,
|
|
461
|
-
borderColor: "#28a745",
|
|
462
|
-
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
463
|
-
fill: false,
|
|
464
|
-
tension: 0.4
|
|
465
|
-
},
|
|
466
|
-
{
|
|
467
|
-
label: "Offer",
|
|
468
|
-
data: offerData,
|
|
469
|
-
borderColor: "#dc3545",
|
|
470
|
-
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
471
|
-
fill: false,
|
|
472
|
-
tension: 0.4
|
|
473
|
-
},
|
|
474
|
-
{
|
|
475
|
-
label: "Spread",
|
|
476
|
-
data: spreadData,
|
|
477
|
-
borderColor: "#6c757d",
|
|
478
|
-
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
479
|
-
fill: false,
|
|
480
|
-
tension: 0.4
|
|
481
|
-
},
|
|
482
|
-
{
|
|
483
|
-
label: "Volume",
|
|
484
|
-
data: volumeData,
|
|
485
|
-
borderColor: "#007bff",
|
|
486
|
-
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
487
|
-
fill: true,
|
|
488
|
-
tension: 0.4
|
|
489
|
-
}
|
|
490
|
-
]
|
|
491
|
-
},
|
|
492
|
-
options: {
|
|
493
|
-
responsive: true,
|
|
494
|
-
plugins: {
|
|
495
|
-
title: {
|
|
496
|
-
display: true,
|
|
497
|
-
text: `${symbol} Market Data`
|
|
498
|
-
}
|
|
499
|
-
},
|
|
500
|
-
scales: {
|
|
501
|
-
y: {
|
|
502
|
-
beginAtZero: false
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
chart.setConfig(config);
|
|
508
|
-
const imageBuffer = await chart.toBinary();
|
|
509
|
-
const base64 = imageBuffer.toString("base64");
|
|
510
|
-
return {
|
|
511
|
-
content: [
|
|
512
|
-
{
|
|
513
|
-
type: "resource",
|
|
514
|
-
resource: {
|
|
515
|
-
uri: "resource://graph",
|
|
516
|
-
mimeType: "image/png",
|
|
517
|
-
blob: base64
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
]
|
|
521
|
-
};
|
|
522
|
-
} catch (error) {
|
|
523
|
-
return {
|
|
524
|
-
content: [
|
|
525
|
-
{
|
|
526
|
-
type: "text",
|
|
527
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
528
|
-
uri: "getStockGraph"
|
|
529
|
-
}
|
|
530
|
-
],
|
|
531
|
-
isError: true
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
};
|
|
536
|
-
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
537
|
-
return async (args) => {
|
|
538
|
-
try {
|
|
539
|
-
const symbol = args.symbol;
|
|
540
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
541
|
-
if (priceHistory.length === 0) {
|
|
542
|
-
return {
|
|
543
|
-
content: [
|
|
544
|
-
{
|
|
545
|
-
type: "text",
|
|
546
|
-
text: `No price data available for ${symbol}`,
|
|
547
|
-
uri: "getStockPriceHistory"
|
|
548
|
-
}
|
|
549
|
-
]
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
return {
|
|
553
|
-
content: [
|
|
554
|
-
{
|
|
555
|
-
type: "text",
|
|
556
|
-
text: JSON.stringify(
|
|
557
|
-
{
|
|
558
|
-
symbol,
|
|
559
|
-
count: priceHistory.length,
|
|
560
|
-
data: priceHistory.map((point) => ({
|
|
561
|
-
timestamp: new Date(point.timestamp).toISOString(),
|
|
562
|
-
bid: point.bid,
|
|
563
|
-
offer: point.offer,
|
|
564
|
-
spread: point.spread,
|
|
565
|
-
volume: point.volume
|
|
566
|
-
}))
|
|
567
|
-
},
|
|
568
|
-
null,
|
|
569
|
-
2
|
|
570
|
-
),
|
|
571
|
-
uri: "getStockPriceHistory"
|
|
572
|
-
}
|
|
573
|
-
]
|
|
574
|
-
};
|
|
575
|
-
} catch (error) {
|
|
576
|
-
return {
|
|
577
|
-
content: [
|
|
578
|
-
{
|
|
579
|
-
type: "text",
|
|
580
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
581
|
-
uri: "getStockPriceHistory"
|
|
582
|
-
}
|
|
583
|
-
],
|
|
584
|
-
isError: true
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
// src/tools/order.ts
|
|
591
|
-
var import_fixparser2 = require("fixparser");
|
|
592
|
-
var ordTypeNames = {
|
|
593
|
-
"1": "Market",
|
|
594
|
-
"2": "Limit",
|
|
595
|
-
"3": "Stop",
|
|
596
|
-
"4": "StopLimit",
|
|
597
|
-
"5": "MarketOnClose",
|
|
598
|
-
"6": "WithOrWithout",
|
|
599
|
-
"7": "LimitOrBetter",
|
|
600
|
-
"8": "LimitWithOrWithout",
|
|
601
|
-
"9": "OnBasis",
|
|
602
|
-
A: "OnClose",
|
|
603
|
-
B: "LimitOnClose",
|
|
604
|
-
C: "ForexMarket",
|
|
605
|
-
D: "PreviouslyQuoted",
|
|
606
|
-
E: "PreviouslyIndicated",
|
|
607
|
-
F: "ForexLimit",
|
|
608
|
-
G: "ForexSwap",
|
|
609
|
-
H: "ForexPreviouslyQuoted",
|
|
610
|
-
I: "Funari",
|
|
611
|
-
J: "MarketIfTouched",
|
|
612
|
-
K: "MarketWithLeftOverAsLimit",
|
|
613
|
-
L: "PreviousFundValuationPoint",
|
|
614
|
-
M: "NextFundValuationPoint",
|
|
615
|
-
P: "Pegged",
|
|
616
|
-
Q: "CounterOrderSelection",
|
|
617
|
-
R: "StopOnBidOrOffer",
|
|
618
|
-
S: "StopLimitOnBidOrOffer"
|
|
619
|
-
};
|
|
620
|
-
var sideNames = {
|
|
621
|
-
"1": "Buy",
|
|
622
|
-
"2": "Sell",
|
|
623
|
-
"3": "BuyMinus",
|
|
624
|
-
"4": "SellPlus",
|
|
625
|
-
"5": "SellShort",
|
|
626
|
-
"6": "SellShortExempt",
|
|
627
|
-
"7": "Undisclosed",
|
|
628
|
-
"8": "Cross",
|
|
629
|
-
"9": "CrossShort",
|
|
630
|
-
A: "CrossShortExempt",
|
|
631
|
-
B: "AsDefined",
|
|
632
|
-
C: "Opposite",
|
|
633
|
-
D: "Subscribe",
|
|
634
|
-
E: "Redeem",
|
|
635
|
-
F: "Lend",
|
|
636
|
-
G: "Borrow",
|
|
637
|
-
H: "SellUndisclosed"
|
|
638
|
-
};
|
|
639
|
-
var timeInForceNames = {
|
|
640
|
-
"0": "Day",
|
|
641
|
-
"1": "GoodTillCancel",
|
|
642
|
-
"2": "AtTheOpening",
|
|
643
|
-
"3": "ImmediateOrCancel",
|
|
644
|
-
"4": "FillOrKill",
|
|
645
|
-
"5": "GoodTillCrossing",
|
|
646
|
-
"6": "GoodTillDate",
|
|
647
|
-
"7": "AtTheClose",
|
|
648
|
-
"8": "GoodThroughCrossing",
|
|
649
|
-
"9": "AtCrossing",
|
|
650
|
-
A: "GoodForTime",
|
|
651
|
-
B: "GoodForAuction",
|
|
652
|
-
C: "GoodForMonth"
|
|
653
|
-
};
|
|
654
|
-
var handlInstNames = {
|
|
655
|
-
"1": "AutomatedExecutionNoIntervention",
|
|
656
|
-
"2": "AutomatedExecutionInterventionOK",
|
|
657
|
-
"3": "ManualOrder"
|
|
658
|
-
};
|
|
659
|
-
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
660
|
-
return async (args) => {
|
|
661
|
-
try {
|
|
662
|
-
verifiedOrders.set(args.clOrdID, {
|
|
663
|
-
clOrdID: args.clOrdID,
|
|
664
|
-
handlInst: args.handlInst,
|
|
665
|
-
quantity: Number.parseFloat(String(args.quantity)),
|
|
666
|
-
price: Number.parseFloat(String(args.price)),
|
|
667
|
-
ordType: args.ordType,
|
|
668
|
-
side: args.side,
|
|
669
|
-
symbol: args.symbol,
|
|
670
|
-
timeInForce: args.timeInForce
|
|
671
|
-
});
|
|
672
|
-
return {
|
|
673
|
-
content: [
|
|
674
|
-
{
|
|
675
|
-
type: "text",
|
|
676
|
-
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
677
|
-
|
|
678
|
-
Parameters verified:
|
|
679
|
-
- ClOrdID: ${args.clOrdID}
|
|
680
|
-
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
681
|
-
- Quantity: ${args.quantity}
|
|
682
|
-
- Price: ${args.price}
|
|
683
|
-
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
684
|
-
- Side: ${args.side} (${sideNames[args.side]})
|
|
685
|
-
- Symbol: ${args.symbol}
|
|
686
|
-
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
687
|
-
|
|
688
|
-
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
689
|
-
uri: "verifyOrder"
|
|
690
|
-
}
|
|
691
|
-
]
|
|
692
|
-
};
|
|
693
|
-
} catch (error) {
|
|
694
|
-
return {
|
|
695
|
-
content: [
|
|
696
|
-
{
|
|
697
|
-
type: "text",
|
|
698
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
699
|
-
uri: "verifyOrder"
|
|
700
|
-
}
|
|
701
|
-
],
|
|
702
|
-
isError: true
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
};
|
|
707
|
-
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
708
|
-
return async (args) => {
|
|
709
|
-
try {
|
|
710
|
-
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
711
|
-
if (!verifiedOrder) {
|
|
712
|
-
return {
|
|
713
|
-
content: [
|
|
714
|
-
{
|
|
715
|
-
type: "text",
|
|
716
|
-
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
717
|
-
uri: "executeOrder"
|
|
718
|
-
}
|
|
719
|
-
],
|
|
720
|
-
isError: true
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
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) {
|
|
724
|
-
return {
|
|
725
|
-
content: [
|
|
726
|
-
{
|
|
727
|
-
type: "text",
|
|
728
|
-
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
729
|
-
uri: "executeOrder"
|
|
730
|
-
}
|
|
731
|
-
],
|
|
732
|
-
isError: true
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
const response = new Promise((resolve) => {
|
|
736
|
-
pendingRequests.set(args.clOrdID, resolve);
|
|
737
|
-
});
|
|
738
|
-
const order = parser.createMessage(
|
|
739
|
-
new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
|
|
740
|
-
new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
741
|
-
new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
|
|
742
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
|
|
743
|
-
new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
|
|
744
|
-
new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
|
|
745
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
|
|
746
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
|
|
747
|
-
new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
748
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
|
|
749
|
-
new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
|
|
750
|
-
new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
|
|
751
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
|
|
752
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
|
|
753
|
-
);
|
|
754
|
-
if (!parser.connected) {
|
|
755
|
-
return {
|
|
756
|
-
content: [
|
|
757
|
-
{
|
|
758
|
-
type: "text",
|
|
759
|
-
text: "Error: Not connected. Ignoring message.",
|
|
760
|
-
uri: "executeOrder"
|
|
761
|
-
}
|
|
762
|
-
],
|
|
763
|
-
isError: true
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
parser.send(order);
|
|
767
|
-
const fixData = await response;
|
|
768
|
-
verifiedOrders.delete(args.clOrdID);
|
|
769
|
-
return {
|
|
770
|
-
content: [
|
|
771
|
-
{
|
|
772
|
-
type: "text",
|
|
773
|
-
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())}`,
|
|
774
|
-
uri: "executeOrder"
|
|
775
|
-
}
|
|
776
|
-
]
|
|
777
|
-
};
|
|
778
|
-
} catch (error) {
|
|
779
|
-
return {
|
|
780
|
-
content: [
|
|
781
|
-
{
|
|
782
|
-
type: "text",
|
|
783
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
784
|
-
uri: "executeOrder"
|
|
785
|
-
}
|
|
786
|
-
],
|
|
787
|
-
isError: true
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
};
|
|
791
|
-
};
|
|
792
|
-
|
|
793
|
-
// src/tools/parse.ts
|
|
794
|
-
var createParseHandler = (parser) => {
|
|
795
|
-
return async (args) => {
|
|
796
|
-
try {
|
|
797
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
798
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
799
|
-
return {
|
|
800
|
-
content: [
|
|
801
|
-
{
|
|
802
|
-
type: "text",
|
|
803
|
-
text: "Error: Failed to parse FIX string",
|
|
804
|
-
uri: "parse"
|
|
805
|
-
}
|
|
806
|
-
],
|
|
807
|
-
isError: true
|
|
808
|
-
};
|
|
809
|
-
}
|
|
810
|
-
return {
|
|
811
|
-
content: [
|
|
812
|
-
{
|
|
813
|
-
type: "text",
|
|
814
|
-
text: `${parsedMessage[0].description}
|
|
815
|
-
${parsedMessage[0].messageTypeDescription}`,
|
|
816
|
-
uri: "parse"
|
|
817
|
-
}
|
|
818
|
-
]
|
|
819
|
-
};
|
|
820
|
-
} catch (error) {
|
|
821
|
-
return {
|
|
822
|
-
content: [
|
|
823
|
-
{
|
|
824
|
-
type: "text",
|
|
825
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
826
|
-
uri: "parse"
|
|
827
|
-
}
|
|
828
|
-
],
|
|
829
|
-
isError: true
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
};
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
// src/tools/parseToJSON.ts
|
|
836
|
-
var createParseToJSONHandler = (parser) => {
|
|
837
|
-
return async (args) => {
|
|
838
|
-
try {
|
|
839
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
840
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
841
|
-
return {
|
|
842
|
-
content: [
|
|
843
|
-
{
|
|
844
|
-
type: "text",
|
|
845
|
-
text: "Error: Failed to parse FIX string",
|
|
846
|
-
uri: "parseToJSON"
|
|
847
|
-
}
|
|
848
|
-
],
|
|
849
|
-
isError: true
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
|
-
return {
|
|
853
|
-
content: [
|
|
854
|
-
{
|
|
855
|
-
type: "text",
|
|
856
|
-
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
857
|
-
uri: "parseToJSON"
|
|
858
|
-
}
|
|
859
|
-
]
|
|
860
|
-
};
|
|
861
|
-
} catch (error) {
|
|
862
|
-
return {
|
|
863
|
-
content: [
|
|
864
|
-
{
|
|
865
|
-
type: "text",
|
|
866
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
867
|
-
uri: "parseToJSON"
|
|
868
|
-
}
|
|
869
|
-
],
|
|
870
|
-
isError: true
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
};
|
|
875
|
-
|
|
876
|
-
// src/tools/index.ts
|
|
877
|
-
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
878
|
-
parse: createParseHandler(parser),
|
|
879
|
-
parseToJSON: createParseToJSONHandler(parser),
|
|
880
|
-
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
881
|
-
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
882
|
-
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
883
|
-
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
884
|
-
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
885
|
-
});
|
|
886
|
-
|
|
887
|
-
// src/utils/messageHandler.ts
|
|
888
|
-
var import_fixparser3 = require("fixparser");
|
|
889
|
-
function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
|
|
890
|
-
parser.logger.log({
|
|
891
|
-
level: "info",
|
|
892
|
-
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
893
|
-
});
|
|
894
|
-
const msgType = message.messageType;
|
|
895
|
-
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
|
|
896
|
-
const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
|
|
897
|
-
const fixJson = message.toFIXJSON();
|
|
898
|
-
const entries = fixJson.Body?.NoMDEntries || [];
|
|
899
|
-
const data = {
|
|
900
|
-
timestamp: Date.now(),
|
|
901
|
-
bid: 0,
|
|
902
|
-
offer: 0,
|
|
903
|
-
spread: 0,
|
|
904
|
-
volume: 0,
|
|
905
|
-
trade: 0,
|
|
906
|
-
indexValue: 0,
|
|
907
|
-
openingPrice: 0,
|
|
908
|
-
closingPrice: 0,
|
|
909
|
-
settlementPrice: 0,
|
|
910
|
-
tradingSessionHighPrice: 0,
|
|
911
|
-
tradingSessionLowPrice: 0,
|
|
912
|
-
vwap: 0,
|
|
913
|
-
imbalance: 0,
|
|
914
|
-
openInterest: 0,
|
|
915
|
-
compositeUnderlyingPrice: 0,
|
|
916
|
-
simulatedSellPrice: 0,
|
|
917
|
-
simulatedBuyPrice: 0,
|
|
918
|
-
marginRate: 0,
|
|
919
|
-
midPrice: 0,
|
|
920
|
-
emptyBook: 0,
|
|
921
|
-
settleHighPrice: 0,
|
|
922
|
-
settleLowPrice: 0,
|
|
923
|
-
priorSettlePrice: 0,
|
|
924
|
-
sessionHighBid: 0,
|
|
925
|
-
sessionLowOffer: 0,
|
|
926
|
-
earlyPrices: 0,
|
|
927
|
-
auctionClearingPrice: 0,
|
|
928
|
-
swapValueFactor: 0,
|
|
929
|
-
dailyValueAdjustmentForLongPositions: 0,
|
|
930
|
-
cumulativeValueAdjustmentForLongPositions: 0,
|
|
931
|
-
dailyValueAdjustmentForShortPositions: 0,
|
|
932
|
-
cumulativeValueAdjustmentForShortPositions: 0,
|
|
933
|
-
fixingPrice: 0,
|
|
934
|
-
cashRate: 0,
|
|
935
|
-
recoveryRate: 0,
|
|
936
|
-
recoveryRateForLong: 0,
|
|
937
|
-
recoveryRateForShort: 0,
|
|
938
|
-
marketBid: 0,
|
|
939
|
-
marketOffer: 0,
|
|
940
|
-
shortSaleMinPrice: 0,
|
|
941
|
-
previousClosingPrice: 0,
|
|
942
|
-
thresholdLimitPriceBanding: 0,
|
|
943
|
-
dailyFinancingValue: 0,
|
|
944
|
-
accruedFinancingValue: 0,
|
|
945
|
-
twap: 0
|
|
946
|
-
};
|
|
947
|
-
for (const entry of entries) {
|
|
948
|
-
const entryType = entry.MDEntryType;
|
|
949
|
-
const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
|
|
950
|
-
const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
|
|
951
|
-
switch (entryType) {
|
|
952
|
-
case import_fixparser3.MDEntryType.Bid:
|
|
953
|
-
data.bid = price;
|
|
954
|
-
break;
|
|
955
|
-
case import_fixparser3.MDEntryType.Offer:
|
|
956
|
-
data.offer = price;
|
|
957
|
-
break;
|
|
958
|
-
case import_fixparser3.MDEntryType.Trade:
|
|
959
|
-
data.trade = price;
|
|
960
|
-
break;
|
|
961
|
-
case import_fixparser3.MDEntryType.IndexValue:
|
|
962
|
-
data.indexValue = price;
|
|
963
|
-
break;
|
|
964
|
-
case import_fixparser3.MDEntryType.OpeningPrice:
|
|
965
|
-
data.openingPrice = price;
|
|
966
|
-
break;
|
|
967
|
-
case import_fixparser3.MDEntryType.ClosingPrice:
|
|
968
|
-
data.closingPrice = price;
|
|
969
|
-
break;
|
|
970
|
-
case import_fixparser3.MDEntryType.SettlementPrice:
|
|
971
|
-
data.settlementPrice = price;
|
|
972
|
-
break;
|
|
973
|
-
case import_fixparser3.MDEntryType.TradingSessionHighPrice:
|
|
974
|
-
data.tradingSessionHighPrice = price;
|
|
975
|
-
break;
|
|
976
|
-
case import_fixparser3.MDEntryType.TradingSessionLowPrice:
|
|
977
|
-
data.tradingSessionLowPrice = price;
|
|
978
|
-
break;
|
|
979
|
-
case import_fixparser3.MDEntryType.VWAP:
|
|
980
|
-
data.vwap = price;
|
|
981
|
-
break;
|
|
982
|
-
case import_fixparser3.MDEntryType.Imbalance:
|
|
983
|
-
data.imbalance = size;
|
|
984
|
-
break;
|
|
985
|
-
case import_fixparser3.MDEntryType.TradeVolume:
|
|
986
|
-
data.volume = size;
|
|
987
|
-
break;
|
|
988
|
-
case import_fixparser3.MDEntryType.OpenInterest:
|
|
989
|
-
data.openInterest = size;
|
|
990
|
-
break;
|
|
991
|
-
case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
|
|
992
|
-
data.compositeUnderlyingPrice = price;
|
|
993
|
-
break;
|
|
994
|
-
case import_fixparser3.MDEntryType.SimulatedSellPrice:
|
|
995
|
-
data.simulatedSellPrice = price;
|
|
996
|
-
break;
|
|
997
|
-
case import_fixparser3.MDEntryType.SimulatedBuyPrice:
|
|
998
|
-
data.simulatedBuyPrice = price;
|
|
999
|
-
break;
|
|
1000
|
-
case import_fixparser3.MDEntryType.MarginRate:
|
|
1001
|
-
data.marginRate = price;
|
|
1002
|
-
break;
|
|
1003
|
-
case import_fixparser3.MDEntryType.MidPrice:
|
|
1004
|
-
data.midPrice = price;
|
|
1005
|
-
break;
|
|
1006
|
-
case import_fixparser3.MDEntryType.EmptyBook:
|
|
1007
|
-
data.emptyBook = 1;
|
|
1008
|
-
break;
|
|
1009
|
-
case import_fixparser3.MDEntryType.SettleHighPrice:
|
|
1010
|
-
data.settleHighPrice = price;
|
|
1011
|
-
break;
|
|
1012
|
-
case import_fixparser3.MDEntryType.SettleLowPrice:
|
|
1013
|
-
data.settleLowPrice = price;
|
|
1014
|
-
break;
|
|
1015
|
-
case import_fixparser3.MDEntryType.PriorSettlePrice:
|
|
1016
|
-
data.priorSettlePrice = price;
|
|
1017
|
-
break;
|
|
1018
|
-
case import_fixparser3.MDEntryType.SessionHighBid:
|
|
1019
|
-
data.sessionHighBid = price;
|
|
1020
|
-
break;
|
|
1021
|
-
case import_fixparser3.MDEntryType.SessionLowOffer:
|
|
1022
|
-
data.sessionLowOffer = price;
|
|
1023
|
-
break;
|
|
1024
|
-
case import_fixparser3.MDEntryType.EarlyPrices:
|
|
1025
|
-
data.earlyPrices = price;
|
|
1026
|
-
break;
|
|
1027
|
-
case import_fixparser3.MDEntryType.AuctionClearingPrice:
|
|
1028
|
-
data.auctionClearingPrice = price;
|
|
1029
|
-
break;
|
|
1030
|
-
case import_fixparser3.MDEntryType.SwapValueFactor:
|
|
1031
|
-
data.swapValueFactor = price;
|
|
1032
|
-
break;
|
|
1033
|
-
case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
|
|
1034
|
-
data.dailyValueAdjustmentForLongPositions = price;
|
|
1035
|
-
break;
|
|
1036
|
-
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
|
|
1037
|
-
data.cumulativeValueAdjustmentForLongPositions = price;
|
|
1038
|
-
break;
|
|
1039
|
-
case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
|
|
1040
|
-
data.dailyValueAdjustmentForShortPositions = price;
|
|
1041
|
-
break;
|
|
1042
|
-
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
|
|
1043
|
-
data.cumulativeValueAdjustmentForShortPositions = price;
|
|
1044
|
-
break;
|
|
1045
|
-
case import_fixparser3.MDEntryType.FixingPrice:
|
|
1046
|
-
data.fixingPrice = price;
|
|
1047
|
-
break;
|
|
1048
|
-
case import_fixparser3.MDEntryType.CashRate:
|
|
1049
|
-
data.cashRate = price;
|
|
1050
|
-
break;
|
|
1051
|
-
case import_fixparser3.MDEntryType.RecoveryRate:
|
|
1052
|
-
data.recoveryRate = price;
|
|
1053
|
-
break;
|
|
1054
|
-
case import_fixparser3.MDEntryType.RecoveryRateForLong:
|
|
1055
|
-
data.recoveryRateForLong = price;
|
|
1056
|
-
break;
|
|
1057
|
-
case import_fixparser3.MDEntryType.RecoveryRateForShort:
|
|
1058
|
-
data.recoveryRateForShort = price;
|
|
1059
|
-
break;
|
|
1060
|
-
case import_fixparser3.MDEntryType.MarketBid:
|
|
1061
|
-
data.marketBid = price;
|
|
1062
|
-
break;
|
|
1063
|
-
case import_fixparser3.MDEntryType.MarketOffer:
|
|
1064
|
-
data.marketOffer = price;
|
|
1065
|
-
break;
|
|
1066
|
-
case import_fixparser3.MDEntryType.ShortSaleMinPrice:
|
|
1067
|
-
data.shortSaleMinPrice = price;
|
|
1068
|
-
break;
|
|
1069
|
-
case import_fixparser3.MDEntryType.PreviousClosingPrice:
|
|
1070
|
-
data.previousClosingPrice = price;
|
|
1071
|
-
break;
|
|
1072
|
-
case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
|
|
1073
|
-
data.thresholdLimitPriceBanding = price;
|
|
1074
|
-
break;
|
|
1075
|
-
case import_fixparser3.MDEntryType.DailyFinancingValue:
|
|
1076
|
-
data.dailyFinancingValue = price;
|
|
1077
|
-
break;
|
|
1078
|
-
case import_fixparser3.MDEntryType.AccruedFinancingValue:
|
|
1079
|
-
data.accruedFinancingValue = price;
|
|
1080
|
-
break;
|
|
1081
|
-
case import_fixparser3.MDEntryType.TWAP:
|
|
1082
|
-
data.twap = price;
|
|
1083
|
-
break;
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
data.spread = data.offer - data.bid;
|
|
1087
|
-
if (!marketDataPrices.has(symbol)) {
|
|
1088
|
-
marketDataPrices.set(symbol, []);
|
|
1089
|
-
}
|
|
1090
|
-
const prices = marketDataPrices.get(symbol);
|
|
1091
|
-
prices.push(data);
|
|
1092
|
-
if (prices.length > maxPriceHistory) {
|
|
1093
|
-
prices.splice(0, prices.length - maxPriceHistory);
|
|
1094
|
-
}
|
|
1095
|
-
onPriceUpdate?.(symbol, data);
|
|
1096
|
-
const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
|
|
1097
|
-
if (mdReqID) {
|
|
1098
|
-
const callback = pendingRequests.get(mdReqID);
|
|
1099
|
-
if (callback) {
|
|
1100
|
-
callback(message);
|
|
1101
|
-
pendingRequests.delete(mdReqID);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
} else if (msgType === import_fixparser3.Messages.ExecutionReport) {
|
|
1105
|
-
const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
|
|
1106
|
-
const callback = pendingRequests.get(reqId);
|
|
1107
|
-
if (callback) {
|
|
1108
|
-
callback(message);
|
|
1109
|
-
pendingRequests.delete(reqId);
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
// src/MCPRemote.ts
|
|
1115
|
-
var transports = {};
|
|
1116
|
-
function jsonSchemaToZod(schema) {
|
|
1117
|
-
if (schema.type === "object") {
|
|
1118
|
-
const shape = {};
|
|
1119
|
-
for (const [key, prop] of Object.entries(schema.properties || {})) {
|
|
1120
|
-
const propSchema = prop;
|
|
1121
|
-
if (propSchema.type === "string") {
|
|
1122
|
-
if (propSchema.enum) {
|
|
1123
|
-
shape[key] = import_zod.z.enum(propSchema.enum);
|
|
1124
|
-
} else {
|
|
1125
|
-
shape[key] = import_zod.z.string();
|
|
1126
|
-
}
|
|
1127
|
-
} else if (propSchema.type === "number") {
|
|
1128
|
-
shape[key] = import_zod.z.number();
|
|
1129
|
-
} else if (propSchema.type === "boolean") {
|
|
1130
|
-
shape[key] = import_zod.z.boolean();
|
|
1131
|
-
} else if (propSchema.type === "array") {
|
|
1132
|
-
if (propSchema.items.type === "string") {
|
|
1133
|
-
shape[key] = import_zod.z.array(import_zod.z.string());
|
|
1134
|
-
} else if (propSchema.items.type === "number") {
|
|
1135
|
-
shape[key] = import_zod.z.array(import_zod.z.number());
|
|
1136
|
-
} else if (propSchema.items.type === "boolean") {
|
|
1137
|
-
shape[key] = import_zod.z.array(import_zod.z.boolean());
|
|
1138
|
-
} else {
|
|
1139
|
-
shape[key] = import_zod.z.array(import_zod.z.any());
|
|
1140
|
-
}
|
|
1141
|
-
} else {
|
|
1142
|
-
shape[key] = import_zod.z.any();
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
return shape;
|
|
1146
|
-
}
|
|
1147
|
-
return {};
|
|
1148
|
-
}
|
|
1149
|
-
var MCPRemote = class extends MCPBase {
|
|
1150
|
-
/**
|
|
1151
|
-
* Port number the server will listen on.
|
|
1152
47
|
* @private
|
|
1153
48
|
*/
|
|
1154
|
-
|
|
49
|
+
parser;
|
|
1155
50
|
/**
|
|
1156
51
|
* Node.js HTTP server instance created internally.
|
|
1157
52
|
* @private
|
|
1158
53
|
*/
|
|
1159
|
-
|
|
54
|
+
server;
|
|
1160
55
|
/**
|
|
1161
56
|
* MCP server instance handling MCP protocol logic.
|
|
1162
57
|
* @private
|
|
@@ -1166,74 +61,90 @@ var MCPRemote = class extends MCPBase {
|
|
|
1166
61
|
* Optional name of the plugin/server instance.
|
|
1167
62
|
* @private
|
|
1168
63
|
*/
|
|
1169
|
-
|
|
64
|
+
name;
|
|
1170
65
|
/**
|
|
1171
66
|
* Optional version string of the plugin/server.
|
|
1172
67
|
* @private
|
|
1173
68
|
*/
|
|
1174
|
-
|
|
69
|
+
version;
|
|
1175
70
|
/**
|
|
1176
|
-
*
|
|
71
|
+
* Called when server is setup and listening.
|
|
1177
72
|
* @private
|
|
1178
73
|
*/
|
|
1179
|
-
|
|
74
|
+
onReady = void 0;
|
|
1180
75
|
/**
|
|
1181
|
-
*
|
|
76
|
+
* A map of pending market data requests, keyed by MDReqID.
|
|
77
|
+
* Each entry contains a resolver function that is called when the corresponding
|
|
78
|
+
* FIX Message is received.
|
|
1182
79
|
* @private
|
|
80
|
+
* @type {Map<string, (data: Message) => void>}
|
|
1183
81
|
*/
|
|
1184
82
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
1185
|
-
/**
|
|
1186
|
-
* Map to store market data prices for each symbol
|
|
1187
|
-
* @private
|
|
1188
|
-
*/
|
|
1189
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
1190
|
-
/**
|
|
1191
|
-
* Maximum number of price history entries to keep per symbol
|
|
1192
|
-
* @private
|
|
1193
|
-
*/
|
|
1194
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
1195
83
|
constructor({ port, logger, onReady }) {
|
|
1196
|
-
super({ logger, onReady });
|
|
1197
84
|
this.port = port;
|
|
85
|
+
if (logger) this.logger = logger;
|
|
86
|
+
if (onReady) this.onReady = onReady;
|
|
1198
87
|
}
|
|
1199
88
|
async register(parser) {
|
|
1200
89
|
this.parser = parser;
|
|
90
|
+
this.parser.addOnMessageCallback((message) => {
|
|
91
|
+
this.logger?.log({
|
|
92
|
+
level: "info",
|
|
93
|
+
message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
|
|
94
|
+
});
|
|
95
|
+
const msgType = message.messageType;
|
|
96
|
+
if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport) {
|
|
97
|
+
const idField = msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh ? message.getField(import_fixparser.Fields.MDReqID) : message.getField(import_fixparser.Fields.ClOrdID);
|
|
98
|
+
if (idField) {
|
|
99
|
+
const id = idField.value;
|
|
100
|
+
if (typeof id === "string" || typeof id === "number") {
|
|
101
|
+
const callback = this.pendingRequests.get(String(id));
|
|
102
|
+
if (callback) {
|
|
103
|
+
callback(message);
|
|
104
|
+
this.pendingRequests.delete(String(id));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
1201
110
|
this.logger = parser.logger;
|
|
1202
111
|
this.logger?.log({
|
|
1203
112
|
level: "info",
|
|
1204
113
|
message: `FIXParser (MCP): -- Plugin registered. Creating MCP server on port ${this.port}...`
|
|
1205
114
|
});
|
|
1206
|
-
this.
|
|
1207
|
-
if (this.parser) {
|
|
1208
|
-
handleMessage(
|
|
1209
|
-
message,
|
|
1210
|
-
this.parser,
|
|
1211
|
-
this.pendingRequests,
|
|
1212
|
-
this.marketDataPrices,
|
|
1213
|
-
this.MAX_PRICE_HISTORY
|
|
1214
|
-
);
|
|
1215
|
-
}
|
|
1216
|
-
});
|
|
1217
|
-
this.httpServer = (0, import_node_http.createServer)(async (req, res) => {
|
|
1218
|
-
this.logger?.log({
|
|
1219
|
-
level: "info",
|
|
1220
|
-
message: `Incoming request: ${req.method} ${req.url}`
|
|
1221
|
-
});
|
|
115
|
+
this.server = (0, import_node_http.createServer)(async (req, res) => {
|
|
1222
116
|
if (!req.url || !req.method) {
|
|
1223
|
-
this.logger?.log({
|
|
1224
|
-
level: "error",
|
|
1225
|
-
message: "Invalid request: missing URL or method"
|
|
1226
|
-
});
|
|
1227
117
|
res.writeHead(400);
|
|
1228
118
|
res.end("Bad Request");
|
|
1229
119
|
return;
|
|
1230
120
|
}
|
|
1231
|
-
|
|
121
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
122
|
+
if (url.pathname === "/.well-known/oauth-authorization-server") {
|
|
123
|
+
const config = {
|
|
124
|
+
issuer: "https://accounts.google.com",
|
|
125
|
+
authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
126
|
+
token_endpoint: "https://oauth2.googleapis.com/token",
|
|
127
|
+
jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
|
|
128
|
+
response_types_supported: [
|
|
129
|
+
"code",
|
|
130
|
+
"token",
|
|
131
|
+
"id_token",
|
|
132
|
+
"code token",
|
|
133
|
+
"code id_token",
|
|
134
|
+
"token id_token",
|
|
135
|
+
"code token id_token"
|
|
136
|
+
],
|
|
137
|
+
subject_types_supported: ["public"],
|
|
138
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
139
|
+
scopes_supported: ["openid", "email", "profile"],
|
|
140
|
+
token_endpoint_auth_methods_supported: ["client_secret_basic", "client_secret_post"]
|
|
141
|
+
};
|
|
142
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
143
|
+
res.end(JSON.stringify(config));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (url.pathname === "/") {
|
|
1232
147
|
const sessionId = req.headers["mcp-session-id"];
|
|
1233
|
-
this.logger?.log({
|
|
1234
|
-
level: "info",
|
|
1235
|
-
message: `MCP request received. Session ID: ${sessionId || "none"}, headers: ${req.headers}`
|
|
1236
|
-
});
|
|
1237
148
|
if (req.method === "POST") {
|
|
1238
149
|
const bodyChunks = [];
|
|
1239
150
|
req.on("data", (chunk) => {
|
|
@@ -1244,61 +155,33 @@ var MCPRemote = class extends MCPBase {
|
|
|
1244
155
|
const body = Buffer.concat(bodyChunks).toString();
|
|
1245
156
|
try {
|
|
1246
157
|
parsed = JSON.parse(body);
|
|
1247
|
-
this.logger?.log({
|
|
1248
|
-
level: "info",
|
|
1249
|
-
message: `Parsed request body: ${JSON.stringify(parsed)}`
|
|
1250
|
-
});
|
|
1251
158
|
} catch (err) {
|
|
1252
|
-
this.logger?.log({
|
|
1253
|
-
level: "error",
|
|
1254
|
-
message: `Failed to parse JSON body: ${err}`
|
|
1255
|
-
});
|
|
1256
159
|
res.writeHead(400);
|
|
1257
160
|
res.end(JSON.stringify({ error: "Invalid JSON" }));
|
|
1258
161
|
return;
|
|
1259
162
|
}
|
|
1260
163
|
let transport;
|
|
1261
164
|
if (sessionId && transports[sessionId]) {
|
|
1262
|
-
this.logger?.log({
|
|
1263
|
-
level: "info",
|
|
1264
|
-
message: `Using existing transport for session: ${sessionId}`
|
|
1265
|
-
});
|
|
1266
165
|
transport = transports[sessionId];
|
|
1267
166
|
} else if (!sessionId && req.method === "POST" && (0, import_types.isInitializeRequest)(parsed)) {
|
|
1268
|
-
this.logger?.log({
|
|
1269
|
-
level: "info",
|
|
1270
|
-
message: "Creating new transport for initialization request"
|
|
1271
|
-
});
|
|
1272
167
|
transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
1273
168
|
sessionIdGenerator: () => (0, import_node_crypto.randomUUID)(),
|
|
1274
169
|
onsessioninitialized: (sessionId2) => {
|
|
1275
|
-
this.logger?.log({
|
|
1276
|
-
level: "info",
|
|
1277
|
-
message: `New session initialized: ${sessionId2}`
|
|
1278
|
-
});
|
|
1279
170
|
transports[sessionId2] = transport;
|
|
1280
171
|
}
|
|
1281
172
|
});
|
|
1282
173
|
transport.onclose = () => {
|
|
1283
174
|
if (transport.sessionId) {
|
|
1284
|
-
this.logger?.log({
|
|
1285
|
-
level: "info",
|
|
1286
|
-
message: `Session closed: ${transport.sessionId}`
|
|
1287
|
-
});
|
|
1288
175
|
delete transports[transport.sessionId];
|
|
1289
176
|
}
|
|
1290
177
|
};
|
|
1291
178
|
this.mcpServer = new import_mcp.McpServer({
|
|
1292
|
-
name: this.
|
|
1293
|
-
version: this.
|
|
179
|
+
name: this.name || "FIXParser",
|
|
180
|
+
version: this.version || "1.0.0"
|
|
1294
181
|
});
|
|
1295
|
-
this.
|
|
182
|
+
this.addWorkflows();
|
|
1296
183
|
await this.mcpServer.connect(transport);
|
|
1297
184
|
} else {
|
|
1298
|
-
this.logger?.log({
|
|
1299
|
-
level: "error",
|
|
1300
|
-
message: "Invalid request: No valid session ID provided"
|
|
1301
|
-
});
|
|
1302
185
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
1303
186
|
res.end(
|
|
1304
187
|
JSON.stringify({
|
|
@@ -1312,62 +195,26 @@ var MCPRemote = class extends MCPBase {
|
|
|
1312
195
|
);
|
|
1313
196
|
return;
|
|
1314
197
|
}
|
|
1315
|
-
|
|
1316
|
-
await transport.handleRequest(req, res, parsed);
|
|
1317
|
-
this.logger?.log({
|
|
1318
|
-
level: "info",
|
|
1319
|
-
message: "Request handled successfully"
|
|
1320
|
-
});
|
|
1321
|
-
} catch (error) {
|
|
1322
|
-
this.logger?.log({
|
|
1323
|
-
level: "error",
|
|
1324
|
-
message: `Error handling request: ${error}`
|
|
1325
|
-
});
|
|
1326
|
-
throw error;
|
|
1327
|
-
}
|
|
198
|
+
await transport.handleRequest(req, res, parsed);
|
|
1328
199
|
});
|
|
1329
200
|
} else if (req.method === "GET" || req.method === "DELETE") {
|
|
1330
201
|
if (!sessionId || !transports[sessionId]) {
|
|
1331
|
-
this.logger?.log({
|
|
1332
|
-
level: "error",
|
|
1333
|
-
message: `Invalid session ID for ${req.method} request: ${sessionId}`
|
|
1334
|
-
});
|
|
1335
202
|
res.writeHead(400);
|
|
1336
203
|
res.end("Invalid or missing session ID");
|
|
1337
204
|
return;
|
|
1338
205
|
}
|
|
1339
206
|
const transport = transports[sessionId];
|
|
1340
|
-
|
|
1341
|
-
await transport.handleRequest(req, res);
|
|
1342
|
-
this.logger?.log({
|
|
1343
|
-
level: "info",
|
|
1344
|
-
message: `${req.method} request handled successfully for session: ${sessionId}`
|
|
1345
|
-
});
|
|
1346
|
-
} catch (error) {
|
|
1347
|
-
this.logger?.log({
|
|
1348
|
-
level: "error",
|
|
1349
|
-
message: `Error handling ${req.method} request: ${error}`
|
|
1350
|
-
});
|
|
1351
|
-
throw error;
|
|
1352
|
-
}
|
|
207
|
+
await transport.handleRequest(req, res);
|
|
1353
208
|
} else {
|
|
1354
|
-
this.logger?.log({
|
|
1355
|
-
level: "error",
|
|
1356
|
-
message: `Method not allowed: ${req.method}`
|
|
1357
|
-
});
|
|
1358
209
|
res.writeHead(405);
|
|
1359
210
|
res.end("Method Not Allowed");
|
|
1360
211
|
}
|
|
1361
|
-
|
|
1362
|
-
this.logger?.log({
|
|
1363
|
-
level: "error",
|
|
1364
|
-
message: `Not found: ${req.url}`
|
|
1365
|
-
});
|
|
1366
|
-
res.writeHead(404);
|
|
1367
|
-
res.end("Not Found");
|
|
212
|
+
return;
|
|
1368
213
|
}
|
|
214
|
+
res.writeHead(404);
|
|
215
|
+
res.end("Not Found");
|
|
1369
216
|
});
|
|
1370
|
-
this.
|
|
217
|
+
this.server.listen(this.port, () => {
|
|
1371
218
|
this.logger?.log({
|
|
1372
219
|
level: "info",
|
|
1373
220
|
message: `FIXParser (MCP): -- Server listening on http://localhost:${this.port}...`
|
|
@@ -1377,55 +224,381 @@ var MCPRemote = class extends MCPBase {
|
|
|
1377
224
|
this.onReady();
|
|
1378
225
|
}
|
|
1379
226
|
}
|
|
1380
|
-
|
|
227
|
+
addWorkflows() {
|
|
1381
228
|
if (!this.parser) {
|
|
1382
229
|
this.logger?.log({
|
|
1383
230
|
level: "error",
|
|
1384
|
-
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of
|
|
231
|
+
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
|
|
1385
232
|
});
|
|
1386
233
|
return;
|
|
1387
234
|
}
|
|
1388
235
|
if (!this.mcpServer) {
|
|
1389
236
|
this.logger?.log({
|
|
1390
237
|
level: "error",
|
|
1391
|
-
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of
|
|
238
|
+
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
|
|
1392
239
|
});
|
|
1393
240
|
return;
|
|
1394
241
|
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
242
|
+
this.mcpServer.tool(
|
|
243
|
+
"parse",
|
|
244
|
+
"Parses a FIX message and describes it in plain language",
|
|
245
|
+
{ fixString: import_zod.z.string() },
|
|
246
|
+
async ({ fixString }) => {
|
|
247
|
+
const parsedMessage = this.parser?.parse(fixString);
|
|
248
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
249
|
+
this.logger?.log({
|
|
250
|
+
level: "error",
|
|
251
|
+
message: "FIXParser (MCP): -- Failed to parse FIX string"
|
|
252
|
+
});
|
|
253
|
+
return {
|
|
254
|
+
isError: true,
|
|
255
|
+
content: [
|
|
256
|
+
{
|
|
257
|
+
type: "text",
|
|
258
|
+
text: "Error: Failed to parse FIX string"
|
|
259
|
+
}
|
|
260
|
+
]
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
content: [
|
|
265
|
+
{
|
|
266
|
+
type: "text",
|
|
267
|
+
text: parsedMessage ? `${parsedMessage[0].description} - ${parsedMessage[0].messageTypeDescription}` : ""
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
}
|
|
1400
272
|
);
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
{
|
|
1414
|
-
type: "text",
|
|
1415
|
-
text: `Tool not found: ${name}`
|
|
1416
|
-
}
|
|
1417
|
-
],
|
|
1418
|
-
isError: true
|
|
1419
|
-
};
|
|
273
|
+
this.mcpServer.prompt(
|
|
274
|
+
"parse",
|
|
275
|
+
"Parses a FIX message and describes it in plain language",
|
|
276
|
+
{ fixString: import_zod.z.string() },
|
|
277
|
+
({ fixString }) => ({
|
|
278
|
+
messages: [
|
|
279
|
+
{
|
|
280
|
+
role: "user",
|
|
281
|
+
content: {
|
|
282
|
+
type: "text",
|
|
283
|
+
text: `Please parse and explain this FIX message: ${fixString}`
|
|
284
|
+
}
|
|
1420
285
|
}
|
|
1421
|
-
|
|
286
|
+
]
|
|
287
|
+
})
|
|
288
|
+
);
|
|
289
|
+
this.mcpServer.tool(
|
|
290
|
+
"parseToJSON",
|
|
291
|
+
"Parses a FIX message into JSON",
|
|
292
|
+
{ fixString: import_zod.z.string() },
|
|
293
|
+
async ({ fixString }) => {
|
|
294
|
+
const parsedMessage = this.parser?.parse(fixString);
|
|
295
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
296
|
+
this.logger?.log({
|
|
297
|
+
level: "error",
|
|
298
|
+
message: "FIXParser (MCP): -- Failed to parse FIX string"
|
|
299
|
+
});
|
|
1422
300
|
return {
|
|
1423
|
-
|
|
1424
|
-
|
|
301
|
+
isError: true,
|
|
302
|
+
content: [
|
|
303
|
+
{
|
|
304
|
+
type: "text",
|
|
305
|
+
text: "Error: Failed to parse FIX string"
|
|
306
|
+
}
|
|
307
|
+
]
|
|
1425
308
|
};
|
|
1426
309
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
310
|
+
return {
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
type: "text",
|
|
314
|
+
text: parsedMessage ? JSON.stringify(parsedMessage[0].toFIXJSON()) : ""
|
|
315
|
+
}
|
|
316
|
+
]
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
this.mcpServer.prompt(
|
|
321
|
+
"parseToJSON",
|
|
322
|
+
"Parses a FIX message into JSON",
|
|
323
|
+
{ fixString: import_zod.z.string() },
|
|
324
|
+
({ fixString }) => ({
|
|
325
|
+
messages: [
|
|
326
|
+
{
|
|
327
|
+
role: "user",
|
|
328
|
+
content: {
|
|
329
|
+
type: "text",
|
|
330
|
+
text: `Please parse the FIX message to JSON: ${fixString}`
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
})
|
|
335
|
+
);
|
|
336
|
+
this.mcpServer.tool(
|
|
337
|
+
"newOrderSingle",
|
|
338
|
+
"Creates and sends a New Order Single",
|
|
339
|
+
{
|
|
340
|
+
clOrdID: import_zod.z.string(),
|
|
341
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).default(import_fixparser.HandlInst.AutomatedExecutionNoIntervention).optional(),
|
|
342
|
+
quantity: import_zod.z.number(),
|
|
343
|
+
price: import_zod.z.number(),
|
|
344
|
+
ordType: import_zod.z.enum([
|
|
345
|
+
"1",
|
|
346
|
+
"2",
|
|
347
|
+
"3",
|
|
348
|
+
"4",
|
|
349
|
+
"5",
|
|
350
|
+
"6",
|
|
351
|
+
"7",
|
|
352
|
+
"8",
|
|
353
|
+
"9",
|
|
354
|
+
"A",
|
|
355
|
+
"B",
|
|
356
|
+
"C",
|
|
357
|
+
"D",
|
|
358
|
+
"E",
|
|
359
|
+
"F",
|
|
360
|
+
"G",
|
|
361
|
+
"H",
|
|
362
|
+
"I",
|
|
363
|
+
"J",
|
|
364
|
+
"K",
|
|
365
|
+
"L",
|
|
366
|
+
"M",
|
|
367
|
+
"P",
|
|
368
|
+
"Q",
|
|
369
|
+
"R",
|
|
370
|
+
"S"
|
|
371
|
+
]).default(import_fixparser.OrdType.Market).optional(),
|
|
372
|
+
side: import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"]),
|
|
373
|
+
// 1 = Buy, 2 = Sell...
|
|
374
|
+
symbol: import_zod.z.string(),
|
|
375
|
+
timeInForce: import_zod.z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(import_fixparser.TimeInForce.Day).optional()
|
|
376
|
+
},
|
|
377
|
+
async ({ clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce }) => {
|
|
378
|
+
const response = new Promise((resolve) => {
|
|
379
|
+
this.pendingRequests.set(clOrdID, resolve);
|
|
380
|
+
});
|
|
381
|
+
const order = this.parser?.createMessage(
|
|
382
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
383
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
384
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
385
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
386
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
387
|
+
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
|
|
388
|
+
new import_fixparser.Field(import_fixparser.Fields.Side, side),
|
|
389
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
390
|
+
new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
|
|
391
|
+
new import_fixparser.Field(import_fixparser.Fields.Price, price),
|
|
392
|
+
new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
|
|
393
|
+
new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
|
|
394
|
+
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
|
|
395
|
+
new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
|
|
396
|
+
);
|
|
397
|
+
if (!this.parser?.connected) {
|
|
398
|
+
this.logger?.log({
|
|
399
|
+
level: "error",
|
|
400
|
+
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
401
|
+
});
|
|
402
|
+
return {
|
|
403
|
+
isError: true,
|
|
404
|
+
content: [
|
|
405
|
+
{
|
|
406
|
+
type: "text",
|
|
407
|
+
text: "Error: Not connected. Ignoring message."
|
|
408
|
+
}
|
|
409
|
+
]
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
this.parser?.send(order);
|
|
413
|
+
this.logger?.log({
|
|
414
|
+
level: "info",
|
|
415
|
+
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
416
|
+
});
|
|
417
|
+
const fixData = await response;
|
|
418
|
+
return {
|
|
419
|
+
content: [
|
|
420
|
+
{
|
|
421
|
+
type: "text",
|
|
422
|
+
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
423
|
+
}
|
|
424
|
+
]
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
);
|
|
428
|
+
this.mcpServer.prompt(
|
|
429
|
+
"newOrderSingle",
|
|
430
|
+
"Creates and sends a New Order Single",
|
|
431
|
+
{
|
|
432
|
+
clOrdID: import_zod.z.string(),
|
|
433
|
+
handlInst: import_zod.z.string(),
|
|
434
|
+
quantity: import_zod.z.string(),
|
|
435
|
+
price: import_zod.z.string(),
|
|
436
|
+
ordType: import_zod.z.string(),
|
|
437
|
+
side: import_zod.z.string(),
|
|
438
|
+
symbol: import_zod.z.string(),
|
|
439
|
+
timeInForce: import_zod.z.string()
|
|
440
|
+
},
|
|
441
|
+
({ clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce }) => ({
|
|
442
|
+
messages: [
|
|
443
|
+
{
|
|
444
|
+
role: "user",
|
|
445
|
+
content: {
|
|
446
|
+
type: "text",
|
|
447
|
+
text: [
|
|
448
|
+
"Create a New Order Single FIX message with the following parameters:",
|
|
449
|
+
`- ClOrdID: ${clOrdID}`,
|
|
450
|
+
`- HandlInst: ${handlInst ?? "default"}`,
|
|
451
|
+
`- Quantity: ${quantity}`,
|
|
452
|
+
`- Price: ${price}`,
|
|
453
|
+
`- OrdType: ${ordType ?? "default (Market)"}`,
|
|
454
|
+
`- Side: ${side}`,
|
|
455
|
+
`- Symbol: ${symbol}`,
|
|
456
|
+
`- TimeInForce: ${timeInForce ?? "default (Day)"}`,
|
|
457
|
+
"",
|
|
458
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
|
|
459
|
+
].join("\n")
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
]
|
|
463
|
+
})
|
|
464
|
+
);
|
|
465
|
+
this.mcpServer.tool(
|
|
466
|
+
"marketDataRequest",
|
|
467
|
+
"Sends a request for Market Data with the given symbol",
|
|
468
|
+
{
|
|
469
|
+
mdUpdateType: import_zod.z.enum(["0", "1"]).default("0").optional(),
|
|
470
|
+
// MDUpdateType.FullRefresh
|
|
471
|
+
symbol: import_zod.z.string(),
|
|
472
|
+
mdReqID: import_zod.z.string(),
|
|
473
|
+
subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).default(import_fixparser.SubscriptionRequestType.SnapshotAndUpdates).optional(),
|
|
474
|
+
mdEntryType: import_zod.z.enum([
|
|
475
|
+
"0",
|
|
476
|
+
"1",
|
|
477
|
+
"2",
|
|
478
|
+
"3",
|
|
479
|
+
"4",
|
|
480
|
+
"5",
|
|
481
|
+
"6",
|
|
482
|
+
"7",
|
|
483
|
+
"8",
|
|
484
|
+
"9",
|
|
485
|
+
"A",
|
|
486
|
+
"B",
|
|
487
|
+
"C",
|
|
488
|
+
"D",
|
|
489
|
+
"E",
|
|
490
|
+
"F",
|
|
491
|
+
"G",
|
|
492
|
+
"H",
|
|
493
|
+
"J",
|
|
494
|
+
"K",
|
|
495
|
+
"L",
|
|
496
|
+
"M",
|
|
497
|
+
"N",
|
|
498
|
+
"O",
|
|
499
|
+
"P",
|
|
500
|
+
"Q",
|
|
501
|
+
"S",
|
|
502
|
+
"R",
|
|
503
|
+
"T",
|
|
504
|
+
"U",
|
|
505
|
+
"V",
|
|
506
|
+
"W",
|
|
507
|
+
"X",
|
|
508
|
+
"Y",
|
|
509
|
+
"Z",
|
|
510
|
+
"a",
|
|
511
|
+
"b",
|
|
512
|
+
"c",
|
|
513
|
+
"d",
|
|
514
|
+
"e",
|
|
515
|
+
"g",
|
|
516
|
+
"h",
|
|
517
|
+
"i",
|
|
518
|
+
"t"
|
|
519
|
+
]).default(import_fixparser.MDEntryType.Bid).optional()
|
|
520
|
+
},
|
|
521
|
+
async ({ mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType }) => {
|
|
522
|
+
const response = new Promise((resolve) => {
|
|
523
|
+
this.pendingRequests.set(mdReqID, resolve);
|
|
524
|
+
});
|
|
525
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
526
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
527
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
528
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
529
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
530
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
531
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
532
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
|
|
533
|
+
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
534
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
535
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
|
|
536
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
537
|
+
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
538
|
+
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
|
|
539
|
+
);
|
|
540
|
+
if (!this.parser?.connected) {
|
|
541
|
+
this.logger?.log({
|
|
542
|
+
level: "error",
|
|
543
|
+
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
544
|
+
});
|
|
545
|
+
return {
|
|
546
|
+
isError: true,
|
|
547
|
+
content: [
|
|
548
|
+
{
|
|
549
|
+
type: "text",
|
|
550
|
+
text: "Error: Not connected. Ignoring message."
|
|
551
|
+
}
|
|
552
|
+
]
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
this.parser?.send(marketDataRequest);
|
|
556
|
+
this.logger?.log({
|
|
557
|
+
level: "info",
|
|
558
|
+
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
559
|
+
});
|
|
560
|
+
const fixData = await response;
|
|
561
|
+
return {
|
|
562
|
+
content: [
|
|
563
|
+
{
|
|
564
|
+
type: "text",
|
|
565
|
+
text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
this.mcpServer.prompt(
|
|
572
|
+
"marketDataRequest",
|
|
573
|
+
"Sends a request for Market Data with the given symbol",
|
|
574
|
+
{
|
|
575
|
+
mdUpdateType: import_zod.z.string(),
|
|
576
|
+
symbol: import_zod.z.string(),
|
|
577
|
+
mdReqID: import_zod.z.string(),
|
|
578
|
+
subscriptionRequestType: import_zod.z.string(),
|
|
579
|
+
mdEntryType: import_zod.z.string()
|
|
580
|
+
},
|
|
581
|
+
({ mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType }) => ({
|
|
582
|
+
messages: [
|
|
583
|
+
{
|
|
584
|
+
role: "user",
|
|
585
|
+
content: {
|
|
586
|
+
type: "text",
|
|
587
|
+
text: [
|
|
588
|
+
"Create a Market Data Request FIX message with the following parameters:",
|
|
589
|
+
`- MDUpdateType: ${mdUpdateType ?? "default (0 = FullRefresh)"}`,
|
|
590
|
+
`- Symbol: ${symbol}`,
|
|
591
|
+
`- MDReqID: ${mdReqID}`,
|
|
592
|
+
`- SubscriptionRequestType: ${subscriptionRequestType ?? "default (0 = Snapshot + Updates)"}`,
|
|
593
|
+
`- MDEntryType: ${mdEntryType ?? "default (0 = Bid)"}`,
|
|
594
|
+
"",
|
|
595
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
|
|
596
|
+
].join("\n")
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
]
|
|
600
|
+
})
|
|
601
|
+
);
|
|
1429
602
|
}
|
|
1430
603
|
};
|
|
1431
604
|
// Annotate the CommonJS export names for ESM import in node:
|