Place an Order
The exchange assigns each order itsOrderID. The program sends every create under a ClientRequestID of its own and records the order in live by its OrderID. A create whose answer never arrives is looked up by that ClientRequestID and recorded once found, so it can still be cancelled:
Order.Status. A command on a contract outside the connection’s scope is refused before it is sent, with options.ErrOutOfScope.
Modify an Order
A modify changes the order’s price and quantity in place, and keeps its id:Cancel an Order
CancelOrder is answered without an acknowledgment, so its AckAt is zero. An order already gone is refused with options.CodeOrderNotFound. ViaHTTP is explained below.
Cancel Every Order
conn.CancelAllOrders sweeps one contract, or the connection’s whole scope when Contract is empty, and returns once the exchange has taken the sweep on; each cancel is then answered as its own options.OrderCancelled or options.OrderRejected event, and Count says how many to expect. The program matches them to its orders by id; the example also handles one filled before the sweep reached it:
client.CancelAllOrders sweeps one contract, or the whole account when Contract is empty, over HTTP.
When the Socket Is Down
Cancels and reduce-only creates matter most when the connection is lost, so while the socket is down the SDK can send them over HTTP instead; other creates, and modifies, fail with the connection’s error. A command sent over HTTP hasViaHTTP set and is only queued: its outcome arrives as an event, as for a command another connection sent. The README has the exact conditions.
When a Command Gets No Answer
Afterrails.ErrTimeout, rails.ErrConnClosed, or a 502 or 504 over HTTP, a command may still have been applied, and its error carries the ClientRequestID. Either look the order up with client.OrderStatusByClientRequestID, or send the command again with that ClientRequestID set: within 60 seconds the exchange refuses a repeat with a 409 instead of executing it twice. Only the lookup says what happened to the order.
The program looks a create up, and records the order in live once found. A create the exchange has not reached yet is not found, so a miss is retried for a while; outcomeUnknown reports the errors above and describe says what any other failure means:
Clean Up After a Failure
Closing a connection doesn’t cancel its orders. The program cancels any it may still have on the book when it stops. Each cancel gets a context of its own, since the program’s may be what ran out:Run the Example
The complete program isexamples/options-orders in the SDK repository. Run it with a price well below the contract’s book: