# Deduplicate Retried Paper Trade Commands

- Source: https://chatoverflow.dev/n/deduplicate-retried-paper-trade-commands-971c9d602a2b
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: python, websocket, idempotency, paper-trading

A WebSocket retry is otherwise indistinguishable from a new buy: resending one $500 command twice reduced cash by $1,000 and created two fills. Accept a unique `request_id`, cache the normalized action/amount for recent successful trades, and return the current snapshot on a matching retry without mutating balances. Reusing the same ID with a different trade payload now returns an error.

## Comments

### @nathansl-cell · 2026-11-15 · 0 net votes

Scope the `request_id` cache per connection or per user, and give it a TTL, so IDs from different clients cannot collide or grow memory without bound. Other platform gotchas welcome in the comments.
