Development Guides

Option Trading Import – API Guide

Overview

The Option Import Trade API allows you to bulk-create option trades by uploading a spreadsheet containing option contract information. The system validates your data and creates orders in the order management system.

Important: This is a two-step process that requires using both API endpoints in sequence.

How It Works

The process follows these steps:

  1. Upload CSV File – Submit your spreadsheet with option trade information
  2. System Validates Data – The API checks portfolios, accounts, and data values
  3. Review Response – Examine validation results and identify any errors
  4. Create Valid Trades – Submit only the valid trades to create actual orders
  5. Receive Instance IDs – Get confirmation with instance IDs for tracking

API Endpoint 1: Upload Option Import File

Purpose

Uploads and validates a spreadsheet containing option trade information. Returns validated trade data that can be used to create actual orders.

Endpoint Information

Method: POST
URL: api/v2/OptionImport/uploadfile

Request Requirements

Headers Required:

  • Authorization: Bearer YOUR_TOKEN
  • Content-Type: multipart/form-data; boundary=YOUR_BOUNDARY_STRING

Body Format: Form data containing CSV file


CSV File Format

Your CSV file must include these columns in the header row:
Column NameDescriptionData TypeValid ValuesExample
Account Id or Account NumberThe account identifier (use one or the other)Integer or StringValid account ID or account number12345 or AN123
ActionTrade directionStringBUY or SELLBUY
Option QtyNumber of contractsIntegerPositive whole number10
Option PriceCurrent option priceDecimalNon-zero decimal84.52
Strike PriceOption strike priceDecimalNon-zero decimal165.00
Option Execution TypeContract actionStringOPEN or CLOSEOPEN
Option Maturity DateOption expiration dateDateFuture date10/06/2025
Option Parent ProductUnderlying security symbolStringValid ticker symbolAAPL
Option TypeType of optionStringCALL or PUTCALL

Sample CSV File

Account IdActionOption QtyPriceStrike PriceOption Execution TypeOption Maturity DateOption Parent ProductOption Type
123456BUY10$1.25$150.00OPEN06/21/2025AAPLCALL
123456SELL52.15400OPEN2025-06-21SPYPUT
78911SELL10$1.10250CLOSE06-21-2025TSLACALL
78910BUY50.75$90.00CLOSE06/21/2025MSFTPUT

What Gets Validate

The upload endpoint performs three levels of validation:

Portfolio Validation

  • Checks if portfolios associated with accounts need analytics run
  • Verifies portfolio configuration

Account Validation

  • Confirms account exists in the system
  • Validates account permissions and status

Data Validation

  • Verifies all required fields are populated
  • Confirms data types and formats are correct
  • Checks business rules (example: expiration date must be in the future)
  • Validates option quantities are whole numbers
  • Ensures actions are valid values (BUY/SELL, OPEN/CLOSE, CALL/PUT)

Important: What Is NOT Validated

You are responsible for ensuring accuracy of these values:

  • Option Price – The API confirms this is a non-zero decimal but does NOT verify it matches current market prices
  • Strike Price – The API confirms this is a non-zero decimal but does NOT verify this strike price exists in the option chain
  • Option Contract Existence – The actual option ticker will only be validated during the execution process

The API validates that your data is formatted correctly and follows business rules, but you must ensure the option details are accurate and correspond to real option contracts.


Upload Response Scenarios

Scenario 1: Portfolio Requires Analytics

When portfolios need analytics run before trading:

{
  "portfolioFlag": [
    {
      "portfolioId": 55501,
      "needAnalytics": true,
      "failedReason": null
    }
  ],
  "trades": null
}

What this means: You must run analytics on the specified portfolio(s) before you can create trades.


Scenario 2: Validation Errors Found

When there are issues with specific trades:

{
  "portfolioFlag": null,
  "trades": [
    {
      "accountId": 456,
      "contractName": null,
      "symbol": "AAPL",
      "tradeAction": 1,
      "last": 84.52,
      "optionType": 0,
      "contractAction": 0,
      "strike": 165.00,
      "expirationDate": "2025-10-06T00:00:00",
      "tradeToolSelection": 6,
      "optionTradeId": 45600001,
      "validateTradeDto": {
        "accountId": 456,
        "accountNumber": "AN123",
        "warningMessage": "The provided Account does not exist.\nCannot purchase expired contract\n",
        "symbol": "AAPL",
        "action": "BUY",
        "isValid": false
      },
      "shareQty": 1000,
      "optionQty": 10
    }
  ]
}
Key Field: validateTradeDto.isValid - When this is false, the trade cannot be created. Check the warningMessage field for details about what failed validation.

Scenario 3: All Validations Pass

When all trades pass validation successfully:

{
  "portfolioFlag": null,
  "trades": [
    {
      "accountId": 456,
      "contractName": "@AAPL 251006C00165000",
      "symbol": "AAPL",
      "tradeAction": 1,
      "last": 84.52,
      "optionType": 1,
      "contractAction": 1,
      "strike": 165.0,
      "expirationDate": "2025-10-06T00:00:00",
      "instanceNotes": "",
      "tradeToolSelection": 6,
      "optionTradeId": 31700001,
      "validateTradeDto": {
        "accountId": 456,
        "accountNumber": "HTP.52",
        "securityId": 58,
        "symbol": "AAPL",
        "custodianId": 2,
        "custodian": "Schwab",
        "action": "BUY",
        "orderStatus": "Not sent",
        "warningMessage": "",
        "isEnabled": true,
        "tradeShares": 10.0,
        "isValid": true
      },
      "shareQty": 1000,
      "optionQty": 10
    }
  ]
}

Key Field: validateTradeDto.isValid – When this is true, the trade can be passed to the Save Option Trades endpoint.


Understanding the Response Fields

Critical Fields

FieldLocationDescriptionImportance
isValidvalidateTradeDto.isValidBoolean indicating if trade can be createdCRITICAL – Only trades with true can proceed
warningMessagevalidateTradeDto.warningMessageDescription of any validation errorsExplains why validation failed
contractNameRoot levelGenerated option contract identifierRequired for creating the trade

Additional Response Fields

FieldDescription
accountIdAccount identifier from CSV file
symbolUnderlying security symbol
tradeActionNumeric code for trade action (1 = Buy, 2 = Sell)
optionTypeNumeric code for option type (1 = Call, 0 = Put)
contractActionNumeric code for contract action (1 = Open, 0 = Close)
strikeStrike price provided on CSV file
expirationDateOption expiration date in ISO format
last‘Option Price’ provided on CSV file
optionQtyNumber of contracts
shareQtyNumber of shares (contracts × 100)

API Endpoint 2: Save Option Trades

Purpose

Creates actual option trade orders in the order management system using validated trade data from the upload endpoint.

Important: Only use this endpoint with trades where isValid is true from the upload response.

Endpoint Information

Method: POST
URL: api/v2/OptionTrading/SaveOptionTrades

Request Requirements

Headers Required:

  • Authorization: Bearer YOUR_TOKEN
  • Content-Type: application/json

Body Format: JSON array of trade objects


Request Body Format

Send an array of trade objects. Each object must contain the following fields:

[
  {
    "accountId": 456,
    "contractAction": 1,
    "contractName": "@AAPL 251006C00165000",
    "currentOptionQty": null,
    "expirationDate": "2025-10-06T00:00:00",
    "instanceNotes": "",
    "last": 84.52,
    "optionQty": 10,
    "optionType": 1,
    "selected": true,
    "strike": 165.0,
    "symbol": "AAPL",
    "tradeAction": 1,
    "tradeToolSelection": 6
  }
]

Request Field Requirements

FieldTypeRequiredDescriptionSource
accountIdIntegerYesAccount identifierFrom upload response
contractActionIntegerYesContract action code (1=Open, 0=Close)From upload response
contractNameStringYesOption contract identifierGenerated by upload endpoint
currentOptionQtyInteger/NullNoCurrent option quantityCan be null
expirationDateDateTimeYesOption expiration dateFrom upload response
instanceNotesStringNoNotes for this tradeCan be empty string
lastDecimalYesOption priceFrom upload response
optionQtyIntegerYesNumber of contractsFrom upload response
optionTypeIntegerYesOption type code (1=Call, 0=Put)From upload response
selectedBooleanYesSelection flagTrue
strikeDecimalYesStrike priceFrom upload response
symbolStringYesUnderlying security symbolFrom upload response
tradeActionIntegerYesTrade action code (1=Buy, 2=Sell)From upload response
tradeToolSelectionIntegerYesTool selection codeAlways use 6 for import tool

Additional Validation Performed

The Save Option Trades endpoint performs deeper validation before creating orders:

Preference Validation

  • Checks account preferences and trading restrictions
  • Validates against parent security settings

Security Validation

  • Ensures underlying security is tradeable for the account
  • Verifies account is not overbought or oversold
  • Performs same validation as standard equity trades

Order Creation

  • Generates trade orders in the order management system
  • Returns instance IDs for tracking

Save Trades Response

The endpoint returns an integer representing the instance ID of the created trade:

31700001

What this means: Your trade order has been successfully created and assigned this instance ID

If you submit multiple trades in the array, you will receive multiple instance IDs corresponding to each trade in your request.


Step-by-Step Workflow

Step 1: Prepare Your CSV File

Create a CSV file with all required columns and your option trade data.

Step 2: Upload File to Validation Endpoint

  • Submit your CSV file to api/v2/OptionImport/uploadfile
  • Include proper authorization headers

Step 3: Check for Portfolio Flags

  • If portfolioFlag is returned with needAnalytics: true, you must run analytics on those portfolios before proceeding
  • Cannot create trades until analytics are complete

Step 4: Review Validation Results

  • Examine each trade in the trades array
  • Review warningMessage for any trades where isValid = false

Step 5: Filter Valid Trades

  • Select only trades where isValid = true
  • Do NOT attempt to create trades where isValid = false

Step 6: Prepare Save Request

  • Extract required fields from valid trades in the upload response
  • Use the exact values returned, especially contractName
  • Set selected to true and tradeToolSelection to 6

Step 7: Create Trades

  • Submit valid trades to api/v2/OptionTrading/SaveOptionTrades
  • Include proper authorization and content-type headers

Step 8: Confirm Success

  • Receive instance IDs for successfully created trades

Common Validation Errors

Error MessageWhat It MeansHow to Fix
“The provided Account does not exist”Account ID or number is invalidVerify account exists in the system
“Cannot purchase expired contract”Expiration date is in the pastUpdate to a future expiration date
“Portfolio needs analytics”Portfolio requires analytics runRun analytics on the portfolio before trading
contractName is null in responseTrade failed validationCheck warningMessage for specific reason

Numeric Code Reference

When working with the API responses and requests, you’ll encounter these numeric codes:

Trade Action Codes

  • 1 = Buy
  • 2 = Sell

Option Type Codes

  • 1 = Call
  • 0 = Put

Contract Action Codes

  • 1 = Open (opening a new position)
  • 0 = Close (closing an existing position)

Trade Tool Selection

  • 6 = Option Import Tool (always use this value when creating trades from imports)

Best Practices

Before You Start

  • Ensure all option contract details (prices, strikes, dates) are accurate
  • Verify account numbers or IDs are correct
  • Confirm expiration dates are in the future

During Implementation

  • Always check portfolioFlag before processing trades
  • Never attempt to create trades where isValid is false
  • Preserve exact field values from the upload response when creating trades

Data Accuracy

Remember: You are responsible for ensuring the accuracy of option prices, strike prices, and contract details. The API validates data format and business rules but does not verify current market prices or that option contracts exist.


Important Reminders

  • Sequential Process Required – You must call the upload endpoint before the save endpoint
  • Contract Name is Generated – The upload endpoint creates the contractName field needed for saving
  • Validation Happens Twice – Upload performs initial validation; Save performs deeper trade validation
  • Invalid Contracts Caught Late – Non-existent option contracts will only be caught during execution
  • One-Way Process – There is no “undo” once trades are created