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