Skip to main content

Partially Close Positions

API URL: POST https://api.topstepx.com/api/Position/partialCloseContract

API Reference: /api/Position/partialCloseContract

Description


Partially close a position.

Parameters


NameTypeDescriptionRequiredNullable
accountIdintegerThe account ID.Requiredfalse
contractIdstringThe contract ID.Requiredfalse
sizeintegerThe size to close.Requiredfalse

Error Codes


errorCodeNameMeaning
0SuccessThe closing order was executed.
1AccountNotFoundThe account does not exist or is not owned by the caller.
2PositionNotFoundNo open position exists for the account and contract.
3ContractNotFoundThe contract ID is not recognized.
4ContractNotActiveThe contract is not the currently active contract.
5InvalidCloseSizeThe size is zero, negative, or larger than the open position.
6OrderRejectedThe closing market order was rejected. See below.
7OrderPendingThe closing order is still being processed.
8UnknownErrorAn unexpected error occurred.
9AccountRejectedThe account is not allowed to close positions (live accounts).

errorCode 6 (OrderRejected)

This code is returned for more than one reason:

  • Trading is not allowed for the symbol. The market is closed, halted, or otherwise not tradable at the moment of the request. The closing order is recorded as rejected for being outside trading hours.
  • No current price is available for the contract. The engine could not resolve a price to execute the close. The closing order is recorded as rejected with an invalid price.

In both cases errorMessage is null, so the response alone does not indicate which cause applied. Retry once the market is open and quoting.

Example Usage


Example Request

curl -X 'POST' \
'https://api.topstepx.com/api/Position/partialCloseContract' \
-H 'accept: text/plain' \
-H 'Content-Type: application/json' \
-d '{
"accountId": 536,
"contractId": "CON.F.US.GMET.J25",
"size": 1
}'

Example Response

{
"success": true,
"errorCode": 0,
"errorMessage": null
}