Update PositionCloseRequest and position demo#643
Update PositionCloseRequest and position demo#643DJB31st wants to merge 1 commit intobennycode:mainfrom
Conversation
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 |
There was a problem hiding this comment.
When providing a different type than MARKET does it mean you will have to specify a level then?
There was a problem hiding this comment.
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}]
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