Getting Started
This guide walks you through enabling OpenAPI access and issuing your first request in under five minutes.
API Host
- HTTP API —
https://openapi.futunn.com - WebSocket Quote —
wss://openapi-quote.futunn.com - WebSocket Trade —
wss://openapi-trade.futunn.com
Time Format
All time-related fields returned by APIs use Unix Timestamp (milliseconds) in UTC timezone.
Prerequisites
Install SDK
Python
bash
pip3 install futu-openapiJavaScript
bash
yarn add @futu/openapiConfiguration
Create a Developer Account
- Download moomoo and complete account opening
- Obtain authentication credentials from the Developer Portal
Authentication
OpenAPI supports two authentication methods. See Authentication for details.
Method 1: OAuth 2.0 (Recommended)
OAuth 2.0 is a modern authentication method using Bearer Tokens. No HMAC signing needed — more secure and convenient.
python
from futu.openapi import Config, OAuthBuilder
oauth = OAuthBuilder("your-client-id").build(
lambda url: print(f"Please visit this URL to authorize: {url}")
)
config = Config.from_oauth(oauth)Method 2: Traditional API Key
Obtain App Key, App Secret, and Access Token from the Developer Portal, then set as environment variables:
bash
export FUTU_APP_KEY="Your App Key"
export FUTU_APP_SECRET="Your App Secret"
export FUTU_ACCESS_TOKEN="Your Access Token":::caution Protect your Access Token carefully — anyone who obtains it can trade on your account via OpenAPI! :::
Examples
Get Real-time Quote
Python
python
from futu.openapi import QuoteContext, Config, OAuthBuilder
oauth = OAuthBuilder("your-client-id").build(
lambda url: print(f"Please visit this URL to authorize: {url}")
)
config = Config.from_oauth(oauth)
# Or use API Key: config = Config.from_env()
ctx = QuoteContext(config)
resp = ctx.get_snapshot(["HK.00700", "US.AAPL"])
print(resp)JavaScript
javascript
const { Config, QuoteContext, OAuth } = require('@futu/openapi')
async function main() {
const oauth = await OAuth.build('your-client-id', (_, url) => {
console.log('Please visit this URL to authorize: ' + url)
})
const config = Config.fromOAuth(oauth)
const ctx = QuoteContext.new(config)
const resp = await ctx.getSnapshot(['HK.00700', 'US.AAPL'])
console.log(resp)
}
main().catch(console.error)curl (RESTful API)
bash
curl -X POST 'https://openapi.futunn.com/v1/quote/snapshot' \
-H 'Content-Type: application/json' \
-H 'X-Futu-Client-Nnid: your_nnid' \
-d '{"code_list": ["HK.00700", "US.AAPL"]}' | jqSubscribe to Real-time Quotes
Python
python
from time import sleep
from futu.openapi import QuoteContext, Config, OAuthBuilder, SubType, PushQuote
def on_quote(symbol: str, quote: PushQuote):
print(symbol, quote)
oauth = OAuthBuilder("your-client-id").build(
lambda url: print(f"Please visit this URL to authorize: {url}")
)
config = Config.from_oauth(oauth)
ctx = QuoteContext(config)
ctx.set_on_quote(on_quote)
ctx.subscribe(["HK.00700", "US.AAPL", "US.TSLA"], [SubType.Quote])
sleep(30)Get K-line Data
curl
bash
curl 'https://openapi.futunn.com/v1/quote/HK.00700/cur-kline?num=5&ktype=2&autype=1' \
-H 'X-Futu-Client-Nnid: your_nnid' | jqSymbol Format
All APIs use the <MARKET>.<CODE> format for symbols:
| Example | Description |
|---|---|
HK.00700 | Hong Kong — Tencent Holdings |
US.AAPL | US — Apple Inc. |
SH.600519 | Shanghai — Kweichow Moutai |
SZ.000001 | Shenzhen — Ping An Bank |
HK.HSImain | HSI Futures Main Contract |
BMD.FCPOmain | Malaysia Palm Oil Futures Main Contract |
Next Steps
- Authentication — Understand how credentials are signed and rotated.
- Rate Limit — Quota rules for production readiness.
- API Reference — Browse the full API documentation.