Jump to content
Sign in to follow this  
OldWiseAndExperienced

Trade->IfDone Errors Encountered

Recommended Posts

Hi,

Trade->IfDone Issues:
I have a SubmitMarketOrder (Trade->MarketOrder) function that works fine but it did not have any IfDone parameters.  Now I have modified my MarketOrder / Trade request to include the IfDone parameters.  Something in the below IfDone block is causing me to get "Red Carded" [ Where's the ref, I want to complain... :-) ].  If I remove the IfDone parameters, the MarketOrder / Trade request functions Ok.

The result codes are:   "Status": 2, "StatusReason": 75,

I am pulling what little hair I have left out....  Could you examine the below request / response messages, and try to find the issue and point me in the right direction to get this working.
While you're at it, I have some additional questions:
1 - The "Guaranteed" parameter, is it actually supported?
2 - The "Quantity" parameter, in another forum post, I see you provided an example of an IfDone block to another developer, but you specified the quantity to be "1".  Can you clarify the reason and proper use of this parameter?  I have tried a value of 1, but still get an error saying value must be greater than zero :-/

Thank-you in advance for your answer.

Here is the Post Request:

{
  "IfDone": [
    {
      "Limit": {
        "TrailingDistance": null,
        "TriggerPrice": 1.1333,
        "Guaranteed": false,
        "Applicability": "GTC",
        "OrderId": 0,
        "Direction": "buy",
        "ExpiryDateTimeUTC": null,
        "Quantity": 5003
      }
    },
    {
      "Stop": {
        "TrailingDistance": null,
        "TriggerPrice": 1.1293,
        "Guaranteed": false,
        "Applicability": "GTC",
        "OrderId": 0,
        "Direction": "sell",
        "ExpiryDateTimeUTC": null,
        "Quantity": 5003
      }
    }
  ],
  "MarketID": 401484347,
  "MarketName": "EUR/USD",
  "Direction": "buy",
  "BidPrice": 1.1313,
  "OfferPrice": 1.13149,
  "Quantity": 5003.0,
  "TradingAccountId": 401756423,
  "AuditId": null,
  "PriceTolerance": 5,
  "Close": null,
  "PositionMethodId": 1,
  "QuoteId": null,
  "Reference": "GCAPI",
  "OrderReference": null,
  "Source": null,
  "Currency": null,
  "AutoRollover": false,
  "AllocationProfileId": null
}

Here is the Response:

{
  "Status": 2,
  "StatusReason": 75,
  "OrderId": 0,
  "Orders": [
    {
      "OrderId": 0,
      "StatusReason": 1,
      "Status": 1,
      "OrderTypeId": 1,
      "Price": 0.0,
      "Quantity": 5003.0,
      "TriggerPrice": 0.0,
      "CommissionCharge": 0.0,
      "IfDone": [],
      "GuaranteedPremium": 0.0,
      "OCO": null,
      "AssociatedOrders": {
        "Stop": {
          "OrderId": 0,
          "StatusReason": 1,
          "Status": 1,
          "OrderTypeId": 2,
          "Price": 0.0,
          "Quantity": 5003.0,
          "TriggerPrice": 1.1293,
          "CommissionCharge": 0.0,
          "IfDone": [],
          "GuaranteedPremium": 0.0,
          "OCO": {
            "OrderId": 0,
            "StatusReason": 49,
            "Status": 10,
            "OrderTypeId": 3,
            "Price": 0.0,
            "Quantity": 5003.0,
            "TriggerPrice": 1.1333,
            "CommissionCharge": 0.0,
            "IfDone": [],
            "GuaranteedPremium": 0.0,
            "OCO": null,
            "AssociatedOrders": {
              "Stop": null,
              "Limit": null
            },
            "Associated": true
          },
          "AssociatedOrders": {
            "Stop": null,
            "Limit": null
          },
          "Associated": true
        },
        "Limit": {
          "OrderId": 0,
          "StatusReason": 49,
          "Status": 10,
          "OrderTypeId": 3,
          "Price": 0.0,
          "Quantity": 5003.0,
          "TriggerPrice": 1.1333,
          "CommissionCharge": 0.0,
          "IfDone": [],
          "GuaranteedPremium": 0.0,
          "OCO": null,
          "AssociatedOrders": {
            "Stop": null,
            "Limit": null
          },
          "Associated": true
        }
      },
      "Associated": false
    }
  ],
  "Quote": null,
  "Actions": [],

Share this post


Link to post

Hi,

The easiest way to solve this is to use code that I've just tested multiple times and know works 100%. I've pasted it in below using one of my test accounts and with prices current at the time I tested them.

You can use this code and edit in your TradingAccountId, current prices and desired trade sizes and the orders will work.

A1) Guaranteed works only for supported markets. If I recall correctly you are a US Forex.com client? None of the spot forex markets you can trade support guaranteed orders so that parameter is not applicable for you.

A2) The quantity in that other post must have been for a CFD or Great Britain Spreadbet client, where quantity sizes are different than for spot FX. 

{
"MarketId":401484347,
"Direction":"buy",
"Quantity":5000,
"BidPrice":1.13172,
"OfferPrice":1.13184,
"TradingAccountId":401637645,
"PositionMethodId":1,
"IfDone":[{"Stop":{"OrderId":null,"Direction":"sell","Applicability":"gtc","ExpiryDateTimeUTC":null,"Guaranteed":false,"Quantity":5000,"TriggerPrice":1.12644,"IfDone":[],"OcoOrder":null},
           "Limit":{"OrderId":null,"Direction":"sell","Applicability":"gtc","ExpiryDateTimeUTC":null,"Quantity":5000,"TriggerPrice":1.13644,"IfDone":[],"OcoOrder":null}}]
}

 

Kind Regards, PM

Share this post


Link to post

Thank-you so much.  You provided a very abbreviated example of the entire request which answers a few other questions too.

As a side note, when I closely examined your IfDone block, they weren't symmetrical.  You were missing the "Guaranteed" parameter in the Limit section.  I simply added that to my code to make both the Stop and Limit blocks symmetrical.  This omission may mean that the "Guaranteed" parameter is actually not needed at all anywhere in the IfDone block.

The problems that I found in my request example that I sent to you were:
1 - 1 layer too many curly brackets in the IfDone block.
2 - In the IfDone block, I didn't have the "direction" parameters pointing the same way for both the Limit and the Stop.  One was a buy, the other a sell.  (I'm very tired, didn't think that one through).  Both need to be opposite of the initial market order entry direction.

Again, Thank-you so much.

Share this post


Link to post

Hi,

Glad to hear that it's all working fine for you now. 

As a US Forex.com client, you can leave out the Guaranteed parameter as no markets you can trade support Guaranteed Stops. As a note, Guaranteed is redundant for Limit orders, since by definition, they can only fill at the price you specify or better (should the market touch the trigger price) but never worse. Stops on the other hand can be subject to slippage. 

Kind Regards, 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
Sign in to follow this  
×