Learn how to place your first equity order by getting market data, running preflight checks, placing the order, and verifying execution.
First, retrieve your account ID using the accounts endpoint:
curl --request GET \
--url https://api.public.com/userapigateway/trading/account \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'This returns your available accounts with their IDs:
{
"accounts": [
{
"accountId": "YOUR_ACCOUNT_ID",
"accountType": "BROKERAGE",
"optionsLevel": "LEVEL_2",
"brokerageAccountType": "MARGIN"
}
]
}Get the current market price for the stock you want to buy (e.g., AAPL):
curl --request POST \
--url https://api.public.com/userapigateway/marketdata/{YOUR_ACCOUNT_ID}/quotes \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"instruments": [
{
"symbol": "AAPL",
"type": "EQUITY"
}
]
}'This returns current bid/ask prices and last trade information:
{
"quotes": [
{
"instrument": {
"symbol": "AAPL",
"type": "EQUITY"
},
"outcome": "SUCCESS",
"last": "150.25",
"lastTimestamp": "2024-01-15T15:59:00Z",
"bid": "150.20",
"bidSize": 100,
"ask": "150.30",
"askSize": 200
}
]
}Before placing an order, run a preflight check to estimate costs and validate the order:
curl --request POST \
--url https://api.public.com/userapigateway/trading/{YOUR_ACCOUNT_ID}/preflight/single-leg \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"instrument": {
"symbol": "AAPL",
"type": "EQUITY"
},
"orderSide": "BUY",
"orderType": "MARKET",
"expiration": {
"timeInForce": "DAY"
},
"quantity": "1"
}'The response provides estimated costs and order details:
{
"instrument": {
"symbol": "AAPL",
"type": "EQUITY"
},
"estimatedCommission": "0.00",
"orderValue": "150.25",
"estimatedQuantity": "1",
"estimatedCost": "150.25",
"buyingPowerRequirement": "150.25",
"regulatoryFees": {
"secFee": "0.00",
"tafFee": "0.00"
}
}Now place the actual order. Generate a unique UUID for the orderId:
curl --request POST \
--url https://api.public.com/userapigateway/trading/{YOUR_ACCOUNT_ID}/order \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{
"orderId": "550e8400-e29b-41d4-a716-446655440000",
"instrument": {
"symbol": "AAPL",
"type": "EQUITY"
},
"orderSide": "BUY",
"orderType": "MARKET",
"expiration": {
"timeInForce": "DAY"
},
"quantity": "1"
}'The response confirms the order was submitted:
{
"orderId": "550e8400-e29b-41d4-a716-446655440000"
}Monitor your order status to see if it has been filled:
curl --request GET \
--url https://api.public.com/userapigateway/trading/{YOUR_ACCOUNT_ID}/order/550e8400-e29b-41d4-a716-446655440000 \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'The response shows the current order status:
{
"orderId": "550e8400-e29b-41d4-a716-446655440000",
"instrument": {
"symbol": "AAPL",
"type": "EQUITY"
},
"createdAt": "2024-01-15T16:00:00Z",
"type": "MARKET",
"side": "BUY",
"status": "FILLED",
"quantity": "1",
"filledQuantity": "1",
"averagePrice": "150.23",
"expiration": {
"timeInForce": "DAY"
}
}Finally, check your portfolio to confirm the new position:
curl --request GET \
--url https://api.public.com/userapigateway/trading/{YOUR_ACCOUNT_ID}/portfolio/v2 \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'You should now see your new AAPL position in the portfolio:
{
"accountId": "YOUR_ACCOUNT_ID",
"accountType": "BROKERAGE",
"buyingPower": {
"cashOnlyBuyingPower": "4849.77",
"buyingPower": "9849.77",
"optionsBuyingPower": "9849.77"
},
"positions": [
{
"instrument": {
"symbol": "AAPL",
"name": "Apple Inc.",
"type": "EQUITY"
},
"quantity": "1.0",
"currentValue": "150.25",
"percentOfPortfolio": "1.50",
"costBasis": {
"totalCost": "150.23",
"unitCost": "150.23",
"gainValue": "0.02",
"gainPercentage": "0.01"
}
}
]
}📝 Important Notes