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