fixparser-plugin-mcp 9.1.7-9d6b5ca3 → 9.1.7-a0e655a2
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 +600 -1223
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/cjs/MCPRemote.js +435 -1294
- package/build/cjs/MCPRemote.js.map +4 -4
- package/build/esm/MCPLocal.mjs +600 -1213
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build/esm/MCPRemote.mjs +444 -1284
- package/build/esm/MCPRemote.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +46 -8
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +46 -8
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +8 -9
- package/types/MCPLocal.d.ts +14 -0
- package/types/MCPRemote.d.ts +60 -0
- package/types/PluginOptions.d.ts +6 -0
- package/types/index.d.ts +3 -0
- package/build/cjs/index.js +0 -1593
- package/build/cjs/index.js.map +0 -7
- package/build/esm/index.mjs +0 -1555
- package/build/esm/index.mjs.map +0 -7
- package/build-examples/cjs/example_mcp_remote.js +0 -16
- package/build-examples/cjs/example_mcp_remote.js.map +0 -7
- package/build-examples/esm/example_mcp_remote.mjs +0 -16
- package/build-examples/esm/example_mcp_remote.mjs.map +0 -7
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,1276 +1,663 @@
|
|
|
1
1
|
// src/MCPLocal.ts
|
|
2
|
-
import {
|
|
2
|
+
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { Field, Fields, Messages } from "fixparser";
|
|
4
5
|
import { z } from "zod";
|
|
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
|
-
*/
|
|
6
|
+
var MCPLocal = class {
|
|
17
7
|
parser;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
server = new McpServer(
|
|
9
|
+
{
|
|
10
|
+
name: "fixparser",
|
|
11
|
+
version: "1.0.0"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
capabilities: {
|
|
15
|
+
tools: {},
|
|
16
|
+
prompts: {},
|
|
17
|
+
resources: {}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
transport = new StdioServerTransport();
|
|
22
22
|
onReady = void 0;
|
|
23
|
-
/**
|
|
24
|
-
* Map to store verified orders before execution
|
|
25
|
-
* @protected
|
|
26
|
-
*/
|
|
27
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
28
|
-
/**
|
|
29
|
-
* Map to store pending market data requests
|
|
30
|
-
* @protected
|
|
31
|
-
*/
|
|
32
23
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
33
|
-
|
|
34
|
-
* Map to store market data prices
|
|
35
|
-
* @protected
|
|
36
|
-
*/
|
|
37
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
38
|
-
/**
|
|
39
|
-
* Maximum number of price history entries to keep per symbol
|
|
40
|
-
* @protected
|
|
41
|
-
*/
|
|
42
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
24
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
43
25
|
constructor({ logger, onReady }) {
|
|
44
|
-
this.
|
|
45
|
-
this.onReady = onReady;
|
|
26
|
+
if (onReady) this.onReady = onReady;
|
|
46
27
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
28
|
+
async register(parser) {
|
|
29
|
+
this.parser = parser;
|
|
30
|
+
this.parser.addOnMessageCallback((message) => {
|
|
31
|
+
const msgType = message.messageType;
|
|
32
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject) {
|
|
33
|
+
let id;
|
|
34
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
35
|
+
const mdReqID = message.getField(Fields.MDReqID);
|
|
36
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
37
|
+
} else if (msgType === Messages.ExecutionReport) {
|
|
38
|
+
const clOrdID = message.getField(Fields.ClOrdID);
|
|
39
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
40
|
+
} else if (msgType === Messages.Reject) {
|
|
41
|
+
const refSeqNum = message.getField(Fields.RefSeqNum);
|
|
42
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
43
|
+
}
|
|
44
|
+
if (id) {
|
|
45
|
+
const callback = this.pendingRequests.get(id);
|
|
46
|
+
if (callback) {
|
|
47
|
+
callback(message);
|
|
48
|
+
this.pendingRequests.delete(id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
this.addWorkflows();
|
|
54
|
+
await this.server.connect(this.transport);
|
|
55
|
+
if (this.onReady) {
|
|
56
|
+
this.onReady();
|
|
59
57
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
type: "object",
|
|
65
|
-
properties: {
|
|
66
|
-
fixString: { type: "string" }
|
|
67
|
-
},
|
|
68
|
-
required: ["fixString"]
|
|
58
|
+
}
|
|
59
|
+
addWorkflows() {
|
|
60
|
+
if (!this.parser) {
|
|
61
|
+
return;
|
|
69
62
|
}
|
|
70
|
-
|
|
71
|
-
|
|
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"]
|
|
63
|
+
if (!this.server) {
|
|
64
|
+
return;
|
|
129
65
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
}
|
|
66
|
+
this.server.tool(
|
|
67
|
+
"parse",
|
|
68
|
+
"Parses a FIX message and describes it in plain language",
|
|
69
|
+
{
|
|
70
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
187
71
|
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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"
|
|
72
|
+
async (args) => {
|
|
73
|
+
try {
|
|
74
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
75
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
76
|
+
return {
|
|
77
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
78
|
+
isError: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: `${parsedMessage[0].description}
|
|
86
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
87
|
+
}
|
|
249
88
|
]
|
|
250
|
-
}
|
|
251
|
-
|
|
89
|
+
};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: "text",
|
|
95
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
isError: true
|
|
99
|
+
};
|
|
252
100
|
}
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
this.server.tool(
|
|
104
|
+
"parseToJSON",
|
|
105
|
+
"Parses a FIX message into JSON",
|
|
106
|
+
{
|
|
107
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
253
108
|
},
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
109
|
+
async (args) => {
|
|
110
|
+
try {
|
|
111
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
112
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
115
|
+
isError: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: "text",
|
|
122
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
return {
|
|
128
|
+
content: [
|
|
129
|
+
{
|
|
130
|
+
type: "text",
|
|
131
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
isError: true
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
this.server.tool(
|
|
140
|
+
"verifyOrder",
|
|
141
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
142
|
+
{
|
|
143
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
144
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
145
|
+
quantity: z.string().describe("Order quantity"),
|
|
146
|
+
price: z.string().describe("Order price"),
|
|
147
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
148
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
149
|
+
symbol: z.string().describe("Trading symbol"),
|
|
150
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
273
151
|
},
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
152
|
+
async (args) => {
|
|
153
|
+
try {
|
|
154
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
155
|
+
clOrdID: args.clOrdID,
|
|
156
|
+
handlInst: args.handlInst,
|
|
157
|
+
quantity: Number.parseFloat(args.quantity),
|
|
158
|
+
price: Number.parseFloat(args.price),
|
|
159
|
+
ordType: args.ordType,
|
|
160
|
+
side: args.side,
|
|
161
|
+
symbol: args.symbol,
|
|
162
|
+
timeInForce: args.timeInForce
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
content: [
|
|
166
|
+
{
|
|
167
|
+
type: "text",
|
|
168
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
169
|
+
|
|
170
|
+
Parameters verified:
|
|
171
|
+
- ClOrdID: ${args.clOrdID}
|
|
172
|
+
- HandlInst: ${args.handlInst}
|
|
173
|
+
- Quantity: ${args.quantity}
|
|
174
|
+
- Price: ${args.price}
|
|
175
|
+
- OrdType: ${args.ordType}
|
|
176
|
+
- Side: ${args.side}
|
|
177
|
+
- Symbol: ${args.symbol}
|
|
178
|
+
- TimeInForce: ${args.timeInForce}
|
|
278
179
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
});
|
|
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"
|
|
373
|
-
}
|
|
374
|
-
],
|
|
375
|
-
isError: true
|
|
376
|
-
};
|
|
180
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
181
|
+
}
|
|
182
|
+
]
|
|
183
|
+
};
|
|
184
|
+
} catch (error) {
|
|
185
|
+
return {
|
|
186
|
+
content: [
|
|
187
|
+
{
|
|
188
|
+
type: "text",
|
|
189
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
isError: true
|
|
193
|
+
};
|
|
194
|
+
}
|
|
377
195
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
196
|
+
);
|
|
197
|
+
this.server.tool(
|
|
198
|
+
"executeOrder",
|
|
199
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
200
|
+
{
|
|
201
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
202
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
203
|
+
quantity: z.string().describe("Order quantity"),
|
|
204
|
+
price: z.string().describe("Order price"),
|
|
205
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
206
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
207
|
+
symbol: z.string().describe("Trading symbol"),
|
|
208
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
209
|
+
},
|
|
210
|
+
async (args) => {
|
|
211
|
+
try {
|
|
212
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
213
|
+
if (!verifiedOrder) {
|
|
214
|
+
return {
|
|
215
|
+
content: [
|
|
216
|
+
{
|
|
217
|
+
type: "text",
|
|
218
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
isError: true
|
|
222
|
+
};
|
|
394
223
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
224
|
+
if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
|
|
225
|
+
return {
|
|
226
|
+
content: [
|
|
227
|
+
{
|
|
228
|
+
type: "text",
|
|
229
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
isError: true
|
|
233
|
+
};
|
|
404
234
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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: [
|
|
444
|
-
{
|
|
445
|
-
label: "Bid",
|
|
446
|
-
data: bidData,
|
|
447
|
-
borderColor: "#28a745",
|
|
448
|
-
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
449
|
-
fill: false,
|
|
450
|
-
tension: 0.4
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
label: "Offer",
|
|
454
|
-
data: offerData,
|
|
455
|
-
borderColor: "#dc3545",
|
|
456
|
-
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
457
|
-
fill: false,
|
|
458
|
-
tension: 0.4
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
label: "Spread",
|
|
462
|
-
data: spreadData,
|
|
463
|
-
borderColor: "#6c757d",
|
|
464
|
-
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
465
|
-
fill: false,
|
|
466
|
-
tension: 0.4
|
|
467
|
-
},
|
|
468
|
-
{
|
|
469
|
-
label: "Trade",
|
|
470
|
-
data: tradeData,
|
|
471
|
-
borderColor: "#ffc107",
|
|
472
|
-
backgroundColor: "rgba(255, 193, 7, 0.1)",
|
|
473
|
-
fill: false,
|
|
474
|
-
tension: 0.4
|
|
475
|
-
},
|
|
476
|
-
{
|
|
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
|
|
499
|
-
}
|
|
500
|
-
]
|
|
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
|
-
}
|
|
235
|
+
const response = new Promise((resolve) => {
|
|
236
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
237
|
+
});
|
|
238
|
+
const order = this.parser?.createMessage(
|
|
239
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
240
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
241
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
242
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
243
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
244
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
245
|
+
new Field(Fields.Side, args.side),
|
|
246
|
+
new Field(Fields.Symbol, args.symbol),
|
|
247
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
248
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
249
|
+
new Field(Fields.OrdType, args.ordType),
|
|
250
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
251
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
252
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
253
|
+
);
|
|
254
|
+
if (!this.parser?.connected) {
|
|
255
|
+
return {
|
|
256
|
+
content: [
|
|
257
|
+
{
|
|
258
|
+
type: "text",
|
|
259
|
+
text: "Error: Not connected. Ignoring message."
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
isError: true
|
|
263
|
+
};
|
|
514
264
|
}
|
|
265
|
+
this.parser?.send(order);
|
|
266
|
+
const fixData = await response;
|
|
267
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
268
|
+
return {
|
|
269
|
+
content: [
|
|
270
|
+
{
|
|
271
|
+
type: "text",
|
|
272
|
+
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())}`
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
};
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return {
|
|
278
|
+
content: [
|
|
279
|
+
{
|
|
280
|
+
type: "text",
|
|
281
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
282
|
+
}
|
|
283
|
+
],
|
|
284
|
+
isError: true
|
|
285
|
+
};
|
|
515
286
|
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
this.server.tool(
|
|
290
|
+
"marketDataRequest",
|
|
291
|
+
"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
292
|
+
{
|
|
293
|
+
mdUpdateType: z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
294
|
+
symbol: z.string().describe("Trading symbol"),
|
|
295
|
+
mdReqID: z.string().describe("Market data request ID"),
|
|
296
|
+
subscriptionRequestType: z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
297
|
+
mdEntryType: z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
298
|
+
},
|
|
299
|
+
async (args) => {
|
|
300
|
+
try {
|
|
301
|
+
const response = new Promise((resolve) => {
|
|
302
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
303
|
+
});
|
|
304
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
305
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
306
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
307
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
308
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
309
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
310
|
+
new Field(Fields.MarketDepth, 0),
|
|
311
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType),
|
|
312
|
+
new Field(Fields.NoRelatedSym, 1),
|
|
313
|
+
new Field(Fields.Symbol, args.symbol),
|
|
314
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
315
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
316
|
+
new Field(Fields.NoMDEntryTypes, 1),
|
|
317
|
+
new Field(Fields.MDEntryType, args.mdEntryType)
|
|
318
|
+
);
|
|
319
|
+
if (!this.parser?.connected) {
|
|
320
|
+
return {
|
|
321
|
+
content: [
|
|
322
|
+
{
|
|
323
|
+
type: "text",
|
|
324
|
+
text: "Error: Not connected. Ignoring message."
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
isError: true
|
|
328
|
+
};
|
|
539
329
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
330
|
+
this.parser?.send(marketDataRequest);
|
|
331
|
+
const fixData = await response;
|
|
332
|
+
return {
|
|
333
|
+
content: [
|
|
334
|
+
{
|
|
335
|
+
type: "text",
|
|
336
|
+
text: `Market data for ${args.symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
};
|
|
340
|
+
} catch (error) {
|
|
341
|
+
return {
|
|
342
|
+
content: [
|
|
343
|
+
{
|
|
344
|
+
type: "text",
|
|
345
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
isError: true
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
this.server.prompt(
|
|
354
|
+
"parse",
|
|
355
|
+
"Parses a FIX message and describes it in plain language",
|
|
356
|
+
{
|
|
357
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
358
|
+
},
|
|
359
|
+
async (args) => {
|
|
552
360
|
return {
|
|
553
|
-
|
|
361
|
+
messages: [
|
|
554
362
|
{
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
363
|
+
role: "user",
|
|
364
|
+
content: {
|
|
365
|
+
type: "text",
|
|
366
|
+
text: `Please parse and explain this FIX message: ${args.fixString}`
|
|
367
|
+
}
|
|
558
368
|
}
|
|
559
369
|
]
|
|
560
370
|
};
|
|
561
371
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
-
|
|
729
|
-
Parameters verified:
|
|
730
|
-
- ClOrdID: ${args.clOrdID}
|
|
731
|
-
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
732
|
-
- Quantity: ${args.quantity}
|
|
733
|
-
- Price: ${args.price}
|
|
734
|
-
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
735
|
-
- Side: ${args.side} (${sideNames[args.side]})
|
|
736
|
-
- Symbol: ${args.symbol}
|
|
737
|
-
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
738
|
-
|
|
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"
|
|
741
|
-
}
|
|
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"
|
|
751
|
-
}
|
|
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) {
|
|
372
|
+
);
|
|
373
|
+
this.server.prompt(
|
|
374
|
+
"parseToJSON",
|
|
375
|
+
"Parses a FIX message into JSON",
|
|
376
|
+
{
|
|
377
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
378
|
+
},
|
|
379
|
+
async (args) => {
|
|
763
380
|
return {
|
|
764
|
-
|
|
381
|
+
messages: [
|
|
765
382
|
{
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
383
|
+
role: "user",
|
|
384
|
+
content: {
|
|
385
|
+
type: "text",
|
|
386
|
+
text: `Please parse the FIX message to JSON: ${args.fixString}`
|
|
387
|
+
}
|
|
769
388
|
}
|
|
770
|
-
]
|
|
771
|
-
isError: true
|
|
389
|
+
]
|
|
772
390
|
};
|
|
773
391
|
}
|
|
774
|
-
|
|
392
|
+
);
|
|
393
|
+
this.server.prompt(
|
|
394
|
+
"verifyOrder",
|
|
395
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
396
|
+
{
|
|
397
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
398
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
399
|
+
quantity: z.string().describe("Order quantity"),
|
|
400
|
+
price: z.string().describe("Order price"),
|
|
401
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
402
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
403
|
+
symbol: z.string().describe("Trading symbol"),
|
|
404
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
405
|
+
},
|
|
406
|
+
async (args) => {
|
|
775
407
|
return {
|
|
776
|
-
|
|
408
|
+
messages: [
|
|
777
409
|
{
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
410
|
+
role: "user",
|
|
411
|
+
content: {
|
|
412
|
+
type: "text",
|
|
413
|
+
text: [
|
|
414
|
+
"You are an AI assistant that helps users verify FIX New Order Single parameters.",
|
|
415
|
+
"This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.",
|
|
416
|
+
"",
|
|
417
|
+
"You must verify that all required fields are provided and valid:",
|
|
418
|
+
"- ClOrdID (Client Order ID)",
|
|
419
|
+
"- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
420
|
+
"- Quantity (Order quantity)",
|
|
421
|
+
"- Price (Order price)",
|
|
422
|
+
"- OrdType (1=Market, 2=Limit, 3=Stop)",
|
|
423
|
+
"- 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)",
|
|
424
|
+
"- Symbol (Trading symbol)",
|
|
425
|
+
"- TimeInForce (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",
|
|
426
|
+
"",
|
|
427
|
+
"Current parameters to verify:",
|
|
428
|
+
`- ClOrdID: ${args.clOrdID}`,
|
|
429
|
+
`- HandlInst: ${args.handlInst}`,
|
|
430
|
+
`- Quantity: ${args.quantity}`,
|
|
431
|
+
`- Price: ${args.price}`,
|
|
432
|
+
`- OrdType: ${args.ordType}`,
|
|
433
|
+
`- Side: ${args.side}`,
|
|
434
|
+
`- Symbol: ${args.symbol}`,
|
|
435
|
+
`- TimeInForce: ${args.timeInForce}`,
|
|
436
|
+
"",
|
|
437
|
+
"If all parameters are valid, respond with:",
|
|
438
|
+
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
439
|
+
"",
|
|
440
|
+
"Otherwise, list the missing or invalid ones.",
|
|
441
|
+
"",
|
|
442
|
+
"IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."
|
|
443
|
+
].join("\n")
|
|
444
|
+
}
|
|
781
445
|
}
|
|
782
|
-
]
|
|
783
|
-
isError: true
|
|
446
|
+
]
|
|
784
447
|
};
|
|
785
448
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
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) {
|
|
449
|
+
);
|
|
450
|
+
this.server.prompt(
|
|
451
|
+
"executeOrder",
|
|
452
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
453
|
+
{
|
|
454
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
455
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
456
|
+
quantity: z.string().describe("Order quantity"),
|
|
457
|
+
price: z.string().describe("Order price"),
|
|
458
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
459
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
460
|
+
symbol: z.string().describe("Trading symbol"),
|
|
461
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
462
|
+
},
|
|
463
|
+
async (args) => {
|
|
806
464
|
return {
|
|
807
|
-
|
|
465
|
+
messages: [
|
|
808
466
|
{
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
467
|
+
role: "user",
|
|
468
|
+
content: {
|
|
469
|
+
type: "text",
|
|
470
|
+
text: [
|
|
471
|
+
"You are an AI assistant that helps users execute FIX New Order Single messages.",
|
|
472
|
+
"This is STEP 2 of 2 - EXECUTION. This will send the order to the market.",
|
|
473
|
+
"",
|
|
474
|
+
"IMPORTANT: This tool should only be called after successful verification of all parameters.",
|
|
475
|
+
"",
|
|
476
|
+
"Parameters to execute:",
|
|
477
|
+
`- ClOrdID: ${args.clOrdID}`,
|
|
478
|
+
`- HandlInst: ${args.handlInst}`,
|
|
479
|
+
`- Quantity: ${args.quantity}`,
|
|
480
|
+
`- Price: ${args.price}`,
|
|
481
|
+
`- OrdType: ${args.ordType}`,
|
|
482
|
+
`- Side: ${args.side}`,
|
|
483
|
+
`- Symbol: ${args.symbol}`,
|
|
484
|
+
`- TimeInForce: ${args.timeInForce}`,
|
|
485
|
+
"",
|
|
486
|
+
"IMPORTANT: The response will be either:",
|
|
487
|
+
"1. An Execution Report (MsgType=8) if the order was successfully placed",
|
|
488
|
+
"2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
|
|
489
|
+
].join("\n")
|
|
490
|
+
}
|
|
812
491
|
}
|
|
813
|
-
]
|
|
814
|
-
isError: true
|
|
492
|
+
]
|
|
815
493
|
};
|
|
816
494
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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) {
|
|
495
|
+
);
|
|
496
|
+
this.server.prompt(
|
|
497
|
+
"marketDataRequest",
|
|
498
|
+
"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
499
|
+
{
|
|
500
|
+
mdUpdateType: z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
501
|
+
symbol: z.string().describe("Trading symbol"),
|
|
502
|
+
mdReqID: z.string().describe("Market data request ID"),
|
|
503
|
+
subscriptionRequestType: z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
504
|
+
mdEntryType: z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
505
|
+
},
|
|
506
|
+
async (args) => {
|
|
850
507
|
return {
|
|
851
|
-
|
|
508
|
+
messages: [
|
|
852
509
|
{
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
510
|
+
role: "user",
|
|
511
|
+
content: {
|
|
512
|
+
type: "text",
|
|
513
|
+
text: [
|
|
514
|
+
"You are an AI assistant that helps users create FIX Market Data Request messages.",
|
|
515
|
+
"You must **first verify** that all required fields are provided:",
|
|
516
|
+
"- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
|
|
517
|
+
"- Symbol (Trading symbol)",
|
|
518
|
+
"- MDReqID (Market data request ID)",
|
|
519
|
+
"- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
520
|
+
"- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
521
|
+
"",
|
|
522
|
+
"Only when all fields are present and valid, respond with:",
|
|
523
|
+
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
524
|
+
"",
|
|
525
|
+
"Otherwise, list the missing or invalid ones.",
|
|
526
|
+
"",
|
|
527
|
+
"Do not create the FIX message until verification is complete.",
|
|
528
|
+
"",
|
|
529
|
+
"Current parameters:",
|
|
530
|
+
`- MDUpdateType: ${args.mdUpdateType}`,
|
|
531
|
+
`- Symbol: ${args.symbol}`,
|
|
532
|
+
`- MDReqID: ${args.mdReqID}`,
|
|
533
|
+
`- SubscriptionRequestType: ${args.subscriptionRequestType}`,
|
|
534
|
+
`- MDEntryType: ${args.mdEntryType}`
|
|
535
|
+
].join("\n")
|
|
536
|
+
}
|
|
856
537
|
}
|
|
857
|
-
]
|
|
858
|
-
isError: true
|
|
538
|
+
]
|
|
859
539
|
};
|
|
860
540
|
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
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) {
|
|
541
|
+
);
|
|
542
|
+
this.server.resource(
|
|
543
|
+
"greeting-resource",
|
|
544
|
+
"https://example.com/greetings/default",
|
|
545
|
+
{ mimeType: "text/plain" },
|
|
546
|
+
async () => {
|
|
892
547
|
return {
|
|
893
|
-
|
|
548
|
+
contents: [
|
|
894
549
|
{
|
|
895
|
-
|
|
896
|
-
text: "
|
|
897
|
-
uri: "parseToJSON"
|
|
550
|
+
uri: "https://example.com/greetings/default",
|
|
551
|
+
text: "Hello, world!"
|
|
898
552
|
}
|
|
899
|
-
]
|
|
900
|
-
isError: true
|
|
553
|
+
]
|
|
901
554
|
};
|
|
902
555
|
}
|
|
903
|
-
|
|
904
|
-
|
|
556
|
+
);
|
|
557
|
+
this.server.resource(
|
|
558
|
+
"greeting",
|
|
559
|
+
new ResourceTemplate("greeting://{name}", { list: void 0 }),
|
|
560
|
+
async (uri, { name }) => ({
|
|
561
|
+
contents: [
|
|
905
562
|
{
|
|
906
|
-
|
|
907
|
-
text:
|
|
908
|
-
uri: "parseToJSON"
|
|
563
|
+
uri: uri.href,
|
|
564
|
+
text: `Hello, ${name}!`
|
|
909
565
|
}
|
|
910
566
|
]
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
567
|
+
})
|
|
568
|
+
);
|
|
569
|
+
this.server.resource(
|
|
570
|
+
"echo",
|
|
571
|
+
new ResourceTemplate("echo://{message}", { list: void 0 }),
|
|
572
|
+
async (uri, { message }) => ({
|
|
573
|
+
contents: [
|
|
915
574
|
{
|
|
916
|
-
|
|
917
|
-
text: `
|
|
918
|
-
uri: "parseToJSON"
|
|
575
|
+
uri: uri.href,
|
|
576
|
+
text: `Resource echo: ${message}`
|
|
919
577
|
}
|
|
920
|
-
]
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
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
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
};
|
|
997
|
-
for (const entry of entries) {
|
|
998
|
-
const entryType = entry.MDEntryType;
|
|
999
|
-
const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
|
|
1000
|
-
const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
|
|
1001
|
-
const enumValue = getEnumValue(MDEntryType2, entryType);
|
|
1002
|
-
switch (enumValue) {
|
|
1003
|
-
case MDEntryType2.Bid:
|
|
1004
|
-
data.bid = price;
|
|
1005
|
-
break;
|
|
1006
|
-
case MDEntryType2.Offer:
|
|
1007
|
-
data.offer = price;
|
|
1008
|
-
break;
|
|
1009
|
-
case MDEntryType2.Trade:
|
|
1010
|
-
data.trade = price;
|
|
1011
|
-
break;
|
|
1012
|
-
case MDEntryType2.IndexValue:
|
|
1013
|
-
data.indexValue = price;
|
|
1014
|
-
break;
|
|
1015
|
-
case MDEntryType2.OpeningPrice:
|
|
1016
|
-
data.openingPrice = price;
|
|
1017
|
-
break;
|
|
1018
|
-
case MDEntryType2.ClosingPrice:
|
|
1019
|
-
data.closingPrice = price;
|
|
1020
|
-
break;
|
|
1021
|
-
case MDEntryType2.SettlementPrice:
|
|
1022
|
-
data.settlementPrice = price;
|
|
1023
|
-
break;
|
|
1024
|
-
case MDEntryType2.TradingSessionHighPrice:
|
|
1025
|
-
data.tradingSessionHighPrice = price;
|
|
1026
|
-
break;
|
|
1027
|
-
case MDEntryType2.TradingSessionLowPrice:
|
|
1028
|
-
data.tradingSessionLowPrice = price;
|
|
1029
|
-
break;
|
|
1030
|
-
case MDEntryType2.VWAP:
|
|
1031
|
-
data.vwap = price;
|
|
1032
|
-
break;
|
|
1033
|
-
case MDEntryType2.Imbalance:
|
|
1034
|
-
data.imbalance = size;
|
|
1035
|
-
break;
|
|
1036
|
-
case MDEntryType2.TradeVolume:
|
|
1037
|
-
data.volume = size;
|
|
1038
|
-
break;
|
|
1039
|
-
case MDEntryType2.OpenInterest:
|
|
1040
|
-
data.openInterest = size;
|
|
1041
|
-
break;
|
|
1042
|
-
case MDEntryType2.CompositeUnderlyingPrice:
|
|
1043
|
-
data.compositeUnderlyingPrice = price;
|
|
1044
|
-
break;
|
|
1045
|
-
case MDEntryType2.SimulatedSellPrice:
|
|
1046
|
-
data.simulatedSellPrice = price;
|
|
1047
|
-
break;
|
|
1048
|
-
case MDEntryType2.SimulatedBuyPrice:
|
|
1049
|
-
data.simulatedBuyPrice = price;
|
|
1050
|
-
break;
|
|
1051
|
-
case MDEntryType2.MarginRate:
|
|
1052
|
-
data.marginRate = price;
|
|
1053
|
-
break;
|
|
1054
|
-
case MDEntryType2.MidPrice:
|
|
1055
|
-
data.midPrice = price;
|
|
1056
|
-
break;
|
|
1057
|
-
case MDEntryType2.EmptyBook:
|
|
1058
|
-
data.emptyBook = 1;
|
|
1059
|
-
break;
|
|
1060
|
-
case MDEntryType2.SettleHighPrice:
|
|
1061
|
-
data.settleHighPrice = price;
|
|
1062
|
-
break;
|
|
1063
|
-
case MDEntryType2.SettleLowPrice:
|
|
1064
|
-
data.settleLowPrice = price;
|
|
1065
|
-
break;
|
|
1066
|
-
case MDEntryType2.PriorSettlePrice:
|
|
1067
|
-
data.priorSettlePrice = price;
|
|
1068
|
-
break;
|
|
1069
|
-
case MDEntryType2.SessionHighBid:
|
|
1070
|
-
data.sessionHighBid = price;
|
|
1071
|
-
break;
|
|
1072
|
-
case MDEntryType2.SessionLowOffer:
|
|
1073
|
-
data.sessionLowOffer = price;
|
|
1074
|
-
break;
|
|
1075
|
-
case MDEntryType2.EarlyPrices:
|
|
1076
|
-
data.earlyPrices = price;
|
|
1077
|
-
break;
|
|
1078
|
-
case MDEntryType2.AuctionClearingPrice:
|
|
1079
|
-
data.auctionClearingPrice = price;
|
|
1080
|
-
break;
|
|
1081
|
-
case MDEntryType2.SwapValueFactor:
|
|
1082
|
-
data.swapValueFactor = price;
|
|
1083
|
-
break;
|
|
1084
|
-
case MDEntryType2.DailyValueAdjustmentForLongPositions:
|
|
1085
|
-
data.dailyValueAdjustmentForLongPositions = price;
|
|
1086
|
-
break;
|
|
1087
|
-
case MDEntryType2.CumulativeValueAdjustmentForLongPositions:
|
|
1088
|
-
data.cumulativeValueAdjustmentForLongPositions = price;
|
|
1089
|
-
break;
|
|
1090
|
-
case MDEntryType2.DailyValueAdjustmentForShortPositions:
|
|
1091
|
-
data.dailyValueAdjustmentForShortPositions = price;
|
|
1092
|
-
break;
|
|
1093
|
-
case MDEntryType2.CumulativeValueAdjustmentForShortPositions:
|
|
1094
|
-
data.cumulativeValueAdjustmentForShortPositions = price;
|
|
1095
|
-
break;
|
|
1096
|
-
case MDEntryType2.FixingPrice:
|
|
1097
|
-
data.fixingPrice = price;
|
|
1098
|
-
break;
|
|
1099
|
-
case MDEntryType2.CashRate:
|
|
1100
|
-
data.cashRate = price;
|
|
1101
|
-
break;
|
|
1102
|
-
case MDEntryType2.RecoveryRate:
|
|
1103
|
-
data.recoveryRate = price;
|
|
1104
|
-
break;
|
|
1105
|
-
case MDEntryType2.RecoveryRateForLong:
|
|
1106
|
-
data.recoveryRateForLong = price;
|
|
1107
|
-
break;
|
|
1108
|
-
case MDEntryType2.RecoveryRateForShort:
|
|
1109
|
-
data.recoveryRateForShort = price;
|
|
1110
|
-
break;
|
|
1111
|
-
case MDEntryType2.MarketBid:
|
|
1112
|
-
data.marketBid = price;
|
|
1113
|
-
break;
|
|
1114
|
-
case MDEntryType2.MarketOffer:
|
|
1115
|
-
data.marketOffer = price;
|
|
1116
|
-
break;
|
|
1117
|
-
case MDEntryType2.ShortSaleMinPrice:
|
|
1118
|
-
data.shortSaleMinPrice = price;
|
|
1119
|
-
break;
|
|
1120
|
-
case MDEntryType2.PreviousClosingPrice:
|
|
1121
|
-
data.previousClosingPrice = price;
|
|
1122
|
-
break;
|
|
1123
|
-
case MDEntryType2.ThresholdLimitPriceBanding:
|
|
1124
|
-
data.thresholdLimitPriceBanding = price;
|
|
1125
|
-
break;
|
|
1126
|
-
case MDEntryType2.DailyFinancingValue:
|
|
1127
|
-
data.dailyFinancingValue = price;
|
|
1128
|
-
break;
|
|
1129
|
-
case MDEntryType2.AccruedFinancingValue:
|
|
1130
|
-
data.accruedFinancingValue = price;
|
|
1131
|
-
break;
|
|
1132
|
-
case MDEntryType2.TWAP:
|
|
1133
|
-
data.twap = price;
|
|
1134
|
-
break;
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
data.spread = data.offer - data.bid;
|
|
1138
|
-
if (!marketDataPrices.has(symbol)) {
|
|
1139
|
-
marketDataPrices.set(symbol, []);
|
|
1140
|
-
}
|
|
1141
|
-
const prices = marketDataPrices.get(symbol);
|
|
1142
|
-
prices.push(data);
|
|
1143
|
-
if (prices.length > maxPriceHistory) {
|
|
1144
|
-
prices.splice(0, prices.length - maxPriceHistory);
|
|
1145
|
-
}
|
|
1146
|
-
onPriceUpdate?.(symbol, data);
|
|
1147
|
-
const mdReqID = message.getField(Fields3.MDReqID)?.value;
|
|
1148
|
-
if (mdReqID) {
|
|
1149
|
-
const callback = pendingRequests.get(mdReqID);
|
|
1150
|
-
if (callback) {
|
|
1151
|
-
callback(message);
|
|
1152
|
-
pendingRequests.delete(mdReqID);
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
} else if (msgType === Messages3.ExecutionReport) {
|
|
1156
|
-
const reqId = message.getField(Fields3.ClOrdID)?.value;
|
|
1157
|
-
const callback = pendingRequests.get(reqId);
|
|
1158
|
-
if (callback) {
|
|
1159
|
-
callback(message);
|
|
1160
|
-
pendingRequests.delete(reqId);
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
// src/MCPLocal.ts
|
|
1166
|
-
var MCPLocal = class extends MCPBase {
|
|
1167
|
-
/**
|
|
1168
|
-
* Map to store verified orders before execution
|
|
1169
|
-
* @private
|
|
1170
|
-
*/
|
|
1171
|
-
verifiedOrders = /* @__PURE__ */ new Map();
|
|
1172
|
-
/**
|
|
1173
|
-
* Map to store pending requests and their callbacks
|
|
1174
|
-
* @private
|
|
1175
|
-
*/
|
|
1176
|
-
pendingRequests = /* @__PURE__ */ new Map();
|
|
1177
|
-
/**
|
|
1178
|
-
* Map to store market data prices for each symbol
|
|
1179
|
-
* @private
|
|
1180
|
-
*/
|
|
1181
|
-
marketDataPrices = /* @__PURE__ */ new Map();
|
|
1182
|
-
/**
|
|
1183
|
-
* Maximum number of price history entries to keep per symbol
|
|
1184
|
-
* @private
|
|
1185
|
-
*/
|
|
1186
|
-
MAX_PRICE_HISTORY = 1e5;
|
|
1187
|
-
server = new Server(
|
|
1188
|
-
{
|
|
1189
|
-
name: "fixparser",
|
|
1190
|
-
version: "1.0.0"
|
|
1191
|
-
},
|
|
1192
|
-
{
|
|
1193
|
-
capabilities: {
|
|
1194
|
-
tools: Object.entries(toolSchemas).reduce(
|
|
1195
|
-
(acc, [name, { description, schema }]) => {
|
|
1196
|
-
acc[name] = {
|
|
1197
|
-
description,
|
|
1198
|
-
parameters: schema
|
|
1199
|
-
};
|
|
1200
|
-
return acc;
|
|
1201
|
-
},
|
|
1202
|
-
{}
|
|
1203
|
-
)
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
);
|
|
1207
|
-
transport = new StdioServerTransport();
|
|
1208
|
-
constructor({ logger, onReady }) {
|
|
1209
|
-
super({ logger, onReady });
|
|
1210
|
-
}
|
|
1211
|
-
async register(parser) {
|
|
1212
|
-
this.parser = parser;
|
|
1213
|
-
this.parser.addOnMessageCallback((message) => {
|
|
1214
|
-
handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
|
|
1215
|
-
});
|
|
1216
|
-
this.addWorkflows();
|
|
1217
|
-
await this.server.connect(this.transport);
|
|
1218
|
-
if (this.onReady) {
|
|
1219
|
-
this.onReady();
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
addWorkflows() {
|
|
1223
|
-
if (!this.parser) {
|
|
1224
|
-
return;
|
|
1225
|
-
}
|
|
1226
|
-
if (!this.server) {
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
this.server.setRequestHandler(z.object({ method: z.literal("tools/list") }), async () => {
|
|
1230
|
-
return {
|
|
1231
|
-
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
1232
|
-
name,
|
|
1233
|
-
description,
|
|
1234
|
-
inputSchema: schema
|
|
1235
|
-
}))
|
|
1236
|
-
};
|
|
1237
|
-
});
|
|
1238
|
-
this.server.setRequestHandler(
|
|
1239
|
-
z.object({
|
|
1240
|
-
method: z.literal("tools/call"),
|
|
1241
|
-
params: z.object({
|
|
1242
|
-
name: z.string(),
|
|
1243
|
-
arguments: z.any(),
|
|
1244
|
-
_meta: z.object({
|
|
1245
|
-
progressToken: z.number()
|
|
1246
|
-
}).optional()
|
|
1247
|
-
})
|
|
1248
|
-
}),
|
|
1249
|
-
async (request) => {
|
|
1250
|
-
const { name, arguments: args } = request.params;
|
|
1251
|
-
const toolHandlers = createToolHandlers(
|
|
1252
|
-
this.parser,
|
|
1253
|
-
this.verifiedOrders,
|
|
1254
|
-
this.pendingRequests,
|
|
1255
|
-
this.marketDataPrices
|
|
1256
|
-
);
|
|
1257
|
-
const handler = toolHandlers[name];
|
|
1258
|
-
if (!handler) {
|
|
1259
|
-
return {
|
|
1260
|
-
content: [
|
|
1261
|
-
{
|
|
1262
|
-
type: "text",
|
|
1263
|
-
text: `Tool not found: ${name}`,
|
|
1264
|
-
uri: name
|
|
1265
|
-
}
|
|
1266
|
-
],
|
|
1267
|
-
isError: true
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
const result = await handler(args);
|
|
578
|
+
]
|
|
579
|
+
})
|
|
580
|
+
);
|
|
581
|
+
this.server.resource(
|
|
582
|
+
"stockGraph",
|
|
583
|
+
new ResourceTemplate("stock://{symbol}", { list: void 0 }),
|
|
584
|
+
async (uri, variables) => {
|
|
585
|
+
const symbol = variables.symbol;
|
|
586
|
+
const data = [
|
|
587
|
+
{ time: "09:30", price: 150 },
|
|
588
|
+
{ time: "10:30", price: 152.5 },
|
|
589
|
+
{ time: "11:30", price: 151.75 },
|
|
590
|
+
{ time: "12:30", price: 153.25 },
|
|
591
|
+
{ time: "13:30", price: 154 },
|
|
592
|
+
{ time: "14:30", price: 153.5 },
|
|
593
|
+
{ time: "15:30", price: 155 },
|
|
594
|
+
{ time: "16:00", price: 154.75 }
|
|
595
|
+
];
|
|
596
|
+
const width = 600;
|
|
597
|
+
const height = 300;
|
|
598
|
+
const padding = 40;
|
|
599
|
+
const xScale = (width - 2 * padding) / (data.length - 1);
|
|
600
|
+
const yMin = Math.min(...data.map((d) => d.price));
|
|
601
|
+
const yMax = Math.max(...data.map((d) => d.price));
|
|
602
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
603
|
+
const points = data.map((d, i) => {
|
|
604
|
+
const x = padding + i * xScale;
|
|
605
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
606
|
+
return `${x},${y}`;
|
|
607
|
+
}).join(" L ");
|
|
608
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
609
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
610
|
+
<!-- Background -->
|
|
611
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
612
|
+
|
|
613
|
+
<!-- Grid lines -->
|
|
614
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
615
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
616
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
617
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
618
|
+
}).join("\n")}
|
|
619
|
+
</g>
|
|
620
|
+
|
|
621
|
+
<!-- Price line -->
|
|
622
|
+
<path d="M ${points}"
|
|
623
|
+
fill="none"
|
|
624
|
+
stroke="#007bff"
|
|
625
|
+
stroke-width="2"/>
|
|
626
|
+
|
|
627
|
+
<!-- Data points -->
|
|
628
|
+
${data.map((d, i) => {
|
|
629
|
+
const x = padding + i * xScale;
|
|
630
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
631
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
632
|
+
}).join("\n")}
|
|
633
|
+
|
|
634
|
+
<!-- Labels -->
|
|
635
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
636
|
+
${data.map((d, i) => {
|
|
637
|
+
const x = padding + i * xScale;
|
|
638
|
+
return `<text x="${x}" y="${height - padding + 20}" text-anchor="middle">${d.time}</text>`;
|
|
639
|
+
}).join("\n")}
|
|
640
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
641
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
642
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
643
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
644
|
+
}).join("\n")}
|
|
645
|
+
</g>
|
|
646
|
+
|
|
647
|
+
<!-- Title -->
|
|
648
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
649
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
650
|
+
text-anchor="middle" fill="#212529">
|
|
651
|
+
${symbol} - 1 Day Price Chart
|
|
652
|
+
</text>
|
|
653
|
+
</svg>`;
|
|
1271
654
|
return {
|
|
1272
|
-
|
|
1273
|
-
|
|
655
|
+
contents: [
|
|
656
|
+
{
|
|
657
|
+
uri: uri.href,
|
|
658
|
+
text: svg
|
|
659
|
+
}
|
|
660
|
+
]
|
|
1274
661
|
};
|
|
1275
662
|
}
|
|
1276
663
|
);
|