@lap v0.3
# Machine-readable API spec. Each @endpoint block is one API call.
@api Client Portal Web API
@community true
@base http://localhost:5000/v1/api
@version 1.0.0
@endpoints 83
@hint download_for_search
@toc fyi(12), trsrv(4), ws(1), tickle(1), logout(1), ccp(10), hmds(2), sso(1), md(1), pa(3), portfolio(12), iserver(35)

@group fyi
@endpoint GET /fyi/unreadnumber
@desc Get unread number of fyis. The HTTP method POST is also supported.
@returns(200) An object

@endpoint GET /fyi/settings
@desc Get a list of subscriptions
@returns(200) An array

@endpoint POST /fyi/settings/{typecode}
@desc Enable/Disable certain subscription
@required {typecode: any # fyi code, body: map}
@returns(200) 200 means successful

@endpoint GET /fyi/disclaimer/{typecode}
@desc Get disclaimer for a certain kind of fyi
@required {typecode: any # fyi code, for example --M8, EA}
@returns(200) receives the disclaimer message

@endpoint PUT /fyi/disclaimer/{typecode}
@desc Mark disclaimer read
@required {typecode: any # fyi code, for example --M8, EA}
@returns(200) 200 means successful

@endpoint GET /fyi/deliveryoptions
@desc Get delivery options
@returns(200) An object

@endpoint PUT /fyi/deliveryoptions/email
@desc Enable/Disable email option
@required {enabled: any # true/false}
@returns(200) 200 means successful

@endpoint POST /fyi/deliveryoptions/device
@desc Enable/Disable device option
@required {body: map # device info}
@returns(200) 200 means successful

@endpoint DELETE /fyi/deliveryoptions/{deviceId}
@desc Delete a device
@required {deviceId: any # device ID}
@returns(200) 200 means successful

@endpoint GET /fyi/notifications
@desc Get a list of notifications
@required {max: any # max number of fyis in response}
@optional {exclude: any # if set, don't set include, include: any # if set, don't set exclude}
@returns(200) An array

@endpoint GET /fyi/notifications/more
@desc Get more notifications based on a certain one
@required {id: any # id of last notification in the list}
@returns(200) An array

@endpoint PUT /fyi/notifications/{notificationId}
@desc Get a list of notifications
@required {notificationId: any # mark a notification read}
@returns(200) when 200 receives, it means successful

@endgroup

@group trsrv
@endpoint POST /trsrv/secdef
@desc Secdef by Conid
@required {body: map # request body}
@returns(200) returns an array of secdef info

@endpoint GET /trsrv/secdef/schedule
@desc Get trading schedule for symbol
@required {assetClass: any # specify the asset class of the contract. Available values-- Stock: STK, Option: OPT, Future: FUT, Contract For Difference: CFD, Warrant: WAR, Forex: SWP, Mutual Fund: FND, Bond: BND, Inter-Commodity Spreads: ICS, symbol: any # Underlying Symbol for specified contract, for example 'AAPL' for US Stock - Apple Inc.}
@optional {exchange: any # Native exchange for contract, for example 'NASDAQ' for US Stock - Apple Inc., exchangeFilter: any # Response only returns trading schedule for specified exchange}
@returns(200) Returns an object

@endpoint GET /trsrv/futures
@desc Security Futures by Symbol
@required {symbols: any # list of case-sensitive symbols separated by comma}
@returns(200) returns an object with symbol and and array of its future contracts
@errors {500: error while processing the request}

@endpoint GET /trsrv/stocks
@desc Security Stocks by Symbol
@required {symbols: any # list of upper-sensitive symbols separated by comma}
@returns(200) returns an object with symbols
@errors {500: error while processing the request}

@endgroup

@group ws
@endpoint POST /ws
@desc Websocket Endpoint
@returns(200) confirms session is open

@endgroup

@group tickle
@endpoint POST /tickle
@desc Ping the server to keep the session open
@returns(200) confirms session is open

@endgroup

@group logout
@endpoint POST /logout
@desc Ends the current session
@returns(200) returned status indicates if user is logged in

@endgroup

@group ccp
@endpoint POST /ccp/auth/init
@desc Start CCP Session
@optional {compete: any # Allow competing CCP session to run, locale: any # Concatenate value for language and region, set to "en_US", mac: any # Local MAC Address, machineId: any # Local machine ID, username: any # Login user, set to dash "-"}
@returns(200) Returns challenge for connection
@errors {401: Access denied, 500: System error}

@endgroup

@group hmds
@endpoint GET /hmds/history
@desc Market Data History (Beta)
@required {conid: any # contract id, period: any # Time period for history request.    * min: Minutes   * h: Hours   * d: Days   * w: Weeks   * m: Months   * y: Years}
@optional {bar: any # Duration of time for each candlestick bar.   * min: Minutes   * h: Hours   * d: Days   * w: Weeks   * m: Months, outsideRth: any # For contracts that support it, will determine if history data includes outside of regular trading hours.}
@returns(200) Valid result
@errors {400: Bad request}

@endgroup

@group ccp
@endpoint POST /ccp/auth/response
@desc Complete CCP Session
@optional {auth: map}
@returns(200) Valid result
@errors {401: Access denied, 500: System error}

@endpoint GET /ccp/status
@desc CCP Status
@returns(200) Valid result
@errors {401: Access denied, 500: System error}

@endpoint GET /ccp/account
@desc Brokerage Accounts
@returns(200) An array of accounts

@endpoint GET /ccp/positions
@desc Positions
@returns(200) Valid result
@errors {401: Access denied, 500: System error}

@endpoint GET /ccp/orders
@desc Order Status
@required {acct: any # User Account}
@optional {cancelled: any # Return only Rejected or Cancelled orders since today midnight}
@returns(200) An Object
@errors {400: Bad request, 401: Access denied, 500: System error}

@endpoint POST /ccp/order
@desc Submit Order
@required {acct: any # User Account, conid: any # Contract identifier from IBKR's database., ccy: any # Contract Currency, exchange: any # Exchange, qty: any # Order Quantity}
@optional {type: any # Order Price; required if order type is limit, side: any # Side, price: any # Order Price; required if order type is limit, tif: any # Time in Force}
@returns(200) An Object
@errors {400: Bad Request, 401: Access denied, 500: System error, for example when connection to CCP failed}

@endpoint DELETE /ccp/order
@desc Delete Order
@required {acct: any # Account Number, id: any # Order Identifier of original submit order}
@returns(200) An Object
@errors {401: Access denied, 500: System error, for example when connection to CCP failed}

@endpoint PUT /ccp/order
@desc Update Order
@required {acct: any # User Account, id: any # Order ID to be modified}
@returns(200) An Object
@errors {401: Access denied, 500: System error, for example when connection to CCP failed}

@endpoint GET /ccp/trades
@desc Trades
@optional {from: any # From Date (YYYYMMDD-HH:mm:ss) or offset (-1,-2,-3..), to: any # To Date (YYYYMMDD-HH:mm:ss) or offset (-1,-2,-3..). To value should be bigger than from value.}
@returns(200) An Object
@errors {400: Bad request, 401: Access denied, 500: System error}

@endgroup

@group sso
@endpoint GET /sso/validate
@desc Validate SSO
@returns(200) An Object
@errors {401: Authentication failed, 500: System failed}

@endgroup

@group hmds
@endpoint POST /hmds/scanner
@desc Run Scanner (Beta)
@required {body: map # request body}
@returns(200) Valid result
@errors {400: Bad request}

@endgroup

@group md
@endpoint GET /md/snapshot
@desc Market Data Snapshot (Beta)
@required {conids: any # List of conids comma separated. Optional exchange and instrument type can be specified.   * conid: IBKR Contract Identifier   * exchange: Exchange or venue   * instrType: Instrument Type supported values: CS (Stocks), OPT (Options), FUT (Futures), FOP (Future Options), WAR (Warrants), BOND (Bonds), FUND (Mutual Funds), CASH (Forex), CFD (Contract for difference), IND (Index)}
@optional {fields: any # list of fields separated by comma}
@returns(200) An Object
@errors {401: Authentication failed, 500: System failed}

@endgroup

@group pa
@endpoint POST /pa/performance
@desc Account Performance
@required {body: map # an array of account ids}
@returns(200) returns an object

@endpoint POST /pa/summary
@desc Account Balance's Summary (Deprecated)
@required {body: map # an array of account ids}
@returns(200) returns an object

@endpoint POST /pa/transactions
@desc Position's Transaction History
@required {body: map}
@returns(200) returns an object

@endgroup

@group portfolio
@endpoint GET /portfolio/accounts
@desc Portfolio Accounts
@returns(200) An array

@endpoint GET /portfolio/subaccounts
@desc List of Sub-Accounts
@returns(200) An array

@endpoint GET /portfolio/subaccounts2
@desc List of Sub-Accounts (Large Accounts)
@required {page: any}
@returns(200) An object containing an array

@endpoint GET /portfolio/{accountId}/meta
@desc Account Information
@required {accountId: any # account id}
@returns(200) An object

@endpoint GET /portfolio/{accountId}/allocation
@desc Account Allocation
@required {accountId: any # account id}
@returns(200) returns an object of three different allocations

@endpoint POST /portfolio/allocation
@desc Account Alloction (All Accounts)
@required {body: map # accounts info}
@returns(200) returns an object of three different allocations

@endpoint GET /portfolio/{accountId}/positions/{pageId}
@desc Portfolio Positions
@required {accountId: any # account id, pageId: any # page id}
@optional {model: any # optional, sort: any # declare the table to be sorted by which column, direction: any # in which order, a means ascending - d means descending, period: any # period for pnl column, can be 1D, 7D, 1M...}
@returns(200) returns a list of positions in the portfolio

@endpoint GET /portfolio/{accountId}/position/{conid}
@desc Position by Conid
@required {accountId: any # account id, conid: any # contract id}
@returns(200) returns a list containing only one position for the conid

@endpoint POST /portfolio/{accountId}/positions/invalidate
@desc Invalidates the backend cache of the Portfolio
@required {accountId: any # account id}
@returns(200) Means successful

@endpoint GET /portfolio/{accountId}/summary
@desc Account Summary
@required {accountId: any # account id}
@returns(200) returns an object containing account summary. The object contains multiple properties. A property is sufficed with -c if its provides commodity value, -s if it provides security value and -c if its UKL segment value

@endpoint GET /portfolio/{accountId}/ledger
@desc Account Ledger
@required {accountId: any # account id}
@returns(200) 200 means successful

@endpoint GET /portfolio/positions/{conid}
@desc Positions by Conid
@required {conid: any # contract id}
@returns(200) returns an object containing account and its position information

@endgroup

@group iserver
@endpoint POST /iserver/auth/status
@desc Authentication Status
@returns(200) Authentication Status

@endpoint POST /iserver/reauthenticate
@desc Tries to re-authenticate to Brokerage
@returns(200) Authentication Status

@endpoint GET /iserver/account/trades
@desc List of Trades for the selected account
@returns(200) An array of trades

@endpoint GET /iserver/accounts
@desc Brokerage Accounts
@returns(200) An array of accounts

@endpoint POST /iserver/account
@desc Switch Account
@required {body: map # account id}
@returns(200) an object containing updated account ID

@endpoint POST /iserver/account/{accountId}/alert
@desc Create or modify alert
@required {accountId: any # account id, body: map # alert info}
@returns(200) returns an object

@endpoint GET /iserver/account/:accountId/alerts
@desc Get a list of available alerts
@required {accountId: any # account id}
@returns(200) returns an array of objects

@endpoint POST /iserver/account/:accountId/alert/activate
@desc Activate or deactivate an alert
@required {accountId: any # account id, body: map # order request info}
@returns(200) returns an object

@endpoint DELETE /iserver/account/:accountId/alert/:alertId
@desc Delete an alert
@required {accountId: any # account id, alertId: any # alert id}
@returns(200) returns an object

@endpoint GET /iserver/account/alert/:id
@desc Get details of an alert
@required {id: any # alert id}
@returns(200) returns an object

@endpoint GET /iserver/account/mta
@desc Get MTA alert
@returns(200) returns an object

@endpoint GET /iserver/account/orders
@desc Live Orders
@optional {Filters: any # list of filters separated by comma}
@returns(200) An object contains two arrays

@endpoint POST /iserver/account/{accountId}/order
@desc Place Order (Deprecated)
@required {accountId: any # account id, body: map # order request info}
@returns(200) returns an array

@endpoint POST /iserver/account/{accountId}/orders
@desc Place Orders
@required {accountId: any # account id, body: map # order request info}
@returns(200) returns an array

@endpoint POST /iserver/account/orders/{faGroup}
@desc Place Orders for FA
@required {faGroup: any # financial advisor group, body: map # order request info}
@returns(200) returns an array

@endpoint POST /iserver/reply/{replyid}
@desc Place Order Reply
@required {replyid: any # Please use the "id" from the response of "Place Order" endpoint, body: map # Answer to question}
@returns(200) Order is submitted successfully, returns an array contains one object
@errors {400: When you send "confirmed-false" in the request, you will receive this}

@endpoint POST /iserver/account/{accountId}/order/whatif
@desc Preview Order (Deprecated)
@required {accountId: any # account id, body: map # order info}
@returns(200) returns an object

@endpoint POST /iserver/account/{accountId}/orders/whatif
@desc Preview Orders
@required {accountId: any # account id, body: map # order info}
@returns(200) returns an object

@endpoint GET /iserver/account/order/status/{orderId}
@desc Order Status
@required {orderId: any # Customer order id, use /iservers/account/orders endpoint to query orderId.}
@returns(200) returns an object

@endpoint POST /iserver/account/{accountId}/order/{orderId}
@desc Modify Order
@required {accountId: any # account id, or fa group if modifying a group order, orderId: any # Customer order id, use /iservers/account/orders endpoint to query orderId., body: map # modify-order request}
@returns(200) returns an array

@endpoint DELETE /iserver/account/{accountId}/order/{orderId}
@desc Cancel Order
@required {accountId: any # account id, or fa group if deleting a group order, orderId: any # Customer order id, use /iservers/account/orders endpoint to query orderId.}
@returns(200) returns an object with order id, message, conid and account id

@endpoint GET /iserver/marketdata/snapshot
@desc Market Data
@required {conids: any # list of conids separated by comma}
@optional {since: any # time period since which updates are required. uses epoch time with milliseconds., fields: any # list of fields separated by comma}
@returns(200) Returns an array of objects
@errors {400: sent when accounts are not queried before sending this request}

@endpoint GET /iserver/marketdata/{conid}/unsubscribe
@desc Market Data Cancel (Single)
@required {conid: any # contract id}
@returns(200) confirms market data for conid is cancelled
@errors {500: cancel failed}

@endpoint GET /iserver/marketdata/unsubscribeall
@desc Market Data Cancel (All)
@returns(200) confirms market data is cancelled

@endpoint GET /iserver/marketdata/history
@desc Market Data History
@required {conid: any # contract id, period: any # available time period-- {1-30}min, {1-8}h, {1-1000}d, {1-792}w, {1-182}m, {1-15}y}
@optional {exchange: any # Exchange of the conid (e.g. ISLAND, NYSE, etc.). Default value is empty which corresponds to primary exchange of the conid., bar: any # possible value-- 1min, 2min, 3min, 5min, 10min, 15min, 30min, 1h, 2h, 3h, 4h, 8h, 1d, 1w, 1m, outsideRth: any # For contracts that support it, will determine if historical data includes outside of regular trading hours.}
@returns(200) Returns an object
@errors {429: Too many requests, 500: System Error}

@endpoint GET /iserver/contract/{conid}/info
@desc Contract Details
@required {conid: any # contract id}
@returns(200) returns an object

@endpoint POST /iserver/secdef/search
@desc Search by Symbol or Name
@required {symbol: map # Symbol or Company Name to be searched}
@returns(200) returns an array of results
@errors {500: error while processing the request}

@endpoint GET /iserver/secdef/strikes
@desc Search Strikes
@required {conid: any # contract id of the underlying contract, sectype: any # OPT/WAR, month: any # contract month}
@optional {exchange: any # optional, default is SMART}
@returns(200) returns an object contains call/put strike prices
@errors {500: error while processing the request}

@endpoint GET /iserver/secdef/info
@desc Secdef Info
@required {conid: any # underlying contract id, sectype: any # FUT/OPT/WAR/CASH/CFD}
@optional {month: any # contract month, only required for FUT/OPT/WAR in the format MMMYY, example JAN00, exchange: any # optional, default is SMART, strike: any # optional, only required for OPT/WAR, right: any # C for call, P for put}
@returns(200) returns an array of objects
@errors {500: error while processing the request}

@endpoint GET /iserver/contract/{conid}/algos
@desc IB Algo Params
@required {conid: any # IBKR contract identifier}
@optional {algos: any # List of algo ids delimited by ";" to filter by. Max of 8 algos ids can be specified., addDescription: any # Whether or not to add algo descriptions to response. Set to 1 for yes, 0 for no., addParams: any # Whether or not to show algo parameters.  Set to 1 for yes, 0 for no.}
@returns(200) returns an array of algos

@endpoint POST /iserver/contract/rules
@desc Contract Rules
@required {conid: map}
@returns(200) returns an array

@endpoint GET /iserver/contract/{conid}/info-and-rules
@desc Info and Rules
@required {conid: any # IBKR contract identifier, isBuy: any # Side of the market rules apply too. Set to **true** for Buy Orders, set to **false** for Sell Orders}
@returns(200) returns an array

@endpoint GET /iserver/scanner/params
@desc Scanner Parameters
@returns(200) An object contains lists

@endpoint POST /iserver/scanner/run
@desc Scanner Run
@required {body: map # scanner-params request}
@returns(200) returns an array

@endpoint GET /iserver/account/pnl/partitioned
@desc PnL for the selected account
@returns(200) An object containing account and model(s) pnl

@endgroup

@end
