Skip to content

Conversation

DJB31st
Copy link

@DJB31st DJB31st commented Mar 20, 2025

Out of the box this doesn't seem to work correctly, it'll return saying its closed but never close, expiry and level are optional

Out of the box this doesn't seem to work correctly, it'll return saying its closed but never close, expiry and level are optional
orderType: createPositionRequest.orderType,
size: createPositionRequest.size,
direction: Direction.SELL, //ensure opposite direction to close the position
orderType: PositionOrderType.MARKET, //seemingly have to use market otherwise it'll wait for the level
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When providing a different type than MARKET does it mean you will have to specify a level then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to work this out myself based on the documentation and testing.

It's awkward to test as it isn't 100% clear.

The docs state

"Limit orders get executed at the price seen by IG at the moment of booking a trade. A limit determines the level at which the order or the remainder of the order will be rejected."

I wasn't getting any response when using LIMIT, with various test levels, however i don't know if the close would happen at that particular level. That seems logical, but then a stop level would do the same thing and i don't think IG supports closing at a predefined level any other way.

I made this change off the back of looking at this implementation which always passes "market"

https://github.com/gfiocco/node-ig-api/blob/master/index.js and this discussion here ig-python/trading-ig#181

My assumption was that Market should always be used for the order type when closing. Although the documentation constraints suggest you can enter a LIMIT, it isn't really clear when that close should trigger?

[Constraint: If epic is defined, then set expiry]
[Constraint: If orderType equals LIMIT, then DO NOT set quoteId]
[Constraint: If orderType equals LIMIT, then set level]
[Constraint: If orderType equals MARKET, then DO NOT set level,quoteId]
[Constraint: If orderType equals QUOTE, then set level,quoteId]
[Constraint: Set only one of {dealId,epic}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants