Jump to content
Sign in to follow this  
danilo

How to place market order

Recommended Posts

Hi All

My requirement is to place an trade which gets executed at current price. I do not see such api and have to specify some values along with price tolerance. On running I can see an open position but it do not execute.

 

Can you help me with 

a) is there any API which places market order (trade) at current price.

B) If not available then how to place a trade with specified values. If value matches trade executes else cancels it.

 

I am using /order/newtradeorder API

Sample Request/Response  below -

 

 

{"IfDone":[],"Direction":"sell","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,"OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":null,"AuditId":"e5b8b0f3-633b-480d-8744-0d9798b55257","AutoRollover":false,"MarketId":154290,"OrderId":0,"Currency":null,"Quantity":10,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId":1,"TradingAccountId":1234,"MarketName":"XYZ","Status":null,"isTrade":true,"OfferPrice":1.1077,"BidPrice":null,"PriceTolerance":5}
 
 
{"Status":1,"StatusReason":1,"OrderId":570670750,"Orders":[{"OrderId":570670750,"StatusReason":1,"Status":3,"OrderTypeId":1,"Price":1.10756,"Quantity":10,"TriggerPrice":0,"CommissionCharge":0,"IfDone":[],"GuaranteedPremium":0,"OCO":null,"AssociatedOrders":{"Stop":null,"Limit":null},"Associated":false}],"Quote":null,"Actions":[{"ActionedOrderId":570670750,"ActioningOrderId":570670750,"Quantity":10,"ProfitAndLoss":0,"ProfitAndLossCurrency":null,"OrderActionTypeId":1}],"ErrorMessage":null}
 
In response I can see "OrderActionTypeId":1 which means order is in opening state and that I can see on web interface too.
 
Thanks  
 
 
 

 

Share this post


Link to post

Hi Danilo,

 

To place a trade at current price (a market order) you are using the correct API call - Trade (/newtradseorder). The values of offer and bid price you enter when making this call should be the current market price that you read from the LighStreamer subscription to the market prices stream. 

 

For your second query, placing an entry order is accomplished with the Order call (/newstoplimitorder).

 

You can find examples of using both calls in the API documentation.

 

Kind Regards,

PM!

Share this post


Link to post

Thanks for your answer but I am using same  (/newtradseorder)  and the bid/offer price was taken from lightstreamer only.  It just lands up in Trade section and never executes. Can you please help me understansd what I am doing wrong

 

I am using /order/newtradeorder API

Sample Request/Response  below -

 

 

{"IfDone":[],"Direction":"sell","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,"OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":null,"AuditId":"e5b8b0f3-633b-480d-8744-0d9798b55257","AutoRollover":false,"MarketId":154290,"OrderId":0,"Currency":null,"Quantity":10,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId":1,"TradingAccountId":1234,"MarketName":"XYZ","Status":null,"isTrade":true,"OfferPrice":1.1077,"BidPrice":null,"PriceTolerance":5}
 
 
{"Status":1,"StatusReason":1,"OrderId":570670750,"Orders":[{"OrderId":570670750,"StatusReason":1,"Status":3,"OrderTypeId":1,"Price":1.10756,"Quantity":10,"TriggerPrice":0,"CommissionCharge":0,"IfDone":[],"GuaranteedPremium":0,"OCO":null,"AssociatedOrders":{"Stop":null,"Limit":null},"Associated":false}],"Quote":null,"Actions":[{"ActionedOrderId":570670750,"ActioningOrderId":570670750,"Quantity":10,"ProfitAndLoss":0,"ProfitAndLossCurrency":null,"OrderActionTypeId":1}],"ErrorMessage":null}

Share this post


Link to post

Hi,

 

I only needed to make a few edits to your code in order to successfully place a trade.

 

  1. I entered the real TradingAccountId for the account I was using. Did you use the real ID in your call and you just replaced it with the dummy "1234" in this forum post?
  2. Your BidPrice is null - I entered a valid BidPrice in my call. 
  3. Are you using a CFD account? I'm using a Spreadbet only test account and it didn't recognise the MarketId you used. If you are using a CFD account and that is a CFD market then it should be fine. From the prices it looks like it is the EUR/USD market. I simply used the MarketId for the Spreadbet EUR/USD in my call.

Those changed were enough for me to successfully place the trade and for it to appear in my open positions. I used the Advantage Web platform to see the open position in my account.

doPost('/order/newtradeorder', {"IfDone":[],"Direction":"sell","ExpiryDateTimeUTCDate":null,"LastChangedDateTimeUTCDate":null,"OcoOrder":null,"Type":null,"ExpiryDateTimeUTC":null,"Applicability":null,"AuditId":"e5b8b0f3-633b-480d-8744-0d9798b55257","AutoRollover":false,"MarketId":400616149,"OrderId":0,"Currency":null,"Quantity":10,"QuoteId":null,"LastChangedDateTimeUTC":null,"PositionMethodId":1,"TradingAccountId":1234,"MarketName":"XYZ","Status":null,"isTrade":true,"OfferPrice":1.1060,"BidPrice":1.1040,"PriceTolerance":5}); 

Share this post


Link to post

Hi

do we need both bid and offer price? I think we should be needed only once based on the direction. Also With my call also I am able to see a open position in Advantage Web platform but it never executes. I saw that even if it the price matches it doesn't execute.

 

My requirement is that if it finds the value (+- price tolerance) at the time of trade order placed, it executes else it cancels.

 

Thanks

Share this post


Link to post

Hello,

 

I'd like to clarify: the (/newtradeorder) command is placing a trade at market immediately. That is why you see an open position in the Open Positions panel of Advantage Web. 

 

It sounds like you are looking for a "fill or kill" (with price tolerance) type order? Our system does not support the sort of order you are looking for unfortunately.

 

Kind Regards,

PM! 

Share this post


Link to post

Okay but even if it places trade, I want to know when actually it gets execute. It always stays in there for me. 

 

Also what is the purpose of price tolerance. Does it work in both (+ 0-) direction. Any plans to support kill or fill feature?

 

Thanks

Share this post


Link to post

I don't understand what you mean by "it always stays in there for me"?

 

If you successfully place a trade using (/newtradeorder) you should have a new open position showing in your Open Positions panel. If the trade attempt was unsuccessful you would receive back an error code.

Are you seeing the trade order itself just sit there with no trade placed or no error message for a failed trade attempt?

 

Price tolerance enables you to define the amount of possible slippage you are willing to accept in getting a trade done. As an example price tolerance = 2, market sell price = 10, and buy price = 12. You click to sell at 10. The trade is accepted if our sell price is 8 or higher at the time the trade is received at our servers. If the price is 7 or lower then the trade is refused,

 

You can get a fill or kill trade by setting the price tolerance to 0. 

 

Kind Regards,

PM!

Share this post


Link to post

What I mean by order stays there is that I can see one open position and on trade order in (Opening) state. Setting price tolerance to 0 will not open position?  

Share this post


Link to post

Thanks for the clarification I can see where the confusion is now.

 

The OrderActionTypeId is a description of the order, it is not the current state of the order.

You have sent an order to place a trade - the trade is accepted and you have 1 open position. The OrderActionTypeId describes what the order you sent is - it is an Opening Order (used to open your trade).

When you fully close the trade - the OrderActionTypeId will be 2 meaning "Full Close".

 

The OrderActionTypeId is used in our trading platform Trade History panel in the Type column. If you open and close some trades using for example the Web platform, you can see in the Trade History Types column "Opening" and "Closing" as the description for the trade orders.

 

When you set price tolerance = 0, then a trade order will open a position only if the market price has not moved during the time it took for your order to transmit to our servers. If the price has changed during the time it took for your order to travel from your computer to our servers, then the trade is rejected.

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  
×