I'm James Wilson, a Python developer and crypto trader. I'm still relatively new to software development, but I have considerably more experience in trading. Lately, I've been exploring trading automation and have already made significant progress in streamlining my workflow.
I've been using two tools from QATS: QATS for Chrome for manual trading and QATS Trader API for automation. Here's how they fit together and what you can build with Python.
1. Trading directly from TradingView
QATS for Chrome connects a QATS trading account to TradingView, allowing you to:
- Trade directly from the chart.
- View open positions.
- Manage stop-loss and take-profit orders. The main benefit for me is spending less time switching between charts and trading terminals. TradingView remains my analysis workspace, while QATS handles execution.
One caveat: prices on TradingView and QATS may differ, so always check the execution platform's quotes before placing an order.
2. Connecting to QATS Trader API with Python
QATS provides a REST API for account data, market data, positions, and order management. It also offers a free sandbox with a virtual $100,000 balance and separate API keys.
API documentation includes an OpenAPI specification and a Postman collection.
Install requests:
pip install requests
Create a sandbox API key and set the QATS_TOKEN environment variable. A small reusable client is enough to get started:
import os
import requests
BASE_URL = "https://prop.qats.us/api/sandbox/v1"
session = requests.Session()
session.headers.update({
"Authorization": f"Bearer {os.environ['QATS_TOKEN']}",
"Accept": "application/json",
})
def get(path, params=None):
response = session.get(
f"{BASE_URL}{path}",
params=params,
timeout=10,
)
response.raise_for_status()
return response.json()
Use a read-only key for monitoring scripts. Grant order-writing permissions only when needed.
3. Monitoring account risk and open positions
One of the most useful applications of the API is automating account monitoring:
data = get("/trading/account")
figures = data["rules"]["figures"]
print("Account:", data["account"]["id"])
print("Max loss:", figures.get("maxLoss"))
print("Daily loss limit:", figures.get("dailyLossLimit"))
print("Drawdown type:", figures.get("drawdownType"))
positions = get("/trading/positions")["positions"]
print("Open positions:", len(positions))
For prop traders, retrieving account rules dynamically is particularly useful. Different accounts may have different drawdown and daily loss limits. Hardcoding these values makes switching accounts unnecessarily risky.
The configured maximum loss is not the remaining loss allowance; use current server-side risk data for that.
Before placing orders, the following endpoints also help validate prices and instrument constraints:
GET /trading/instruments?symbol=BTCUSDT
GET /trading/market?symbol=BTCUSDT
QATS supports quantity (base asset units) or lots (QATS lot units). They are mutually exclusive, so make sure your sizing logic uses the correct unit.
4. Idempotency: avoiding duplicate orders
Imagine sending a market order and getting a network timeout. The server may have executed the order even though your script received no response.
Retrying with a new command ID could create an unintended second order.
QATS requires an Idempotency-Key header for write operations:
from uuid import uuid4
command_id = uuid4().hex
headers = {"Idempotency-Key": command_id}
payload = {
"symbol": "BTCUSDT",
"side": "BUY",
"type": "MARKET",
"quantity": 0.001,
}
This is an illustrative sandbox payload, not an order submission. Validate the instrument, quantity, price and account restrictions before sending it to POST /trading/orders.
If the outcome is unknown after submission, check the command status using the original ID:
result = get(f"/trading/commands/{command_id}")
print(result)
The API documents three possible states: confirmed, not_executed, and unconfirmed.
An unconfirmed command is not proof that an order failed. Persist the original ID and payload before submission, and reuse them when recovering the operation instead of blindly generating another UUID.
5. Real-time updates with Server-Sent Events
Instead of continuously polling the API, QATS supports Server-Sent Events (SSE) for order, position and execution updates.
with session.get(
f"{BASE_URL}/trading/events/stream",
headers={"Accept": "text/event-stream"},
stream=True,
timeout=(10, 60),
) as response:
response.raise_for_status()
response.encoding = "utf-8"
for line in response.iter_lines(decode_unicode=True):
if line:
print(line)
This example prints the raw stream. A production client needs event parsing, reconnection and deduplication. QATS assigns event IDs in the accountId:sequence format and supports recovery using the Last-Event-ID header.
This makes it possible to build a trade journal, position monitor or Telegram notification service without constantly requesting the entire account history.
6. Combining manual trading and automation
Rather than building a fully autonomous trading bot, I prefer a hybrid approach:
I can keep market analysis and trading decisions manual while delegating repetitive operations to Python scripts.
Before automating order execution, I'd test network failures, partial fills, rate limits, stale market data and conflicts between manual and automated actions. The server must remain the source of truth, and automation must respect the account's risk limits.
Final thoughts
QATS for Chrome and Trader API helped me simplify my trading workflow without building an entire trading platform from scratch. From a developer's perspective, idempotent commands and SSE are the most interesting features because they address real reliability challenges in trading integrations.
Automation doesn't make a strategy profitable, but it can reduce repetitive work and make account monitoring more consistent.
Next, I'd like to build a Python-based position monitoring service with Telegram notifications.

Top comments (0)