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/MCPLocal.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/MCPLocal.ts
|
|
@@ -33,1190 +23,508 @@ __export(MCPLocal_exports, {
|
|
|
33
23
|
MCPLocal: () => MCPLocal
|
|
34
24
|
});
|
|
35
25
|
module.exports = __toCommonJS(MCPLocal_exports);
|
|
36
|
-
var
|
|
26
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
37
27
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
28
|
+
var import_fixparser = require("fixparser");
|
|
38
29
|
var import_zod = require("zod");
|
|
39
|
-
|
|
40
|
-
// src/MCPBase.ts
|
|
41
|
-
var MCPBase = class {
|
|
42
|
-
/**
|
|
43
|
-
* Optional logger instance for diagnostics and output.
|
|
44
|
-
* @protected
|
|
45
|
-
*/
|
|
46
|
-
logger;
|
|
47
|
-
/**
|
|
48
|
-
* FIXParser instance, set during plugin register().
|
|
49
|
-
* @protected
|
|
50
|
-
*/
|
|
30
|
+
var MCPLocal = class {
|
|
51
31
|
parser;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
server = new import_mcp.McpServer(
|
|
33
|
+
{
|
|
34
|
+
name: "fixparser",
|
|
35
|
+
version: "1.0.0"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
capabilities: {
|
|
39
|
+
tools: {},
|
|
40
|
+
resources: {}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
transport = new import_stdio.StdioServerTransport();
|
|
56
45
|
onReady = void 0;
|
|
57
|
-
/**
|
|
58
|
-
* Map to store verified orders before execution
|
|
59
|
-
* @protected
|
|
60
|
-
*/
|
|
61
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
62
|
-
/**
|
|
63
|
-
* Map to store pending market data requests
|
|
64
|
-
* @protected
|
|
65
|
-
*/
|
|
66
46
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* @protected
|
|
70
|
-
*/
|
|
47
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
48
|
+
// Store market data prices with timestamps
|
|
71
49
|
marketDataPrices = /* @__PURE__ */ new Map();
|
|
72
|
-
/**
|
|
73
|
-
* Maximum number of price history entries to keep per symbol
|
|
74
|
-
* @protected
|
|
75
|
-
*/
|
|
76
50
|
MAX_PRICE_HISTORY = 1e5;
|
|
51
|
+
// Maximum number of price points to store per symbol
|
|
77
52
|
constructor({ logger, onReady }) {
|
|
78
|
-
this.
|
|
79
|
-
this.onReady = onReady;
|
|
53
|
+
if (onReady) this.onReady = onReady;
|
|
80
54
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
verifyOrder: {
|
|
106
|
-
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
107
|
-
schema: {
|
|
108
|
-
type: "object",
|
|
109
|
-
properties: {
|
|
110
|
-
clOrdID: { type: "string" },
|
|
111
|
-
handlInst: {
|
|
112
|
-
type: "string",
|
|
113
|
-
enum: ["1", "2", "3"],
|
|
114
|
-
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
115
|
-
},
|
|
116
|
-
quantity: { type: "string" },
|
|
117
|
-
price: { type: "string" },
|
|
118
|
-
ordType: {
|
|
119
|
-
type: "string",
|
|
120
|
-
enum: [
|
|
121
|
-
"1",
|
|
122
|
-
"2",
|
|
123
|
-
"3",
|
|
124
|
-
"4",
|
|
125
|
-
"5",
|
|
126
|
-
"6",
|
|
127
|
-
"7",
|
|
128
|
-
"8",
|
|
129
|
-
"9",
|
|
130
|
-
"A",
|
|
131
|
-
"B",
|
|
132
|
-
"C",
|
|
133
|
-
"D",
|
|
134
|
-
"E",
|
|
135
|
-
"F",
|
|
136
|
-
"G",
|
|
137
|
-
"H",
|
|
138
|
-
"I",
|
|
139
|
-
"J",
|
|
140
|
-
"K",
|
|
141
|
-
"L",
|
|
142
|
-
"M",
|
|
143
|
-
"P",
|
|
144
|
-
"Q",
|
|
145
|
-
"R",
|
|
146
|
-
"S"
|
|
147
|
-
],
|
|
148
|
-
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"
|
|
149
|
-
},
|
|
150
|
-
side: {
|
|
151
|
-
type: "string",
|
|
152
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
153
|
-
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"
|
|
154
|
-
},
|
|
155
|
-
symbol: { type: "string" },
|
|
156
|
-
timeInForce: {
|
|
157
|
-
type: "string",
|
|
158
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
159
|
-
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"
|
|
55
|
+
async register(parser) {
|
|
56
|
+
this.parser = parser;
|
|
57
|
+
this.parser.addOnMessageCallback((message) => {
|
|
58
|
+
const msgType = message.messageType;
|
|
59
|
+
if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
|
|
60
|
+
let id;
|
|
61
|
+
if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
|
|
62
|
+
const symbol = message.getField(import_fixparser.Fields.Symbol);
|
|
63
|
+
const price = message.getField(import_fixparser.Fields.MDEntryPx);
|
|
64
|
+
const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
|
|
65
|
+
if (symbol?.value && price?.value) {
|
|
66
|
+
const symbolStr = String(symbol.value);
|
|
67
|
+
const priceNum = Number(price.value);
|
|
68
|
+
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
69
|
+
priceHistory.push({
|
|
70
|
+
timestamp: Number(timestamp),
|
|
71
|
+
price: priceNum
|
|
72
|
+
});
|
|
73
|
+
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
74
|
+
priceHistory.shift();
|
|
75
|
+
}
|
|
76
|
+
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
77
|
+
}
|
|
160
78
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
clOrdID: { type: "string" },
|
|
171
|
-
handlInst: {
|
|
172
|
-
type: "string",
|
|
173
|
-
enum: ["1", "2", "3"],
|
|
174
|
-
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
175
|
-
},
|
|
176
|
-
quantity: { type: "string" },
|
|
177
|
-
price: { type: "string" },
|
|
178
|
-
ordType: {
|
|
179
|
-
type: "string",
|
|
180
|
-
enum: [
|
|
181
|
-
"1",
|
|
182
|
-
"2",
|
|
183
|
-
"3",
|
|
184
|
-
"4",
|
|
185
|
-
"5",
|
|
186
|
-
"6",
|
|
187
|
-
"7",
|
|
188
|
-
"8",
|
|
189
|
-
"9",
|
|
190
|
-
"A",
|
|
191
|
-
"B",
|
|
192
|
-
"C",
|
|
193
|
-
"D",
|
|
194
|
-
"E",
|
|
195
|
-
"F",
|
|
196
|
-
"G",
|
|
197
|
-
"H",
|
|
198
|
-
"I",
|
|
199
|
-
"J",
|
|
200
|
-
"K",
|
|
201
|
-
"L",
|
|
202
|
-
"M",
|
|
203
|
-
"P",
|
|
204
|
-
"Q",
|
|
205
|
-
"R",
|
|
206
|
-
"S"
|
|
207
|
-
],
|
|
208
|
-
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"
|
|
209
|
-
},
|
|
210
|
-
side: {
|
|
211
|
-
type: "string",
|
|
212
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
213
|
-
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"
|
|
214
|
-
},
|
|
215
|
-
symbol: { type: "string" },
|
|
216
|
-
timeInForce: {
|
|
217
|
-
type: "string",
|
|
218
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
219
|
-
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"
|
|
79
|
+
if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
|
|
80
|
+
const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
|
|
81
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
82
|
+
} else if (msgType === import_fixparser.Messages.ExecutionReport) {
|
|
83
|
+
const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
|
|
84
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
85
|
+
} else if (msgType === import_fixparser.Messages.Reject) {
|
|
86
|
+
const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
|
|
87
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
220
88
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
schema: {
|
|
228
|
-
type: "object",
|
|
229
|
-
properties: {
|
|
230
|
-
mdUpdateType: {
|
|
231
|
-
type: "string",
|
|
232
|
-
enum: ["0", "1"],
|
|
233
|
-
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
234
|
-
},
|
|
235
|
-
symbols: { type: "array", items: { type: "string" } },
|
|
236
|
-
mdReqID: { type: "string" },
|
|
237
|
-
subscriptionRequestType: {
|
|
238
|
-
type: "string",
|
|
239
|
-
enum: ["0", "1", "2"],
|
|
240
|
-
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
241
|
-
},
|
|
242
|
-
mdEntryTypes: {
|
|
243
|
-
type: "array",
|
|
244
|
-
items: {
|
|
245
|
-
type: "string",
|
|
246
|
-
enum: [
|
|
247
|
-
"0",
|
|
248
|
-
"1",
|
|
249
|
-
"2",
|
|
250
|
-
"3",
|
|
251
|
-
"4",
|
|
252
|
-
"5",
|
|
253
|
-
"6",
|
|
254
|
-
"7",
|
|
255
|
-
"8",
|
|
256
|
-
"9",
|
|
257
|
-
"A",
|
|
258
|
-
"B",
|
|
259
|
-
"C",
|
|
260
|
-
"D",
|
|
261
|
-
"E",
|
|
262
|
-
"F",
|
|
263
|
-
"G",
|
|
264
|
-
"H",
|
|
265
|
-
"I",
|
|
266
|
-
"J",
|
|
267
|
-
"K",
|
|
268
|
-
"L",
|
|
269
|
-
"M",
|
|
270
|
-
"N",
|
|
271
|
-
"O",
|
|
272
|
-
"P",
|
|
273
|
-
"Q",
|
|
274
|
-
"R",
|
|
275
|
-
"S",
|
|
276
|
-
"T",
|
|
277
|
-
"U",
|
|
278
|
-
"V",
|
|
279
|
-
"W",
|
|
280
|
-
"X",
|
|
281
|
-
"Y",
|
|
282
|
-
"Z"
|
|
283
|
-
]
|
|
284
|
-
},
|
|
285
|
-
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"
|
|
89
|
+
if (id) {
|
|
90
|
+
const callback = this.pendingRequests.get(id);
|
|
91
|
+
if (callback) {
|
|
92
|
+
callback(message);
|
|
93
|
+
this.pendingRequests.delete(id);
|
|
94
|
+
}
|
|
286
95
|
}
|
|
287
|
-
}
|
|
288
|
-
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.addWorkflows();
|
|
99
|
+
await this.server.connect(this.transport);
|
|
100
|
+
if (this.onReady) {
|
|
101
|
+
this.onReady();
|
|
289
102
|
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
type: "object",
|
|
295
|
-
properties: {
|
|
296
|
-
symbol: { type: "string" }
|
|
297
|
-
},
|
|
298
|
-
required: ["symbol"]
|
|
103
|
+
}
|
|
104
|
+
addWorkflows() {
|
|
105
|
+
if (!this.parser) {
|
|
106
|
+
return;
|
|
299
107
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
description: "Returns price history for a given symbol",
|
|
303
|
-
schema: {
|
|
304
|
-
type: "object",
|
|
305
|
-
properties: {
|
|
306
|
-
symbol: { type: "string" }
|
|
307
|
-
},
|
|
308
|
-
required: ["symbol"]
|
|
108
|
+
if (!this.server) {
|
|
109
|
+
return;
|
|
309
110
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
import_fixparser.MDEntryType.Offer,
|
|
325
|
-
import_fixparser.MDEntryType.Trade,
|
|
326
|
-
import_fixparser.MDEntryType.IndexValue,
|
|
327
|
-
import_fixparser.MDEntryType.OpeningPrice,
|
|
328
|
-
import_fixparser.MDEntryType.ClosingPrice,
|
|
329
|
-
import_fixparser.MDEntryType.SettlementPrice,
|
|
330
|
-
import_fixparser.MDEntryType.TradingSessionHighPrice,
|
|
331
|
-
import_fixparser.MDEntryType.TradingSessionLowPrice,
|
|
332
|
-
import_fixparser.MDEntryType.VWAP,
|
|
333
|
-
import_fixparser.MDEntryType.Imbalance,
|
|
334
|
-
import_fixparser.MDEntryType.TradeVolume,
|
|
335
|
-
import_fixparser.MDEntryType.OpenInterest,
|
|
336
|
-
import_fixparser.MDEntryType.CompositeUnderlyingPrice,
|
|
337
|
-
import_fixparser.MDEntryType.SimulatedSellPrice,
|
|
338
|
-
import_fixparser.MDEntryType.SimulatedBuyPrice,
|
|
339
|
-
import_fixparser.MDEntryType.MarginRate,
|
|
340
|
-
import_fixparser.MDEntryType.MidPrice,
|
|
341
|
-
import_fixparser.MDEntryType.EmptyBook,
|
|
342
|
-
import_fixparser.MDEntryType.SettleHighPrice,
|
|
343
|
-
import_fixparser.MDEntryType.SettleLowPrice,
|
|
344
|
-
import_fixparser.MDEntryType.PriorSettlePrice,
|
|
345
|
-
import_fixparser.MDEntryType.SessionHighBid,
|
|
346
|
-
import_fixparser.MDEntryType.SessionLowOffer,
|
|
347
|
-
import_fixparser.MDEntryType.EarlyPrices,
|
|
348
|
-
import_fixparser.MDEntryType.AuctionClearingPrice,
|
|
349
|
-
import_fixparser.MDEntryType.SwapValueFactor,
|
|
350
|
-
import_fixparser.MDEntryType.DailyValueAdjustmentForLongPositions,
|
|
351
|
-
import_fixparser.MDEntryType.CumulativeValueAdjustmentForLongPositions,
|
|
352
|
-
import_fixparser.MDEntryType.DailyValueAdjustmentForShortPositions,
|
|
353
|
-
import_fixparser.MDEntryType.CumulativeValueAdjustmentForShortPositions,
|
|
354
|
-
import_fixparser.MDEntryType.FixingPrice,
|
|
355
|
-
import_fixparser.MDEntryType.CashRate,
|
|
356
|
-
import_fixparser.MDEntryType.RecoveryRate,
|
|
357
|
-
import_fixparser.MDEntryType.RecoveryRateForLong,
|
|
358
|
-
import_fixparser.MDEntryType.RecoveryRateForShort,
|
|
359
|
-
import_fixparser.MDEntryType.MarketBid,
|
|
360
|
-
import_fixparser.MDEntryType.MarketOffer,
|
|
361
|
-
import_fixparser.MDEntryType.ShortSaleMinPrice,
|
|
362
|
-
import_fixparser.MDEntryType.PreviousClosingPrice,
|
|
363
|
-
import_fixparser.MDEntryType.ThresholdLimitPriceBanding,
|
|
364
|
-
import_fixparser.MDEntryType.DailyFinancingValue,
|
|
365
|
-
import_fixparser.MDEntryType.AccruedFinancingValue,
|
|
366
|
-
import_fixparser.MDEntryType.TWAP
|
|
367
|
-
];
|
|
368
|
-
const messageFields = [
|
|
369
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
370
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
|
|
371
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
372
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
|
|
373
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
|
|
374
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
375
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
376
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
377
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
378
|
-
];
|
|
379
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
380
|
-
args.symbols.forEach((symbol) => {
|
|
381
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
382
|
-
});
|
|
383
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
|
|
384
|
-
entryTypes.forEach((entryType) => {
|
|
385
|
-
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
386
|
-
});
|
|
387
|
-
const mdr = parser.createMessage(...messageFields);
|
|
388
|
-
if (!parser.connected) {
|
|
389
|
-
return {
|
|
390
|
-
content: [
|
|
391
|
-
{
|
|
392
|
-
type: "text",
|
|
393
|
-
text: "Error: Not connected. Ignoring message.",
|
|
394
|
-
uri: "marketDataRequest"
|
|
395
|
-
}
|
|
396
|
-
],
|
|
397
|
-
isError: true
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
parser.send(mdr);
|
|
401
|
-
const fixData = await response;
|
|
402
|
-
return {
|
|
403
|
-
content: [
|
|
404
|
-
{
|
|
405
|
-
type: "text",
|
|
406
|
-
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
407
|
-
uri: "marketDataRequest"
|
|
408
|
-
}
|
|
409
|
-
]
|
|
410
|
-
};
|
|
411
|
-
} catch (error) {
|
|
412
|
-
return {
|
|
413
|
-
content: [
|
|
414
|
-
{
|
|
415
|
-
type: "text",
|
|
416
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
417
|
-
uri: "marketDataRequest"
|
|
111
|
+
this.server.tool(
|
|
112
|
+
"parse",
|
|
113
|
+
"Parses a FIX message and describes it in plain language",
|
|
114
|
+
{
|
|
115
|
+
fixString: import_zod.z.string().describe("FIX message string to parse")
|
|
116
|
+
},
|
|
117
|
+
async (args) => {
|
|
118
|
+
try {
|
|
119
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
120
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
121
|
+
return {
|
|
122
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
123
|
+
isError: true
|
|
124
|
+
};
|
|
418
125
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
};
|
|
126
|
+
return {
|
|
127
|
+
content: [
|
|
128
|
+
{
|
|
129
|
+
type: "text",
|
|
130
|
+
text: `${parsedMessage[0].description}
|
|
131
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
} catch (error) {
|
|
136
|
+
return {
|
|
137
|
+
content: [
|
|
138
|
+
{
|
|
139
|
+
type: "text",
|
|
140
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
141
|
+
}
|
|
142
|
+
],
|
|
143
|
+
isError: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
440
146
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
label: "Bid",
|
|
457
|
-
data: bidData,
|
|
458
|
-
borderColor: "#28a745",
|
|
459
|
-
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
460
|
-
fill: false,
|
|
461
|
-
tension: 0.4
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
label: "Offer",
|
|
465
|
-
data: offerData,
|
|
466
|
-
borderColor: "#dc3545",
|
|
467
|
-
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
468
|
-
fill: false,
|
|
469
|
-
tension: 0.4
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
label: "Spread",
|
|
473
|
-
data: spreadData,
|
|
474
|
-
borderColor: "#6c757d",
|
|
475
|
-
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
476
|
-
fill: false,
|
|
477
|
-
tension: 0.4
|
|
478
|
-
},
|
|
479
|
-
{
|
|
480
|
-
label: "Volume",
|
|
481
|
-
data: volumeData,
|
|
482
|
-
borderColor: "#007bff",
|
|
483
|
-
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
484
|
-
fill: true,
|
|
485
|
-
tension: 0.4
|
|
486
|
-
}
|
|
487
|
-
]
|
|
488
|
-
},
|
|
489
|
-
options: {
|
|
490
|
-
responsive: true,
|
|
491
|
-
plugins: {
|
|
492
|
-
title: {
|
|
493
|
-
display: true,
|
|
494
|
-
text: `${symbol} Market Data`
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
|
-
scales: {
|
|
498
|
-
y: {
|
|
499
|
-
beginAtZero: false
|
|
500
|
-
}
|
|
147
|
+
);
|
|
148
|
+
this.server.tool(
|
|
149
|
+
"parseToJSON",
|
|
150
|
+
"Parses a FIX message into JSON",
|
|
151
|
+
{
|
|
152
|
+
fixString: import_zod.z.string().describe("FIX message string to parse")
|
|
153
|
+
},
|
|
154
|
+
async (args) => {
|
|
155
|
+
try {
|
|
156
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
157
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
158
|
+
return {
|
|
159
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
160
|
+
isError: true
|
|
161
|
+
};
|
|
501
162
|
}
|
|
163
|
+
return {
|
|
164
|
+
content: [
|
|
165
|
+
{
|
|
166
|
+
type: "text",
|
|
167
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return {
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
type: "text",
|
|
176
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
isError: true
|
|
180
|
+
};
|
|
502
181
|
}
|
|
503
|
-
};
|
|
504
|
-
chart.setConfig(config);
|
|
505
|
-
const imageBuffer = await chart.toBinary();
|
|
506
|
-
const base64 = imageBuffer.toString("base64");
|
|
507
|
-
return {
|
|
508
|
-
content: [
|
|
509
|
-
{
|
|
510
|
-
type: "resource",
|
|
511
|
-
resource: {
|
|
512
|
-
uri: "resource://graph",
|
|
513
|
-
mimeType: "image/png",
|
|
514
|
-
blob: base64
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
]
|
|
518
|
-
};
|
|
519
|
-
} catch (error) {
|
|
520
|
-
return {
|
|
521
|
-
content: [
|
|
522
|
-
{
|
|
523
|
-
type: "text",
|
|
524
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
525
|
-
uri: "getStockGraph"
|
|
526
|
-
}
|
|
527
|
-
],
|
|
528
|
-
isError: true
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
};
|
|
533
|
-
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
534
|
-
return async (args) => {
|
|
535
|
-
try {
|
|
536
|
-
const symbol = args.symbol;
|
|
537
|
-
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
538
|
-
if (priceHistory.length === 0) {
|
|
539
|
-
return {
|
|
540
|
-
content: [
|
|
541
|
-
{
|
|
542
|
-
type: "text",
|
|
543
|
-
text: `No price data available for ${symbol}`,
|
|
544
|
-
uri: "getStockPriceHistory"
|
|
545
|
-
}
|
|
546
|
-
]
|
|
547
|
-
};
|
|
548
182
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
183
|
+
);
|
|
184
|
+
this.server.tool(
|
|
185
|
+
"verifyOrder",
|
|
186
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
187
|
+
{
|
|
188
|
+
clOrdID: import_zod.z.string().describe("Client Order ID"),
|
|
189
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
190
|
+
quantity: import_zod.z.string().describe("Order quantity"),
|
|
191
|
+
price: import_zod.z.string().describe("Order price"),
|
|
192
|
+
ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
193
|
+
side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
194
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
195
|
+
timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
196
|
+
},
|
|
197
|
+
async (args) => {
|
|
198
|
+
try {
|
|
199
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
200
|
+
clOrdID: args.clOrdID,
|
|
201
|
+
handlInst: args.handlInst,
|
|
202
|
+
quantity: Number.parseFloat(args.quantity),
|
|
203
|
+
price: Number.parseFloat(args.price),
|
|
204
|
+
ordType: args.ordType,
|
|
205
|
+
side: args.side,
|
|
206
|
+
symbol: args.symbol,
|
|
207
|
+
timeInForce: args.timeInForce
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
content: [
|
|
554
211
|
{
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
timestamp: new Date(point.timestamp).toISOString(),
|
|
559
|
-
bid: point.bid,
|
|
560
|
-
offer: point.offer,
|
|
561
|
-
spread: point.spread,
|
|
562
|
-
volume: point.volume
|
|
563
|
-
}))
|
|
564
|
-
},
|
|
565
|
-
null,
|
|
566
|
-
2
|
|
567
|
-
),
|
|
568
|
-
uri: "getStockPriceHistory"
|
|
569
|
-
}
|
|
570
|
-
]
|
|
571
|
-
};
|
|
572
|
-
} catch (error) {
|
|
573
|
-
return {
|
|
574
|
-
content: [
|
|
575
|
-
{
|
|
576
|
-
type: "text",
|
|
577
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
578
|
-
uri: "getStockPriceHistory"
|
|
579
|
-
}
|
|
580
|
-
],
|
|
581
|
-
isError: true
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
};
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
// src/tools/order.ts
|
|
588
|
-
var import_fixparser2 = require("fixparser");
|
|
589
|
-
var ordTypeNames = {
|
|
590
|
-
"1": "Market",
|
|
591
|
-
"2": "Limit",
|
|
592
|
-
"3": "Stop",
|
|
593
|
-
"4": "StopLimit",
|
|
594
|
-
"5": "MarketOnClose",
|
|
595
|
-
"6": "WithOrWithout",
|
|
596
|
-
"7": "LimitOrBetter",
|
|
597
|
-
"8": "LimitWithOrWithout",
|
|
598
|
-
"9": "OnBasis",
|
|
599
|
-
A: "OnClose",
|
|
600
|
-
B: "LimitOnClose",
|
|
601
|
-
C: "ForexMarket",
|
|
602
|
-
D: "PreviouslyQuoted",
|
|
603
|
-
E: "PreviouslyIndicated",
|
|
604
|
-
F: "ForexLimit",
|
|
605
|
-
G: "ForexSwap",
|
|
606
|
-
H: "ForexPreviouslyQuoted",
|
|
607
|
-
I: "Funari",
|
|
608
|
-
J: "MarketIfTouched",
|
|
609
|
-
K: "MarketWithLeftOverAsLimit",
|
|
610
|
-
L: "PreviousFundValuationPoint",
|
|
611
|
-
M: "NextFundValuationPoint",
|
|
612
|
-
P: "Pegged",
|
|
613
|
-
Q: "CounterOrderSelection",
|
|
614
|
-
R: "StopOnBidOrOffer",
|
|
615
|
-
S: "StopLimitOnBidOrOffer"
|
|
616
|
-
};
|
|
617
|
-
var sideNames = {
|
|
618
|
-
"1": "Buy",
|
|
619
|
-
"2": "Sell",
|
|
620
|
-
"3": "BuyMinus",
|
|
621
|
-
"4": "SellPlus",
|
|
622
|
-
"5": "SellShort",
|
|
623
|
-
"6": "SellShortExempt",
|
|
624
|
-
"7": "Undisclosed",
|
|
625
|
-
"8": "Cross",
|
|
626
|
-
"9": "CrossShort",
|
|
627
|
-
A: "CrossShortExempt",
|
|
628
|
-
B: "AsDefined",
|
|
629
|
-
C: "Opposite",
|
|
630
|
-
D: "Subscribe",
|
|
631
|
-
E: "Redeem",
|
|
632
|
-
F: "Lend",
|
|
633
|
-
G: "Borrow",
|
|
634
|
-
H: "SellUndisclosed"
|
|
635
|
-
};
|
|
636
|
-
var timeInForceNames = {
|
|
637
|
-
"0": "Day",
|
|
638
|
-
"1": "GoodTillCancel",
|
|
639
|
-
"2": "AtTheOpening",
|
|
640
|
-
"3": "ImmediateOrCancel",
|
|
641
|
-
"4": "FillOrKill",
|
|
642
|
-
"5": "GoodTillCrossing",
|
|
643
|
-
"6": "GoodTillDate",
|
|
644
|
-
"7": "AtTheClose",
|
|
645
|
-
"8": "GoodThroughCrossing",
|
|
646
|
-
"9": "AtCrossing",
|
|
647
|
-
A: "GoodForTime",
|
|
648
|
-
B: "GoodForAuction",
|
|
649
|
-
C: "GoodForMonth"
|
|
650
|
-
};
|
|
651
|
-
var handlInstNames = {
|
|
652
|
-
"1": "AutomatedExecutionNoIntervention",
|
|
653
|
-
"2": "AutomatedExecutionInterventionOK",
|
|
654
|
-
"3": "ManualOrder"
|
|
655
|
-
};
|
|
656
|
-
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
657
|
-
return async (args) => {
|
|
658
|
-
try {
|
|
659
|
-
verifiedOrders.set(args.clOrdID, {
|
|
660
|
-
clOrdID: args.clOrdID,
|
|
661
|
-
handlInst: args.handlInst,
|
|
662
|
-
quantity: Number.parseFloat(String(args.quantity)),
|
|
663
|
-
price: Number.parseFloat(String(args.price)),
|
|
664
|
-
ordType: args.ordType,
|
|
665
|
-
side: args.side,
|
|
666
|
-
symbol: args.symbol,
|
|
667
|
-
timeInForce: args.timeInForce
|
|
668
|
-
});
|
|
669
|
-
return {
|
|
670
|
-
content: [
|
|
671
|
-
{
|
|
672
|
-
type: "text",
|
|
673
|
-
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
674
|
-
|
|
212
|
+
type: "text",
|
|
213
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
214
|
+
|
|
675
215
|
Parameters verified:
|
|
676
216
|
- ClOrdID: ${args.clOrdID}
|
|
677
|
-
- HandlInst: ${args.handlInst}
|
|
217
|
+
- HandlInst: ${args.handlInst}
|
|
678
218
|
- Quantity: ${args.quantity}
|
|
679
219
|
- Price: ${args.price}
|
|
680
|
-
- OrdType: ${args.ordType}
|
|
681
|
-
- Side: ${args.side}
|
|
220
|
+
- OrdType: ${args.ordType}
|
|
221
|
+
- Side: ${args.side}
|
|
682
222
|
- Symbol: ${args.symbol}
|
|
683
|
-
- TimeInForce: ${args.timeInForce}
|
|
223
|
+
- TimeInForce: ${args.timeInForce}
|
|
684
224
|
|
|
685
|
-
To execute this order, call the executeOrder tool with these exact same parameters
|
|
686
|
-
|
|
225
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
226
|
+
}
|
|
227
|
+
]
|
|
228
|
+
};
|
|
229
|
+
} catch (error) {
|
|
230
|
+
return {
|
|
231
|
+
content: [
|
|
232
|
+
{
|
|
233
|
+
type: "text",
|
|
234
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
isError: true
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
this.server.tool(
|
|
243
|
+
"executeOrder",
|
|
244
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
245
|
+
{
|
|
246
|
+
clOrdID: import_zod.z.string().describe("Client Order ID"),
|
|
247
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
248
|
+
quantity: import_zod.z.string().describe("Order quantity"),
|
|
249
|
+
price: import_zod.z.string().describe("Order price"),
|
|
250
|
+
ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
251
|
+
side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
252
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
253
|
+
timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
254
|
+
},
|
|
255
|
+
async (args) => {
|
|
256
|
+
try {
|
|
257
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
258
|
+
if (!verifiedOrder) {
|
|
259
|
+
return {
|
|
260
|
+
content: [
|
|
261
|
+
{
|
|
262
|
+
type: "text",
|
|
263
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
264
|
+
}
|
|
265
|
+
],
|
|
266
|
+
isError: true
|
|
267
|
+
};
|
|
687
268
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
269
|
+
if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
|
|
270
|
+
return {
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
type: "text",
|
|
274
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
isError: true
|
|
278
|
+
};
|
|
697
279
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
280
|
+
const response = new Promise((resolve) => {
|
|
281
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
282
|
+
});
|
|
283
|
+
const order = this.parser?.createMessage(
|
|
284
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
285
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
286
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
287
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
288
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
289
|
+
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
|
|
290
|
+
new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
|
|
291
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
|
|
292
|
+
new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
293
|
+
new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
|
|
294
|
+
new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
|
|
295
|
+
new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
|
|
296
|
+
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
|
|
297
|
+
new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
|
|
298
|
+
);
|
|
299
|
+
if (!this.parser?.connected) {
|
|
300
|
+
return {
|
|
301
|
+
content: [
|
|
302
|
+
{
|
|
303
|
+
type: "text",
|
|
304
|
+
text: "Error: Not connected. Ignoring message."
|
|
305
|
+
}
|
|
306
|
+
],
|
|
307
|
+
isError: true
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
this.parser?.send(order);
|
|
311
|
+
const fixData = await response;
|
|
312
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
313
|
+
return {
|
|
314
|
+
content: [
|
|
315
|
+
{
|
|
316
|
+
type: "text",
|
|
317
|
+
text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
};
|
|
321
|
+
} catch (error) {
|
|
322
|
+
return {
|
|
323
|
+
content: [
|
|
324
|
+
{
|
|
325
|
+
type: "text",
|
|
326
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
327
|
+
}
|
|
328
|
+
],
|
|
329
|
+
isError: true
|
|
330
|
+
};
|
|
331
|
+
}
|
|
719
332
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
333
|
+
);
|
|
334
|
+
this.server.tool(
|
|
335
|
+
"marketDataRequest",
|
|
336
|
+
"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
337
|
+
{
|
|
338
|
+
mdUpdateType: import_zod.z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
339
|
+
symbols: import_zod.z.array(import_zod.z.string()).min(1).describe("Array of trading symbols"),
|
|
340
|
+
mdReqID: import_zod.z.string().describe("Market data request ID"),
|
|
341
|
+
subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
342
|
+
mdEntryTypes: import_zod.z.array(import_zod.z.string()).min(1).describe("Array of market data entry types (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
343
|
+
},
|
|
344
|
+
async (args) => {
|
|
345
|
+
try {
|
|
346
|
+
const response = new Promise((resolve) => {
|
|
347
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
348
|
+
});
|
|
349
|
+
const messageFields = [
|
|
350
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
351
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
352
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
353
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
354
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
355
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
356
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
357
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
358
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
359
|
+
];
|
|
360
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
361
|
+
args.symbols.forEach((symbol) => {
|
|
362
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
363
|
+
});
|
|
364
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
365
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
366
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
367
|
+
});
|
|
368
|
+
const mdr = this.parser?.createMessage(...messageFields);
|
|
369
|
+
if (!this.parser?.connected) {
|
|
370
|
+
return {
|
|
371
|
+
content: [
|
|
372
|
+
{
|
|
373
|
+
type: "text",
|
|
374
|
+
text: "Error: Not connected. Ignoring message."
|
|
375
|
+
}
|
|
376
|
+
],
|
|
377
|
+
isError: true
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
this.parser?.send(mdr);
|
|
381
|
+
const fixData = await response;
|
|
382
|
+
return {
|
|
383
|
+
content: [
|
|
384
|
+
{
|
|
385
|
+
type: "text",
|
|
386
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
387
|
+
}
|
|
388
|
+
]
|
|
389
|
+
};
|
|
390
|
+
} catch (error) {
|
|
391
|
+
return {
|
|
392
|
+
content: [
|
|
393
|
+
{
|
|
394
|
+
type: "text",
|
|
395
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
396
|
+
}
|
|
397
|
+
],
|
|
398
|
+
isError: true
|
|
399
|
+
};
|
|
400
|
+
}
|
|
731
401
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
|
|
739
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
|
|
740
|
-
new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
|
|
741
|
-
new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
|
|
742
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
|
|
743
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
|
|
744
|
-
new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
745
|
-
new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
|
|
746
|
-
new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
|
|
747
|
-
new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
|
|
748
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
|
|
749
|
-
new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
|
|
750
|
-
);
|
|
751
|
-
if (!parser.connected) {
|
|
402
|
+
);
|
|
403
|
+
this.server.resource(
|
|
404
|
+
"greeting-resource",
|
|
405
|
+
"https://example.com/greetings/default",
|
|
406
|
+
{ mimeType: "text/plain" },
|
|
407
|
+
async () => {
|
|
752
408
|
return {
|
|
753
|
-
|
|
409
|
+
contents: [
|
|
754
410
|
{
|
|
755
|
-
|
|
756
|
-
text: "
|
|
757
|
-
uri: "executeOrder"
|
|
411
|
+
uri: "https://example.com/greetings/default",
|
|
412
|
+
text: "Hello, world!"
|
|
758
413
|
}
|
|
759
|
-
]
|
|
760
|
-
isError: true
|
|
414
|
+
]
|
|
761
415
|
};
|
|
762
416
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
417
|
+
);
|
|
418
|
+
this.server.resource(
|
|
419
|
+
"stockGraph",
|
|
420
|
+
new import_mcp.ResourceTemplate("stock://{symbol}", { list: void 0 }),
|
|
421
|
+
async (uri, variables) => {
|
|
422
|
+
const symbol = String(variables.symbol);
|
|
423
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
424
|
+
if (priceHistory.length === 0) {
|
|
425
|
+
return {
|
|
426
|
+
contents: [
|
|
427
|
+
{
|
|
428
|
+
uri: uri.href,
|
|
429
|
+
text: `No price data available for ${symbol}`
|
|
430
|
+
}
|
|
431
|
+
]
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const width = 600;
|
|
435
|
+
const height = 300;
|
|
436
|
+
const padding = 40;
|
|
437
|
+
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
438
|
+
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
439
|
+
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
440
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
441
|
+
const points = priceHistory.map((d, i) => {
|
|
442
|
+
const x = padding + i * xScale;
|
|
443
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
444
|
+
return `${x},${y}`;
|
|
445
|
+
}).join(" L ");
|
|
446
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
447
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
448
|
+
<!-- Background -->
|
|
449
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
450
|
+
|
|
451
|
+
<!-- Grid lines -->
|
|
452
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
453
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
454
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
455
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
456
|
+
}).join("\n")}
|
|
457
|
+
</g>
|
|
458
|
+
|
|
459
|
+
<!-- Price line -->
|
|
460
|
+
<path d="M ${points}"
|
|
461
|
+
fill="none"
|
|
462
|
+
stroke="#007bff"
|
|
463
|
+
stroke-width="2"/>
|
|
464
|
+
|
|
465
|
+
<!-- Data points -->
|
|
466
|
+
${priceHistory.map((d, i) => {
|
|
467
|
+
const x = padding + i * xScale;
|
|
468
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
469
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
470
|
+
}).join("\n")}
|
|
471
|
+
|
|
472
|
+
<!-- Labels -->
|
|
473
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
474
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
475
|
+
const x = padding + (width - 2 * padding) * i / 4;
|
|
476
|
+
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
477
|
+
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
478
|
+
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
479
|
+
}).join("\n")}
|
|
480
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
481
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
482
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
483
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
484
|
+
}).join("\n")}
|
|
485
|
+
</g>
|
|
486
|
+
|
|
487
|
+
<!-- Title -->
|
|
488
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
489
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
490
|
+
text-anchor="middle" fill="#212529">
|
|
491
|
+
${symbol} - Price Chart (${priceHistory.length} points)
|
|
492
|
+
</text>
|
|
493
|
+
</svg>`;
|
|
796
494
|
return {
|
|
797
|
-
|
|
495
|
+
contents: [
|
|
798
496
|
{
|
|
799
|
-
|
|
800
|
-
text:
|
|
801
|
-
uri: "parse"
|
|
497
|
+
uri: uri.href,
|
|
498
|
+
text: svg
|
|
802
499
|
}
|
|
803
|
-
]
|
|
804
|
-
isError: true
|
|
500
|
+
]
|
|
805
501
|
};
|
|
806
502
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
]
|
|
816
|
-
};
|
|
817
|
-
} catch (error) {
|
|
818
|
-
return {
|
|
819
|
-
content: [
|
|
820
|
-
{
|
|
821
|
-
type: "text",
|
|
822
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
823
|
-
uri: "parse"
|
|
824
|
-
}
|
|
825
|
-
],
|
|
826
|
-
isError: true
|
|
827
|
-
};
|
|
828
|
-
}
|
|
829
|
-
};
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
// src/tools/parseToJSON.ts
|
|
833
|
-
var createParseToJSONHandler = (parser) => {
|
|
834
|
-
return async (args) => {
|
|
835
|
-
try {
|
|
836
|
-
const parsedMessage = parser.parse(args.fixString);
|
|
837
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
503
|
+
);
|
|
504
|
+
this.server.resource(
|
|
505
|
+
"stockPriceHistory",
|
|
506
|
+
new import_mcp.ResourceTemplate("price-history://{symbol}", { list: void 0 }),
|
|
507
|
+
async (uri, variables) => {
|
|
508
|
+
const symbol = String(variables.symbol);
|
|
509
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
838
510
|
return {
|
|
839
|
-
|
|
511
|
+
contents: [
|
|
840
512
|
{
|
|
841
|
-
|
|
842
|
-
text:
|
|
843
|
-
|
|
513
|
+
uri: uri.href,
|
|
514
|
+
text: JSON.stringify(
|
|
515
|
+
{
|
|
516
|
+
symbol,
|
|
517
|
+
count: priceHistory.length,
|
|
518
|
+
prices: priceHistory.map((point) => ({
|
|
519
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
520
|
+
price: point.price
|
|
521
|
+
}))
|
|
522
|
+
},
|
|
523
|
+
null,
|
|
524
|
+
2
|
|
525
|
+
)
|
|
844
526
|
}
|
|
845
|
-
]
|
|
846
|
-
isError: true
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
return {
|
|
850
|
-
content: [
|
|
851
|
-
{
|
|
852
|
-
type: "text",
|
|
853
|
-
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
854
|
-
uri: "parseToJSON"
|
|
855
|
-
}
|
|
856
|
-
]
|
|
857
|
-
};
|
|
858
|
-
} catch (error) {
|
|
859
|
-
return {
|
|
860
|
-
content: [
|
|
861
|
-
{
|
|
862
|
-
type: "text",
|
|
863
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
864
|
-
uri: "parseToJSON"
|
|
865
|
-
}
|
|
866
|
-
],
|
|
867
|
-
isError: true
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
};
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
// src/tools/index.ts
|
|
874
|
-
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
875
|
-
parse: createParseHandler(parser),
|
|
876
|
-
parseToJSON: createParseToJSONHandler(parser),
|
|
877
|
-
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
878
|
-
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
879
|
-
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
880
|
-
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
881
|
-
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
882
|
-
});
|
|
883
|
-
|
|
884
|
-
// src/utils/messageHandler.ts
|
|
885
|
-
var import_fixparser3 = require("fixparser");
|
|
886
|
-
function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
|
|
887
|
-
parser.logger.log({
|
|
888
|
-
level: "info",
|
|
889
|
-
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
890
|
-
});
|
|
891
|
-
const msgType = message.messageType;
|
|
892
|
-
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
|
|
893
|
-
const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
|
|
894
|
-
const fixJson = message.toFIXJSON();
|
|
895
|
-
const entries = fixJson.Body?.NoMDEntries || [];
|
|
896
|
-
const data = {
|
|
897
|
-
timestamp: Date.now(),
|
|
898
|
-
bid: 0,
|
|
899
|
-
offer: 0,
|
|
900
|
-
spread: 0,
|
|
901
|
-
volume: 0,
|
|
902
|
-
trade: 0,
|
|
903
|
-
indexValue: 0,
|
|
904
|
-
openingPrice: 0,
|
|
905
|
-
closingPrice: 0,
|
|
906
|
-
settlementPrice: 0,
|
|
907
|
-
tradingSessionHighPrice: 0,
|
|
908
|
-
tradingSessionLowPrice: 0,
|
|
909
|
-
vwap: 0,
|
|
910
|
-
imbalance: 0,
|
|
911
|
-
openInterest: 0,
|
|
912
|
-
compositeUnderlyingPrice: 0,
|
|
913
|
-
simulatedSellPrice: 0,
|
|
914
|
-
simulatedBuyPrice: 0,
|
|
915
|
-
marginRate: 0,
|
|
916
|
-
midPrice: 0,
|
|
917
|
-
emptyBook: 0,
|
|
918
|
-
settleHighPrice: 0,
|
|
919
|
-
settleLowPrice: 0,
|
|
920
|
-
priorSettlePrice: 0,
|
|
921
|
-
sessionHighBid: 0,
|
|
922
|
-
sessionLowOffer: 0,
|
|
923
|
-
earlyPrices: 0,
|
|
924
|
-
auctionClearingPrice: 0,
|
|
925
|
-
swapValueFactor: 0,
|
|
926
|
-
dailyValueAdjustmentForLongPositions: 0,
|
|
927
|
-
cumulativeValueAdjustmentForLongPositions: 0,
|
|
928
|
-
dailyValueAdjustmentForShortPositions: 0,
|
|
929
|
-
cumulativeValueAdjustmentForShortPositions: 0,
|
|
930
|
-
fixingPrice: 0,
|
|
931
|
-
cashRate: 0,
|
|
932
|
-
recoveryRate: 0,
|
|
933
|
-
recoveryRateForLong: 0,
|
|
934
|
-
recoveryRateForShort: 0,
|
|
935
|
-
marketBid: 0,
|
|
936
|
-
marketOffer: 0,
|
|
937
|
-
shortSaleMinPrice: 0,
|
|
938
|
-
previousClosingPrice: 0,
|
|
939
|
-
thresholdLimitPriceBanding: 0,
|
|
940
|
-
dailyFinancingValue: 0,
|
|
941
|
-
accruedFinancingValue: 0,
|
|
942
|
-
twap: 0
|
|
943
|
-
};
|
|
944
|
-
for (const entry of entries) {
|
|
945
|
-
const entryType = entry.MDEntryType;
|
|
946
|
-
const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
|
|
947
|
-
const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
|
|
948
|
-
switch (entryType) {
|
|
949
|
-
case import_fixparser3.MDEntryType.Bid:
|
|
950
|
-
data.bid = price;
|
|
951
|
-
break;
|
|
952
|
-
case import_fixparser3.MDEntryType.Offer:
|
|
953
|
-
data.offer = price;
|
|
954
|
-
break;
|
|
955
|
-
case import_fixparser3.MDEntryType.Trade:
|
|
956
|
-
data.trade = price;
|
|
957
|
-
break;
|
|
958
|
-
case import_fixparser3.MDEntryType.IndexValue:
|
|
959
|
-
data.indexValue = price;
|
|
960
|
-
break;
|
|
961
|
-
case import_fixparser3.MDEntryType.OpeningPrice:
|
|
962
|
-
data.openingPrice = price;
|
|
963
|
-
break;
|
|
964
|
-
case import_fixparser3.MDEntryType.ClosingPrice:
|
|
965
|
-
data.closingPrice = price;
|
|
966
|
-
break;
|
|
967
|
-
case import_fixparser3.MDEntryType.SettlementPrice:
|
|
968
|
-
data.settlementPrice = price;
|
|
969
|
-
break;
|
|
970
|
-
case import_fixparser3.MDEntryType.TradingSessionHighPrice:
|
|
971
|
-
data.tradingSessionHighPrice = price;
|
|
972
|
-
break;
|
|
973
|
-
case import_fixparser3.MDEntryType.TradingSessionLowPrice:
|
|
974
|
-
data.tradingSessionLowPrice = price;
|
|
975
|
-
break;
|
|
976
|
-
case import_fixparser3.MDEntryType.VWAP:
|
|
977
|
-
data.vwap = price;
|
|
978
|
-
break;
|
|
979
|
-
case import_fixparser3.MDEntryType.Imbalance:
|
|
980
|
-
data.imbalance = size;
|
|
981
|
-
break;
|
|
982
|
-
case import_fixparser3.MDEntryType.TradeVolume:
|
|
983
|
-
data.volume = size;
|
|
984
|
-
break;
|
|
985
|
-
case import_fixparser3.MDEntryType.OpenInterest:
|
|
986
|
-
data.openInterest = size;
|
|
987
|
-
break;
|
|
988
|
-
case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
|
|
989
|
-
data.compositeUnderlyingPrice = price;
|
|
990
|
-
break;
|
|
991
|
-
case import_fixparser3.MDEntryType.SimulatedSellPrice:
|
|
992
|
-
data.simulatedSellPrice = price;
|
|
993
|
-
break;
|
|
994
|
-
case import_fixparser3.MDEntryType.SimulatedBuyPrice:
|
|
995
|
-
data.simulatedBuyPrice = price;
|
|
996
|
-
break;
|
|
997
|
-
case import_fixparser3.MDEntryType.MarginRate:
|
|
998
|
-
data.marginRate = price;
|
|
999
|
-
break;
|
|
1000
|
-
case import_fixparser3.MDEntryType.MidPrice:
|
|
1001
|
-
data.midPrice = price;
|
|
1002
|
-
break;
|
|
1003
|
-
case import_fixparser3.MDEntryType.EmptyBook:
|
|
1004
|
-
data.emptyBook = 1;
|
|
1005
|
-
break;
|
|
1006
|
-
case import_fixparser3.MDEntryType.SettleHighPrice:
|
|
1007
|
-
data.settleHighPrice = price;
|
|
1008
|
-
break;
|
|
1009
|
-
case import_fixparser3.MDEntryType.SettleLowPrice:
|
|
1010
|
-
data.settleLowPrice = price;
|
|
1011
|
-
break;
|
|
1012
|
-
case import_fixparser3.MDEntryType.PriorSettlePrice:
|
|
1013
|
-
data.priorSettlePrice = price;
|
|
1014
|
-
break;
|
|
1015
|
-
case import_fixparser3.MDEntryType.SessionHighBid:
|
|
1016
|
-
data.sessionHighBid = price;
|
|
1017
|
-
break;
|
|
1018
|
-
case import_fixparser3.MDEntryType.SessionLowOffer:
|
|
1019
|
-
data.sessionLowOffer = price;
|
|
1020
|
-
break;
|
|
1021
|
-
case import_fixparser3.MDEntryType.EarlyPrices:
|
|
1022
|
-
data.earlyPrices = price;
|
|
1023
|
-
break;
|
|
1024
|
-
case import_fixparser3.MDEntryType.AuctionClearingPrice:
|
|
1025
|
-
data.auctionClearingPrice = price;
|
|
1026
|
-
break;
|
|
1027
|
-
case import_fixparser3.MDEntryType.SwapValueFactor:
|
|
1028
|
-
data.swapValueFactor = price;
|
|
1029
|
-
break;
|
|
1030
|
-
case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
|
|
1031
|
-
data.dailyValueAdjustmentForLongPositions = price;
|
|
1032
|
-
break;
|
|
1033
|
-
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
|
|
1034
|
-
data.cumulativeValueAdjustmentForLongPositions = price;
|
|
1035
|
-
break;
|
|
1036
|
-
case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
|
|
1037
|
-
data.dailyValueAdjustmentForShortPositions = price;
|
|
1038
|
-
break;
|
|
1039
|
-
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
|
|
1040
|
-
data.cumulativeValueAdjustmentForShortPositions = price;
|
|
1041
|
-
break;
|
|
1042
|
-
case import_fixparser3.MDEntryType.FixingPrice:
|
|
1043
|
-
data.fixingPrice = price;
|
|
1044
|
-
break;
|
|
1045
|
-
case import_fixparser3.MDEntryType.CashRate:
|
|
1046
|
-
data.cashRate = price;
|
|
1047
|
-
break;
|
|
1048
|
-
case import_fixparser3.MDEntryType.RecoveryRate:
|
|
1049
|
-
data.recoveryRate = price;
|
|
1050
|
-
break;
|
|
1051
|
-
case import_fixparser3.MDEntryType.RecoveryRateForLong:
|
|
1052
|
-
data.recoveryRateForLong = price;
|
|
1053
|
-
break;
|
|
1054
|
-
case import_fixparser3.MDEntryType.RecoveryRateForShort:
|
|
1055
|
-
data.recoveryRateForShort = price;
|
|
1056
|
-
break;
|
|
1057
|
-
case import_fixparser3.MDEntryType.MarketBid:
|
|
1058
|
-
data.marketBid = price;
|
|
1059
|
-
break;
|
|
1060
|
-
case import_fixparser3.MDEntryType.MarketOffer:
|
|
1061
|
-
data.marketOffer = price;
|
|
1062
|
-
break;
|
|
1063
|
-
case import_fixparser3.MDEntryType.ShortSaleMinPrice:
|
|
1064
|
-
data.shortSaleMinPrice = price;
|
|
1065
|
-
break;
|
|
1066
|
-
case import_fixparser3.MDEntryType.PreviousClosingPrice:
|
|
1067
|
-
data.previousClosingPrice = price;
|
|
1068
|
-
break;
|
|
1069
|
-
case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
|
|
1070
|
-
data.thresholdLimitPriceBanding = price;
|
|
1071
|
-
break;
|
|
1072
|
-
case import_fixparser3.MDEntryType.DailyFinancingValue:
|
|
1073
|
-
data.dailyFinancingValue = price;
|
|
1074
|
-
break;
|
|
1075
|
-
case import_fixparser3.MDEntryType.AccruedFinancingValue:
|
|
1076
|
-
data.accruedFinancingValue = price;
|
|
1077
|
-
break;
|
|
1078
|
-
case import_fixparser3.MDEntryType.TWAP:
|
|
1079
|
-
data.twap = price;
|
|
1080
|
-
break;
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
data.spread = data.offer - data.bid;
|
|
1084
|
-
if (!marketDataPrices.has(symbol)) {
|
|
1085
|
-
marketDataPrices.set(symbol, []);
|
|
1086
|
-
}
|
|
1087
|
-
const prices = marketDataPrices.get(symbol);
|
|
1088
|
-
prices.push(data);
|
|
1089
|
-
if (prices.length > maxPriceHistory) {
|
|
1090
|
-
prices.splice(0, prices.length - maxPriceHistory);
|
|
1091
|
-
}
|
|
1092
|
-
onPriceUpdate?.(symbol, data);
|
|
1093
|
-
const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
|
|
1094
|
-
if (mdReqID) {
|
|
1095
|
-
const callback = pendingRequests.get(mdReqID);
|
|
1096
|
-
if (callback) {
|
|
1097
|
-
callback(message);
|
|
1098
|
-
pendingRequests.delete(mdReqID);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
} else if (msgType === import_fixparser3.Messages.ExecutionReport) {
|
|
1102
|
-
const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
|
|
1103
|
-
const callback = pendingRequests.get(reqId);
|
|
1104
|
-
if (callback) {
|
|
1105
|
-
callback(message);
|
|
1106
|
-
pendingRequests.delete(reqId);
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
// src/MCPLocal.ts
|
|
1112
|
-
var MCPLocal = class extends MCPBase {
|
|
1113
|
-
/**
|
|
1114
|
-
* Map to store verified orders before execution
|
|
1115
|
-
* @private
|
|
1116
|
-
*/
|
|
1117
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
1118
|
-
/**
|
|
1119
|
-
* Map to store pending requests and their callbacks
|
|
1120
|
-
* @private
|
|
1121
|
-
*/
|
|
1122
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
1123
|
-
/**
|
|
1124
|
-
* Map to store market data prices for each symbol
|
|
1125
|
-
* @private
|
|
1126
|
-
*/
|
|
1127
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
1128
|
-
/**
|
|
1129
|
-
* Maximum number of price history entries to keep per symbol
|
|
1130
|
-
* @private
|
|
1131
|
-
*/
|
|
1132
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
1133
|
-
server = new import_server.Server(
|
|
1134
|
-
{
|
|
1135
|
-
name: "fixparser",
|
|
1136
|
-
version: "1.0.0"
|
|
1137
|
-
},
|
|
1138
|
-
{
|
|
1139
|
-
capabilities: {
|
|
1140
|
-
tools: Object.entries(toolSchemas).reduce(
|
|
1141
|
-
(acc, [name, { description, schema }]) => {
|
|
1142
|
-
acc[name] = {
|
|
1143
|
-
description,
|
|
1144
|
-
parameters: schema
|
|
1145
|
-
};
|
|
1146
|
-
return acc;
|
|
1147
|
-
},
|
|
1148
|
-
{}
|
|
1149
|
-
)
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
);
|
|
1153
|
-
transport = new import_stdio.StdioServerTransport();
|
|
1154
|
-
constructor({ logger, onReady }) {
|
|
1155
|
-
super({ logger, onReady });
|
|
1156
|
-
}
|
|
1157
|
-
async register(parser) {
|
|
1158
|
-
this.parser = parser;
|
|
1159
|
-
this.parser.addOnMessageCallback((message) => {
|
|
1160
|
-
handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
|
|
1161
|
-
});
|
|
1162
|
-
this.addWorkflows();
|
|
1163
|
-
await this.server.connect(this.transport);
|
|
1164
|
-
if (this.onReady) {
|
|
1165
|
-
this.onReady();
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
addWorkflows() {
|
|
1169
|
-
if (!this.parser) {
|
|
1170
|
-
return;
|
|
1171
|
-
}
|
|
1172
|
-
if (!this.server) {
|
|
1173
|
-
return;
|
|
1174
|
-
}
|
|
1175
|
-
this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
|
|
1176
|
-
return {
|
|
1177
|
-
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
1178
|
-
name,
|
|
1179
|
-
description,
|
|
1180
|
-
inputSchema: schema
|
|
1181
|
-
}))
|
|
1182
|
-
};
|
|
1183
|
-
});
|
|
1184
|
-
this.server.setRequestHandler(
|
|
1185
|
-
import_zod.z.object({
|
|
1186
|
-
method: import_zod.z.literal("tools/call"),
|
|
1187
|
-
params: import_zod.z.object({
|
|
1188
|
-
name: import_zod.z.string(),
|
|
1189
|
-
arguments: import_zod.z.any(),
|
|
1190
|
-
_meta: import_zod.z.object({
|
|
1191
|
-
progressToken: import_zod.z.number()
|
|
1192
|
-
}).optional()
|
|
1193
|
-
})
|
|
1194
|
-
}),
|
|
1195
|
-
async (request) => {
|
|
1196
|
-
const { name, arguments: args } = request.params;
|
|
1197
|
-
const toolHandlers = createToolHandlers(
|
|
1198
|
-
this.parser,
|
|
1199
|
-
this.verifiedOrders,
|
|
1200
|
-
this.pendingRequests,
|
|
1201
|
-
this.marketDataPrices
|
|
1202
|
-
);
|
|
1203
|
-
const handler = toolHandlers[name];
|
|
1204
|
-
if (!handler) {
|
|
1205
|
-
return {
|
|
1206
|
-
content: [
|
|
1207
|
-
{
|
|
1208
|
-
type: "text",
|
|
1209
|
-
text: `Tool not found: ${name}`,
|
|
1210
|
-
uri: name
|
|
1211
|
-
}
|
|
1212
|
-
],
|
|
1213
|
-
isError: true
|
|
1214
|
-
};
|
|
1215
|
-
}
|
|
1216
|
-
const result = await handler(args);
|
|
1217
|
-
return {
|
|
1218
|
-
content: result.content,
|
|
1219
|
-
isError: result.isError
|
|
527
|
+
]
|
|
1220
528
|
};
|
|
1221
529
|
}
|
|
1222
530
|
);
|