Jump to content
Sign in to follow this  
danilo

Not able to set the stop loss

Recommended Posts

Hello

Setting of stop loss limit starts failing with reason code 75. tried contacting support and they informed that this restriction is applied to account registered for UK and non UK accounts does not have this restrictions. They created  a new practice account for us to solve this issue and it worked for some days but all of sudden I start getting status code 75 again. Any lead on this behavior or solution to the problem?

 

Thanks

Share this post


Link to post

Hi Danilo,

Is that OrderStatusReason code 75 you are talking about or InstructionStatusReason code?

OrderStatusReason code 75 states "The total quantity of guaranteed stop orders must be equal to trade order quantity." Have you accidentally set the total quantity of all your stops to be greater than the total position you have open? You can find all the lookup codes at:

http://docs.labs.gaincapital.com/#APICodesList.htm%3FTocPath%3DGetting%20Started|Lookup%20Values|_____1

If it is the InstructionStatusReason code of 75 you are receiving, then what is the corresponding OrderStatusReason code? The OrderStatusReason code provides the explanatory information as to why your orders were rejected/failed.

Kind Regards, PM

 

Share this post


Link to post

Hello , Please find request and response . Please have a look and let me know if what is wrong in it.

Request -

{"IfDone":[{"Stop":{"ExpiryDateTimeUTC":null,"Guaranteed":false,"Direction":"buy","Quantity":1000,"Applicability":"GTC","TriggerPrice":1.9621,"OrderId":0}}],"Direction":"sell","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,"OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":"GTC","TriggerPrice":1.9629,"BidPrice":2.43708,"AutoRollover":false,"MarketId":401484388,"OfferPrice":2.43708,"AuditId":"bb2ad99c-354e-4acc-a9aa-429bafd2057c","OrderId":709910755,"Currency":null,"Quantity":2,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId":1,"TradingAccountId":402373909,"Status":null,"isTrade":true}

Response  {"Status":2,"StatusReason":75,"OrderId":709910755,"Orders":[{"OrderId":709910755,"StatusReason":1,"Status":3,"OrderTypeId":1,"Price":1.9629,"Quantity":1000.0,"TriggerPrice":0.0,"CommissionCharge":0.0,"IfDone":[],"GuaranteedPremium":0.0,"OCO":null,"AssociatedOrders":{"Stop":null,"Limit":null},"Associated":false}],"Quote":null,"Actions":[],"ErrorMessage":null}
 

Share this post


Link to post

Hello,

I "prettified" the JSON in your request and saw that the you did have mismatching trade quantities. 

Your entry order has a quantity of 2, whereas the stop you are trying to attach to the entry order has a trade size of 1000. The stop must have a trade size equal to the original entry order, if you want the stop to fully close, or less than the entry order size if your stop is only a partial close.

Kind Regards, PM

image.png

Share this post


Link to post

Thanks for your reply. But I see another request with same diff is worked fine

 

{
"IfDone": [
{
"Stop": {
"ExpiryDateTimeUTC": null,
"Guaranteed": false,
"Direction": "buy",
"Quantity": 1000,
"Applicability": "GTC",
"TriggerPrice": 1.99467,
"OrderId": 0
}
}
],
"Direction": "sell",
"ExpiryDateTimeUTCDate": null,
"LastChangedDateTimeUTCDate": null,
"OcoOrder": null,
"Type": null,
"ExpiryDateTimeUTC": null,
"Applicability": "GTC",
"TriggerPrice": 1.99237,
"BidPrice": 2.43708,
"AutoRollover": false,
"MarketId": 401484388,
"OfferPrice": 2.43708,
"AuditId": "a60a608e-5641-4a3d-9a50-a8bbf85ec9c0",
"OrderId": 711005695,
"Currency": null,
"Quantity": 2,
"QuoteId": null,
"LastChangedDateTimeUTC": null,
"PositionMethodId": 1,
"TradingAccountId": 402373909,
"Status": null,
"isTrade": true
}
 
{
"Status": 1,
"StatusReason": 1,
"OrderId": 711005695,
"Orders": [
{
"OrderId": 711005695,
"StatusReason": 1,
"Status": 3,
"OrderTypeId": 1,
"Price": 1.99237,
"Quantity": 1000.0,
"TriggerPrice": 0.0,
"CommissionCharge": 0.0,
"IfDone": [],
"GuaranteedPremium": 0.0,
"OCO": null,
"AssociatedOrders": {
"Stop": null,
"Limit": null
},
"Associated": false
},
{
"OrderId": 711005696,
"StatusReason": 1,
"Status": 2,
"OrderTypeId": 2,
"Price": 0.0,
"Quantity": 1000.0,
"TriggerPrice": 1.99467,
"CommissionCharge": 0.0,
"IfDone": [],
"GuaranteedPremium": 0.0,
"OCO": null,
"AssociatedOrders": {
"Stop": null,
"Limit": null
},
"Associated": false
}
],
"Quote": null,
"Actions": [],
"ErrorMessage": null
}

Share this post


Link to post

Hi Danilo,

I see 2 anomalies in the pasted JSON request and response that is most puzzling indeed.

The request is to place an entry order to Sell with quantity 2 should the market price reach 1.99237. Yet the response is that of a trade where you have opened a position at 1.99237 with quantity 1000!?!

1) How did you manage to send an entry order that results in placing a trade with an open position instead?

2) How did sending the entry order request with quantity = 2 result in a trade with open position quantity = 1000?

 

The only thing we have managed to answer is why the stop loss attached is accepted in this case. It is because the open position has quantity = 1000 and the stop loss quantity also = 1000, so you do not receive the Error 75 as you did in the previous case.

My suggestions are to ensure that you are sending the entry order requests to the /newstoplimitorder endpoint, and to ensure that the quantities of the stop loss and entry orders are equal. This will result in a full close should the stop loss order be triggered. The system will never accept orders when you have an open position of quantity = 2 and a stop loss of quantity = 1000. 

image.png

Kind Regards, PM

 

 

Share this post


Link to post

Thank you for your reply. My use case is 

1) execute a postion 

2) then set the stop loss 

3) update the stop loss 

Pls find below request response. I corrected the Quantity issue but still end up same error. Per my understanding the issue is with the value of stop loss I am trying to update. It was set to 1.9922 in step 2 and I tried to update it to 1.99380.  

I am using /updatetradeorder API. When I tried to set the value 1.99380 from forex web application , they have also not allowed me with some validations that max value is so and so.  

Requesting you to please have a look and let me know what is the mistake that I am doing. I tried contacting support guys and they said that this stop loss price restrictions is applicable to UK accounts and they confirmed that mine account is not UK. Not sure what is wrong here. 

 

// Execute buy order
{
"MarketName": "XYZ",
"TradingAccountId": XXXXX,
"MarketId": 401484388,
"Quantity": 1000,
"OrderId": 0,
"Direction": "buy",
"OfferPrice": 1.9939,
"BidPrice": 1.99315,
"PriceTolerance": 10,
"PositionMethodId": 1,
"AuditId": "ed6c6c6f-a368-4d54-8b87-59c564f991dc",
"AutoRollover": false,
"isTrade": true
}
// success  response
{
"Status": 1, // OK
"StatusReason": 1, // OK
"OrderId": 711777646, // Order ID
"Orders": [
{
"OrderId": 711777646,
"StatusReason": 1, // OK
"Status": 3, // OPen
"OrderTypeId": 1, // Trade
"Price": 1.9939, // Open Price
"Quantity": 1000.0, // Qty
"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": 1000.0,
"ProfitAndLoss": 0.0,
"ProfitAndLossCurrency": null,
"OrderActionTypeId": 1
}
],
"ErrorMessage": null
}
// Set Stop Loss
{
"IfDone": [
{
"Stop": { // Set Stop
"ExpiryDateTimeUTC": null,
"Guaranteed": false,
"Direction": "sell",
"Quantity": 1000, // Qty
"Applicability": "GTC",
"TriggerPrice": 1.9922, // price to set stop loss 
"OrderId": 0
}
}
],
 
"Direction": "buy",
"ExpiryDateTimeUTCDate": null,
"LastChangedDateTimeUTCDate": null,
"OcoOrder": null,
"Type": null,
"ExpiryDateTimeUTC": null,
"Applicability": "GTC",
"TriggerPrice": 1.9939, // open price of parent order
"BidPrice": 2.43708, // dummy
"AutoRollover": false,
"MarketId": 401484388,
"OfferPrice": 2.43708, // dummy
"AuditId": "a8aaec68-2957-45d8-b89f-bd1ffc58d67a",
"OrderId": 711777646,
"Currency": null,
"Quantity": 1000,
"QuoteId": null,
"LastChangedDateTimeUTC": null,
"PositionMethodId": 1,
"TradingAccountId": XXXX,
"Status": null,
"isTrade": true
}
// Response
{
"Status": 1, // OK
"StatusReason": 1, // OK
"OrderId": 711777646, // Parent Order Id
"Orders": [
// parent order details
{
"OrderId": 711777646, // order id
"StatusReason": 1, // ok
"Status": 3, // open
"OrderTypeId": 1, // trade
"Price": 1.9939, // order price
"Quantity": 1000.0, // qty
"TriggerPrice": 0.0,
"CommissionCharge": 0.0,
"IfDone": [],
"GuaranteedPremium": 0.0,
"OCO": null,
"AssociatedOrders": {
"Stop": null,
"Limit": null
},
"Associated": false
},
// stop
{
"OrderId": 711777649, // stop order id
"StatusReason": 1, // ok
"Status": 2, // accepted
"OrderTypeId": 2, // stop
"Price": 0.0,
"Quantity": 1000.0,
"TriggerPrice": 1.9922, // stop price
"CommissionCharge": 0.0,
"IfDone": [],
"GuaranteedPremium": 0.0,
"OCO": null,
"AssociatedOrders": {
"Stop": null,
"Limit": null
},
"Associated": false
}
],
"Quote": null,
"Actions": [],
"ErrorMessage": null
}
// update stop loss
{
"IfDone": [
{
"Stop": {
"ExpiryDateTimeUTC": null,
"Guaranteed": false,
"Direction": "sell",
"Quantity": 1000,
"Applicability": "GTC",
"TriggerPrice": 1.99380, // updating price to 1.99380 from 1.99220
"OrderId": 0
}
}
],
"Direction": "buy",
"ExpiryDateTimeUTCDate": null,
"LastChangedDateTimeUTCDate": null,
"OcoOrder": null,
"Type": null,
"ExpiryDateTimeUTC": null,
"Applicability": "GTC",
"TriggerPrice": 1.9939,
"BidPrice": 2.43708,
"AutoRollover": false,
"MarketId": 401484388,
"OfferPrice": 2.43708,
"AuditId": "462d21b4-5ec9-4ab9-a32e-0545c299bda2",
"OrderId": 711777646,
"Currency": null,
"Quantity": 1000,
"QuoteId": null,
"LastChangedDateTimeUTC": null,
"PositionMethodId": 1,
"TradingAccountId": XXXXX,
"Status": null,
"isTrade": true
}
 
// response FAIL
{
"Status": 2, // Red Card
"StatusReason": 75, // Check the values
"OrderId": 711777646,
"Orders": [
{
"OrderId": 711777646,
"StatusReason": 1,
"Status": 3,
"OrderTypeId": 1,
"Price": 1.9939,
"Quantity": 1000.0,
"TriggerPrice": 0.0,
"CommissionCharge": 0.0,
"IfDone": [],
"GuaranteedPremium": 0.0,
"OCO": null,
"AssociatedOrders": {
"Stop": null,
"Limit": null
},
"Associated": false
}
],
"Quote": null,
"Actions": [],
"ErrorMessage": null
}

 

 

Share this post


Link to post

Hello Danilo,

I very much appreciate your laying out the exact steps you are taking and the requests/responses. It makes everything very clear and significantly easier to troubleshoot. Thank you! 

Looking through your requests I believe I have found the reason why your step 3 (editing the stop loss trigger) price is failing. In your update stop request, the OrderID of the Stop loss (received in the response to step 2) must be supplied. Your request has: 

"OrderId"0

It should be for example based on the stop loss order ID you received from step 2: 

"OrderId"711777646// stop order id

image.png

Note 1

In your step 2 when you are first adding a stop loss to your open position, although it appears to be working you should set the order ID as null instead of zero.

  "OrderId"null,
 
Note 2
You mentioned using the web trading platform to attempt moving the stop loss and receiving a validation warning preventing you from moving the stop loss. I presume this is because you attempted to update the stop level too close to the current price? Some markets have a minimum distance for stop/limit orders away from the the current price. 
 
Kind Regards, PM

 

 

 

Share this post


Link to post

Thank you so much for your kind words and feedback. I tried the suggestion and still end up getting same error.  Please confirm the order Id to pass in Step 3 will be order Id of trade order OR stop loss order.  Also as you mentioned "Some markets have a minimum distance for stop/limit orders away from the the current price" so is this a forex API restrictions or a market restrictions? Also as per forex person this is only applicable for UK accounts but I am not able to set even if my test account is not UK based. 

Also I see two document links so which one is correct?

http://docs.labs.gaincapital.com/

http://docs.labs.cityindex.com/

Thanks

Share this post


Link to post

Hi Danilo,

Since you mentioned you have a test account (NOT a Live account), please send me a DM with the test account credentials. I can then use that test account to send the API requests to perform Steps 1, 2, and 3 as you have described. We can see what happens and investigate from there as needed.

http://docs.labs.gaincapital.com/ is the correct URL. The other one is the old address - we moved the API documentation to http://docs.labs.gaincapital.com/ so no need to use the other address. :)

Kind Regards, PM

Share this post


Link to post

I forgot to address your other query about minimum order distance. :D

The minimum order distance is a restriction set on every market, not a limitation of the API. For most markets it is quite small, for example EUR/USD is 0.8 pips outside the spread. You can view the minimum order distance by sending a ListMarketInformation call for the markets you are interested in trading. In the reponse, there will be a field MinDistance, that shows how close to the current market spread you can place your stop or limit orders.

image.png

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  
×