fixparser-plugin-mcp 9.1.7-33c7782a → 9.1.7-38cee007
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 +1555 -627
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/cjs/MCPRemote.js +1618 -435
- package/build/cjs/MCPRemote.js.map +4 -4
- package/build/cjs/index.js +1917 -0
- package/build/cjs/index.js.map +7 -0
- package/build/esm/MCPLocal.mjs +1545 -642
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build/esm/MCPRemote.mjs +1608 -444
- package/build/esm/MCPRemote.mjs.map +4 -4
- package/build/esm/index.mjs +1879 -0
- package/build/esm/index.mjs.map +7 -0
- package/build-examples/cjs/example_mcp_local.js +16 -4
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/cjs/example_mcp_remote.js +18 -0
- package/build-examples/cjs/example_mcp_remote.js.map +7 -0
- package/build-examples/esm/example_mcp_local.mjs +16 -4
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/build-examples/esm/example_mcp_remote.mjs +18 -0
- package/build-examples/esm/example_mcp_remote.mjs.map +7 -0
- package/package.json +10 -10
- package/types/MCPLocal.d.ts +0 -14
- package/types/MCPRemote.d.ts +0 -60
- package/types/PluginOptions.d.ts +0 -6
- package/types/index.d.ts +0 -3
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,685 +35,1603 @@ __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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
var import_zod = require("zod");
|
|
39
|
+
|
|
40
|
+
// src/MCPBase.ts
|
|
41
|
+
var MCPBase = class {
|
|
42
|
+
/**
|
|
43
|
+
* Optional logger instance for diagnostics and output.
|
|
44
|
+
* @protected
|
|
45
|
+
*/
|
|
46
|
+
logger;
|
|
47
|
+
/**
|
|
48
|
+
* FIXParser instance, set during plugin register().
|
|
49
|
+
* @protected
|
|
50
|
+
*/
|
|
51
|
+
parser;
|
|
52
|
+
/**
|
|
53
|
+
* Called when server is setup and listening.
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
onReady = void 0;
|
|
57
|
+
/**
|
|
58
|
+
* Map to store verified orders before execution
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
62
|
+
/**
|
|
63
|
+
* Map to store pending market data requests
|
|
64
|
+
* @protected
|
|
65
|
+
*/
|
|
66
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
67
|
+
/**
|
|
68
|
+
* Map to store market data prices
|
|
69
|
+
* @protected
|
|
70
|
+
*/
|
|
71
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
72
|
+
/**
|
|
73
|
+
* Maximum number of price history entries to keep per symbol
|
|
74
|
+
* @protected
|
|
75
|
+
*/
|
|
76
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
77
|
+
constructor({ logger, onReady }) {
|
|
78
|
+
this.logger = logger;
|
|
79
|
+
this.onReady = onReady;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/schemas/schemas.ts
|
|
84
|
+
var toolSchemas = {
|
|
85
|
+
parse: {
|
|
86
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
87
|
+
schema: {
|
|
88
|
+
type: "object",
|
|
89
|
+
properties: {
|
|
90
|
+
fixString: { type: "string" }
|
|
91
|
+
},
|
|
92
|
+
required: ["fixString"]
|
|
36
93
|
}
|
|
37
94
|
},
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
95
|
+
parseToJSON: {
|
|
96
|
+
description: "Parses a FIX message into JSON",
|
|
97
|
+
schema: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
fixString: { type: "string" }
|
|
101
|
+
},
|
|
102
|
+
required: ["fixString"]
|
|
46
103
|
}
|
|
47
104
|
},
|
|
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)'
|
|
105
|
+
verifyOrder: {
|
|
106
|
+
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
107
|
+
schema: {
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
clOrdID: { type: "string" },
|
|
111
|
+
handlInst: {
|
|
112
|
+
type: "string",
|
|
113
|
+
enum: ["1", "2", "3"],
|
|
114
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
115
|
+
},
|
|
116
|
+
quantity: { type: "string" },
|
|
117
|
+
price: { type: "string" },
|
|
118
|
+
ordType: {
|
|
119
|
+
type: "string",
|
|
120
|
+
enum: [
|
|
121
|
+
"1",
|
|
122
|
+
"2",
|
|
123
|
+
"3",
|
|
124
|
+
"4",
|
|
125
|
+
"5",
|
|
126
|
+
"6",
|
|
127
|
+
"7",
|
|
128
|
+
"8",
|
|
129
|
+
"9",
|
|
130
|
+
"A",
|
|
131
|
+
"B",
|
|
132
|
+
"C",
|
|
133
|
+
"D",
|
|
134
|
+
"E",
|
|
135
|
+
"F",
|
|
136
|
+
"G",
|
|
137
|
+
"H",
|
|
138
|
+
"I",
|
|
139
|
+
"J",
|
|
140
|
+
"K",
|
|
141
|
+
"L",
|
|
142
|
+
"M",
|
|
143
|
+
"P",
|
|
144
|
+
"Q",
|
|
145
|
+
"R",
|
|
146
|
+
"S"
|
|
147
|
+
],
|
|
148
|
+
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"
|
|
149
|
+
},
|
|
150
|
+
side: {
|
|
151
|
+
type: "string",
|
|
152
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
153
|
+
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"
|
|
154
|
+
},
|
|
155
|
+
symbol: { type: "string" },
|
|
156
|
+
timeInForce: {
|
|
157
|
+
type: "string",
|
|
158
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
159
|
+
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"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
118
163
|
}
|
|
119
164
|
},
|
|
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
|
-
"V",
|
|
179
|
-
"W",
|
|
180
|
-
"X",
|
|
181
|
-
"Y",
|
|
182
|
-
"Z",
|
|
183
|
-
"a",
|
|
184
|
-
"b",
|
|
185
|
-
"c",
|
|
186
|
-
"d",
|
|
187
|
-
"e",
|
|
188
|
-
"g",
|
|
189
|
-
"h",
|
|
190
|
-
"i",
|
|
191
|
-
"t"
|
|
192
|
-
],
|
|
193
|
-
default: import_fixparser.MDEntryType.Bid,
|
|
194
|
-
description: 'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'
|
|
165
|
+
executeOrder: {
|
|
166
|
+
description: "Executes a verified order. verifyOrder must be called before executeOrder.",
|
|
167
|
+
schema: {
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: {
|
|
170
|
+
clOrdID: { type: "string" },
|
|
171
|
+
handlInst: {
|
|
172
|
+
type: "string",
|
|
173
|
+
enum: ["1", "2", "3"],
|
|
174
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
175
|
+
},
|
|
176
|
+
quantity: { type: "string" },
|
|
177
|
+
price: { type: "string" },
|
|
178
|
+
ordType: {
|
|
179
|
+
type: "string",
|
|
180
|
+
enum: [
|
|
181
|
+
"1",
|
|
182
|
+
"2",
|
|
183
|
+
"3",
|
|
184
|
+
"4",
|
|
185
|
+
"5",
|
|
186
|
+
"6",
|
|
187
|
+
"7",
|
|
188
|
+
"8",
|
|
189
|
+
"9",
|
|
190
|
+
"A",
|
|
191
|
+
"B",
|
|
192
|
+
"C",
|
|
193
|
+
"D",
|
|
194
|
+
"E",
|
|
195
|
+
"F",
|
|
196
|
+
"G",
|
|
197
|
+
"H",
|
|
198
|
+
"I",
|
|
199
|
+
"J",
|
|
200
|
+
"K",
|
|
201
|
+
"L",
|
|
202
|
+
"M",
|
|
203
|
+
"P",
|
|
204
|
+
"Q",
|
|
205
|
+
"R",
|
|
206
|
+
"S"
|
|
207
|
+
],
|
|
208
|
+
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"
|
|
209
|
+
},
|
|
210
|
+
side: {
|
|
211
|
+
type: "string",
|
|
212
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
213
|
+
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"
|
|
214
|
+
},
|
|
215
|
+
symbol: { type: "string" },
|
|
216
|
+
timeInForce: {
|
|
217
|
+
type: "string",
|
|
218
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
219
|
+
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"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
195
223
|
}
|
|
196
224
|
},
|
|
197
|
-
|
|
225
|
+
marketDataRequest: {
|
|
226
|
+
description: "Requests market data for specified symbols",
|
|
227
|
+
schema: {
|
|
228
|
+
type: "object",
|
|
229
|
+
properties: {
|
|
230
|
+
mdUpdateType: {
|
|
231
|
+
type: "string",
|
|
232
|
+
enum: ["0", "1"],
|
|
233
|
+
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
234
|
+
},
|
|
235
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
236
|
+
mdReqID: { type: "string" },
|
|
237
|
+
subscriptionRequestType: {
|
|
238
|
+
type: "string",
|
|
239
|
+
enum: ["0", "1", "2"],
|
|
240
|
+
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
241
|
+
},
|
|
242
|
+
mdEntryTypes: {
|
|
243
|
+
type: "array",
|
|
244
|
+
items: {
|
|
245
|
+
type: "string",
|
|
246
|
+
enum: [
|
|
247
|
+
"0",
|
|
248
|
+
"1",
|
|
249
|
+
"2",
|
|
250
|
+
"3",
|
|
251
|
+
"4",
|
|
252
|
+
"5",
|
|
253
|
+
"6",
|
|
254
|
+
"7",
|
|
255
|
+
"8",
|
|
256
|
+
"9",
|
|
257
|
+
"A",
|
|
258
|
+
"B",
|
|
259
|
+
"C",
|
|
260
|
+
"D",
|
|
261
|
+
"E",
|
|
262
|
+
"F",
|
|
263
|
+
"G",
|
|
264
|
+
"H",
|
|
265
|
+
"I",
|
|
266
|
+
"J",
|
|
267
|
+
"K",
|
|
268
|
+
"L",
|
|
269
|
+
"M",
|
|
270
|
+
"N",
|
|
271
|
+
"O",
|
|
272
|
+
"P",
|
|
273
|
+
"Q",
|
|
274
|
+
"R",
|
|
275
|
+
"S",
|
|
276
|
+
"T",
|
|
277
|
+
"U",
|
|
278
|
+
"V",
|
|
279
|
+
"W",
|
|
280
|
+
"X",
|
|
281
|
+
"Y",
|
|
282
|
+
"Z"
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
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"
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
getStockGraph: {
|
|
292
|
+
description: "Generates a price chart for a given symbol",
|
|
293
|
+
schema: {
|
|
294
|
+
type: "object",
|
|
295
|
+
properties: {
|
|
296
|
+
symbol: { type: "string" }
|
|
297
|
+
},
|
|
298
|
+
required: ["symbol"]
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
getStockPriceHistory: {
|
|
302
|
+
description: "Returns price history for a given symbol",
|
|
303
|
+
schema: {
|
|
304
|
+
type: "object",
|
|
305
|
+
properties: {
|
|
306
|
+
symbol: { type: "string" }
|
|
307
|
+
},
|
|
308
|
+
required: ["symbol"]
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
technicalAnalysis: {
|
|
312
|
+
description: "Performs comprehensive technical analysis on market data for a given symbol, including indicators like SMA, EMA, RSI, Bollinger Bands, and trading signals",
|
|
313
|
+
schema: {
|
|
314
|
+
type: "object",
|
|
315
|
+
properties: {
|
|
316
|
+
symbol: {
|
|
317
|
+
type: "string",
|
|
318
|
+
description: "The trading symbol to analyze (e.g., AAPL, MSFT, EURUSD)"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
required: ["symbol"]
|
|
322
|
+
}
|
|
323
|
+
}
|
|
198
324
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
325
|
+
|
|
326
|
+
// src/tools/analytics.ts
|
|
327
|
+
function sum(numbers) {
|
|
328
|
+
return numbers.reduce((acc, val) => acc + val, 0);
|
|
329
|
+
}
|
|
330
|
+
var TechnicalAnalyzer = class {
|
|
331
|
+
prices;
|
|
332
|
+
volumes;
|
|
333
|
+
highs;
|
|
334
|
+
lows;
|
|
335
|
+
constructor(data) {
|
|
336
|
+
this.prices = data.map((d) => d.trade > 0 ? d.trade : d.midPrice);
|
|
337
|
+
this.volumes = data.map((d) => d.volume);
|
|
338
|
+
this.highs = data.map((d) => d.tradingSessionHighPrice > 0 ? d.tradingSessionHighPrice : d.trade);
|
|
339
|
+
this.lows = data.map((d) => d.tradingSessionLowPrice > 0 ? d.tradingSessionLowPrice : d.trade);
|
|
340
|
+
}
|
|
341
|
+
// Calculate Simple Moving Average
|
|
342
|
+
calculateSMA(data, period) {
|
|
343
|
+
const sma = [];
|
|
344
|
+
for (let i = period - 1; i < data.length; i++) {
|
|
345
|
+
const sum2 = data.slice(i - period + 1, i + 1).reduce((a, b) => a + b, 0);
|
|
346
|
+
sma.push(sum2 / period);
|
|
213
347
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
348
|
+
return sma;
|
|
349
|
+
}
|
|
350
|
+
// Calculate Exponential Moving Average
|
|
351
|
+
calculateEMA(data, period) {
|
|
352
|
+
const multiplier = 2 / (period + 1);
|
|
353
|
+
const ema = [data[0]];
|
|
354
|
+
for (let i = 1; i < data.length; i++) {
|
|
355
|
+
ema.push(data[i] * multiplier + ema[i - 1] * (1 - multiplier));
|
|
221
356
|
}
|
|
222
|
-
|
|
357
|
+
return ema;
|
|
223
358
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (
|
|
227
|
-
|
|
359
|
+
// Calculate RSI
|
|
360
|
+
calculateRSI(data, period = 14) {
|
|
361
|
+
if (data.length < period + 1) return [];
|
|
362
|
+
const changes = [];
|
|
363
|
+
for (let i = 1; i < data.length; i++) {
|
|
364
|
+
changes.push(data[i] - data[i - 1]);
|
|
228
365
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.pendingRequests.delete(String(id));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
this.addWorkflows();
|
|
246
|
-
await this.server.connect(this.transport);
|
|
247
|
-
if (this.onReady) {
|
|
248
|
-
this.onReady();
|
|
366
|
+
const gains = changes.map((change) => change > 0 ? change : 0);
|
|
367
|
+
const losses = changes.map((change) => change < 0 ? Math.abs(change) : 0);
|
|
368
|
+
let avgGain = gains.slice(0, period).reduce((a, b) => a + b, 0) / period;
|
|
369
|
+
let avgLoss = losses.slice(0, period).reduce((a, b) => a + b, 0) / period;
|
|
370
|
+
const rsi = [];
|
|
371
|
+
for (let i = period; i < changes.length; i++) {
|
|
372
|
+
const rs = avgGain / avgLoss;
|
|
373
|
+
rsi.push(100 - 100 / (1 + rs));
|
|
374
|
+
avgGain = (avgGain * (period - 1) + gains[i]) / period;
|
|
375
|
+
avgLoss = (avgLoss * (period - 1) + losses[i]) / period;
|
|
249
376
|
}
|
|
377
|
+
return rsi;
|
|
250
378
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
379
|
+
// Calculate Bollinger Bands
|
|
380
|
+
calculateBollingerBands(data, period = 20, stdDev = 2) {
|
|
381
|
+
if (data.length < period) return [];
|
|
382
|
+
const sma = this.calculateSMA(data, period);
|
|
383
|
+
const bands = [];
|
|
384
|
+
for (let i = 0; i < sma.length; i++) {
|
|
385
|
+
const dataSlice = data.slice(i, i + period);
|
|
386
|
+
const mean = sma[i];
|
|
387
|
+
const variance = dataSlice.reduce((sum2, price) => sum2 + (price - mean) ** 2, 0) / period;
|
|
388
|
+
const standardDeviation = Math.sqrt(variance);
|
|
389
|
+
bands.push({
|
|
390
|
+
upper: mean + standardDeviation * stdDev,
|
|
391
|
+
middle: mean,
|
|
392
|
+
lower: mean - standardDeviation * stdDev
|
|
256
393
|
});
|
|
257
|
-
return;
|
|
258
394
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
395
|
+
return bands;
|
|
396
|
+
}
|
|
397
|
+
// Calculate maximum drawdown
|
|
398
|
+
calculateMaxDrawdown(prices) {
|
|
399
|
+
let maxPrice = prices[0];
|
|
400
|
+
let maxDrawdown = 0;
|
|
401
|
+
for (let i = 1; i < prices.length; i++) {
|
|
402
|
+
if (prices[i] > maxPrice) {
|
|
403
|
+
maxPrice = prices[i];
|
|
404
|
+
}
|
|
405
|
+
const drawdown = (maxPrice - prices[i]) / maxPrice;
|
|
406
|
+
if (drawdown > maxDrawdown) {
|
|
407
|
+
maxDrawdown = drawdown;
|
|
408
|
+
}
|
|
265
409
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
410
|
+
return maxDrawdown;
|
|
411
|
+
}
|
|
412
|
+
// Calculate price changes for volatility
|
|
413
|
+
calculatePriceChanges() {
|
|
414
|
+
const changes = [];
|
|
415
|
+
for (let i = 1; i < this.prices.length; i++) {
|
|
416
|
+
changes.push((this.prices[i] - this.prices[i - 1]) / this.prices[i - 1]);
|
|
417
|
+
}
|
|
418
|
+
return changes;
|
|
419
|
+
}
|
|
420
|
+
// Generate comprehensive market analysis
|
|
421
|
+
analyze() {
|
|
422
|
+
const currentPrice = this.prices[this.prices.length - 1];
|
|
423
|
+
const startPrice = this.prices[0];
|
|
424
|
+
const sessionHigh = Math.max(...this.highs);
|
|
425
|
+
const sessionLow = Math.min(...this.lows);
|
|
426
|
+
const totalVolume = sum(this.volumes);
|
|
427
|
+
const avgVolume = totalVolume / this.volumes.length;
|
|
428
|
+
const priceChanges = this.calculatePriceChanges();
|
|
429
|
+
const volatility = priceChanges.length > 0 ? Math.sqrt(
|
|
430
|
+
priceChanges.reduce((sum2, change) => sum2 + change ** 2, 0) / priceChanges.length
|
|
431
|
+
) * Math.sqrt(252) * 100 : 0;
|
|
432
|
+
const sessionReturn = (currentPrice - startPrice) / startPrice * 100;
|
|
433
|
+
const pricePosition = (currentPrice - sessionLow) / (sessionHigh - sessionLow) * 100;
|
|
434
|
+
const trueVWAP = this.prices.reduce((sum2, price, i) => sum2 + price * this.volumes[i], 0) / totalVolume;
|
|
435
|
+
const momentum5 = this.prices.length > 5 ? (currentPrice - this.prices[Math.max(0, this.prices.length - 6)]) / this.prices[Math.max(0, this.prices.length - 6)] * 100 : 0;
|
|
436
|
+
const momentum10 = this.prices.length > 10 ? (currentPrice - this.prices[Math.max(0, this.prices.length - 11)]) / this.prices[Math.max(0, this.prices.length - 11)] * 100 : 0;
|
|
437
|
+
const maxDrawdown = this.calculateMaxDrawdown(this.prices);
|
|
438
|
+
return {
|
|
439
|
+
currentPrice,
|
|
440
|
+
startPrice,
|
|
441
|
+
sessionHigh,
|
|
442
|
+
sessionLow,
|
|
443
|
+
totalVolume,
|
|
444
|
+
avgVolume,
|
|
445
|
+
volatility,
|
|
446
|
+
sessionReturn,
|
|
447
|
+
pricePosition,
|
|
448
|
+
trueVWAP,
|
|
449
|
+
momentum5,
|
|
450
|
+
momentum10,
|
|
451
|
+
maxDrawdown
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
// Generate technical indicators
|
|
455
|
+
getTechnicalIndicators() {
|
|
456
|
+
return {
|
|
457
|
+
sma5: this.calculateSMA(this.prices, 5),
|
|
458
|
+
sma10: this.calculateSMA(this.prices, 10),
|
|
459
|
+
ema8: this.calculateEMA(this.prices, 8),
|
|
460
|
+
ema21: this.calculateEMA(this.prices, 21),
|
|
461
|
+
rsi: this.calculateRSI(this.prices, 14),
|
|
462
|
+
bollinger: this.calculateBollingerBands(this.prices, 20, 2)
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
// Generate trading signals
|
|
466
|
+
generateSignals() {
|
|
467
|
+
const analysis = this.analyze();
|
|
468
|
+
let bullishSignals = 0;
|
|
469
|
+
let bearishSignals = 0;
|
|
470
|
+
const signals = [];
|
|
471
|
+
if (analysis.currentPrice > analysis.trueVWAP) {
|
|
472
|
+
signals.push(
|
|
473
|
+
`\u2713 BULLISH: Price above VWAP (+${((analysis.currentPrice - analysis.trueVWAP) / analysis.trueVWAP * 100).toFixed(2)}%)`
|
|
474
|
+
);
|
|
475
|
+
bullishSignals++;
|
|
476
|
+
} else {
|
|
477
|
+
signals.push(
|
|
478
|
+
`\u2717 BEARISH: Price below VWAP (${((analysis.currentPrice - analysis.trueVWAP) / analysis.trueVWAP * 100).toFixed(2)}%)`
|
|
479
|
+
);
|
|
480
|
+
bearishSignals++;
|
|
481
|
+
}
|
|
482
|
+
if (analysis.momentum5 > 0 && analysis.momentum10 > 0) {
|
|
483
|
+
signals.push("\u2713 BULLISH: Positive momentum on both timeframes");
|
|
484
|
+
bullishSignals++;
|
|
485
|
+
} else if (analysis.momentum5 < 0 && analysis.momentum10 < 0) {
|
|
486
|
+
signals.push("\u2717 BEARISH: Negative momentum on both timeframes");
|
|
487
|
+
bearishSignals++;
|
|
488
|
+
} else {
|
|
489
|
+
signals.push("\u25D0 MIXED: Conflicting momentum signals");
|
|
490
|
+
}
|
|
491
|
+
const currentVolume = this.volumes[this.volumes.length - 1];
|
|
492
|
+
const volumeRatio = currentVolume / analysis.avgVolume;
|
|
493
|
+
if (volumeRatio > 1.2 && analysis.sessionReturn > 0) {
|
|
494
|
+
signals.push("\u2713 BULLISH: Above-average volume supporting upward move");
|
|
495
|
+
bullishSignals++;
|
|
496
|
+
} else if (volumeRatio > 1.2 && analysis.sessionReturn < 0) {
|
|
497
|
+
signals.push("\u2717 BEARISH: Above-average volume supporting downward move");
|
|
498
|
+
bearishSignals++;
|
|
499
|
+
} else {
|
|
500
|
+
signals.push("\u25D0 NEUTRAL: Volume not providing clear direction");
|
|
501
|
+
}
|
|
502
|
+
if (analysis.pricePosition > 65 && analysis.volatility > 30) {
|
|
503
|
+
signals.push("\u2717 BEARISH: High in range with elevated volatility - reversal risk");
|
|
504
|
+
bearishSignals++;
|
|
505
|
+
} else if (analysis.pricePosition < 35 && analysis.volatility > 30) {
|
|
506
|
+
signals.push("\u2713 BULLISH: Low in range with volatility - potential bounce");
|
|
507
|
+
bullishSignals++;
|
|
508
|
+
} else {
|
|
509
|
+
signals.push("\u25D0 NEUTRAL: Price position and volatility not extreme");
|
|
510
|
+
}
|
|
511
|
+
return { bullishSignals, bearishSignals, signals };
|
|
512
|
+
}
|
|
513
|
+
// Generate comprehensive JSON analysis
|
|
514
|
+
generateJSONAnalysis(symbol) {
|
|
515
|
+
const analysis = this.analyze();
|
|
516
|
+
const indicators = this.getTechnicalIndicators();
|
|
517
|
+
const signals = this.generateSignals();
|
|
518
|
+
const currentSMA5 = indicators.sma5.length > 0 ? indicators.sma5[indicators.sma5.length - 1] : null;
|
|
519
|
+
const currentSMA10 = indicators.sma10.length > 0 ? indicators.sma10[indicators.sma10.length - 1] : null;
|
|
520
|
+
const currentEMA8 = indicators.ema8[indicators.ema8.length - 1];
|
|
521
|
+
const currentEMA21 = indicators.ema21[indicators.ema21.length - 1];
|
|
522
|
+
const currentRSI = indicators.rsi.length > 0 ? indicators.rsi[indicators.rsi.length - 1] : null;
|
|
523
|
+
const currentBB = indicators.bollinger.length > 0 ? indicators.bollinger[indicators.bollinger.length - 1] : null;
|
|
524
|
+
const currentVolume = this.volumes[this.volumes.length - 1];
|
|
525
|
+
const volumeRatio = currentVolume / analysis.avgVolume;
|
|
526
|
+
const currentDrawdown = (analysis.sessionHigh - analysis.currentPrice) / analysis.sessionHigh * 100;
|
|
527
|
+
const rangeWidth = (analysis.sessionHigh - analysis.sessionLow) / analysis.sessionLow * 100;
|
|
528
|
+
const priceVsVWAP = (analysis.currentPrice - analysis.trueVWAP) / analysis.trueVWAP * 100;
|
|
529
|
+
const totalScore = signals.bullishSignals - signals.bearishSignals;
|
|
530
|
+
const overallSignal = totalScore > 0 ? "BULLISH_BIAS" : totalScore < 0 ? "BEARISH_BIAS" : "NEUTRAL";
|
|
531
|
+
const targetEntry = Math.max(analysis.sessionLow * 1.005, analysis.trueVWAP * 0.998);
|
|
532
|
+
const stopLoss = analysis.sessionLow * 0.995;
|
|
533
|
+
const profitTarget = analysis.sessionHigh * 0.995;
|
|
534
|
+
const riskRewardRatio = (profitTarget - analysis.currentPrice) / (analysis.currentPrice - stopLoss);
|
|
535
|
+
return {
|
|
536
|
+
symbol,
|
|
537
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
538
|
+
marketStructure: {
|
|
539
|
+
currentPrice: analysis.currentPrice,
|
|
540
|
+
startPrice: analysis.startPrice,
|
|
541
|
+
sessionHigh: analysis.sessionHigh,
|
|
542
|
+
sessionLow: analysis.sessionLow,
|
|
543
|
+
rangeWidth,
|
|
544
|
+
totalVolume: analysis.totalVolume,
|
|
545
|
+
sessionPerformance: analysis.sessionReturn,
|
|
546
|
+
positionInRange: analysis.pricePosition
|
|
547
|
+
},
|
|
548
|
+
volatility: {
|
|
549
|
+
impliedVolatility: analysis.volatility,
|
|
550
|
+
maxDrawdown: analysis.maxDrawdown * 100,
|
|
551
|
+
currentDrawdown
|
|
552
|
+
},
|
|
553
|
+
technicalIndicators: {
|
|
554
|
+
sma5: currentSMA5,
|
|
555
|
+
sma10: currentSMA10,
|
|
556
|
+
ema8: currentEMA8,
|
|
557
|
+
ema21: currentEMA21,
|
|
558
|
+
rsi: currentRSI,
|
|
559
|
+
bollingerBands: currentBB ? {
|
|
560
|
+
upper: currentBB.upper,
|
|
561
|
+
middle: currentBB.middle,
|
|
562
|
+
lower: currentBB.lower,
|
|
563
|
+
position: (analysis.currentPrice - currentBB.lower) / (currentBB.upper - currentBB.lower) * 100
|
|
564
|
+
} : null
|
|
565
|
+
},
|
|
566
|
+
volumeAnalysis: {
|
|
567
|
+
currentVolume,
|
|
568
|
+
averageVolume: Math.round(analysis.avgVolume),
|
|
569
|
+
volumeRatio,
|
|
570
|
+
trueVWAP: analysis.trueVWAP,
|
|
571
|
+
priceVsVWAP
|
|
572
|
+
},
|
|
573
|
+
momentum: {
|
|
574
|
+
momentum5: analysis.momentum5,
|
|
575
|
+
momentum10: analysis.momentum10,
|
|
576
|
+
sessionROC: analysis.sessionReturn
|
|
577
|
+
},
|
|
578
|
+
tradingSignals: {
|
|
579
|
+
...signals,
|
|
580
|
+
overallSignal,
|
|
581
|
+
signalScore: totalScore
|
|
582
|
+
},
|
|
583
|
+
riskManagement: {
|
|
584
|
+
targetEntry,
|
|
585
|
+
stopLoss,
|
|
586
|
+
profitTarget,
|
|
587
|
+
riskRewardRatio
|
|
279
588
|
}
|
|
280
|
-
return result;
|
|
281
589
|
};
|
|
282
|
-
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
var createTechnicalAnalysisHandler = (marketDataPrices) => {
|
|
593
|
+
return async (args) => {
|
|
594
|
+
try {
|
|
595
|
+
const symbol = args.symbol;
|
|
596
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
597
|
+
if (priceHistory.length === 0) {
|
|
598
|
+
return {
|
|
599
|
+
content: [
|
|
600
|
+
{
|
|
601
|
+
type: "text",
|
|
602
|
+
text: `No price data available for ${symbol}. Please request market data first.`,
|
|
603
|
+
uri: "technicalAnalysis"
|
|
604
|
+
}
|
|
605
|
+
]
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
const analyzer = new TechnicalAnalyzer(priceHistory);
|
|
609
|
+
const analysis = analyzer.generateJSONAnalysis(symbol);
|
|
283
610
|
return {
|
|
284
|
-
|
|
611
|
+
content: [
|
|
612
|
+
{
|
|
613
|
+
type: "text",
|
|
614
|
+
text: `Technical Analysis for ${symbol}:
|
|
615
|
+
|
|
616
|
+
${JSON.stringify(analysis, null, 2)}`,
|
|
617
|
+
uri: "technicalAnalysis"
|
|
618
|
+
}
|
|
619
|
+
]
|
|
285
620
|
};
|
|
286
|
-
})
|
|
287
|
-
this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
621
|
+
} catch (error) {
|
|
288
622
|
return {
|
|
289
|
-
|
|
290
|
-
{
|
|
291
|
-
name: "parse",
|
|
292
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
293
|
-
inputSchema: parseInputSchema
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
name: "parseToJSON",
|
|
297
|
-
description: "Parses a FIX message into JSON",
|
|
298
|
-
inputSchema: parseToJSONInputSchema
|
|
299
|
-
},
|
|
623
|
+
content: [
|
|
300
624
|
{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
625
|
+
type: "text",
|
|
626
|
+
text: `Error performing technical analysis: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
627
|
+
uri: "technicalAnalysis"
|
|
628
|
+
}
|
|
629
|
+
],
|
|
630
|
+
isError: true
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
// src/tools/marketData.ts
|
|
637
|
+
var import_fixparser = require("fixparser");
|
|
638
|
+
var import_quickchart_js = __toESM(require("quickchart-js"), 1);
|
|
639
|
+
var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
640
|
+
return async (args) => {
|
|
641
|
+
try {
|
|
642
|
+
parser.logger.log({
|
|
643
|
+
level: "info",
|
|
644
|
+
message: `Sending market data request for symbols: ${args.symbols.join(", ")}`
|
|
645
|
+
});
|
|
646
|
+
const response = new Promise((resolve) => {
|
|
647
|
+
pendingRequests.set(args.mdReqID, resolve);
|
|
648
|
+
parser.logger.log({
|
|
649
|
+
level: "info",
|
|
650
|
+
message: `Registered callback for market data request ID: ${args.mdReqID}`
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
const entryTypes = args.mdEntryTypes || [
|
|
654
|
+
import_fixparser.MDEntryType.Bid,
|
|
655
|
+
import_fixparser.MDEntryType.Offer,
|
|
656
|
+
import_fixparser.MDEntryType.Trade,
|
|
657
|
+
import_fixparser.MDEntryType.IndexValue,
|
|
658
|
+
import_fixparser.MDEntryType.OpeningPrice,
|
|
659
|
+
import_fixparser.MDEntryType.ClosingPrice,
|
|
660
|
+
import_fixparser.MDEntryType.SettlementPrice,
|
|
661
|
+
import_fixparser.MDEntryType.TradingSessionHighPrice,
|
|
662
|
+
import_fixparser.MDEntryType.TradingSessionLowPrice,
|
|
663
|
+
import_fixparser.MDEntryType.VWAP,
|
|
664
|
+
import_fixparser.MDEntryType.Imbalance,
|
|
665
|
+
import_fixparser.MDEntryType.TradeVolume,
|
|
666
|
+
import_fixparser.MDEntryType.OpenInterest,
|
|
667
|
+
import_fixparser.MDEntryType.CompositeUnderlyingPrice,
|
|
668
|
+
import_fixparser.MDEntryType.SimulatedSellPrice,
|
|
669
|
+
import_fixparser.MDEntryType.SimulatedBuyPrice,
|
|
670
|
+
import_fixparser.MDEntryType.MarginRate,
|
|
671
|
+
import_fixparser.MDEntryType.MidPrice,
|
|
672
|
+
import_fixparser.MDEntryType.EmptyBook,
|
|
673
|
+
import_fixparser.MDEntryType.SettleHighPrice,
|
|
674
|
+
import_fixparser.MDEntryType.SettleLowPrice,
|
|
675
|
+
import_fixparser.MDEntryType.PriorSettlePrice,
|
|
676
|
+
import_fixparser.MDEntryType.SessionHighBid,
|
|
677
|
+
import_fixparser.MDEntryType.SessionLowOffer,
|
|
678
|
+
import_fixparser.MDEntryType.EarlyPrices,
|
|
679
|
+
import_fixparser.MDEntryType.AuctionClearingPrice,
|
|
680
|
+
import_fixparser.MDEntryType.SwapValueFactor,
|
|
681
|
+
import_fixparser.MDEntryType.DailyValueAdjustmentForLongPositions,
|
|
682
|
+
import_fixparser.MDEntryType.CumulativeValueAdjustmentForLongPositions,
|
|
683
|
+
import_fixparser.MDEntryType.DailyValueAdjustmentForShortPositions,
|
|
684
|
+
import_fixparser.MDEntryType.CumulativeValueAdjustmentForShortPositions,
|
|
685
|
+
import_fixparser.MDEntryType.FixingPrice,
|
|
686
|
+
import_fixparser.MDEntryType.CashRate,
|
|
687
|
+
import_fixparser.MDEntryType.RecoveryRate,
|
|
688
|
+
import_fixparser.MDEntryType.RecoveryRateForLong,
|
|
689
|
+
import_fixparser.MDEntryType.RecoveryRateForShort,
|
|
690
|
+
import_fixparser.MDEntryType.MarketBid,
|
|
691
|
+
import_fixparser.MDEntryType.MarketOffer,
|
|
692
|
+
import_fixparser.MDEntryType.ShortSaleMinPrice,
|
|
693
|
+
import_fixparser.MDEntryType.PreviousClosingPrice,
|
|
694
|
+
import_fixparser.MDEntryType.ThresholdLimitPriceBanding,
|
|
695
|
+
import_fixparser.MDEntryType.DailyFinancingValue,
|
|
696
|
+
import_fixparser.MDEntryType.AccruedFinancingValue,
|
|
697
|
+
import_fixparser.MDEntryType.TWAP
|
|
698
|
+
];
|
|
699
|
+
const messageFields = [
|
|
700
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
701
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
|
|
702
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
703
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
|
|
704
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
|
|
705
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
706
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
707
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
708
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
709
|
+
];
|
|
710
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
711
|
+
args.symbols.forEach((symbol) => {
|
|
712
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
713
|
+
});
|
|
714
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
|
|
715
|
+
entryTypes.forEach((entryType) => {
|
|
716
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
717
|
+
});
|
|
718
|
+
const mdr = parser.createMessage(...messageFields);
|
|
719
|
+
if (!parser.connected) {
|
|
720
|
+
parser.logger.log({
|
|
721
|
+
level: "error",
|
|
722
|
+
message: "Not connected. Cannot send market data request."
|
|
723
|
+
});
|
|
724
|
+
return {
|
|
725
|
+
content: [
|
|
726
|
+
{
|
|
727
|
+
type: "text",
|
|
728
|
+
text: "Error: Not connected. Ignoring message.",
|
|
729
|
+
uri: "marketDataRequest"
|
|
730
|
+
}
|
|
731
|
+
],
|
|
732
|
+
isError: true
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
parser.logger.log({
|
|
736
|
+
level: "info",
|
|
737
|
+
message: `Sending market data request message: ${JSON.stringify(mdr?.toFIXJSON())}`
|
|
738
|
+
});
|
|
739
|
+
parser.send(mdr);
|
|
740
|
+
const fixData = await response;
|
|
741
|
+
parser.logger.log({
|
|
742
|
+
level: "info",
|
|
743
|
+
message: `Received market data response for request ID: ${args.mdReqID}`
|
|
744
|
+
});
|
|
745
|
+
return {
|
|
746
|
+
content: [
|
|
305
747
|
{
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
748
|
+
type: "text",
|
|
749
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
750
|
+
uri: "marketDataRequest"
|
|
309
751
|
}
|
|
310
752
|
]
|
|
311
753
|
};
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
320
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
321
|
-
return {
|
|
322
|
-
isError: true,
|
|
323
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
return {
|
|
327
|
-
content: [
|
|
328
|
-
{
|
|
329
|
-
type: "text",
|
|
330
|
-
text: `${parsedMessage[0].description}
|
|
331
|
-
${parsedMessage[0].messageTypeDescription}`
|
|
332
|
-
}
|
|
333
|
-
]
|
|
334
|
-
};
|
|
335
|
-
} catch (error) {
|
|
336
|
-
return {
|
|
337
|
-
isError: true,
|
|
338
|
-
content: [
|
|
339
|
-
{
|
|
340
|
-
type: "text",
|
|
341
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
342
|
-
}
|
|
343
|
-
]
|
|
344
|
-
};
|
|
754
|
+
} catch (error) {
|
|
755
|
+
return {
|
|
756
|
+
content: [
|
|
757
|
+
{
|
|
758
|
+
type: "text",
|
|
759
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
760
|
+
uri: "marketDataRequest"
|
|
345
761
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
762
|
+
],
|
|
763
|
+
isError: true
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
};
|
|
768
|
+
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
769
|
+
return async (args) => {
|
|
770
|
+
try {
|
|
771
|
+
const symbol = args.symbol;
|
|
772
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
773
|
+
if (priceHistory.length === 0) {
|
|
774
|
+
return {
|
|
775
|
+
content: [
|
|
776
|
+
{
|
|
777
|
+
type: "text",
|
|
778
|
+
text: `No price data available for ${symbol}`,
|
|
779
|
+
uri: "getStockGraph"
|
|
356
780
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
781
|
+
]
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
const chart = new import_quickchart_js.default();
|
|
785
|
+
chart.setWidth(1200);
|
|
786
|
+
chart.setHeight(600);
|
|
787
|
+
chart.setBackgroundColor("transparent");
|
|
788
|
+
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
789
|
+
const bidData = priceHistory.map((point) => point.bid);
|
|
790
|
+
const offerData = priceHistory.map((point) => point.offer);
|
|
791
|
+
const spreadData = priceHistory.map((point) => point.spread);
|
|
792
|
+
const volumeData = priceHistory.map((point) => point.volume);
|
|
793
|
+
const tradeData = priceHistory.map((point) => point.trade);
|
|
794
|
+
const vwapData = priceHistory.map((point) => point.vwap);
|
|
795
|
+
const twapData = priceHistory.map((point) => point.twap);
|
|
796
|
+
const config = {
|
|
797
|
+
type: "line",
|
|
798
|
+
data: {
|
|
799
|
+
labels,
|
|
800
|
+
datasets: [
|
|
801
|
+
{
|
|
802
|
+
label: "Bid",
|
|
803
|
+
data: bidData,
|
|
804
|
+
borderColor: "#28a745",
|
|
805
|
+
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
806
|
+
fill: false,
|
|
807
|
+
tension: 0.4
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
label: "Offer",
|
|
811
|
+
data: offerData,
|
|
812
|
+
borderColor: "#dc3545",
|
|
813
|
+
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
814
|
+
fill: false,
|
|
815
|
+
tension: 0.4
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
label: "Spread",
|
|
819
|
+
data: spreadData,
|
|
820
|
+
borderColor: "#6c757d",
|
|
821
|
+
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
822
|
+
fill: false,
|
|
823
|
+
tension: 0.4
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
label: "Trade",
|
|
827
|
+
data: tradeData,
|
|
828
|
+
borderColor: "#ffc107",
|
|
829
|
+
backgroundColor: "rgba(255, 193, 7, 0.1)",
|
|
830
|
+
fill: false,
|
|
831
|
+
tension: 0.4
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
label: "VWAP",
|
|
835
|
+
data: vwapData,
|
|
836
|
+
borderColor: "#17a2b8",
|
|
837
|
+
backgroundColor: "rgba(23, 162, 184, 0.1)",
|
|
838
|
+
fill: false,
|
|
839
|
+
tension: 0.4
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
label: "TWAP",
|
|
843
|
+
data: twapData,
|
|
844
|
+
borderColor: "#6610f2",
|
|
845
|
+
backgroundColor: "rgba(102, 16, 242, 0.1)",
|
|
846
|
+
fill: false,
|
|
847
|
+
tension: 0.4
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
label: "Volume",
|
|
851
|
+
data: volumeData,
|
|
852
|
+
borderColor: "#007bff",
|
|
853
|
+
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
854
|
+
fill: true,
|
|
855
|
+
tension: 0.4
|
|
856
|
+
}
|
|
857
|
+
]
|
|
858
|
+
},
|
|
859
|
+
options: {
|
|
860
|
+
responsive: true,
|
|
861
|
+
plugins: {
|
|
862
|
+
title: {
|
|
863
|
+
display: true,
|
|
864
|
+
text: `${symbol} Market Data`
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
scales: {
|
|
868
|
+
y: {
|
|
869
|
+
beginAtZero: false
|
|
413
870
|
}
|
|
414
|
-
this.parser?.send(order);
|
|
415
|
-
this.logger?.log({
|
|
416
|
-
level: "info",
|
|
417
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
418
|
-
});
|
|
419
|
-
const fixData = await response;
|
|
420
|
-
return {
|
|
421
|
-
content: [
|
|
422
|
-
{
|
|
423
|
-
type: "text",
|
|
424
|
-
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
425
|
-
}
|
|
426
|
-
]
|
|
427
|
-
};
|
|
428
|
-
} catch (error) {
|
|
429
|
-
return {
|
|
430
|
-
isError: true,
|
|
431
|
-
content: [
|
|
432
|
-
{
|
|
433
|
-
type: "text",
|
|
434
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
|
|
435
|
-
}
|
|
436
|
-
]
|
|
437
|
-
};
|
|
438
871
|
}
|
|
439
872
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
453
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
454
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
455
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
456
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
|
|
457
|
-
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
458
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
459
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
|
|
460
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
461
|
-
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
462
|
-
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
|
|
463
|
-
);
|
|
464
|
-
if (!this.parser?.connected) {
|
|
465
|
-
this.logger?.log({
|
|
466
|
-
level: "error",
|
|
467
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
468
|
-
});
|
|
469
|
-
return {
|
|
470
|
-
isError: true,
|
|
471
|
-
content: [
|
|
472
|
-
{
|
|
473
|
-
type: "text",
|
|
474
|
-
text: "Error: Not connected. Ignoring message."
|
|
475
|
-
}
|
|
476
|
-
]
|
|
477
|
-
};
|
|
873
|
+
};
|
|
874
|
+
chart.setConfig(config);
|
|
875
|
+
const imageBuffer = await chart.toBinary();
|
|
876
|
+
const base64 = imageBuffer.toString("base64");
|
|
877
|
+
return {
|
|
878
|
+
content: [
|
|
879
|
+
{
|
|
880
|
+
type: "resource",
|
|
881
|
+
resource: {
|
|
882
|
+
uri: "resource://graph",
|
|
883
|
+
mimeType: "image/png",
|
|
884
|
+
blob: base64
|
|
478
885
|
}
|
|
479
|
-
this.parser?.send(marketDataRequest);
|
|
480
|
-
this.logger?.log({
|
|
481
|
-
level: "info",
|
|
482
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
483
|
-
});
|
|
484
|
-
const fixData = await response;
|
|
485
|
-
return {
|
|
486
|
-
content: [
|
|
487
|
-
{
|
|
488
|
-
type: "text",
|
|
489
|
-
text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
490
|
-
}
|
|
491
|
-
]
|
|
492
|
-
};
|
|
493
|
-
} catch (error) {
|
|
494
|
-
return {
|
|
495
|
-
isError: true,
|
|
496
|
-
content: [
|
|
497
|
-
{
|
|
498
|
-
type: "text",
|
|
499
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
500
|
-
}
|
|
501
|
-
]
|
|
502
|
-
};
|
|
503
886
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
887
|
+
]
|
|
888
|
+
};
|
|
889
|
+
} catch (error) {
|
|
890
|
+
return {
|
|
891
|
+
content: [
|
|
892
|
+
{
|
|
893
|
+
type: "text",
|
|
894
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to generate graph"}`,
|
|
895
|
+
uri: "getStockGraph"
|
|
896
|
+
}
|
|
897
|
+
],
|
|
898
|
+
isError: true
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
904
|
+
return async (args) => {
|
|
905
|
+
try {
|
|
906
|
+
const symbol = args.symbol;
|
|
907
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
908
|
+
if (priceHistory.length === 0) {
|
|
909
|
+
return {
|
|
910
|
+
content: [
|
|
911
|
+
{
|
|
912
|
+
type: "text",
|
|
913
|
+
text: `No price data available for ${symbol}`,
|
|
914
|
+
uri: "getStockPriceHistory"
|
|
915
|
+
}
|
|
916
|
+
]
|
|
917
|
+
};
|
|
507
918
|
}
|
|
508
|
-
});
|
|
509
|
-
this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
|
|
510
919
|
return {
|
|
511
|
-
|
|
920
|
+
content: [
|
|
512
921
|
{
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
arguments: [
|
|
922
|
+
type: "text",
|
|
923
|
+
text: JSON.stringify(
|
|
516
924
|
{
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
925
|
+
symbol,
|
|
926
|
+
count: priceHistory.length,
|
|
927
|
+
data: priceHistory.map((point) => ({
|
|
928
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
929
|
+
bid: point.bid,
|
|
930
|
+
offer: point.offer,
|
|
931
|
+
spread: point.spread,
|
|
932
|
+
volume: point.volume,
|
|
933
|
+
trade: point.trade,
|
|
934
|
+
indexValue: point.indexValue,
|
|
935
|
+
openingPrice: point.openingPrice,
|
|
936
|
+
closingPrice: point.closingPrice,
|
|
937
|
+
settlementPrice: point.settlementPrice,
|
|
938
|
+
tradingSessionHighPrice: point.tradingSessionHighPrice,
|
|
939
|
+
tradingSessionLowPrice: point.tradingSessionLowPrice,
|
|
940
|
+
vwap: point.vwap,
|
|
941
|
+
imbalance: point.imbalance,
|
|
942
|
+
openInterest: point.openInterest,
|
|
943
|
+
compositeUnderlyingPrice: point.compositeUnderlyingPrice,
|
|
944
|
+
simulatedSellPrice: point.simulatedSellPrice,
|
|
945
|
+
simulatedBuyPrice: point.simulatedBuyPrice,
|
|
946
|
+
marginRate: point.marginRate,
|
|
947
|
+
midPrice: point.midPrice,
|
|
948
|
+
emptyBook: point.emptyBook,
|
|
949
|
+
settleHighPrice: point.settleHighPrice,
|
|
950
|
+
settleLowPrice: point.settleLowPrice,
|
|
951
|
+
priorSettlePrice: point.priorSettlePrice,
|
|
952
|
+
sessionHighBid: point.sessionHighBid,
|
|
953
|
+
sessionLowOffer: point.sessionLowOffer,
|
|
954
|
+
earlyPrices: point.earlyPrices,
|
|
955
|
+
auctionClearingPrice: point.auctionClearingPrice,
|
|
956
|
+
swapValueFactor: point.swapValueFactor,
|
|
957
|
+
dailyValueAdjustmentForLongPositions: point.dailyValueAdjustmentForLongPositions,
|
|
958
|
+
cumulativeValueAdjustmentForLongPositions: point.cumulativeValueAdjustmentForLongPositions,
|
|
959
|
+
dailyValueAdjustmentForShortPositions: point.dailyValueAdjustmentForShortPositions,
|
|
960
|
+
cumulativeValueAdjustmentForShortPositions: point.cumulativeValueAdjustmentForShortPositions,
|
|
961
|
+
fixingPrice: point.fixingPrice,
|
|
962
|
+
cashRate: point.cashRate,
|
|
963
|
+
recoveryRate: point.recoveryRate,
|
|
964
|
+
recoveryRateForLong: point.recoveryRateForLong,
|
|
965
|
+
recoveryRateForShort: point.recoveryRateForShort,
|
|
966
|
+
marketBid: point.marketBid,
|
|
967
|
+
marketOffer: point.marketOffer,
|
|
968
|
+
shortSaleMinPrice: point.shortSaleMinPrice,
|
|
969
|
+
previousClosingPrice: point.previousClosingPrice,
|
|
970
|
+
thresholdLimitPriceBanding: point.thresholdLimitPriceBanding,
|
|
971
|
+
dailyFinancingValue: point.dailyFinancingValue,
|
|
972
|
+
accruedFinancingValue: point.accruedFinancingValue,
|
|
973
|
+
twap: point.twap
|
|
974
|
+
}))
|
|
975
|
+
},
|
|
976
|
+
null,
|
|
977
|
+
2
|
|
978
|
+
),
|
|
979
|
+
uri: "getStockPriceHistory"
|
|
980
|
+
}
|
|
981
|
+
]
|
|
982
|
+
};
|
|
983
|
+
} catch (error) {
|
|
984
|
+
return {
|
|
985
|
+
content: [
|
|
523
986
|
{
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
987
|
+
type: "text",
|
|
988
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to get price history"}`,
|
|
989
|
+
uri: "getStockPriceHistory"
|
|
990
|
+
}
|
|
991
|
+
],
|
|
992
|
+
isError: true
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
// src/tools/order.ts
|
|
999
|
+
var import_fixparser2 = require("fixparser");
|
|
1000
|
+
var ordTypeNames = {
|
|
1001
|
+
"1": "Market",
|
|
1002
|
+
"2": "Limit",
|
|
1003
|
+
"3": "Stop",
|
|
1004
|
+
"4": "StopLimit",
|
|
1005
|
+
"5": "MarketOnClose",
|
|
1006
|
+
"6": "WithOrWithout",
|
|
1007
|
+
"7": "LimitOrBetter",
|
|
1008
|
+
"8": "LimitWithOrWithout",
|
|
1009
|
+
"9": "OnBasis",
|
|
1010
|
+
A: "OnClose",
|
|
1011
|
+
B: "LimitOnClose",
|
|
1012
|
+
C: "ForexMarket",
|
|
1013
|
+
D: "PreviouslyQuoted",
|
|
1014
|
+
E: "PreviouslyIndicated",
|
|
1015
|
+
F: "ForexLimit",
|
|
1016
|
+
G: "ForexSwap",
|
|
1017
|
+
H: "ForexPreviouslyQuoted",
|
|
1018
|
+
I: "Funari",
|
|
1019
|
+
J: "MarketIfTouched",
|
|
1020
|
+
K: "MarketWithLeftOverAsLimit",
|
|
1021
|
+
L: "PreviousFundValuationPoint",
|
|
1022
|
+
M: "NextFundValuationPoint",
|
|
1023
|
+
P: "Pegged",
|
|
1024
|
+
Q: "CounterOrderSelection",
|
|
1025
|
+
R: "StopOnBidOrOffer",
|
|
1026
|
+
S: "StopLimitOnBidOrOffer"
|
|
1027
|
+
};
|
|
1028
|
+
var sideNames = {
|
|
1029
|
+
"1": "Buy",
|
|
1030
|
+
"2": "Sell",
|
|
1031
|
+
"3": "BuyMinus",
|
|
1032
|
+
"4": "SellPlus",
|
|
1033
|
+
"5": "SellShort",
|
|
1034
|
+
"6": "SellShortExempt",
|
|
1035
|
+
"7": "Undisclosed",
|
|
1036
|
+
"8": "Cross",
|
|
1037
|
+
"9": "CrossShort",
|
|
1038
|
+
A: "CrossShortExempt",
|
|
1039
|
+
B: "AsDefined",
|
|
1040
|
+
C: "Opposite",
|
|
1041
|
+
D: "Subscribe",
|
|
1042
|
+
E: "Redeem",
|
|
1043
|
+
F: "Lend",
|
|
1044
|
+
G: "Borrow",
|
|
1045
|
+
H: "SellUndisclosed"
|
|
1046
|
+
};
|
|
1047
|
+
var timeInForceNames = {
|
|
1048
|
+
"0": "Day",
|
|
1049
|
+
"1": "GoodTillCancel",
|
|
1050
|
+
"2": "AtTheOpening",
|
|
1051
|
+
"3": "ImmediateOrCancel",
|
|
1052
|
+
"4": "FillOrKill",
|
|
1053
|
+
"5": "GoodTillCrossing",
|
|
1054
|
+
"6": "GoodTillDate",
|
|
1055
|
+
"7": "AtTheClose",
|
|
1056
|
+
"8": "GoodThroughCrossing",
|
|
1057
|
+
"9": "AtCrossing",
|
|
1058
|
+
A: "GoodForTime",
|
|
1059
|
+
B: "GoodForAuction",
|
|
1060
|
+
C: "GoodForMonth"
|
|
1061
|
+
};
|
|
1062
|
+
var handlInstNames = {
|
|
1063
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
1064
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
1065
|
+
"3": "ManualOrder"
|
|
1066
|
+
};
|
|
1067
|
+
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
1068
|
+
return async (args) => {
|
|
1069
|
+
try {
|
|
1070
|
+
verifiedOrders.set(args.clOrdID, {
|
|
1071
|
+
clOrdID: args.clOrdID,
|
|
1072
|
+
handlInst: args.handlInst,
|
|
1073
|
+
quantity: Number.parseFloat(String(args.quantity)),
|
|
1074
|
+
price: Number.parseFloat(String(args.price)),
|
|
1075
|
+
ordType: args.ordType,
|
|
1076
|
+
side: args.side,
|
|
1077
|
+
symbol: args.symbol,
|
|
1078
|
+
timeInForce: args.timeInForce
|
|
1079
|
+
});
|
|
1080
|
+
return {
|
|
1081
|
+
content: [
|
|
534
1082
|
{
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
required: true
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
name: "ordType",
|
|
560
|
-
description: "Order type",
|
|
561
|
-
required: false
|
|
562
|
-
},
|
|
563
|
-
{
|
|
564
|
-
name: "side",
|
|
565
|
-
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)",
|
|
566
|
-
required: true
|
|
567
|
-
},
|
|
568
|
-
{
|
|
569
|
-
name: "symbol",
|
|
570
|
-
description: "Trading symbol",
|
|
571
|
-
required: true
|
|
572
|
-
},
|
|
573
|
-
{
|
|
574
|
-
name: "timeInForce",
|
|
575
|
-
description: "Time in force",
|
|
576
|
-
required: false
|
|
577
|
-
}
|
|
578
|
-
]
|
|
579
|
-
},
|
|
1083
|
+
type: "text",
|
|
1084
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
1085
|
+
|
|
1086
|
+
Parameters verified:
|
|
1087
|
+
- ClOrdID: ${args.clOrdID}
|
|
1088
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
1089
|
+
- Quantity: ${args.quantity}
|
|
1090
|
+
- Price: ${args.price}
|
|
1091
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
1092
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
1093
|
+
- Symbol: ${args.symbol}
|
|
1094
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
1095
|
+
|
|
1096
|
+
To execute this order, call the executeOrder tool with these exact same parameters. Important: The user has to explicitly confirm before executeOrder is called!`,
|
|
1097
|
+
uri: "verifyOrder"
|
|
1098
|
+
}
|
|
1099
|
+
]
|
|
1100
|
+
};
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
return {
|
|
1103
|
+
content: [
|
|
580
1104
|
{
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
1105
|
+
type: "text",
|
|
1106
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
1107
|
+
uri: "verifyOrder"
|
|
1108
|
+
}
|
|
1109
|
+
],
|
|
1110
|
+
isError: true
|
|
1111
|
+
};
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
};
|
|
1115
|
+
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
1116
|
+
return async (args) => {
|
|
1117
|
+
try {
|
|
1118
|
+
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
1119
|
+
if (!verifiedOrder) {
|
|
1120
|
+
return {
|
|
1121
|
+
content: [
|
|
1122
|
+
{
|
|
1123
|
+
type: "text",
|
|
1124
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
1125
|
+
uri: "executeOrder"
|
|
1126
|
+
}
|
|
1127
|
+
],
|
|
1128
|
+
isError: true
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
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) {
|
|
1132
|
+
return {
|
|
1133
|
+
content: [
|
|
1134
|
+
{
|
|
1135
|
+
type: "text",
|
|
1136
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
1137
|
+
uri: "executeOrder"
|
|
1138
|
+
}
|
|
1139
|
+
],
|
|
1140
|
+
isError: true
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
const response = new Promise((resolve) => {
|
|
1144
|
+
pendingRequests.set(args.clOrdID, resolve);
|
|
1145
|
+
});
|
|
1146
|
+
const order = parser.createMessage(
|
|
1147
|
+
new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
|
|
1148
|
+
new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
1149
|
+
new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
|
|
1150
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
|
|
1151
|
+
new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
|
|
1152
|
+
new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
|
|
1153
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
|
|
1154
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
|
|
1155
|
+
new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
1156
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
|
|
1157
|
+
new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
|
|
1158
|
+
new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
|
|
1159
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
|
|
1160
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
|
|
1161
|
+
);
|
|
1162
|
+
if (!parser.connected) {
|
|
1163
|
+
return {
|
|
1164
|
+
content: [
|
|
1165
|
+
{
|
|
1166
|
+
type: "text",
|
|
1167
|
+
text: "Error: Not connected. Ignoring message.",
|
|
1168
|
+
uri: "executeOrder"
|
|
1169
|
+
}
|
|
1170
|
+
],
|
|
1171
|
+
isError: true
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
parser.send(order);
|
|
1175
|
+
const fixData = await response;
|
|
1176
|
+
verifiedOrders.delete(args.clOrdID);
|
|
1177
|
+
return {
|
|
1178
|
+
content: [
|
|
1179
|
+
{
|
|
1180
|
+
type: "text",
|
|
1181
|
+
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())}`,
|
|
1182
|
+
uri: "executeOrder"
|
|
1183
|
+
}
|
|
1184
|
+
]
|
|
1185
|
+
};
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
return {
|
|
1188
|
+
content: [
|
|
1189
|
+
{
|
|
1190
|
+
type: "text",
|
|
1191
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
1192
|
+
uri: "executeOrder"
|
|
1193
|
+
}
|
|
1194
|
+
],
|
|
1195
|
+
isError: true
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
// src/tools/parse.ts
|
|
1202
|
+
var createParseHandler = (parser) => {
|
|
1203
|
+
return async (args) => {
|
|
1204
|
+
try {
|
|
1205
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
1206
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1207
|
+
return {
|
|
1208
|
+
content: [
|
|
1209
|
+
{
|
|
1210
|
+
type: "text",
|
|
1211
|
+
text: "Error: Failed to parse FIX string",
|
|
1212
|
+
uri: "parse"
|
|
1213
|
+
}
|
|
1214
|
+
],
|
|
1215
|
+
isError: true
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
return {
|
|
1219
|
+
content: [
|
|
1220
|
+
{
|
|
1221
|
+
type: "text",
|
|
1222
|
+
text: `${parsedMessage[0].description}
|
|
1223
|
+
${parsedMessage[0].messageTypeDescription}`,
|
|
1224
|
+
uri: "parse"
|
|
1225
|
+
}
|
|
1226
|
+
]
|
|
1227
|
+
};
|
|
1228
|
+
} catch (error) {
|
|
1229
|
+
return {
|
|
1230
|
+
content: [
|
|
1231
|
+
{
|
|
1232
|
+
type: "text",
|
|
1233
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
1234
|
+
uri: "parse"
|
|
1235
|
+
}
|
|
1236
|
+
],
|
|
1237
|
+
isError: true
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1243
|
+
// src/tools/parseToJSON.ts
|
|
1244
|
+
var createParseToJSONHandler = (parser) => {
|
|
1245
|
+
return async (args) => {
|
|
1246
|
+
try {
|
|
1247
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
1248
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1249
|
+
return {
|
|
1250
|
+
content: [
|
|
1251
|
+
{
|
|
1252
|
+
type: "text",
|
|
1253
|
+
text: "Error: Failed to parse FIX string",
|
|
1254
|
+
uri: "parseToJSON"
|
|
1255
|
+
}
|
|
1256
|
+
],
|
|
1257
|
+
isError: true
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
return {
|
|
1261
|
+
content: [
|
|
1262
|
+
{
|
|
1263
|
+
type: "text",
|
|
1264
|
+
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
1265
|
+
uri: "parseToJSON"
|
|
610
1266
|
}
|
|
611
1267
|
]
|
|
612
1268
|
};
|
|
1269
|
+
} catch (error) {
|
|
1270
|
+
return {
|
|
1271
|
+
content: [
|
|
1272
|
+
{
|
|
1273
|
+
type: "text",
|
|
1274
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
1275
|
+
uri: "parseToJSON"
|
|
1276
|
+
}
|
|
1277
|
+
],
|
|
1278
|
+
isError: true
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
// src/tools/index.ts
|
|
1285
|
+
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
1286
|
+
parse: createParseHandler(parser),
|
|
1287
|
+
parseToJSON: createParseToJSONHandler(parser),
|
|
1288
|
+
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
1289
|
+
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
1290
|
+
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
1291
|
+
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
1292
|
+
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices),
|
|
1293
|
+
technicalAnalysis: createTechnicalAnalysisHandler(marketDataPrices)
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
// src/utils/messageHandler.ts
|
|
1297
|
+
var import_fixparser3 = require("fixparser");
|
|
1298
|
+
function getEnumValue(enumObj, name) {
|
|
1299
|
+
return enumObj[name] || name;
|
|
1300
|
+
}
|
|
1301
|
+
function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
|
|
1302
|
+
const msgType = message.messageType;
|
|
1303
|
+
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
|
|
1304
|
+
const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
|
|
1305
|
+
const fixJson = message.toFIXJSON();
|
|
1306
|
+
const entries = fixJson.Body?.NoMDEntries || [];
|
|
1307
|
+
const data = {
|
|
1308
|
+
timestamp: Date.now(),
|
|
1309
|
+
bid: 0,
|
|
1310
|
+
offer: 0,
|
|
1311
|
+
spread: 0,
|
|
1312
|
+
volume: 0,
|
|
1313
|
+
trade: 0,
|
|
1314
|
+
indexValue: 0,
|
|
1315
|
+
openingPrice: 0,
|
|
1316
|
+
closingPrice: 0,
|
|
1317
|
+
settlementPrice: 0,
|
|
1318
|
+
tradingSessionHighPrice: 0,
|
|
1319
|
+
tradingSessionLowPrice: 0,
|
|
1320
|
+
vwap: 0,
|
|
1321
|
+
imbalance: 0,
|
|
1322
|
+
openInterest: 0,
|
|
1323
|
+
compositeUnderlyingPrice: 0,
|
|
1324
|
+
simulatedSellPrice: 0,
|
|
1325
|
+
simulatedBuyPrice: 0,
|
|
1326
|
+
marginRate: 0,
|
|
1327
|
+
midPrice: 0,
|
|
1328
|
+
emptyBook: 0,
|
|
1329
|
+
settleHighPrice: 0,
|
|
1330
|
+
settleLowPrice: 0,
|
|
1331
|
+
priorSettlePrice: 0,
|
|
1332
|
+
sessionHighBid: 0,
|
|
1333
|
+
sessionLowOffer: 0,
|
|
1334
|
+
earlyPrices: 0,
|
|
1335
|
+
auctionClearingPrice: 0,
|
|
1336
|
+
swapValueFactor: 0,
|
|
1337
|
+
dailyValueAdjustmentForLongPositions: 0,
|
|
1338
|
+
cumulativeValueAdjustmentForLongPositions: 0,
|
|
1339
|
+
dailyValueAdjustmentForShortPositions: 0,
|
|
1340
|
+
cumulativeValueAdjustmentForShortPositions: 0,
|
|
1341
|
+
fixingPrice: 0,
|
|
1342
|
+
cashRate: 0,
|
|
1343
|
+
recoveryRate: 0,
|
|
1344
|
+
recoveryRateForLong: 0,
|
|
1345
|
+
recoveryRateForShort: 0,
|
|
1346
|
+
marketBid: 0,
|
|
1347
|
+
marketOffer: 0,
|
|
1348
|
+
shortSaleMinPrice: 0,
|
|
1349
|
+
previousClosingPrice: 0,
|
|
1350
|
+
thresholdLimitPriceBanding: 0,
|
|
1351
|
+
dailyFinancingValue: 0,
|
|
1352
|
+
accruedFinancingValue: 0,
|
|
1353
|
+
twap: 0
|
|
1354
|
+
};
|
|
1355
|
+
for (const entry of entries) {
|
|
1356
|
+
const entryType = entry.MDEntryType;
|
|
1357
|
+
const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
|
|
1358
|
+
const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
|
|
1359
|
+
const enumValue = getEnumValue(import_fixparser3.MDEntryType, entryType);
|
|
1360
|
+
switch (enumValue) {
|
|
1361
|
+
case import_fixparser3.MDEntryType.Bid:
|
|
1362
|
+
data.bid = price;
|
|
1363
|
+
break;
|
|
1364
|
+
case import_fixparser3.MDEntryType.Offer:
|
|
1365
|
+
data.offer = price;
|
|
1366
|
+
break;
|
|
1367
|
+
case import_fixparser3.MDEntryType.Trade:
|
|
1368
|
+
data.trade = price;
|
|
1369
|
+
break;
|
|
1370
|
+
case import_fixparser3.MDEntryType.IndexValue:
|
|
1371
|
+
data.indexValue = price;
|
|
1372
|
+
break;
|
|
1373
|
+
case import_fixparser3.MDEntryType.OpeningPrice:
|
|
1374
|
+
data.openingPrice = price;
|
|
1375
|
+
break;
|
|
1376
|
+
case import_fixparser3.MDEntryType.ClosingPrice:
|
|
1377
|
+
data.closingPrice = price;
|
|
1378
|
+
break;
|
|
1379
|
+
case import_fixparser3.MDEntryType.SettlementPrice:
|
|
1380
|
+
data.settlementPrice = price;
|
|
1381
|
+
break;
|
|
1382
|
+
case import_fixparser3.MDEntryType.TradingSessionHighPrice:
|
|
1383
|
+
data.tradingSessionHighPrice = price;
|
|
1384
|
+
break;
|
|
1385
|
+
case import_fixparser3.MDEntryType.TradingSessionLowPrice:
|
|
1386
|
+
data.tradingSessionLowPrice = price;
|
|
1387
|
+
break;
|
|
1388
|
+
case import_fixparser3.MDEntryType.VWAP:
|
|
1389
|
+
data.vwap = price;
|
|
1390
|
+
break;
|
|
1391
|
+
case import_fixparser3.MDEntryType.Imbalance:
|
|
1392
|
+
data.imbalance = size;
|
|
1393
|
+
break;
|
|
1394
|
+
case import_fixparser3.MDEntryType.TradeVolume:
|
|
1395
|
+
data.volume = size;
|
|
1396
|
+
break;
|
|
1397
|
+
case import_fixparser3.MDEntryType.OpenInterest:
|
|
1398
|
+
data.openInterest = size;
|
|
1399
|
+
break;
|
|
1400
|
+
case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
|
|
1401
|
+
data.compositeUnderlyingPrice = price;
|
|
1402
|
+
break;
|
|
1403
|
+
case import_fixparser3.MDEntryType.SimulatedSellPrice:
|
|
1404
|
+
data.simulatedSellPrice = price;
|
|
1405
|
+
break;
|
|
1406
|
+
case import_fixparser3.MDEntryType.SimulatedBuyPrice:
|
|
1407
|
+
data.simulatedBuyPrice = price;
|
|
1408
|
+
break;
|
|
1409
|
+
case import_fixparser3.MDEntryType.MarginRate:
|
|
1410
|
+
data.marginRate = price;
|
|
1411
|
+
break;
|
|
1412
|
+
case import_fixparser3.MDEntryType.MidPrice:
|
|
1413
|
+
data.midPrice = price;
|
|
1414
|
+
break;
|
|
1415
|
+
case import_fixparser3.MDEntryType.EmptyBook:
|
|
1416
|
+
data.emptyBook = 1;
|
|
1417
|
+
break;
|
|
1418
|
+
case import_fixparser3.MDEntryType.SettleHighPrice:
|
|
1419
|
+
data.settleHighPrice = price;
|
|
1420
|
+
break;
|
|
1421
|
+
case import_fixparser3.MDEntryType.SettleLowPrice:
|
|
1422
|
+
data.settleLowPrice = price;
|
|
1423
|
+
break;
|
|
1424
|
+
case import_fixparser3.MDEntryType.PriorSettlePrice:
|
|
1425
|
+
data.priorSettlePrice = price;
|
|
1426
|
+
break;
|
|
1427
|
+
case import_fixparser3.MDEntryType.SessionHighBid:
|
|
1428
|
+
data.sessionHighBid = price;
|
|
1429
|
+
break;
|
|
1430
|
+
case import_fixparser3.MDEntryType.SessionLowOffer:
|
|
1431
|
+
data.sessionLowOffer = price;
|
|
1432
|
+
break;
|
|
1433
|
+
case import_fixparser3.MDEntryType.EarlyPrices:
|
|
1434
|
+
data.earlyPrices = price;
|
|
1435
|
+
break;
|
|
1436
|
+
case import_fixparser3.MDEntryType.AuctionClearingPrice:
|
|
1437
|
+
data.auctionClearingPrice = price;
|
|
1438
|
+
break;
|
|
1439
|
+
case import_fixparser3.MDEntryType.SwapValueFactor:
|
|
1440
|
+
data.swapValueFactor = price;
|
|
1441
|
+
break;
|
|
1442
|
+
case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
|
|
1443
|
+
data.dailyValueAdjustmentForLongPositions = price;
|
|
1444
|
+
break;
|
|
1445
|
+
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
|
|
1446
|
+
data.cumulativeValueAdjustmentForLongPositions = price;
|
|
1447
|
+
break;
|
|
1448
|
+
case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
|
|
1449
|
+
data.dailyValueAdjustmentForShortPositions = price;
|
|
1450
|
+
break;
|
|
1451
|
+
case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
|
|
1452
|
+
data.cumulativeValueAdjustmentForShortPositions = price;
|
|
1453
|
+
break;
|
|
1454
|
+
case import_fixparser3.MDEntryType.FixingPrice:
|
|
1455
|
+
data.fixingPrice = price;
|
|
1456
|
+
break;
|
|
1457
|
+
case import_fixparser3.MDEntryType.CashRate:
|
|
1458
|
+
data.cashRate = price;
|
|
1459
|
+
break;
|
|
1460
|
+
case import_fixparser3.MDEntryType.RecoveryRate:
|
|
1461
|
+
data.recoveryRate = price;
|
|
1462
|
+
break;
|
|
1463
|
+
case import_fixparser3.MDEntryType.RecoveryRateForLong:
|
|
1464
|
+
data.recoveryRateForLong = price;
|
|
1465
|
+
break;
|
|
1466
|
+
case import_fixparser3.MDEntryType.RecoveryRateForShort:
|
|
1467
|
+
data.recoveryRateForShort = price;
|
|
1468
|
+
break;
|
|
1469
|
+
case import_fixparser3.MDEntryType.MarketBid:
|
|
1470
|
+
data.marketBid = price;
|
|
1471
|
+
break;
|
|
1472
|
+
case import_fixparser3.MDEntryType.MarketOffer:
|
|
1473
|
+
data.marketOffer = price;
|
|
1474
|
+
break;
|
|
1475
|
+
case import_fixparser3.MDEntryType.ShortSaleMinPrice:
|
|
1476
|
+
data.shortSaleMinPrice = price;
|
|
1477
|
+
break;
|
|
1478
|
+
case import_fixparser3.MDEntryType.PreviousClosingPrice:
|
|
1479
|
+
data.previousClosingPrice = price;
|
|
1480
|
+
break;
|
|
1481
|
+
case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
|
|
1482
|
+
data.thresholdLimitPriceBanding = price;
|
|
1483
|
+
break;
|
|
1484
|
+
case import_fixparser3.MDEntryType.DailyFinancingValue:
|
|
1485
|
+
data.dailyFinancingValue = price;
|
|
1486
|
+
break;
|
|
1487
|
+
case import_fixparser3.MDEntryType.AccruedFinancingValue:
|
|
1488
|
+
data.accruedFinancingValue = price;
|
|
1489
|
+
break;
|
|
1490
|
+
case import_fixparser3.MDEntryType.TWAP:
|
|
1491
|
+
data.twap = price;
|
|
1492
|
+
break;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
data.spread = data.offer - data.bid;
|
|
1496
|
+
if (!marketDataPrices.has(symbol)) {
|
|
1497
|
+
marketDataPrices.set(symbol, []);
|
|
1498
|
+
}
|
|
1499
|
+
const prices = marketDataPrices.get(symbol);
|
|
1500
|
+
prices.push(data);
|
|
1501
|
+
if (prices.length > maxPriceHistory) {
|
|
1502
|
+
prices.splice(0, prices.length - maxPriceHistory);
|
|
1503
|
+
}
|
|
1504
|
+
onPriceUpdate?.(symbol, data);
|
|
1505
|
+
const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
|
|
1506
|
+
if (mdReqID) {
|
|
1507
|
+
const callback = pendingRequests.get(mdReqID);
|
|
1508
|
+
if (callback) {
|
|
1509
|
+
callback(message);
|
|
1510
|
+
pendingRequests.delete(mdReqID);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
} else if (msgType === import_fixparser3.Messages.ExecutionReport) {
|
|
1514
|
+
const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
|
|
1515
|
+
const callback = pendingRequests.get(reqId);
|
|
1516
|
+
if (callback) {
|
|
1517
|
+
callback(message);
|
|
1518
|
+
pendingRequests.delete(reqId);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
// src/MCPLocal.ts
|
|
1524
|
+
var MCPLocal = class extends MCPBase {
|
|
1525
|
+
/**
|
|
1526
|
+
* Map to store verified orders before execution
|
|
1527
|
+
* @private
|
|
1528
|
+
*/
|
|
1529
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
1530
|
+
/**
|
|
1531
|
+
* Map to store pending requests and their callbacks
|
|
1532
|
+
* @private
|
|
1533
|
+
*/
|
|
1534
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
1535
|
+
/**
|
|
1536
|
+
* Map to store market data prices for each symbol
|
|
1537
|
+
* @private
|
|
1538
|
+
*/
|
|
1539
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
1540
|
+
/**
|
|
1541
|
+
* Maximum number of price history entries to keep per symbol
|
|
1542
|
+
* @private
|
|
1543
|
+
*/
|
|
1544
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
1545
|
+
server = new import_server.Server(
|
|
1546
|
+
{
|
|
1547
|
+
name: "fixparser",
|
|
1548
|
+
version: "1.0.0"
|
|
1549
|
+
},
|
|
1550
|
+
{
|
|
1551
|
+
capabilities: {
|
|
1552
|
+
tools: Object.entries(toolSchemas).reduce(
|
|
1553
|
+
(acc, [name, { description, schema }]) => {
|
|
1554
|
+
acc[name] = {
|
|
1555
|
+
description,
|
|
1556
|
+
parameters: schema
|
|
1557
|
+
};
|
|
1558
|
+
return acc;
|
|
1559
|
+
},
|
|
1560
|
+
{}
|
|
1561
|
+
)
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
);
|
|
1565
|
+
transport = new import_stdio.StdioServerTransport();
|
|
1566
|
+
constructor({ logger, onReady }) {
|
|
1567
|
+
super({ logger, onReady });
|
|
1568
|
+
}
|
|
1569
|
+
async register(parser) {
|
|
1570
|
+
this.parser = parser;
|
|
1571
|
+
this.parser.addOnMessageCallback((message) => {
|
|
1572
|
+
handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
|
|
1573
|
+
});
|
|
1574
|
+
this.addWorkflows();
|
|
1575
|
+
await this.server.connect(this.transport);
|
|
1576
|
+
if (this.onReady) {
|
|
1577
|
+
this.onReady();
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
addWorkflows() {
|
|
1581
|
+
if (!this.parser) {
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
if (!this.server) {
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
|
|
1588
|
+
return {
|
|
1589
|
+
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
1590
|
+
name,
|
|
1591
|
+
description,
|
|
1592
|
+
inputSchema: schema
|
|
1593
|
+
}))
|
|
1594
|
+
};
|
|
613
1595
|
});
|
|
614
|
-
this.server.setRequestHandler(
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
1596
|
+
this.server.setRequestHandler(
|
|
1597
|
+
import_zod.z.object({
|
|
1598
|
+
method: import_zod.z.literal("tools/call"),
|
|
1599
|
+
params: import_zod.z.object({
|
|
1600
|
+
name: import_zod.z.string(),
|
|
1601
|
+
arguments: import_zod.z.any(),
|
|
1602
|
+
_meta: import_zod.z.object({
|
|
1603
|
+
progressToken: import_zod.z.number()
|
|
1604
|
+
}).optional()
|
|
1605
|
+
})
|
|
1606
|
+
}),
|
|
1607
|
+
async (request) => {
|
|
1608
|
+
const { name, arguments: args } = request.params;
|
|
1609
|
+
const toolHandlers = createToolHandlers(
|
|
1610
|
+
this.parser,
|
|
1611
|
+
this.verifiedOrders,
|
|
1612
|
+
this.pendingRequests,
|
|
1613
|
+
this.marketDataPrices
|
|
1614
|
+
);
|
|
1615
|
+
const handler = toolHandlers[name];
|
|
1616
|
+
if (!handler) {
|
|
619
1617
|
return {
|
|
620
|
-
|
|
1618
|
+
content: [
|
|
621
1619
|
{
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
text: `Please parse and explain this FIX message: ${fixString}`
|
|
626
|
-
}
|
|
1620
|
+
type: "text",
|
|
1621
|
+
text: `Tool not found: ${name}`,
|
|
1622
|
+
uri: name
|
|
627
1623
|
}
|
|
628
|
-
]
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
case "parseToJSON": {
|
|
632
|
-
const fixString = args?.fixString || "";
|
|
633
|
-
return {
|
|
634
|
-
messages: [
|
|
635
|
-
{
|
|
636
|
-
role: "user",
|
|
637
|
-
content: {
|
|
638
|
-
type: "text",
|
|
639
|
-
text: `Please parse the FIX message to JSON: ${fixString}`
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
]
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
case "newOrderSingle": {
|
|
646
|
-
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
|
|
647
|
-
return {
|
|
648
|
-
messages: [
|
|
649
|
-
{
|
|
650
|
-
role: "user",
|
|
651
|
-
content: {
|
|
652
|
-
type: "text",
|
|
653
|
-
text: [
|
|
654
|
-
"Create a New Order Single FIX message with the following parameters:",
|
|
655
|
-
`- ClOrdID: ${clOrdID}`,
|
|
656
|
-
`- 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)`,
|
|
657
|
-
`- Quantity: ${quantity}`,
|
|
658
|
-
`- Price: ${price}`,
|
|
659
|
-
`- 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)`,
|
|
660
|
-
`- Side: ${side} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Buy, '2' for Sell)`,
|
|
661
|
-
`- Symbol: ${symbol}`,
|
|
662
|
-
`- 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)`,
|
|
663
|
-
"",
|
|
664
|
-
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
665
|
-
"",
|
|
666
|
-
'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.',
|
|
667
|
-
'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.',
|
|
668
|
-
'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.',
|
|
669
|
-
'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.'
|
|
670
|
-
].join("\n")
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
]
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
case "marketDataRequest": {
|
|
677
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
|
|
678
|
-
return {
|
|
679
|
-
messages: [
|
|
680
|
-
{
|
|
681
|
-
role: "user",
|
|
682
|
-
content: {
|
|
683
|
-
type: "text",
|
|
684
|
-
text: [
|
|
685
|
-
"Create a Market Data Request FIX message with the following parameters:",
|
|
686
|
-
`- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
|
|
687
|
-
`- Symbol: ${symbol}`,
|
|
688
|
-
`- MDReqID: ${mdReqID}`,
|
|
689
|
-
`- 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)`,
|
|
690
|
-
`- 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)`,
|
|
691
|
-
"",
|
|
692
|
-
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
693
|
-
"",
|
|
694
|
-
'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.',
|
|
695
|
-
'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.',
|
|
696
|
-
'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.'
|
|
697
|
-
].join("\n")
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
]
|
|
1624
|
+
],
|
|
1625
|
+
isError: true
|
|
701
1626
|
};
|
|
702
1627
|
}
|
|
703
|
-
|
|
704
|
-
|
|
1628
|
+
const result = await handler(args);
|
|
1629
|
+
return {
|
|
1630
|
+
content: result.content,
|
|
1631
|
+
isError: result.isError
|
|
1632
|
+
};
|
|
705
1633
|
}
|
|
706
|
-
|
|
1634
|
+
);
|
|
707
1635
|
process.on("SIGINT", async () => {
|
|
708
1636
|
await this.server.close();
|
|
709
1637
|
process.exit(0);
|