fixparser-plugin-mcp 9.1.7-c213f7c6 → 9.1.7-c415bb75
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 +4 -78
- package/build/cjs/MCPLocal.js.map +2 -2
- package/build/cjs/MCPRemote.js +60 -82
- package/build/cjs/MCPRemote.js.map +2 -2
- package/build/cjs/index.js +60 -82
- package/build/cjs/index.js.map +2 -2
- package/build/esm/MCPLocal.mjs +4 -78
- package/build/esm/MCPLocal.mjs.map +2 -2
- package/build/esm/MCPRemote.mjs +60 -82
- package/build/esm/MCPRemote.mjs.map +2 -2
- package/build/esm/index.mjs +60 -82
- package/build/esm/index.mjs.map +2 -2
- package/build-examples/cjs/example_mcp_local.js +6 -6
- package/build-examples/cjs/example_mcp_local.js.map +3 -3
- package/build-examples/cjs/example_mcp_remote.js +3 -3
- package/build-examples/cjs/example_mcp_remote.js.map +3 -3
- package/build-examples/esm/example_mcp_local.mjs +6 -6
- package/build-examples/esm/example_mcp_local.mjs.map +3 -3
- package/build-examples/esm/example_mcp_remote.mjs +7 -7
- package/build-examples/esm/example_mcp_remote.mjs.map +3 -3
- package/package.json +1 -1
- package/types/MCPRemote.d.ts +1 -1
- package/types/schemas/index.d.ts +0 -1
- package/types/tools/index.d.ts +11 -2
- package/types/tools/marketData.d.ts +24 -3
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{EncryptMethod as K,FIXParser as z,Field as b,Fields as O,LicenseManager as Y,Messages as Z,ResetSeqNumFlag as ee}from"fixparser";var x=class{format;useStderr;constructor({format:t="json",useStderr:a=!1}){this.format=t,this.useStderr=a}configure(t){this.format=t.format||"json",t.useStderr!==void 0&&(this.useStderr=t.useStderr)}async send(t){let a=this.useStderr?console.error:console.log;if(this.format==="json")a(JSON.stringify(t));else if(this.format==="jsonrpc"){let{message:e,...i}=t,r={jsonrpc:"2.0",method:t.level,params:{message:e,...i},id:t.id||Date.now()};a(JSON.stringify(r))}else{let{name:e,id:i,message:r,level:u,...P}=t,d=Object.entries(P).map(([v,o])=>`${v}: ${o}`),m="";e&&(m+=`${e} `),m+=`${i}: ${r}`,a(m,d.join(", "))}}async flush(){}async close(){}status(){return"connected"}};import{Server as E}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as D}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as f}from"zod";import{Field as y,Fields as h,MDEntryType as n,Messages as A}from"fixparser";import B from"quickchart-js";import{Field as p,Fields as g,Messages as w}from"fixparser";import{Fields as C,MDEntryType as s,Messages as k}from"fixparser";import{McpServer as me}from"@modelcontextprotocol/sdk/server/mcp.js";import{StreamableHTTPServerTransport as ge}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{isInitializeRequest as he}from"@modelcontextprotocol/sdk/types.js";import{z as Se}from"zod";var L=class{logger;parser;onReady=void 0;verifiedOrders=new Map;pendingRequests=new Map;marketDataPrices=new Map;MAX_PRICE_HISTORY=1e5;constructor({logger:t,onReady:a}){this.logger=t,this.onReady=a}},R={parse:{description:"Parses a FIX message and describes it in plain language",schema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},parseToJSON:{description:"Parses a FIX message into JSON",schema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},verifyOrder:{description:"Verifies order parameters before execution. verifyOrder must be called before executeOrder.",schema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"],description:"Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"],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"},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],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"},symbol:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],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"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},executeOrder:{description:"Executes a verified order. verifyOrder must be called before executeOrder.",schema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"],description:"Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"],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"},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],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"},symbol:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],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"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},marketDataRequest:{description:"Requests market data for specified symbols",schema:{type:"object",properties:{mdUpdateType:{type:"string",enum:["0","1"],description:"Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"},symbols:{type:"array",items:{type:"string"}},mdReqID:{type:"string"},subscriptionRequestType:{type:"string",enum:["0","1","2"],description:"Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"},mdEntryTypes:{type:"array",items:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]},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"}},required:["mdUpdateType","symbols","mdReqID","subscriptionRequestType"]}},getStockGraph:{description:"Generates a price chart for a given symbol",schema:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},getStockPriceHistory:{description:"Returns price history for a given symbol",schema:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}},N=(t,a)=>async e=>{try{let i=new Promise(m=>{a.set(e.mdReqID,m)}),r=e.mdEntryTypes||[n.Bid,n.Offer,n.Trade,n.IndexValue,n.OpeningPrice,n.ClosingPrice,n.SettlementPrice,n.TradingSessionHighPrice,n.TradingSessionLowPrice,n.VWAP,n.Imbalance,n.TradeVolume,n.OpenInterest,n.CompositeUnderlyingPrice,n.SimulatedSellPrice,n.SimulatedBuyPrice,n.MarginRate,n.MidPrice,n.EmptyBook,n.SettleHighPrice,n.SettleLowPrice,n.PriorSettlePrice,n.SessionHighBid,n.SessionLowOffer,n.EarlyPrices,n.AuctionClearingPrice,n.SwapValueFactor,n.DailyValueAdjustmentForLongPositions,n.CumulativeValueAdjustmentForLongPositions,n.DailyValueAdjustmentForShortPositions,n.CumulativeValueAdjustmentForShortPositions,n.FixingPrice,n.CashRate,n.RecoveryRate,n.RecoveryRateForLong,n.RecoveryRateForShort,n.MarketBid,n.MarketOffer,n.ShortSaleMinPrice,n.PreviousClosingPrice,n.ThresholdLimitPriceBanding,n.DailyFinancingValue,n.AccruedFinancingValue,n.TWAP],u=[new y(h.MsgType,A.MarketDataRequest),new y(h.SenderCompID,t.sender),new y(h.MsgSeqNum,t.getNextTargetMsgSeqNum()),new y(h.TargetCompID,t.target),new y(h.SendingTime,t.getTimestamp()),new y(h.MDReqID,e.mdReqID),new y(h.SubscriptionRequestType,e.subscriptionRequestType),new y(h.MarketDepth,0),new y(h.MDUpdateType,e.mdUpdateType)];u.push(new y(h.NoRelatedSym,e.symbols.length)),e.symbols.forEach(m=>{u.push(new y(h.Symbol,m))}),u.push(new y(h.NoMDEntryTypes,r.length)),r.forEach(m=>{u.push(new y(h.MDEntryType,m))});let P=t.createMessage(...u);if(!t.connected)return{content:[{type:"text",text:"Error: Not connected. Ignoring message.",uri:"marketDataRequest"}],isError:!0};t.send(P);let d=await i;return{content:[{type:"text",text:`Market data for ${e.symbols.join(", ")}: ${JSON.stringify(d.toFIXJSON())}`,uri:"marketDataRequest"}]}}catch(i){return{content:[{type:"text",text:`Error: ${i instanceof Error?i.message:"Failed to request market data"}`,uri:"marketDataRequest"}],isError:!0}}},V=t=>async a=>{try{let e=a.symbol,i=t.get(e)||[];if(i.length===0)return{content:[{type:"text",text:`No price data available for ${e}`,uri:"getStockGraph"}]};let r=new B;r.setWidth(1200),r.setHeight(600),r.setBackgroundColor("transparent");let u=i.map(l=>new Date(l.timestamp).toLocaleTimeString()),P=i.map(l=>l.bid),d=i.map(l=>l.offer),m=i.map(l=>l.spread),v=i.map(l=>l.volume),o=i.map(l=>l.trade),F=i.map(l=>l.vwap),I=i.map(l=>l.twap),S={type:"line",data:{labels:u,datasets:[{label:"Bid",data:P,borderColor:"#28a745",backgroundColor:"rgba(40, 167, 69, 0.1)",fill:!1,tension:.4},{label:"Offer",data:d,borderColor:"#dc3545",backgroundColor:"rgba(220, 53, 69, 0.1)",fill:!1,tension:.4},{label:"Spread",data:m,borderColor:"#6c757d",backgroundColor:"rgba(108, 117, 125, 0.1)",fill:!1,tension:.4},{label:"Trade",data:o,borderColor:"#ffc107",backgroundColor:"rgba(255, 193, 7, 0.1)",fill:!1,tension:.4},{label:"VWAP",data:F,borderColor:"#17a2b8",backgroundColor:"rgba(23, 162, 184, 0.1)",fill:!1,tension:.4},{label:"TWAP",data:I,borderColor:"#6610f2",backgroundColor:"rgba(102, 16, 242, 0.1)",fill:!1,tension:.4},{label:"Volume",data:v,borderColor:"#007bff",backgroundColor:"rgba(0, 123, 255, 0.1)",fill:!0,tension:.4}]},options:{responsive:!0,plugins:{title:{display:!0,text:`${e} Market Data`}},scales:{y:{beginAtZero:!1}}}};return r.setConfig(S),{content:[{type:"resource",resource:{uri:"resource://graph",mimeType:"image/png",blob:(await r.toBinary()).toString("base64")}}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to generate graph"}`,uri:"getStockGraph"}],isError:!0}}},H=t=>async a=>{try{let e=a.symbol,i=t.get(e)||[];return i.length===0?{content:[{type:"text",text:`No price data available for ${e}`,uri:"getStockPriceHistory"}]}:{content:[{type:"text",text:JSON.stringify({symbol:e,count:i.length,data:i.map(r=>({timestamp:new Date(r.timestamp).toISOString(),bid:r.bid,offer:r.offer,spread:r.spread,volume:r.volume,trade:r.trade,indexValue:r.indexValue,openingPrice:r.openingPrice,closingPrice:r.closingPrice,settlementPrice:r.settlementPrice,tradingSessionHighPrice:r.tradingSessionHighPrice,tradingSessionLowPrice:r.tradingSessionLowPrice,vwap:r.vwap,imbalance:r.imbalance,openInterest:r.openInterest,compositeUnderlyingPrice:r.compositeUnderlyingPrice,simulatedSellPrice:r.simulatedSellPrice,simulatedBuyPrice:r.simulatedBuyPrice,marginRate:r.marginRate,midPrice:r.midPrice,emptyBook:r.emptyBook,settleHighPrice:r.settleHighPrice,settleLowPrice:r.settleLowPrice,priorSettlePrice:r.priorSettlePrice,sessionHighBid:r.sessionHighBid,sessionLowOffer:r.sessionLowOffer,earlyPrices:r.earlyPrices,auctionClearingPrice:r.auctionClearingPrice,swapValueFactor:r.swapValueFactor,dailyValueAdjustmentForLongPositions:r.dailyValueAdjustmentForLongPositions,cumulativeValueAdjustmentForLongPositions:r.cumulativeValueAdjustmentForLongPositions,dailyValueAdjustmentForShortPositions:r.dailyValueAdjustmentForShortPositions,cumulativeValueAdjustmentForShortPositions:r.cumulativeValueAdjustmentForShortPositions,fixingPrice:r.fixingPrice,cashRate:r.cashRate,recoveryRate:r.recoveryRate,recoveryRateForLong:r.recoveryRateForLong,recoveryRateForShort:r.recoveryRateForShort,marketBid:r.marketBid,marketOffer:r.marketOffer,shortSaleMinPrice:r.shortSaleMinPrice,previousClosingPrice:r.previousClosingPrice,thresholdLimitPriceBanding:r.thresholdLimitPriceBanding,dailyFinancingValue:r.dailyFinancingValue,accruedFinancingValue:r.accruedFinancingValue,twap:r.twap}))},null,2),uri:"getStockPriceHistory"}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to get price history"}`,uri:"getStockPriceHistory"}],isError:!0}}},j={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"},$={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"},q={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"},G={1:"AutomatedExecutionNoIntervention",2:"AutomatedExecutionInterventionOK",3:"ManualOrder"},X=(t,a)=>async e=>{try{return a.set(e.clOrdID,{clOrdID:e.clOrdID,handlInst:e.handlInst,quantity:Number.parseFloat(String(e.quantity)),price:Number.parseFloat(String(e.price)),ordType:e.ordType,side:e.side,symbol:e.symbol,timeInForce:e.timeInForce}),{content:[{type:"text",text:`VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
2
|
+
import{EncryptMethod as K,FIXParser as z,Field as P,Fields as O,LicenseManager as Y,Messages as Z,ResetSeqNumFlag as ee}from"fixparser";var x=class{format;useStderr;constructor({format:r="json",useStderr:n=!1}){this.format=r,this.useStderr=n}configure(r){this.format=r.format||"json",r.useStderr!==void 0&&(this.useStderr=r.useStderr)}async send(r){let n=this.useStderr?console.error:console.log;if(this.format==="json")n(JSON.stringify(r));else if(this.format==="jsonrpc"){let{message:e,...t}=r,l={jsonrpc:"2.0",method:r.level,params:{message:e,...t},id:r.id||Date.now()};n(JSON.stringify(l))}else{let{name:e,id:t,message:l,level:u,...f}=r,c=Object.entries(f).map(([v,o])=>`${v}: ${o}`),p="";e&&(p+=`${e} `),p+=`${t}: ${l}`,n(p,c.join(", "))}}async flush(){}async close(){}status(){return"connected"}};import{Server as w}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as D}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as S}from"zod";import{Field as y,Fields as h,MDEntryType as i,Messages as A}from"fixparser";import N from"quickchart-js";import{Field as m,Fields as g,Messages as E}from"fixparser";import{Fields as F,MDEntryType as s,Messages as C}from"fixparser";import{McpServer as pe}from"@modelcontextprotocol/sdk/server/mcp.js";import{StreamableHTTPServerTransport as ge}from"@modelcontextprotocol/sdk/server/streamableHttp.js";import{isInitializeRequest as he}from"@modelcontextprotocol/sdk/types.js";import{z as Se}from"zod";var L=class{logger;parser;onReady=void 0;verifiedOrders=new Map;pendingRequests=new Map;marketDataPrices=new Map;MAX_PRICE_HISTORY=1e5;constructor({logger:r,onReady:n}){this.logger=r,this.onReady=n}},k={parse:{description:"Parses a FIX message and describes it in plain language",schema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},parseToJSON:{description:"Parses a FIX message into JSON",schema:{type:"object",properties:{fixString:{type:"string"}},required:["fixString"]}},verifyOrder:{description:"Verifies order parameters before execution. verifyOrder must be called before executeOrder.",schema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"],description:"Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"],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"},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],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"},symbol:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],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"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},executeOrder:{description:"Executes a verified order. verifyOrder must be called before executeOrder.",schema:{type:"object",properties:{clOrdID:{type:"string"},handlInst:{type:"string",enum:["1","2","3"],description:"Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"},quantity:{type:"string"},price:{type:"string"},ordType:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","P","Q","R","S"],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"},side:{type:"string",enum:["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"],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"},symbol:{type:"string"},timeInForce:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C"],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"}},required:["clOrdID","handlInst","quantity","price","ordType","side","symbol","timeInForce"]}},marketDataRequest:{description:"Requests market data for specified symbols",schema:{type:"object",properties:{mdUpdateType:{type:"string",enum:["0","1"],description:"Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"},symbols:{type:"array",items:{type:"string"}},mdReqID:{type:"string"},subscriptionRequestType:{type:"string",enum:["0","1","2"],description:"Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"},mdEntryTypes:{type:"array",items:{type:"string",enum:["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]},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"}},required:["mdUpdateType","symbols","mdReqID","subscriptionRequestType"]}},getStockGraph:{description:"Generates a price chart for a given symbol",schema:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}},getStockPriceHistory:{description:"Returns price history for a given symbol",schema:{type:"object",properties:{symbol:{type:"string"}},required:["symbol"]}}},B=(r,n)=>async e=>{try{let t=new Promise(p=>{n.set(e.mdReqID,p)}),l=e.mdEntryTypes||[i.Bid,i.Offer,i.Trade,i.IndexValue,i.OpeningPrice,i.ClosingPrice,i.SettlementPrice,i.TradingSessionHighPrice,i.TradingSessionLowPrice,i.VWAP,i.Imbalance,i.TradeVolume,i.OpenInterest,i.CompositeUnderlyingPrice,i.SimulatedSellPrice,i.SimulatedBuyPrice,i.MarginRate,i.MidPrice,i.EmptyBook,i.SettleHighPrice,i.SettleLowPrice,i.PriorSettlePrice,i.SessionHighBid,i.SessionLowOffer,i.EarlyPrices,i.AuctionClearingPrice,i.SwapValueFactor,i.DailyValueAdjustmentForLongPositions,i.CumulativeValueAdjustmentForLongPositions,i.DailyValueAdjustmentForShortPositions,i.CumulativeValueAdjustmentForShortPositions,i.FixingPrice,i.CashRate,i.RecoveryRate,i.RecoveryRateForLong,i.RecoveryRateForShort,i.MarketBid,i.MarketOffer,i.ShortSaleMinPrice,i.PreviousClosingPrice,i.ThresholdLimitPriceBanding,i.DailyFinancingValue,i.AccruedFinancingValue,i.TWAP],u=[new y(h.MsgType,A.MarketDataRequest),new y(h.SenderCompID,r.sender),new y(h.MsgSeqNum,r.getNextTargetMsgSeqNum()),new y(h.TargetCompID,r.target),new y(h.SendingTime,r.getTimestamp()),new y(h.MDReqID,e.mdReqID),new y(h.SubscriptionRequestType,e.subscriptionRequestType),new y(h.MarketDepth,0),new y(h.MDUpdateType,e.mdUpdateType)];u.push(new y(h.NoRelatedSym,e.symbols.length)),e.symbols.forEach(p=>{u.push(new y(h.Symbol,p))}),u.push(new y(h.NoMDEntryTypes,l.length)),l.forEach(p=>{u.push(new y(h.MDEntryType,p))});let f=r.createMessage(...u);if(!r.connected)return{content:[{type:"text",text:"Error: Not connected. Ignoring message.",uri:"marketDataRequest"}],isError:!0};r.send(f);let c=await t;return{content:[{type:"text",text:`Market data for ${e.symbols.join(", ")}: ${JSON.stringify(c.toFIXJSON())}`,uri:"marketDataRequest"}]}}catch(t){return{content:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to request market data"}`,uri:"marketDataRequest"}],isError:!0}}},H=r=>async n=>{try{let e=n.symbol,t=r.get(e)||[];if(t.length===0)return{content:[{type:"text",text:`No price data available for ${e}`,uri:"getStockGraph"}]};let l=new N;l.setWidth(1200),l.setHeight(600),l.setBackgroundColor("transparent");let u=t.map(d=>new Date(d.timestamp).toLocaleTimeString()),f=t.map(d=>d.bid),c=t.map(d=>d.offer),p=t.map(d=>d.spread),v=t.map(d=>d.volume),o={type:"line",data:{labels:u,datasets:[{label:"Bid",data:f,borderColor:"#28a745",backgroundColor:"rgba(40, 167, 69, 0.1)",fill:!1,tension:.4},{label:"Offer",data:c,borderColor:"#dc3545",backgroundColor:"rgba(220, 53, 69, 0.1)",fill:!1,tension:.4},{label:"Spread",data:p,borderColor:"#6c757d",backgroundColor:"rgba(108, 117, 125, 0.1)",fill:!1,tension:.4},{label:"Volume",data:v,borderColor:"#007bff",backgroundColor:"rgba(0, 123, 255, 0.1)",fill:!0,tension:.4}]},options:{responsive:!0,plugins:{title:{display:!0,text:`${e} Market Data`}},scales:{y:{beginAtZero:!1}}}};return l.setConfig(o),{content:[{type:"resource",resource:{uri:"resource://graph",mimeType:"image/png",blob:(await l.toBinary()).toString("base64")}}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to generate chart"}`,uri:"getStockGraph"}],isError:!0}}},$=r=>async n=>{try{let e=n.symbol,t=r.get(e)||[];return t.length===0?{content:[{type:"text",text:`No price data available for ${e}`,uri:"getStockPriceHistory"}]}:{content:[{type:"text",text:JSON.stringify({symbol:e,count:t.length,data:t.map(l=>({timestamp:new Date(l.timestamp).toISOString(),bid:l.bid,offer:l.offer,spread:l.spread,volume:l.volume}))},null,2),uri:"getStockPriceHistory"}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to get stock price history"}`,uri:"getStockPriceHistory"}],isError:!0}}},V={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"},q={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"},j={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"},G={1:"AutomatedExecutionNoIntervention",2:"AutomatedExecutionInterventionOK",3:"ManualOrder"},X=(r,n)=>async e=>{try{return n.set(e.clOrdID,{clOrdID:e.clOrdID,handlInst:e.handlInst,quantity:Number.parseFloat(String(e.quantity)),price:Number.parseFloat(String(e.price)),ordType:e.ordType,side:e.side,symbol:e.symbol,timeInForce:e.timeInForce}),{content:[{type:"text",text:`VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
3
3
|
|
|
4
4
|
Parameters verified:
|
|
5
5
|
- ClOrdID: ${e.clOrdID}
|
|
6
6
|
- HandlInst: ${e.handlInst} (${G[e.handlInst]})
|
|
7
7
|
- Quantity: ${e.quantity}
|
|
8
8
|
- Price: ${e.price}
|
|
9
|
-
- OrdType: ${e.ordType} (${
|
|
10
|
-
- Side: ${e.side} (${
|
|
9
|
+
- OrdType: ${e.ordType} (${V[e.ordType]})
|
|
10
|
+
- Side: ${e.side} (${q[e.side]})
|
|
11
11
|
- Symbol: ${e.symbol}
|
|
12
|
-
- TimeInForce: ${e.timeInForce} (${
|
|
12
|
+
- TimeInForce: ${e.timeInForce} (${j[e.timeInForce]})
|
|
13
13
|
|
|
14
|
-
To execute this order, call the executeOrder tool with these exact same parameters
|
|
15
|
-
${e[0].messageTypeDescription}`,uri:"parse"}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to parse FIX string"}`,uri:"parse"}],isError:!0}}},U=
|
|
14
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`,uri:"verifyOrder"}]}}catch(t){return{content:[{type:"text",text:`Error: ${t instanceof Error?t.message:"Failed to verify order parameters"}`,uri:"verifyOrder"}],isError:!0}}},J=(r,n,e)=>async t=>{try{let l=n.get(t.clOrdID);if(!l)return{content:[{type:"text",text:`Error: Order ${t.clOrdID} has not been verified. Please call verifyOrder first.`,uri:"executeOrder"}],isError:!0};if(l.handlInst!==t.handlInst||l.quantity!==Number.parseFloat(String(t.quantity))||l.price!==Number.parseFloat(String(t.price))||l.ordType!==t.ordType||l.side!==t.side||l.symbol!==t.symbol||l.timeInForce!==t.timeInForce)return{content:[{type:"text",text:"Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",uri:"executeOrder"}],isError:!0};let u=new Promise(p=>{e.set(t.clOrdID,p)}),f=r.createMessage(new m(g.MsgType,E.NewOrderSingle),new m(g.MsgSeqNum,r.getNextTargetMsgSeqNum()),new m(g.SenderCompID,r.sender),new m(g.TargetCompID,r.target),new m(g.SendingTime,r.getTimestamp()),new m(g.ClOrdID,t.clOrdID),new m(g.Side,t.side),new m(g.Symbol,t.symbol),new m(g.OrderQty,Number.parseFloat(String(t.quantity))),new m(g.Price,Number.parseFloat(String(t.price))),new m(g.OrdType,t.ordType),new m(g.HandlInst,t.handlInst),new m(g.TimeInForce,t.timeInForce),new m(g.TransactTime,r.getTimestamp()));if(!r.connected)return{content:[{type:"text",text:"Error: Not connected. Ignoring message.",uri:"executeOrder"}],isError:!0};r.send(f);let c=await u;return n.delete(t.clOrdID),{content:[{type:"text",text:c.messageType===E.Reject?`Reject message for order ${t.clOrdID}: ${JSON.stringify(c.toFIXJSON())}`:`Execution Report for order ${t.clOrdID}: ${JSON.stringify(c.toFIXJSON())}`,uri:"executeOrder"}]}}catch(l){return{content:[{type:"text",text:`Error: ${l instanceof Error?l.message:"Failed to execute order"}`,uri:"executeOrder"}],isError:!0}}},W=r=>async n=>{try{let e=r.parse(n.fixString);return!e||e.length===0?{content:[{type:"text",text:"Error: Failed to parse FIX string",uri:"parse"}],isError:!0}:{content:[{type:"text",text:`${e[0].description}
|
|
15
|
+
${e[0].messageTypeDescription}`,uri:"parse"}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to parse FIX string"}`,uri:"parse"}],isError:!0}}},U=r=>async n=>{try{let e=r.parse(n.fixString);return!e||e.length===0?{content:[{type:"text",text:"Error: Failed to parse FIX string",uri:"parseToJSON"}],isError:!0}:{content:[{type:"text",text:`${e[0].toFIXJSON()}`,uri:"parseToJSON"}]}}catch(e){return{content:[{type:"text",text:`Error: ${e instanceof Error?e.message:"Failed to parse FIX string"}`,uri:"parseToJSON"}],isError:!0}}},_=(r,n,e,t)=>({parse:W(r),parseToJSON:U(r),verifyOrder:X(r,n),executeOrder:J(r,n,e),marketDataRequest:B(r,e),getStockGraph:H(t),getStockPriceHistory:$(t)});function Q(r,n,e,t,l,u){n.logger.log({level:"info",message:`MCP Server received message: ${r.messageType}: ${r.description}`});let f=r.messageType;if(f===C.MarketDataSnapshotFullRefresh||f===C.MarketDataIncrementalRefresh){let c=r.getField(F.Symbol)?.value,v=r.toFIXJSON().Body?.NoMDEntries||[],o={timestamp:Date.now(),bid:0,offer:0,spread:0,volume:0,trade:0,indexValue:0,openingPrice:0,closingPrice:0,settlementPrice:0,tradingSessionHighPrice:0,tradingSessionLowPrice:0,vwap:0,imbalance:0,openInterest:0,compositeUnderlyingPrice:0,simulatedSellPrice:0,simulatedBuyPrice:0,marginRate:0,midPrice:0,emptyBook:0,settleHighPrice:0,settleLowPrice:0,priorSettlePrice:0,sessionHighBid:0,sessionLowOffer:0,earlyPrices:0,auctionClearingPrice:0,swapValueFactor:0,dailyValueAdjustmentForLongPositions:0,cumulativeValueAdjustmentForLongPositions:0,dailyValueAdjustmentForShortPositions:0,cumulativeValueAdjustmentForShortPositions:0,fixingPrice:0,cashRate:0,recoveryRate:0,recoveryRateForLong:0,recoveryRateForShort:0,marketBid:0,marketOffer:0,shortSaleMinPrice:0,previousClosingPrice:0,thresholdLimitPriceBanding:0,dailyFinancingValue:0,accruedFinancingValue:0,twap:0};for(let d of v){let R=d.MDEntryType,a=d.MDEntryPx?Number.parseFloat(d.MDEntryPx):0,I=d.MDEntrySize?Number.parseFloat(d.MDEntrySize):0;switch(R){case s.Bid:o.bid=a;break;case s.Offer:o.offer=a;break;case s.Trade:o.trade=a;break;case s.IndexValue:o.indexValue=a;break;case s.OpeningPrice:o.openingPrice=a;break;case s.ClosingPrice:o.closingPrice=a;break;case s.SettlementPrice:o.settlementPrice=a;break;case s.TradingSessionHighPrice:o.tradingSessionHighPrice=a;break;case s.TradingSessionLowPrice:o.tradingSessionLowPrice=a;break;case s.VWAP:o.vwap=a;break;case s.Imbalance:o.imbalance=I;break;case s.TradeVolume:o.volume=I;break;case s.OpenInterest:o.openInterest=I;break;case s.CompositeUnderlyingPrice:o.compositeUnderlyingPrice=a;break;case s.SimulatedSellPrice:o.simulatedSellPrice=a;break;case s.SimulatedBuyPrice:o.simulatedBuyPrice=a;break;case s.MarginRate:o.marginRate=a;break;case s.MidPrice:o.midPrice=a;break;case s.EmptyBook:o.emptyBook=1;break;case s.SettleHighPrice:o.settleHighPrice=a;break;case s.SettleLowPrice:o.settleLowPrice=a;break;case s.PriorSettlePrice:o.priorSettlePrice=a;break;case s.SessionHighBid:o.sessionHighBid=a;break;case s.SessionLowOffer:o.sessionLowOffer=a;break;case s.EarlyPrices:o.earlyPrices=a;break;case s.AuctionClearingPrice:o.auctionClearingPrice=a;break;case s.SwapValueFactor:o.swapValueFactor=a;break;case s.DailyValueAdjustmentForLongPositions:o.dailyValueAdjustmentForLongPositions=a;break;case s.CumulativeValueAdjustmentForLongPositions:o.cumulativeValueAdjustmentForLongPositions=a;break;case s.DailyValueAdjustmentForShortPositions:o.dailyValueAdjustmentForShortPositions=a;break;case s.CumulativeValueAdjustmentForShortPositions:o.cumulativeValueAdjustmentForShortPositions=a;break;case s.FixingPrice:o.fixingPrice=a;break;case s.CashRate:o.cashRate=a;break;case s.RecoveryRate:o.recoveryRate=a;break;case s.RecoveryRateForLong:o.recoveryRateForLong=a;break;case s.RecoveryRateForShort:o.recoveryRateForShort=a;break;case s.MarketBid:o.marketBid=a;break;case s.MarketOffer:o.marketOffer=a;break;case s.ShortSaleMinPrice:o.shortSaleMinPrice=a;break;case s.PreviousClosingPrice:o.previousClosingPrice=a;break;case s.ThresholdLimitPriceBanding:o.thresholdLimitPriceBanding=a;break;case s.DailyFinancingValue:o.dailyFinancingValue=a;break;case s.AccruedFinancingValue:o.accruedFinancingValue=a;break;case s.TWAP:o.twap=a;break}}o.spread=o.offer-o.bid,t.has(c)||t.set(c,[]);let b=t.get(c);b.push(o),b.length>l&&b.splice(0,b.length-l),u?.(c,o);let T=r.getField(F.MDReqID)?.value;if(T){let d=e.get(T);d&&(d(r),e.delete(T))}}else if(f===C.ExecutionReport){let c=r.getField(F.ClOrdID)?.value,p=e.get(c);p&&(p(r),e.delete(c))}}var M=class extends L{verifiedOrders=new Map;pendingRequests=new Map;marketDataPrices=new Map;MAX_PRICE_HISTORY=1e5;server=new w({name:"fixparser",version:"1.0.0"},{capabilities:{tools:Object.entries(k).reduce((r,[n,{description:e,schema:t}])=>(r[n]={description:e,parameters:t},r),{})}});transport=new D;constructor({logger:r,onReady:n}){super({logger:r,onReady:n})}async register(r){this.parser=r,this.parser.addOnMessageCallback(n=>{Q(n,this.parser,this.pendingRequests,this.marketDataPrices,this.MAX_PRICE_HISTORY)}),this.addWorkflows(),await this.server.connect(this.transport),this.onReady&&this.onReady()}addWorkflows(){this.parser&&this.server&&(this.server.setRequestHandler(S.object({method:S.literal("tools/list")}),async()=>({tools:Object.entries(k).map(([r,{description:n,schema:e}])=>({name:r,description:n,inputSchema:e}))})),this.server.setRequestHandler(S.object({method:S.literal("tools/call"),params:S.object({name:S.string(),arguments:S.any(),_meta:S.object({progressToken:S.number()}).optional()})}),async r=>{let{name:n,arguments:e}=r.params,l=_(this.parser,this.verifiedOrders,this.pendingRequests,this.marketDataPrices)[n];if(!l)return{content:[{type:"text",text:`Tool not found: ${n}`,uri:n}],isError:!0};let u=await l(e);return{content:u.content,isError:u.isError}}),process.on("SIGINT",async()=>{await this.server.close(),process.exit(0)}))}};var re=async()=>{await Y.setLicenseKey(process.env.FIXPARSER_LICENSE_KEY);let r=process.env.FIXPARSER_SENDER||"SENDER",n=process.env.FIXPARSER_TARGET||"TARGET",e=new z({logging:!0,logOptions:{level:"info",format:"jsonrpc",transport:new x({format:"jsonrpc"})},plugins:[new M({port:3099,onReady:()=>{}})]}),t=()=>{let u=e.createMessage(new P(O.MsgType,Z.Logon),new P(O.MsgSeqNum,e.getNextTargetMsgSeqNum()),new P(O.SenderCompID,r),new P(O.SendingTime,e.getTimestamp()),new P(O.TargetCompID,n),new P(O.ResetSeqNumFlag,ee.Yes),new P(O.EncryptMethod,K.None),new P(O.HeartBtInt,10));e.send(u)},l={host:process.env.FIXPARSER_HOST||"10.0.1.42",port:process.env.FIXPARSER_PORT?Number.parseInt(process.env.FIXPARSER_PORT,10):5001,protocol:"tcp",sender:r,target:n,fixVersion:"FIX.4.4",onOpen:()=>{e.logger.log({level:"info",message:"FIXParser logging in..."}),t()},onClose:()=>{e.logger.log({level:"info",message:"FIXParser disconnected. Reconnecting in 1 second..."}),setTimeout(()=>{e.connect(l)},1e3)}};e.connect(l)};re().catch(r=>console.error("Error initializing server:",r));
|
|
16
16
|
//# sourceMappingURL=example_mcp_local.mjs.map
|