Jump to content
CaptainRedBeard

Attached Limit Order for New Trade fails in Live Account

Recommended Posts

I was able to attach  limit orders to new trades without any issues when using my demo account (so that my position is closed at a given price). However, when I tried to do the same thing in my Live account, the trade placement fails because the associated limit order fails with "StatusReason":71,"Status":10 . According to the error codes docs, reason 71 is "This Market does not allow limit orders".
When I remove the limit order to my new trade post request, the trade is placed successfully. When I add it back, trade placement fails. I am using the STP Pro account for my live account so could it be that it doesn't support limit orders? Here is my New trade request (with sensitive info removed):

{
  "MarketId": 400723798,
  "Direction": "buy",
  "Quantity": 100000,
  "BidPrice": 107.2129,
  "OfferPrice": 107.21293,
  "AuditId": "dGDHFKIE_FX_GDJU12378",
  "TradingAccountId": "12345678",
  "PositionMethodId": 1,
  "IfDone": [
    {
      "Limit": {
        "OrderId": null,
        "Direction": "sell",
        "Applicability": "gtc",
        "ExpiryDateTimeUTC": null,
        "Quantity": 100000,
        "TriggerPrice": 107.21416,
        "IfDone": [],
        "OcoOrder": null
      }
    }
  ],
  "Reference": "GCAPI"
}

Am I missing something in my request or is there a limitation with my account type and the API?

Thanks,
CRB

Share this post


Link to post

Hi,

Are you using a Direct Market Access (DMA) account? Those are our account types that don't allow users to attach Stops/limits to close a specific position. Or do you have an account under US jurisdiction? There are certain restrictions for those accounts too.

I checked the API JSON code you are sending and it is in a valid format. It should work - if your account supports it.  

Kind Regards, PM 

 

Share this post


Link to post

I have a follow up question regarding attaching Stop/Limit order with a New Trade Order.

Documentation says  "NewTradeOrderRequestDTO" has "IfDone" property where I can attach STOP and LIMIT Orders. IfDone is consists of these two (in c#) properties

        public ApiStopLimitOrderDTO Stop { get; set; }
        public ApiStopLimitOrderDTO Limit { get; set; }

 

And "ApiStopLimitOrderDTO" has these properties


        public bool Guaranteed { get; set; }
        public decimal TriggerPrice { get; set; }
        public string ExpiryDateTimeUTC { get; set; }
        public string Applicability { get; set; }
        public int? ParentOrderId { get; set; }
        public decimal? TrailingDistance { get; set; }
        public bool Associated { get; set; }

in the ABOVE Example we have 

"IfDone": [
    {
      "Limit": {
        "OrderId": null,
        "Direction": "sell",
        "Applicability": "gtc",
        "ExpiryDateTimeUTC": null,
        "Quantity": 100000,
        "TriggerPrice": 107.21416,
        "IfDone": [],
        "OcoOrder": null
      }
    }
  ],

Here the IfDone's "Limit" does not conform to ApiStopLimitOrderDTO Properties. What am I missing here?

What's the proper way to Attach Stop/Limit Order when sending a Trade-At-Market-Rate Order?

 

Share this post


Link to post

Hi Superee,

ApiStopLimitOrderDTO also inherits from ApiOrderDTO and all of its properties, hence the link to that DTO in the documentation. Additionally, many of the Properties are nullable and can be dropped from the reqeusts. 

image.png

 

A valid trade request with attached stops/limits can be formed as in the following example:

"IfDone": [
                {
                    "Stop": {
                        "OrderId": 778252070,
                        "StatusReason": 1,
                        "Status": 2,
                        "OrderTypeId": 2,
                        "Price": 0,
                        "Quantity": 1000,
                        "TriggerPrice": 1.36261,
                        "CommissionCharge": 0,
                        "IfDone": [],
                        "GuaranteedPremium": 0,
                        "OCO": null,
                        "AssociatedOrders": {
                            "Stop": null,
                            "Limit": null
                        },
                        "Associated": false
                    },
                    "Limit": {
                        "OrderId": 778252069,
                        "StatusReason": 1,
                        "Status": 2,
                        "OrderTypeId": 3,
                        "Price": 0,
                        "Quantity": 1000,
                        "TriggerPrice": 1.36661,
                        "CommissionCharge": 0,
                        "IfDone": [],
                        "GuaranteedPremium": 0,
                        "OCO": null,
                        "AssociatedOrders": {
                            "Stop": null,
                            "Limit": null
                        },
                        "Associated": false
                    }
                }
            ],

Kind Regards, PM

 

Share this post


Link to post

Ok, I should've guessed the "Inheritance" - may be I missed that to remember when studied the documentation. Thanks for pointing that out.

I assume anytime I see something like :-

ApiPrimaryMarketTagDTO > ApiMarketTagDTO

I know "ApiPrimaryMarketTagDTO" class inherits from "ApiMarketTagDTO" class (in c# terms)

Thanks for the info!

Share this post


Link to post

I am trying to submit a "GBP/JPY" Trade Order through API, that will do the same as the GUI Submission - screenshot attached.

My "order/newtradeorder" POST body :-

{
   "MarketId":401484385,
   "Currency":null,
   "AutoRollover":false,
   "Direction":"Buy",
   "Quantity":11000.0,
   "QuoteId":0,
   "PositionMethodId":1,
   "BidPrice":143.402,
   "OfferPrice":143.528,
   "AuditId":"7975276",
   "TradingAccountId":40319,
   "IfDone":{
      "Stop":{
         "Guaranteed":false,
         "TriggerPrice":142.979,
         "ExpiryDateTimeUTC":null,
         "Applicability":"GTC",
         "ParentOrderId":null,
         "TrailingDistance":null,
         "Associated":false,
         "OrderId":null,
         "Reference":null,
         "OrderReference":null,
         "AutoRollover":false,
         "MarketId":401484385,
         "Direction":"Sell",
         "Quantity":11000.0,
                  
         
         "TradingAccountId":40319,
         
         "IfDone":null,
         "OcoOrder":null,
         "LastChangedDateTimeUTC":null,
         "AssociatedOrders":null
      },
      "Limit":{
         "Guaranteed":false,
         "TriggerPrice":144.038,
         "ExpiryDateTimeUTC":null,
         "Applicability":"GTC",
         "ParentOrderId":null,
         "TrailingDistance":null,
         "Associated":false,
         "OrderId":null,
         "Reference":null,
         "OrderReference":null,
         "AutoRollover":false,
         "MarketId":401484385,
         "Direction":"Sell",
         "Quantity":11000.0,

         "TradingAccountId":40319,
         
         "IfDone":null,
         "OcoOrder":null,
         "LastChangedDateTimeUTC":null,
         "AssociatedOrders":null
      }
   },
   "Close":null,
   "Reference":null,
   "AllocationProfileId":0,
   "OrderReference":null,
   "Source":null,
   "PriceTolerance":0
}

 

API Call produces no ERROR, a Trade is created/opened BUT NO STOP LIMIT Order created. I do not see any ERROR message in the RESPONSE :-

{
    "Status": 1,
    "StatusReason": 1,
    "OrderId": 778264513,
    "Orders": [
        {
            "OrderId": 778264513,
            "StatusReason": 1,
            "Status": 3,
            "OrderTypeId": 1,
            "Price": 143.446,
            "Quantity": 11000.0,
            "TriggerPrice": 0.0,
            "CommissionCharge": 0.0,
            "IfDone": [],
            "GuaranteedPremium": 0.0,
            "OCO": null,
            "AssociatedOrders": {
                "Stop": null,
                "Limit": null
            },
            "Associated": false
        }
    ],
    "Quote": null,
    "Actions": [
        {
            "ActionedOrderId": 0,
            "ActioningOrderId": 0,
            "Quantity": 11000.0,
            "ProfitAndLoss": 0.0,
            "ProfitAndLossCurrency": null,
            "OrderActionTypeId": 1
        }
    ],
    "ErrorMessage": null
}

 

Second question:

 In my C# Classes some of the Integer Properties are not marked as "nullable", thus they show up in JSON with value '0', like "OrderId":0, instead on "OrderId":null. Can that cause problem?

 

FX_Trade_GUI_Submitted.PNG

FX_BuyWStopLoss.PNG

Share this post


Link to post

OK, I found the issue - It's related to the "IfDone" class and how c# serializes it.

In the Request JSON I have 

.... ... .. .
"TradingAccountId":40319,
"IfDone":{
      "Stop":{
... ... ...
},
"Close":null,
.... ... .. .

But IfDone has to be an "ARRAY" Object in JSON, like

.... ... .. .
"TradingAccountId":40319,
"IfDone":[{
      "Stop":{
... ... ...
}],
"Close":null,
.... ... .. .

The Square Brackets

                   "IfDone" : [ {

has to be there for the API Call to Work. 

 

In My C# Class "ApiIfDoneDTO" has TWO "ApiStopLimitOrderDTO" Properties Stop and Limit. But it is not an "Array". I can hack in to the NewtonSoft's JSON converted text and add "[" and "]" to the "IfDone" segment of the JSON. But not sure how to create the "ApiIfDoneDTO" Class that will create JSON with [ and] automatically.

 

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
×