OrdersService
Describes github.com/stxapp/stx-go v0.3.1, the current release.
OrdersService
Section titled “OrdersService”type OrdersService struct { // contains filtered or unexported fields}OrdersService places, lists and cancels orders. Use it through Client.Orders.
func (s *OrdersService) All(ctx context.Context, q *OrdersQuery) iter.Seq2[Order, error]All returns every order matching q, following the cursor.
Cancel
Section titled “Cancel”func (s *OrdersService) Cancel(ctx context.Context, orderID string) (*Cancellation, error)Cancel requests a cancel (DELETE /api/v1/orders/{order_id}). A fill already in flight can still land.
CancelAll
Section titled “CancelAll”func (s *OrdersService) CancelAll(ctx context.Context) ([]Cancellation, error)CancelAll cancels every order resting on the account (DELETE /api/v1/orders/all).
CancelBatch
Section titled “CancelBatch”func (s *OrdersService) CancelBatch(ctx context.Context, orderIDs []string) ([]Cancellation, error)CancelBatch cancels the named orders (DELETE /api/v1/orders/batched).
func (s *OrdersService) Get(ctx context.Context, orderID string) (*Order, error)Get returns one of your orders (GET /api/v1/orders/{order_id}).
func (s *OrdersService) List(ctx context.Context, q *OrdersQuery) (*Page[Order], error)List returns one page of your orders, newest first (GET /api/v1/orders).
func (s *OrdersService) Place(ctx context.Context, order OrderRequest) (*Order, error)Place places one order (POST /api/v1/orders). The exchange validates it: a bad price step or a fractional quantity returns an error matching ErrBadRequest or ErrRejected with the API’s message.
A POST is never retried after a 5xx or a dropped connection; set ClientOrderID and look the order up with OrdersService.List if that happens.
With FillMode PostOnly or FillOrKill, Place sends the order and the exchange decides: where the mode is not enabled it rejects the order and Place returns an error matching ErrNotAvailable. A market that does not take the mode, such as a combination market, returns an error matching ErrFillModeNotAllowed; a post-only order that would have matched returns a *PostOnlyWouldMatchError.
Example
Place a limit order, then cancel it.
ctx := context.Background()client, err := stx.New()if err != nil { log.Fatal(err)}order, err := client.Orders.Place(ctx, stx.OrderRequest{ MarketID: "42b861f8-8340-4046-ae06-83a0cec93456", Action: stx.Buy, OrderType: stx.Limit, Price: stx.MustDecimal("0.01"), Quantity: stx.MustDecimal("1"), ClientOrderID: "my-order-001",})if errors.Is(err, stx.ErrRejected) { log.Fatalf("refused by the exchange: %v", err)} else if err != nil { log.Fatal(err)}fmt.Println("Placed", order.ID, order.Status)cancel, err := client.Orders.Cancel(ctx, order.ID)if err != nil { log.Fatal(err)}fmt.Println("Cancelled:", cancel.Status)PlaceBatch
Section titled “PlaceBatch”func (s *OrdersService) PlaceBatch(ctx context.Context, orders []OrderRequest) ([]BatchOrderResult, error)PlaceBatch places several orders in one call (POST /api/v1/orders/batched). It returns one result per order, in order; a rejected order carries Errors and does not stop the others.
When the exchange rejects the batch because a FillMode (PostOnly or FillOrKill) is not enabled there, PlaceBatch returns an error matching ErrNotAvailable. In a batch a post-only order that would have matched comes back as its result: a cancelled Order (CancellationReason “auto_matching”) or Errors.

