When building an API to place trades, there are a number of input fields that are essential, as well as some that are nice to have. Below are a couple great examples of trading APIs that have been successfully used in production for years:
https://docs.alpaca.markets/reference/postorder
https://documentation.tradier.com/brokerage-api/trading/place-equity-order
Prerequisite:
-
Recent orders
This is required for trading functionality in order to check the status of trades placed over the API. This allows us to indicate whether the trade is pending, executed, rejected, etc
See: Recent Orders
-
Market Quotes / Symbol Search
This is required in order for us to ensure we know the current price of the security from the brokerage’s perspective. We use this information to to do validations on our side (ensure the user has enough available cash to place the trade)
Nice to have but not essential:
- Get order by ID. Same as recent order endpoint but instead pass an order id to get the details of a single order
- Order impact. Get impact an order would have on an account (estimated cost, fees, commissions, etc) Ex: https://documentation.tradier.com/brokerage-api/trading/preview-order
- Websocket for streaming updates around order status in order to avoid constant polling
Request:
Essential Input Parameters:
- account_id - usually path parameter to indicate the account the trade should be placed on
- symbol - ticker or ID of the security to be traded
- quantity - number of shares, should allow integer and decimal numbers if supported. For options this would be integer representing number of contracts
- side - buy or sell
- type - MARKET, LIMIT and ideally STOP, STOPLIMIT
- time_in_force - when the trade will expire. Common values:
- limit_price - required if type is LIMIT or STOPLIMIT