### Example Success Response for Open Positions Source: https://gateway.docs.projectx.com/docs/api-reference/positions/search-open-positions This is an example of a successful response when searching for open positions. It includes details about the positions found, such as ID, account ID, contract ID, creation timestamp, type, size, and average price. ```json { "positions": [ { "id": 6124, "accountId": 536, "contractId": "CON.F.US.GMET.J25", "creationTimestamp": "2025-04-21T19:52:32.175721+00:00", "type": 1, "size": 2, "averagePrice": 1575.750000000 } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Order Search Response Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-search This is an example of a successful response when searching for orders. It includes a list of orders matching the criteria and success status. ```json { "orders": [ { "id": 36598, "accountId": 704, "contractId": "CON.F.US.EP.U25", "symbolId": "F.US.EP", "creationTimestamp": "2025-07-18T21:00:01.268009+00:00", "updateTimestamp": "2025-07-18T21:00:01.268009+00:00", "status": 2, "type": 2, "side": 0, "size": 1, "limitPrice": null, "stopPrice": null, "fillVolume": 1, "filledPrice": 6335.250000000, "customTag": null } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Error Response for Open Positions Source: https://gateway.docs.projectx.com/docs/api-reference/positions/search-open-positions This example shows an error response, typically indicating an issue like an unauthorized request (e.g., status code 401). ```text Error: response status is 401 ``` -------------------------------- ### Example Success Response for Open Orders Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-search-open This is a successful response structure when searching for open orders. It includes a list of orders with their details. ```json { "orders": [ { "id": 26970, "accountId": 212, "contractId": "CON.F.US.EP.M25", "creationTimestamp": "2025-04-21T19:45:52.105808+00:00", "updateTimestamp": "2025-04-21T19:45:52.105808+00:00", "status": 1, "type": 4, "side": 1, "size": 1, "limitPrice": null, "stopPrice": 5138.000000000, "filledPrice": null } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Error Response for Account Search Source: https://gateway.docs.projectx.com/docs/api-reference/account/search-accounts This example shows an error response, typically indicating an authentication issue (e.g., status 401). ```text Error: response status is 401 ``` -------------------------------- ### Example Error Response for Open Orders Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-search-open This indicates an error response, typically due to authentication or authorization issues. ```text Error: response status is 401 ``` -------------------------------- ### API Response for Successful Login Source: https://gateway.docs.projectx.com/docs/getting-started/authenticate/authenticate-api-key This is an example of a successful API response after logging in with your API key. The 'token' field contains the session token required for subsequent API requests. ```json { "token": "your_session_token_here", "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Successful Contract Search Response Source: https://gateway.docs.projectx.com/docs/api-reference/market-data/search-contracts Example of a successful response from the Contract Search API, listing contract details. ```json { "contracts": [ { "id": "CON.F.US.ENQ.U25", "name": "NQU5", "description": "E-mini NASDAQ-100: September 2025", "tickSize": 0.25, "tickValue": 5, "activeContract": true, "symbolId": "F.US.ENQ" }, { "id": "CON.F.US.MNQ.U25", "name": "MNQU5", "description": "Micro E-mini Nasdaq-100: September 2025", "tickSize": 0.25, "tickValue": 0.5, "activeContract": true, "symbolId": "F.US.MNQ" }, { "id": "CON.F.US.NQG.Q25", "name": "QGQ5", "description": "E-Mini Natural Gas: August 2025", "tickSize": 0.005, "tickValue": 12.5, "activeContract": true, "symbolId": "F.US.NQG" }, { "id": "CON.F.US.NQM.U25", "name": "QMU5", "description": "E-Mini Crude Oil: September 2025", "tickSize": 0.025, "tickValue": 12.5, "activeContract": true, "symbolId": "F.US.NQM" } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Success Response for Account Search Source: https://gateway.docs.projectx.com/docs/api-reference/account/search-accounts This is an example of a successful response when searching for accounts. It includes a list of accounts with their details and a success status. ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "balance": 50000, "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### API Response for Application Login Source: https://gateway.docs.projectx.com/docs/getting-started/authenticate/authenticate-as-application This is an example of a successful API response after authenticating your application. The 'token' field contains the session token required for subsequent API calls. ```json { "token": "your_session_token_here", "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Validate Session Token Response Source: https://gateway.docs.projectx.com/docs/getting-started/validate-session This is an example of a successful response from the token validation endpoint. It includes a new token if the validation is successful. ```json { "success": true, "errorCode": 0, "errorMessage": null, "newToken": "NEW_TOKEN" } ``` -------------------------------- ### Example API Response for Available Contracts Source: https://gateway.docs.projectx.com/docs/api-reference/market-data/available-contracts This JSON structure represents a successful response when querying for available contracts. It lists various contract details such as ID, name, description, tick size, tick value, and active status. ```json { "contracts": [ { "id": "CON.F.US.BP6.U25", "name": "6BU5", "description": "British Pound (Globex): September 2025", "tickSize": 0.0001, "tickValue": 6.25, "activeContract": true, "symbolId": "F.US.BP6" }, { "id": "CON.F.US.CA6.U25", "name": "6CU5", "description": "Canadian Dollar (Globex): September 2025", "tickSize": 0.00005, "tickValue": 5, "activeContract": true, "symbolId": "F.US.CA6" }, { "id": "CON.F.US.DA6.U25", "name": "6AU5", "description": "Australian Dollar (Globex): September 2025", "tickSize": 0.00005, "tickValue": 5, "activeContract": true, "symbolId": "F.US.DA6" }, { "id": "CON.F.US.EEU.U25", "name": "E7U5", "description": "E-mini Euro FX: September 2025", "tickSize": 0.0001, "tickValue": 6.25, "activeContract": true, "symbolId": "F.US.EEU" }, { "id": "CON.F.US.EMD.U25", "name": "EMDU5", "description": "E-mini MidCap 400: September 2025", "tickSize": 0.1, "tickValue": 10, "activeContract": true, "symbolId": "F.US.EMD" }, { "id": "CON.F.US.ENQ.U25", "name": "NQU5", "description": "E-mini NASDAQ-100: September 2025", "tickSize": 0.25, "tickValue": 5, "activeContract": true, "symbolId": "F.US.ENQ" }, { "id": "CON.F.US.EP.U25", "name": "ESU5", "description": "E-Mini S&P 500: September 2025", "tickSize": 0.25, "tickValue": 12.5, "activeContract": true, "symbolId": "F.US.EP" }, { "id": "CON.F.US.EU6.U25", "name": "6EU5", "description": "Euro FX (Globex): September 2025", "tickSize": 0.00005, "tickValue": 6.25, "activeContract": true, "symbolId": "F.US.EU6" }, { "id": "CON.F.US.GF.Q25", "name": "GFQ5", "description": "Feeder Cattle (Globex): August 2025", "tickSize": 0.025, "tickValue": 12.5, "activeContract": true, "symbolId": "F.US.GF" }, { "id": "CON.F.US.GLE.Q25", "name": "LEQ5", "description": "Live Cattle (Globex): August 2025", "tickSize": 0.025, "tickValue": 10, "activeContract": true, "symbolId": "F.US.GLE" }, { "id": "CON.F.US.GMCD.U25", "name": "MCDU5", "description": "E-Micro CAD/USD: September 2025", "tickSize": 0.0001, "tickValue": 1, "activeContract": true, "symbolId": "F.US.GMCD" }, { "id": "CON.F.US.GMET.N25", "name": "METN5", "description": "Micro Ether: July 2025", "tickSize": 0.5, "tickValue": 0.05, "activeContract": true, "symbolId": "F.US.GMET" }, { "id": "CON.F.US.HE.Q25", "name": "HEQ5", "description": "Lean Hogs (Globex): August 2025", "tickSize": 0.025, "tickValue": 10, "activeContract": true, "symbolId": "F.US.HE" }, { "id": "CON.F.US.JY6.U25", "name": "6JU5", "description": "Japanese Yen (Globex): September 2025", "tickSize": 0.0000005, "tickValue": 6.25, "activeContract": true, "symbolId": "F.US.JY6" }, { "id": "CON.F.US.M2K.U25", "name": "M2KU5", "description": "Micro E-mini Russell 2000: September 2025", "tickSize": 0.1, "tickValue": 0.5, "activeContract": true, "symbolId": "F.US.M2K" }, { "id": "CON.F.US.M6A.U25", "name": "M6AU5", "description": "E-Micro AUD/USD: September 2025", "tickSize": 0.0001, "tickValue": 1, "activeContract": true, "symbolId": "F.US.M6A" }, { "id": "CON.F.US.M6B.U25", "name": "M6BU5", "description": "E-Micro GBP/USD: September 2025", "tickSize": 0.0001, "tickValue": 1, "activeContract": true, "symbolId": "F.US.M6B" } ] } ``` -------------------------------- ### Close Position Response (JSON) Source: https://gateway.docs.projectx.com/docs/api-reference/positions/close-positions Example JSON responses for closing a position. The success response indicates the operation was completed, while an error response will contain details about the failure. ```json { "success": true, "errorCode": 0, "errorMessage": null } ``` ```json Error: response status is 401 ``` -------------------------------- ### Example API Response for Contract Search Source: https://gateway.docs.projectx.com/docs/api-reference/market-data/search-contracts-by-id This JSON object represents a successful response when searching for a contract by its ID, including contract details and success status. ```json { "contract": { "id": "CON.F.US.ENQ.H25", "name": "NQH5", "description": "E-mini NASDAQ-100: March 2025", "tickSize": 0.25, "tickValue": 5, "activeContract": false, "symbolId": "F.US.ENQ" }, "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### Example Success Response for Trade Search Source: https://gateway.docs.projectx.com/docs/api-reference/trade/trade-search This JSON structure represents a successful response from the Trade Search API, containing a list of trades with their details. A null profitAndLoss indicates a half-turn trade. ```json { "trades": [ { "id": 8604, "accountId": 203, "contractId": "CON.F.US.EP.H25", "creationTimestamp": "2025-01-21T16:13:52.523293+00:00", "price": 6065.250000000, "profitAndLoss": 50.000000000, "fees": 1.4000, "side": 1, "size": 1, "voided": false, "orderId": 14328 }, { "id": 8603, "accountId": 203, "contractId": "CON.F.US.EP.H25", "creationTimestamp": "2025-01-21T16:13:04.142302+00:00", "price": 6064.250000000, "profitAndLoss": null, //a null value indicates a half-turn trade "fees": 1.4000, "side": 0, "size": 1, "voided": false, "orderId": 14326 } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### cURL Request for Order Search Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-search Use this cURL request to search for orders. It requires an account ID and a start timestamp, with an optional end timestamp. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Order/search' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 704, "startTimestamp": "2025-07-18T21:00:01.268009+00:00", "endTimestamp": "2025-07-18T21:00:01.278009+00:00" }' ``` -------------------------------- ### Successful Bars Response Source: https://gateway.docs.projectx.com/docs/api-reference/market-data/retrieve-bars This is an example of a successful response from the Retrieve Bars API, containing an array of bar data, including timestamp, open, high, low, close prices, and volume. ```json { "bars": [ { "t": "2024-12-20T14:00:00+00:00", "o": 2208.100000000, "h": 2217.000000000, "l": 2206.700000000, "c": 2210.100000000, "v": 87 }, { "t": "2024-12-20T13:00:00+00:00", "o": 2195.800000000, "h": 2215.000000000, "l": 2192.900000000, "c": 2209.800000000, "v": 536 }, { "t": "2024-12-20T12:00:00+00:00", "o": 2193.600000000, "h": 2200.300000000, "l": 2192.000000000, "c": 2198.000000000, "v": 180 }, { "t": "2024-12-20T11:00:00+00:00", "o": 2192.200000000, "h": 2194.800000000, "l": 2189.900000000, "c": 2194.800000000, "v": 174 }, { "t": "2024-12-20T10:00:00+00:00", "o": 2200.400000000, "h": 2200.400000000, "l": 2191.000000000, "c": 2193.100000000, "v": 150 }, { "t": "2024-12-20T09:00:00+00:00", "o": 2205.000000000, "h": 2205.800000000, "l": 2198.900000000, "c": 2200.500000000, "v": 56 }, { "t": "2024-12-20T08:00:00+00:00", "o": 2207.700000000, "h": 2210.100000000, "l": 2198.100000000, "c": 2204.900000000, "v": 144 } ], "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### API Response for Order Cancellation Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-cancel Example of a successful response from the Order Cancel API. A 'success' value of true indicates the order was cancelled. Error responses will contain an errorCode and errorMessage. ```json { "success": true, "errorCode": 0, "errorMessage": null } ``` ```text Error: response status is 401 ``` -------------------------------- ### cURL Request to Search Trades Source: https://gateway.docs.projectx.com/docs/api-reference/trade/trade-search Use this cURL command to send a POST request to the Trade Search API. Ensure the Content-Type is set to application/json and provide the required account ID and start timestamp. ```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" }' ``` -------------------------------- ### Step 3: Place an Order Source: https://gateway.docs.projectx.com/docs/getting-started/placing-your-first-order Submit an order request using the account ID and contract ID obtained in the previous steps. ```APIDOC ## POST /api/Order/place ### Description Places an order for a specified contract on a given account. ### Method POST ### Endpoint https://api.topstepx.com/api/Order/place ### Parameters #### Request Body - **accountId** (integer) - Required - The ID of the account on which to place the order. - **contractId** (string) - Required - The ID of the contract to trade. - **type** (integer) - Required - The type of order (e.g., 2 for Market order). - **side** (integer) - Required - The side of the order (e.g., 1 for Ask). - **size** (integer) - Required - The size of the order. ### Request Example ```json { "accountId": 1, "contractId": "CON.F.US.BP6.U25", "type": 2, "side": 1, "size": 1 } ``` ### Response #### Success Response (200) - **orderId** (integer) - The unique identifier for the placed order. - **success** (boolean) - Indicates if the operation was successful. - **errorCode** (integer) - The error code, 0 for success. - **errorMessage** (null) - Error message, null if successful. #### Response Example ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` #### Error Response - **Error**: response status is 401 ``` -------------------------------- ### Place an Order Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-place Allows users to place an order. Supports different order types, sides, and optional bracket configurations for stop-loss and take-profit. ```APIDOC ## POST /api/Order/place ### Description Place an order. ### Method POST ### Endpoint https://api.topstepx.com/api/Order/place ### Parameters #### Request Body - **accountId** (integer) - Required - The account ID. - **contractId** (string) - Required - The contract ID. - **type** (integer) - Required - The order type: `1` = Limit, `2` = Market, `4` = Stop, `5` = TrailingStop, `6` = JoinBid, `7` = JoinAsk. - **side** (integer) - Required - The side of the order: `0` = Bid (buy), `1` = Ask (sell). - **size** (integer) - Required - The size of the order. - **limitPrice** (decimal) - Optional - The limit price for the order, if applicable. - **stopPrice** (decimal) - Optional - The stop price for the order, if applicable. - **trailPrice** (decimal) - Optional - The trail price for the order, if applicable. - **customTag** (string) - Optional - An optional custom tag for the order. Must be unique across the account. - **stopLossBracket** (object) - Optional - Stop loss bracket configuration. - **ticks** (integer) - Required - Number of ticks for stop loss. - **type** (integer) - Required - Type of stop loss bracket. Uses same OrderType enum values: `1` = Limit, `2` = Market, `4` = Stop, `5` = TrailingStop, `6` = JoinBid, `7` = JoinAsk. - **takeProfitBracket** (object) - Optional - Take profit bracket configuration. - **ticks** (integer) - Required - Number of ticks for take profit. - **type** (integer) - Required - Type of take profit bracket. Uses same OrderType enum values: `1` = Limit, `2` = Market, `4` = Stop, `5` = TrailingStop, `6` = JoinBid, `7` = JoinAsk. ### Request Example ```json { "accountId": 465, "contractId": "CON.F.US.DA6.M25", "type": 2, "side": 1, "size": 1, "limitPrice": null, "stopPrice": null, "trailPrice": null, "customTag": null, "stopLossBracket": { "ticks": 10, "type": 4 }, "takeProfitBracket": { "ticks": 20, "type": 1 } } ``` ### Response #### Success Response (200) - **orderId** (integer) - Description of orderId. - **success** (boolean) - Indicates if the order placement was successful. - **errorCode** (integer) - Error code if the operation failed. - **errorMessage** (string) - Error message if the operation failed. #### Response Example ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` ``` -------------------------------- ### Step 1: Retrieve Active Accounts Source: https://gateway.docs.projectx.com/docs/getting-started/placing-your-first-order Initiate the order process by retrieving a list of active accounts linked to your user. This step is essential for confirming your account status before placing an order. ```APIDOC ## POST /api/Account/search ### Description Retrieves a list of active accounts associated with the user. ### Method POST ### Endpoint https://api.topstepx.com/api/Account/search ### Parameters #### Request Body - **onlyActiveAccounts** (boolean) - Required - Specifies whether to retrieve only active accounts. ### Request Example ```json { "onlyActiveAccounts": true } ``` ### Response #### Success Response (200) - **accounts** (array) - A list of account objects. - **id** (integer) - The unique identifier for the account. - **name** (string) - The name of the account. - **canTrade** (boolean) - Indicates if trading is allowed for this account. - **isVisible** (boolean) - Indicates if the account is visible. - **success** (boolean) - Indicates if the operation was successful. - **errorCode** (integer) - The error code, 0 for success. - **errorMessage** (null) - Error message, null if successful. #### Response Example ```json { "accounts": [ { "id": 1, "name": "TEST_ACCOUNT_1", "canTrade": true, "isVisible": true } ], "success": true, "errorCode": 0, "errorMessage": null } ``` ``` -------------------------------- ### Place an Order Source: https://gateway.docs.projectx.com/docs/getting-started/placing-your-first-order Submit your order request using the account ID and contract ID. This endpoint allows for market orders. ```json { "accountId": 1, // Replace with your actual account ID "contractId": "CON.F.US.BP6.U25", // Replace with the contract ID you want to trade "type": 2, // Market order "side": 1, // Ask "size": 1 // Size of the order } ``` ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` ```curl curl -X 'POST' \ 'https://api.topstepx.com/api/Order/place' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ \ "accountId": 1, \ "contractId": "CON.F.US.BP6.U25", \ "type": 2, \ "side": 1, \ "size": 1 \ }' ``` ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` ```text Error: response status is 401 ``` -------------------------------- ### cURL Request to Search Open Positions Source: https://gateway.docs.projectx.com/docs/api-reference/positions/search-open-positions Use this cURL command to send a POST request to search for open positions. Ensure the Content-Type is application/json and provide the account ID in the request body. ```curl curl -X 'POST' \ 'https://api.topstepx.com/api/Position/searchOpen' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "accountId": 536 }' ``` -------------------------------- ### Step 2: Retrieve Available Contracts Source: https://gateway.docs.projectx.com/docs/getting-started/placing-your-first-order Retrieve a list of available contracts that can be traded. This step allows you to browse through the contracts. ```APIDOC ## POST /api/Contract/available ### Description Retrieves a list of available contracts for trading. ### Method POST ### Endpoint https://api.topstepx.com/api/Contract/available ### Parameters #### Request Body - **live** (boolean) - Required - Specifies whether to retrieve live contracts. ### Request Example ```json { "live": false } ``` ### Response #### Success Response (200) - **contracts** (array) - A list of contract objects. - **id** (string) - The unique identifier for the contract. - **name** (string) - The name of the contract. - **description** (string) - A description of the contract. - **tickSize** (number) - The minimum price movement for the contract. - **tickValue** (number) - The value of one tick for the contract. - **activeContract** (boolean) - Indicates if the contract is active. - **symbolId** (string) - The symbol identifier for the contract. - **success** (boolean) - Indicates if the operation was successful. - **errorCode** (integer) - The error code, 0 for success. - **errorMessage** (null) - Error message, null if successful. #### Response Example ```json { "contracts": [ { "id": "CON.F.US.BP6.U25", "name": "6BU5", "description": "British Pound (Globex): September 2025", "tickSize": 0.0001, "tickValue": 6.25, "activeContract": true, "symbolId": "F.US.BP6" } ], "success": true, "errorCode": 0, "errorMessage": null } ``` ``` -------------------------------- ### Place Order Success Response Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-place A successful order placement will return a JSON object with the order ID and a success status. ```json { "orderId": 9056, "success": true, "errorCode": 0, "errorMessage": null } ``` -------------------------------- ### cURL Request to List Available Contracts Source: https://gateway.docs.projectx.com/docs/api-reference/market-data/available-contracts Use this cURL command to send a POST request to the API to list available contracts. Ensure the Content-Type is set to application/json and include the 'live' parameter in the request body. ```curl curl -X 'POST' \ 'https://api.topstepx.com/api/Contract/available' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "live": true }' ``` -------------------------------- ### cURL Request to Login with API Key Source: https://gateway.docs.projectx.com/docs/getting-started/authenticate/authenticate-api-key Use this cURL command to send your API key and username to the login endpoint to obtain a session token. Ensure you replace 'string' with your actual credentials. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Auth/loginKey' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "userName": "string", "apiKey": "string" }' ``` -------------------------------- ### cURL Request to Login Application Source: https://gateway.docs.projectx.com/docs/getting-started/authenticate/authenticate-as-application Use this cURL command to send your application credentials to the loginApp endpoint. Ensure you replace placeholder values with your actual credentials. ```bash curl -X 'POST' \ 'https://api.topstepx.com/api/Auth/loginApp' \ -H 'accept: text/plain' \ -H 'Content-Type: application/json' \ -d '{ "userName": "yourUsername", "password": "yourPassword", "deviceId": "yourDeviceId", "appId": "yourApplicationID", "verifyKey": "yourVerifyKey" }' ``` -------------------------------- ### Place Order cURL Request Source: https://gateway.docs.projectx.com/docs/api-reference/order/order-place Use this cURL command to send a POST request to the Place Order API. Ensure all required parameters are correctly formatted in the JSON body. ```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, "stopLossBracket": { "ticks": 10, "type": 4 }, "takeProfitBracket": { "ticks": 20, "type": 1 } }' ``` -------------------------------- ### Connect to User Hub with SignalR Source: https://gateway.docs.projectx.com/docs/realtime Establishes a SignalR connection to the User Hub to subscribe to account, order, position, and trade updates. Ensure you have a valid JWT token and the correct account ID. ```javascript // Import the necessary modules from @microsoft/signalr const { HubConnectionBuilder, HttpTransportType } = require('@microsoft/signalr'); function setupSignalRConnection() { const JWT_TOKEN = 'your_bearer_token'; const SELECTED_ACCOUNT_ID = 123; // your currently selected/visible account ID const userHubUrl = 'https://rtc.topstepx.com/hubs/user?access_token=YOUR_JWT_TOKEN'; const rtcConnection = new HubConnectionBuilder() .withUrl(userHubUrl, { skipNegotiation: true, transport: HttpTransportType.WebSockets, accessTokenFactory: () => JWT_TOKEN, timeout: 10000 }) .withAutomaticReconnect() .build(); rtcConnection.start() .then(() => { const subscribe = () => { rtcConnection.invoke('SubscribeAccounts'); rtcConnection.invoke('SubscribeOrders', SELECTED_ACCOUNT_ID); rtcConnection.invoke('SubscribePositions', SELECTED_ACCOUNT_ID); rtcConnection.invoke('SubscribeTrades', SELECTED_ACCOUNT_ID); }; const unsubscribe = () => { 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(); }); }) .catch((err) => { console.error('Error starting connection:', err); }); } // Call the function to set up and start the connection setupSignalRConnection(); ``` -------------------------------- ### Login with API Key Source: https://gateway.docs.projectx.com/docs/getting-started/authenticate/authenticate-api-key This endpoint is used to authenticate your application with the Gateway API by providing your API key. Upon successful authentication, a session token will be returned, which is required for subsequent API requests. ```APIDOC ## POST /api/Auth/loginKey ### Description Authenticates a user with an API key and returns a session token. ### Method POST ### Endpoint https://api.topstepx.com/api/Auth/loginKey ### Request Body - **userName** (string) - Required - The username associated with the API key. - **apiKey** (string) - Required - The API key provided by your firm. ### Request Example ```json { "userName": "string", "apiKey": "string" } ``` ### Response #### Success Response (0) - **token** (string) - The session token for accessing the Gateway API. - **success** (boolean) - Indicates if the authentication was successful. - **errorCode** (integer) - The error code (0 for success). - **errorMessage** (null) - Null if the operation was successful. #### Response Example ```json { "token": "your_session_token_here", "success": true, "errorCode": 0, "errorMessage": null } ``` ``` -------------------------------- ### List Available Contracts Source: https://gateway.docs.projectx.com/docs/category/market-data Retrieves a list of all available financial contracts. ```APIDOC ## List Available Contracts ### Description Provides a comprehensive list of all financial contracts available through the API. ### Method GET ### Endpoint /marketdata/contracts ### Query Parameters - **limit** (integer) - Optional - The maximum number of results to return. Defaults to 100. - **offset** (integer) - Optional - The number of results to skip. Defaults to 0. ### Response #### Success Response (200) - **contracts** (array) - A list of available contracts. - **id** (string) - The unique identifier for the contract. - **symbol** (string) - The contract's symbol. - **name** (string) - The full name of the contract. - **assetClass** (string) - The asset class of the contract. ``` -------------------------------- ### Connect to Market Hub with SignalR Source: https://gateway.docs.projectx.com/docs/realtime Establishes a SignalR connection to the Market Hub to subscribe to contract quotes, trades, and market depth. Requires a valid JWT token and contract ID. ```javascript // Import the necessary modules from @microsoft/signalr const { HubConnectionBuilder, HttpTransportType } = require('@microsoft/signalr'); function setupSignalRConnection() { const JWT_TOKEN = 'your_bearer_token'; const marketHubUrl = 'https://rtc.topstepx.com/hubs/market?access_token=YOUR_JWT_TOKEN'; const CONTRACT_ID = 'CON.F.US.RTY.H25'; const rtcConnection = new HubConnectionBuilder() .withUrl(marketHubUrl, { skipNegotiation: true, transport: HttpTransportType.WebSockets, accessTokenFactory: () => JWT_TOKEN, timeout: 10000 }) .withAutomaticReconnect() .build(); rtcConnection.start() .then(() => { const subscribe = () => { rtcConnection.invoke('SubscribeContractQuotes', CONTRACT_ID); rtcConnection.invoke('SubscribeContractTrades', CONTRACT_ID); rtcConnection.invoke('SubscribeContractMarketDepth', CONTRACT_ID); }; const unsubscribe = () => { rtcConnection.invoke('UnsubscribeContractQuotes', CONTRACT_ID); rtcConnection.invoke('UnsubscribeContractTrades', CONTRACT_ID); rtcConnection.invoke('UnsubscribeContractMarketDepth', CONTRACT_ID); }; rtcConnection.on('GatewayQuote', (contractId, data) => { console.log('Received market quote data', data); }); rtcConnection.on('GatewayTrade', (contractId, data) => { console.log('Received market trade data', data); }); rtcConnection.on('GatewayDepth', (contractId, data) => { console.log('Received market depth data', data); }); subscribe(); rtcConnection.onreconnected((connectionId) => { console.log('RTC Connection Reconnected'); subscribe(); }); }) .catch((err) => { console.error('Error starting connection:', err); }); } // Call the function to set up and start the connection setupSignalRConnection(); ``` -------------------------------- ### List Available Contracts Source: https://gateway.docs.projectx.com/docs/api-reference/market-data/available-contracts Lists available contracts based on the provided request parameters. ```APIDOC ## POST /api/Contract/available ### Description Lists available contracts based on the provided request parameters. ### Method POST ### Endpoint https://api.topstepx.com/api/Contract/available ### Parameters #### Request Body - **live** (boolean) - Required - Whether to retrieve live contracts. ### Request Example ```json { "live": true } ``` ### Response #### Success Response (200) - **contracts** (array) - A list of available contracts. - **symbol** (string) - The contract symbol. - **description** (string) - The contract description. - **expirationDate** (string) - The contract expiration date. - **tickValue** (number) - The value of a single tick. - **tickSize** (number) - The minimum price increment. - **contractSize** (number) - The size of the contract. - **exchange** (string) - The exchange where the contract is traded. - **multiplier** (number) - The contract multiplier. - **pointValue** (number) - The value of a point. - **contractType** (string) - The type of contract. - **underlyingSymbol** (string) - The symbol of the underlying asset. - **underlyingType** (string) - The type of the underlying asset. - **isTradingHalted** (boolean) - Indicates if trading is halted for the contract. - **lastTradingDate** (string) - The last date for trading the contract. - **tradingHours** (string) - The trading hours for the contract. - **marginRequirement** (number) - The margin required for the contract. - **commission** (number) - The commission for trading the contract. - **fees** (number) - The fees associated with the contract. - **contractMultiplierUnit** (string) - The unit of the contract multiplier. - **contractSizeUnit** (string) - The unit of the contract size. - **pointValueUnit** (string) - The unit of the point value. - **tickValueUnit** (string) - The unit of the tick value. - **tickSizeUnit** (string) - The unit of the tick size. - **marginRequirementUnit** (string) - The unit of the margin requirement. - **commissionUnit** (string) - The unit of the commission. - **feesUnit** (string) - The unit of the fees. #### Response Example ```json { "contracts": [ { "symbol": "ES", "description": "E-mini S&P 500", "expirationDate": "2023-12-15T00:00:00Z", "tickValue": 50.0, "tickSize": 0.25, "contractSize": 50.0, "exchange": "CME", "multiplier": 50.0, "pointValue": 50.0, "contractType": "FUT", "underlyingSymbol": "SPX", "underlyingType": "INDEX", "isTradingHalted": false, "lastTradingDate": "2023-12-15T00:00:00Z", "tradingHours": "00:00-23:59", "marginRequirement": 10000.0, "commission": 1.5, "fees": 0.5, "contractMultiplierUnit": "USD", "contractSizeUnit": "USD", "pointValueUnit": "USD", "tickValueUnit": "USD", "tickSizeUnit": "USD", "marginRequirementUnit": "USD", "commissionUnit": "USD", "feesUnit": "USD" } ] } ``` ```