Cancel all and Place new order

Hi,

Is any api end point helps to achieve the following steps in one call.

  1. cancel all if any open position exists
  2. open new position

And I see from other post that liquidatePosition cancels all open position, what is contract id here?

liquidatePosition will attempt to flatten your position for the contract with ID contractId, provided you have a position open for that contract. There isn’t a way to liquidate your positions in one single call. To liquidate all open positions you’d need to find what contracts you have positions open for - I’d use /position/list to find your positions, then iterate over each position and call the liquidatePosition endpoint with the contractId that matches the contractId field in the given position.

In the web, we have feature called “exit at market and cancel all” to flatten the position. is that equivalent api end point is ‘liquidatePosition’ or is any other end point exists?

When you click that button, it causes this flow to happen:

  • Trader app iterates over all of your positions.
  • Use the netPos field to find any position that isn’t flat; save the contractId field from the non-flat position.
  • Call the liquidatePosition API operation with the contractId's of any non-flat positions found.

Thank you Alexander!

Regarding liquidatePosition endpoint, I keep receiving Error 401 (Access is Denied). Tried multiple permutations and combinations of Api Key access but no use.

In my client’s account, positions have “Read Only Access”. Is that causing the problem?

Edit:

Got it to work!

Just had to use following body

{
“accountId”:123456,
“contractId”: 654321,
“admin”: false
}

how would you get the open positions for a specific ticker?