Trim or close an options or stock trade
https://app.skylit.ai/api/nexus/v1/trades/{id}/exitsSell part of a trade with quantity, or all of what's left with "closeAll": true. Not both. Fills at market (the live bid for options), or at your own price inside the window, as on an open. On a short stock trade an exit buys it back.
Close at your price. "orderType": "limit" with limitPrice (the least you'll take, or the most you'll pay to cover a short) rests until the market gets there: an option fills at your limit when the bid comes up to it (at the bid right away if it's already there). A stock also takes "orderType": "stop" with stopPrice. Add timeInForce for gtc. It answers 201 with the order and meta.tradeId. You can't close more than the trade holds (400 invalid_quantity), and if you hold the same contract on more than one trade in that wallet, the fill closes the oldest first.
Protect an options trade. Send stopLoss, takeProfit or both. They're prices of the stock, not the option: a stop at 585 on an SPY call fires when SPY trades at or under 585. On a call the stop sits under the stock's price and the target over it, on a put the other way round. Both together are one bracket order: whichever the stock reaches first fires and the other goes with it. When a level hits, the covered contracts sell at the market, at the option's live bid. With no live quote (nothing in the last 15 seconds) nothing sells and it tries again a few seconds later. It stays on until it fires, you cancel it, or the contract expires, so it takes no timeInForce. "orderType": "stop" with stopPrice works too, the same as stopLoss alone. It answers 201 with the order (orderType stop, take_profit or bracket, "triggerOn": "underlying"). meta.underlyingPrice is the stock's price now, and meta.firesNow: true means it's already through a level and fires on the next check. A stop goes on a trade you hold, never on an entry.
On a test order's id this is a test exit, whatever the body says. Futures have no exits: close a futures position with the account close route.
Authorization
Authorization: Bearer <your API key>Required. A missing header returns 401; an invalid, revoked or expired key returns 403.
Path parameters
idstringuuidrequiredThe trade's id, from the open or the list.
Headers
Idempotency-KeystringYour
clientOrderId, as a header instead of a body field. If you send both they must match.
Request body
quantityintegerHow many to sell, 1 or more.
closeAllbooleantruesells everything that's left.pricenumberYour own fill price, inside the window.
ifOutsidestringWhat happens when
priceis outside the window.rejectmarketorderTypestringlimitcloses at your price.stopcloses a stock when it trades throughstopPrice, or arms an options stop on the stock's price.marketlimitstoplimitPricenumberA limit exit: the least you'll take per contract or share (the most you'll pay to cover a short).
stopPricenumberA stop exit. On a stock, the stock price that sets it off. On an option, the stock price the stop fires at, the same as
stopLoss.timeInForcestringLimit and stock stop exits. An options stop stays on until it fires, you cancel it, or the contract expires, so it takes none.
daygtcstopLossnumberOptions only: the stock price your stop fires at. On a call it sits under the stock's price, on a put over it.
takeProfitnumberOptions only: the stock price your target fires at. With
stopLossit's one bracket order.clientOrderIdstringYour own id for safe retries.
testbooleanOptional. The trade decides: a test order's exit is always a test.
Responses
- 200
The trade with its new exit.
meta.fill.quantityis how many this exit sold. - 201
A resting exit: a limit or stop to close, or an options stop-loss and target. The order, with
meta.tradeId. Manage it with the Options and stocks resting orders routes. - 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,limit_price_required(a limit with nolimitPrice),invalid_limit_price(not in cents, or outside 0.01 to 99,999.99 for options or 999,999.99 for stocks),stop_price_required(a stop with nostopPrice),invalid_stop_price(not in cents, or outside 0.01 to 999,999.99),invalid_take_profit,test_orders_unavailable,test_modify_unavailable. - 401
No key, or a key that isn't valid. Codes:
missing_api_key,invalid_api_key. - 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: add to it instead),trade_closed,open_position_limit(open positions plus resting opens through the API are at 50),working_order_limit(50 options and stock orders already resting through the API),position_size_limit(an add would take the position past 1,000 contracts or 100,000 shares),client_order_id_used,request_in_progress,account_locked,account_busy,account_ended,order_not_working(it already filled, expired, or was cancelled or rejected),stop_triggered(a stop that's been set off is filling now, so it can't be cancelled or changed). - 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,order_rejected(a resting order that tried to fill right away and couldn't;orderIdpoints to it). A resting order that can't be covered answersinsufficient_buying_powerwithorderIdtoo: it's recorded as rejected. - 429
Over a rate limit. Wait
Retry-Afterseconds, then retry. Codes:rate_limited, andstream_limit_reached(too many live streams open: 3 per key, 6 per account). - 503
Try again in a moment (honour
Retry-Afterwhen it's sent). Codes:stale_quote(the quote, or a stock's last trade, is more than 15 seconds old, so nothing filled),no_live_price,rules_pending,unavailable,auth_unavailable,access_check_unavailable,api_keys_unavailable,trades_api_disabled,stream_unavailable(the live stream isn't on, or the server is restarting: try again shortly, or poll the reads).
Response fields
dataobjectAn options or stock trade, as Nexus shows it. Stocks use
directioncallfor long andputfor short, strike 0 and today's date. Nexus may add other fields it shows on a trade (Greeks, P/L, reactions).idstringuuiduserIdstringuuidtickerstringstrikenumberexpirationstringdatedirectionstringcallputassetClassstringoptionsstocksaverageEntryPricenumbercurrentPricenumberThe latest mark.
totalQuantityintegerremainingQuantityintegerstatusstringactiveclosedentryDatestringdate-timeexitDatestringdate-timeexitsobject[]sourcestringapion a trade a key opened.testbooleantrueon a test order.
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.tradeIdstringuuidA resting exit or an options stop: the trade it closes or protects.
triggerOnstringAn options stop:
underlying.underlyingPricenumberAn options stop: the stock's price right now.
marketOpenbooleanAn options stop: whether the market's open for the contract.
firesNowbooleanAn options stop: the stock's already through a level, so it fires on the next check.
firesOnsays which leg.wouldFireNowbooleanA test options stop: what
firesNowwould say.wouldFillNowbooleanA test limit: whether the real one would've filled right away, with
fillPrice.wouldTriggerNowbooleanA test stock stop: the last trade's already through it.
wouldRestBecausestringA test limit: why the real one would rest.
alreadyCancelledbooleanA repeated cancel: it was already cancelled.
Last updated