跳轉到

api 物件結構

所屬章節:入門 以 2026-08-20 實際執行結果為準

Overview

so.login() 回傳的物件上掛好這些命名空間,登入時建立。本版不含即時行情訂閱(api 上沒有 SWQuote / Quote / USQuote / FutQuote)。

Manual Sample Input/Output

Example 1:完整屬性表

input

for n in sorted(n for n in dir(api) if not n.startswith('_')):
    print(f"{n:12} {type(getattr(api, n)).__name__}")

output

Block        Block
Data         _DataObj
MSMP         _MSMP
USData       _USDataObj
USMSMP       _MSMP
bt           SecureMain
login        method
logout       method
person_id    str
person_pwd   str
type         str

Example 2:各命名空間的方法

input

print(api.Block)

output

Block(積木)
  台股  get_table_tw()  con_tw()  screener_tw()
  美股  get_table_us()  con_us()  screener_us()

input

[n for n in dir(api.Data) if not n.startswith('_')]
[n for n in dir(api.USData) if not n.startswith('_')]

output

['get', 'get_table']                       # 台股:無 get_snapshots
['get', 'get_snapshots', 'get_table']      # 美股:有 get_snapshots

input

[n for n in dir(api.bt) if not n.startswith('_')]

會用到的四個

['Core', 'Tools', 'config', 'generate_report']

Core 寫策略、config 設商品規格與成本、generate_report 產報表、Tools 是取資料與參數尋優。用法見 backtest.md 起五頁。


SnowyOwl 的能力邊界

功能 SnowyOwl
表格查詢 api.Data / api.USData 有
矩陣資料 api.MSMP / api.USMSMP 有(另有 MSMP._fut_TXF:台指期 1 分 K,9.3 年)
積木選股 api.Block 有(台股 405 個、美股 260 個積木)
回測 api.bt 有(backtest_plus)
即時行情訂閱(推送) 沒有,api 上不存在 SWQuote / Quote / USQuote / FutQuote
盤中快照(拉取式) 美股 api.USData.get_snapshots();台股用 api.Data.get() 分K查詢
下單 / 帳務 沒有,api 上不存在 Order

api 上沒有 Order,也沒有 CA 憑證流程——SnowyOwl 是資料、選股與回測用的, 不做交易委託。要下單得用另外的下單套件。