fixparser-plugin-mcp 9.1.7-edd9ee17 → 9.1.7-eea80766
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 +117 -482
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/cjs/MCPRemote.js +435 -1328
- package/build/cjs/MCPRemote.js.map +4 -4
- package/build/esm/MCPLocal.mjs +117 -482
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build/esm/MCPRemote.mjs +444 -1318
- package/build/esm/MCPRemote.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +7 -7
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +7 -7
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +7 -7
- package/types/MCPLocal.d.ts +9 -25
- package/types/MCPRemote.d.ts +27 -25
- package/types/schemas/index.d.ts +15 -3
- package/types/tools/index.d.ts +11 -2
- package/types/tools/marketData.d.ts +28 -7
- package/types/tools/order.d.ts +3 -4
- package/types/tools/parse.d.ts +2 -2
- package/types/tools/parseToJSON.d.ts +2 -2
- package/build/cjs/index.js +0 -1627
- package/build/cjs/index.js.map +0 -7
- package/build/esm/index.mjs +0 -1589
- 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/marketData.d.ts +0 -48
- 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,1242 +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
|
-
parser.logger.log({
|
|
323
|
-
level: "info",
|
|
324
|
-
message: `Sending market data request for symbols: ${args.symbols.join(", ")}`
|
|
325
|
-
});
|
|
326
|
-
const response = new Promise((resolve) => {
|
|
327
|
-
pendingRequests.set(args.mdReqID, resolve);
|
|
328
|
-
parser.logger.log({
|
|
329
|
-
level: "info",
|
|
330
|
-
message: `Registered callback for market data request ID: ${args.mdReqID}`
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
const entryTypes = args.mdEntryTypes || [
|
|
334
|
-
import_fixparser.MDEntryType.Bid,
|
|
335
|
-
import_fixparser.MDEntryType.Offer,
|
|
336
|
-
import_fixparser.MDEntryType.Trade,
|
|
337
|
-
import_fixparser.MDEntryType.IndexValue,
|
|
338
|
-
import_fixparser.MDEntryType.OpeningPrice,
|
|
339
|
-
import_fixparser.MDEntryType.ClosingPrice,
|
|
340
|
-
import_fixparser.MDEntryType.SettlementPrice,
|
|
341
|
-
import_fixparser.MDEntryType.TradingSessionHighPrice,
|
|
342
|
-
import_fixparser.MDEntryType.TradingSessionLowPrice,
|
|
343
|
-
import_fixparser.MDEntryType.VWAP,
|
|
344
|
-
import_fixparser.MDEntryType.Imbalance,
|
|
345
|
-
import_fixparser.MDEntryType.TradeVolume,
|
|
346
|
-
import_fixparser.MDEntryType.OpenInterest,
|
|
347
|
-
import_fixparser.MDEntryType.CompositeUnderlyingPrice,
|
|
348
|
-
import_fixparser.MDEntryType.SimulatedSellPrice,
|
|
349
|
-
import_fixparser.MDEntryType.SimulatedBuyPrice,
|
|
350
|
-
import_fixparser.MDEntryType.MarginRate,
|
|
351
|
-
import_fixparser.MDEntryType.MidPrice,
|
|
352
|
-
import_fixparser.MDEntryType.EmptyBook,
|
|
353
|
-
import_fixparser.MDEntryType.SettleHighPrice,
|
|
354
|
-
import_fixparser.MDEntryType.SettleLowPrice,
|
|
355
|
-
import_fixparser.MDEntryType.PriorSettlePrice,
|
|
356
|
-
import_fixparser.MDEntryType.SessionHighBid,
|
|
357
|
-
import_fixparser.MDEntryType.SessionLowOffer,
|
|
358
|
-
import_fixparser.MDEntryType.EarlyPrices,
|
|
359
|
-
import_fixparser.MDEntryType.AuctionClearingPrice,
|
|
360
|
-
import_fixparser.MDEntryType.SwapValueFactor,
|
|
361
|
-
import_fixparser.MDEntryType.DailyValueAdjustmentForLongPositions,
|
|
362
|
-
import_fixparser.MDEntryType.CumulativeValueAdjustmentForLongPositions,
|
|
363
|
-
import_fixparser.MDEntryType.DailyValueAdjustmentForShortPositions,
|
|
364
|
-
import_fixparser.MDEntryType.CumulativeValueAdjustmentForShortPositions,
|
|
365
|
-
import_fixparser.MDEntryType.FixingPrice,
|
|
366
|
-
import_fixparser.MDEntryType.CashRate,
|
|
367
|
-
import_fixparser.MDEntryType.RecoveryRate,
|
|
368
|
-
import_fixparser.MDEntryType.RecoveryRateForLong,
|
|
369
|
-
import_fixparser.MDEntryType.RecoveryRateForShort,
|
|
370
|
-
import_fixparser.MDEntryType.MarketBid,
|
|
371
|
-
import_fixparser.MDEntryType.MarketOffer,
|
|
372
|
-
import_fixparser.MDEntryType.ShortSaleMinPrice,
|
|
373
|
-
import_fixparser.MDEntryType.PreviousClosingPrice,
|
|
374
|
-
import_fixparser.MDEntryType.ThresholdLimitPriceBanding,
|
|
375
|
-
import_fixparser.MDEntryType.DailyFinancingValue,
|
|
376
|
-
import_fixparser.MDEntryType.AccruedFinancingValue,
|
|
377
|
-
import_fixparser.MDEntryType.TWAP
|
|
378
|
-
];
|
|
379
|
-
const messageFields = [
|
|
380
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
381
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
|
|
382
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
383
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
|
|
384
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
|
|
385
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
386
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
387
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
388
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
389
|
-
];
|
|
390
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
391
|
-
args.symbols.forEach((symbol) => {
|
|
392
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
393
|
-
});
|
|
394
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
|
|
395
|
-
entryTypes.forEach((entryType) => {
|
|
396
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
397
|
-
});
|
|
398
|
-
const mdr = parser.createMessage(...messageFields);
|
|
399
|
-
if (!parser.connected) {
|
|
400
|
-
parser.logger.log({
|
|
401
|
-
level: "error",
|
|
402
|
-
message: "Not connected. Cannot send market data request."
|
|
403
|
-
});
|
|
404
|
-
return {
|
|
405
|
-
content: [
|
|
406
|
-
{
|
|
407
|
-
type: "text",
|
|
408
|
-
text: "Error: Not connected. Ignoring message.",
|
|
409
|
-
uri: "marketDataRequest"
|
|
410
|
-
}
|
|
411
|
-
],
|
|
412
|
-
isError: true
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
parser.logger.log({
|
|
416
|
-
level: "info",
|
|
417
|
-
message: `Sending market data request message: ${JSON.stringify(mdr?.toFIXJSON())}`
|
|
418
|
-
});
|
|
419
|
-
parser.send(mdr);
|
|
420
|
-
const fixData = await response;
|
|
421
|
-
parser.logger.log({
|
|
422
|
-
level: "info",
|
|
423
|
-
message: `Received market data response for request ID: ${args.mdReqID}`
|
|
424
|
-
});
|
|
425
|
-
return {
|
|
426
|
-
content: [
|
|
427
|
-
{
|
|
428
|
-
type: "text",
|
|
429
|
-
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
430
|
-
uri: "marketDataRequest"
|
|
431
|
-
}
|
|
432
|
-
]
|
|
433
|
-
};
|
|
434
|
-
} catch (error) {
|
|
435
|
-
return {
|
|
436
|
-
content: [
|
|
437
|
-
{
|
|
438
|
-
type: "text",
|
|
439
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
440
|
-
uri: "marketDataRequest"
|
|
441
|
-
}
|
|
442
|
-
],
|
|
443
|
-
isError: true
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
};
|
|
448
|
-
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
449
|
-
return async (args) => {
|
|
450
|
-
try {
|
|
451
|
-
const symbol = args.symbol;
|
|
452
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
453
|
-
if (priceHistory.length === 0) {
|
|
454
|
-
return {
|
|
455
|
-
content: [
|
|
456
|
-
{
|
|
457
|
-
type: "text",
|
|
458
|
-
text: `No price data available for ${symbol}`,
|
|
459
|
-
uri: "getStockGraph"
|
|
460
|
-
}
|
|
461
|
-
]
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
const chart = new import_quickchart_js.default();
|
|
465
|
-
chart.setWidth(1200);
|
|
466
|
-
chart.setHeight(600);
|
|
467
|
-
chart.setBackgroundColor("transparent");
|
|
468
|
-
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
469
|
-
const bidData = priceHistory.map((point) => point.bid);
|
|
470
|
-
const offerData = priceHistory.map((point) => point.offer);
|
|
471
|
-
const spreadData = priceHistory.map((point) => point.spread);
|
|
472
|
-
const volumeData = priceHistory.map((point) => point.volume);
|
|
473
|
-
const tradeData = priceHistory.map((point) => point.trade);
|
|
474
|
-
const vwapData = priceHistory.map((point) => point.vwap);
|
|
475
|
-
const twapData = priceHistory.map((point) => point.twap);
|
|
476
|
-
const config = {
|
|
477
|
-
type: "line",
|
|
478
|
-
data: {
|
|
479
|
-
labels,
|
|
480
|
-
datasets: [
|
|
481
|
-
{
|
|
482
|
-
label: "Bid",
|
|
483
|
-
data: bidData,
|
|
484
|
-
borderColor: "#28a745",
|
|
485
|
-
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
486
|
-
fill: false,
|
|
487
|
-
tension: 0.4
|
|
488
|
-
},
|
|
489
|
-
{
|
|
490
|
-
label: "Offer",
|
|
491
|
-
data: offerData,
|
|
492
|
-
borderColor: "#dc3545",
|
|
493
|
-
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
494
|
-
fill: false,
|
|
495
|
-
tension: 0.4
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
label: "Spread",
|
|
499
|
-
data: spreadData,
|
|
500
|
-
borderColor: "#6c757d",
|
|
501
|
-
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
502
|
-
fill: false,
|
|
503
|
-
tension: 0.4
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
label: "Trade",
|
|
507
|
-
data: tradeData,
|
|
508
|
-
borderColor: "#ffc107",
|
|
509
|
-
backgroundColor: "rgba(255, 193, 7, 0.1)",
|
|
510
|
-
fill: false,
|
|
511
|
-
tension: 0.4
|
|
512
|
-
},
|
|
513
|
-
{
|
|
514
|
-
label: "VWAP",
|
|
515
|
-
data: vwapData,
|
|
516
|
-
borderColor: "#17a2b8",
|
|
517
|
-
backgroundColor: "rgba(23, 162, 184, 0.1)",
|
|
518
|
-
fill: false,
|
|
519
|
-
tension: 0.4
|
|
520
|
-
},
|
|
521
|
-
{
|
|
522
|
-
label: "TWAP",
|
|
523
|
-
data: twapData,
|
|
524
|
-
borderColor: "#6610f2",
|
|
525
|
-
backgroundColor: "rgba(102, 16, 242, 0.1)",
|
|
526
|
-
fill: false,
|
|
527
|
-
tension: 0.4
|
|
528
|
-
},
|
|
529
|
-
{
|
|
530
|
-
label: "Volume",
|
|
531
|
-
data: volumeData,
|
|
532
|
-
borderColor: "#007bff",
|
|
533
|
-
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
534
|
-
fill: true,
|
|
535
|
-
tension: 0.4
|
|
536
|
-
}
|
|
537
|
-
]
|
|
538
|
-
},
|
|
539
|
-
options: {
|
|
540
|
-
responsive: true,
|
|
541
|
-
plugins: {
|
|
542
|
-
title: {
|
|
543
|
-
display: true,
|
|
544
|
-
text: `${symbol} Market Data`
|
|
545
|
-
}
|
|
546
|
-
},
|
|
547
|
-
scales: {
|
|
548
|
-
y: {
|
|
549
|
-
beginAtZero: false
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
chart.setConfig(config);
|
|
555
|
-
const imageBuffer = await chart.toBinary();
|
|
556
|
-
const base64 = imageBuffer.toString("base64");
|
|
557
|
-
return {
|
|
558
|
-
content: [
|
|
559
|
-
{
|
|
560
|
-
type: "resource",
|
|
561
|
-
resource: {
|
|
562
|
-
uri: "resource://graph",
|
|
563
|
-
mimeType: "image/png",
|
|
564
|
-
blob: base64
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
]
|
|
568
|
-
};
|
|
569
|
-
} catch (error) {
|
|
570
|
-
return {
|
|
571
|
-
content: [
|
|
572
|
-
{
|
|
573
|
-
type: "text",
|
|
574
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to generate graph"}`,
|
|
575
|
-
uri: "getStockGraph"
|
|
576
|
-
}
|
|
577
|
-
],
|
|
578
|
-
isError: true
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
};
|
|
583
|
-
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
584
|
-
return async (args) => {
|
|
585
|
-
try {
|
|
586
|
-
const symbol = args.symbol;
|
|
587
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
588
|
-
if (priceHistory.length === 0) {
|
|
589
|
-
return {
|
|
590
|
-
content: [
|
|
591
|
-
{
|
|
592
|
-
type: "text",
|
|
593
|
-
text: `No price data available for ${symbol}`,
|
|
594
|
-
uri: "getStockPriceHistory"
|
|
595
|
-
}
|
|
596
|
-
]
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
return {
|
|
600
|
-
content: [
|
|
601
|
-
{
|
|
602
|
-
type: "text",
|
|
603
|
-
text: JSON.stringify(
|
|
604
|
-
{
|
|
605
|
-
symbol,
|
|
606
|
-
count: priceHistory.length,
|
|
607
|
-
data: priceHistory.map((point) => ({
|
|
608
|
-
timestamp: new Date(point.timestamp).toISOString(),
|
|
609
|
-
bid: point.bid,
|
|
610
|
-
offer: point.offer,
|
|
611
|
-
spread: point.spread,
|
|
612
|
-
volume: point.volume,
|
|
613
|
-
trade: point.trade,
|
|
614
|
-
indexValue: point.indexValue,
|
|
615
|
-
openingPrice: point.openingPrice,
|
|
616
|
-
closingPrice: point.closingPrice,
|
|
617
|
-
settlementPrice: point.settlementPrice,
|
|
618
|
-
tradingSessionHighPrice: point.tradingSessionHighPrice,
|
|
619
|
-
tradingSessionLowPrice: point.tradingSessionLowPrice,
|
|
620
|
-
vwap: point.vwap,
|
|
621
|
-
imbalance: point.imbalance,
|
|
622
|
-
openInterest: point.openInterest,
|
|
623
|
-
compositeUnderlyingPrice: point.compositeUnderlyingPrice,
|
|
624
|
-
simulatedSellPrice: point.simulatedSellPrice,
|
|
625
|
-
simulatedBuyPrice: point.simulatedBuyPrice,
|
|
626
|
-
marginRate: point.marginRate,
|
|
627
|
-
midPrice: point.midPrice,
|
|
628
|
-
emptyBook: point.emptyBook,
|
|
629
|
-
settleHighPrice: point.settleHighPrice,
|
|
630
|
-
settleLowPrice: point.settleLowPrice,
|
|
631
|
-
priorSettlePrice: point.priorSettlePrice,
|
|
632
|
-
sessionHighBid: point.sessionHighBid,
|
|
633
|
-
sessionLowOffer: point.sessionLowOffer,
|
|
634
|
-
earlyPrices: point.earlyPrices,
|
|
635
|
-
auctionClearingPrice: point.auctionClearingPrice,
|
|
636
|
-
swapValueFactor: point.swapValueFactor,
|
|
637
|
-
dailyValueAdjustmentForLongPositions: point.dailyValueAdjustmentForLongPositions,
|
|
638
|
-
cumulativeValueAdjustmentForLongPositions: point.cumulativeValueAdjustmentForLongPositions,
|
|
639
|
-
dailyValueAdjustmentForShortPositions: point.dailyValueAdjustmentForShortPositions,
|
|
640
|
-
cumulativeValueAdjustmentForShortPositions: point.cumulativeValueAdjustmentForShortPositions,
|
|
641
|
-
fixingPrice: point.fixingPrice,
|
|
642
|
-
cashRate: point.cashRate,
|
|
643
|
-
recoveryRate: point.recoveryRate,
|
|
644
|
-
recoveryRateForLong: point.recoveryRateForLong,
|
|
645
|
-
recoveryRateForShort: point.recoveryRateForShort,
|
|
646
|
-
marketBid: point.marketBid,
|
|
647
|
-
marketOffer: point.marketOffer,
|
|
648
|
-
shortSaleMinPrice: point.shortSaleMinPrice,
|
|
649
|
-
previousClosingPrice: point.previousClosingPrice,
|
|
650
|
-
thresholdLimitPriceBanding: point.thresholdLimitPriceBanding,
|
|
651
|
-
dailyFinancingValue: point.dailyFinancingValue,
|
|
652
|
-
accruedFinancingValue: point.accruedFinancingValue,
|
|
653
|
-
twap: point.twap
|
|
654
|
-
}))
|
|
655
|
-
},
|
|
656
|
-
null,
|
|
657
|
-
2
|
|
658
|
-
),
|
|
659
|
-
uri: "getStockPriceHistory"
|
|
660
|
-
}
|
|
661
|
-
]
|
|
662
|
-
};
|
|
663
|
-
} catch (error) {
|
|
664
|
-
return {
|
|
665
|
-
content: [
|
|
666
|
-
{
|
|
667
|
-
type: "text",
|
|
668
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to get price history"}`,
|
|
669
|
-
uri: "getStockPriceHistory"
|
|
670
|
-
}
|
|
671
|
-
],
|
|
672
|
-
isError: true
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
};
|
|
677
|
-
|
|
678
|
-
// src/tools/order.ts
|
|
679
|
-
var import_fixparser2 = require("fixparser");
|
|
680
|
-
var ordTypeNames = {
|
|
681
|
-
"1": "Market",
|
|
682
|
-
"2": "Limit",
|
|
683
|
-
"3": "Stop",
|
|
684
|
-
"4": "StopLimit",
|
|
685
|
-
"5": "MarketOnClose",
|
|
686
|
-
"6": "WithOrWithout",
|
|
687
|
-
"7": "LimitOrBetter",
|
|
688
|
-
"8": "LimitWithOrWithout",
|
|
689
|
-
"9": "OnBasis",
|
|
690
|
-
A: "OnClose",
|
|
691
|
-
B: "LimitOnClose",
|
|
692
|
-
C: "ForexMarket",
|
|
693
|
-
D: "PreviouslyQuoted",
|
|
694
|
-
E: "PreviouslyIndicated",
|
|
695
|
-
F: "ForexLimit",
|
|
696
|
-
G: "ForexSwap",
|
|
697
|
-
H: "ForexPreviouslyQuoted",
|
|
698
|
-
I: "Funari",
|
|
699
|
-
J: "MarketIfTouched",
|
|
700
|
-
K: "MarketWithLeftOverAsLimit",
|
|
701
|
-
L: "PreviousFundValuationPoint",
|
|
702
|
-
M: "NextFundValuationPoint",
|
|
703
|
-
P: "Pegged",
|
|
704
|
-
Q: "CounterOrderSelection",
|
|
705
|
-
R: "StopOnBidOrOffer",
|
|
706
|
-
S: "StopLimitOnBidOrOffer"
|
|
707
|
-
};
|
|
708
|
-
var sideNames = {
|
|
709
|
-
"1": "Buy",
|
|
710
|
-
"2": "Sell",
|
|
711
|
-
"3": "BuyMinus",
|
|
712
|
-
"4": "SellPlus",
|
|
713
|
-
"5": "SellShort",
|
|
714
|
-
"6": "SellShortExempt",
|
|
715
|
-
"7": "Undisclosed",
|
|
716
|
-
"8": "Cross",
|
|
717
|
-
"9": "CrossShort",
|
|
718
|
-
A: "CrossShortExempt",
|
|
719
|
-
B: "AsDefined",
|
|
720
|
-
C: "Opposite",
|
|
721
|
-
D: "Subscribe",
|
|
722
|
-
E: "Redeem",
|
|
723
|
-
F: "Lend",
|
|
724
|
-
G: "Borrow",
|
|
725
|
-
H: "SellUndisclosed"
|
|
726
|
-
};
|
|
727
|
-
var timeInForceNames = {
|
|
728
|
-
"0": "Day",
|
|
729
|
-
"1": "GoodTillCancel",
|
|
730
|
-
"2": "AtTheOpening",
|
|
731
|
-
"3": "ImmediateOrCancel",
|
|
732
|
-
"4": "FillOrKill",
|
|
733
|
-
"5": "GoodTillCrossing",
|
|
734
|
-
"6": "GoodTillDate",
|
|
735
|
-
"7": "AtTheClose",
|
|
736
|
-
"8": "GoodThroughCrossing",
|
|
737
|
-
"9": "AtCrossing",
|
|
738
|
-
A: "GoodForTime",
|
|
739
|
-
B: "GoodForAuction",
|
|
740
|
-
C: "GoodForMonth"
|
|
741
|
-
};
|
|
742
|
-
var handlInstNames = {
|
|
743
|
-
"1": "AutomatedExecutionNoIntervention",
|
|
744
|
-
"2": "AutomatedExecutionInterventionOK",
|
|
745
|
-
"3": "ManualOrder"
|
|
746
|
-
};
|
|
747
|
-
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
748
|
-
return async (args) => {
|
|
749
|
-
try {
|
|
750
|
-
verifiedOrders.set(args.clOrdID, {
|
|
751
|
-
clOrdID: args.clOrdID,
|
|
752
|
-
handlInst: args.handlInst,
|
|
753
|
-
quantity: Number.parseFloat(String(args.quantity)),
|
|
754
|
-
price: Number.parseFloat(String(args.price)),
|
|
755
|
-
ordType: args.ordType,
|
|
756
|
-
side: args.side,
|
|
757
|
-
symbol: args.symbol,
|
|
758
|
-
timeInForce: args.timeInForce
|
|
759
|
-
});
|
|
760
|
-
return {
|
|
761
|
-
content: [
|
|
762
|
-
{
|
|
763
|
-
type: "text",
|
|
764
|
-
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
765
|
-
|
|
766
|
-
Parameters verified:
|
|
767
|
-
- ClOrdID: ${args.clOrdID}
|
|
768
|
-
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
769
|
-
- Quantity: ${args.quantity}
|
|
770
|
-
- Price: ${args.price}
|
|
771
|
-
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
772
|
-
- Side: ${args.side} (${sideNames[args.side]})
|
|
773
|
-
- Symbol: ${args.symbol}
|
|
774
|
-
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
775
|
-
|
|
776
|
-
To execute this order, call the executeOrder tool with these exact same parameters. Important: The user has to explicitly confirm before executeOrder is called!`,
|
|
777
|
-
uri: "verifyOrder"
|
|
778
|
-
}
|
|
779
|
-
]
|
|
780
|
-
};
|
|
781
|
-
} catch (error) {
|
|
782
|
-
return {
|
|
783
|
-
content: [
|
|
784
|
-
{
|
|
785
|
-
type: "text",
|
|
786
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
787
|
-
uri: "verifyOrder"
|
|
788
|
-
}
|
|
789
|
-
],
|
|
790
|
-
isError: true
|
|
791
|
-
};
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
};
|
|
795
|
-
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
796
|
-
return async (args) => {
|
|
797
|
-
try {
|
|
798
|
-
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
799
|
-
if (!verifiedOrder) {
|
|
800
|
-
return {
|
|
801
|
-
content: [
|
|
802
|
-
{
|
|
803
|
-
type: "text",
|
|
804
|
-
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
805
|
-
uri: "executeOrder"
|
|
806
|
-
}
|
|
807
|
-
],
|
|
808
|
-
isError: true
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
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) {
|
|
812
|
-
return {
|
|
813
|
-
content: [
|
|
814
|
-
{
|
|
815
|
-
type: "text",
|
|
816
|
-
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
817
|
-
uri: "executeOrder"
|
|
818
|
-
}
|
|
819
|
-
],
|
|
820
|
-
isError: true
|
|
821
|
-
};
|
|
822
|
-
}
|
|
823
|
-
const response = new Promise((resolve) => {
|
|
824
|
-
pendingRequests.set(args.clOrdID, resolve);
|
|
825
|
-
});
|
|
826
|
-
const order = parser.createMessage(
|
|
827
|
-
new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
|
|
828
|
-
new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
829
|
-
new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
|
|
830
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
|
|
831
|
-
new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
|
|
832
|
-
new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
|
|
833
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
|
|
834
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
|
|
835
|
-
new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
836
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
|
|
837
|
-
new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
|
|
838
|
-
new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
|
|
839
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
|
|
840
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
|
|
841
|
-
);
|
|
842
|
-
if (!parser.connected) {
|
|
843
|
-
return {
|
|
844
|
-
content: [
|
|
845
|
-
{
|
|
846
|
-
type: "text",
|
|
847
|
-
text: "Error: Not connected. Ignoring message.",
|
|
848
|
-
uri: "executeOrder"
|
|
849
|
-
}
|
|
850
|
-
],
|
|
851
|
-
isError: true
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
parser.send(order);
|
|
855
|
-
const fixData = await response;
|
|
856
|
-
verifiedOrders.delete(args.clOrdID);
|
|
857
|
-
return {
|
|
858
|
-
content: [
|
|
859
|
-
{
|
|
860
|
-
type: "text",
|
|
861
|
-
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())}`,
|
|
862
|
-
uri: "executeOrder"
|
|
863
|
-
}
|
|
864
|
-
]
|
|
865
|
-
};
|
|
866
|
-
} catch (error) {
|
|
867
|
-
return {
|
|
868
|
-
content: [
|
|
869
|
-
{
|
|
870
|
-
type: "text",
|
|
871
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
872
|
-
uri: "executeOrder"
|
|
873
|
-
}
|
|
874
|
-
],
|
|
875
|
-
isError: true
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
};
|
|
880
|
-
|
|
881
|
-
// src/tools/parse.ts
|
|
882
|
-
var createParseHandler = (parser) => {
|
|
883
|
-
return async (args) => {
|
|
884
|
-
try {
|
|
885
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
886
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
887
|
-
return {
|
|
888
|
-
content: [
|
|
889
|
-
{
|
|
890
|
-
type: "text",
|
|
891
|
-
text: "Error: Failed to parse FIX string",
|
|
892
|
-
uri: "parse"
|
|
893
|
-
}
|
|
894
|
-
],
|
|
895
|
-
isError: true
|
|
896
|
-
};
|
|
897
|
-
}
|
|
898
|
-
return {
|
|
899
|
-
content: [
|
|
900
|
-
{
|
|
901
|
-
type: "text",
|
|
902
|
-
text: `${parsedMessage[0].description}
|
|
903
|
-
${parsedMessage[0].messageTypeDescription}`,
|
|
904
|
-
uri: "parse"
|
|
905
|
-
}
|
|
906
|
-
]
|
|
907
|
-
};
|
|
908
|
-
} catch (error) {
|
|
909
|
-
return {
|
|
910
|
-
content: [
|
|
911
|
-
{
|
|
912
|
-
type: "text",
|
|
913
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
914
|
-
uri: "parse"
|
|
915
|
-
}
|
|
916
|
-
],
|
|
917
|
-
isError: true
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
};
|
|
922
|
-
|
|
923
|
-
// src/tools/parseToJSON.ts
|
|
924
|
-
var createParseToJSONHandler = (parser) => {
|
|
925
|
-
return async (args) => {
|
|
926
|
-
try {
|
|
927
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
928
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
929
|
-
return {
|
|
930
|
-
content: [
|
|
931
|
-
{
|
|
932
|
-
type: "text",
|
|
933
|
-
text: "Error: Failed to parse FIX string",
|
|
934
|
-
uri: "parseToJSON"
|
|
935
|
-
}
|
|
936
|
-
],
|
|
937
|
-
isError: true
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
return {
|
|
941
|
-
content: [
|
|
942
|
-
{
|
|
943
|
-
type: "text",
|
|
944
|
-
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
945
|
-
uri: "parseToJSON"
|
|
946
|
-
}
|
|
947
|
-
]
|
|
948
|
-
};
|
|
949
|
-
} catch (error) {
|
|
950
|
-
return {
|
|
951
|
-
content: [
|
|
952
|
-
{
|
|
953
|
-
type: "text",
|
|
954
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
955
|
-
uri: "parseToJSON"
|
|
956
|
-
}
|
|
957
|
-
],
|
|
958
|
-
isError: true
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
};
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
// src/tools/index.ts
|
|
965
|
-
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
966
|
-
parse: createParseHandler(parser),
|
|
967
|
-
parseToJSON: createParseToJSONHandler(parser),
|
|
968
|
-
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
969
|
-
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
970
|
-
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
971
|
-
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
972
|
-
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
973
|
-
});
|
|
974
|
-
|
|
975
|
-
// src/utils/messageHandler.ts
|
|
976
|
-
var import_fixparser3 = require("fixparser");
|
|
977
|
-
function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
|
|
978
|
-
parser.logger.log({
|
|
979
|
-
level: "info",
|
|
980
|
-
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
981
|
-
});
|
|
982
|
-
const msgType = message.messageType;
|
|
983
|
-
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
|
|
984
|
-
const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
|
|
985
|
-
parser.logger.log({
|
|
986
|
-
level: "info",
|
|
987
|
-
message: `Processing market data for symbol: ${symbol}`
|
|
988
|
-
});
|
|
989
|
-
const fixJson = message.toFIXJSON();
|
|
990
|
-
const entries = fixJson.Body?.NoMDEntries || [];
|
|
991
|
-
parser.logger.log({
|
|
992
|
-
level: "info",
|
|
993
|
-
message: `Found ${entries.length} market data entries`
|
|
994
|
-
});
|
|
995
|
-
const data = {
|
|
996
|
-
timestamp: Date.now(),
|
|
997
|
-
bid: 0,
|
|
998
|
-
offer: 0,
|
|
999
|
-
spread: 0,
|
|
1000
|
-
volume: 0,
|
|
1001
|
-
trade: 0,
|
|
1002
|
-
indexValue: 0,
|
|
1003
|
-
openingPrice: 0,
|
|
1004
|
-
closingPrice: 0,
|
|
1005
|
-
settlementPrice: 0,
|
|
1006
|
-
tradingSessionHighPrice: 0,
|
|
1007
|
-
tradingSessionLowPrice: 0,
|
|
1008
|
-
vwap: 0,
|
|
1009
|
-
imbalance: 0,
|
|
1010
|
-
openInterest: 0,
|
|
1011
|
-
compositeUnderlyingPrice: 0,
|
|
1012
|
-
simulatedSellPrice: 0,
|
|
1013
|
-
simulatedBuyPrice: 0,
|
|
1014
|
-
marginRate: 0,
|
|
1015
|
-
midPrice: 0,
|
|
1016
|
-
emptyBook: 0,
|
|
1017
|
-
settleHighPrice: 0,
|
|
1018
|
-
settleLowPrice: 0,
|
|
1019
|
-
priorSettlePrice: 0,
|
|
1020
|
-
sessionHighBid: 0,
|
|
1021
|
-
sessionLowOffer: 0,
|
|
1022
|
-
earlyPrices: 0,
|
|
1023
|
-
auctionClearingPrice: 0,
|
|
1024
|
-
swapValueFactor: 0,
|
|
1025
|
-
dailyValueAdjustmentForLongPositions: 0,
|
|
1026
|
-
cumulativeValueAdjustmentForLongPositions: 0,
|
|
1027
|
-
dailyValueAdjustmentForShortPositions: 0,
|
|
1028
|
-
cumulativeValueAdjustmentForShortPositions: 0,
|
|
1029
|
-
fixingPrice: 0,
|
|
1030
|
-
cashRate: 0,
|
|
1031
|
-
recoveryRate: 0,
|
|
1032
|
-
recoveryRateForLong: 0,
|
|
1033
|
-
recoveryRateForShort: 0,
|
|
1034
|
-
marketBid: 0,
|
|
1035
|
-
marketOffer: 0,
|
|
1036
|
-
shortSaleMinPrice: 0,
|
|
1037
|
-
previousClosingPrice: 0,
|
|
1038
|
-
thresholdLimitPriceBanding: 0,
|
|
1039
|
-
dailyFinancingValue: 0,
|
|
1040
|
-
accruedFinancingValue: 0,
|
|
1041
|
-
twap: 0
|
|
1042
|
-
};
|
|
1043
|
-
for (const entry of entries) {
|
|
1044
|
-
const entryType = entry.MDEntryType;
|
|
1045
|
-
const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
|
|
1046
|
-
const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
|
|
1047
|
-
if (entryType === import_fixparser3.MDEntryType.Bid || entryType === import_fixparser3.MDEntryType.Offer || entryType === import_fixparser3.MDEntryType.TradeVolume) {
|
|
1048
|
-
parser.logger.log({
|
|
1049
|
-
level: "info",
|
|
1050
|
-
message: `Market Data Entry - Type: ${entryType}, Price: ${price}, Size: ${size}`
|
|
1051
|
-
});
|
|
1052
|
-
}
|
|
1053
|
-
switch (entryType) {
|
|
1054
|
-
case import_fixparser3.MDEntryType.Bid:
|
|
1055
|
-
data.bid = price;
|
|
1056
|
-
break;
|
|
1057
|
-
case import_fixparser3.MDEntryType.Offer:
|
|
1058
|
-
data.offer = price;
|
|
1059
|
-
break;
|
|
1060
|
-
case import_fixparser3.MDEntryType.Trade:
|
|
1061
|
-
data.trade = price;
|
|
1062
|
-
break;
|
|
1063
|
-
case import_fixparser3.MDEntryType.IndexValue:
|
|
1064
|
-
data.indexValue = price;
|
|
1065
|
-
break;
|
|
1066
|
-
case import_fixparser3.MDEntryType.OpeningPrice:
|
|
1067
|
-
data.openingPrice = price;
|
|
1068
|
-
break;
|
|
1069
|
-
case import_fixparser3.MDEntryType.ClosingPrice:
|
|
1070
|
-
data.closingPrice = price;
|
|
1071
|
-
break;
|
|
1072
|
-
case import_fixparser3.MDEntryType.SettlementPrice:
|
|
1073
|
-
data.settlementPrice = price;
|
|
1074
|
-
break;
|
|
1075
|
-
case import_fixparser3.MDEntryType.TradingSessionHighPrice:
|
|
1076
|
-
data.tradingSessionHighPrice = price;
|
|
1077
|
-
break;
|
|
1078
|
-
case import_fixparser3.MDEntryType.TradingSessionLowPrice:
|
|
1079
|
-
data.tradingSessionLowPrice = price;
|
|
1080
|
-
break;
|
|
1081
|
-
case import_fixparser3.MDEntryType.VWAP:
|
|
1082
|
-
data.vwap = price;
|
|
1083
|
-
break;
|
|
1084
|
-
case import_fixparser3.MDEntryType.Imbalance:
|
|
1085
|
-
data.imbalance = size;
|
|
1086
|
-
break;
|
|
1087
|
-
case import_fixparser3.MDEntryType.TradeVolume:
|
|
1088
|
-
data.volume = size;
|
|
1089
|
-
break;
|
|
1090
|
-
case import_fixparser3.MDEntryType.OpenInterest:
|
|
1091
|
-
data.openInterest = size;
|
|
1092
|
-
break;
|
|
1093
|
-
case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
|
|
1094
|
-
data.compositeUnderlyingPrice = price;
|
|
1095
|
-
break;
|
|
1096
|
-
case import_fixparser3.MDEntryType.SimulatedSellPrice:
|
|
1097
|
-
data.simulatedSellPrice = price;
|
|
1098
|
-
break;
|
|
1099
|
-
case import_fixparser3.MDEntryType.SimulatedBuyPrice:
|
|
1100
|
-
data.simulatedBuyPrice = price;
|
|
1101
|
-
break;
|
|
1102
|
-
case import_fixparser3.MDEntryType.MarginRate:
|
|
1103
|
-
data.marginRate = price;
|
|
1104
|
-
break;
|
|
1105
|
-
case import_fixparser3.MDEntryType.MidPrice:
|
|
1106
|
-
data.midPrice = price;
|
|
1107
|
-
break;
|
|
1108
|
-
case import_fixparser3.MDEntryType.EmptyBook:
|
|
1109
|
-
data.emptyBook = 1;
|
|
1110
|
-
break;
|
|
1111
|
-
case import_fixparser3.MDEntryType.SettleHighPrice:
|
|
1112
|
-
data.settleHighPrice = price;
|
|
1113
|
-
break;
|
|
1114
|
-
case import_fixparser3.MDEntryType.SettleLowPrice:
|
|
1115
|
-
data.settleLowPrice = price;
|
|
1116
|
-
break;
|
|
1117
|
-
case import_fixparser3.MDEntryType.PriorSettlePrice:
|
|
1118
|
-
data.priorSettlePrice = price;
|
|
1119
|
-
break;
|
|
1120
|
-
case import_fixparser3.MDEntryType.SessionHighBid:
|
|
1121
|
-
data.sessionHighBid = price;
|
|
1122
|
-
break;
|
|
1123
|
-
case import_fixparser3.MDEntryType.SessionLowOffer:
|
|
1124
|
-
data.sessionLowOffer = price;
|
|
1125
|
-
break;
|
|
1126
|
-
case import_fixparser3.MDEntryType.EarlyPrices:
|
|
1127
|
-
data.earlyPrices = price;
|
|
1128
|
-
break;
|
|
1129
|
-
case import_fixparser3.MDEntryType.AuctionClearingPrice:
|
|
1130
|
-
data.auctionClearingPrice = price;
|
|
1131
|
-
break;
|
|
1132
|
-
case import_fixparser3.MDEntryType.SwapValueFactor:
|
|
1133
|
-
data.swapValueFactor = price;
|
|
1134
|
-
break;
|
|
1135
|
-
case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
|
|
1136
|
-
data.dailyValueAdjustmentForLongPositions = price;
|
|
1137
|
-
break;
|
|
1138
|
-
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
|
|
1139
|
-
data.cumulativeValueAdjustmentForLongPositions = price;
|
|
1140
|
-
break;
|
|
1141
|
-
case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
|
|
1142
|
-
data.dailyValueAdjustmentForShortPositions = price;
|
|
1143
|
-
break;
|
|
1144
|
-
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
|
|
1145
|
-
data.cumulativeValueAdjustmentForShortPositions = price;
|
|
1146
|
-
break;
|
|
1147
|
-
case import_fixparser3.MDEntryType.FixingPrice:
|
|
1148
|
-
data.fixingPrice = price;
|
|
1149
|
-
break;
|
|
1150
|
-
case import_fixparser3.MDEntryType.CashRate:
|
|
1151
|
-
data.cashRate = price;
|
|
1152
|
-
break;
|
|
1153
|
-
case import_fixparser3.MDEntryType.RecoveryRate:
|
|
1154
|
-
data.recoveryRate = price;
|
|
1155
|
-
break;
|
|
1156
|
-
case import_fixparser3.MDEntryType.RecoveryRateForLong:
|
|
1157
|
-
data.recoveryRateForLong = price;
|
|
1158
|
-
break;
|
|
1159
|
-
case import_fixparser3.MDEntryType.RecoveryRateForShort:
|
|
1160
|
-
data.recoveryRateForShort = price;
|
|
1161
|
-
break;
|
|
1162
|
-
case import_fixparser3.MDEntryType.MarketBid:
|
|
1163
|
-
data.marketBid = price;
|
|
1164
|
-
break;
|
|
1165
|
-
case import_fixparser3.MDEntryType.MarketOffer:
|
|
1166
|
-
data.marketOffer = price;
|
|
1167
|
-
break;
|
|
1168
|
-
case import_fixparser3.MDEntryType.ShortSaleMinPrice:
|
|
1169
|
-
data.shortSaleMinPrice = price;
|
|
1170
|
-
break;
|
|
1171
|
-
case import_fixparser3.MDEntryType.PreviousClosingPrice:
|
|
1172
|
-
data.previousClosingPrice = price;
|
|
1173
|
-
break;
|
|
1174
|
-
case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
|
|
1175
|
-
data.thresholdLimitPriceBanding = price;
|
|
1176
|
-
break;
|
|
1177
|
-
case import_fixparser3.MDEntryType.DailyFinancingValue:
|
|
1178
|
-
data.dailyFinancingValue = price;
|
|
1179
|
-
break;
|
|
1180
|
-
case import_fixparser3.MDEntryType.AccruedFinancingValue:
|
|
1181
|
-
data.accruedFinancingValue = price;
|
|
1182
|
-
break;
|
|
1183
|
-
case import_fixparser3.MDEntryType.TWAP:
|
|
1184
|
-
data.twap = price;
|
|
1185
|
-
break;
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
data.spread = data.offer - data.bid;
|
|
1189
|
-
if (!marketDataPrices.has(symbol)) {
|
|
1190
|
-
parser.logger.log({
|
|
1191
|
-
level: "info",
|
|
1192
|
-
message: `Creating new price history array for symbol: ${symbol}`
|
|
1193
|
-
});
|
|
1194
|
-
marketDataPrices.set(symbol, []);
|
|
1195
|
-
}
|
|
1196
|
-
const prices = marketDataPrices.get(symbol);
|
|
1197
|
-
prices.push(data);
|
|
1198
|
-
parser.logger.log({
|
|
1199
|
-
level: "info",
|
|
1200
|
-
message: `Updated price history for ${symbol}. Current size: ${prices.length}`
|
|
1201
|
-
});
|
|
1202
|
-
if (prices.length > maxPriceHistory) {
|
|
1203
|
-
prices.splice(0, prices.length - maxPriceHistory);
|
|
1204
|
-
parser.logger.log({
|
|
1205
|
-
level: "info",
|
|
1206
|
-
message: `Trimmed price history for ${symbol} to ${maxPriceHistory} entries`
|
|
1207
|
-
});
|
|
1208
|
-
}
|
|
1209
|
-
onPriceUpdate?.(symbol, data);
|
|
1210
|
-
const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
|
|
1211
|
-
if (mdReqID) {
|
|
1212
|
-
const callback = pendingRequests.get(mdReqID);
|
|
1213
|
-
if (callback) {
|
|
1214
|
-
callback(message);
|
|
1215
|
-
pendingRequests.delete(mdReqID);
|
|
1216
|
-
parser.logger.log({
|
|
1217
|
-
level: "info",
|
|
1218
|
-
message: `Resolved market data request for ID: ${mdReqID}`
|
|
1219
|
-
});
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
} else if (msgType === import_fixparser3.Messages.ExecutionReport) {
|
|
1223
|
-
const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
|
|
1224
|
-
const callback = pendingRequests.get(reqId);
|
|
1225
|
-
if (callback) {
|
|
1226
|
-
callback(message);
|
|
1227
|
-
pendingRequests.delete(reqId);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
// src/MCPRemote.ts
|
|
1233
|
-
var transports = {};
|
|
1234
|
-
function jsonSchemaToZod(schema) {
|
|
1235
|
-
if (schema.type === "object") {
|
|
1236
|
-
const shape = {};
|
|
1237
|
-
for (const [key, prop] of Object.entries(schema.properties || {})) {
|
|
1238
|
-
const propSchema = prop;
|
|
1239
|
-
if (propSchema.type === "string") {
|
|
1240
|
-
if (propSchema.enum) {
|
|
1241
|
-
shape[key] = import_zod.z.enum(propSchema.enum);
|
|
1242
|
-
} else {
|
|
1243
|
-
shape[key] = import_zod.z.string();
|
|
1244
|
-
}
|
|
1245
|
-
} else if (propSchema.type === "number") {
|
|
1246
|
-
shape[key] = import_zod.z.number();
|
|
1247
|
-
} else if (propSchema.type === "boolean") {
|
|
1248
|
-
shape[key] = import_zod.z.boolean();
|
|
1249
|
-
} else if (propSchema.type === "array") {
|
|
1250
|
-
if (propSchema.items.type === "string") {
|
|
1251
|
-
shape[key] = import_zod.z.array(import_zod.z.string());
|
|
1252
|
-
} else if (propSchema.items.type === "number") {
|
|
1253
|
-
shape[key] = import_zod.z.array(import_zod.z.number());
|
|
1254
|
-
} else if (propSchema.items.type === "boolean") {
|
|
1255
|
-
shape[key] = import_zod.z.array(import_zod.z.boolean());
|
|
1256
|
-
} else {
|
|
1257
|
-
shape[key] = import_zod.z.array(import_zod.z.any());
|
|
1258
|
-
}
|
|
1259
|
-
} else {
|
|
1260
|
-
shape[key] = import_zod.z.any();
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
return shape;
|
|
1264
|
-
}
|
|
1265
|
-
return {};
|
|
1266
|
-
}
|
|
1267
|
-
var MCPRemote = class extends MCPBase {
|
|
1268
|
-
/**
|
|
1269
|
-
* Port number the server will listen on.
|
|
1270
47
|
* @private
|
|
1271
48
|
*/
|
|
1272
|
-
|
|
49
|
+
parser;
|
|
1273
50
|
/**
|
|
1274
51
|
* Node.js HTTP server instance created internally.
|
|
1275
52
|
* @private
|
|
1276
53
|
*/
|
|
1277
|
-
|
|
54
|
+
server;
|
|
1278
55
|
/**
|
|
1279
56
|
* MCP server instance handling MCP protocol logic.
|
|
1280
57
|
* @private
|
|
@@ -1284,65 +61,89 @@ var MCPRemote = class extends MCPBase {
|
|
|
1284
61
|
* Optional name of the plugin/server instance.
|
|
1285
62
|
* @private
|
|
1286
63
|
*/
|
|
1287
|
-
|
|
64
|
+
name;
|
|
1288
65
|
/**
|
|
1289
66
|
* Optional version string of the plugin/server.
|
|
1290
67
|
* @private
|
|
1291
68
|
*/
|
|
1292
|
-
|
|
69
|
+
version;
|
|
1293
70
|
/**
|
|
1294
|
-
*
|
|
71
|
+
* Called when server is setup and listening.
|
|
1295
72
|
* @private
|
|
1296
73
|
*/
|
|
1297
|
-
|
|
74
|
+
onReady = void 0;
|
|
1298
75
|
/**
|
|
1299
|
-
*
|
|
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.
|
|
1300
79
|
* @private
|
|
80
|
+
* @type {Map<string, (data: Message) => void>}
|
|
1301
81
|
*/
|
|
1302
82
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
1303
|
-
/**
|
|
1304
|
-
* Map to store market data prices for each symbol
|
|
1305
|
-
* @private
|
|
1306
|
-
*/
|
|
1307
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
1308
|
-
/**
|
|
1309
|
-
* Maximum number of price history entries to keep per symbol
|
|
1310
|
-
* @private
|
|
1311
|
-
*/
|
|
1312
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
1313
83
|
constructor({ port, logger, onReady }) {
|
|
1314
|
-
super({ logger, onReady });
|
|
1315
84
|
this.port = port;
|
|
85
|
+
if (logger) this.logger = logger;
|
|
86
|
+
if (onReady) this.onReady = onReady;
|
|
1316
87
|
}
|
|
1317
88
|
async register(parser) {
|
|
1318
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
|
+
});
|
|
1319
110
|
this.logger = parser.logger;
|
|
1320
111
|
this.logger?.log({
|
|
1321
112
|
level: "info",
|
|
1322
113
|
message: `FIXParser (MCP): -- Plugin registered. Creating MCP server on port ${this.port}...`
|
|
1323
114
|
});
|
|
1324
|
-
this.
|
|
1325
|
-
if (this.parser) {
|
|
1326
|
-
handleMessage(
|
|
1327
|
-
message,
|
|
1328
|
-
this.parser,
|
|
1329
|
-
this.pendingRequests,
|
|
1330
|
-
this.marketDataPrices,
|
|
1331
|
-
this.MAX_PRICE_HISTORY
|
|
1332
|
-
);
|
|
1333
|
-
this.logger?.log({
|
|
1334
|
-
level: "info",
|
|
1335
|
-
message: `Market Data Prices TEST: ${JSON.stringify(this.marketDataPrices)}`
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
});
|
|
1339
|
-
this.httpServer = (0, import_node_http.createServer)(async (req, res) => {
|
|
115
|
+
this.server = (0, import_node_http.createServer)(async (req, res) => {
|
|
1340
116
|
if (!req.url || !req.method) {
|
|
1341
117
|
res.writeHead(400);
|
|
1342
118
|
res.end("Bad Request");
|
|
1343
119
|
return;
|
|
1344
120
|
}
|
|
1345
|
-
|
|
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 === "/") {
|
|
1346
147
|
const sessionId = req.headers["mcp-session-id"];
|
|
1347
148
|
if (req.method === "POST") {
|
|
1348
149
|
const bodyChunks = [];
|
|
@@ -1375,10 +176,10 @@ var MCPRemote = class extends MCPBase {
|
|
|
1375
176
|
}
|
|
1376
177
|
};
|
|
1377
178
|
this.mcpServer = new import_mcp.McpServer({
|
|
1378
|
-
name: this.
|
|
1379
|
-
version: this.
|
|
179
|
+
name: this.name || "FIXParser",
|
|
180
|
+
version: this.version || "1.0.0"
|
|
1380
181
|
});
|
|
1381
|
-
this.
|
|
182
|
+
this.addWorkflows();
|
|
1382
183
|
await this.mcpServer.connect(transport);
|
|
1383
184
|
} else {
|
|
1384
185
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
@@ -1394,15 +195,7 @@ var MCPRemote = class extends MCPBase {
|
|
|
1394
195
|
);
|
|
1395
196
|
return;
|
|
1396
197
|
}
|
|
1397
|
-
|
|
1398
|
-
await transport.handleRequest(req, res, parsed);
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
this.logger?.log({
|
|
1401
|
-
level: "error",
|
|
1402
|
-
message: `Error handling request: ${error}`
|
|
1403
|
-
});
|
|
1404
|
-
throw error;
|
|
1405
|
-
}
|
|
198
|
+
await transport.handleRequest(req, res, parsed);
|
|
1406
199
|
});
|
|
1407
200
|
} else if (req.method === "GET" || req.method === "DELETE") {
|
|
1408
201
|
if (!sessionId || !transports[sessionId]) {
|
|
@@ -1411,29 +204,17 @@ var MCPRemote = class extends MCPBase {
|
|
|
1411
204
|
return;
|
|
1412
205
|
}
|
|
1413
206
|
const transport = transports[sessionId];
|
|
1414
|
-
|
|
1415
|
-
await transport.handleRequest(req, res);
|
|
1416
|
-
} catch (error) {
|
|
1417
|
-
this.logger?.log({
|
|
1418
|
-
level: "error",
|
|
1419
|
-
message: `Error handling ${req.method} request: ${error}`
|
|
1420
|
-
});
|
|
1421
|
-
throw error;
|
|
1422
|
-
}
|
|
207
|
+
await transport.handleRequest(req, res);
|
|
1423
208
|
} else {
|
|
1424
|
-
this.logger?.log({
|
|
1425
|
-
level: "error",
|
|
1426
|
-
message: `Method not allowed: ${req.method}`
|
|
1427
|
-
});
|
|
1428
209
|
res.writeHead(405);
|
|
1429
210
|
res.end("Method Not Allowed");
|
|
1430
211
|
}
|
|
1431
|
-
|
|
1432
|
-
res.writeHead(404);
|
|
1433
|
-
res.end("Not Found");
|
|
212
|
+
return;
|
|
1434
213
|
}
|
|
214
|
+
res.writeHead(404);
|
|
215
|
+
res.end("Not Found");
|
|
1435
216
|
});
|
|
1436
|
-
this.
|
|
217
|
+
this.server.listen(this.port, () => {
|
|
1437
218
|
this.logger?.log({
|
|
1438
219
|
level: "info",
|
|
1439
220
|
message: `FIXParser (MCP): -- Server listening on http://localhost:${this.port}...`
|
|
@@ -1443,55 +224,381 @@ var MCPRemote = class extends MCPBase {
|
|
|
1443
224
|
this.onReady();
|
|
1444
225
|
}
|
|
1445
226
|
}
|
|
1446
|
-
|
|
227
|
+
addWorkflows() {
|
|
1447
228
|
if (!this.parser) {
|
|
1448
229
|
this.logger?.log({
|
|
1449
230
|
level: "error",
|
|
1450
|
-
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of
|
|
231
|
+
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
|
|
1451
232
|
});
|
|
1452
233
|
return;
|
|
1453
234
|
}
|
|
1454
235
|
if (!this.mcpServer) {
|
|
1455
236
|
this.logger?.log({
|
|
1456
237
|
level: "error",
|
|
1457
|
-
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of
|
|
238
|
+
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
|
|
1458
239
|
});
|
|
1459
240
|
return;
|
|
1460
241
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
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
|
+
}
|
|
1466
272
|
);
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
{
|
|
1480
|
-
type: "text",
|
|
1481
|
-
text: `Tool not found: ${name}`
|
|
1482
|
-
}
|
|
1483
|
-
],
|
|
1484
|
-
isError: true
|
|
1485
|
-
};
|
|
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
|
+
}
|
|
1486
285
|
}
|
|
1487
|
-
|
|
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
|
+
});
|
|
1488
300
|
return {
|
|
1489
|
-
|
|
1490
|
-
|
|
301
|
+
isError: true,
|
|
302
|
+
content: [
|
|
303
|
+
{
|
|
304
|
+
type: "text",
|
|
305
|
+
text: "Error: Failed to parse FIX string"
|
|
306
|
+
}
|
|
307
|
+
]
|
|
1491
308
|
};
|
|
1492
309
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
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
|
+
);
|
|
1495
602
|
}
|
|
1496
603
|
};
|
|
1497
604
|
// Annotate the CommonJS export names for ESM import in node:
|