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