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