### Example GET Request Configuration Source: https://developer.webull.com/apis/docs/reference/footprint This snippet shows a typical configuration object for a GET request, including the URL and method. Ensure the URL is correctly formatted for the desired endpoint. ```json { "url": "/v1/users/me/accounts", "method": "GET" } ``` -------------------------------- ### Options Order Example Source: https://developer.webull.com/apis/docs/reference/common-order-preview Example of placing a single leg options order. ```APIDOC ## POST /api/orders ### Description Places a new order for an option contract. ### Method POST ### Endpoint /api/orders ### Request Body - **account_id** (string) - Required - The ID of the account to place the order from. - **new_orders** (array) - Required - A list of new orders to be placed. - **client_order_id** (string) - Required - A unique identifier for the client's order. - **combo_type** (string) - Required - The type of order combination (e.g., NORMAL). - **order_type** (string) - Required - The type of order (e.g., LIMIT). - **limit_price** (string) - Optional - The limit price for LIMIT orders. - **quantity** (string) - Required - The quantity of the option contract to trade. - **option_strategy** (string) - Required - The options strategy (e.g., SINGLE). - **side** (string) - Required - The side of the order (e.g., BUY, SELL). - **time_in_force** (string) - Required - The duration the order remains active (e.g., DAY). - **entrust_type** (string) - Required - The type of entrustment (e.g., QTY). - **instrument_type** (string) - Required - The type of financial instrument (must be OPTION). - **market** (string) - Required - The market where the instrument is traded (e.g., US). - **symbol** (string) - Required - The trading symbol of the underlying financial instrument. - **legs** (array) - Required - Details for each leg of the option order. - **side** (string) - Required - The side of the leg order (e.g., BUY, SELL). - **quantity** (string) - Required - The quantity for this leg. - **symbol** (string) - Required - The trading symbol of the underlying financial instrument for this leg. - **strike_price** (string) - Required - The exercise price of the option. - **option_expire_date** (string) - Required - The expiration date of the option in yyyy-MM-dd format. - **instrument_type** (string) - Required - The type of financial instrument for this leg (must be OPTION). - **option_type** (string) - Required - The type of the option (CALL or PUT). - **market** (string) - Required - The market where the instrument is traded (e.g., US). ### Request Example ```json { "account_id": "", "new_orders": [ { "client_order_id": "", "combo_type": "NORMAL", "order_type": "LIMIT", "limit_price": "11.25", "quantity": "1", "option_strategy": "SINGLE", "side": "BUY", "time_in_force": "DAY", "entrust_type": "QTY", "instrument_type": "OPTION", "market": "US", "symbol": "AAPL", "legs": [ { "side": "BUY", "quantity": "1", "symbol": "AAPL", "strike_price": "220.00", "option_expire_date": "2026-06-19", "instrument_type": "OPTION", "option_type": "CALL", "market": "US" } ] } ] } ``` ### Response #### Success Response (200) - **order_id** (string) - The unique identifier for the placed order. - **client_order_id** (string) - The client-provided order ID. - **status** (string) - The status of the order. #### Response Example ```json { "order_id": "", "client_order_id": "", "status": "FILLED" } ``` ``` -------------------------------- ### GET Request Example Source: https://developer.webull.com/apis/docs/reference/crypto-instrument-list An example of a GET request, illustrating the use of the required headers. ```APIDOC ## GET /api/some/endpoint ### Description This endpoint retrieves data from a specific resource. ### Method GET ### Endpoint `/api/some/endpoint` ### Headers - **x-app-key** (string) - Required - **x-app-secret** (string) - Required - **x-timestamp** (string) - Required - **x-signature-version** (string) - Required - **x-signature-algorithm** (string) - Required - **x-signature-nonce** (string) - Required - **x-access-token** (string) - Required - **x-version** (string) - Required - **x-signature** (string) - Required - **Accept** (string) - Optional ### Response #### Success Response (200) - **data** (object) - The retrieved data. #### Response Example ```json { "data": { "example_field": "example_value" } } ``` ``` -------------------------------- ### Install Webull Python SDK Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/skills Install the Webull Python SDK using pip. This is a prerequisite for using the Agent Skills. ```bash pip install webull-openapi-python-sdk ``` -------------------------------- ### Futures Order Example Source: https://developer.webull.com/apis/docs/reference/common-order-preview Example of placing a futures order. ```APIDOC ## POST /api/orders ### Description Places a new order for a futures contract. ### Method POST ### Endpoint /api/orders ### Request Body - **account_id** (string) - Required - The ID of the account to place the order from. - **new_orders** (array) - Required - A list of new orders to be placed. - **combo_type** (string) - Required - The type of order combination (e.g., NORMAL). - **client_order_id** (string) - Required - A unique identifier for the client's order. - **symbol** (string) - Required - The trading symbol of the futures contract. - **instrument_type** (string) - Required - The type of financial instrument (must be FUTURES). - **market** (string) - Required - The market where the instrument is traded (e.g., US). - **order_type** (string) - Required - The type of order (e.g., LIMIT). - **limit_price** (string) - Optional - The limit price for LIMIT orders. - **quantity** (string) - Required - The quantity of the futures contract to trade. - **side** (string) - Required - The side of the order (e.g., BUY, SELL). - **time_in_force** (string) - Required - The duration the order remains active (e.g., DAY). - **entrust_type** (string) - Required - The type of entrustment (e.g., QTY). ### Request Example ```json { "account_id": "", "new_orders": [ { "combo_type": "NORMAL", "client_order_id": "", "symbol": "ESZ5", "instrument_type": "FUTURES", "market": "US", "order_type": "LIMIT", "limit_price": "4500", "quantity": "1", "side": "BUY", "time_in_force": "DAY", "entrust_type": "QTY" } ] } ``` ### Response #### Success Response (200) - **order_id** (string) - The unique identifier for the placed order. - **client_order_id** (string) - The client-provided order ID. - **status** (string) - The status of the order. #### Response Example ```json { "order_id": "", "client_order_id": "", "status": "FILLED" } ``` ``` -------------------------------- ### Install Webull Python SDK Source: https://developer.webull.com/apis/docs/getting-started Use pip to install the Webull OpenAPI Python SDK. Ensure you are using pip3 for Python 3 installations. ```bash pip3 install --upgrade webull-openapi-python-sdk ``` -------------------------------- ### Verify Python SDK Setup Source: https://developer.webull.com/apis/docs/sdk Verify your Webull SDK setup by initializing the ApiClient and TradeClient, then fetching the account list. This requires your app key, app secret, and the correct endpoint. ```python import json from webull.core.client import ApiClient from webull.trade.trade_client import TradeClient api_client = ApiClient("", "", "us") api_client.add_endpoint("us", "us-openapi-alb.uat.webullbroker.com") trade_client = TradeClient(api_client) res = trade_client.account_v2.get_account_list() if res.status_code == 200: print("Success!", json.dumps(res.json(), indent=2)) else: print("Error:", res.status_code, res.text) ``` -------------------------------- ### Stock Order Example Source: https://developer.webull.com/apis/docs/reference/common-order-preview Example of placing a stock limit order. ```APIDOC ## POST /api/orders ### Description Places a new order for a financial instrument. ### Method POST ### Endpoint /api/orders ### Request Body - **account_id** (string) - Required - The ID of the account to place the order from. - **new_orders** (array) - Required - A list of new orders to be placed. - **client_order_id** (string) - Required - A unique identifier for the client's order. - **combo_type** (string) - Required - The type of order combination (e.g., NORMAL). - **symbol** (string) - Required - The trading symbol of the financial instrument. - **instrument_type** (string) - Required - The type of financial instrument (e.g., EQUITY, OPTION, FUTURES, CRYPTO). - **market** (string) - Required - The market where the instrument is traded (e.g., US). - **order_type** (string) - Required - The type of order (e.g., LIMIT, MARKET). - **limit_price** (string) - Optional - The limit price for LIMIT orders. - **quantity** (string) - Required - The quantity of the instrument to trade. - **side** (string) - Required - The side of the order (e.g., BUY, SELL). - **time_in_force** (string) - Required - The duration the order remains active (e.g., DAY, GTC). - **support_trading_session** (string) - Optional - The trading session for the order (e.g., CORE). - **entrust_type** (string) - Required - The type of entrustment (e.g., QTY). ### Request Example ```json { "account_id": "", "new_orders": [ { "client_order_id": "", "combo_type": "NORMAL", "symbol": "AAPL", "instrument_type": "EQUITY", "market": "US", "order_type": "LIMIT", "limit_price": "180.00", "quantity": "10", "side": "BUY", "time_in_force": "DAY", "support_trading_session": "CORE", "entrust_type": "QTY" } ] } ``` ### Response #### Success Response (200) - **order_id** (string) - The unique identifier for the placed order. - **client_order_id** (string) - The client-provided order ID. - **status** (string) - The status of the order. #### Response Example ```json { "order_id": "", "client_order_id": "", "status": "FILLED" } ``` ``` -------------------------------- ### Verify Java SDK Setup Source: https://developer.webull.com/apis/docs/sdk Verify your Webull SDK setup by creating an HttpApiConfig with your credentials and endpoint, then initializing the TradeClientV2 to fetch the account list. ```java import com.webull.openapi.core.http.HttpApiConfig; import com.webull.openapi.trade.TradeClientV2; public class VerifySetup { public static void main(String[] args) { HttpApiConfig config = HttpApiConfig.builder() .appKey("") .appSecret("") .regionId("us") .endpoint("us-openapi-alb.uat.webullbroker.com") .build(); TradeClientV2 client = new TradeClientV2(config); System.out.println("Account list: " + client.getAccountList()); } } ``` -------------------------------- ### Example Data API Request Source: https://developer.webull.com/apis/docs/market-data-api/data-api This is an example of a GET request to the Data API for stock snapshot data. Ensure all required authentication headers are included. ```http GET /openapi/market-data/stock/snapshot?symbols=AAPL&category=US_STOCK&extend_hour_required=false&overnight_required=false x-app-key: x-timestamp: 2025-03-19T10:00:00Z x-signature-algorithm: HMAC-SHA1 x-signature-version: 1.0 x-signature-nonce: x-version: v2 x-signature: ``` -------------------------------- ### Usage Examples Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/mcp Examples of how to use the API for market data queries and trading operations. ```APIDOC ## Usage Examples ### Market Data ``` Get a real-time snapshot for AAPL ``` ``` Show me AAPL's daily bars for the last 5 days ``` ### Trading ``` Buy 100 shares of AAPL at market price ``` ``` Buy 10 shares of TSLA at market price ``` ``` -------------------------------- ### Crypto Order Example Source: https://developer.webull.com/apis/docs/reference/common-order-preview Example of a normal crypto order with limit price and quantity. ```json { "account_id": "", "new_orders": [ { "combo_type": "NORMAL", "client_order_id": "", "symbol": "BTCUSD", "instrument_type": "CRYPTO", "market": "US", "order_type": "LIMIT", "limit_price": "80000", "quantity": "0.003", "side": "BUY", "time_in_force": "DAY", "entrust_type": "QTY" } ] } ``` -------------------------------- ### Equity Order Preview Request Example Source: https://developer.webull.com/apis/docs/reference/common-order-preview Example JSON request body for an equity order preview, including details for a single option leg. ```json { "account_id": "93IUJ28O9VO2KBGHDHR4H9", "client_combo_order_id": "0KGOHL4PR2SLC0DKIND4TI0001", "new_orders": [ { "client_order_id": "0KGOHL4PR2SLC0DKIND4TI0002", "combo_type": "NORMAL", "option_strategy": "SINGLE", "instrument_type": "EQUITY", "entrust_type": "QTY", "support_trading_session": "CORE", "symbol": "AAPL", "market": "US", "side": "BUY", "order_type": "MARKET", "time_in_force": "DAY", "stop_price": "11.0", "limit_price": "11.0", "quantity": "1", "trailing_type": "AMOUNT", "trailing_stop_step": "1", "current_ask": "11.1", "current_bid": "11.0", "algo_type": "TWAP", "target_vol_percent": "10", "max_target_percent": "10", "algo_start_time": "09:30:00", "algo_end_time": "16:00:00", "event_outcome": "yes", "legs": [ { "side": "BUY", "quantity": "1", "market": "US", "instrument_type": "OPTION", "symbol": "AAPL", "strike_price": "11.0", "option_expire_date": "2025-08-01", "option_type": "CALL" } ] } ] } ``` -------------------------------- ### Batch Order Response Example Source: https://developer.webull.com/apis/docs/reference/order-batch-place An example of a batch order response, showing a mix of successful and failed orders. ```json { "total": 2, "success": 1, "failed": 1, "batch_orders": [ { "client_order_id": "0KGOHL4PR2SLC0DKIND4TI0001", "order_id": "80HG7CPSFDPCAL3TP66LKBAS69" }, { "client_order_id": "0KGOHL4PR2SLC0DKIND4TI0002", "error_code": "OAUTH_OPENAPI_NO_TRADING_TIME", "message": "Non-trading time." } ] } ``` -------------------------------- ### Single Leg Option Order Example Source: https://developer.webull.com/apis/docs/reference/common-order-place Example of placing a single leg option order. Replace placeholders with your specific account and order details. ```json { "account_id": "", "new_orders": [ { "client_order_id": "", "combo_type": "NORMAL", "order_type": "LIMIT", "limit_price": "11.25", "quantity": "1", "option_strategy": "SINGLE", "side": "BUY", "time_in_force": "DAY", "entrust_type": "QTY" } ] } ``` -------------------------------- ### Python Position Events Subscription Example Source: https://developer.webull.com/apis/docs/reference/custom/subscribe-position-events Example demonstrating how to subscribe to position events in Python. It shows how to set up logging and event message handling using the TradeEventsClient. Ensure you are using the latest SDK version. ```python import logging from webull.trade.events.types import EVENT_TYPE_POSITION, POSITION_STATUS_CHANGED from webull.trade.trade_events_client import TradeEventsClient your_app_key = "" your_app_secret = "" account_id = "" region_id = "us" # PRD env host: events-api.webull.com ``` -------------------------------- ### JSON Request Body Example for Batch Orders Source: https://developer.webull.com/apis/docs/reference/order-batch-place An example of a JSON request body for placing orders in batch. Includes account ID and details for multiple orders. ```json { "account_id": "93IUJ28O9VO2KBGHDHR4H9", "batch_orders": [ { "client_order_id": "0KGOHL4PR2SLC0DKIND4TI0002", "combo_type": "NORMAL", "instrument_type": "EQUITY", "entrust_type": "QTY", "support_trading_session": "CORE", "symbol": "BULL", "market": "US", "side": "BUY", "order_type": "MARKET", "time_in_force": "DAY", "quantity": "1" } ] } ``` -------------------------------- ### Webull API Signature Generation Worked Example Source: https://developer.webull.com/apis/docs/authentication/signature This example demonstrates the complete signature generation process using provided request details, headers, body, and App Secret. ```json { "k1": 123, "k2": "this is the api request body", "k3": true, "k4": { "foo": [ 1, 2 ] } } ``` -------------------------------- ### Get AAPL Latest Price using Natural Language Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/skills This is an example of a natural language query to get the latest price for AAPL, intended for use with AI assistants. ```natural_language Get AAPL latest price ``` -------------------------------- ### Query Account List (Production Environment) Source: https://developer.webull.com/apis/docs/connect-api/authentication Example of how to query the account list in the production environment using a Bearer token. Ensure your access token is valid and included in the Authorization header. ```bash curl -X GET "https://us-oauth-open-api.webull.com/oauth-openapi/account/list" \ -H "Authorization: Bearer " \ -H "accept: application/json" ``` -------------------------------- ### Create and Verify Token Source: https://developer.webull.com/apis/docs/changelog Demonstrates the process of creating and verifying an access token for API authentication. ```python import requests # --- Create Token --- create_token_url = "https://api.webull.com/v1/oauth2/token" client_id = "YOUR_CLIENT_ID" client_secret = "YOUR_CLIENT_SECRET" payload = { "grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret } response = requests.post(create_token_url, data=payload) token_data = response.json() access_token = token_data.get("access_token") print(f"Access Token: {access_token}") # --- Verify Token --- # In a real scenario, you would use the access token in subsequent API requests. # For demonstration, we'll just check if we got a token. if access_token: print("Token created successfully.") else: print("Failed to create token.") print(token_data) ``` -------------------------------- ### Query Market Data via CLI Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/skills Use this command to query market data. Replace with the desired market data query and provide necessary arguments. ```bash python3 scripts/cli.py market-data --action [args...] ``` -------------------------------- ### Verify Webull Connection Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/skills Execute this command to verify your connection and setup by listing your trading accounts. Successful execution returns account information. ```bash python3 scripts/cli.py trading --action account-list ``` -------------------------------- ### Order Replace Request Body Example Source: https://developer.webull.com/apis/docs/reference/common-order-replace This JSON object demonstrates the structure for modifying orders. It includes fields for account ID and a list of orders to be modified, with each order specifying client order ID, time in force, stop price, limit price, quantity, order type, trailing type, trailing stop step, target volume percentage, algorithm start and end times, and legs. ```json { "account_id": "93IUJ28O9VO2KBGHDHR4H9", "modify_orders": [ { "client_order_id": "0KGOHL4PR2SLC0DKIND4TI0002", "time_in_force": "DAY", "stop_price": "11.0", "limit_price": "11.0", "quantity": "1", "order_type": "MARKET", "trailing_type": "AMOUNT", "trailing_stop_step": "1", "target_vol_percent": "10", "max_target_percent": "10", "algo_start_time": "09:30:00", "algo_end_time": "16:00:00", "legs": [ { "id": "G2JAJPOR4KUA0F5I9LONH8J83A", "quantity": "1" } ] } ] } ``` -------------------------------- ### Authenticate 2FA for Webull Account Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/skills Run this command to initiate the 2FA authentication flow if your account has Two-Factor Authentication enabled. This is a one-time setup. ```bash python3 scripts/cli.py auth ``` -------------------------------- ### Get Account List Source: https://developer.webull.com/apis/docs/changelog Retrieve a list of all available accounts. This is necessary to get account-specific data. ```python from py_webull import webull # Initialize Webull API api = webull("YOUR_USERNAME", "YOUR_PASSWORD") # Login to your account api.login() # Get account list accounts = api.get_account_list() print(accounts) ``` -------------------------------- ### Make First API Call with Python SDK Source: https://developer.webull.com/apis/docs/getting-started This Python snippet demonstrates how to initialize the API client and make a call to retrieve account information using the Trading API. Replace placeholders with your actual App Key and App Secret. ```python from webull.core.client import ApiClient from webull.trade.trade_client import TradeClient api_client = ApiClient("", "", "us") api_client.add_endpoint("us", "us-openapi-alb.uat.webullbroker.com") trade_client = TradeClient(api_client) res = trade_client.account_v2.get_account_list() print(res.json()) ``` -------------------------------- ### Event Contract Order Example Source: https://developer.webull.com/apis/docs/reference/common-order-preview Example of a normal event contract order with limit price, quantity, and event outcome. ```json { "account_id": "", "new_orders": [ { "combo_type": "NORMAL", "client_order_id": "", "symbol": "KXRATECUTCOUNT-26DEC31-T3", "instrument_type": "EVENT", "market": "US", "order_type": "LIMIT", "limit_price": "0.10", "quantity": "5", "side": "BUY", "time_in_force": "DAY", "entrust_type": "QTY", "event_outcome": "yes" } ] } ``` -------------------------------- ### Query Account List (UAT Environment) Source: https://developer.webull.com/apis/docs/connect-api/authentication Example of how to query the account list in the UAT environment using a Bearer token. Ensure your access token is valid and included in the Authorization header. ```bash curl -X GET "https://us-oauth-open-api.uat.webullbroker.com/oauth-openapi/account/list" \ -H "Authorization: Bearer " \ -H "accept: application/json" ``` -------------------------------- ### Configure Production API Credentials Source: https://developer.webull.com/apis/docs/AI-friendly-Resources/skills Set up your production API credentials in a .env file. Ensure WEBULL_ENVIRONMENT is set to 'prod' and WEBULL_REGION_ID to 'us'. ```env WEBULL_APP_KEY=your_app_key WEBULL_APP_SECRET=your_app_secret WEBULL_ENVIRONMENT=prod WEBULL_REGION_ID=us ``` -------------------------------- ### Event Contract Example Source: https://developer.webull.com/apis/docs/reference/custom/subscribe-position-events This example shows the structure of a position event contract, including details like event name, settlement conditions, and cost. It also includes a debug response snippet with event metadata. ```json { "event_name": "Number of rate cuts in 2025", "yes_condition": "Exactly 8 cuts", "settle_result": "Yes", "settle_side": "Yes", "quantity": "40", "cost": "20.00", "settle_amount": "40.00" } DEBUG response:eventType: Ping subscribeType: 2 contentType: "text/plain" requestId: "ab39b532-3ad4-46c4-823d-3dff12e0f1b9" timestamp: 1768994319673 ``` -------------------------------- ### Construct Signature String - Step 1 Source: https://developer.webull.com/apis/docs/authentication/signature This step involves merging query parameters and signing headers, sorting them alphabetically, and joining them into a single string. ```text a1=webull, a2=123, a3=xxx, host=api.webull.com, q1=yyy, x-app-key=776da210ab4a452795d74e726ebd74b6, x-signature-algorithm=HMAC-SHA1, x-signature-nonce=48ef5afed43d4d91ae514aaeafbc29ba, x-signature-version=1.0, x-timestamp=2022-01-04T03:55:31Z ``` ```text a1=webull&a2=123&a3=xxx&host=api.webull.com&q1=yyy&x-app-key=776da210ab4a452795d74e726ebd74b6&x-signature-algorithm=HMAC-SHA1&x-signature-nonce=48ef5afed43d4d91ae514aaeafbc29ba&x-signature-version=1.0&x-timestamp=2022-01-04T03:55:31Z ``` -------------------------------- ### Place Single Leg Options Order Source: https://developer.webull.com/apis/docs/reference/common-order-preview This example demonstrates how to place a single leg limit order for options. It includes details specific to options like strike price and expiration date. ```json { "account_id": "", "new_orders": [ { "client_order_id": "", "combo_type": "NORMAL", "order_type": "LIMIT", "limit_price": "11.25", "quantity": "1", "option_strategy": "SINGLE", "side": "BUY", "time_in_force": "DAY", "entrust_type": "QTY", "instrument_type": "OPTION", "market": "US", "symbol": "AAPL", "legs": [ { "side": "BUY", "quantity": "1", "symbol": "AAPL", "strike_price": "220.00", "option_expire_date": "2026-06-19", "instrument_type": "OPTION", "option_type": "CALL", "market": "US" } ] } ] } ``` -------------------------------- ### Python Trade Events Subscription Example Source: https://developer.webull.com/apis/docs/reference/custom/subscribe-trade-events Example of subscribing to trade events using the Webull SDK. When using the SDK, subscribeType, timestamp, and contentType can be ignored. The _on_log method is for logging, and my_on_events_message handles received order status change messages. ```python import logging from webull.trade.types import ORDER_STATUS_CHANGED, EVENT_TYPE_ORDER from webull.trade.trade_events_client import TradeEventsClient your_app_key = "" your_app_secret = "" account_id = "" region_id = "us" # PRD env host: events-api.webull.com ```