tradovate-mcp-gateway
Interface with the Tradovate trading infrastructure to facilitate order execution, account administration, and real-time market data retrieval via a dedicated Model Context Protocol (MCP) server.
Author

alexanimal
Quick Info
Actions
Tags
Tradovate MCP Server Interface
An implementation of a Model Context Protocol (MCP) backend designed specifically for seamless interaction with the Tradovate trading platform's proprietary Application Programming Interface (API). This service exposes abstracted functions for comprehensive trading lifecycle management, including position oversight, order creation/amendment, account status retrieval, and market data streaming.
Core Capabilities
- Securely handles all authentication handshakes with the Tradovate remote service.
- Implements mechanisms for immediate data retrieval augmented with internal caching to minimize redundant API calls.
- Provides discrete toolsets for managing contract specifications, open positions, submitted orders, and account metrics.
- Includes a contingency mechanism to serve synthetic/simulated data if the primary Tradovate endpoint becomes temporarily unreachable.
Deployment Instructions
- Obtain a local copy of the source repository:
bash git clone [repository-url] cd tradovate-mcp-server
- Resolve project dependencies:
bash npm install
- Configure environment variables in a
.envfile using your specific Tradovate access parameters:
bash TRADOVATE_API_ENVIRONMENT=demo TRADOVATE_USERNAME=your_user_id TRADOVATE_PASSWORD=your_secret_key TRADOVATE_APP_ID=AppIdentifier TRADOVATE_APP_VERSION=1.0.0 TRADOVATE_CID=client_identifier TRADOVATE_SEC=security_token
Execution
To initiate the MCP server:
bash npm start
To interact via the dedicated MCP inspection utility:
bash npm run inspector
Development & Architecture
Directory Layout
src/index.ts- The primary executable script initializing the server process.src/auth.ts- Logic dedicated to token acquisition and validation.src/data.ts- Handles all data acquisition, transformation, and caching strategies.src/tools.ts- Defines the exposed MCP operations.src/types.ts- TypeScript interface definitions for strict typing.tests/- Unit and integration test suites.
Building Artifacts
Compilation step:
bash npm run build
Quality Assurance
Execute the full test suite:
bash npm test
Run tests while generating execution metrics:
bash npm run test:coverage
Update the code coverage reporting badge:
bash npm run coverage:badge
Exposed Toolset
The following primitives are accessible via the MCP interface:
get_contract_details- Retrieves granular attributes for a given market instrument symbol.list_positions- Fetches a summary of all current net exposures associated with an account.place_order- Submits a new trading instruction to the broker.modify_order- Updates parameters of a previously submitted, open order.cancel_order- Revokes a pending order from the exchange.liquidate_position- Executes an immediate closing trade for an existing holding.get_account_summary- Pulls high-level financial metrics for the designated account.get_market_data- Retrieves current pricing snapshots, Depth of Market (DOM) levels, or historical chart data streams.
Tradovate API Interaction Map
The server utilizes the following distinct resource paths on the external API:
Authentication Flows
/auth/accessTokenRequest- Initiates the primary token grant process./auth/renewAccessToken- Refreshes an expired session token.
Instrument Definitions
/contract/list- Returns the complete universe of tradeable items./contract/find- Locates the definition for a specific contract identifier.
Position Management
/position/list- Enumerates all active risk positions.
Trade Execution Control
/order/list- Views the history and status of all orders./order/placeOrder- Endpoint for order submission./order/modifyOrder- Endpoint for order modification./order/cancelOrder- Endpoint for order cancellation./order/liquidatePosition- Specialized endpoint for position closure.
Account Metrics
/account/list- Retrieves all associated user accounts./account/find- Searches for a specific account entity./cashBalance/getCashBalanceSnapshot- Fetches the latest margin and cash settlement data.
Real-Time Data Feeds
/md/getQuote- Fetches the current bid/ask prices./md/getDOM- Retrieves the order book structure./md/getChart- Requests time-series data for charting applications.
Licensing Information
This software is distributed under the terms of the MIT License. Consult the LICENSE file for full details.
== XMLHttpRequest Deep Dive ==
The XMLHttpRequest (XHR) object serves as a crucial Application Programming Interface (API) within JavaScript environments, enabling the dispatch of HyperText Transfer Protocol (HTTP) requests between a running web browser instance and a remote web server. Its key utility lies in permitting asynchronous data exchange subsequent to the initial page load. This capability forms the foundation of Asynchronous JavaScript and XML (Ajax) programming paradigms. Before XHR's widespread adoption, interactivity with servers was predominantly achieved via standard hyperlink navigation or form submissions, both of which typically necessitated a full-page refresh.
=== Genesis ===
The conceptual underpinnings of XMLHttpRequest emerged around the year 2000, primarily driven by developers working on Microsoft Outlook. This idea was first instantiated in Internet Explorer 5 (released in 1999). Notably, the initial implementations did not utilize the standardized XMLHttpRequest string; instead, proprietary object constructors such as ActiveXObject("Msxml2.XMLHTTP") or ActiveXObject("Microsoft.XMLHTTP") were employed. By the release of Internet Explorer 7 (2006), support for the standardized XMLHttpRequest identifier became universal across major browser engines, including Mozilla's Gecko (2002), Safari (2004), and Opera (2005).
==== Standardization Efforts ====
The World Wide Web Consortium (W3C) formally published a Working Draft specification for the XMLHttpRequest object on April 5, 2006. This was followed by the Level 2 specification draft on February 25, 2008, which introduced enhancements such as event progress monitoring, facilitation of cross-site requests, and mechanisms for handling raw byte streams. By the close of 2011, the Level 2 features were integrated back into the primary specification document. As of the end of 2012, the maintenance and evolution of the living document were transferred to the WHATWG, utilizing the Web Interface Definition Language (Web IDL).
== Operational Flow ==
Executing a data request using XMLHttpRequest generally involves a sequence of distinct programmatic actions:
- Instantiation: An XHR object instance is created by invoking its constructor function.
- Configuration: The
open()method is invoked to define the request methodology (e.g., GET, POST), specify the target Uniform Resource Identifier (URI), and determine whether the operation will execute synchronously or asynchronously. - Event Handling (Asynchronous Path): For non-blocking operations, a callback function (listener) must be assigned to handle state transitions upon the server's response.
- Transmission: The request is dispatched to the server by calling the
send()method, optionally providing payload data. - Response Processing: The assigned listener monitors the object's state. Upon reaching state 4 (the 'done' status), the complete response body is accessible, typically in the
responseTextproperty.
Beyond these fundamental steps, XHR offers extensive control over request parameters. Custom HTTP headers can be prepended to guide server processing, and data uploads can be managed within the send() call. Furthermore, the incoming response stream can be parsed directly into a structured JavaScript object (e.g., from JSON format) or processed incrementally as data segments arrive, avoiding latency associated with waiting for total transfer completion. The process can also be manually terminated prematurely or configured with a timeout threshold.
