Futures Examples
End-to-end Python scripts for perpetual futures: REST trading plus the market data and account streams.
Use these scripts to automate common futures workflows.
Start Here
Use Setup & Helpers first.
That page covers:
Python version and package install
The signed REST client for the futures API
The private WebSocket
AUTHhelperPair lookup, rounding to tick and lot size, and market data helpers
Trading Workflows
Open a Position with TP/SL — market order sized by spend, with take-profit and stop-loss attached
Limit Entry with Timeout — rest a post-only limit below the bid, wait for the fill on the account stream, cancel if it does not fill
Protect Open Positions — put a stop-loss and take-profit on every open position that has none
Monitoring and Risk
Live PnL Monitor — unrealized PnL of every position, updated from the account stream and best bid/ask
Margin Call Guard — reduce cross positions automatically when a margin call arrives
Related Pages
Futures API
Futures Market Data
Futures Account streams
Was this helpful?

