Jump to content
  • 0

How does the relation between DealId and DealReference work in the different API endpoints


SZZ

Question

I'm trying to follow the documentation here: https://labs.ig.com/rest-trading-api-reference

My goal: I want to open an order via API, get frequent updates via lightstream and a final update when the order is closed, including P&L information.

I open the order by putting a request to /gateway/deal/positions/otc v2. This works and returns a deal id and a deal reference

Then I confirm the order by deal id using /gateway/deal/confirms/ v1. This also works.

I also get updates via the lightstream API on the trade type OPU with the status OPEN and DELETED when the order is closed. Again, the DealId and the Reference match. But the DELETED update does not contain a P&L information.

 

So on DELETE I access the activity transaction history by deal ID: /gateway/deal/history/activity v3. This also works, but also does not contain P&L, but therefore a description with a new Id, reading "Position opened: [some id]". This id consits of the last part of the DealId.

Afterwards, I access the transaction history on /gateway/deal/history/transactions v2. Here I finally have a P&L, but the reference field contains a new reference that never showed up before. There is just no way to link the transaction to the activity or to an order.

 

So the question: Is there any way to get P&L information on a closed position based on deal Id or deal reference? I really don't want to match opening date and epic name, that's just bad practice.

 

 

 

 

 

  • Like 1
Link to comment

8 answers to this question

Recommended Posts

  • 0
INFO:trading_ig.rest:GET '/history/activity/', resp 200
                   date                  marketName                      epic  period    level direction           dealId
0   2023-11-10T05:45:05           Oil - Brent Crude        EN.D.LCO.Month6.IP  JAN-24   8034.5      SELL  DIAAAANP68C8YAQ
1   2023-11-09T05:45:11  10-Year T-Note Decimalised  IR.D.10YEAR100.Month2.IP  DEC-23    10845       BUY  DIAAAANPPY34SAG


INFO:trading_ig.rest:GET '/history/transactions', resp 200
            openDateUtc              dateUtc              instrumentName  period openLevel closeLevel   size        reference profitAndLoss
0   2023-10-27T18:59:23  2023-11-10T05:45:05           Oil - Brent Crude  JAN-24      8923     8034.5  +0.53  DIAAAANP68C8YAQ      £-470.91
1   2023-09-26T17:17:04  2023-11-09T05:45:11  10-Year T-Note Decimalised  DEC-23   10814.4      10845  -0.62  DIAAAANPPY34SAG       £-18.97

The dealId field from the activities endpoint (/history/activity) matches the reference field from the transactions endpoint (/history/transactions)

  • Like 1
Link to comment
  • 0

Thanks for confirming @bug-or-feature - the confusion is caused by what I presume is a Demo env bug, where the transaction reference generated for a closed trade is only half the length of the typical deadId character length 🤦‍♂️.

Here's an example: 

"date": "06/11/23",
"instrumentName": "FTSE 100 Cash (£10)",
"period": "-",
"profitAndLoss": "£25.00",
"transactionType": "DEAL",
"reference": "NR3HSJAP",
"openLevel": "7420",
"closeLevel": "7415",
"size": "-0.50",
"currency": "£",
"cashTransaction": false

The prefix of DIAAAAN was missing in this scenario and I couldn't in good faith presume it'd always be the same thus the confusion. Perhaps someone in the IG team could address how widespread this bug is.

 

Link to comment
  • 0

Hmm not sure what is going on. My previous examples were market orders. I just tried a working order, and the transaction response contained the full 15 character reference field, eg DIAAAANXXXXXXXX

Maybe someone from IG can explain. Why does the reference field in the /history/transactions response sometimes contain the full dealId, and sometimes just the portion after DIAAAAN?

 

Link to comment
  • 0

I've done a bit more digging - I think there is a bug. And now I understand the issue as described by @SZZ It looks to me like the /confirms endpoint returns the wrong dealId when closing a position. The Streaming API also reports the wrong dealId from the TRADE Subscription. They both respond with the dealId of the opening trade instead of the closing trade.

The correct closing trade dealId is reported by the /history/activity endpoint, and by the /history/transactions endpoint. So there is a workaround for your issue right now @SZZ . Once your trade is closed, look at the response of the /history/activity endpoint. Find the dealId where the affectedDealId is the ID of the opening trade, and description is "Positions/s closed: XXXXXXXX". Then lookup that dealId in the response of the /history/transactions endpoint, with field name reference.

I have reported this to the webapi team, will post any updates here

  • Like 1
Link to comment
  • 0

UPDATE:

I told the Web API team about this issue via their email address webapisupport@ig.com. Their reponse was: we know about this, it's not a bug. The excuse was

Quote

I understand that this is not 'consistent' with the history section but i looked through both reference documents and we also did not specify which dealID it is supposed to return

and then

Quote

This was how it is when we developed the API and we can submit this as a feedback to them to consider for future improvements.

My interpretation is: it has been like that since the API was released. They know its wrong, but to change it now would admit the mistake.

So for now, the laborious workaround mentioned above is the only solution.

Maybe if enough people make a noise about it, they will fix it. But I doubt it

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • Wheat Elliott Wave Analysis Function - Trend Mode - Trend Structure -Impulse wave Position - Wave A of (B) Direction - Wave A of (B) is still in play Details -  Wheat daily and H4 have been adjusted due to how fast and deep decline from 720’4 has emerged. The long-term forecast on the daily chart shows that the surge to 720’4 is part of the impulse wave from March 2022. We are now in wave (5) which is expected to emerge into a 3-wave structure. Price now appears to be in wave A after which it will correct upside for B before returning downside. Overview: Since late May, grain prices have been falling sharply, with Wheat shedding over 20% since May 28th, 2024. This decline is about to erase the gains made from mid-April to late May. The nearly one-month sell-off adds to the long-term decline from March 2022, when Wheat traded at 1364’4. Currently trading at 571’4, Wheat is likely to fall further toward 500 in the coming weeks.   Daily Chart Analysis: The decline from March 2022 is forming a bearish impulse wave structure in the primary degree. The 5th wave is completing a diagonal structure, which has been the most time-consuming among the actionary waves, lasting nearly 21 months. The price is currently in wave (5) of 5 (circled), which will likely evolve into a 3-wave structure targeting the 500 major psychological level.   H4 Chart Analysis: The H4 chart shows the sub-waves of wave (5), which is now close to completing its first leg - wave A of (5). A corrective bounce is expected to follow for wave B before the price turns downside for wave C of (5) toward 500, provided the 720’4 pivot is not breached. Wheat and other grains are overwhelmingly bearish and may continue in this direction for the next several weeks before major bullish corrections begin.   In conclusion, Wheat prices remain bearish with potential for further declines, targeting the 500 psychological level, contingent on the completion of the current corrective wave B and the subsequent wave C of (5). Technical Analyst : Sanmi Adeagbo Source : Tradinglounge.com get trial here!  
    • Dear @Naren12166, Thank you for the post. Please note that we don't have a definite date but the product team is in the testing phase, a few countries should have Trading View soon. Thanks, KoketsoIG
    • TXN Elliott Wave Analysis Trading Lounge Daily Chart, Texas Instruments Inc., (TXN) Daily Chart TXN Elliott Wave Technical Analysis FUNCTION: Counter Trend MODE: Corrective STRUCTURE: Triangle POSITION: Wave {iv}. DIRECTION: Bottom in wave {iv}.   DETAILS: Looking for a triangle in wave {iv} of 3 as we have found resistance on TL2 at 200$.     TXN Elliott Wave Analysis Trading Lounge 4Hr Chart, Texas Instruments Inc., ( TXN) 4Hr Chart TXN Elliott Wave Technical Analysis FUNCTION: Counter Trend MODE: Corrective STRUCTURE: Triangle POSITION: Wave (e) of {iv}. DIRECTION: Bottom in (e).   DETAILS: Looking for wave (e) to be near completion to then resume higher and find support on top of 200$.   Welcome to our latest Elliott Wave analysis for Texas Instruments Inc. (TXN). This analysis provides an in-depth look at TXN's price movements using the Elliott Wave Theory, helping traders identify potential opportunities based on current trends and market structure. We will cover insights from both the daily and 4-hour charts to offer a comprehensive perspective on TXN's market behavior.   * TXN Elliott Wave Technical Analysis – Daily Chart* In our Elliott Wave analysis of Texas Instruments Inc. (TXN), we observe a counter-trend corrective pattern characterized by a triangle structure. TXN is currently positioned in wave {iv} of 3, suggesting a bottoming process in wave {iv}. The recent price action indicates that TXN has encountered resistance around the TL2 trendline at $200. This resistance could imply the formation of a triangle in wave {iv}, setting the stage for a potential resumption of the upward trend once the triangle completes. Traders should monitor the $200 level for signs of a breakout or further consolidation within the triangle.   *TXN Elliott Wave Technical Analysis – 4Hr Chart* On the 4-hour chart, TXN is following a counter-trend corrective mode within a triangle structure, specifically in wave (e) of {iv}. The current analysis suggests that wave (e) is nearing completion, which could signal the end of the triangle and the beginning of a move higher. The completion of wave (e) should ideally find support above the $200 level, aligning with the daily chart's indication of a possible upward resumption post-triangle. Traders should watch for the termination of wave (e) and the subsequent price action to confirm a bullish continuation.   Technical Analyst : Alessio Barretta Source : Tradinglounge.com get trial here!  
×
×
  • Create New...
us