Skip to content

Commit 792bdef

Browse files
committed
refactor(topstepx): migrate to extensions & enhance cli integration
- **Migration**: Moved TopstepX Python client to and SignalR Bridge to . - **Refactor**: Updated all tests to be standalone, removing server dependencies. Verified 20/20 pass. - **CLI**: Added command group for managing credentials, environment, and Hub URLs. - **Configuration**: Standardized environment variables (, , ) with production defaults. - **Documentation**: Added guide and files for Agent support.
1 parent 353e158 commit 792bdef

48 files changed

Lines changed: 1479 additions & 197 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/TOPSTEPX_INTEGRATION.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# TopstepX Integration Guide
2+
3+
## Overview
4+
The **TopstepX Integration** enables QuanuX to interact with the TopstepX platform for trading, account management, and real-time market data. It is architected as a set of decoupled [QuanuX Extensions](EXTENSIONS.md):
5+
6+
1. **TopstepX Interface (`quanux-topstepx`)**: A Python-based REST client for account retrieval, order execution, and history.
7+
2. **SignalR Bridge (`quanux-bridge-signalr`)**: A polyglot (Node.js/Python) bridge that maintains a persistent WebSocket connection to TopstepX's SignalR hubs for real-time market data and user events.
8+
9+
## Architecture
10+
11+
```mermaid
12+
graph TD
13+
User[User / QuanuX Agent] -->|CLI / Events| TopstepX[TopstepX Extension]
14+
User -->|Market Data| SignalR[SignalR Bridge]
15+
16+
TopstepX -->|REST API| TS_API[api.topstepx.com]
17+
SignalR -->|WebSockets| TS_Hubs[rtc.topstepx.com]
18+
19+
subgraph "Extensions Layer"
20+
TopstepX
21+
SignalR
22+
end
23+
24+
subgraph "External"
25+
TS_API
26+
TS_Hubs
27+
end
28+
```
29+
30+
## Configuration
31+
32+
### Credentials
33+
All sensitive credentials are stored securely in the system keyring via `quanuxctl`. They are **never** stored in plain text configuration files.
34+
35+
| Key | Description |
36+
| :--- | :--- |
37+
| `QUANUX_TOPSTEP__USERNAME` | TopstepX Username |
38+
| `QUANUX_TOPSTEP__PASSWORD` | TopstepX Password |
39+
| `QUANUX_TOPSTEP__API_KEY` | TopstepX API Key |
40+
41+
### Endpoints (Defaults)
42+
The extensions are pre-configured for the production environment but can be overridden via `quanuxctl`.
43+
44+
| Key | Default Value | Description |
45+
| :--- | :--- | :--- |
46+
| `QUANUX_TOPSTEP__BASE_API_URL` | `https://api.topstepx.com` | REST API Base URL |
47+
| `QUANUX_SIGNALR_USER_HUB` | `https://rtc.topstepx.com/hubs/user` | Real-time User Events |
48+
| `QUANUX_SIGNALR_MARKET_HUB` | `https://rtc.topstepx.com/hubs/market` | Real-time Market Data |
49+
50+
## Usage
51+
52+
### CLI Management (`quanuxctl`)
53+
Manage the integration directly from the command line:
54+
55+
```bash
56+
# Set Credentials
57+
quanuxctl topstepx user "myuser"
58+
quanuxctl topstepx password "mypass"
59+
quanuxctl topstepx apikey "mykey"
60+
61+
# Verify Environment
62+
quanuxctl topstepx env
63+
64+
# Install Dependencies
65+
quanuxctl topstepx install
66+
```
67+
68+
### SignalR Bridge
69+
The bridge runs as a separate process managed by QuanuX. It connects to the configured hubs and broadcasts events to the local QuanuX message bus.
70+
71+
**Status Check:**
72+
```bash
73+
quanuxctl bridge status
74+
```
75+
76+
**Manual Start (Debug):**
77+
```bash
78+
quanuxctl bridge run
79+
```
80+
81+
## Developer Usage
82+
83+
### Python Extension (`extensions/python/topstepx`)
84+
The extension exposes a standard interface for interactions. The source code is located in `extensions/python/topstepx/src`.
85+
86+
**Key Modules:**
87+
* `auth.py`: Handles authentication and token management.
88+
* `orders.py`: Order placement and management.
89+
* `positions.py`: Position tracking.
90+
* `history.py`: Historical bar retrieval.
91+
92+
### SignalR Bridge (`extensions/python/signalr_bridge`)
93+
The bridge uses a Node.js worker (default) or Flask app to handle the proprietary SignalR protocol.
94+
95+
**Custom Hub Configuration:**
96+
If you need to connect to a different environment (e.g., simulation):
97+
```bash
98+
quanuxctl topstepx user-hub "https://sim-rtc.topstepx.com/hubs/user"
99+
quanuxctl topstepx market-hub "https://sim-rtc.topstepx.com/hubs/market"
100+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
name: signalr-bridge
3+
description: Instructions for operating and configuring the SignalR Bridge for TopstepX.
4+
---
5+
6+
# SignalR Bridge Skill
7+
8+
The **SignalR Bridge** (`quanux-bridge-signalr`) is a specialized extension that maintains persistent WebSocket connections to TopstepX's SignalR Hubs. It bridges the gap between the proprietary SignalR protocol and QuanuX's internal messaging.
9+
10+
## Location
11+
- **Path**: `extensions/python/signalr_bridge`
12+
- **Config**: `extensions/python/signalr_bridge/extension.yaml`
13+
- **Node Runtime**: `extensions/python/signalr_bridge/src/node` (Preferred)
14+
- **Flask Runtime**: `extensions/python/signalr_bridge/src/flask` (Legacy/Fallback)
15+
16+
## Architecture
17+
The bridge runs as a standalone process (supervised by QuanuX).
18+
- **Upstream**: Connects to `rtc.topstepx.com` (User/Market Hubs).
19+
- **Downstream**: Exposes a wrapper WebSocket (or HTTP callbacks) to QuanuX components.
20+
21+
## Configuration (TopstepX Specific)
22+
This bridge is pre-configured for TopstepX logic but is technically generic.
23+
24+
**Key Environment Variables (Managed via `quanuxctl topstepx env`):**
25+
- `QUANUX_SIGNALR_USER_HUB`: URL for the User Hub (Login, Orders, Fills).
26+
- Default: `https://rtc.topstepx.com/hubs/user`
27+
- `QUANUX_SIGNALR_MARKET_HUB`: URL for the Market Hub (Quotes, Level 2).
28+
- Default: `https://rtc.topstepx.com/hubs/market`
29+
30+
## Operation
31+
32+
### Starting the Bridge
33+
The bridge is usually started automatically by `quanuxctl bridge` or the main server.
34+
To verify functionality manually:
35+
```bash
36+
# In extensions/python/signalr_bridge
37+
python src/supervisor.py
38+
```
39+
40+
### Health Check
41+
The Node runtime exposes a health endpoint:
42+
```bash
43+
curl http://localhost:8077/health
44+
```
45+
Response should include `"status": "ok"` and `"hubUrl"`.
46+
47+
### Debugging Connection Issues
48+
1. **Check URLs**: Ensure `QUANUX_SIGNALR_USER_HUB` is set correctly.
49+
2. **Check Token**: The bridge relies on `SIGNALR_ACCESS_TOKEN` which is usually refreshed and injected by the main `quanux-topstepx` auth flow. If authentication fails, the bridge cannot connect.
50+
3. **Logs**: Check `~/.quanux/logs/quanux-bridge-signalr.log`.
51+
52+
## Development
53+
- **Node.js**: `src/node/index.mjs`. Uses `@microsoft/signalr` client.
54+
- To install deps: `npm install` in `src/node`.
55+
- **Modifying Events**: If new TopstepX events need to be tracked, update the `on(...)` listeners in `index.mjs`.

server/bridges/signalr/manifest.yaml renamed to extensions/python/signalr_bridge/extension.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: quanux-bridge-signalr
22
version: v0.0.1
33
owner: platform
44
description: "Real-time SignalR bridge for QuanuX (scaffold). Choose Flask or Node runtime."
5+
command: "python src/supervisor.py"
56

67
default_runtime: flask
78
alternatives:
@@ -12,6 +13,8 @@ config:
1213
QUANUX_BRIDGE_PORT: 8077
1314
QUANUX_LOG_LEVEL: INFO
1415
QUANUX_BRIDGE_CORS: "*"
16+
QUANUX_SIGNALR_USER_HUB: "https://rtc.topstepx.com/hubs/user"
17+
QUANUX_SIGNALR_MARKET_HUB: "https://rtc.topstepx.com/hubs/market"
1518

1619
endpoints:
1720
flask:
@@ -20,15 +23,17 @@ endpoints:
2023

2124
runtimes:
2225
flask:
23-
entry: "python3 server/bridges/signalr/flask/app.py"
26+
entry: "python src/flask/app.py"
2427
node:
25-
entry: "node server/bridges/signalr/node/index.mjs"
28+
entry: "node src/node/index.mjs"
2629

2730
process_model:
2831
node_worker:
29-
entry: "server/bridges/signalr/node/index.mjs"
32+
entry: "src/node/index.mjs"
3033
env:
3134
SIGNALR_HUB_URL: "${SIGNALR_HUB_URL}"
35+
SIGNALR_USER_HUB: "${QUANUX_SIGNALR_USER_HUB}"
36+
SIGNALR_MARKET_HUB: "${QUANUX_SIGNALR_MARKET_HUB}"
3237
SIGNALR_ACCESS_TOKEN: "${SIGNALR_ACCESS_TOKEN}"
3338
SIGNALR_PROTOCOL: "json"
3439

@@ -42,6 +47,10 @@ security:
4247
secrets:
4348
- key: "SIGNALR_ACCESS_TOKEN"
4449
provider: "quanux.secrets"
50+
- key: "QUANUX_SIGNALR_USER_HUB"
51+
provider: "quanux.secrets"
52+
- key: "QUANUX_SIGNALR_MARKET_HUB"
53+
provider: "quanux.secrets"
4554

4655
health:
4756
checks:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)