Jump to content
Sign in to follow this  
smironov

How do I close a trade?

Recommended Posts

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

Just to clarify Say I have 3 trades in a certain market – they have been opened in the order (oldest to newest) pos1, pos2, pos3

Can I specifically close pos2?

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

@yarane Yes you can, just put the order id of pos2 into the close field. Just make sure to wrap it with square brackets as the field is an int array.

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

I get

 ‘{“OrderId”:0,“Orders”:[],“Quote”:{“QuoteId”:401327156,“Status”:1,“StatusReason”:7},“Status”:3,“StatusReason”:96}’

 response but the trade I tried to close still alive.

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

@smironov Your close request has generated a quote. If you subscribe to the quote stream then you’ll get a streamed notification when the quote changes state, which you can present to the client.

The quote is sent to the dealers for approval. Since you are connecting to a preprod environment, there are no dealers watching the approval console so the quote will stay there and the trade won’t get closed.

Looking at your response (StatusReason 96, quote has been generated), your close request has been processed correctly. At this point there’s not much more you can do in the preprod environment other than presenting the quote status.

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

How do I close a trade with stop and limit attached? Same approach as if I close a single trade (specifying it’s id in “close” field) doesn’t work. Do I have to delete orders before close trade or there is a way to do all it in one request?

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

@smironov Just pass the trade id in the close field, with the full quantity. The attached orders (stop and/or limit), will then be removed.

Share this post


Link to post

Trades are executed in a FIFO manner. You send a new trade request (populating the Close field, which is an array of order id’s to close). You also need to switch the direction and specify the quantity to close.

@wilsoncg Unfortunatelly it doesn’t want to close. I get StatusReason=75 which says something about quantity but I didn’t say anything about quantity, I simply passed trade’s id to new trade request. That works well for trades without ifDone orders.

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  
×