Place an Order
ClientRequestID. Commands from any number of goroutines can share one connection.
Modify an Order
A modify replaces the order under a new id, and the result describes the replacement:Cancel an Order
CancelOrder resends in the one case where the exchange itself asks for the cancel again.
Cancel Every Order
To cancel every order on a market, or on all of them withperps.MarketAll, call client.CancelAllOrders. It goes over HTTP, so it works even when the WebSocket can’t be dialled during a soft ban.
When a Command Gets No Answer
Afterrails.ErrTimeout or rails.ErrConnClosed the command may still have been applied, and its error carries the clientRequestId. Either look the order up with it, as the example does, or send the command again with that ClientRequestID set: within 60 seconds the exchange refuses a repeat with DUPLICATE_REQUEST instead of executing it twice. Only the lookup says what happened to the order.
Clean Up After a Failure
Closing a connection doesn’t cancel its orders. The program keeps the id of the order it has on the book, set to the replacement’s id after the modify and cleared after the cancel, and cancels it if it stops before cancelling it itself. The cleanup gets a context of its own, since the program’s may be what ran out:Run the Example
The complete program isexamples/perps-orders in the SDK repository. Run it with a price well below the market: