Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

how to retrieve positions from the Webull API (get positions)

Last updated on 2 days ago
K
KevinMember
Posted 2 days ago
To retrieve positions from the Webull API, you'll need to send an authorized request to the relevant endpoint. Since Webull's API is not officially documented, this guide is based on commonly reverse-engineered methods.

### Prerequisites
1. **Access Token**: Authenticate using Webull's login API to obtain your access_token.
2. **Account ID**: Retrieve your account ID using the account details API.

### Sample Python Code to Get Positions

#### Install Required Libraries:
bash
pip install requests

#### Code:
python
import requests
import json
# Webull API Base URL
BASE_URL = "https://api.webull.com/api/trade"
# Replace with your credentials
ACCESS_TOKEN = "your_access_token" # Token obtained after login
ACCOUNT_ID = "your_account_id" # Fetch using account details API
def get_positions():
 """
 Function to retrieve positions from Webull account.
 :return: API response with account positions
 """
 url = f"{BASE_URL}/v2/option/positions?secAccountId={ACCOUNT_ID}"
 headers = {
 "Authorization": f"Bearer {ACCESS_TOKEN}",
 "Content-Type": "application/json",
 }
 # Send GET request
 response = requests.get(url, headers=headers)

 if response.status_code == 200:
 return response.json()
 else:
 return {
 "error": response.status_code,
 "message": response.text,
 }
# Example: Get positions
positions = get_positions()
print(json.dumps(positions, indent=4))
K
KevinMember
Posted 2 days ago
### Explanation of the Key Elements

#### Endpoint:
- **URL**:
https://api.webull.com/api/trade/v2/option/positions?secAccountId={ACCOUNT_ID}
Replace {ACCOUNT_ID} with your Webull account ID.

#### Headers:
- **Authorization**:
Include your Bearer token in the header for authenticated requests.

#### Response Fields:
The response typically includes details about your positions, such as:
- **symbol**: The ticker symbol (e.g., "AAPL").
- **quantity**: Number of shares held.
- **averagePrice**: Average purchase price.
- **currentPrice**: Current market price.
- **marketValue**: Total value of the position.

---

### Steps to Retrieve Required Data
1. **Login to Obtain Access Token**:
Use Webull's login API to authenticate and get the access_token.
python
 POST https://api.webull.com/api/passport/login
 


2. **Fetch Account Details**:
Use the account details endpoint to retrieve your account ID:
python
 GET https://api.webull.com/api/trade/accounts
 


3. **Get Positions**:
Send a GET request to the positions endpoint with your account ID and token.

---

### Notes
1. **Unofficial API**:
- Webull's API is not officially documented or supported for third-party use. API behavior may change without notice.
2. **Rate Limits**:
- Webull may enforce rate limits for API requests. Implement retry mechanisms as needed.
3. **Security**:
- Never expose your access token or account credentials. Store them securely.

---
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 3
Members Online 0

Total Members: 11
Newest Member: Jhilam