# 實時報價回呼

on_recv_rsp(self, rsp_pb)

  • 介紹

    實時報價回呼,非同步處理已訂閲股票的實時報價推送。
    在收到實時報價數據推送後會回呼到該函數,您需要在衍生類別中覆寫 on_recv_rsp。

  • 參數

    參數 類型 説明
    rsp_pb Qot_UpdateBasicQot_pb2.Response 衍生類別中不需要直接處理該參數
  • 返回

    參數 類型 説明
    ret RET_CODE 介面呼叫結果
    data pd.DataFrame 當 ret == RET_OK,返回報價數據
    str 當 ret != RET_OK,返回錯誤描述
    • 報價數據格式如下:
      欄位 類型 説明
      code 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

import time
from moomoo import *

class StockQuoteTest(StockQuoteHandlerBase):
    def on_recv_rsp(self, rsp_pb):
        ret_code, data = super(StockQuoteTest,self).on_recv_rsp(rsp_pb)
        if ret_code != RET_OK:
            print("StockQuoteTest: error, msg: %s" % data)
            return RET_ERROR, data
        print("StockQuoteTest ", data) # StockQuoteTest 自己的處理邏輯
        return RET_OK, data
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
handler = StockQuoteTest()
quote_ctx.set_handler(handler)  # 設定實時報價回呼
ret, data = quote_ctx.subscribe(['US.AAPL'], [SubType.QUOTE])  # 訂閲實時報價類型,OpenD 開始持續收到伺服器的推送
if ret == RET_OK:
    print(data)
else:
    print('error:', data)
time.sleep(15)  #  設定腳本接收 OpenD 的推送持續時間為15秒
quote_ctx.close()   # 關閉當條連線,OpenD 會在1分鐘後自動取消相應股票相應類型的訂閲    	
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  • Output
StockQuoteTest        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   蘋果                             0.0         0.0         0.0        0.0               0.0       0       0.0            0.0        0.0       False                        0.0         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       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                N/A                  N/A                   N/A                 N/A
1
2

提示