Jump to content
Sign in to follow this  
Ynor

Set Stop/Limit to a new trade

Recommended Posts

Hello,

I have a service that opens new trades using the /newtradeorder endpoint.

This is my request Json:

{
	"Id":0,
	"IfDone":[
		{
			"Id":0,
			"Stop":{
				"Id":0,
				"Guaranteed":false,
				"TriggerPrice":null,
				"ExpiryDateTimeUTC":null,
				"Applicability":"gtc",
				"ParentOrderId":0,
				"TrailingDistance":10.0,
				"Associated":false,
				"Direction":"sell",
				"Quantity":1000
			},
			"Limit":{
				"Id":0,
				"Guaranteed":false,
				"TriggerPrice":106.31527,
				"ExpiryDateTimeUTC":null,
				"Applicability":"gtc",
				"ParentOrderId":0,
				"TrailingDistance":null,
				"Associated":false,
				"Direction":"sell",
				"Quantity":1000
			}
		}
	],
	"Direction":"buy",
	"ExpiryDateTimeUTCDate":null,
	"LastChangedDateTimeUTCDate":null,
	"OcoOrder":null,
	"Type":null,
	"ExpiryDateTimeUTC":null,
	"Applicability":"gtc",
	"TriggerPrice":106.31527,
	"BidPrice":106.251,
	"AuditId":"LJ40690714",
	"AutoRollover":false,
	"MarketId":401484414,
	"OfferPrice":106.262,
	"OrderId":0,
	"Currency":null,
	"Quantity":1000,
	"QuoteId":null,
	"LastChangedDateTimeUTC":null,
	"PositionMethodId":1,
	"TradingAccountId":"<removed id>",
	"MarketName":null,
	"Status":null,
	"isTrade":false,
	"Json":null
}

 

 

Here's my response:

{
	"Status":1,
	"StatusReason":1,
	"OrderId":754499310,
	"Orders":[
		{
			"OrderId":754499310,
			"StatusReason":1,
			"Status":3,
			"OrderTypeId":1,
			"Price":106.262,
			"Quantity":1000.0,
			"TriggerPrice":0.0,
			"CommissionCharge":0.0,
			"IfDone":[
				
			],
			"GuaranteedPremium":0.0,
			"OCO":null,
			"AssociatedOrders":{
				"Stop":{
					"OrderId":754497194,
					"StatusReason":1,
					"Status":2,
					"OrderTypeId":2,
					"Price":0.0,
					"Quantity":9000.0,
					"TriggerPrice":106.151000,
					"CommissionCharge":0.0,
					"IfDone":[
						
					],
					"GuaranteedPremium":0.0,
					"OCO":{
						"OrderId":754497195,
						"StatusReason":1,
						"Status":2,
						"OrderTypeId":3,
						"Price":0.0,
						"Quantity":9000.0,
						"TriggerPrice":106.31527,
						"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":754497195,
					"StatusReason":1,
					"Status":2,
					"OrderTypeId":3,
					"Price":0.0,
					"Quantity":9000.0,
					"TriggerPrice":106.31527,
					"CommissionCharge":0.0,
					"IfDone":[
						
					],
					"GuaranteedPremium":0.0,
					"OCO":null,
					"AssociatedOrders":{
						"Stop":null,
						"Limit":null
					},
					"Associated":true
				}
			},
			"Associated":false
		}
	],
	"Quote":null,
	"Actions":[
		{
			"ActionedOrderId":0,
			"ActioningOrderId":0,
			"Quantity":1000.0,
			"ProfitAndLoss":0.0,
			"ProfitAndLossCurrency":null,
			"OrderActionTypeId":1
		}
	],
	"ErrorMessage":null
}

 

The issue:

I am trying to open multiple positions (long and short) on the same market. Each of these new positions should have its own unique Stop/Limit with different trigger prices. 

What is happening now is that any position I open on the same market seems to get overridden by each other. For example:  if I open multiple short and long positions in the same Market--  they all seem to default to one position with the same limit and stop: 

image.thumb.png.b9e644d25883536b4624ef48159c2307.png

 

I am wondering what I am doing wrong with my request? 

 

Regards,

 

Rony

Share this post


Link to post

Hi Rony,

I have a couple of questions to help clarify the situation.

1) Do you have a US based account?

This is because US accounts cannot have simultaneous long and short open positions in the same market. This is a rule from the US regulator so is not something we can change.  

2) Are you trying to place an entry order to enter the market should it reach a certain trigger price, or are you trying to place a market order to trade immediately on whatever the current buy/sell price is?

You wrote you are sending to the /newtradeorder endpoint, which is for placing a market order trade to buy/sell immediately at market price. However, your request is structured as an entry order to buy when the market reaches a certain trigger price. Entry orders should be sent to the /newstoplimitorder endpoint instead.

NOTE: US accounts also cannot attach If/Done Stop or Limit orders to an entry order. Again this is a rule from the US regulator.

Kind Regards, PM

 

Share this post


Link to post

Hello PM,

1) Do you have a US based account?

Yes, I do -- I guess that's that. 

2) Are you trying to place an entry order to enter the market should it reach a certain trigger price, or are you trying to place a market order to trade immediately on whatever the current buy/sell price is?

I am trying to place a market order to trade immediately. What changes should I make to my request? Should I remove the trigger price?

NOTE: US accounts also cannot attach If/Done Stop or Limit orders to an entry order. Again this is a rule from the US regulator.

I am still allowed to attach If/Done order to a market order, correct?

 

Thank you,

 

Rony

Share this post


Link to post

Hi Rony,

Yes, mainly removing the TriggerPrice field. The list of permissable fields for a market order (trade) request is detailed at http://docs.labs.gaincapital.com/#Data Types/NewTradeOrderRequestDTO.htm. I've pasted an example below.

Yes, US clients can send a market order (trade) request with attached stops and limits as I have done in the example below.

Kind Regards, PM

{
    "MarketId": 400723798,
    "Direction": "buy",
    "Quantity": 1000,
    "BidPrice": 106.174,
    "OfferPrice": 106.204,
    "AuditId": "ELU17236432",
    "TradingAccountId": 401843563,
    "PositionMethodId": 1,
    "IfDone": [
        {
            "Stop": {
                "OrderId": null,
                "Direction": "sell",
                "Applicability": "gtc",
                "ExpiryDateTimeUTC": null,
                "Guaranteed": false,
                "TrailingDistance": 10,
                "Quantity": 1000,
                "TriggerPrice": null,
                "IfDone": [],
                "OcoOrder": null
            },
            "Limit": {
                "OrderId": null,
                "Direction": "sell",
                "Applicability": "gtc",
                "ExpiryDateTimeUTC": null,
                "Quantity": 1000,
                "TriggerPrice": 106.704,
                "IfDone": [],
                "OcoOrder": null
            }
        }
    ],
    "Reference": "Origin601"
}

 

Share this post


Link to post

Hi,

It is described in the list of fields at the link I posted previously. 

The "Reference" field is a code to identify the source origin of the trade order request. I would suggest using your API Key as the reference string, or you could tag your request as "GCAPI" to show it is an API request.

Origin601 is an internal reference.

Kind Regards, PM

Share this post


Link to post

I read the description from the link but still wasn't entirely sure. Thanks for the quick response!

Is it possible to have multiple  market order (trade) requests with attached stops/limits (each with unique trigger values) on the same market?

 

Thanks in advance,

 

Rony

Share this post


Link to post

Hi Rony,

For US clients that use what are called "associated" stops/limits, the values of stops/limits cannot be different for each of your trades in the same market. When you place the 2nd or subsequent trade with stop/limits, these will replace/overwrite the previous stops/limits you have set. 

Again, this is unfortunately due to specific US NFA regulations.

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  
×