Jump to content
  • 0

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


SZZ

Question

Posted

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

8 answers to this question

Recommended Posts

  • 0
Posted
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
  • 0
Posted

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.

 

  • 0
Posted

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?

 

  • 0
Posted

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
  • 0
Posted

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

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

    • Lately I’ve been following AIXBT by Virtuals for a bit, and I’m not gonna lie, it’s making me wonder about the direction AI is taking in the crypto space. Kinda seen a lot of hype around AI lately on X and different forums. So here’s my take, instead of just applying AI to the usual market analysis, AIXBT is talking about AI agents that could actually be co-owned and tokenized like digital assets that interact with games, social platforms, and even manage wallets. More findings in the whole co-ownership thingy, which is a great idea especially with the blockchain aspect. A lot of people are talking about how AI could help boost revenue across different platforms, but I’m still skeptical about how this will actually work in practice. These agents are supposed to be able to do things like pick up a sword in Roblox or interact on TikTok, but will they actually change the way users engage with digital spaces? Couple of top exchanges like BINGX already listed $AIXBT which is a big deal, imho as it’s gaining some real traction already.  Notwithstanding, still thinking if this is the future of digital assets, or is it just another trend that’s getting way too much hype?
    • With Clanker native token recently listed on Bitget and already trading above $68, some people have start speculating that this AI-driven token deployment platform on the Base network could increase adoption on the blockchain due to some various reason such as; 1. Ease of Token Creation: Clanker simplifies the process of token creation to the point where it's accessible to anyone with basic social media skills. Users can deploy tokens by simply tagging Clanker on the Farcaster platform, describing their desired token, thereby lowering the entry barriers for token creators and potentially attracting a broader user base to the Base ecosystem. 2. Community Engagement and Viral Potential: The integration of token deployment with social media platforms like Farcaster encourages community participation. Memes and viral content can naturally lead to increased attention and, consequently, adoption. Clanker's tokens often become memes themselves, which can drive speculative interest and trading volume, furthering the network's visibility 3. Profit Sharing Mechanism: Clanker's model includes sharing a portion of the fees with the users who request token deployments. This financial incentive could encourage more people to use Clanker for launching tokens, thus increasing activity on Base. The promise of earning from the liquidity pool fees makes it an attractive proposition for users looking to participate in the crypto space in a potentially profitable manner. 4. Innovation in Tokenomics: By introducing tokens like LUM, which were autonomously created through AI collaboration, Clanker showcases innovative tokenomics. This not only promotes the idea of AI in blockchain but also piques interest in how tokens can be generated, possibly drawing tech enthusiasts and investors curious about new token models. 5. Fostering Decentralized Social Interaction: Clanker's operation within the Farcaster ecosystem highlights how blockchain can intersect with decentralized social networks. This intersection can lead to new forms of interaction and economic models where social engagement directly correlates with token creation, potentially making Base a hub for such activities.  6. Market Activity Boost: The surge in transaction volumes due to Clanker's activity indicates its substantial impact on the network's activity. High transaction volumes often correlate with increased interest and investment in a blockchain, which could lead to greater adoption as more participants are drawn to where the action is.   Is obvious that these factors could increase adoption to base chain but what do you think?
    • I just claimed my allocation to bitget since there is $0 gass fee for claiming. I hope this project cooks 
×
×
  • Create New...
us