拋棄繁瑣的 DLL 與 COM 元件。Unitrade 提供純粹、現代化的 Python 介面,支援國內期貨、選擇權與海外期貨的極速下單與即時報價。
import unitrade
from unitrade.unitrade import *
from unitrade.quote.ddata import *
# 1. 快速登入 (支援測試環境)
api = Unitrade()
api.login(
url=URL_TEST,
user="登入帳號",
password="登入密碼",
ca_filename="憑證檔名",
ca_password="憑證密碼"
)
# 2. 監聽即時報價
def on_tick_data_trade(tick: DTickDataTrade):
print(tick)
api.dquote.on_tick_data_trade=on_tick_data_trade
api.dquote.subscribe_trade_bid_offer("TXFL6")
# 3. 極速下單 (大台指/買進/市價/1口)
order = DOrderObject()
order.actno = actno#帳號
order.productid = "TXFL6"#商品代號
order.bs = "B"#買賣別B/S
order.ordertype = "L"#L:限價 M:市價 P:範圍市價
order.price = 28000#委託價格
order.orderqty = 1#數量
order.ordercondition = "R"##委託種類 I:IOC R:ROD F:FOK
order.opencloseflag = ""##開倉別 str 0:新倉 1:平倉 空白:自動
order.dtrade="N"## Y:當沖 N:非當沖
orderresponse=api.dtrade.order(order)
專為需要低延遲與高穩定性的交易者設計
底層優化核心,支援國內和國外期貨。即時回報系統確保您不錯過任何成交資訊。
完整的 Event 機制,讓您的策略能精準回應盤中變化,同時處理報價與下單。
無論是 Windows 開發環境,還是 Linux 交易伺服器,Unitrade 都能完美運行。支援 Python 3.7+。
只需五個步驟,即可開始您的程式交易之旅
pip install unitrade