=============== LIBRARY RULES =============== From library maintainers: - Use HTTPS endpoints with base URL https://api.topstepx.com - Always authenticate using API key or session token - Handle rate limiting and error responses properly - Use SignalR for real-time market data and user updates - Implement proper error handling for all API calls - Follow REST conventions for request/response patterns ### JSON Example Success Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Success Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### cURL Example Request for Placing an Order Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example cURL command demonstrating how to send a POST request to the 'Place an Order' API endpoint with a JSON payload containing typical order parameters. ```curl curl -X 'POST' \ 'https://api.topstepx.com/api/Order/place' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 465, \ "contractId": "CON.F.US.DA6.M25", \ "type": 2, \ "side": 1, \ "size": 1, \ "limitPrice": null, \ "stopPrice": null, \ "trailPrice": null, \ "customTag": null, \ "linkedOrderId": null \ }' ``` -------------------------------- ### cURL Example Request for Placing an Order Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md An example cURL command demonstrating how to send a POST request to the 'Place an Order' API endpoint with a JSON payload containing typical order parameters. ```curl curl -X 'POST' \ 'https://api.topstepx.com/api/Order/place' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 465, \ "contractId": "CON.F.US.DA6.M25", \ "type": 2, \ "side": 1, \ "size": 1, \ "limitPrice": null, \ "stopPrice": null, \ "trailPrice": null, \ "customTag": null, \ "linkedOrderId": null \ }' ``` -------------------------------- ### cURL Example Request for Placing an Order Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example cURL command demonstrating how to send a POST request to the 'Place an Order' API endpoint with a JSON payload containing typical order parameters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Order/place' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 465, ``` -------------------------------- ### JSON Example Success Response for Order Placement Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example JSON response received upon successful placement of an order, including the generated order ID, a success flag, and error details if any. ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Success Response for Order Placement Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example JSON response received upon successful placement of an order, including the generated order ID, a success flag, and error details if any. ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Success Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Error Response for Order Placement Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example of a generic error response, specifically indicating an HTTP 401 Unauthorized status, which might occur if authentication fails. ```text Error: response status is 401 ``` -------------------------------- ### Account Search API Success Response Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Success Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-account-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Response: Successful Order Cancellation Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md Provides an example of the JSON response received when an order cancellation request is processed successfully. ```JSON { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Success Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-history-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Success Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md An example of a successful JSON response returned by the Account search API, showing a list of accounts with their details. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Order Placement: Example Error Response (Unauthorized) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md An example of a generic error response, specifically indicating an HTTP 401 Unauthorized status, which might occur if authentication fails. ```text Error: response status is 401 ``` -------------------------------- ### JSON Example Success Response for Order Placement Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md An example JSON response received upon successful placement of an order, including the generated order ID, a success flag, and error details if any. ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Error Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example of an error response from the Account search API, typically indicating an unauthorized access (HTTP 401). ```json Error: response status is 401 ``` -------------------------------- ### Search Open Orders API Reference and cURL Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides the API reference for searching open orders and a cURL example to demonstrate how to query for open orders, including the endpoint and required parameters. ```APIDOC API URL: POST https://api.topstepx.com/api/Order/searchOpen API Reference: /api/Order/searchOpen Description: Search for open orders. Parameters: accountId: Type: integer Description: The account ID. Required: true Nullable: false ``` ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/searchOpen' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 465 }' ``` -------------------------------- ### Example Error Response for Order Placement Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md An example of a generic error response, specifically indicating an HTTP 401 Unauthorized status, which might occur if authentication fails. ```JSON { "success": false, "errorCode": 401, "errorMessage": "Unauthorized" } ``` -------------------------------- ### Example cURL Request for Trade Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's 'Search for Trades' endpoint using cURL, including headers and a JSON request body with example account and timestamp filters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Trade/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 203, "startTimestamp": "2025-01-20T15:47:39.882Z", "endTimestamp": "2025-01-30T15:47:39.882Z" }' ``` -------------------------------- ### Example cURL Request for Trade Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's 'Search for Trades' endpoint using cURL, including headers and a JSON request body with example account and timestamp filters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Trade/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 203, "startTimestamp": "2025-01-20T15:47:39.882Z", "endTimestamp": "2025-01-30T15:47:39.882Z" }' ``` -------------------------------- ### Example cURL Request for Trade Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's 'Search for Trades' endpoint using cURL, including headers and a JSON request body with example account and timestamp filters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Trade/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 203, \ "startTimestamp": "2025-01-20T15:47:39.882Z", \ "endTimestamp": "2025-01-30T15:47:39.882Z" \ }' ``` -------------------------------- ### Example Response: Successful Order Cancellation Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-account-module.md Provides an example of the JSON response received when an order cancellation request is processed successfully, indicating the operation's status, error code, and message. ```JSON { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example cURL Request for Trade Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's 'Search for Trades' endpoint using cURL, including headers and a JSON request body with example account and timestamp filters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Trade/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 203, "startTimestamp": "2025-01-20T15:47:39.882Z", "endTimestamp": "2025-01-30T15:47:39.882Z" }' ``` -------------------------------- ### Example cURL Request for Trade Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's 'Search for Trades' endpoint using cURL, including headers and a JSON request body with example account and timestamp filters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Trade/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 203, \ "startTimestamp": "2025-01-20T15:47:39.882Z", \ "endTimestamp": "2025-01-30T15:47:39.882Z" \ }' ``` -------------------------------- ### Example cURL Request for Trade Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's 'Search for Trades' endpoint using cURL, including headers and a JSON request body with example account and timestamp filters. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Trade/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 203, "startTimestamp": "2025-01-20T15:47:39.882Z", "endTimestamp": "2025-01-30T15:47:39.882Z" }' ``` -------------------------------- ### Example Response: Successful Order Cancellation Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md Provides an example of the JSON response received when an order cancellation request is processed successfully. ```JSON { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### JSON Example Error Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md An example of an error response from the Account search API, typically indicating an unauthorized access (HTTP 401). ```JSON Error: response status is 401 ``` -------------------------------- ### JSON Response Example: Successful Order Modification Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md An example of a successful JSON response received after modifying an order, indicating the operation's success status. ```json { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example cURL Request to Search Contracts Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Demonstrates how to make a POST request to the 'Search for Contracts' API endpoint using cURL, including setting headers and providing the request body with 'live' and 'searchText' parameters. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Contract/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "live": false, \ "searchText": "NQ" \ }' ``` -------------------------------- ### Example cURL Request to Search Contracts Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Demonstrates how to make a POST request to the 'Search for Contracts' API endpoint using cURL, including setting headers and providing the request body with 'live' and 'searchText' parameters. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Contract/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "live": false, "searchText": "NQ" }' ``` -------------------------------- ### Example Error Responses (Unauthorized/Authentication Failure) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides examples of error responses indicating an HTTP 401 Unauthorized status, which typically occurs due to authentication failures across various API endpoints like order placement, partial close, and contract searches. ```Text Error: response status is 401 ``` -------------------------------- ### Place an Order API Reference Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Detailed API documentation for the 'Place an Order' endpoint, including its URL, purpose, and a comprehensive list of all supported parameters with their types, descriptions, and optionality. ```APIDOC API URL: POST https://api.topstepx.com/api/Order/place Description: Place an order. Parameters: accountId: integer (Required, Not Nullable) - The account ID. contractId: string (Required, Not Nullable) - The contract ID. type: integer (Required, Not Nullable) - The order type: 1 = Limit 2 = Market 4 = Stop 5 = TrailingStop 6 = JoinBid 7 = JoinAsk side: integer (Required, Not Nullable) - The side of the order: 0 = Bid (buy) 1 = Ask (sell) size: integer (Required, Not Nullable) - The size of the order. limitPrice: decimal (Optional, Nullable) - The limit price for the order, if applicable. stopPrice: decimal (Optional, Nullable) - The stop price for the order, if applicable. trailPrice: decimal (Optional, Nullable) - The trail price for the order, if applicable. customTag: string (Optional, Nullable) - An optional custom tag for the order. linkedOrderId: integer (Optional, Nullable) - The linked order id. ``` -------------------------------- ### Cancel Order API Endpoint and Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Defines the API endpoint and parameters for cancelling an order, along with a cURL example demonstrating how to execute the cancellation request. ```APIDOC API URL: POST https://api.topstepx.com/api/Order/cancel API Reference: /api/Order/cancel Description: Cancel an order. Parameters: accountId: Type: integer Description: The account ID. Required: true Nullable: false orderId: Type: integer Description: The order id. Required: true Nullable: false ``` ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Order/cancel' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 465, "orderId": 26974 }' ``` -------------------------------- ### Example JSON Error Response for Account Search Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md An example of an error response from the Account search API, typically indicating an unauthorized access (HTTP 401). ```JSON Error: response status is 401 ``` -------------------------------- ### Place an Order API Reference Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Detailed API documentation for the 'Place an Order' endpoint, including its URL, purpose, and a comprehensive list of all supported parameters with their types, descriptions, and optionality. ```APIDOC API URL: POST https://api.topstepx.com/api/Order/place Description: Place an order. Parameters: accountId: integer (Required, Not Nullable) - The account ID. contractId: string (Required, Not Nullable) - The contract ID. type: integer (Required, Not Nullable) - The order type: 1 = Limit 2 = Market 4 = Stop 5 = TrailingStop 6 = JoinBid 7 = JoinAsk side: integer (Required, Not Nullable) - The side of the order: 0 = Bid (buy) 1 = Ask (sell) size: integer (Required, Not Nullable) - The size of the order. limitPrice: decimal (Optional, Nullable) - The limit price for the order, if applicable. ``` -------------------------------- ### Example cURL Request to Search Contracts Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Demonstrates how to make a POST request to the 'Search for Contracts' API endpoint using cURL, including setting headers and providing the request body with 'live' and 'searchText' parameters. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Contract/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "live": false, "searchText": "NQ" }' ``` -------------------------------- ### Example cURL Request to Search Open Orders Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md Demonstrates how to make a POST request to the Search Open Orders API using cURL, including necessary headers and the JSON request body with the account ID. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/searchOpen' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 465 }' ``` -------------------------------- ### JSON Response Example: Successful Order Modification Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md An example of a successful JSON response received after modifying an order, indicating the operation's success status. ```json { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Request: Cancel Order using cURL Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-account-module.md Illustrates how to construct and execute a POST request using cURL to cancel an order. This example includes the target URL, necessary headers, and the JSON payload containing account and order IDs. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Order/cancel' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 465, \ "orderId": 26974 \ }' ``` -------------------------------- ### ProjectX Real Time API Overview Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Provides a high-level overview of the ProjectX Real Time API, detailing its use of SignalR for WebSocket communication and the types of financial data it delivers. ```APIDOC ProjectX Real Time API: Description: Provides real-time access to data updates. Technology: SignalR library (via WebSocket) Capabilities: - Real-time access to data updates Data Types: - Accounts - Orders - Positions - Balances - Quotes ``` -------------------------------- ### ProjectX Real Time API Overview Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides an overview of the ProjectX Real Time API, detailing its reliance on the SignalR library for real-time data updates via WebSockets and listing supported data types. ```APIDOC ProjectX Real Time API: Description: Provides real-time access to data updates. Technology: SignalR library (via WebSocket) Capabilities: - Real-time access to data updates Data Types: - Accounts - Orders - Positions - Balances - Quotes ``` -------------------------------- ### SignalR Connection Setup Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Sets up and establishes a SignalR connection for real-time updates, handling various data streams like position and trade updates, and includes reconnection logic. ```javascript setupSignalRConnection(); ``` -------------------------------- ### JSON Error Response Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md An example of a JSON error response from the Retrieve Bars API, indicating a 401 Unauthorized status, typically due to authentication issues. ```JSON Error: response status is 401 ``` -------------------------------- ### JSON Error Response Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md An example of a JSON error response from the Retrieve Bars API, indicating a 401 Unauthorized status, typically due to authentication issues. ```JSON Error: response status is 401 ``` -------------------------------- ### Example cURL Request for Order Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's Order search endpoint using cURL. This example includes the required JSON body with 'accountId', 'startTimestamp', and 'endTimestamp' parameters for filtering orders within a specified time range. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 202, "startTimestamp": "2024-12-30T16:48:16.003Z", "endTimestamp": "2025-12-30T16:48:16.003Z" }' ``` -------------------------------- ### Example cURL Request for Order Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's Order search endpoint using cURL. This example includes the required JSON body with 'accountId', 'startTimestamp', and 'endTimestamp' parameters for filtering orders within a specified time range. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 202, \ "startTimestamp": "2024-12-30T16:48:16.003Z", \ "endTimestamp": "2025-12-30T16:48:16.003Z" \ }' ``` -------------------------------- ### Text Response Example: Order Modification Error (401) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md An example of an error response, specifically a 401 Unauthorized status, which might occur if authentication fails during an attempt to modify an order. ```text Error: response status is 401 ``` -------------------------------- ### Example cURL Request for Order Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's Order search endpoint using cURL. This example includes the required JSON body with 'accountId', 'startTimestamp', and 'endTimestamp' parameters for filtering orders within a specified time range. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 202, \ "startTimestamp": "2024-12-30T16:48:16.003Z", \ "endTimestamp": "2025-12-30T16:48:16.003Z" \ }' ``` -------------------------------- ### JSON Example Error Response for Retrieve Bars Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md Shows an example of an error response from the Retrieve Bars API, indicating a 401 Unauthorized status, typically due to authentication issues. ```JSON Error: response status is 401 ``` -------------------------------- ### Example cURL Request to Search Open Orders Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md Demonstrates how to make a POST request to the Search Open Orders API using cURL, including necessary headers and the JSON request body with the account ID. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/searchOpen' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 465 }' ``` -------------------------------- ### SignalR Real-Time Connection Setup Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Establishes and manages a real-time connection using SignalR for receiving updates on accounts, orders, positions, and trades. Includes subscription logic and reconnection handling. ```javascript function setupSignalRConnection() { const rtcConnection = new signalR.HubConnectionBuilder() .withUrl("https://gateway.topstepx.com/gateway") .withAutomaticReconnect() .build(); const subscribe = () => { rtcConnection.invoke('UnsubscribeAccounts'); rtcConnection.invoke('UnsubscribeOrders', SELECTED_ACCOUNT_ID); rtcConnection.invoke('UnsubscribePositions', SELECTED_ACCOUNT_ID); rtcConnection.invoke('UnsubscribeTrades', SELECTED_ACCOUNT_ID); }; rtcConnection.on('GatewayUserAccount', (data) => { console.log('Received account update', data); }); rtcConnection.on('GatewayUserOrder', (data) => { console.log('Received order update', data); }); rtcConnection.on('GatewayUserPosition', (data) => { console.log('Received position update', data); }); rtcConnection.on('GatewayUserTrade', (data) => { console.log('Received trade update', data); }); subscribe(); rtcConnection.onreconnected((connectionId) => { console.log('RTC Connection Reconnected'); subscribe(); }); rtcConnection.start().catch((err) => { console.error('Error starting connection:', err); }); } setupSignalRConnection(); ``` -------------------------------- ### Modify Order API Reference and cURL Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Details the API endpoint for modifying orders, including the HTTP method, URL, parameters, and a cURL example for executing the modification request. ```APIDOC API Endpoint: POST https://api.topstepx.com/api/Order/modify Description: Modify an open order. Parameters: - accountId: integer (Required, Not Nullable) Description: The account ID. - orderId: integer (Required, Not Nullable) Description: The order id. - size: integer (Optional, Nullable) Description: The size of the order. - limitPrice: decimal (Optional, Nullable) Description: The limit price for the order, if applicable. - stopPrice: decimal (Optional, Nullable) Description: The stop price for the order, if applicable. - trailPrice: decimal (Optional, Nullable) Description: The trail price for the order, if applicable. ``` ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/modify' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 465, "orderId": 26974, "size": 1, "limitPrice": null, "stopPrice": 1604, "trailPrice": null }' ``` -------------------------------- ### Example JSON Error Response for Retrieve Bars Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Shows an example of an error response from the Retrieve Bars API, indicating a 401 Unauthorized status, typically due to authentication issues. ```JSON Error: response status is 401 ``` -------------------------------- ### Example cURL Request for Order Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Demonstrates how to make a POST request to the ProjectX Gateway API's Order search endpoint using cURL. This example includes the required JSON body with 'accountId', 'startTimestamp', and 'endTimestamp' parameters for filtering orders within a specified time range. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 202, \ "startTimestamp": "2024-12-30T16:48:16.003Z", \ "endTimestamp": "2025-12-30T16:48:16.003Z" \ }' ``` -------------------------------- ### Text Response Example: Order Modification Error (401) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-history-module.md An example of an error response, specifically a 401 Unauthorized status, which might occur if authentication fails during an attempt to modify an order. ```Text Error: response status is 401 ``` -------------------------------- ### Example JSON Error Response: Unauthorized (401) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Shows an example of a JSON formatted error response from an API, indicating a 401 Unauthorized status, which typically arises from authentication failures. ```JSON Error: response status is 401 ``` -------------------------------- ### ProjectX Real Time API Overview Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides an overview of the ProjectX Real Time API, highlighting its use of SignalR over WebSockets for delivering real-time financial data including accounts, orders, positions, balances, and quotes. ```APIDOC ProjectX Real Time API: Description: Leverages SignalR over WebSocket to deliver real-time updates for critical financial data points. Data Streams: - Accounts - Orders - Positions - Balances - Quotes Protocols: - WebSocket Libraries: - @microsoft/signalr Key Features: - Real-time data delivery - Automatic reconnection Usage: - Establish a SignalR connection to the appropriate hub (e.g., /hubs/user, /hubs/gateway). - Authenticate using JWT tokens. - Invoke methods to subscribe to specific data streams (e.g., SubscribeAccounts, SubscribeContractQuotes). - Register event handlers for incoming data (e.g., GatewayUserAccount, GatewayQuote). - Handle connection events like reconnection. Example Hubs: - User Hub: For account-related data. - Gateway Hub: For market data (quotes, trades, depth). ``` -------------------------------- ### Example Response: Successful Order Cancellation Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Provides an example of the JSON response received when an order cancellation request is processed successfully, indicating the operation's status, error code, and message. ```JSON { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Response: Successful Order Cancellation Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md Provides an example of the JSON response received when an order cancellation request is processed successfully, indicating the operation's status, error code, and message. ```JSON { "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### ProjectX Real Time API Overview Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Provides a high-level overview of the ProjectX Real Time API, detailing its reliance on SignalR for real-time data delivery across various financial instruments. ```APIDOC ProjectX Real Time API: Description: Provides real-time access to data updates. Technology: SignalR library (via WebSocket) Capabilities: - Real-time access to data updates Data Types: - Accounts - Orders - Positions - Balances - Quotes ``` -------------------------------- ### JSON Error Response Example (401 Unauthorized) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides examples of JSON error responses indicating a 401 Unauthorized status, commonly seen in API requests due to authentication issues. ```JSON Error: response status is 401 ``` ```JSON { "success": true, "errorCode": 0, "errorMessage": null, "newToken": "NEW_TOKEN" } ``` -------------------------------- ### ProjectX Real Time API Overview Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md Provides a high-level overview of the ProjectX Real Time API, detailing its reliance on the SignalR library over WebSocket for delivering real-time financial data. ```APIDOC ProjectX Real Time API: Description: Provides real-time access to data updates. Technology: SignalR library (via WebSocket) Capabilities: - Real-time access to data updates Data Types: - Accounts - Orders - Positions - Balances - Quotes ``` -------------------------------- ### API Request Example: Search Active Accounts (curl) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-trade-module.md cURL command to demonstrate making a POST request to the /api/Account/search endpoint. ```curl curl -X 'POST' \ 'https://api.topstepx.com/api/Account/search' \ ``` -------------------------------- ### Text Response Example: Order Modification Error (401) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md An example of an error response, specifically a 401 Unauthorized status, which might occur if authentication fails during an attempt to modify an order. ```text Error: response status is 401 ``` -------------------------------- ### cURL Example Request for Account Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md A cURL command demonstrating how to invoke the Account search API endpoint with the specified headers. ```curl curl -X 'undefined' \ 'https://api.topstepx.com/api/Account/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' ``` -------------------------------- ### API Error Response Examples (401 Unauthorized) Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-account-module.md Examples of error responses from various ProjectX Gateway API endpoints, all indicating a 401 Unauthorized status, typically due to authentication issues. ```JSON Error: response status is 401 ``` ```json Error: response status is 401 ``` ```Text Error: response status is 401 ``` ```text Error: response status is 401 ``` ```Plaintext Error: response status is 401 ``` -------------------------------- ### SignalR Connection Setup Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-contract-module.md Sets up and establishes a SignalR connection for real-time updates, handling various data streams like position and trade updates, and includes reconnection logic. ```javascript setupSignalRConnection(); ``` -------------------------------- ### cURL Example Request to Close a Position Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md A cURL command demonstrating how to send a POST request to the 'Close Positions' endpoint. It includes necessary headers and a JSON body with example `accountId` and `contractId` values. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Position/closeContract' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 536, \ "contractId": "CON.F.US.GMET.J25" \ }' ``` -------------------------------- ### cURL Example Request to Close a Position Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-position-module.md A cURL command demonstrating how to send a POST request to the 'Close Positions' endpoint. It includes necessary headers and a JSON body with example `accountId` and `contractId` values. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Position/closeContract' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 536, "contractId": "CON.F.US.GMET.J25" }' ``` -------------------------------- ### cURL Example Request for Account Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-auth-module.md A cURL command demonstrating how to invoke the Account search API endpoint with the specified headers. ```curl curl -X 'undefined' \ 'https://api.topstepx.com/api/Account/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' ``` -------------------------------- ### Cancel Order API Reference and cURL Example Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides the API reference for cancelling an order and an example of how to execute this using cURL. It details the endpoint, request method, headers, and the JSON payload for cancellation. ```APIDOC POST /api/Order/cancel Operation ID: Order_CancelOrder Summary: Cancels an existing order based on the provided request. Full URL: https://api.topstepx.com/api/Order/cancel Parameters: - request (body): object - A request containing order cancellation details. - Required - Type Reference: #/definitions/CancelOrderRequest Responses: - 200: A response with order cancellation details. - Response Type: #/definitions/CancelOrderResponse Examples: /api/Order/cancel API Reference: /api/Order/cancel Description: Cancel an order. Parameters: accountId: Type: integer Description: The account ID. Required: true Nullable: false orderId: Type: integer Description: The order id. Required: true Nullable: false ``` ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Order/cancel' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 465, "orderId": 26974 }' ``` -------------------------------- ### Example cURL Request to Search Contracts Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md Provides a cURL command to demonstrate how to search for contracts using the API. It includes the endpoint URL, necessary headers, and a JSON body with parameters for `searchText` and `live`. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Contract/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "searchText": "ES", \ "live": true \ }' ``` -------------------------------- ### cURL Example Request to Close a Position Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md A cURL command demonstrating how to send a POST request to the 'Close Positions' endpoint. It includes necessary headers and a JSON body with example `accountId` and `contractId` values. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Position/closeContract' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 536, \ "contractId": "CON.F.US.GMET.J25" \ }' ``` -------------------------------- ### cURL Example Request to Close a Position Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-order-module.md A cURL command demonstrating how to send a POST request to the 'Close Positions' endpoint. It includes necessary headers and a JSON body with example `accountId` and `contractId` values. ```cURL curl -X 'POST' \ 'https://api.topstepx.com/api/Position/closeContract' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 536, "contractId": "CON.F.US.GMET.J25" }' ``` -------------------------------- ### cURL Example Request for Account Search API Source: https://github.com/1of1adam/topstepx/blob/main/topstepx-account-module.md A cURL command demonstrating how to invoke the Account search API endpoint with the specified headers. ```curl curl -X 'undefined' \ 'https://api.topstepx.com/api/Account/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' ```