Skip to content

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-openapi

JavaScript

bash
yarn add @futu/openapi

Configuration

Create a Developer Account

  1. Download moomoo and complete account opening
  2. Obtain authentication credentials from the Developer Portal

Authentication

OpenAPI supports two authentication methods. See Authentication for details.

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"]}' | jq

Subscribe 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' | jq

Symbol Format

All APIs use the <MARKET>.<CODE> format for symbols:

ExampleDescription
HK.00700Hong Kong — Tencent Holdings
US.AAPLUS — Apple Inc.
SH.600519Shanghai — Kweichow Moutai
SZ.000001Shenzhen — Ping An Bank
HK.HSImainHSI Futures Main Contract
BMD.FCPOmainMalaysia Palm Oil Futures Main Contract

Next Steps