# 獲取即時報價

get_stock_quote(code_list)

  • 介紹

    獲取已訂閱股票的即時報價,必須要先訂閱。

  • 參數

    參數 類型 説明
    code_list list 股票代碼列表
  • 返回

    參數 類型 説明
    ret RET_CODE 介面呼叫結果
    data pd.DataFrame 當 ret == RET_OK,返回報價數據
    str 當 ret != RET_OK,返回錯誤描述
    • 報價數據格式如下:
      欄位 類型 説明
      code str 股票代碼
      name str 股票名稱
      data_date str 日期
      data_time str 當前價更新時間
      last_price float 最新價格
      open_price float 今日開盤價
      high_price float 最高價格
      low_price float 最低價格
      prev_close_price float 昨收盤價格
      volume int 成交數量
      turnover float 成交金額
      turnover_rate float 換手率
      amplitude int 振幅
      suspension bool 是否停牌
      listing_date str 上市日期
      price_spread float 當前向上的價差
      dark_status DarkStatus 暗盤交易狀態
      sec_status SecurityStatus 股票狀態
      strike_price float 行權價
      contract_size float 每份合約數
      open_interest int 未平倉合約數
      implied_volatility float 隱含波動率
      premium float 溢價
      delta float 希臘值 Delta
      gamma float 希臘值 Gamma
      vega float 希臘值 Vega
      theta float 希臘值 Theta
      rho float 希臘值 Rho
      index_option_type IndexOptionType 指數期權類型
      net_open_interest int 淨未平倉合約數
      expiry_date_distance int 距離到期日天數
      contract_nominal_value float 合約名義金額
      owner_lot_multiplier float 相等正股手數
      option_area_type OptionAreaType 期權類型(按行權時間)
      contract_multiplier float 合約乘數
      pre_price float 盤前價格
      pre_high_price float 盤前最高價
      pre_low_price float 盤前最低價
      pre_volume int 盤前成交量
      pre_turnover float 盤前成交額
      pre_change_val float 盤前漲跌額
      pre_change_rate float 盤前漲跌幅
      pre_amplitude float 盤前振幅
      after_price float 盤後價格
      after_high_price float 盤後最高價
      after_low_price float 盤後最低價
      after_volume int 盤後成交量
      after_turnover float 盤後成交額
      after_change_val float 盤後漲跌額
      after_change_rate float 盤後漲跌幅
      after_amplitude float 盤後振幅
      overnight_price float 夜盤價格
      overnight_high_price float 夜盤最高價
      overnight_low_price float 夜盤最低價
      overnight_volume int 夜盤成交量
      overnight_turnover float 夜盤成交額
      overnight_change_val float 夜盤漲跌額
      overnight_change_rate float 夜盤漲跌幅
      overnight_amplitude float 夜盤振幅
      last_settle_price float 昨結
      position float 持倉量
      position_change float 日增倉
  • Example

from moomoo import *
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)

ret_sub, err_message = quote_ctx.subscribe(['US.AAPL'], [SubType.QUOTE], subscribe_push=False)
# 先訂閱 K 線類型。訂閱成功後 OpenD 將持續收到伺服器的推送,False 代表暫時不需要推送給腳本
if ret_sub == RET_OK:  # 訂閱成功
    ret, data = quote_ctx.get_stock_quote(['US.AAPL'])  # 獲取訂閱股票報價的即時數據
    if ret == RET_OK:
        print(data)
        print(data['code'][0])   # 取第一條的股票代碼
        print(data['code'].values.tolist())   # 轉為 list
    else:
        print('error:', data)
else:
    print('subscription failed', err_message)
quote_ctx.close()  # 關閉當條連線,OpenD 會在1分鐘後自動取消相應股票相應類型的訂閱
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • Output
code name   data_date     data_time  last_price  open_price  high_price  low_price  prev_close_price     volume      turnover  turnover_rate  amplitude  suspension listing_date  price_spread dark_status sec_status strike_price contract_size open_interest implied_volatility premium delta gamma vega theta  rho net_open_interest expiry_date_distance contract_nominal_value owner_lot_multiplier option_area_type contract_multiplier last_settle_price position position_change index_option_type  pre_price  pre_high_price  pre_low_price  pre_volume  pre_turnover  pre_change_val  pre_change_rate  pre_amplitude  after_price  after_high_price  after_low_price  after_volume  after_turnover  after_change_val  after_change_rate  after_amplitude  overnight_price  overnight_high_price  overnight_low_price  overnight_volume  overnight_turnover  overnight_change_val  overnight_change_rate  overnight_amplitude
0  US.AAPL   蘋果  2025-04-07  05:37:21.794      188.38      193.89      199.88     187.34            203.19  125910913  2.424473e+10          0.838      6.172       False   1980-12-12          0.01         N/A     NORMAL          N/A           N/A           N/A                N/A     N/A   N/A   N/A  N/A   N/A  N/A               N/A                  N/A                    N/A                  N/A              N/A                 N/A               N/A      N/A             N/A               N/A     181.43          181.98         177.47      288853   52132735.18           -6.95           -3.689          2.394        186.6           188.639           186.44       3151311    5.930968e+08             -1.78             -0.944           1.1673           176.94                 186.5                174.4            533115         94944250.56                -11.44                 -6.072               6.4231
US.AAPL
['US.AAPL']
1
2
3
4

提示