Place orders, stream quotes, and manage portfolios using Python. Start with these minimal examples.
import requests
API_KEY = 'YOUR_API_KEY'
# Get JWT token
r = requests.post('https://api.paperinvest.io/v1/auth/token', json={'apiKey': API_KEY})
access_token = r.json()['access_token']
# Place a market order
headers = {'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json'}
order = {
'accountId': 'your-account-id',
'portfolioId': 'your-portfolio-id',
'symbol': 'AAPL', 'quantity': 10,
'side': 'buy', 'type': 'market', 'timeInForce': 'day'
}
resp = requests.post('https://api.paperinvest.io/v1/orders', headers=headers, json=order)
print(resp.status_code, resp.text)
import sseclient, requests
# Requires sseclient-py
access_token = requests.post('https://api.paperinvest.io/v1/auth/token', json={'apiKey': 'YOUR_API_KEY'}).json()['access_token']
headers = {'Authorization': f'Bearer {access_token}'}
# Example SSE portfolio stream
url = 'https://api.paperinvest.io/v1/stream/portfolio/YOUR_PORTFOLIO_ID'
r = requests.get(url, headers=headers, stream=True)
client = sseclient.SSEClient(r)
for event in client.events():
print('snapshot:', event.data)
Python 3.9+ is recommended.
HTTP-based usage works in any environment; SDK is planned. Examples below are copy-paste ready.
Use SSE or WebSockets. See the examples and websocket guide.