Skip to content

OpenedOrdersTickets

Just the ticket numbers of all open orders โ€” the lightweight "what's open?" read.

API Information:

  • Low-level API: MT4Account.OpenedOrdersTickets(ctx) (defined in mt4/MT4Account.go)
  • gRPC service: mt4_term_api.AccountHelper
  • Payload: OpenedOrdersTicketsData

๐Ÿ’ฌ Just the essentials

  • What it is. The list of open-order ticket IDs โ€” no prices, no volumes.
  • Why you need it. Cheap polling to detect new fills / closes without the full payload.
  • When to use. Reconciliation loops where full detail would be overkill.

๐ŸŽฏ Purpose

  • Fetch all open-order tickets in one small call
  • Diff between calls to spot additions / removals
  • Drive follow-up detail reads via OrderSelect

Method Signature

func (a *MT4Account) OpenedOrdersTickets(ctx context.Context) (*pb.OpenedOrdersTicketsData, error)

Request message:

message OpenedOrdersTicketsRequest {}   // no arguments

Payload message:

message OpenedOrdersTicketsData { repeated int32 tickets = 1; }

๐Ÿ”ฝ Input

Parameter Type Required Description
ctx context.Context yes Cancellation / timeout. The call takes no other arguments.

โฌ†๏ธ Output โ€” *pb.OpenedOrdersTicketsData

Field Proto Type Go getter Description
tickets repeated int32 GetTickets() []int32 All open-order ticket IDs

On failure the call returns a non-nil error (text "API error (code=โ€ฆ): โ€ฆ") โ€” see the Return Codes Reference.


๐Ÿงฉ Notes & Tips

  • IDs only. For symbol/price/SL use OpenedOrders or look one up with OrderSelect.
  • No position/pending split here โ€” this unary call returns a flat ticket list. The streaming OnOpenedOrdersTickets splits them.
  • Diff two reads to detect what opened or closed between polls.

๐Ÿ”— Usage Examples

1) Print the open tickets

func printTickets(ctx context.Context, acc *mt4.MT4Account) error {
    d, err := acc.OpenedOrdersTickets(ctx)
    if err != nil { return err }
    fmt.Printf("%d open: %v\n", len(d.GetTickets()), d.GetTickets())
    return nil
}

2) Detect closes between two polls

func closedSince(ctx context.Context, acc *mt4.MT4Account, before []int32) ([]int32, error) {
    d, err := acc.OpenedOrdersTickets(ctx)
    if err != nil { return nil, err }
    now := map[int32]bool{}
    for _, t := range d.GetTickets() { now[t] = true }
    var gone []int32
    for _, t := range before {
        if !now[t] { gone = append(gone, t) }
    }
    return gone, nil
}

3) Fetch details for each ticket

func detailAll(ctx context.Context, acc *mt4.MT4Account) error {
    d, err := acc.OpenedOrdersTickets(ctx)
    if err != nil { return err }
    for _, t := range d.GetTickets() {
        if o, err := acc.OrderSelect(ctx, t); err == nil {
            fmt.Printf("#%d %s %.2f\n", o.GetTicket(), o.GetSymbol(), o.GetLots())
        }
    }
    return nil
}

โš ๏ธ Pitfalls

  • Snapshot. Tickets can change the instant after the read โ€” treat as point-in-time.
  • Empty is normal. A flat account returns an empty slice โ€” guard len(...).

๐Ÿงช Testing Suggestions

  • Happy path (demo). Open an order; its ticket appears here.
  • Diff. Close it and assert closedSince reports its ticket.
  • Consistency. len(GetTickets()) equals len(OpenedOrders().GetOrderInfos()).

๐Ÿ“š See also