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