Skip to content

How to reliably map a closed dealId to its closeLevel (Transaction History vs Activity) #362

Description

@TAsUjxnMIL

Hi, I have a question about retrieving the closeLevel for a closed position.

Context

  • Positions are opened via POST /positions/otc
  • I store the returned dealId
  • Later I detect that the position is closed (the dealId no longer appears in open positions)
  • At that point I want to determine the closeLevel and whether the position closed via TP or SL

What I’ve observed

  • There is no endpoint that allows a direct lookup
    dealId -> closeLevel
  • closeLevel is available in Transaction History (/history/transactions)
  • However, the transaction reference does not match:
    • the position dealId
    • nor the dealReference used when opening the position
  • Account Activity (/history/activity) is not fully reliable for mapping closes:
    • close-related entries are not always present
    • dealReference does not clearly map to transaction reference

Current workaround

I match the correct transaction heuristically using:

  • price proximity (openLevel vs entry price)
  • time proximity (dateUtc vs local close detection time)
  • closeness of closeLevel to known TP / SL levels

This works in practice, but feels like a workaround rather than an intended solution.

Question

Is there an official or deterministic way in the IG API to map a closed dealId to its closeLevel?
Or is heuristic matching (price + time proximity) the expected approach?

Thanks in advance, and thanks for maintaining the library.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions