Jump to content
zedd

order/newtradeorder documentation is not clear

Recommended Posts

Dear PM! 

I'm trying to implement order/newtradeorder and i have a problem in interpreting response:

{
	"Status":2,
	"StatusReason":75,
	"OrderId":0,
	"Orders":[
		{
			"OrderId":0,
			"StatusReason":158,
			"Status":10,
			"OrderTypeId":1,
			"Price":0,
			"Quantity":1000,
			"TriggerPrice":0,
			"CommissionCharge":0,
			"IfDone":[],
			"GuaranteedPremium":0,
			"OCO":null,
			"AssociatedOrders":{"Stop":null,"Limit":null},
			"Associated":false
		}
	],
	"Quote":null,
	"Actions":[],
	"ErrorMessage":null
}

When i open the docs for http://docs.labs.gaincapital.com/#HTTP Services/Trade.htm%3FTocPath%3DCIAPI%20Reference|HTTP%20Services|Trades%20and%20Orders|_____16,
I have links to ApiTradeOrderResponseDTO and ApiOrderResponseDTO

Each DTO has Status and StatusReason fields descriptions which leads to Lookup Values page.
I can assume that Status and StatusReason fields of ApiOrderResponseDTO are related to OrderStatus Codes and OrderStatusReason Codes of lookup values.
And do i understand correctly that Status and StatusReason fields of ApiTradeOrderResponseDTO are related to InstructionStatus Codes and InstructionStatusReason Codes of lookup values? 
Additionally it would be nice to make Documentation more clear for understanding.

Thank you very much
Cheers
zedd

Share this post


Link to post

Hi Zedd,

You are correct, ApiTradeOrderResponseDTO contains the InstructionStatus and InstructionStatusReason codes, while ApiOrderResponseDTO carries the OrderStatus and OrderStatusReason codes. 

Specifically in this case, the reason your trade request failed is because the market price had moved greater than your price tolerance level. The default value for price tolerance is 2, unless you have manually over-ridden it. 

The section on "Trading Status Codes & Error Messages" in the topic: Usage Notes: Messages & Errors, explains in more detail to try and clarify this subject. It may be time to revise parts of the API documentation to better explain to the user. A note has been made to improve this in a future iteration of the documentation.

Many thanks for your suggestion on improving the explanatory text - we appreciate that. :)

Kind Regards, PM

 

Share this post


Link to post

Hi PM,

Thank you for response.

Currently i use this json to create new position with market price:

{
	"ifDone": [],
	"marketId": position.MarketId,
	"direction": position.Direction,
	"quantity": position.Quantity,
	"bidPrice": currentPrices[position.MarketId].bid,
	"close": [],
	"offerPrice": currentPrices[position.MarketId].offer,
	"tradingAccountId": position.TradingAccountId,
	"orderId": 0
}

Do i understand correctly that if i remove bidPrice and offerPrice then i'll avoid getting exceeded price tolerance level errors? Should my json request body be like this then?

{
	"ifDone": [],
	"marketId": position.MarketId,
	"direction": position.Direction,
	"quantity": position.Quantity,
	"close": [],
	"tradingAccountId": position.TradingAccountId,
	"orderId": 0
}

Best regards
zedd

Share this post


Link to post

Hi Zedd,

Not quite. The Price Tolerance setting (default = 2), specifies how much slippage you are willing to tolerate to get a trade placed. According to the StatusReason = 158 you pasted in yoru original post, this was due to the price tolerance being exceeded. 

This means that for the market you were trying to trade, the market price has moved more than 2 points since the time you attempted to place the trade. This should usually only occur in very fast moving markets. If you are consistently receiving this error message I think that there is another problem happening. 

I have a couple of questions:

1) Were you in the past able to place trades in this market with this account?

2) Have you changed your code recently?

3) Are you reading in the current live streaming bid and offer prices using Lightstreamer? 

4) Please post the entirety of the JSON code you are using to place this trade. I can examine and see if I can spot any errors there.

Kind Regards, PM

Share this post


Link to post

1) Yes, in the past i was able to successfully place trades
2) No, this code was not modified recently
3) Yes, i'm reading current lightstreaming bid and offer prices and store them in currentPrices map You can see this from my previous message.
4) Unfortunately i didn't log request body but i don't think there is some errors in there because it was working another time. Additionally i noticed the same error in webtrader2 platform.

I don't really think this is critical issue for me because i can retry this couple of times to successfully create new order. I just through that i could avoid this price tolerance errors somehow.

Best regards
zedd

Share this post


Link to post

Hi Zedd,

You can reduce the frequency of the price tolerance error occurring by increasing the price tolerance value. There is a drawback in that this could potentially increase the slippage during fast markets should your trade be executed.

The only reason I was suspicious of what is the root cause of the error is because you are seeing this error repeatedly even though you have made attempts at different times. Not sure which market you are trading but I didn't see any fast markets in any of the major indices or currencies yesterday. If everything is working your trades should have gone through.

Please keep us updated and we can investigate further if your're still encountering this problem.

Kind Regards, PM

Share this post


Link to post

Would you mind elaborating how to increase the price tolerance value? (I looked through the documentation, and it only seems to tells me that I'm getting a red card error, and I'm not sure what that means.

The output I'm getting is similar to Zedd's, but not identical:

{'Status': 2, 'StatusReason': 75, 'SimulatedCash': 0.0, 'ActualCash': 0.0, 'SimulatedTotalMarginRequirement': 0.0, 'ActualTotalMarginRequirement': 0.0, 'CurrencyId': 0, 'Orders': [{'StatusReason': 160, 'Status': 10}]}

We have yet to successfully place a simulated trade order, and any pointers on how to fix this problem would be much appreciated.

Thanks, Eric

Share this post


Link to post

Hi Eric, 

To change the Price Tolerance for a market, use the SaveMarketInformation call: http://docs.labs.gaincapital.com/#HTTP Services/SaveMarketInformation.htm.

NOTE: Price Tolerance settings are per individual market.

The API Error Codes can be looked up from the API documentation page: http://docs.labs.gaincapital.com/#APICodesList.htm%3FTocPath%3DGetting%20Started|Lookup%20Values|_____1

The OrderStatusReason of 160 you are receiving means you are attempting to place a trade or order on a marker that is not available to your account. 

Try following the Find Market ID instructions at: http://docs.labs.gaincapital.com/#How Do I/Find Market ID.htm%3FTocPath%3DHow%20Do%20I...%3F|_____1.  The response will only show you markets available to your account so you will have the valid Market ID to use in your call.

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
×