Close a futures position, or flatten the account
https://app.skylit.ai/api/nexus/v1/trading/accounts/{account}/closeSend ticker to close one position at market, or "closeAll": true to flatten every position in the account. Not both. A close works on a quiet price, and it's the same close as the Flatten button in Nexus.
Nothing to close answers 200 with an empty closed list and meta.nothingToClose: true. If closeAll closes some positions and fails on one, the error says how many closed and which is still open. Send it again (with a new clientOrderId if you sent one). A repeated closeAll id returns what already closed, plus meta.stillOpen if anything is.
Authorization
Authorization: Bearer <your API key>Required. A missing header returns 401; an invalid, revoked or expired key returns 403.
Path parameters
accountstringrequiredpractice,evaluationorfunded(when you have exactly one running), or a futures account id from capabilities.
Headers
Idempotency-KeystringYour
clientOrderId, as a header instead of a body field. If you send both they must match.
Request body
tickerstringThe position to close, like
NQorNQZ26.closeAllbooleantrueflattens every position in the account.clientOrderIdstringYour own id for safe retries.
testbooleantruepreviews the close against what the account really holds, and places nothing.
Responses
- 200
What closed.
- 400
The request was refused before anything was traded. Codes:
bad_request,bad_contract,invalid_quantity,invalid_price,unsupported_asset_class,unsupported_order_type,only_market_orders,test_orders_unavailable,test_modify_unavailable. - 401
No key, or a key that isn't valid. Codes:
missing_api_key,invalid_api_key. - 403
The key works but the account can't do this. Codes:
account_suspended,nexus_access_denied,futures_access_denied. - 404
Not on your account. Codes:
trade_not_found,account_not_found,order_not_found. - 409
The order clashes with what you hold or sent before. Codes:
duplicate_position(withtradeId),trade_closed,open_position_limit,client_order_id_used,request_in_progress,account_locked,account_busy,account_ended,order_not_working. - 422
Read fine, but the market or the account says no. Codes:
market_closed,contract_expired,contract_not_offered,price_outside_market,insufficient_buying_power,account_not_tradable,account_ambiguous,reduce_only_would_open,order_refused. - 429
Over a rate limit. Wait
Retry-Afterseconds, then retry. Code:rate_limited. - 500
Something went wrong on our side. If you sent a
clientOrderId, retry with the same one. Code:internal_error. - 503
Try again in a moment (honour
Retry-Afterwhen it's sent). Codes:stale_quote,no_live_price,rules_pending,unavailable,auth_unavailable,access_check_unavailable,api_keys_unavailable,trades_api_disabled.
Response fields
dataobjectaccountobjectclosedobject[]
metaobjectExtra facts about an order. Each field is there only when it applies.
fillobjectThe fill:
price,priceSource(marketorclient), and when you sent a price, thebidandaskit was checked against. On an exit,quantityis how many sold.clientOrderIdstringidempotentReplaybooleanThis answer is a repeat of an earlier order with the same
clientOrderId.testbooleanA test order: nothing was placed.
notCheckedstring[]Futures test orders: what the preview couldn't check, like
account_rules_judgmentorbracket_netting.discordRoutingobjectWhere Nexus routed the trade to Discord, when it did.
nothingToClosebooleanstillOpenstring[]A repeated
closeAll: positions still open.
Last updated