fixparser-plugin-mcp 9.1.7-f34f63d7 → 9.1.7-f3af791d
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 +844 -1654
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +834 -1667
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +14 -5
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +14 -5
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +12 -11
- package/types/MCPLocal.d.ts +3 -1
- package/types/schemas/index.d.ts +32 -0
- package/types/schemas/schemas.d.ts +168 -0
- package/types/tools/index.d.ts +17 -0
- package/types/tools/marketData.d.ts +40 -0
- package/types/tools/order.d.ts +11 -0
- package/types/tools/parse.d.ts +5 -0
- package/types/tools/parseToJSON.d.ts +5 -0
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,1282 +1,768 @@
|
|
|
1
1
|
// src/MCPLocal.ts
|
|
2
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import {
|
|
5
|
-
CallToolRequestSchema,
|
|
6
|
-
ListResourcesRequestSchema,
|
|
7
|
-
ListToolsRequestSchema
|
|
8
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { Fields as Fields3, MDEntryType as MDEntryType2, Messages as Messages3 } from "fixparser";
|
|
9
5
|
import { z } from "zod";
|
|
10
6
|
|
|
11
|
-
//
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
89
|
-
import { ZodFirstPartyTypeKind } from "zod";
|
|
90
|
-
function parseArrayDef(def, refs) {
|
|
91
|
-
const res = {
|
|
92
|
-
type: "array"
|
|
93
|
-
};
|
|
94
|
-
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
95
|
-
res.items = parseDef(def.type._def, {
|
|
96
|
-
...refs,
|
|
97
|
-
currentPath: [...refs.currentPath, "items"]
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
if (def.minLength) {
|
|
101
|
-
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
102
|
-
}
|
|
103
|
-
if (def.maxLength) {
|
|
104
|
-
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
105
|
-
}
|
|
106
|
-
if (def.exactLength) {
|
|
107
|
-
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
108
|
-
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
109
|
-
}
|
|
110
|
-
return res;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
114
|
-
function parseBigintDef(def, refs) {
|
|
115
|
-
const res = {
|
|
116
|
-
type: "integer",
|
|
117
|
-
format: "int64"
|
|
118
|
-
};
|
|
119
|
-
if (!def.checks)
|
|
120
|
-
return res;
|
|
121
|
-
for (const check of def.checks) {
|
|
122
|
-
switch (check.kind) {
|
|
123
|
-
case "min":
|
|
124
|
-
if (refs.target === "jsonSchema7") {
|
|
125
|
-
if (check.inclusive) {
|
|
126
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
127
|
-
} else {
|
|
128
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
if (!check.inclusive) {
|
|
132
|
-
res.exclusiveMinimum = true;
|
|
133
|
-
}
|
|
134
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
7
|
+
// src/schemas/schemas.ts
|
|
8
|
+
var toolSchemas = {
|
|
9
|
+
parse: {
|
|
10
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
11
|
+
schema: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
fixString: { type: "string" }
|
|
15
|
+
},
|
|
16
|
+
required: ["fixString"]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
parseToJSON: {
|
|
20
|
+
description: "Parses a FIX message into JSON",
|
|
21
|
+
schema: {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
fixString: { type: "string" }
|
|
25
|
+
},
|
|
26
|
+
required: ["fixString"]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
verifyOrder: {
|
|
30
|
+
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
31
|
+
schema: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
clOrdID: { type: "string" },
|
|
35
|
+
handlInst: {
|
|
36
|
+
type: "string",
|
|
37
|
+
enum: ["1", "2", "3"],
|
|
38
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
39
|
+
},
|
|
40
|
+
quantity: { type: "string" },
|
|
41
|
+
price: { type: "string" },
|
|
42
|
+
ordType: {
|
|
43
|
+
type: "string",
|
|
44
|
+
enum: [
|
|
45
|
+
"1",
|
|
46
|
+
"2",
|
|
47
|
+
"3",
|
|
48
|
+
"4",
|
|
49
|
+
"5",
|
|
50
|
+
"6",
|
|
51
|
+
"7",
|
|
52
|
+
"8",
|
|
53
|
+
"9",
|
|
54
|
+
"A",
|
|
55
|
+
"B",
|
|
56
|
+
"C",
|
|
57
|
+
"D",
|
|
58
|
+
"E",
|
|
59
|
+
"F",
|
|
60
|
+
"G",
|
|
61
|
+
"H",
|
|
62
|
+
"I",
|
|
63
|
+
"J",
|
|
64
|
+
"K",
|
|
65
|
+
"L",
|
|
66
|
+
"M",
|
|
67
|
+
"P",
|
|
68
|
+
"Q",
|
|
69
|
+
"R",
|
|
70
|
+
"S"
|
|
71
|
+
],
|
|
72
|
+
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"
|
|
73
|
+
},
|
|
74
|
+
side: {
|
|
75
|
+
type: "string",
|
|
76
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
77
|
+
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"
|
|
78
|
+
},
|
|
79
|
+
symbol: { type: "string" },
|
|
80
|
+
timeInForce: {
|
|
81
|
+
type: "string",
|
|
82
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
83
|
+
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"
|
|
135
84
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
85
|
+
},
|
|
86
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
executeOrder: {
|
|
90
|
+
description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
|
|
91
|
+
schema: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
clOrdID: { type: "string" },
|
|
95
|
+
handlInst: {
|
|
96
|
+
type: "string",
|
|
97
|
+
enum: ["1", "2", "3"],
|
|
98
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
99
|
+
},
|
|
100
|
+
quantity: { type: "string" },
|
|
101
|
+
price: { type: "string" },
|
|
102
|
+
ordType: {
|
|
103
|
+
type: "string",
|
|
104
|
+
enum: [
|
|
105
|
+
"1",
|
|
106
|
+
"2",
|
|
107
|
+
"3",
|
|
108
|
+
"4",
|
|
109
|
+
"5",
|
|
110
|
+
"6",
|
|
111
|
+
"7",
|
|
112
|
+
"8",
|
|
113
|
+
"9",
|
|
114
|
+
"A",
|
|
115
|
+
"B",
|
|
116
|
+
"C",
|
|
117
|
+
"D",
|
|
118
|
+
"E",
|
|
119
|
+
"F",
|
|
120
|
+
"G",
|
|
121
|
+
"H",
|
|
122
|
+
"I",
|
|
123
|
+
"J",
|
|
124
|
+
"K",
|
|
125
|
+
"L",
|
|
126
|
+
"M",
|
|
127
|
+
"P",
|
|
128
|
+
"Q",
|
|
129
|
+
"R",
|
|
130
|
+
"S"
|
|
131
|
+
],
|
|
132
|
+
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"
|
|
133
|
+
},
|
|
134
|
+
side: {
|
|
135
|
+
type: "string",
|
|
136
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
137
|
+
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"
|
|
138
|
+
},
|
|
139
|
+
symbol: { type: "string" },
|
|
140
|
+
timeInForce: {
|
|
141
|
+
type: "string",
|
|
142
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
143
|
+
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"
|
|
149
144
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
},
|
|
146
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
marketDataRequest: {
|
|
150
|
+
description: "Requests market data for specified symbols",
|
|
151
|
+
schema: {
|
|
152
|
+
type: "object",
|
|
153
|
+
properties: {
|
|
154
|
+
mdUpdateType: {
|
|
155
|
+
type: "string",
|
|
156
|
+
enum: ["0", "1"],
|
|
157
|
+
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
158
|
+
},
|
|
159
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
160
|
+
mdReqID: { type: "string" },
|
|
161
|
+
subscriptionRequestType: {
|
|
162
|
+
type: "string",
|
|
163
|
+
enum: ["0", "1", "2"],
|
|
164
|
+
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
165
|
+
},
|
|
166
|
+
mdEntryTypes: {
|
|
167
|
+
type: "array",
|
|
168
|
+
items: {
|
|
169
|
+
type: "string",
|
|
170
|
+
enum: [
|
|
171
|
+
"0",
|
|
172
|
+
"1",
|
|
173
|
+
"2",
|
|
174
|
+
"3",
|
|
175
|
+
"4",
|
|
176
|
+
"5",
|
|
177
|
+
"6",
|
|
178
|
+
"7",
|
|
179
|
+
"8",
|
|
180
|
+
"9",
|
|
181
|
+
"A",
|
|
182
|
+
"B",
|
|
183
|
+
"C",
|
|
184
|
+
"D",
|
|
185
|
+
"E",
|
|
186
|
+
"F",
|
|
187
|
+
"G",
|
|
188
|
+
"H",
|
|
189
|
+
"I",
|
|
190
|
+
"J",
|
|
191
|
+
"K",
|
|
192
|
+
"L",
|
|
193
|
+
"M",
|
|
194
|
+
"N",
|
|
195
|
+
"O",
|
|
196
|
+
"P",
|
|
197
|
+
"Q",
|
|
198
|
+
"R",
|
|
199
|
+
"S",
|
|
200
|
+
"T",
|
|
201
|
+
"U",
|
|
202
|
+
"V",
|
|
203
|
+
"W",
|
|
204
|
+
"X",
|
|
205
|
+
"Y",
|
|
206
|
+
"Z"
|
|
207
|
+
]
|
|
208
|
+
},
|
|
209
|
+
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"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
getStockGraph: {
|
|
216
|
+
description: "Generates a price chart for a given symbol",
|
|
217
|
+
schema: {
|
|
218
|
+
type: "object",
|
|
219
|
+
properties: {
|
|
220
|
+
symbol: { type: "string" }
|
|
221
|
+
},
|
|
222
|
+
required: ["symbol"]
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
getStockPriceHistory: {
|
|
226
|
+
description: "Returns price history for a given symbol",
|
|
227
|
+
schema: {
|
|
228
|
+
type: "object",
|
|
229
|
+
properties: {
|
|
230
|
+
symbol: { type: "string" }
|
|
231
|
+
},
|
|
232
|
+
required: ["symbol"]
|
|
154
233
|
}
|
|
155
234
|
}
|
|
156
|
-
return res;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
160
|
-
function parseBooleanDef() {
|
|
161
|
-
return {
|
|
162
|
-
type: "boolean"
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
167
|
-
function parseBrandedDef(_def, refs) {
|
|
168
|
-
return parseDef(_def.type._def, refs);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
172
|
-
var parseCatchDef = (def, refs) => {
|
|
173
|
-
return parseDef(def.innerType._def, refs);
|
|
174
235
|
};
|
|
175
236
|
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
237
|
+
// src/tools/marketData.ts
|
|
238
|
+
import { Field, Fields, MDEntryType, Messages } from "fixparser";
|
|
239
|
+
import QuickChart from "quickchart-js";
|
|
240
|
+
var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
241
|
+
return async (args) => {
|
|
242
|
+
try {
|
|
243
|
+
const response = new Promise((resolve) => {
|
|
244
|
+
pendingRequests.set(args.mdReqID, resolve);
|
|
245
|
+
});
|
|
246
|
+
const entryTypes = args.mdEntryTypes || [MDEntryType.Bid, MDEntryType.Offer, MDEntryType.TradeVolume];
|
|
247
|
+
const messageFields = [
|
|
248
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
249
|
+
new Field(Fields.SenderCompID, parser.sender),
|
|
250
|
+
new Field(Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
251
|
+
new Field(Fields.TargetCompID, parser.target),
|
|
252
|
+
new Field(Fields.SendingTime, parser.getTimestamp()),
|
|
253
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
254
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
255
|
+
new Field(Fields.MarketDepth, 0),
|
|
256
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
257
|
+
];
|
|
258
|
+
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
259
|
+
args.symbols.forEach((symbol) => {
|
|
260
|
+
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
261
|
+
});
|
|
262
|
+
messageFields.push(new Field(Fields.NoMDEntryTypes, entryTypes.length));
|
|
263
|
+
entryTypes.forEach((entryType) => {
|
|
264
|
+
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
265
|
+
});
|
|
266
|
+
const mdr = parser.createMessage(...messageFields);
|
|
267
|
+
if (!parser.connected) {
|
|
268
|
+
return {
|
|
269
|
+
content: [
|
|
270
|
+
{
|
|
271
|
+
type: "text",
|
|
272
|
+
text: "Error: Not connected. Ignoring message.",
|
|
273
|
+
uri: "marketDataRequest"
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
isError: true
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
parser.send(mdr);
|
|
280
|
+
const fixData = await response;
|
|
187
281
|
return {
|
|
188
|
-
|
|
189
|
-
|
|
282
|
+
content: [
|
|
283
|
+
{
|
|
284
|
+
type: "text",
|
|
285
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
286
|
+
uri: "marketDataRequest"
|
|
287
|
+
}
|
|
288
|
+
]
|
|
190
289
|
};
|
|
191
|
-
|
|
290
|
+
} catch (error) {
|
|
192
291
|
return {
|
|
193
|
-
|
|
194
|
-
|
|
292
|
+
content: [
|
|
293
|
+
{
|
|
294
|
+
type: "text",
|
|
295
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
296
|
+
uri: "marketDataRequest"
|
|
297
|
+
}
|
|
298
|
+
],
|
|
299
|
+
isError: true
|
|
195
300
|
};
|
|
196
|
-
case "integer":
|
|
197
|
-
return integerDateParser(def, refs);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
var integerDateParser = (def, refs) => {
|
|
201
|
-
const res = {
|
|
202
|
-
type: "integer",
|
|
203
|
-
format: "unix-time"
|
|
204
|
-
};
|
|
205
|
-
if (refs.target === "openApi3") {
|
|
206
|
-
return res;
|
|
207
|
-
}
|
|
208
|
-
for (const check of def.checks) {
|
|
209
|
-
switch (check.kind) {
|
|
210
|
-
case "min":
|
|
211
|
-
setResponseValueAndErrors(
|
|
212
|
-
res,
|
|
213
|
-
"minimum",
|
|
214
|
-
check.value,
|
|
215
|
-
// This is in milliseconds
|
|
216
|
-
check.message,
|
|
217
|
-
refs
|
|
218
|
-
);
|
|
219
|
-
break;
|
|
220
|
-
case "max":
|
|
221
|
-
setResponseValueAndErrors(
|
|
222
|
-
res,
|
|
223
|
-
"maximum",
|
|
224
|
-
check.value,
|
|
225
|
-
// This is in milliseconds
|
|
226
|
-
check.message,
|
|
227
|
-
refs
|
|
228
|
-
);
|
|
229
|
-
break;
|
|
230
301
|
}
|
|
231
|
-
}
|
|
232
|
-
return res;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
236
|
-
function parseDefaultDef(_def, refs) {
|
|
237
|
-
return {
|
|
238
|
-
...parseDef(_def.innerType._def, refs),
|
|
239
|
-
default: _def.defaultValue()
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
244
|
-
function parseEffectsDef(_def, refs) {
|
|
245
|
-
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
249
|
-
function parseEnumDef(def) {
|
|
250
|
-
return {
|
|
251
|
-
type: "string",
|
|
252
|
-
enum: Array.from(def.values)
|
|
253
302
|
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
257
|
-
var isJsonSchema7AllOfType = (type) => {
|
|
258
|
-
if ("type" in type && type.type === "string")
|
|
259
|
-
return false;
|
|
260
|
-
return "allOf" in type;
|
|
261
303
|
};
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
mergedAllOf.push(...schema.allOf);
|
|
278
|
-
if (schema.unevaluatedProperties === void 0) {
|
|
279
|
-
unevaluatedProperties = void 0;
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
let nestedSchema = schema;
|
|
283
|
-
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
284
|
-
const { additionalProperties, ...rest } = schema;
|
|
285
|
-
nestedSchema = rest;
|
|
286
|
-
} else {
|
|
287
|
-
unevaluatedProperties = void 0;
|
|
304
|
+
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
305
|
+
return async (args) => {
|
|
306
|
+
try {
|
|
307
|
+
const symbol = args.symbol;
|
|
308
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
309
|
+
if (priceHistory.length === 0) {
|
|
310
|
+
return {
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
type: "text",
|
|
314
|
+
text: `No price data available for ${symbol}`,
|
|
315
|
+
uri: "getStockGraph"
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
};
|
|
288
319
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
334
|
-
/**
|
|
335
|
-
* Constructed a valid Unicode RegExp
|
|
336
|
-
*
|
|
337
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
338
|
-
* in all envs (e.g. React Native).
|
|
339
|
-
*
|
|
340
|
-
* See:
|
|
341
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
342
|
-
* Fix in Zod:
|
|
343
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
344
|
-
*/
|
|
345
|
-
emoji: () => {
|
|
346
|
-
if (emojiRegex === void 0) {
|
|
347
|
-
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
348
|
-
}
|
|
349
|
-
return emojiRegex;
|
|
350
|
-
},
|
|
351
|
-
/**
|
|
352
|
-
* Unused
|
|
353
|
-
*/
|
|
354
|
-
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
355
|
-
/**
|
|
356
|
-
* Unused
|
|
357
|
-
*/
|
|
358
|
-
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
359
|
-
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
360
|
-
/**
|
|
361
|
-
* Unused
|
|
362
|
-
*/
|
|
363
|
-
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
364
|
-
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
365
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
366
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
367
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
368
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
369
|
-
};
|
|
370
|
-
function parseStringDef(def, refs) {
|
|
371
|
-
const res = {
|
|
372
|
-
type: "string"
|
|
373
|
-
};
|
|
374
|
-
if (def.checks) {
|
|
375
|
-
for (const check of def.checks) {
|
|
376
|
-
switch (check.kind) {
|
|
377
|
-
case "min":
|
|
378
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
379
|
-
break;
|
|
380
|
-
case "max":
|
|
381
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
382
|
-
break;
|
|
383
|
-
case "email":
|
|
384
|
-
switch (refs.emailStrategy) {
|
|
385
|
-
case "format:email":
|
|
386
|
-
addFormat(res, "email", check.message, refs);
|
|
387
|
-
break;
|
|
388
|
-
case "format:idn-email":
|
|
389
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
390
|
-
break;
|
|
391
|
-
case "pattern:zod":
|
|
392
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
break;
|
|
396
|
-
case "url":
|
|
397
|
-
addFormat(res, "uri", check.message, refs);
|
|
398
|
-
break;
|
|
399
|
-
case "uuid":
|
|
400
|
-
addFormat(res, "uuid", check.message, refs);
|
|
401
|
-
break;
|
|
402
|
-
case "regex":
|
|
403
|
-
addPattern(res, check.regex, check.message, refs);
|
|
404
|
-
break;
|
|
405
|
-
case "cuid":
|
|
406
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
407
|
-
break;
|
|
408
|
-
case "cuid2":
|
|
409
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
410
|
-
break;
|
|
411
|
-
case "startsWith":
|
|
412
|
-
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
413
|
-
break;
|
|
414
|
-
case "endsWith":
|
|
415
|
-
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
416
|
-
break;
|
|
417
|
-
case "datetime":
|
|
418
|
-
addFormat(res, "date-time", check.message, refs);
|
|
419
|
-
break;
|
|
420
|
-
case "date":
|
|
421
|
-
addFormat(res, "date", check.message, refs);
|
|
422
|
-
break;
|
|
423
|
-
case "time":
|
|
424
|
-
addFormat(res, "time", check.message, refs);
|
|
425
|
-
break;
|
|
426
|
-
case "duration":
|
|
427
|
-
addFormat(res, "duration", check.message, refs);
|
|
428
|
-
break;
|
|
429
|
-
case "length":
|
|
430
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
431
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
432
|
-
break;
|
|
433
|
-
case "includes": {
|
|
434
|
-
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
435
|
-
break;
|
|
436
|
-
}
|
|
437
|
-
case "ip": {
|
|
438
|
-
if (check.version !== "v6") {
|
|
439
|
-
addFormat(res, "ipv4", check.message, refs);
|
|
440
|
-
}
|
|
441
|
-
if (check.version !== "v4") {
|
|
442
|
-
addFormat(res, "ipv6", check.message, refs);
|
|
443
|
-
}
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
case "base64url":
|
|
447
|
-
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
448
|
-
break;
|
|
449
|
-
case "jwt":
|
|
450
|
-
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
451
|
-
break;
|
|
452
|
-
case "cidr": {
|
|
453
|
-
if (check.version !== "v6") {
|
|
454
|
-
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
455
|
-
}
|
|
456
|
-
if (check.version !== "v4") {
|
|
457
|
-
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
458
|
-
}
|
|
459
|
-
break;
|
|
460
|
-
}
|
|
461
|
-
case "emoji":
|
|
462
|
-
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
463
|
-
break;
|
|
464
|
-
case "ulid": {
|
|
465
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
case "base64": {
|
|
469
|
-
switch (refs.base64Strategy) {
|
|
470
|
-
case "format:binary": {
|
|
471
|
-
addFormat(res, "binary", check.message, refs);
|
|
472
|
-
break;
|
|
320
|
+
const chart = new QuickChart();
|
|
321
|
+
chart.setWidth(600);
|
|
322
|
+
chart.setHeight(300);
|
|
323
|
+
const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
|
|
324
|
+
const bidData = priceHistory.map((point) => point.bid);
|
|
325
|
+
const offerData = priceHistory.map((point) => point.offer);
|
|
326
|
+
const spreadData = priceHistory.map((point) => point.spread);
|
|
327
|
+
const volumeData = priceHistory.map((point) => point.volume);
|
|
328
|
+
const config = {
|
|
329
|
+
type: "line",
|
|
330
|
+
data: {
|
|
331
|
+
labels,
|
|
332
|
+
datasets: [
|
|
333
|
+
{
|
|
334
|
+
label: "Bid",
|
|
335
|
+
data: bidData,
|
|
336
|
+
borderColor: "#28a745",
|
|
337
|
+
backgroundColor: "rgba(40, 167, 69, 0.1)",
|
|
338
|
+
fill: false,
|
|
339
|
+
tension: 0.4
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
label: "Offer",
|
|
343
|
+
data: offerData,
|
|
344
|
+
borderColor: "#dc3545",
|
|
345
|
+
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
346
|
+
fill: false,
|
|
347
|
+
tension: 0.4
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
label: "Spread",
|
|
351
|
+
data: spreadData,
|
|
352
|
+
borderColor: "#6c757d",
|
|
353
|
+
backgroundColor: "rgba(108, 117, 125, 0.1)",
|
|
354
|
+
fill: false,
|
|
355
|
+
tension: 0.4
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
label: "Volume",
|
|
359
|
+
data: volumeData,
|
|
360
|
+
borderColor: "#007bff",
|
|
361
|
+
backgroundColor: "rgba(0, 123, 255, 0.1)",
|
|
362
|
+
fill: true,
|
|
363
|
+
tension: 0.4
|
|
473
364
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
365
|
+
]
|
|
366
|
+
},
|
|
367
|
+
options: {
|
|
368
|
+
responsive: true,
|
|
369
|
+
plugins: {
|
|
370
|
+
title: {
|
|
371
|
+
display: true,
|
|
372
|
+
text: `${symbol} Market Data`
|
|
477
373
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
374
|
+
},
|
|
375
|
+
scales: {
|
|
376
|
+
y: {
|
|
377
|
+
beginAtZero: false
|
|
481
378
|
}
|
|
482
379
|
}
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
case "nanoid": {
|
|
486
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
487
|
-
}
|
|
488
|
-
case "toLowerCase":
|
|
489
|
-
case "toUpperCase":
|
|
490
|
-
case "trim":
|
|
491
|
-
break;
|
|
492
|
-
default:
|
|
493
|
-
/* @__PURE__ */ ((_) => {
|
|
494
|
-
})(check);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return res;
|
|
499
|
-
}
|
|
500
|
-
function escapeLiteralCheckValue(literal, refs) {
|
|
501
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
502
|
-
}
|
|
503
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
504
|
-
function escapeNonAlphaNumeric(source) {
|
|
505
|
-
let result = "";
|
|
506
|
-
for (let i = 0; i < source.length; i++) {
|
|
507
|
-
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
508
|
-
result += "\\";
|
|
509
|
-
}
|
|
510
|
-
result += source[i];
|
|
511
|
-
}
|
|
512
|
-
return result;
|
|
513
|
-
}
|
|
514
|
-
function addFormat(schema, value, message, refs) {
|
|
515
|
-
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
516
|
-
if (!schema.anyOf) {
|
|
517
|
-
schema.anyOf = [];
|
|
518
|
-
}
|
|
519
|
-
if (schema.format) {
|
|
520
|
-
schema.anyOf.push({
|
|
521
|
-
format: schema.format,
|
|
522
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
523
|
-
errorMessage: { format: schema.errorMessage.format }
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
delete schema.format;
|
|
527
|
-
if (schema.errorMessage) {
|
|
528
|
-
delete schema.errorMessage.format;
|
|
529
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
530
|
-
delete schema.errorMessage;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
schema.anyOf.push({
|
|
535
|
-
format: value,
|
|
536
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
537
|
-
});
|
|
538
|
-
} else {
|
|
539
|
-
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
function addPattern(schema, regex, message, refs) {
|
|
543
|
-
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
544
|
-
if (!schema.allOf) {
|
|
545
|
-
schema.allOf = [];
|
|
546
|
-
}
|
|
547
|
-
if (schema.pattern) {
|
|
548
|
-
schema.allOf.push({
|
|
549
|
-
pattern: schema.pattern,
|
|
550
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
551
|
-
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
delete schema.pattern;
|
|
555
|
-
if (schema.errorMessage) {
|
|
556
|
-
delete schema.errorMessage.pattern;
|
|
557
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
558
|
-
delete schema.errorMessage;
|
|
559
380
|
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
i: regex.flags.includes("i"),
|
|
576
|
-
m: regex.flags.includes("m"),
|
|
577
|
-
s: regex.flags.includes("s")
|
|
578
|
-
// `.` matches newlines
|
|
579
|
-
};
|
|
580
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
581
|
-
let pattern = "";
|
|
582
|
-
let isEscaped = false;
|
|
583
|
-
let inCharGroup = false;
|
|
584
|
-
let inCharRange = false;
|
|
585
|
-
for (let i = 0; i < source.length; i++) {
|
|
586
|
-
if (isEscaped) {
|
|
587
|
-
pattern += source[i];
|
|
588
|
-
isEscaped = false;
|
|
589
|
-
continue;
|
|
590
|
-
}
|
|
591
|
-
if (flags.i) {
|
|
592
|
-
if (inCharGroup) {
|
|
593
|
-
if (source[i].match(/[a-z]/)) {
|
|
594
|
-
if (inCharRange) {
|
|
595
|
-
pattern += source[i];
|
|
596
|
-
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
597
|
-
inCharRange = false;
|
|
598
|
-
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
599
|
-
pattern += source[i];
|
|
600
|
-
inCharRange = true;
|
|
601
|
-
} else {
|
|
602
|
-
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
381
|
+
};
|
|
382
|
+
chart.setConfig(config);
|
|
383
|
+
const imageBuffer = await chart.toBinary();
|
|
384
|
+
const base64Image = imageBuffer.toString("base64");
|
|
385
|
+
return {
|
|
386
|
+
content: [
|
|
387
|
+
{
|
|
388
|
+
type: "image",
|
|
389
|
+
image: {
|
|
390
|
+
source: {
|
|
391
|
+
data: base64Image
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
uri: "getStockGraph",
|
|
395
|
+
mimeType: "image/png"
|
|
603
396
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
]
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
pattern += `($|(?=[\r
|
|
618
|
-
]))`;
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
if (flags.s && source[i] === ".") {
|
|
623
|
-
pattern += inCharGroup ? `${source[i]}\r
|
|
624
|
-
` : `[${source[i]}\r
|
|
625
|
-
]`;
|
|
626
|
-
continue;
|
|
627
|
-
}
|
|
628
|
-
pattern += source[i];
|
|
629
|
-
if (source[i] === "\\") {
|
|
630
|
-
isEscaped = true;
|
|
631
|
-
} else if (inCharGroup && source[i] === "]") {
|
|
632
|
-
inCharGroup = false;
|
|
633
|
-
} else if (!inCharGroup && source[i] === "[") {
|
|
634
|
-
inCharGroup = true;
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
try {
|
|
638
|
-
new RegExp(pattern);
|
|
639
|
-
} catch {
|
|
640
|
-
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
641
|
-
return regex.source;
|
|
642
|
-
}
|
|
643
|
-
return pattern;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
647
|
-
function parseRecordDef(def, refs) {
|
|
648
|
-
if (refs.target === "openAi") {
|
|
649
|
-
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
650
|
-
}
|
|
651
|
-
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
652
|
-
return {
|
|
653
|
-
type: "object",
|
|
654
|
-
required: def.keyType._def.values,
|
|
655
|
-
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
656
|
-
...acc,
|
|
657
|
-
[key]: parseDef(def.valueType._def, {
|
|
658
|
-
...refs,
|
|
659
|
-
currentPath: [...refs.currentPath, "properties", key]
|
|
660
|
-
}) ?? {}
|
|
661
|
-
}), {}),
|
|
662
|
-
additionalProperties: refs.rejectedAdditionalProperties
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
const schema = {
|
|
666
|
-
type: "object",
|
|
667
|
-
additionalProperties: parseDef(def.valueType._def, {
|
|
668
|
-
...refs,
|
|
669
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
670
|
-
}) ?? refs.allowedAdditionalProperties
|
|
671
|
-
};
|
|
672
|
-
if (refs.target === "openApi3") {
|
|
673
|
-
return schema;
|
|
674
|
-
}
|
|
675
|
-
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
676
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
677
|
-
return {
|
|
678
|
-
...schema,
|
|
679
|
-
propertyNames: keyType
|
|
680
|
-
};
|
|
681
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
682
|
-
return {
|
|
683
|
-
...schema,
|
|
684
|
-
propertyNames: {
|
|
685
|
-
enum: def.keyType._def.values
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
689
|
-
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
690
|
-
return {
|
|
691
|
-
...schema,
|
|
692
|
-
propertyNames: keyType
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
return schema;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
699
|
-
function parseMapDef(def, refs) {
|
|
700
|
-
if (refs.mapStrategy === "record") {
|
|
701
|
-
return parseRecordDef(def, refs);
|
|
702
|
-
}
|
|
703
|
-
const keys = parseDef(def.keyType._def, {
|
|
704
|
-
...refs,
|
|
705
|
-
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
706
|
-
}) || {};
|
|
707
|
-
const values = parseDef(def.valueType._def, {
|
|
708
|
-
...refs,
|
|
709
|
-
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
710
|
-
}) || {};
|
|
711
|
-
return {
|
|
712
|
-
type: "array",
|
|
713
|
-
maxItems: 125,
|
|
714
|
-
items: {
|
|
715
|
-
type: "array",
|
|
716
|
-
items: [keys, values],
|
|
717
|
-
minItems: 2,
|
|
718
|
-
maxItems: 2
|
|
397
|
+
]
|
|
398
|
+
};
|
|
399
|
+
} catch (error) {
|
|
400
|
+
return {
|
|
401
|
+
content: [
|
|
402
|
+
{
|
|
403
|
+
type: "text",
|
|
404
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
|
|
405
|
+
uri: "getStockGraph"
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
isError: true
|
|
409
|
+
};
|
|
719
410
|
}
|
|
720
411
|
};
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
724
|
-
function parseNativeEnumDef(def) {
|
|
725
|
-
const object = def.values;
|
|
726
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
727
|
-
return typeof object[object[key]] !== "number";
|
|
728
|
-
});
|
|
729
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
730
|
-
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
731
|
-
return {
|
|
732
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
733
|
-
enum: actualValues
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
738
|
-
function parseNeverDef() {
|
|
739
|
-
return {
|
|
740
|
-
not: {}
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
745
|
-
function parseNullDef(refs) {
|
|
746
|
-
return refs.target === "openApi3" ? {
|
|
747
|
-
enum: ["null"],
|
|
748
|
-
nullable: true
|
|
749
|
-
} : {
|
|
750
|
-
type: "null"
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
755
|
-
var primitiveMappings = {
|
|
756
|
-
ZodString: "string",
|
|
757
|
-
ZodNumber: "number",
|
|
758
|
-
ZodBigInt: "integer",
|
|
759
|
-
ZodBoolean: "boolean",
|
|
760
|
-
ZodNull: "null"
|
|
761
412
|
};
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
switch (type) {
|
|
778
|
-
case "string":
|
|
779
|
-
case "number":
|
|
780
|
-
case "boolean":
|
|
781
|
-
return [...acc, type];
|
|
782
|
-
case "bigint":
|
|
783
|
-
return [...acc, "integer"];
|
|
784
|
-
case "object":
|
|
785
|
-
if (x._def.value === null)
|
|
786
|
-
return [...acc, "null"];
|
|
787
|
-
case "symbol":
|
|
788
|
-
case "undefined":
|
|
789
|
-
case "function":
|
|
790
|
-
default:
|
|
791
|
-
return acc;
|
|
413
|
+
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
414
|
+
return async (args) => {
|
|
415
|
+
try {
|
|
416
|
+
const symbol = args.symbol;
|
|
417
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
418
|
+
if (priceHistory.length === 0) {
|
|
419
|
+
return {
|
|
420
|
+
content: [
|
|
421
|
+
{
|
|
422
|
+
type: "text",
|
|
423
|
+
text: `No price data available for ${symbol}`,
|
|
424
|
+
uri: "getStockPriceHistory"
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
};
|
|
792
428
|
}
|
|
793
|
-
}, []);
|
|
794
|
-
if (types.length === options.length) {
|
|
795
|
-
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
796
429
|
return {
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
430
|
+
content: [
|
|
431
|
+
{
|
|
432
|
+
type: "text",
|
|
433
|
+
text: JSON.stringify(
|
|
434
|
+
{
|
|
435
|
+
symbol,
|
|
436
|
+
count: priceHistory.length,
|
|
437
|
+
data: priceHistory.map((point) => ({
|
|
438
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
439
|
+
bid: point.bid,
|
|
440
|
+
offer: point.offer,
|
|
441
|
+
spread: point.spread,
|
|
442
|
+
volume: point.volume
|
|
443
|
+
}))
|
|
444
|
+
},
|
|
445
|
+
null,
|
|
446
|
+
2
|
|
447
|
+
),
|
|
448
|
+
uri: "getStockPriceHistory"
|
|
449
|
+
}
|
|
450
|
+
]
|
|
801
451
|
};
|
|
802
|
-
}
|
|
803
|
-
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
804
|
-
return {
|
|
805
|
-
type: "string",
|
|
806
|
-
enum: options.reduce((acc, x) => [
|
|
807
|
-
...acc,
|
|
808
|
-
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
809
|
-
], [])
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
return asAnyOf(def, refs);
|
|
813
|
-
}
|
|
814
|
-
var asAnyOf = (def, refs) => {
|
|
815
|
-
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
816
|
-
...refs,
|
|
817
|
-
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
818
|
-
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
819
|
-
return anyOf.length ? { anyOf } : void 0;
|
|
820
|
-
};
|
|
821
|
-
|
|
822
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
823
|
-
function parseNullableDef(def, refs) {
|
|
824
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
825
|
-
if (refs.target === "openApi3") {
|
|
452
|
+
} catch (error) {
|
|
826
453
|
return {
|
|
827
|
-
|
|
828
|
-
|
|
454
|
+
content: [
|
|
455
|
+
{
|
|
456
|
+
type: "text",
|
|
457
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
458
|
+
uri: "getStockPriceHistory"
|
|
459
|
+
}
|
|
460
|
+
],
|
|
461
|
+
isError: true
|
|
829
462
|
};
|
|
830
463
|
}
|
|
831
|
-
return {
|
|
832
|
-
type: [
|
|
833
|
-
primitiveMappings[def.innerType._def.typeName],
|
|
834
|
-
"null"
|
|
835
|
-
]
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
if (refs.target === "openApi3") {
|
|
839
|
-
const base2 = parseDef(def.innerType._def, {
|
|
840
|
-
...refs,
|
|
841
|
-
currentPath: [...refs.currentPath]
|
|
842
|
-
});
|
|
843
|
-
if (base2 && "$ref" in base2)
|
|
844
|
-
return { allOf: [base2], nullable: true };
|
|
845
|
-
return base2 && { ...base2, nullable: true };
|
|
846
|
-
}
|
|
847
|
-
const base = parseDef(def.innerType._def, {
|
|
848
|
-
...refs,
|
|
849
|
-
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
850
|
-
});
|
|
851
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
855
|
-
function parseNumberDef(def, refs) {
|
|
856
|
-
const res = {
|
|
857
|
-
type: "number"
|
|
858
464
|
};
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/tools/order.ts
|
|
468
|
+
import { Field as Field2, Fields as Fields2, Messages as Messages2 } from "fixparser";
|
|
469
|
+
var ordTypeNames = {
|
|
470
|
+
"1": "Market",
|
|
471
|
+
"2": "Limit",
|
|
472
|
+
"3": "Stop",
|
|
473
|
+
"4": "StopLimit",
|
|
474
|
+
"5": "MarketOnClose",
|
|
475
|
+
"6": "WithOrWithout",
|
|
476
|
+
"7": "LimitOrBetter",
|
|
477
|
+
"8": "LimitWithOrWithout",
|
|
478
|
+
"9": "OnBasis",
|
|
479
|
+
A: "OnClose",
|
|
480
|
+
B: "LimitOnClose",
|
|
481
|
+
C: "ForexMarket",
|
|
482
|
+
D: "PreviouslyQuoted",
|
|
483
|
+
E: "PreviouslyIndicated",
|
|
484
|
+
F: "ForexLimit",
|
|
485
|
+
G: "ForexSwap",
|
|
486
|
+
H: "ForexPreviouslyQuoted",
|
|
487
|
+
I: "Funari",
|
|
488
|
+
J: "MarketIfTouched",
|
|
489
|
+
K: "MarketWithLeftOverAsLimit",
|
|
490
|
+
L: "PreviousFundValuationPoint",
|
|
491
|
+
M: "NextFundValuationPoint",
|
|
492
|
+
P: "Pegged",
|
|
493
|
+
Q: "CounterOrderSelection",
|
|
494
|
+
R: "StopOnBidOrOffer",
|
|
495
|
+
S: "StopLimitOnBidOrOffer"
|
|
496
|
+
};
|
|
497
|
+
var sideNames = {
|
|
498
|
+
"1": "Buy",
|
|
499
|
+
"2": "Sell",
|
|
500
|
+
"3": "BuyMinus",
|
|
501
|
+
"4": "SellPlus",
|
|
502
|
+
"5": "SellShort",
|
|
503
|
+
"6": "SellShortExempt",
|
|
504
|
+
"7": "Undisclosed",
|
|
505
|
+
"8": "Cross",
|
|
506
|
+
"9": "CrossShort",
|
|
507
|
+
A: "CrossShortExempt",
|
|
508
|
+
B: "AsDefined",
|
|
509
|
+
C: "Opposite",
|
|
510
|
+
D: "Subscribe",
|
|
511
|
+
E: "Redeem",
|
|
512
|
+
F: "Lend",
|
|
513
|
+
G: "Borrow",
|
|
514
|
+
H: "SellUndisclosed"
|
|
515
|
+
};
|
|
516
|
+
var timeInForceNames = {
|
|
517
|
+
"0": "Day",
|
|
518
|
+
"1": "GoodTillCancel",
|
|
519
|
+
"2": "AtTheOpening",
|
|
520
|
+
"3": "ImmediateOrCancel",
|
|
521
|
+
"4": "FillOrKill",
|
|
522
|
+
"5": "GoodTillCrossing",
|
|
523
|
+
"6": "GoodTillDate",
|
|
524
|
+
"7": "AtTheClose",
|
|
525
|
+
"8": "GoodThroughCrossing",
|
|
526
|
+
"9": "AtCrossing",
|
|
527
|
+
A: "GoodForTime",
|
|
528
|
+
B: "GoodForAuction",
|
|
529
|
+
C: "GoodForMonth"
|
|
530
|
+
};
|
|
531
|
+
var handlInstNames = {
|
|
532
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
533
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
534
|
+
"3": "ManualOrder"
|
|
535
|
+
};
|
|
536
|
+
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
537
|
+
return async (args) => {
|
|
538
|
+
try {
|
|
539
|
+
verifiedOrders.set(args.clOrdID, {
|
|
540
|
+
clOrdID: args.clOrdID,
|
|
541
|
+
handlInst: args.handlInst,
|
|
542
|
+
quantity: Number.parseFloat(String(args.quantity)),
|
|
543
|
+
price: Number.parseFloat(String(args.price)),
|
|
544
|
+
ordType: args.ordType,
|
|
545
|
+
side: args.side,
|
|
546
|
+
symbol: args.symbol,
|
|
547
|
+
timeInForce: args.timeInForce
|
|
548
|
+
});
|
|
549
|
+
return {
|
|
550
|
+
content: [
|
|
551
|
+
{
|
|
552
|
+
type: "text",
|
|
553
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
554
|
+
|
|
555
|
+
Parameters verified:
|
|
556
|
+
- ClOrdID: ${args.clOrdID}
|
|
557
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
558
|
+
- Quantity: ${args.quantity}
|
|
559
|
+
- Price: ${args.price}
|
|
560
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
561
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
562
|
+
- Symbol: ${args.symbol}
|
|
563
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
564
|
+
|
|
565
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
566
|
+
uri: "verifyOrder"
|
|
887
567
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
568
|
+
]
|
|
569
|
+
};
|
|
570
|
+
} catch (error) {
|
|
571
|
+
return {
|
|
572
|
+
content: [
|
|
573
|
+
{
|
|
574
|
+
type: "text",
|
|
575
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
576
|
+
uri: "verifyOrder"
|
|
891
577
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
case "multipleOf":
|
|
896
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
897
|
-
break;
|
|
578
|
+
],
|
|
579
|
+
isError: true
|
|
580
|
+
};
|
|
898
581
|
}
|
|
899
|
-
}
|
|
900
|
-
return res;
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
904
|
-
import { ZodOptional } from "zod";
|
|
905
|
-
function parseObjectDef(def, refs) {
|
|
906
|
-
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
907
|
-
const result = {
|
|
908
|
-
type: "object",
|
|
909
|
-
properties: {}
|
|
910
582
|
};
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
583
|
+
};
|
|
584
|
+
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
585
|
+
return async (args) => {
|
|
586
|
+
try {
|
|
587
|
+
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
588
|
+
if (!verifiedOrder) {
|
|
589
|
+
return {
|
|
590
|
+
content: [
|
|
591
|
+
{
|
|
592
|
+
type: "text",
|
|
593
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
594
|
+
uri: "executeOrder"
|
|
595
|
+
}
|
|
596
|
+
],
|
|
597
|
+
isError: true
|
|
598
|
+
};
|
|
922
599
|
}
|
|
923
|
-
if (
|
|
924
|
-
|
|
600
|
+
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) {
|
|
601
|
+
return {
|
|
602
|
+
content: [
|
|
603
|
+
{
|
|
604
|
+
type: "text",
|
|
605
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
606
|
+
uri: "executeOrder"
|
|
607
|
+
}
|
|
608
|
+
],
|
|
609
|
+
isError: true
|
|
610
|
+
};
|
|
925
611
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
612
|
+
const response = new Promise((resolve) => {
|
|
613
|
+
pendingRequests.set(args.clOrdID, resolve);
|
|
614
|
+
});
|
|
615
|
+
const order = parser.createMessage(
|
|
616
|
+
new Field2(Fields2.MsgType, Messages2.NewOrderSingle),
|
|
617
|
+
new Field2(Fields2.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
618
|
+
new Field2(Fields2.SenderCompID, parser.sender),
|
|
619
|
+
new Field2(Fields2.TargetCompID, parser.target),
|
|
620
|
+
new Field2(Fields2.SendingTime, parser.getTimestamp()),
|
|
621
|
+
new Field2(Fields2.ClOrdID, args.clOrdID),
|
|
622
|
+
new Field2(Fields2.Side, args.side),
|
|
623
|
+
new Field2(Fields2.Symbol, args.symbol),
|
|
624
|
+
new Field2(Fields2.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
625
|
+
new Field2(Fields2.Price, Number.parseFloat(String(args.price))),
|
|
626
|
+
new Field2(Fields2.OrdType, args.ordType),
|
|
627
|
+
new Field2(Fields2.HandlInst, args.handlInst),
|
|
628
|
+
new Field2(Fields2.TimeInForce, args.timeInForce),
|
|
629
|
+
new Field2(Fields2.TransactTime, parser.getTimestamp())
|
|
630
|
+
);
|
|
631
|
+
if (!parser.connected) {
|
|
632
|
+
return {
|
|
633
|
+
content: [
|
|
634
|
+
{
|
|
635
|
+
type: "text",
|
|
636
|
+
text: "Error: Not connected. Ignoring message.",
|
|
637
|
+
uri: "executeOrder"
|
|
638
|
+
}
|
|
639
|
+
],
|
|
640
|
+
isError: true
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
parser.send(order);
|
|
644
|
+
const fixData = await response;
|
|
645
|
+
verifiedOrders.delete(args.clOrdID);
|
|
646
|
+
return {
|
|
647
|
+
content: [
|
|
648
|
+
{
|
|
649
|
+
type: "text",
|
|
650
|
+
text: fixData.messageType === Messages2.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
651
|
+
uri: "executeOrder"
|
|
652
|
+
}
|
|
653
|
+
]
|
|
654
|
+
};
|
|
655
|
+
} catch (error) {
|
|
656
|
+
return {
|
|
657
|
+
content: [
|
|
658
|
+
{
|
|
659
|
+
type: "text",
|
|
660
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
661
|
+
uri: "executeOrder"
|
|
662
|
+
}
|
|
663
|
+
],
|
|
664
|
+
isError: true
|
|
665
|
+
};
|
|
939
666
|
}
|
|
940
|
-
}
|
|
941
|
-
if (required.length) {
|
|
942
|
-
result.required = required;
|
|
943
|
-
}
|
|
944
|
-
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
945
|
-
if (additionalProperties !== void 0) {
|
|
946
|
-
result.additionalProperties = additionalProperties;
|
|
947
|
-
}
|
|
948
|
-
return result;
|
|
949
|
-
}
|
|
950
|
-
function decideAdditionalProperties(def, refs) {
|
|
951
|
-
if (def.catchall._def.typeName !== "ZodNever") {
|
|
952
|
-
return parseDef(def.catchall._def, {
|
|
953
|
-
...refs,
|
|
954
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
switch (def.unknownKeys) {
|
|
958
|
-
case "passthrough":
|
|
959
|
-
return refs.allowedAdditionalProperties;
|
|
960
|
-
case "strict":
|
|
961
|
-
return refs.rejectedAdditionalProperties;
|
|
962
|
-
case "strip":
|
|
963
|
-
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
function safeIsOptional(schema) {
|
|
967
|
-
try {
|
|
968
|
-
return schema.isOptional();
|
|
969
|
-
} catch {
|
|
970
|
-
return true;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
975
|
-
var parseOptionalDef = (def, refs) => {
|
|
976
|
-
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
977
|
-
return parseDef(def.innerType._def, refs);
|
|
978
|
-
}
|
|
979
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
980
|
-
...refs,
|
|
981
|
-
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
982
|
-
});
|
|
983
|
-
return innerSchema ? {
|
|
984
|
-
anyOf: [
|
|
985
|
-
{
|
|
986
|
-
not: {}
|
|
987
|
-
},
|
|
988
|
-
innerSchema
|
|
989
|
-
]
|
|
990
|
-
} : {};
|
|
991
|
-
};
|
|
992
|
-
|
|
993
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
994
|
-
var parsePipelineDef = (def, refs) => {
|
|
995
|
-
if (refs.pipeStrategy === "input") {
|
|
996
|
-
return parseDef(def.in._def, refs);
|
|
997
|
-
} else if (refs.pipeStrategy === "output") {
|
|
998
|
-
return parseDef(def.out._def, refs);
|
|
999
|
-
}
|
|
1000
|
-
const a = parseDef(def.in._def, {
|
|
1001
|
-
...refs,
|
|
1002
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1003
|
-
});
|
|
1004
|
-
const b = parseDef(def.out._def, {
|
|
1005
|
-
...refs,
|
|
1006
|
-
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1007
|
-
});
|
|
1008
|
-
return {
|
|
1009
|
-
allOf: [a, b].filter((x) => x !== void 0)
|
|
1010
|
-
};
|
|
1011
|
-
};
|
|
1012
|
-
|
|
1013
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1014
|
-
function parsePromiseDef(def, refs) {
|
|
1015
|
-
return parseDef(def.type._def, refs);
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1019
|
-
function parseSetDef(def, refs) {
|
|
1020
|
-
const items = parseDef(def.valueType._def, {
|
|
1021
|
-
...refs,
|
|
1022
|
-
currentPath: [...refs.currentPath, "items"]
|
|
1023
|
-
});
|
|
1024
|
-
const schema = {
|
|
1025
|
-
type: "array",
|
|
1026
|
-
uniqueItems: true,
|
|
1027
|
-
items
|
|
1028
|
-
};
|
|
1029
|
-
if (def.minSize) {
|
|
1030
|
-
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1031
|
-
}
|
|
1032
|
-
if (def.maxSize) {
|
|
1033
|
-
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1034
|
-
}
|
|
1035
|
-
return schema;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1039
|
-
function parseTupleDef(def, refs) {
|
|
1040
|
-
if (def.rest) {
|
|
1041
|
-
return {
|
|
1042
|
-
type: "array",
|
|
1043
|
-
minItems: def.items.length,
|
|
1044
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1045
|
-
...refs,
|
|
1046
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1047
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
1048
|
-
additionalItems: parseDef(def.rest._def, {
|
|
1049
|
-
...refs,
|
|
1050
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1051
|
-
})
|
|
1052
|
-
};
|
|
1053
|
-
} else {
|
|
1054
|
-
return {
|
|
1055
|
-
type: "array",
|
|
1056
|
-
minItems: def.items.length,
|
|
1057
|
-
maxItems: def.items.length,
|
|
1058
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1059
|
-
...refs,
|
|
1060
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1061
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1067
|
-
function parseUndefinedDef() {
|
|
1068
|
-
return {
|
|
1069
|
-
not: {}
|
|
1070
667
|
};
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1074
|
-
function parseUnknownDef() {
|
|
1075
|
-
return {};
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1079
|
-
var parseReadonlyDef = (def, refs) => {
|
|
1080
|
-
return parseDef(def.innerType._def, refs);
|
|
1081
668
|
};
|
|
1082
669
|
|
|
1083
|
-
//
|
|
1084
|
-
var
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
return parseUndefinedDef();
|
|
1100
|
-
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1101
|
-
return parseNullDef(refs);
|
|
1102
|
-
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1103
|
-
return parseArrayDef(def, refs);
|
|
1104
|
-
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1105
|
-
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1106
|
-
return parseUnionDef(def, refs);
|
|
1107
|
-
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1108
|
-
return parseIntersectionDef(def, refs);
|
|
1109
|
-
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1110
|
-
return parseTupleDef(def, refs);
|
|
1111
|
-
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1112
|
-
return parseRecordDef(def, refs);
|
|
1113
|
-
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1114
|
-
return parseLiteralDef(def, refs);
|
|
1115
|
-
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1116
|
-
return parseEnumDef(def);
|
|
1117
|
-
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1118
|
-
return parseNativeEnumDef(def);
|
|
1119
|
-
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1120
|
-
return parseNullableDef(def, refs);
|
|
1121
|
-
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1122
|
-
return parseOptionalDef(def, refs);
|
|
1123
|
-
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1124
|
-
return parseMapDef(def, refs);
|
|
1125
|
-
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1126
|
-
return parseSetDef(def, refs);
|
|
1127
|
-
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1128
|
-
return () => def.getter()._def;
|
|
1129
|
-
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1130
|
-
return parsePromiseDef(def, refs);
|
|
1131
|
-
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1132
|
-
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1133
|
-
return parseNeverDef();
|
|
1134
|
-
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1135
|
-
return parseEffectsDef(def, refs);
|
|
1136
|
-
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1137
|
-
return parseAnyDef();
|
|
1138
|
-
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1139
|
-
return parseUnknownDef();
|
|
1140
|
-
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1141
|
-
return parseDefaultDef(def, refs);
|
|
1142
|
-
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1143
|
-
return parseBrandedDef(def, refs);
|
|
1144
|
-
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1145
|
-
return parseReadonlyDef(def, refs);
|
|
1146
|
-
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1147
|
-
return parseCatchDef(def, refs);
|
|
1148
|
-
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1149
|
-
return parsePipelineDef(def, refs);
|
|
1150
|
-
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1151
|
-
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1152
|
-
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1153
|
-
return void 0;
|
|
1154
|
-
default:
|
|
1155
|
-
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1160
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
1161
|
-
const seenItem = refs.seen.get(def);
|
|
1162
|
-
if (refs.override) {
|
|
1163
|
-
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1164
|
-
if (overrideResult !== ignoreOverride) {
|
|
1165
|
-
return overrideResult;
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
if (seenItem && !forceResolution) {
|
|
1169
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
1170
|
-
if (seenSchema !== void 0) {
|
|
1171
|
-
return seenSchema;
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1175
|
-
refs.seen.set(def, newItem);
|
|
1176
|
-
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1177
|
-
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1178
|
-
if (jsonSchema) {
|
|
1179
|
-
addMeta(def, refs, jsonSchema);
|
|
1180
|
-
}
|
|
1181
|
-
if (refs.postProcess) {
|
|
1182
|
-
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
1183
|
-
newItem.jsonSchema = jsonSchema;
|
|
1184
|
-
return postProcessResult;
|
|
1185
|
-
}
|
|
1186
|
-
newItem.jsonSchema = jsonSchema;
|
|
1187
|
-
return jsonSchema;
|
|
1188
|
-
}
|
|
1189
|
-
var get$ref = (item, refs) => {
|
|
1190
|
-
switch (refs.$refStrategy) {
|
|
1191
|
-
case "root":
|
|
1192
|
-
return { $ref: item.path.join("/") };
|
|
1193
|
-
case "relative":
|
|
1194
|
-
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1195
|
-
case "none":
|
|
1196
|
-
case "seen": {
|
|
1197
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1198
|
-
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1199
|
-
return {};
|
|
670
|
+
// src/tools/parse.ts
|
|
671
|
+
var createParseHandler = (parser) => {
|
|
672
|
+
return async (args) => {
|
|
673
|
+
try {
|
|
674
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
675
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
676
|
+
return {
|
|
677
|
+
content: [
|
|
678
|
+
{
|
|
679
|
+
type: "text",
|
|
680
|
+
text: "Error: Failed to parse FIX string",
|
|
681
|
+
uri: "parse"
|
|
682
|
+
}
|
|
683
|
+
],
|
|
684
|
+
isError: true
|
|
685
|
+
};
|
|
1200
686
|
}
|
|
1201
|
-
return
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
687
|
+
return {
|
|
688
|
+
content: [
|
|
689
|
+
{
|
|
690
|
+
type: "text",
|
|
691
|
+
text: `${parsedMessage[0].description}
|
|
692
|
+
${parsedMessage[0].messageTypeDescription}`,
|
|
693
|
+
uri: "parse"
|
|
694
|
+
}
|
|
695
|
+
]
|
|
696
|
+
};
|
|
697
|
+
} catch (error) {
|
|
698
|
+
return {
|
|
699
|
+
content: [
|
|
700
|
+
{
|
|
701
|
+
type: "text",
|
|
702
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
703
|
+
uri: "parse"
|
|
704
|
+
}
|
|
705
|
+
],
|
|
706
|
+
isError: true
|
|
707
|
+
};
|
|
1218
708
|
}
|
|
1219
|
-
}
|
|
1220
|
-
return jsonSchema;
|
|
709
|
+
};
|
|
1221
710
|
};
|
|
1222
711
|
|
|
1223
|
-
//
|
|
1224
|
-
var
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
712
|
+
// src/tools/parseToJSON.ts
|
|
713
|
+
var createParseToJSONHandler = (parser) => {
|
|
714
|
+
return async (args) => {
|
|
715
|
+
try {
|
|
716
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
717
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
718
|
+
return {
|
|
719
|
+
content: [
|
|
720
|
+
{
|
|
721
|
+
type: "text",
|
|
722
|
+
text: "Error: Failed to parse FIX string",
|
|
723
|
+
uri: "parseToJSON"
|
|
724
|
+
}
|
|
725
|
+
],
|
|
726
|
+
isError: true
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
return {
|
|
730
|
+
content: [
|
|
731
|
+
{
|
|
732
|
+
type: "text",
|
|
733
|
+
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
734
|
+
uri: "parseToJSON"
|
|
735
|
+
}
|
|
736
|
+
]
|
|
737
|
+
};
|
|
738
|
+
} catch (error) {
|
|
739
|
+
return {
|
|
740
|
+
content: [
|
|
741
|
+
{
|
|
742
|
+
type: "text",
|
|
743
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
744
|
+
uri: "parseToJSON"
|
|
745
|
+
}
|
|
746
|
+
],
|
|
747
|
+
isError: true
|
|
748
|
+
};
|
|
1254
749
|
}
|
|
1255
750
|
};
|
|
1256
|
-
if (refs.target === "jsonSchema7") {
|
|
1257
|
-
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1258
|
-
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
1259
|
-
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1260
|
-
}
|
|
1261
|
-
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
1262
|
-
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
1263
|
-
}
|
|
1264
|
-
return combined;
|
|
1265
751
|
};
|
|
1266
752
|
|
|
753
|
+
// src/tools/index.ts
|
|
754
|
+
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
755
|
+
parse: createParseHandler(parser),
|
|
756
|
+
parseToJSON: createParseToJSONHandler(parser),
|
|
757
|
+
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
758
|
+
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
759
|
+
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
760
|
+
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
761
|
+
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
762
|
+
});
|
|
763
|
+
|
|
1267
764
|
// src/MCPLocal.ts
|
|
1268
|
-
import {
|
|
1269
|
-
Field,
|
|
1270
|
-
Fields,
|
|
1271
|
-
HandlInst,
|
|
1272
|
-
MDEntryType,
|
|
1273
|
-
Messages,
|
|
1274
|
-
OrdType,
|
|
1275
|
-
SubscriptionRequestType,
|
|
1276
|
-
TimeInForce
|
|
1277
|
-
} from "fixparser";
|
|
1278
765
|
var MCPLocal = class {
|
|
1279
|
-
logger;
|
|
1280
766
|
parser;
|
|
1281
767
|
server = new Server(
|
|
1282
768
|
{
|
|
@@ -1284,39 +770,106 @@ var MCPLocal = class {
|
|
|
1284
770
|
version: "1.0.0"
|
|
1285
771
|
},
|
|
1286
772
|
{
|
|
1287
|
-
capabilities: {
|
|
773
|
+
capabilities: {
|
|
774
|
+
tools: Object.entries(toolSchemas).reduce(
|
|
775
|
+
(acc, [name, { description, schema }]) => {
|
|
776
|
+
acc[name] = {
|
|
777
|
+
description,
|
|
778
|
+
parameters: schema
|
|
779
|
+
};
|
|
780
|
+
return acc;
|
|
781
|
+
},
|
|
782
|
+
{}
|
|
783
|
+
)
|
|
784
|
+
}
|
|
1288
785
|
}
|
|
1289
786
|
);
|
|
1290
787
|
transport = new StdioServerTransport();
|
|
1291
788
|
onReady = void 0;
|
|
1292
789
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
790
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
791
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
792
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
793
|
+
// Maximum number of price points to store per symbol
|
|
1293
794
|
constructor({ logger, onReady }) {
|
|
1294
|
-
if (logger) this.logger = logger;
|
|
1295
795
|
if (onReady) this.onReady = onReady;
|
|
1296
796
|
}
|
|
1297
797
|
async register(parser) {
|
|
1298
798
|
this.parser = parser;
|
|
1299
799
|
this.parser.addOnMessageCallback((message) => {
|
|
1300
|
-
this.logger
|
|
800
|
+
this.parser?.logger.log({
|
|
1301
801
|
level: "info",
|
|
1302
|
-
message: `
|
|
802
|
+
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
1303
803
|
});
|
|
1304
804
|
const msgType = message.messageType;
|
|
1305
|
-
if (msgType ===
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
805
|
+
if (msgType === Messages3.MarketDataSnapshotFullRefresh || msgType === Messages3.ExecutionReport || msgType === Messages3.Reject || msgType === Messages3.MarketDataIncrementalRefresh) {
|
|
806
|
+
this.parser?.logger.log({
|
|
807
|
+
level: "info",
|
|
808
|
+
message: `MCP Server handling message type: ${msgType}`
|
|
809
|
+
});
|
|
810
|
+
let id;
|
|
811
|
+
if (msgType === Messages3.MarketDataIncrementalRefresh || msgType === Messages3.MarketDataSnapshotFullRefresh) {
|
|
812
|
+
const symbol = message.getField(Fields3.Symbol);
|
|
813
|
+
const entryType = message.getField(Fields3.MDEntryType);
|
|
814
|
+
const price = message.getField(Fields3.MDEntryPx);
|
|
815
|
+
const size = message.getField(Fields3.MDEntrySize);
|
|
816
|
+
const timestamp = message.getField(Fields3.MDEntryTime)?.value || Date.now();
|
|
817
|
+
if (symbol?.value && price?.value) {
|
|
818
|
+
const symbolStr = String(symbol.value);
|
|
819
|
+
const priceNum = Number(price.value);
|
|
820
|
+
const sizeNum = size?.value ? Number(size.value) : 0;
|
|
821
|
+
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
822
|
+
const lastEntry = priceHistory[priceHistory.length - 1] || {
|
|
823
|
+
timestamp: 0,
|
|
824
|
+
bid: 0,
|
|
825
|
+
offer: 0,
|
|
826
|
+
spread: 0,
|
|
827
|
+
volume: 0
|
|
828
|
+
};
|
|
829
|
+
const newEntry = {
|
|
830
|
+
timestamp: Number(timestamp),
|
|
831
|
+
bid: entryType?.value === MDEntryType2.Bid ? priceNum : lastEntry.bid,
|
|
832
|
+
offer: entryType?.value === MDEntryType2.Offer ? priceNum : lastEntry.offer,
|
|
833
|
+
spread: entryType?.value === MDEntryType2.Offer ? priceNum - lastEntry.bid : entryType?.value === MDEntryType2.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
|
|
834
|
+
volume: entryType?.value === MDEntryType2.TradeVolume ? sizeNum : lastEntry.volume
|
|
835
|
+
};
|
|
836
|
+
priceHistory.push(newEntry);
|
|
837
|
+
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
838
|
+
priceHistory.shift();
|
|
1314
839
|
}
|
|
840
|
+
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
841
|
+
this.parser?.logger.log({
|
|
842
|
+
level: "info",
|
|
843
|
+
message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
|
|
844
|
+
});
|
|
845
|
+
this.server.notification({
|
|
846
|
+
method: "priceUpdate",
|
|
847
|
+
params: {
|
|
848
|
+
symbol: symbolStr,
|
|
849
|
+
...newEntry
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
if (msgType === Messages3.MarketDataSnapshotFullRefresh) {
|
|
855
|
+
const mdReqID = message.getField(Fields3.MDReqID);
|
|
856
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
857
|
+
} else if (msgType === Messages3.ExecutionReport) {
|
|
858
|
+
const clOrdID = message.getField(Fields3.ClOrdID);
|
|
859
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
860
|
+
} else if (msgType === Messages3.Reject) {
|
|
861
|
+
const refSeqNum = message.getField(Fields3.RefSeqNum);
|
|
862
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
863
|
+
}
|
|
864
|
+
if (id) {
|
|
865
|
+
const callback = this.pendingRequests.get(id);
|
|
866
|
+
if (callback) {
|
|
867
|
+
callback(message);
|
|
868
|
+
this.pendingRequests.delete(id);
|
|
1315
869
|
}
|
|
1316
870
|
}
|
|
1317
871
|
}
|
|
1318
872
|
});
|
|
1319
|
-
this.logger = parser.logger;
|
|
1320
873
|
this.addWorkflows();
|
|
1321
874
|
await this.server.connect(this.transport);
|
|
1322
875
|
if (this.onReady) {
|
|
@@ -1325,448 +878,62 @@ var MCPLocal = class {
|
|
|
1325
878
|
}
|
|
1326
879
|
addWorkflows() {
|
|
1327
880
|
if (!this.parser) {
|
|
1328
|
-
this.logger?.log({
|
|
1329
|
-
level: "error",
|
|
1330
|
-
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
|
|
1331
|
-
});
|
|
1332
881
|
return;
|
|
1333
882
|
}
|
|
1334
883
|
if (!this.server) {
|
|
1335
|
-
this.logger?.log({
|
|
1336
|
-
level: "error",
|
|
1337
|
-
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
|
|
1338
|
-
});
|
|
1339
884
|
return;
|
|
1340
885
|
}
|
|
1341
|
-
this.server.setRequestHandler(
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
{
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
clOrdID: z.string().describe("Client Order ID"),
|
|
1375
|
-
handlInst: z.enum(["1", "2", "3"]).default(HandlInst.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),
|
|
1376
|
-
quantity: z.number().describe("Order quantity"),
|
|
1377
|
-
price: z.number().describe("Order price"),
|
|
1378
|
-
ordType: z.enum([
|
|
1379
|
-
"1",
|
|
1380
|
-
"2",
|
|
1381
|
-
"3",
|
|
1382
|
-
"4",
|
|
1383
|
-
"5",
|
|
1384
|
-
"6",
|
|
1385
|
-
"7",
|
|
1386
|
-
"8",
|
|
1387
|
-
"9",
|
|
1388
|
-
"A",
|
|
1389
|
-
"B",
|
|
1390
|
-
"C",
|
|
1391
|
-
"D",
|
|
1392
|
-
"E",
|
|
1393
|
-
"F",
|
|
1394
|
-
"G",
|
|
1395
|
-
"H",
|
|
1396
|
-
"I",
|
|
1397
|
-
"J",
|
|
1398
|
-
"K",
|
|
1399
|
-
"L",
|
|
1400
|
-
"M",
|
|
1401
|
-
"P",
|
|
1402
|
-
"Q",
|
|
1403
|
-
"R",
|
|
1404
|
-
"S"
|
|
1405
|
-
]).default("1").optional().describe("Order type"),
|
|
1406
|
-
side: z.enum([
|
|
1407
|
-
"1",
|
|
1408
|
-
"2",
|
|
1409
|
-
"3",
|
|
1410
|
-
"4",
|
|
1411
|
-
"5",
|
|
1412
|
-
"6",
|
|
1413
|
-
"7",
|
|
1414
|
-
"8",
|
|
1415
|
-
"9",
|
|
1416
|
-
"A",
|
|
1417
|
-
"B",
|
|
1418
|
-
"C",
|
|
1419
|
-
"D",
|
|
1420
|
-
"E",
|
|
1421
|
-
"F",
|
|
1422
|
-
"G",
|
|
1423
|
-
"H"
|
|
1424
|
-
]).describe("Order side (1=Buy, 2=Sell)"),
|
|
1425
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1426
|
-
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(TimeInForce.Day).optional().describe("Time in force")
|
|
1427
|
-
}),
|
|
1428
|
-
{ name: "NewOrderSingleInput" }
|
|
1429
|
-
)
|
|
1430
|
-
},
|
|
1431
|
-
{
|
|
1432
|
-
name: "marketDataRequest",
|
|
1433
|
-
description: "Sends a request for Market Data with the given symbol",
|
|
1434
|
-
inputSchema: zodToJsonSchema(
|
|
1435
|
-
z.object({
|
|
1436
|
-
mdUpdateType: z.enum(["0", "1"]).default("0").optional().describe("Market data update type"),
|
|
1437
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1438
|
-
mdReqID: z.string().describe("Market data request ID"),
|
|
1439
|
-
subscriptionRequestType: z.enum(["0", "1", "2"]).default(SubscriptionRequestType.SnapshotAndUpdates).optional().describe("Subscription request type"),
|
|
1440
|
-
mdEntryType: z.enum([
|
|
1441
|
-
"0",
|
|
1442
|
-
"1",
|
|
1443
|
-
"2",
|
|
1444
|
-
"3",
|
|
1445
|
-
"4",
|
|
1446
|
-
"5",
|
|
1447
|
-
"6",
|
|
1448
|
-
"7",
|
|
1449
|
-
"8",
|
|
1450
|
-
"9",
|
|
1451
|
-
"A",
|
|
1452
|
-
"B",
|
|
1453
|
-
"C",
|
|
1454
|
-
"D",
|
|
1455
|
-
"E",
|
|
1456
|
-
"F",
|
|
1457
|
-
"G",
|
|
1458
|
-
"H",
|
|
1459
|
-
"J",
|
|
1460
|
-
"K",
|
|
1461
|
-
"L",
|
|
1462
|
-
"M",
|
|
1463
|
-
"N",
|
|
1464
|
-
"O",
|
|
1465
|
-
"P",
|
|
1466
|
-
"Q",
|
|
1467
|
-
"S",
|
|
1468
|
-
"R",
|
|
1469
|
-
"T",
|
|
1470
|
-
"U",
|
|
1471
|
-
"V",
|
|
1472
|
-
"W",
|
|
1473
|
-
"X",
|
|
1474
|
-
"Y",
|
|
1475
|
-
"Z",
|
|
1476
|
-
"a",
|
|
1477
|
-
"b",
|
|
1478
|
-
"c",
|
|
1479
|
-
"d",
|
|
1480
|
-
"e",
|
|
1481
|
-
"g",
|
|
1482
|
-
"h",
|
|
1483
|
-
"i",
|
|
1484
|
-
"t"
|
|
1485
|
-
]).default(MDEntryType.Bid).optional().describe("Market data entry type")
|
|
1486
|
-
}),
|
|
1487
|
-
{ name: "MarketDataRequestInput" }
|
|
1488
|
-
)
|
|
1489
|
-
}
|
|
1490
|
-
]
|
|
1491
|
-
};
|
|
1492
|
-
});
|
|
1493
|
-
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
1494
|
-
const { name, arguments: args } = request.params;
|
|
1495
|
-
switch (name) {
|
|
1496
|
-
case "parse": {
|
|
1497
|
-
const { fixString } = z.object({
|
|
1498
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1499
|
-
}).parse(args || {});
|
|
1500
|
-
try {
|
|
1501
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
1502
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1503
|
-
return {
|
|
1504
|
-
isError: true,
|
|
1505
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
1506
|
-
};
|
|
1507
|
-
}
|
|
1508
|
-
return {
|
|
1509
|
-
content: [
|
|
1510
|
-
{
|
|
1511
|
-
type: "text",
|
|
1512
|
-
text: `Parsed FIX message: ${fixString} (placeholder implementation)`
|
|
1513
|
-
}
|
|
1514
|
-
]
|
|
1515
|
-
};
|
|
1516
|
-
} catch (error) {
|
|
1517
|
-
return {
|
|
1518
|
-
isError: true,
|
|
1519
|
-
content: [
|
|
1520
|
-
{
|
|
1521
|
-
type: "text",
|
|
1522
|
-
text: "Error: Failed to parse FIX string"
|
|
1523
|
-
}
|
|
1524
|
-
]
|
|
1525
|
-
};
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
case "parseToJSON": {
|
|
1529
|
-
const { fixString } = z.object({
|
|
1530
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1531
|
-
}).parse(args || {});
|
|
1532
|
-
try {
|
|
1533
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
1534
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1535
|
-
return {
|
|
1536
|
-
isError: true,
|
|
1537
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
1538
|
-
};
|
|
1539
|
-
}
|
|
1540
|
-
return {
|
|
1541
|
-
content: [
|
|
1542
|
-
{
|
|
1543
|
-
type: "text",
|
|
1544
|
-
text: JSON.stringify({ fixString, parsed: "placeholder" })
|
|
1545
|
-
}
|
|
1546
|
-
]
|
|
1547
|
-
};
|
|
1548
|
-
} catch (error) {
|
|
1549
|
-
return {
|
|
1550
|
-
isError: true,
|
|
1551
|
-
content: [
|
|
1552
|
-
{
|
|
1553
|
-
type: "text",
|
|
1554
|
-
text: "Error: Failed to parse FIX string"
|
|
1555
|
-
}
|
|
1556
|
-
]
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
case "newOrderSingle": {
|
|
1561
|
-
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = z.object({
|
|
1562
|
-
clOrdID: z.string().describe("Client Order ID"),
|
|
1563
|
-
handlInst: z.enum(["1", "2", "3"]).default(HandlInst.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),
|
|
1564
|
-
quantity: z.number().describe("Order quantity"),
|
|
1565
|
-
price: z.number().describe("Order price"),
|
|
1566
|
-
ordType: z.enum([
|
|
1567
|
-
"1",
|
|
1568
|
-
"2",
|
|
1569
|
-
"3",
|
|
1570
|
-
"4",
|
|
1571
|
-
"5",
|
|
1572
|
-
"6",
|
|
1573
|
-
"7",
|
|
1574
|
-
"8",
|
|
1575
|
-
"9",
|
|
1576
|
-
"A",
|
|
1577
|
-
"B",
|
|
1578
|
-
"C",
|
|
1579
|
-
"D",
|
|
1580
|
-
"E",
|
|
1581
|
-
"F",
|
|
1582
|
-
"G",
|
|
1583
|
-
"H",
|
|
1584
|
-
"I",
|
|
1585
|
-
"J",
|
|
1586
|
-
"K",
|
|
1587
|
-
"L",
|
|
1588
|
-
"M",
|
|
1589
|
-
"P",
|
|
1590
|
-
"Q",
|
|
1591
|
-
"R",
|
|
1592
|
-
"S"
|
|
1593
|
-
]).default(OrdType.Market).optional().describe("Order type"),
|
|
1594
|
-
side: z.enum([
|
|
1595
|
-
"1",
|
|
1596
|
-
"2",
|
|
1597
|
-
"3",
|
|
1598
|
-
"4",
|
|
1599
|
-
"5",
|
|
1600
|
-
"6",
|
|
1601
|
-
"7",
|
|
1602
|
-
"8",
|
|
1603
|
-
"9",
|
|
1604
|
-
"A",
|
|
1605
|
-
"B",
|
|
1606
|
-
"C",
|
|
1607
|
-
"D",
|
|
1608
|
-
"E",
|
|
1609
|
-
"F",
|
|
1610
|
-
"G",
|
|
1611
|
-
"H"
|
|
1612
|
-
]).describe("Order side (1=Buy, 2=Sell)"),
|
|
1613
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1614
|
-
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(TimeInForce.Day).optional().describe("Time in force")
|
|
1615
|
-
}).parse(args || {});
|
|
1616
|
-
const response = new Promise((resolve) => {
|
|
1617
|
-
this.pendingRequests.set(clOrdID, resolve);
|
|
1618
|
-
});
|
|
1619
|
-
const order = this.parser?.createMessage(
|
|
1620
|
-
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
1621
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1622
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1623
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1624
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1625
|
-
new Field(Fields.ClOrdID, clOrdID),
|
|
1626
|
-
new Field(Fields.Side, side),
|
|
1627
|
-
new Field(Fields.Symbol, symbol),
|
|
1628
|
-
new Field(Fields.OrderQty, quantity),
|
|
1629
|
-
new Field(Fields.Price, price),
|
|
1630
|
-
new Field(Fields.OrdType, ordType),
|
|
1631
|
-
new Field(Fields.HandlInst, handlInst),
|
|
1632
|
-
new Field(Fields.TimeInForce, timeInForce),
|
|
1633
|
-
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
1634
|
-
);
|
|
1635
|
-
if (!this.parser?.connected) {
|
|
1636
|
-
this.logger?.log({
|
|
1637
|
-
level: "error",
|
|
1638
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
1639
|
-
});
|
|
1640
|
-
return {
|
|
1641
|
-
isError: true,
|
|
1642
|
-
content: [
|
|
1643
|
-
{
|
|
1644
|
-
type: "text",
|
|
1645
|
-
text: "Error: Not connected. Ignoring message."
|
|
1646
|
-
}
|
|
1647
|
-
]
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
this.parser?.send(order);
|
|
1651
|
-
this.logger?.log({
|
|
1652
|
-
level: "info",
|
|
1653
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
1654
|
-
});
|
|
1655
|
-
const fixData = await response;
|
|
1656
|
-
return {
|
|
1657
|
-
content: [
|
|
1658
|
-
{
|
|
1659
|
-
type: "text",
|
|
1660
|
-
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
1661
|
-
}
|
|
1662
|
-
]
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
case "marketDataRequest": {
|
|
1666
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = z.object({
|
|
1667
|
-
mdUpdateType: z.enum(["0", "1"]).default("0").optional().describe("Market data update type"),
|
|
1668
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1669
|
-
mdReqID: z.string().describe("Market data request ID"),
|
|
1670
|
-
subscriptionRequestType: z.enum(["0", "1", "2"]).default(SubscriptionRequestType.SnapshotAndUpdates).optional().describe("Subscription request type"),
|
|
1671
|
-
mdEntryType: z.enum([
|
|
1672
|
-
"0",
|
|
1673
|
-
"1",
|
|
1674
|
-
"2",
|
|
1675
|
-
"3",
|
|
1676
|
-
"4",
|
|
1677
|
-
"5",
|
|
1678
|
-
"6",
|
|
1679
|
-
"7",
|
|
1680
|
-
"8",
|
|
1681
|
-
"9",
|
|
1682
|
-
"A",
|
|
1683
|
-
"B",
|
|
1684
|
-
"C",
|
|
1685
|
-
"D",
|
|
1686
|
-
"E",
|
|
1687
|
-
"F",
|
|
1688
|
-
"G",
|
|
1689
|
-
"H",
|
|
1690
|
-
"J",
|
|
1691
|
-
"K",
|
|
1692
|
-
"L",
|
|
1693
|
-
"M",
|
|
1694
|
-
"N",
|
|
1695
|
-
"O",
|
|
1696
|
-
"P",
|
|
1697
|
-
"Q",
|
|
1698
|
-
"S",
|
|
1699
|
-
"R",
|
|
1700
|
-
"T",
|
|
1701
|
-
"U",
|
|
1702
|
-
"V",
|
|
1703
|
-
"W",
|
|
1704
|
-
"X",
|
|
1705
|
-
"Y",
|
|
1706
|
-
"Z",
|
|
1707
|
-
"a",
|
|
1708
|
-
"b",
|
|
1709
|
-
"c",
|
|
1710
|
-
"d",
|
|
1711
|
-
"e",
|
|
1712
|
-
"g",
|
|
1713
|
-
"h",
|
|
1714
|
-
"i",
|
|
1715
|
-
"t"
|
|
1716
|
-
]).default(MDEntryType.Bid).optional().describe("Market data entry type")
|
|
1717
|
-
}).parse(args || {});
|
|
1718
|
-
const response = new Promise((resolve) => {
|
|
1719
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
1720
|
-
});
|
|
1721
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
1722
|
-
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
1723
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1724
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1725
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1726
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1727
|
-
new Field(Fields.MarketDepth, 0),
|
|
1728
|
-
new Field(Fields.MDUpdateType, mdUpdateType),
|
|
1729
|
-
new Field(Fields.NoRelatedSym, 1),
|
|
1730
|
-
new Field(Fields.Symbol, symbol),
|
|
1731
|
-
new Field(Fields.MDReqID, mdReqID),
|
|
1732
|
-
new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
1733
|
-
new Field(Fields.NoMDEntryTypes, 1),
|
|
1734
|
-
new Field(Fields.MDEntryType, mdEntryType)
|
|
1735
|
-
);
|
|
1736
|
-
if (!this.parser?.connected) {
|
|
1737
|
-
this.logger?.log({
|
|
1738
|
-
level: "error",
|
|
1739
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
1740
|
-
});
|
|
1741
|
-
return {
|
|
1742
|
-
isError: true,
|
|
1743
|
-
content: [
|
|
1744
|
-
{
|
|
1745
|
-
type: "text",
|
|
1746
|
-
text: "Error: Not connected. Ignoring message."
|
|
1747
|
-
}
|
|
1748
|
-
]
|
|
1749
|
-
};
|
|
1750
|
-
}
|
|
1751
|
-
this.parser?.send(marketDataRequest);
|
|
1752
|
-
this.logger?.log({
|
|
1753
|
-
level: "info",
|
|
1754
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
1755
|
-
});
|
|
1756
|
-
const fixData = await response;
|
|
886
|
+
this.server.setRequestHandler(
|
|
887
|
+
z.object({ method: z.literal("tools/list") }),
|
|
888
|
+
async (request, extra) => {
|
|
889
|
+
return {
|
|
890
|
+
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
891
|
+
name,
|
|
892
|
+
description,
|
|
893
|
+
inputSchema: schema
|
|
894
|
+
}))
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
this.server.setRequestHandler(
|
|
899
|
+
z.object({
|
|
900
|
+
method: z.literal("tools/call"),
|
|
901
|
+
params: z.object({
|
|
902
|
+
name: z.string(),
|
|
903
|
+
arguments: z.any(),
|
|
904
|
+
_meta: z.object({
|
|
905
|
+
progressToken: z.number()
|
|
906
|
+
}).optional()
|
|
907
|
+
})
|
|
908
|
+
}),
|
|
909
|
+
async (request, extra) => {
|
|
910
|
+
const { name, arguments: args } = request.params;
|
|
911
|
+
const toolHandlers = createToolHandlers(
|
|
912
|
+
this.parser,
|
|
913
|
+
this.verifiedOrders,
|
|
914
|
+
this.pendingRequests,
|
|
915
|
+
this.marketDataPrices
|
|
916
|
+
);
|
|
917
|
+
const handler = toolHandlers[name];
|
|
918
|
+
if (!handler) {
|
|
1757
919
|
return {
|
|
1758
920
|
content: [
|
|
1759
921
|
{
|
|
1760
922
|
type: "text",
|
|
1761
|
-
text: `
|
|
923
|
+
text: `Tool not found: ${name}`,
|
|
924
|
+
uri: name
|
|
1762
925
|
}
|
|
1763
|
-
]
|
|
926
|
+
],
|
|
927
|
+
isError: true
|
|
1764
928
|
};
|
|
1765
929
|
}
|
|
1766
|
-
|
|
1767
|
-
|
|
930
|
+
const result = await handler(args);
|
|
931
|
+
return {
|
|
932
|
+
content: result.content,
|
|
933
|
+
isError: result.isError
|
|
934
|
+
};
|
|
1768
935
|
}
|
|
1769
|
-
|
|
936
|
+
);
|
|
1770
937
|
process.on("SIGINT", async () => {
|
|
1771
938
|
await this.server.close();
|
|
1772
939
|
process.exit(0);
|