Jump to content
Sign in to follow this  
Vincent

Close an open position

Recommended Posts

Hello Vincent,

 

I assume your question meant which API *command* to use in closing a trade, rather than which API in general to use??  ;)

 

You still use the Trade command (POST newtradeorder), but this time in the requesting NewTradeOrderDTO you fill in the Close property with the opening OrderId. You also set the trade direction to the opposite of your existing open position that you are closing. 

 

Note: you can partially close your position provided that the closing size and the position size you leave open are both greater than the minimum trade size. You can find the minimum trade size for each market by looking in the market information for that market. 

 

Essentially the flow is:

 

1) Open a trade using the Trade command leaving all Order ID fields empty as this is a new opening trade. For example a Buy trade. 

 

2) Use ListOpenPositions to retrieve a list of all your open positions including the new trade and the Order IDs for each open position.

 

3) Use the Trade command again and in the requesting NewTradeOrderDTO you also set the Close property containing the Order ID of the position you want to close. Set trade direction to Sell in this example. 

 

 

 

 

 

 

 

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  
×