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