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