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

    • It can be a bit overwhelming with so many options out there. When I was looking for renter's insurance, I stumbled upon Lemonade and was pleasantly surprised. They offer customizable coverage options, which is awesome for someone like you with diverse investments. Their process is super easy, all done online in minutes.  But hey, don't just take my word for it, do your research. This link I found might help - https://joywallet.com/article/best-renters-insurance/. And remember, it's not just about the coverage, but also the customer service.
    • Key stock indices ended the day in the red on Tuesday and in after-hours trading Amazon, AMD and McDonald's had mixed results while US yields and the US dollar rose ahead of today's Federal Open Market Committee (FOMC) meeting. The main focus is on Jerome Powell's press conference and what signals he gives about future interest rate policy. The expectation is he will strike a cautious but hawkish tone on inflation, given recent economic data has challenged the Fed's soft landing scenario. On the data front are UK and US manufacturing PMIs, the US ADP's non-farm estimate, job openings, mortgage applications, EIA's inventory estimates and, of course, the FOMC monetary policy meeting at which no rate cut is expected to be announced.
    • AUDJPY Elliott Wave Analysis Trading Lounge Day Chart,     Australian Dollar / Japanese Yen (AUDJPY) Day Chart     AUDJPY Elliott Wave Technical Analysis   FUNCTION: Counter Trend MODE: impulsive as C                                   STRUCTURE: blue wave 1 POSITION:  blue wave 1 DIRECTION NEXT HIGHER DEGREES: blue wave 2                         DETAILS black wave 2 completed at 104.996,now blue wave 1 of black wave C is in play . Wave Cancel invalid level:104.990   The AUD/JPY Elliott Wave Analysis for the Day Chart provides insights into the price action of the Australian Dollar against the Japanese Yen. It explores the wave structure, current positioning, and potential market movements, essential for Elliott Wave analysts and technical traders.   ### Function The analysis defines the function as "Counter Trend," indicating that the current wave pattern opposes the broader market trend. This function typically consists of corrective waves or trend reversals, leading to more complex price action.   ### Mode The mode is characterized as "impulsive as C," suggesting that the wave structure represents an impulsive wave within a corrective phase. This mode is generally composed of five waves, indicating a significant market move.   ### Structure The structure is identified as "blue wave 1," signaling that the current phase is the beginning of a broader impulsive wave within a corrective context. This could be an initial push upward before a subsequent correction and further trend continuation.   ### Position The position is described as "blue wave 1," indicating that the market is in the first wave of a new impulse sequence, suggesting that a larger trend might be forming or reversing.   ### Direction for the Next Higher Degrees The expected direction for the next higher degrees is "blue wave 2," indicating that after the current impulsive wave completes, a corrective phase is likely to follow before the trend continues. This is a key point for traders looking for entry opportunities within a corrective structure.   ### Details The details section provides a deeper look at the wave structure. According to the analysis, "black wave 2" completed at 104.996, with "blue wave 1" of black wave C currently in play. The "Wave Cancel invalid level" is set at 104.990, indicating that if the price crosses this threshold, the current wave structure could be invalidated, suggesting a potential shift in market dynamics.   In summary, the AUD/JPY Elliott Wave Analysis for the Day Chart indicates that the market is in an impulsive phase within a counter-trend context. Black wave 2 completed at 104.996, and blue wave 1 of black wave C is in play, with a potential transition to a corrective phase (blue wave 2) expected. The Wave Cancel invalid level is set at 104.990, providing a critical level for monitoring the validity of the current wave structure. This analysis can be useful for traders and analysts seeking to understand the current market context and predict potential price movements.     AUDJPY Elliott Wave Analysis Trading Lounge 4 Hour Chart,     Australian Dollar / Japanese Yen (AUDJPY) 4 Hour Chart     AUDJPY Elliott Wave Technical Analysis   FUNCTION: Trend                                   MODE: corrective                                   STRUCTURE: red wave 2                                   POSITION:  blue wave 1                                 DIRECTION NEXTLOWER DEGREES: red wave 3                         DETAILS red wave 1 of blue wave 1 completed at 101.393 , now red wave 2 is in play . Wave Cancel invalid level:104.966                                                                     The AUD/JPY Elliott Wave Analysis for the 4-Hour Chart provides a technical outlook on the movement of the Australian Dollar against the Japanese Yen. It highlights the wave structure, current positioning, and anticipated market direction, which is crucial for traders and analysts.   ### Function The analysis defines the function as "Trend," suggesting that the current market movement follows the prevailing trend rather than opposing it. This function is often characterized by more predictable price action, with clear impulse and corrective waves.   ### Mode The mode is described as "corrective," indicating that the current wave pattern represents a correction within the broader trend. Corrective waves often occur in zigzags, flats, or other complex patterns, serving as a retracement before the trend resumes.   ### Structure The structure is identified as "red wave 2," signaling that the current wave is part of a larger corrective phase within the impulse sequence. This correction phase can offer buying opportunities for trend-following traders.   ### Position The position is "blue wave 1," indicating that the current corrective phase is part of a larger impulse sequence within the broader trend. This position suggests that the market may soon transition from correction to impulse, providing direction for future trades.   ### Direction for the Next Lower Degrees The expected direction for the next lower degrees is "red wave 3," suggesting that once the current corrective phase completes, a new impulse wave (red wave 3) will likely emerge, driving the price movement in a more significant direction.   ### Details The details section sheds light on the current state of the wave structure. According to the analysis, "red wave 1 of blue wave 1" is completed at 101.393. Currently, "red wave 2" is in play, indicating that the market is in the corrective phase of an overall uptrend. The "Wave Cancel invalid level" is set at 104.966, which means that if the price crosses this level, the current wave structure could be invalidated, suggesting a shift in market dynamics.   In summary, the AUD/JPY Elliott Wave Analysis for the 4-Hour Chart suggests that the market is in a corrective phase within a broader trend. Red wave 1 of blue wave 1 is complete, and red wave 2 is now in play, potentially leading to a new impulse phase. The Wave Cancel invalid level is 104.966, providing a key reference point for market invalidation. This analysis is useful for traders seeking to understand the current market context and anticipate future movements.     Technical Analyst : Malik Awais   Source : Tradinglounge.com get trial here!  
×
×
  • Create New...
us