fixparser-plugin-mcp 9.1.7-525accda → 9.1.7-537ecaee
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 +768 -596
- package/build/cjs/MCPLocal.js.map +2 -2
- package/build/esm/MCPLocal.mjs +769 -612
- package/build/esm/MCPLocal.mjs.map +2 -2
- package/build-examples/cjs/example_mcp_local.js +49 -4
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +49 -4
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +7 -8
- package/types/MCPLocal.d.ts +3 -1
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,194 +1,237 @@
|
|
|
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 {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
MDEntryType,
|
|
16
|
-
Messages,
|
|
17
|
-
OrdType,
|
|
18
|
-
SubscriptionRequestType,
|
|
19
|
-
TimeInForce
|
|
20
|
-
} from "fixparser";
|
|
21
|
-
var parseInputSchema = {
|
|
22
|
-
type: "object",
|
|
23
|
-
properties: {
|
|
24
|
-
fixString: {
|
|
25
|
-
type: "string",
|
|
26
|
-
description: "FIX message string to parse"
|
|
4
|
+
import { Field, Fields, Messages } from "fixparser";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var toolSchemas = {
|
|
7
|
+
parse: {
|
|
8
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
9
|
+
schema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
fixString: { type: "string" }
|
|
13
|
+
},
|
|
14
|
+
required: ["fixString"]
|
|
27
15
|
}
|
|
28
16
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
parseToJSON: {
|
|
18
|
+
description: "Parses a FIX message into JSON",
|
|
19
|
+
schema: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
fixString: { type: "string" }
|
|
23
|
+
},
|
|
24
|
+
required: ["fixString"]
|
|
37
25
|
}
|
|
38
26
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
98
|
-
description: 'Order side (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Buy, "2" for Sell, "3" for BuyMinus, "4" for SellPlus, "5" for SellShort, "6" for SellShortExempt, "7" for Undisclosed, "8" for Cross, "9" for CrossShort, "A" for CrossShortExempt, "B" for AsDefined, "C" for Opposite, "D" for Subscribe, "E" for Redeem, "F" for Lend, "G" for Borrow, "H" for SellUndisclosed)'
|
|
99
|
-
},
|
|
100
|
-
symbol: {
|
|
101
|
-
type: "string",
|
|
102
|
-
description: "Trading symbol"
|
|
103
|
-
},
|
|
104
|
-
timeInForce: {
|
|
105
|
-
type: "string",
|
|
106
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
107
|
-
default: TimeInForce.Day,
|
|
108
|
-
description: 'Time in force (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Day, "1" for Good Till Cancel, "2" for At Opening, "3" for Immediate or Cancel, "4" for Fill or Kill, "5" for Good Till Crossing, "6" for Good Till Date)'
|
|
27
|
+
verifyOrder: {
|
|
28
|
+
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
29
|
+
schema: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
clOrdID: { type: "string" },
|
|
33
|
+
handlInst: {
|
|
34
|
+
type: "string",
|
|
35
|
+
enum: ["1", "2", "3"],
|
|
36
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
37
|
+
},
|
|
38
|
+
quantity: { type: "string" },
|
|
39
|
+
price: { type: "string" },
|
|
40
|
+
ordType: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: [
|
|
43
|
+
"1",
|
|
44
|
+
"2",
|
|
45
|
+
"3",
|
|
46
|
+
"4",
|
|
47
|
+
"5",
|
|
48
|
+
"6",
|
|
49
|
+
"7",
|
|
50
|
+
"8",
|
|
51
|
+
"9",
|
|
52
|
+
"A",
|
|
53
|
+
"B",
|
|
54
|
+
"C",
|
|
55
|
+
"D",
|
|
56
|
+
"E",
|
|
57
|
+
"F",
|
|
58
|
+
"G",
|
|
59
|
+
"H",
|
|
60
|
+
"I",
|
|
61
|
+
"J",
|
|
62
|
+
"K",
|
|
63
|
+
"L",
|
|
64
|
+
"M",
|
|
65
|
+
"P",
|
|
66
|
+
"Q",
|
|
67
|
+
"R",
|
|
68
|
+
"S"
|
|
69
|
+
],
|
|
70
|
+
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"
|
|
71
|
+
},
|
|
72
|
+
side: {
|
|
73
|
+
type: "string",
|
|
74
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
75
|
+
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"
|
|
76
|
+
},
|
|
77
|
+
symbol: { type: "string" },
|
|
78
|
+
timeInForce: {
|
|
79
|
+
type: "string",
|
|
80
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
81
|
+
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"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
109
85
|
}
|
|
110
86
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"
|
|
182
|
-
"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
87
|
+
executeOrder: {
|
|
88
|
+
description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
|
|
89
|
+
schema: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
clOrdID: { type: "string" },
|
|
93
|
+
handlInst: {
|
|
94
|
+
type: "string",
|
|
95
|
+
enum: ["1", "2", "3"],
|
|
96
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
97
|
+
},
|
|
98
|
+
quantity: { type: "string" },
|
|
99
|
+
price: { type: "string" },
|
|
100
|
+
ordType: {
|
|
101
|
+
type: "string",
|
|
102
|
+
enum: [
|
|
103
|
+
"1",
|
|
104
|
+
"2",
|
|
105
|
+
"3",
|
|
106
|
+
"4",
|
|
107
|
+
"5",
|
|
108
|
+
"6",
|
|
109
|
+
"7",
|
|
110
|
+
"8",
|
|
111
|
+
"9",
|
|
112
|
+
"A",
|
|
113
|
+
"B",
|
|
114
|
+
"C",
|
|
115
|
+
"D",
|
|
116
|
+
"E",
|
|
117
|
+
"F",
|
|
118
|
+
"G",
|
|
119
|
+
"H",
|
|
120
|
+
"I",
|
|
121
|
+
"J",
|
|
122
|
+
"K",
|
|
123
|
+
"L",
|
|
124
|
+
"M",
|
|
125
|
+
"P",
|
|
126
|
+
"Q",
|
|
127
|
+
"R",
|
|
128
|
+
"S"
|
|
129
|
+
],
|
|
130
|
+
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"
|
|
131
|
+
},
|
|
132
|
+
side: {
|
|
133
|
+
type: "string",
|
|
134
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
135
|
+
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"
|
|
136
|
+
},
|
|
137
|
+
symbol: { type: "string" },
|
|
138
|
+
timeInForce: {
|
|
139
|
+
type: "string",
|
|
140
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
141
|
+
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"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
marketDataRequest: {
|
|
148
|
+
description: "Requests market data for specified symbols",
|
|
149
|
+
schema: {
|
|
150
|
+
type: "object",
|
|
151
|
+
properties: {
|
|
152
|
+
mdUpdateType: {
|
|
153
|
+
type: "string",
|
|
154
|
+
enum: ["0", "1"],
|
|
155
|
+
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
156
|
+
},
|
|
157
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
158
|
+
mdReqID: { type: "string" },
|
|
159
|
+
subscriptionRequestType: {
|
|
160
|
+
type: "string",
|
|
161
|
+
enum: ["0", "1", "2"],
|
|
162
|
+
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
163
|
+
},
|
|
164
|
+
mdEntryTypes: {
|
|
165
|
+
type: "array",
|
|
166
|
+
items: {
|
|
167
|
+
type: "string",
|
|
168
|
+
enum: [
|
|
169
|
+
"0",
|
|
170
|
+
"1",
|
|
171
|
+
"2",
|
|
172
|
+
"3",
|
|
173
|
+
"4",
|
|
174
|
+
"5",
|
|
175
|
+
"6",
|
|
176
|
+
"7",
|
|
177
|
+
"8",
|
|
178
|
+
"9",
|
|
179
|
+
"A",
|
|
180
|
+
"B",
|
|
181
|
+
"C",
|
|
182
|
+
"D",
|
|
183
|
+
"E",
|
|
184
|
+
"F",
|
|
185
|
+
"G",
|
|
186
|
+
"H",
|
|
187
|
+
"I",
|
|
188
|
+
"J",
|
|
189
|
+
"K",
|
|
190
|
+
"L",
|
|
191
|
+
"M",
|
|
192
|
+
"N",
|
|
193
|
+
"O",
|
|
194
|
+
"P",
|
|
195
|
+
"Q",
|
|
196
|
+
"R",
|
|
197
|
+
"S",
|
|
198
|
+
"T",
|
|
199
|
+
"U",
|
|
200
|
+
"V",
|
|
201
|
+
"W",
|
|
202
|
+
"X",
|
|
203
|
+
"Y",
|
|
204
|
+
"Z"
|
|
205
|
+
],
|
|
206
|
+
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"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
getStockGraph: {
|
|
214
|
+
description: "Generates a price chart for a given symbol",
|
|
215
|
+
schema: {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: {
|
|
218
|
+
symbol: { type: "string" }
|
|
219
|
+
},
|
|
220
|
+
required: ["symbol"]
|
|
186
221
|
}
|
|
187
222
|
},
|
|
188
|
-
|
|
223
|
+
getStockPriceHistory: {
|
|
224
|
+
description: "Returns price history for a given symbol",
|
|
225
|
+
schema: {
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: {
|
|
228
|
+
symbol: { type: "string" }
|
|
229
|
+
},
|
|
230
|
+
required: ["symbol"]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
189
233
|
};
|
|
190
234
|
var MCPLocal = class {
|
|
191
|
-
logger;
|
|
192
235
|
parser;
|
|
193
236
|
server = new Server(
|
|
194
237
|
{
|
|
@@ -197,38 +240,89 @@ var MCPLocal = class {
|
|
|
197
240
|
},
|
|
198
241
|
{
|
|
199
242
|
capabilities: {
|
|
200
|
-
tools:
|
|
201
|
-
|
|
202
|
-
|
|
243
|
+
tools: Object.entries(toolSchemas).reduce(
|
|
244
|
+
(acc, [name, { description, schema }]) => {
|
|
245
|
+
acc[name] = {
|
|
246
|
+
description,
|
|
247
|
+
parameters: schema
|
|
248
|
+
};
|
|
249
|
+
return acc;
|
|
250
|
+
},
|
|
251
|
+
{}
|
|
252
|
+
)
|
|
203
253
|
}
|
|
204
254
|
}
|
|
205
255
|
);
|
|
206
256
|
transport = new StdioServerTransport();
|
|
207
257
|
onReady = void 0;
|
|
208
258
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
259
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
260
|
+
// Store market data prices with timestamps
|
|
261
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
262
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
263
|
+
// Maximum number of price points to store per symbol
|
|
209
264
|
constructor({ logger, onReady }) {
|
|
210
|
-
if (logger && !logger.silent) {
|
|
211
|
-
this.logger = logger;
|
|
212
|
-
}
|
|
213
265
|
if (onReady) this.onReady = onReady;
|
|
214
266
|
}
|
|
215
267
|
async register(parser) {
|
|
216
268
|
this.parser = parser;
|
|
217
|
-
if (parser.logger && !parser.logger.silent) {
|
|
218
|
-
this.logger = parser.logger;
|
|
219
|
-
}
|
|
220
269
|
this.parser.addOnMessageCallback((message) => {
|
|
270
|
+
this.parser?.logger.log({
|
|
271
|
+
level: "info",
|
|
272
|
+
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
273
|
+
});
|
|
221
274
|
const msgType = message.messageType;
|
|
222
|
-
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
275
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject || msgType === Messages.MarketDataIncrementalRefresh) {
|
|
276
|
+
this.parser?.logger.log({
|
|
277
|
+
level: "info",
|
|
278
|
+
message: `MCP Server handling message type: ${msgType}`
|
|
279
|
+
});
|
|
280
|
+
let id;
|
|
281
|
+
if (msgType === Messages.MarketDataIncrementalRefresh || msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
282
|
+
const symbol = message.getField(Fields.Symbol);
|
|
283
|
+
const price = message.getField(Fields.MDEntryPx);
|
|
284
|
+
const timestamp = message.getField(Fields.MDEntryTime)?.value || Date.now();
|
|
285
|
+
if (symbol?.value && price?.value) {
|
|
286
|
+
const symbolStr = String(symbol.value);
|
|
287
|
+
const priceNum = Number(price.value);
|
|
288
|
+
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
289
|
+
priceHistory.push({
|
|
290
|
+
timestamp: Number(timestamp),
|
|
291
|
+
price: priceNum
|
|
292
|
+
});
|
|
293
|
+
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
294
|
+
priceHistory.shift();
|
|
231
295
|
}
|
|
296
|
+
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
297
|
+
this.parser?.logger.log({
|
|
298
|
+
level: "info",
|
|
299
|
+
message: `MCP Server added ${symbol}: ${priceNum}`
|
|
300
|
+
});
|
|
301
|
+
this.server.notification({
|
|
302
|
+
method: "priceUpdate",
|
|
303
|
+
params: {
|
|
304
|
+
symbol: symbolStr,
|
|
305
|
+
price: priceNum,
|
|
306
|
+
timestamp: Number(timestamp)
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
312
|
+
const mdReqID = message.getField(Fields.MDReqID);
|
|
313
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
314
|
+
} else if (msgType === Messages.ExecutionReport) {
|
|
315
|
+
const clOrdID = message.getField(Fields.ClOrdID);
|
|
316
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
317
|
+
} else if (msgType === Messages.Reject) {
|
|
318
|
+
const refSeqNum = message.getField(Fields.RefSeqNum);
|
|
319
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
320
|
+
}
|
|
321
|
+
if (id) {
|
|
322
|
+
const callback = this.pendingRequests.get(id);
|
|
323
|
+
if (callback) {
|
|
324
|
+
callback(message);
|
|
325
|
+
this.pendingRequests.delete(id);
|
|
232
326
|
}
|
|
233
327
|
}
|
|
234
328
|
}
|
|
@@ -241,460 +335,523 @@ var MCPLocal = class {
|
|
|
241
335
|
}
|
|
242
336
|
addWorkflows() {
|
|
243
337
|
if (!this.parser) {
|
|
244
|
-
this.logger?.log({
|
|
245
|
-
level: "error",
|
|
246
|
-
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
|
|
247
|
-
});
|
|
248
338
|
return;
|
|
249
339
|
}
|
|
250
340
|
if (!this.server) {
|
|
251
|
-
this.logger?.log({
|
|
252
|
-
level: "error",
|
|
253
|
-
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
|
|
254
|
-
});
|
|
255
341
|
return;
|
|
256
342
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
} else if (prop.default !== void 0) {
|
|
268
|
-
result[key] = prop.default;
|
|
269
|
-
}
|
|
343
|
+
this.server.setRequestHandler(
|
|
344
|
+
z.object({ method: z.literal("tools/list") }),
|
|
345
|
+
async (request, extra) => {
|
|
346
|
+
return {
|
|
347
|
+
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
348
|
+
name,
|
|
349
|
+
description,
|
|
350
|
+
inputSchema: schema
|
|
351
|
+
}))
|
|
352
|
+
};
|
|
270
353
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
]
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
305
|
-
const { name, arguments: args } = request.params;
|
|
306
|
-
switch (name) {
|
|
307
|
-
case "parse": {
|
|
308
|
-
try {
|
|
309
|
-
const { fixString } = validateArgs(args, parseInputSchema);
|
|
310
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
311
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
354
|
+
);
|
|
355
|
+
this.server.setRequestHandler(
|
|
356
|
+
z.object({
|
|
357
|
+
method: z.literal("tools/call"),
|
|
358
|
+
params: z.object({
|
|
359
|
+
name: z.string(),
|
|
360
|
+
arguments: z.any(),
|
|
361
|
+
_meta: z.object({
|
|
362
|
+
progressToken: z.number()
|
|
363
|
+
}).optional()
|
|
364
|
+
})
|
|
365
|
+
}),
|
|
366
|
+
async (request, extra) => {
|
|
367
|
+
const { name, arguments: args } = request.params;
|
|
368
|
+
switch (name) {
|
|
369
|
+
case "parse":
|
|
370
|
+
try {
|
|
371
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
372
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
373
|
+
return {
|
|
374
|
+
content: [
|
|
375
|
+
{
|
|
376
|
+
type: "text",
|
|
377
|
+
text: "Error: Failed to parse FIX string",
|
|
378
|
+
uri: "parse"
|
|
379
|
+
}
|
|
380
|
+
],
|
|
381
|
+
isError: true
|
|
382
|
+
};
|
|
383
|
+
}
|
|
312
384
|
return {
|
|
313
|
-
|
|
314
|
-
|
|
385
|
+
content: [
|
|
386
|
+
{
|
|
387
|
+
type: "text",
|
|
388
|
+
text: `${parsedMessage[0].description}
|
|
389
|
+
${parsedMessage[0].messageTypeDescription}`,
|
|
390
|
+
uri: "parse"
|
|
391
|
+
}
|
|
392
|
+
]
|
|
315
393
|
};
|
|
316
|
-
}
|
|
317
|
-
return {
|
|
318
|
-
content: [
|
|
319
|
-
{
|
|
320
|
-
type: "text",
|
|
321
|
-
text: `${parsedMessage[0].description}
|
|
322
|
-
${parsedMessage[0].messageTypeDescription}`
|
|
323
|
-
}
|
|
324
|
-
]
|
|
325
|
-
};
|
|
326
|
-
} catch (error) {
|
|
327
|
-
return {
|
|
328
|
-
isError: true,
|
|
329
|
-
content: [
|
|
330
|
-
{
|
|
331
|
-
type: "text",
|
|
332
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
333
|
-
}
|
|
334
|
-
]
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
case "parseToJSON": {
|
|
339
|
-
try {
|
|
340
|
-
const { fixString } = validateArgs(args, parseToJSONInputSchema);
|
|
341
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
342
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
394
|
+
} catch (error) {
|
|
343
395
|
return {
|
|
344
|
-
|
|
345
|
-
|
|
396
|
+
content: [
|
|
397
|
+
{
|
|
398
|
+
type: "text",
|
|
399
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
400
|
+
uri: "parse"
|
|
401
|
+
}
|
|
402
|
+
],
|
|
403
|
+
isError: true
|
|
346
404
|
};
|
|
347
405
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
]
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
case "newOrderSingle": {
|
|
369
|
-
try {
|
|
370
|
-
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
|
|
371
|
-
const response = new Promise((resolve) => {
|
|
372
|
-
this.pendingRequests.set(clOrdID, resolve);
|
|
373
|
-
});
|
|
374
|
-
const order = this.parser?.createMessage(
|
|
375
|
-
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
376
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
377
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
378
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
379
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
380
|
-
new Field(Fields.ClOrdID, clOrdID),
|
|
381
|
-
new Field(Fields.Side, side),
|
|
382
|
-
new Field(Fields.Symbol, symbol),
|
|
383
|
-
new Field(Fields.OrderQty, quantity),
|
|
384
|
-
new Field(Fields.Price, price),
|
|
385
|
-
new Field(Fields.OrdType, ordType),
|
|
386
|
-
new Field(Fields.HandlInst, handlInst),
|
|
387
|
-
new Field(Fields.TimeInForce, timeInForce),
|
|
388
|
-
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
389
|
-
);
|
|
390
|
-
if (!this.parser?.connected) {
|
|
391
|
-
this.logger?.log({
|
|
392
|
-
level: "error",
|
|
393
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
394
|
-
});
|
|
406
|
+
case "parseToJSON":
|
|
407
|
+
try {
|
|
408
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
409
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
410
|
+
return {
|
|
411
|
+
content: [
|
|
412
|
+
{
|
|
413
|
+
type: "text",
|
|
414
|
+
text: "Error: Failed to parse FIX string",
|
|
415
|
+
uri: "parseToJSON"
|
|
416
|
+
}
|
|
417
|
+
],
|
|
418
|
+
isError: true
|
|
419
|
+
};
|
|
420
|
+
}
|
|
395
421
|
return {
|
|
396
|
-
isError: true,
|
|
397
422
|
content: [
|
|
398
423
|
{
|
|
399
424
|
type: "text",
|
|
400
|
-
text:
|
|
425
|
+
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
426
|
+
uri: "parseToJSON"
|
|
401
427
|
}
|
|
402
428
|
]
|
|
403
429
|
};
|
|
430
|
+
} catch (error) {
|
|
431
|
+
return {
|
|
432
|
+
content: [
|
|
433
|
+
{
|
|
434
|
+
type: "text",
|
|
435
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
436
|
+
uri: "parseToJSON"
|
|
437
|
+
}
|
|
438
|
+
],
|
|
439
|
+
isError: true
|
|
440
|
+
};
|
|
404
441
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
]
|
|
418
|
-
};
|
|
419
|
-
} catch (error) {
|
|
420
|
-
return {
|
|
421
|
-
isError: true,
|
|
422
|
-
content: [
|
|
423
|
-
{
|
|
424
|
-
type: "text",
|
|
425
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
|
|
426
|
-
}
|
|
427
|
-
]
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
case "marketDataRequest": {
|
|
432
|
-
try {
|
|
433
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
|
|
434
|
-
args,
|
|
435
|
-
marketDataRequestInputSchema
|
|
436
|
-
);
|
|
437
|
-
const response = new Promise((resolve) => {
|
|
438
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
439
|
-
});
|
|
440
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
441
|
-
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
442
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
443
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
444
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
445
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
446
|
-
new Field(Fields.MarketDepth, 0),
|
|
447
|
-
new Field(Fields.MDUpdateType, mdUpdateType),
|
|
448
|
-
new Field(Fields.NoRelatedSym, 1),
|
|
449
|
-
new Field(Fields.Symbol, symbol),
|
|
450
|
-
new Field(Fields.MDReqID, mdReqID),
|
|
451
|
-
new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
452
|
-
new Field(Fields.NoMDEntryTypes, 1),
|
|
453
|
-
new Field(Fields.MDEntryType, mdEntryType)
|
|
454
|
-
);
|
|
455
|
-
if (!this.parser?.connected) {
|
|
456
|
-
this.logger?.log({
|
|
457
|
-
level: "error",
|
|
458
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
442
|
+
case "verifyOrder":
|
|
443
|
+
try {
|
|
444
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
445
|
+
clOrdID: args.clOrdID,
|
|
446
|
+
handlInst: args.handlInst,
|
|
447
|
+
quantity: Number.parseFloat(args.quantity),
|
|
448
|
+
price: Number.parseFloat(args.price),
|
|
449
|
+
ordType: args.ordType,
|
|
450
|
+
side: args.side,
|
|
451
|
+
symbol: args.symbol,
|
|
452
|
+
timeInForce: args.timeInForce
|
|
459
453
|
});
|
|
454
|
+
const ordTypeNames = {
|
|
455
|
+
"1": "Market",
|
|
456
|
+
"2": "Limit",
|
|
457
|
+
"3": "Stop",
|
|
458
|
+
"4": "StopLimit",
|
|
459
|
+
"5": "MarketOnClose",
|
|
460
|
+
"6": "WithOrWithout",
|
|
461
|
+
"7": "LimitOrBetter",
|
|
462
|
+
"8": "LimitWithOrWithout",
|
|
463
|
+
"9": "OnBasis",
|
|
464
|
+
A: "OnClose",
|
|
465
|
+
B: "LimitOnClose",
|
|
466
|
+
C: "ForexMarket",
|
|
467
|
+
D: "PreviouslyQuoted",
|
|
468
|
+
E: "PreviouslyIndicated",
|
|
469
|
+
F: "ForexLimit",
|
|
470
|
+
G: "ForexSwap",
|
|
471
|
+
H: "ForexPreviouslyQuoted",
|
|
472
|
+
I: "Funari",
|
|
473
|
+
J: "MarketIfTouched",
|
|
474
|
+
K: "MarketWithLeftOverAsLimit",
|
|
475
|
+
L: "PreviousFundValuationPoint",
|
|
476
|
+
M: "NextFundValuationPoint",
|
|
477
|
+
P: "Pegged",
|
|
478
|
+
Q: "CounterOrderSelection",
|
|
479
|
+
R: "StopOnBidOrOffer",
|
|
480
|
+
S: "StopLimitOnBidOrOffer"
|
|
481
|
+
};
|
|
482
|
+
const sideNames = {
|
|
483
|
+
"1": "Buy",
|
|
484
|
+
"2": "Sell",
|
|
485
|
+
"3": "BuyMinus",
|
|
486
|
+
"4": "SellPlus",
|
|
487
|
+
"5": "SellShort",
|
|
488
|
+
"6": "SellShortExempt",
|
|
489
|
+
"7": "Undisclosed",
|
|
490
|
+
"8": "Cross",
|
|
491
|
+
"9": "CrossShort",
|
|
492
|
+
A: "CrossShortExempt",
|
|
493
|
+
B: "AsDefined",
|
|
494
|
+
C: "Opposite",
|
|
495
|
+
D: "Subscribe",
|
|
496
|
+
E: "Redeem",
|
|
497
|
+
F: "Lend",
|
|
498
|
+
G: "Borrow",
|
|
499
|
+
H: "SellUndisclosed"
|
|
500
|
+
};
|
|
501
|
+
const timeInForceNames = {
|
|
502
|
+
"0": "Day",
|
|
503
|
+
"1": "GoodTillCancel",
|
|
504
|
+
"2": "AtTheOpening",
|
|
505
|
+
"3": "ImmediateOrCancel",
|
|
506
|
+
"4": "FillOrKill",
|
|
507
|
+
"5": "GoodTillCrossing",
|
|
508
|
+
"6": "GoodTillDate",
|
|
509
|
+
"7": "AtTheClose",
|
|
510
|
+
"8": "GoodThroughCrossing",
|
|
511
|
+
"9": "AtCrossing",
|
|
512
|
+
A: "GoodForTime",
|
|
513
|
+
B: "GoodForAuction",
|
|
514
|
+
C: "GoodForMonth"
|
|
515
|
+
};
|
|
516
|
+
const handlInstNames = {
|
|
517
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
518
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
519
|
+
"3": "ManualOrder"
|
|
520
|
+
};
|
|
460
521
|
return {
|
|
461
|
-
isError: true,
|
|
462
522
|
content: [
|
|
463
523
|
{
|
|
464
524
|
type: "text",
|
|
465
|
-
text:
|
|
525
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
526
|
+
|
|
527
|
+
Parameters verified:
|
|
528
|
+
- ClOrdID: ${args.clOrdID}
|
|
529
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
530
|
+
- Quantity: ${args.quantity}
|
|
531
|
+
- Price: ${args.price}
|
|
532
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
533
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
534
|
+
- Symbol: ${args.symbol}
|
|
535
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
536
|
+
|
|
537
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
538
|
+
uri: "verifyOrder"
|
|
466
539
|
}
|
|
467
540
|
]
|
|
468
541
|
};
|
|
542
|
+
} catch (error) {
|
|
543
|
+
return {
|
|
544
|
+
content: [
|
|
545
|
+
{
|
|
546
|
+
type: "text",
|
|
547
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
548
|
+
uri: "verifyOrder"
|
|
549
|
+
}
|
|
550
|
+
],
|
|
551
|
+
isError: true
|
|
552
|
+
};
|
|
469
553
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
} catch (error) {
|
|
485
|
-
return {
|
|
486
|
-
isError: true,
|
|
487
|
-
content: [
|
|
488
|
-
{
|
|
489
|
-
type: "text",
|
|
490
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
491
|
-
}
|
|
492
|
-
]
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
default:
|
|
497
|
-
throw new Error(`Unknown tool: ${name}`);
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
this.server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
501
|
-
return {
|
|
502
|
-
prompts: [
|
|
503
|
-
{
|
|
504
|
-
name: "parse",
|
|
505
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
506
|
-
arguments: [
|
|
507
|
-
{
|
|
508
|
-
name: "fixString",
|
|
509
|
-
description: "FIX message string to parse",
|
|
510
|
-
required: true
|
|
554
|
+
case "executeOrder":
|
|
555
|
+
try {
|
|
556
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
557
|
+
if (!verifiedOrder) {
|
|
558
|
+
return {
|
|
559
|
+
content: [
|
|
560
|
+
{
|
|
561
|
+
type: "text",
|
|
562
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
563
|
+
uri: "executeOrder"
|
|
564
|
+
}
|
|
565
|
+
],
|
|
566
|
+
isError: true
|
|
567
|
+
};
|
|
511
568
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
569
|
+
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) {
|
|
570
|
+
return {
|
|
571
|
+
content: [
|
|
572
|
+
{
|
|
573
|
+
type: "text",
|
|
574
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
575
|
+
uri: "executeOrder"
|
|
576
|
+
}
|
|
577
|
+
],
|
|
578
|
+
isError: true
|
|
579
|
+
};
|
|
522
580
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
name: "side",
|
|
556
|
-
description: "Order side (1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed)",
|
|
557
|
-
required: true
|
|
558
|
-
},
|
|
559
|
-
{
|
|
560
|
-
name: "symbol",
|
|
561
|
-
description: "Trading symbol",
|
|
562
|
-
required: true
|
|
563
|
-
},
|
|
564
|
-
{
|
|
565
|
-
name: "timeInForce",
|
|
566
|
-
description: "Time in force",
|
|
567
|
-
required: false
|
|
568
|
-
}
|
|
569
|
-
]
|
|
570
|
-
},
|
|
571
|
-
{
|
|
572
|
-
name: "marketDataRequest",
|
|
573
|
-
description: "Sends a request for Market Data with the given symbol",
|
|
574
|
-
arguments: [
|
|
575
|
-
{
|
|
576
|
-
name: "mdUpdateType",
|
|
577
|
-
description: "Market data update type",
|
|
578
|
-
required: false
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
name: "symbol",
|
|
582
|
-
description: "Trading symbol",
|
|
583
|
-
required: true
|
|
584
|
-
},
|
|
585
|
-
{
|
|
586
|
-
name: "mdReqID",
|
|
587
|
-
description: "Market data request ID",
|
|
588
|
-
required: true
|
|
589
|
-
},
|
|
590
|
-
{
|
|
591
|
-
name: "subscriptionRequestType",
|
|
592
|
-
description: "Subscription request type",
|
|
593
|
-
required: false
|
|
594
|
-
},
|
|
595
|
-
{
|
|
596
|
-
name: "mdEntryType",
|
|
597
|
-
description: "Market data entry type",
|
|
598
|
-
required: false
|
|
581
|
+
const response = new Promise((resolve) => {
|
|
582
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
583
|
+
});
|
|
584
|
+
const order = this.parser?.createMessage(
|
|
585
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
586
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
587
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
588
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
589
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
590
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
591
|
+
new Field(Fields.Side, args.side),
|
|
592
|
+
new Field(Fields.Symbol, args.symbol),
|
|
593
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
594
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
595
|
+
new Field(Fields.OrdType, args.ordType),
|
|
596
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
597
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
598
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
599
|
+
);
|
|
600
|
+
if (!this.parser?.connected) {
|
|
601
|
+
return {
|
|
602
|
+
content: [
|
|
603
|
+
{
|
|
604
|
+
type: "text",
|
|
605
|
+
text: "Error: Not connected. Ignoring message.",
|
|
606
|
+
uri: "executeOrder"
|
|
607
|
+
}
|
|
608
|
+
],
|
|
609
|
+
isError: true
|
|
610
|
+
};
|
|
599
611
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
content:
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
612
|
+
this.parser?.send(order);
|
|
613
|
+
const fixData = await response;
|
|
614
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
615
|
+
return {
|
|
616
|
+
content: [
|
|
617
|
+
{
|
|
618
|
+
type: "text",
|
|
619
|
+
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())}`,
|
|
620
|
+
uri: "executeOrder"
|
|
621
|
+
}
|
|
622
|
+
]
|
|
623
|
+
};
|
|
624
|
+
} catch (error) {
|
|
625
|
+
return {
|
|
626
|
+
content: [
|
|
627
|
+
{
|
|
628
|
+
type: "text",
|
|
629
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
630
|
+
uri: "executeOrder"
|
|
631
|
+
}
|
|
632
|
+
],
|
|
633
|
+
isError: true
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
case "marketDataRequest":
|
|
637
|
+
try {
|
|
638
|
+
const response = new Promise((resolve) => {
|
|
639
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
640
|
+
});
|
|
641
|
+
const messageFields = [
|
|
642
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
643
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
644
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
645
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
646
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
647
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
648
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
649
|
+
new Field(Fields.MarketDepth, 0),
|
|
650
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
651
|
+
];
|
|
652
|
+
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
653
|
+
args.symbols.forEach((symbol) => {
|
|
654
|
+
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
655
|
+
});
|
|
656
|
+
messageFields.push(new Field(Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
657
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
658
|
+
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
659
|
+
});
|
|
660
|
+
const mdr = this.parser?.createMessage(...messageFields);
|
|
661
|
+
if (!this.parser?.connected) {
|
|
662
|
+
return {
|
|
663
|
+
content: [
|
|
664
|
+
{
|
|
665
|
+
type: "text",
|
|
666
|
+
text: "Error: Not connected. Ignoring message.",
|
|
667
|
+
uri: "marketDataRequest"
|
|
668
|
+
}
|
|
669
|
+
],
|
|
670
|
+
isError: true
|
|
671
|
+
};
|
|
618
672
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
673
|
+
this.parser?.send(mdr);
|
|
674
|
+
const fixData = await response;
|
|
675
|
+
return {
|
|
676
|
+
content: [
|
|
677
|
+
{
|
|
678
|
+
type: "text",
|
|
679
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
680
|
+
uri: "marketDataRequest"
|
|
681
|
+
}
|
|
682
|
+
]
|
|
683
|
+
};
|
|
684
|
+
} catch (error) {
|
|
685
|
+
return {
|
|
686
|
+
content: [
|
|
687
|
+
{
|
|
688
|
+
type: "text",
|
|
689
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
690
|
+
uri: "marketDataRequest"
|
|
691
|
+
}
|
|
692
|
+
],
|
|
693
|
+
isError: true
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
case "getStockGraph":
|
|
697
|
+
try {
|
|
698
|
+
const symbol = args.symbol;
|
|
699
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
700
|
+
if (priceHistory.length === 0) {
|
|
701
|
+
return {
|
|
702
|
+
content: [
|
|
703
|
+
{
|
|
704
|
+
type: "text",
|
|
705
|
+
text: `No price data available for ${symbol}`,
|
|
706
|
+
uri: "getStockGraph"
|
|
707
|
+
}
|
|
708
|
+
]
|
|
709
|
+
};
|
|
632
710
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
{
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
711
|
+
const width = 600;
|
|
712
|
+
const height = 300;
|
|
713
|
+
const padding = 40;
|
|
714
|
+
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
715
|
+
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
716
|
+
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
717
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
718
|
+
const points = priceHistory.map((d, i) => {
|
|
719
|
+
const x = padding + i * xScale;
|
|
720
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
721
|
+
return `${x},${y}`;
|
|
722
|
+
}).join(" L ");
|
|
723
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
724
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
725
|
+
<!-- Background -->
|
|
726
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
727
|
+
|
|
728
|
+
<!-- Grid lines -->
|
|
729
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
730
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
731
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
732
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
733
|
+
}).join("\n")}
|
|
734
|
+
</g>
|
|
735
|
+
|
|
736
|
+
<!-- Price line -->
|
|
737
|
+
<path d="M ${points}"
|
|
738
|
+
fill="none"
|
|
739
|
+
stroke="#007bff"
|
|
740
|
+
stroke-width="2"/>
|
|
741
|
+
|
|
742
|
+
<!-- Data points -->
|
|
743
|
+
${priceHistory.map((d, i) => {
|
|
744
|
+
const x = padding + i * xScale;
|
|
745
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
746
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
747
|
+
}).join("\n")}
|
|
748
|
+
|
|
749
|
+
<!-- Labels -->
|
|
750
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
751
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
752
|
+
const x = padding + (width - 2 * padding) * i / 4;
|
|
753
|
+
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
754
|
+
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
755
|
+
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
756
|
+
}).join("\n")}
|
|
757
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
758
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
759
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
760
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
761
|
+
}).join("\n")}
|
|
762
|
+
</g>
|
|
763
|
+
|
|
764
|
+
<!-- Title -->
|
|
765
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
766
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
767
|
+
text-anchor="middle" fill="#212529">
|
|
768
|
+
${symbol} - Price Chart (${priceHistory.length} points)
|
|
769
|
+
</text>
|
|
770
|
+
</svg>`;
|
|
771
|
+
const base64Svg = Buffer.from(svg).toString("base64");
|
|
772
|
+
return {
|
|
773
|
+
content: [
|
|
774
|
+
{
|
|
775
|
+
type: "image",
|
|
776
|
+
text: base64Svg,
|
|
777
|
+
uri: "getStockGraph",
|
|
778
|
+
mimeType: "image/svg+xml"
|
|
779
|
+
}
|
|
780
|
+
]
|
|
781
|
+
};
|
|
782
|
+
} catch (error) {
|
|
783
|
+
return {
|
|
784
|
+
content: [
|
|
785
|
+
{
|
|
786
|
+
type: "text",
|
|
787
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to generate stock graph"}`,
|
|
788
|
+
uri: "getStockGraph"
|
|
789
|
+
}
|
|
790
|
+
],
|
|
791
|
+
isError: true
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
case "getStockPriceHistory":
|
|
795
|
+
try {
|
|
796
|
+
const symbol = args.symbol;
|
|
797
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
798
|
+
if (priceHistory.length === 0) {
|
|
799
|
+
return {
|
|
800
|
+
content: [
|
|
801
|
+
{
|
|
802
|
+
type: "text",
|
|
803
|
+
text: `No price data available for ${symbol}`,
|
|
804
|
+
uri: "getStockPriceHistory"
|
|
805
|
+
}
|
|
806
|
+
]
|
|
807
|
+
};
|
|
663
808
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
809
|
+
return {
|
|
810
|
+
content: [
|
|
811
|
+
{
|
|
812
|
+
type: "text",
|
|
813
|
+
text: JSON.stringify(
|
|
814
|
+
{
|
|
815
|
+
symbol,
|
|
816
|
+
count: priceHistory.length,
|
|
817
|
+
prices: priceHistory.map((point) => ({
|
|
818
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
819
|
+
price: point.price
|
|
820
|
+
}))
|
|
821
|
+
},
|
|
822
|
+
null,
|
|
823
|
+
2
|
|
824
|
+
),
|
|
825
|
+
uri: "getStockPriceHistory"
|
|
826
|
+
}
|
|
827
|
+
]
|
|
828
|
+
};
|
|
829
|
+
} catch (error) {
|
|
830
|
+
return {
|
|
831
|
+
content: [
|
|
832
|
+
{
|
|
833
|
+
type: "text",
|
|
834
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
835
|
+
uri: "getStockPriceHistory"
|
|
836
|
+
}
|
|
837
|
+
],
|
|
838
|
+
isError: true
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
default:
|
|
842
|
+
return {
|
|
843
|
+
content: [
|
|
844
|
+
{
|
|
674
845
|
type: "text",
|
|
675
|
-
text:
|
|
676
|
-
|
|
677
|
-
`- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
|
|
678
|
-
`- Symbol: ${symbol}`,
|
|
679
|
-
`- MDReqID: ${mdReqID}`,
|
|
680
|
-
`- SubscriptionRequestType: ${subscriptionRequestType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Snapshot + Updates, '1' for Snapshot, '2' for Unsubscribe)`,
|
|
681
|
-
`- MDEntryType: ${mdEntryType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Bid, '1' for Offer, '2' for Trade, '3' for Index Value, '4' for Opening Price)`,
|
|
682
|
-
"",
|
|
683
|
-
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
684
|
-
"",
|
|
685
|
-
'Note: For the MDUpdateType parameter, always use the numeric/alphabetic value (e.g., "0" for FullRefresh, "1" for IncrementalRefresh) as defined in the FIX protocol, not the descriptive name.',
|
|
686
|
-
'Note: For the SubscriptionRequestType parameter, always use the numeric/alphabetic value (e.g., "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe) as defined in the FIX protocol, not the descriptive name.',
|
|
687
|
-
'Note: For the MDEntryType parameter, always use the numeric/alphabetic value (e.g., "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price) as defined in the FIX protocol, not the descriptive name.'
|
|
688
|
-
].join("\n")
|
|
846
|
+
text: `Tool not found: ${name}`,
|
|
847
|
+
uri: name
|
|
689
848
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
849
|
+
],
|
|
850
|
+
isError: true
|
|
851
|
+
};
|
|
693
852
|
}
|
|
694
|
-
default:
|
|
695
|
-
throw new Error(`Unknown prompt: ${name}`);
|
|
696
853
|
}
|
|
697
|
-
|
|
854
|
+
);
|
|
698
855
|
process.on("SIGINT", async () => {
|
|
699
856
|
await this.server.close();
|
|
700
857
|
process.exit(0);
|