內期交易 負責下單,改單,回報接收,回報查詢
DTrade Objects
class DTrade()
on_error
錯誤事件
on_connected
連線成功事件
on_disonnected
斷線事件
on_reply
回報接收事件..傳入物件:DOrderReply
on_match
成回接收事件..傳入物件:DOrderReply
get_current_server
def get_current_server()
目前連結主機IP 和 PORT
Returns
Name | Type | Description |
---|---|---|
host | str | 主機IP |
port | str | 主機Port |
get_server_list
def get_server_list()
透過可連結主機
Returns dict[Server]
Name | Type | Description |
---|---|---|
key | str | servername |
value | Server | Server ip:str / port:int |
set_sever_by_name
def set_sever_by_name(servername)
透過主機名稱連結主機
Parameters
Name | Type | Description |
---|---|---|
servername | str | 主機名稱 |
order
def order(obj: DOrderObject) -> DOrderResponse
下單
Parameters
Name | Type | Description |
---|---|---|
obj | DOrderObject | 下單物件 |
Returns
DOrderResponse
Name | Type | Description |
---|---|---|
ok | bool | True 成功 /False 失敗 |
errorcode | str | 錯誤代碼 |
errormsg | str | 錯誤訊息 |
replace_order
def replace_order(obj: DReplaceObject) -> DOrderResponse
改單
Parameters
Name | Type | Description |
---|---|---|
obj | DReplaceObject | 改單物件 |
Returns
DOrderResponse
Name | Type | Description |
---|---|---|
ok | bool | True 成功 /False 失敗 |
errorcode | str | 錯誤代碼 |
errormsg | str | 錯誤訊息 |
query_reply
def query_reply(actno, num_of_query, network_id_start, network_id_end,
begin_order_time, end_order_time) -> DQueryReplyResponse
查詢委託回報
Parameters
Name | Type | Description |
---|---|---|
actno | str | 帳號 |
networkid_st | str | 網路單號起 |
networkid_ed | str | 網路單號迄 |
beginOrderTime | str | 委託時間起 |
endOrderTime | str | 委託時間迄 |
Returns
QueryReplyResponse
Name | Type | Description |
---|---|---|
ok | bool | True 成功 /False 失敗 |
error | str | 錯誤訊息 |
data | List of OrderReply | 回報集合 |
query_match
def query_match(actno, num_of_query, network_id_start, network_id_end,
begin_match_time, end_match_time) -> DQueryMatchResponse
查詢成交回報
Parameters
Name | Type | Description |
---|---|---|
actno | str | 帳號 |
networkid_st | str | 網路單號起 |
networkid_ed | str | 網路單號迄 |
begin_match_time | str | 成交時間起 |
end_match_time | str | 成交時間迄 |
Returns
QueryReplyResponse
Name | Type | Description |
---|---|---|
ok | bool | True 成功 /False 失敗 |
error | str | 錯誤訊息 |
data | List of MatchReply | 成回集合 |
close
def close()
關閉物件
nav_order: 2 parent: API Reference
title: “dtrade” —
內期交易物件
DOrderReply Objects
class DOrderReply()
委託回報物件
brokerid
分公司 str
investoracno
帳號 str
networkid
網路流水序號 str
ordertime
委託時間 str
orderno
委託書號 str
subact
子帳 str
productkind
商品類別 str (1:期貨 2:選擇權 3:複式選擇權 4:複式期貨)
productid
商品代碼 str
bs
買賣別 str B:買進 S:賣出
ordertype
價格別 str (L:限價 M:市價 P:範圍市價)
price
委託價格 float
orderqty
委託數量 str
nomatchqty
未成交數量
matchqty
成交數量 int
delqty
刪除數量 int
ordercondition
委託種類 I:IOC R:ROD F:FOK
opencloseflag
開倉別 str 0:新倉 1:平倉 空白:自動
tradedate
交易日期 str
note
備註 str
mdate
異動時間 str
orderstatus
委託狀態 str
statuscode
委託狀態碼 str
seq
下單序號 str
DMatchReply Objects
class DMatchReply()
成交回報物件
brokerid
分公司 str
investoracno
帳號 str
networkid
網路流水序號 str
matchtime
成交時間 str
orderno
委託書號 str
subact
子帳 str
productkind
商品類別 str(1:期貨 2:選擇權 3:複式選擇權 4:複式期貨)
productid
商品代碼 str
bs
買賣別 str B:買進 S:賣出
matchprice
成交價格 float
matchqty
成交口數 int
matchseq
成交序號 str
matchpricefoot1
成交價1 float
matchpricefoot2
成交價2 float
note
備註 str
mdate
異動時間 str
brokerid
分公司 str
investoracno
帳號 str
networkid
網路流水序號 str
matchtime
成交時間 str
orderno
委託書號 str
subact
子帳 str
productkind
商品類別 str(1:期貨 2:選擇權 3:複式選擇權 4:複式期貨)
productid
商品代碼 str
bs
買賣別 str B:買進 S:賣出
matchprice
成交價格 float
matchqty
成交口數 int
matchseq
成交序號 str
matchpricefoot1
成交價1 float
matchpricefoot2
成交價2 float
note
備註 str
mdate
異動時間 str
DOrderObject Objects
@dataclass
class DOrderObject()
下單物件
actno
帳號 str
subactno
子帳 str
productid
商品代號 str
bs
買賣別 str B:買進 S:賣出
ordertype
下單方式 str L:限價 M:市價 P:範圍市價
price
委託價格 float
orderqty
委託數量 int
ordercondition
委託種類 str I:IOC R:ROD F:FOK
opencloseflag
新平倉碼 str 0:新倉 1:平倉 空白:自動
dtrade
當沖碼 str Y:當沖 N:非當沖
note
備註 str:限10碼非中文
DReplaceObject Objects
@dataclass
class DReplaceObject()
改單物件
replacetype
修改方式 str4:取消, 5: 減量, m:改價
actno
帳號 str
orderno
委託書號 str
ordercondition
委託種類 str I:IOC R:ROD F:FOK
ordertype
下單方式 str L:限價 M:市價 P:範圍市價
price
委託價格 float
orderqty
委託數量 int
note
備註 str:限10碼非中文
DOrderResponse Objects
@dataclass
class DOrderResponse()
下單回覆物件
issend
是否送出 bool
errorcode
錯誤代碼 str
errormsg
錯誤訊息 str
note
下單傳入備註 str
seq
下單序號 str
DQueryReplyResponse Objects
@dataclass
class DQueryReplyResponse()
委託回報查詢回覆物件
ok
是否成功 bool
error
錯誤訊息 str
data
回報集合 List[OrderReply]
DQueryMatchResponse Objects
@dataclass
class DQueryMatchResponse()
成交回報查詢回覆物件
ok
是否成功 bool
error
錯誤訊息 str
data
成回集合 List[MatchReply]