Skip to main content

MonitorLimitOrder

Monitors a limit order for real-time updates.

Supports lookup by either resource name or external reference using the identifier oneof field in the request. Returns a stream of limit order states as they change.

Server-Side Streaming Method

This method uses server-side streaming, meaning it returns multiple responses over time rather than a single response. The server sends a stream of responses to the client, and the client processes each response as it arrives.

Stream Lifecycle:

  • Initiation: Call the method to create a stream
  • Data Reception: Receive multiple responses over the stream
  • Completion: Stream ends normally (EOF/end event) or with an error
  • Resource Management: Streams should be fully consumed or explicitly closed

See the code examples below for language-specific streaming consumption patterns.

Method Options​

Authorisation specification of the MonitorLimitOrder method.

TypeMETHOD_TYPE_READ
Access LevelMETHOD_ACCESS_LEVEL_AUTHORISED
Roles
  • ROLE_TRADING_ADMIN
  • ROLE_TRADING_VIEWER
  • ROLE_TRADING_LIMIT_ORDER_ADMIN
  • ROLE_TRADING_LIMIT_ORDER_VIEWER

Parameters​

Request and response parameter message overview:

Input: MonitorLimitOrderRequest Message​

FieldTypeRequiredDescription
Name

string

False

The resource name of the limit order to monitor. Format: limit_orders/{ULIDv2}.

ExternalReference

string

False

The external reference identifier.

LiveLedgerData

bool

False

When true, fetches live ledger data for order. When false, returns only stored metadata. Note: The streaming does not stream based on ledger events such as fill amount changes, only limit order state changes triggers a stream update. If this is set to true then live ledger data will populated with the updated limit order state.

Returns: LimitOrder Message​

Code Examples​

Select supported SDK in the language of your choice for a full example of how to invoke the this method:

package main

import (
"context"
"io"
"log"

limit_orderv1 "github.com/meshtrade/api/go/trading/limit_order/v1"
)

func main() {
ctx := context.Background()

// Default configuration is used and credentials come from MESH_API_CREDENTIALS
// environment variable or default discovery methods. Zero config required
// unless you want custom configuration.
service, err := limit_orderv1.NewLimitOrderService()
if err != nil {
log.Fatalf("Failed to create service: %v", err)
}
defer service.Close()

// Monitor a limit order in real-time via server-side streaming
// You can use either the resource name or external reference

// Option 1: Monitor by resource name
request := &limit_orderv1.MonitorLimitOrderRequest{
Identifier: &limit_orderv1.MonitorLimitOrderRequest_Name{
Name: "limit_orders/01HQVBZ9F8X2T3K4M5N6P7Q8R9",
},
}

// Option 2: Monitor by external reference (commented out)
// request := &limit_orderv1.MonitorLimitOrderRequest{
// Identifier: &limit_orderv1.MonitorLimitOrderRequest_ExternalReference{
// ExternalReference: "my-trading-system-order-123",
// },
// }

// Call the MonitorLimitOrder streaming method
// This opens a long-lived server-side stream that pushes order updates
stream, err := service.MonitorLimitOrder(ctx, request)
if err != nil {
log.Fatalf("Failed to initiate stream: %v", err)
}

log.Println("āœ“ Monitoring limit order for real-time updates...")
log.Println(" Listening for status changes... (Ctrl+C to stop)")

// Consume stream responses
// The server pushes updates whenever order status changes on the ledger
monitorOrder:
for {
limitOrder, err := stream.Recv()
if err == io.EOF {
break // Stream completed normally
}
if err != nil {
log.Fatalf("Stream error: %v", err)
}

// Process each order update as it arrives
log.Printf("\nšŸ“” State update received: %s", limitOrder.State)
log.Printf(" Resource name: %s", limitOrder.Name)
log.Printf(" Account: %s", limitOrder.Account)
log.Printf(" External ref: %s", limitOrder.ExternalReference)
log.Printf(" Side: %s", limitOrder.Side)
log.Printf(" Limit price: %s %s", limitOrder.LimitPrice.Value.Value, limitOrder.LimitPrice.Token.Code)
log.Printf(" Quantity: %s %s", limitOrder.Quantity.Value.Value, limitOrder.Quantity.Token.Code)

// Handle order state transitions
switch limitOrder.State {
case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_SUBMISSION_IN_PROGRESS:
log.Printf(" ā³ Order submission in progress...")

case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_SUBMISSION_FAILED:
log.Printf(" āŒ Order submission failed")
break monitorOrder

case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_OPEN:
log.Printf(" āœ“ Order open on ledger and available for matching")
// Order is active - continue monitoring for fills

case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_COMPLETE_IN_PROGRESS:
log.Printf(" ā³ Order completion in progress...")

case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_COMPLETE:
log.Printf(" šŸŽ‰ Order completed (fully filled)!")
break monitorOrder

case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_CANCELLATION_IN_PROGRESS:
log.Printf(" ā³ Order cancellation in progress...")

case limit_orderv1.LimitOrderState_LIMIT_ORDER_STATE_CANCELLED:
log.Printf(" āŒ Order cancelled")
break monitorOrder

default:
log.Printf(" āš ļø Unexpected order state: %v", limitOrder.State)
}
}

log.Println("\nāœ“ Stream completed successfully")
}

Advanced Configuration​

For advanced client configuration options (custom endpoints, TLS settings, timeouts), see the SDK Configuration Guide.

Other Methods​