Jump to content
james

UpateTrade returns a 500

Recommended Posts

Hello!

I want to adjust an existing Stop on an open trade. What is the best way to do this? My working understanding is that UpateTrade is the best route, but I'm having trouble understanding it.

I'm attempting to use the UpdateTrade endpoint as documented at http://docs.labs.gaincapital.com/#HTTP Services/UpdateTrade.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Trades%20and%20Orders|_____18

I'm getting a 500 server error response. What am I doing wrong?

I'm opening a trade using the newtradeorder endpoint. I'll paste an example response at the bottom of this post.

I'm then trying to use UpdateTrade to alter it. I've tried to mimic the example provided on the documentation page, but get the same error. Below is an example of what I have sent with most of the fields stripped out. Which fields should be required?

As always, your advice and guidance is hugely appreciated!

 

UpateTrade request, which results in the 500 error

  'OrderId' => "702495938",
  'TradingAccountId' => "xxxxxxx",
            'IfDone' => [
                [
                    'Stop' => [
                        'Applicability' => 'GTC',
                        'Direction' => 'Sell',
                        'ExpiryDateTimeUTC' => null,
                        'IfDone' => [],
                        'OcoOrder' => null,
                        'OrderId' => null,
                        'Quantity' => 1,
                        'TriggerPrice' => 1450.00,
                    ],
                ],
            ],

 

Response from newtradeorder, which created an open trade I can see in forex.com panel and provided the OrderId I am attempting to update.

"Orders": [
        {
            "OrderId": 702495938,
            "StatusReason": 1,
            "Status": 3,
            "OrderTypeId": 1,
            "Price": 1505.57,
            "Quantity": 1,
            "TriggerPrice": 0,
            "CommissionCharge": 0,
            "IfDone": [],
            "GuaranteedPremium": 0,
            "OCO": null,
            "AssociatedOrders": {
                "Stop": {
                    "OrderId": 702495939,
                    "StatusReason": 1,
                    "Status": 2,
                    "OrderTypeId": 2,
                    "Price": 0,
                    "Quantity": 1,
                    "TriggerPrice": 1400,
                    "CommissionCharge": 0,
                    "IfDone": [],
                    "GuaranteedPremium": 0,
                    "OCO": {
                        "OrderId": 702495940,
                        "StatusReason": 1,
                        "Status": 2,
                        "OrderTypeId": 3,
                        "Price": 0,
                        "Quantity": 1,
                        "TriggerPrice": 1700,
                        "CommissionCharge": 0,
                        "IfDone": [],
                        "GuaranteedPremium": 0,
                        "OCO": null,
                        "AssociatedOrders": {
                            "Stop": null,
                            "Limit": null
                        },
                        "Associated": true
                    },
                    "AssociatedOrders": {
                        "Stop": null,
                        "Limit": null
                    },
                    "Associated": true
                },
                "Limit": {
                    "OrderId": 702495940,
                    "StatusReason": 1,
                    "Status": 2,
                    "OrderTypeId": 3,
                    "Price": 0,
                    "Quantity": 1,
                    "TriggerPrice": 1700,
                    "CommissionCharge": 0,
                    "IfDone": [],
                    "GuaranteedPremium": 0,
                    "OCO": null,
                    "AssociatedOrders": {
                        "Stop": null,
                        "Limit": null
                    },
                    "Associated": true
                }
            },
            "Associated": false
        }
    ],
    "Quote": null,
    "Actions": [
        {
            "ActionedOrderId": 0,
            "ActioningOrderId": 0,
            "Quantity": 1,
            "ProfitAndLoss": 0,
            "ProfitAndLossCurrency": null,
            "OrderActionTypeId": 1
        }
    ],
    "ErrorMessage": null
}

 

Edited by Physicsman
outdate version of request json pasted by mistake

Share this post


Link to post

Hi James,

When updating an open position such as in this example, changing the attached stop loss, you send a call to the UpdateTrade end point as you have correctly stated. The payload body is very similar to the body of the original open trade call, with the addition of the OrderId fields filled in. Clearly, in the UpdateTrade call, you also send the updated Stop loss order details.

As an example, the below is the body of the call to the Trade endpoint I sent to open a position with attached stop and limit.

{
    "MarketId": 401153870,
    "Direction": "buy",
    "Quantity": 1,
    "BidPrice": 1504.56,
    "OfferPrice": 1505.04,
    "TradingAccountId": xxxxxxx,
    "PositionMethodId": 1,
    "IfDone": [
        {
            "Stop": {
                "OrderId": null,
                "Direction": "sell",
                "Applicability": "gtc",
                "ExpiryDateTimeUTC": null,
                "Guaranteed": false,
                "Quantity": 1,
                "TriggerPrice": 1405.04,
                "IfDone": [],
                "OcoOrder": null
            },
            "Limit": {
                "OrderId": null,
                "Direction": "sell",
                "Applicability": "gtc",
                "ExpiryDateTimeUTC": null,
                "Quantity": 1,
                "TriggerPrice": 1605.04,
                "IfDone": [],
                "OcoOrder": null
            }
        }
    ]
}

 

The following body is what I sent to UpdateTrade to pull in the Stop loss by 50 points. You can see it is very similar to the opening trade call, with the additions of the OrderID and the new stop TriggerPrice.

{
    "MarketId": 401153870,
    "OrderId": 702512425,
    "Direction": "buy",
    "Quantity": 1,
    "BidPrice": 1504.87,
    "OfferPrice": 1505.35,
    "TradingAccountId": xxxxxxx,
    "PositionMethodId": 1,
    "IfDone": [
        {
            "Stop": {
                "OrderId": 702512426,
                "Direction": "sell",
                "Applicability": "gtc",
                "ExpiryDateTimeUTC": null,
                "Guaranteed": false,
                "Quantity": 1,
                "TriggerPrice": 1455.47,
                "IfDone": [],
                "OcoOrder": null
            },
            "Limit": {
                "OrderId": 702512427,
                "Direction": "sell",
                "Applicability": "gtc",
                "ExpiryDateTimeUTC": null,
                "Quantity": 1,
                "TriggerPrice": 1605.47,
                "IfDone": [],
                "OcoOrder": null
            }
        }
    ]
}

 

Cordially, PM

Share this post


Link to post

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
×