SubscribeBit 10001/Bit 20 欄位陷阱與獨立解碼器T1/O1/C1/H1:libFTQuote.so 內 G1 指標公式原文 Schema 與唯讀提取法檢索 libFTQuote.so 內嵌 Descriptor,富途自編指標(麥語言 MyLang 或 Python 指標)的完整公式源碼儲存在以下 3 個 Protobuf 結構(同步於客戶端本地目錄及雲端指標同步包):
Proto 檔(libFTQuote.so) | Message | 關鍵欄位(含公式原文與標題 "G1") |
|---|---|---|
FTIndexInfoCommon.proto( pkg=FTIndexInfoCommon) | IndexInfo(下載包: FTindexDownloadRsp.#3 items) | #1 guid (string)|#2 is_main_view (bool)|#3 index_func_param(參數名與預設值)|#5 index_script (string)(G1 公式完整源碼!)|#7 title (FTString: #1 short_cut / #4 traditional / #5 customize = "G1") |
FTIndexInfoCloudSyncVer.proto( pkg=FTScriptIndex) | FTIndexInfo | #2 strGUID (string)|#4 arIndexFuncParam|#6 strIndexScript (string)(公式完整源碼!)|#8 strTitle (FTString) |
FTPythonIndicatorLocalInfo.proto | PythonIndicatorLocalInfo | #1 guid (string)|#2 script (string)(若 G1 為 Python 指標) |
零侵入唯讀定位法(不 attach、不重啟、不洩露 UID/帳號路徑):查看 ls -l /proc/1167794/fd 找出 FTNN 開啟的本地資料目錄(如 SQLite/LevelDB/Index 快取檔),用唯讀 Python 掃描含字串 T1 與 O1(或解析 IndexInfo.#5 index_script)即可直接讀出 G1 公式原文(例如究竟係 REF(O,1)/REF(C,1) 上一根已收 K 線、Heikin-Ashi 均值 (O+H+L+C)/4、抑或特定自訂週期運算;注意公開報告只摘錄純公式邏輯,切勿帶出 uid 或帳戶路徑)。
Bit 10001 與 Bit 20 完整嵌套結構(注意 TimeSharePoint 欄位號與 KlineItem 完全不同!)Bit 20 (TimeSharingPlans.#1 point) 型別係 FTCmdKline.TimeSharePoint,其價量欄位編號為 #2 close, #3 volume, #4 turnover, #5 open, #6 highest, #7 lowest——與 KlineItem(#3 close, #4 open, #5 highest, #6 lowest, #7 volume, #8 turnover)完全錯位!若誤用 KlineItem 映射讀 Bit 20,會將 volume 誤讀為 close、turnover 誤讀為 open。
| 通道 | 外層 Message(FTCmdStockQuoteAccumulateData.proto) | 內層欄位與週期判定依據 |
|---|---|---|
SubscribeBit = 10001( SBIT_CUSTOM_KLINE) |
Kline:#1 point_list (repeated KlinePoint)#2 svr_send_to_client_ms (uint64)#3 volume_precision (uint32) |
KlinePoint:• #1 kline_type (uint32)• #6 kline_type_v2 (KlineTypeV2 {#1 base_type, #2 custom_number}) ← 直接給出該自訂 K 線的確切週期(如 base_type=2 [MINUTE], custom_number=N)!• #2 exright_type / #5 exright_type_new• #3 item (FTCmdKline.KlineItem)(#1 time, #3 close, #4 open, #5 high, #6 low, #22 point_type)• #4 kline_time_ms (uint64)|#7 section_type (repeated uint32)(另訂閱請求 BitInfo.#4 prob2_v2 亦為 FTCmdKline.KlineSubProb,可雙重核對訂閱週期。) |
SubscribeBit = 20( TimeSharingPlans,1D 分時模式主力流) |
TimeSharingPlans:#1 point (FTCmdKline.TimeSharePoint)#2 svr_send_to_client_ms (uint64)#3 kline_time_ms (uint64)#4 volume_precision (uint32)#5 exright_type_new (uint32)#6 section_type (repeated uint32) |
TimeSharePoint:• #1 time (uint64, 秒)• #2 close_price (int64, ÷1e9)• #3 volume (uint64)|#12 hp_volume (string)• #4 turnover (uint64)|#13 hp_turnover (string)• #5 open_price (int64, ÷1e9)• #6 highest_price (int64, ÷1e9)• #7 lowest_price (int64, ÷1e9)• #9 exright_type (uint32)|#11 point_type (int32: 1=NORMAL, 2=REPLENISH) |
time 會大於接收時刻 rx_sec?富途分鐘 K 線採棒尾時間戳(bar-end timestamp)慣例(例如 09:30:00–09:31:00 的進行中 1m bar,在 09:30:12 推送時 item.time 已標為 09:31:00,即比 rx_sec 超前最多 1 個週期 period_sec)。kline_type_v2 得週期秒數 P(分時 bit=20 取 P=60):point_type == 2 (POINT_TYPE_REPLENISH) → 標記為補點/預填佔位,不當實盤已收 bar;point_type == 1 (NORMAL) 且 rx_sec < item.time <= rx_sec + P + 5 → 標記為 FORMING_BAR(當前進行中未收盤 bar,絕不可當壞點丟棄!);point_type == 1 (NORMAL) 且 item.time <= rx_sec → 標記為 CLOSED_BAR(已收盤歷史/剛收盤 bar——重點核對 G1 T1/O1/C1 是否對齊最新一根 CLOSED_BAR 以防信號閃爍!)。# 零依賴純 Python 解碼器:同時支援 BitQuote bit=10001 (AccumulateData.Kline) 與 bit=20 (TimeSharingPlans)
def pb_iter(buf: bytes):
i, n = 0, len(buf)
while i < n:
tag, shift = 0, 0
while True:
b = buf[i]; i += 1
tag |= (b & 0x7F) << shift
if not (b & 0x80): break
shift += 7
fn, wt = tag >> 3, tag & 7
if wt == 0:
val, shift = 0, 0
while True:
b = buf[i]; i += 1
val |= (b & 0x7F) << shift
if not (b & 0x80): break
shift += 7
yield fn, wt, val
elif wt == 2:
ln, shift = 0, 0
while True:
b = buf[i]; i += 1
ln |= (b & 0x7F) << shift
if not (b & 0x80): break
shift += 7
yield fn, wt, buf[i:i+ln]; i += ln
elif wt == 1:
yield fn, wt, buf[i:i+8]; i += 8
elif wt == 5:
yield fn, wt, buf[i:i+4]; i += 4
else:
raise ValueError(f"Unsupported wire type {wt}")
def s64(u: int) -> int:
return u - (1 << 64) if u >= (1 << 63) else u
def decode_kline_item(b: bytes) -> dict:
d = {}
for fn, wt, v in pb_iter(b):
if wt == 0:
if fn == 1: d["time"] = v
elif fn in (3, 4, 5, 6, 11):
nm = {3: "close", 4: "open", 5: "high", 6: "low", 11: "last_close"}[fn]
d[nm] = s64(v) / 1e9; d[nm + "_raw"] = s64(v)
elif fn == 7: d["volume"] = v
elif fn == 8: d["turnover"] = v
elif fn == 21: d["trade_section_v2"] = s64(v)
elif fn == 22: d["point_type"] = s64(v)
elif wt == 2 and fn in (24, 25):
d["hp_volume" if fn == 24 else "hp_turnover"] = v.decode("utf-8", "replace")
return d
def decode_timeshare_point(b: bytes) -> dict:
# 注意 TimeSharePoint 編號:#2=close, #3=vol, #4=turnover, #5=open, #6=high, #7=low
d = {}
for fn, wt, v in pb_iter(b):
if wt == 0:
if fn == 1: d["time"] = v
elif fn in (2, 5, 6, 7):
nm = {2: "close", 5: "open", 6: "high", 7: "low"}[fn]
d[nm] = s64(v) / 1e9; d[nm + "_raw"] = s64(v)
elif fn == 3: d["volume"] = v
elif fn == 4: d["turnover"] = v
elif fn == 9: d["exright_type"] = v
elif fn == 11: d["point_type"] = s64(v)
elif wt == 2 and fn in (12, 13):
d["hp_volume" if fn == 12 else "hp_turnover"] = v.decode("utf-8", "replace")
return d
def decode_bitquote_payload(bit: int, data: bytes) -> dict:
if bit == 10001:
pts, svr_ms, vprec = [], None, None
for fn, wt, v in pb_iter(data):
if fn == 1 and wt == 2:
kp = {}
for kfn, kwt, kv in pb_iter(v):
if kwt == 0:
if kfn == 1: kp["kline_type"] = kv
elif kfn == 2: kp["exright_type"] = kv
elif kfn == 4: kp["kline_time_ms"] = kv
elif kfn == 5: kp["exright_type_new"] = kv
elif kwt == 2:
if kfn == 3: kp["item"] = decode_kline_item(kv)
elif kfn == 6:
kt2 = {}
for tfn, twt, tv in pb_iter(kv):
if twt == 0 and tfn in (1, 2):
kt2["base_type" if tfn == 1 else "custom_number"] = tv
kp["kline_type_v2"] = kt2
pts.append(kp)
elif fn == 2 and wt == 0: svr_ms = v
elif fn == 3 and wt == 0: vprec = v
return {"bit": 10001, "svr_send_to_client_ms": svr_ms, "volume_precision": vprec, "points": pts}
elif bit == 20:
out = {"bit": 20}
for fn, wt, v in pb_iter(data):
if fn == 1 and wt == 2: out["point"] = decode_timeshare_point(v)
elif fn == 2 and wt == 0: out["svr_send_to_client_ms"] = v
elif fn == 3 and wt == 0: out["kline_time_ms"] = v
elif fn == 4 and wt == 0: out["volume_precision"] = v
elif fn == 5 and wt == 0: out["exright_type_new"] = v
return out
return {"bit": bit, "raw_len": len(data)}