Nexus/API Reference/Options and stocks

Trim or close an options or stock trade

POSThttps://app.skylit.ai/api/nexus/v1/trades/{id}/exits

Sell 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

  • idstringuuidrequired

    The trade's id, from the open or the list.

Headers

  • Idempotency-Keystring

    Your clientOrderId, as a header instead of a body field. If you send both they must match.

Request body

  • quantityinteger

    How many to sell, 1 or more.

  • closeAllboolean

    true sells everything that's left.

  • pricenumber

    Your own fill price, inside the window.

  • ifOutsidestring

    What happens when price is outside the window.

    rejectmarket
  • orderTypestring

    limit closes at your price. stop closes a stock when it trades through stopPrice, or arms an options stop on the stock's price.

    marketlimitstop
  • limitPricenumber

    A limit exit: the least you'll take per contract or share (the most you'll pay to cover a short).

  • stopPricenumber

    A 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.

  • timeInForcestring

    Limit and stock stop exits. An options stop stays on until it fires, you cancel it, or the contract expires, so it takes none.

    daygtc
  • stopLossnumber

    Options only: the stock price your stop fires at. On a call it sits under the stock's price, on a put over it.

  • takeProfitnumber

    Options only: the stock price your target fires at. With stopLoss it's one bracket order.

  • clientOrderIdstring

    Your own id for safe retries.

  • testboolean

    Optional. The trade decides: a test order's exit is always a test.

Responses

  • 200

    The trade with its new exit. meta.fill.quantity is 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 no limitPrice), 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 no stopPrice), 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 (with tradeId: 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; orderId points to it). A resting order that can't be covered answers insufficient_buying_power with orderId too: it's recorded as rejected.

  • 429

    Over a rate limit. Wait Retry-After seconds, then retry. Codes: rate_limited, and stream_limit_reached (too many live streams open: 3 per key, 6 per account).

  • 503

    Try again in a moment (honour Retry-After when 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

  • dataobject

    An options or stock trade, as Nexus shows it. Stocks use direction call for long and put for short, strike 0 and today's date. Nexus may add other fields it shows on a trade (Greeks, P/L, reactions).

    • idstringuuid
    • userIdstringuuid
    • tickerstring
    • strikenumber
    • expirationstringdate
    • directionstring
      callput
    • assetClassstring
      optionsstocks
    • averageEntryPricenumber
    • currentPricenumber

      The latest mark.

    • totalQuantityinteger
    • remainingQuantityinteger
    • statusstring
      activeclosed
    • entryDatestringdate-time
    • exitDatestringdate-time
    • exitsobject[]
    • sourcestring

      api on a trade a key opened.

    • testboolean

      true on a test order.

  • metaobject

    Extra facts about an order. Each field is there only when it applies.

    • fillobject

      The fill: price, priceSource (market or client), and when you sent a price, the bid and ask it was checked against. On an exit, quantity is how many sold.

    • clientOrderIdstring
    • idempotentReplayboolean

      This answer is a repeat of an earlier order with the same clientOrderId.

    • testboolean

      A test order: nothing was placed.

    • notCheckedstring[]

      Futures test orders: what the preview couldn't check, like account_rules_judgment or bracket_netting.

    • discordRoutingobject

      Where Nexus routed the trade to Discord, when it did.

    • nothingToCloseboolean
    • stillOpenstring[]

      A repeated closeAll: positions still open.

    • tradeIdstringuuid

      A resting exit or an options stop: the trade it closes or protects.

    • triggerOnstring

      An options stop: underlying.

    • underlyingPricenumber

      An options stop: the stock's price right now.

    • marketOpenboolean

      An options stop: whether the market's open for the contract.

    • firesNowboolean

      An options stop: the stock's already through a level, so it fires on the next check. firesOn says which leg.

    • wouldFireNowboolean

      A test options stop: what firesNow would say.

    • wouldFillNowboolean

      A test limit: whether the real one would've filled right away, with fillPrice.

    • wouldTriggerNowboolean

      A test stock stop: the last trade's already through it.

    • wouldRestBecausestring

      A test limit: why the real one would rest.

    • alreadyCancelledboolean

      A repeated cancel: it was already cancelled.

Last updated

Was this page helpful?