SirNewton 3 Report post Posted February 17 Hello Physicsman, have a question using Close key value pair to close an existing trade. See: https://docs.labs.gaincapital.com/#Data Types/NewTradeOrderRequestDTO.htm Close integer[] List of existing open trade order IDs that require part or full closure. I tied it out on Postman with below JSON object: { "MarketId": 401484406, "Currency": null, "AutoRollover": false, "Direction": "sell", "Quantity": 1000, "QuoteId": 0, "PositionMethodId": 0, "BidPrice": 1.0001, "OfferPrice": 1.5001, "AuditId": "939239####", "TradingAccountId": ##########, "IfDone": null, "Close": ["779386607"], "Reference": null, "AllocationProfileId": 0, "OrderReference": null, "Source": null, "PriceTolerance": 0, "isTrade":true } And the response I get: { "Status": 4, "StatusReason": 112, "OrderId": 0, "Orders": [], "Quote": null, "Actions": [], "ErrorMessage": null } I looked up 112 StatusReason and according the documentation: https://docs.labs.gaincapital.com/#APICodesList.htm?Highlight=API Code Lookup Values I see it say, "NFA FIFO Account - Target closure restricted." What am I doing wrong here? How do I use Close with API NewTradeOrderRequest to close an existing trade? Thank you. Share this post Link to post
Physicsman 26 Report post Posted February 17 Hi SirNewton, A couple of clarifying questions: Are you a US client? Did you have more than one open position in the same market, and you were attempting to close one of those open positions specifically? The error message you are seeing is related to the case when the answers to both questions above are true. US clients are forced by the US regulator to close positions in a First In First Out (FIFO) order. For example, if you buy GBP/USD, then a little time later add to your buy position, and after some more time buy a 3rd position in GBP/USD. As a US client you must close the positions in the order you opened them. If you try to close say the 2nd or 3rd position out of sequence, then you will receive this error message. If the above doesn't apply to you we can investigate further. Kind Regards, PM Share this post Link to post
SirNewton 3 Report post Posted February 17 Are you a US client? Yes, I am in the US. And I am a US client. Did you have more than one open position in the same market, and you were attempting to close one of those open positions specifically? Yes, I had several open in the same market and was trying to close one specifically. When I don't include anything in the CLOSE, it seems to close a random trade. I was hoping to use CLOSE to close a specific trade. Thank you. Share this post Link to post
SirNewton 3 Report post Posted February 17 Why enforce FIFO in the US? Not sure, why that would be the case. Why would the US regulators enforce that? Share this post Link to post
Physicsman 26 Report post Posted February 18 Hi SirNewton, When you didn't include anything in the Close field the system should be closing your positions in the order they were opened going from first to second..., rather than closing them at random. Reading through the following link on the rule, it looks as though the NFA's aim of implementing this FIFO rule was to prevent clients from "hedging", which is to have simultaneous offsetting long and short positions in the same market. https://www.investopedia.com/terms/n/nfa-compliance-rule-2-43b.asp Kind Regards, PM Share this post Link to post
SirNewton 3 Report post Posted February 21 Got it. Even though, I would rather control the order I close the trades myself, I have adjusted for FIFO. Thanks. Share this post Link to post