close

 

 

康和期貨股份有限公司

國內期貨

API

規格說明書

Ver 2.0

 

 

 

2017418
中菲電腦國內期貨API規格說明書 目錄

一、國內期貨API  函數、屬性列表

1

系統登入Login()

2

系統登出Logout()

3

取得商品基數getCntsize()

4

執行商品檔excuteINIDATA()

5

取得部位getPosition()

6

委託送單Ordersend()

7

委託刪單cancelSend()by 委託書號

8

委託減量deleteSend()by 委託書號

9

取得working B getWB()

10

取得working S getWS()

11

取得成交回報明細matchReplyData() 新增組合方式欄位(multipleName)

12

取得委託回報明細orderReplyData()新增組合方式欄位(multipleName)

13

取得期貨商品檔FutureData()

14

取得選擇權商品檔OptionData()

15

行情五檔資料MarketInfoData()

16

行情成交資料MarketInfoDataMatch()

17

取得登入狀態loginStatus()

18

取得錯誤資訊Error()

19

取得登入狀態旗標loginStatusFlag

20

取得使用者帳戶UserOrderSet

21

行情註冊商品regItem()

22

行情反註冊商品unRegItem()

23

執行委託回報歷史查詢DoOrderReplyData

24

執行成交回報歷史查詢DoMatchReplyData

25

取得委託回報歷史資料QueryHOrderReply新增組合方式欄位(multipleName)

26

取得成交回報歷史資料QueryHMatchReply新增組合方式欄位(multipleName)

27

憑證路徑CertFileName

28

憑證密碼CertPassword

29

憑證測試testEkeySign()

30

行情連線MarketInfoConnection

31

交易連線TradeConnection

32

交易回報連線ReplyConnection

33

行情註冊連線RegisterConnection

34

帳務委託連線AccountRequestConnection

35

帳務回報連線AccountReplyConnection

36

即時更新帳務RefreshPosition()

37

複式單委託送單SpreadOrderSend ()

38

改價委託下單ChangePrice()

39

盤前虛擬行情五檔資料BMarketInfoData()

40

盤前虛擬行情成交資料BMarketInfoDataMatch()

使用說明

1. 安裝元件

2. 如何使用元件

        2.1 Excel VBA

3.注意事項

國內期貨API規格說明書

 

一、國內期貨API  函數列表

1.系統登入Login()

函式

Login (ByVal userid_id As String,

ByVal password_pass As String,

ByVal webservice  As String,

)

輸入

Uerid  登入帳號

Password 登入密碼

Webservice 網路服務位置

回傳

說明

登入成功後,loginStatusFlag屬性為true系統啟動,即可接收行情、接收主動回報

 

2.系統登出Logout()

函式

Logout ()

輸入

回傳

說明

登出成功後,loginStatusFlag屬性為false,系統關閉

 

3.取得商品基數getCntsize()

函式

getCntsize (ByVal item As String) As integer

輸入

item  商品代號

回傳

正常:商品基數,ex TXFJ9 =200

錯誤: 0

說明

取得商品基數

 

4.執行商品檔excuteINIDATA ()

函式

excuteINIDATA ()

輸入

回傳

說明

執行成功,觸發FutureData()OptionData() event,取商品檔資訊

 

5.取得部位  getPostion ()

函式

getPostion (ByVal ACTNO As String

, ByVal Productid As String) As integer

輸入

ACTNO 帳戶

Productid 商品代號

回傳

該商品留倉部位

說明

取得該商品留倉部位

 

6.委託送單 Ordersend()by 委託書號

函式

Ordersend (

ByVal ACTNO As String

ByVal ProductId As String

ByVal BS As String

ByVal price As String

ByVal ORDQTYAs String

ByVal effTypeAs String

ByVal OpenOffSetFlag As String

 

)

輸入

ACTNO 帳戶

ProductId 商品代號

BS 買賣別

Price 委託價格 price=0 為市價單

ORDQTY 口數

effType 委託種類   exR(ROD)F(FOK)I(IOC)

OpenOffSetFlag 下單種類 ex:期貨-“”(空白):自動、2:當沖 、選擇權-“”(空白):自動

回傳

說明

委託下單

 

7.委託刪單cancelSend ()by 委託書號

屬性

cancelSend (

ByVal ACTNO As String

ByVal PorductId As String

ByVal Orderno As String

ByVal BS As String

ByVal price As String

)  

輸入

ACTNO 帳戶

ProductId 商品代號

Orderno 委託書號

BS 買賣別

Price 委託價格

 

回傳

說明

委託書號刪單

 

8.委託減量 deleteSend() by 委託書號

屬性

deleteSend (

ByVal ACTNO As String

ByVal PorductId As String

ByVal Orderno As String

ByVal BS As String

ByVal price As String

ByVal ORDQTYAs String

)

輸入

ACTNO 帳戶

ProductId 商品代號

Orderno 委託書號

BS 買賣別

Price 委託價格

ORDQTY 口數

回傳

 

說明

委託書號減量

 

 

9.取得working B getWB ()

函式

getWB (ByVal ACTNO As String

, ByVal Productid As String) As integer

輸入

ACTNO 帳戶

ProductId 商品代號

回傳

取得working 口數

說明

取得該商品之working 口數

 

 

10.取得working S getWS ()

函式

getWS (ByVal ACTNO As String

, ByVal Productid As String) As integer

輸入

ACTNO 帳戶

ProductId 商品代號

回傳

取得working 口數

說明

取得該商品之working 口數

 

11.取得成交回報明細(Event) matchreplyData()

函式

matchreplyData (ByVal  investorAcno As String

, ByVal  orderNo As String

, ByVal  matchTime  As String

, ByVal  BS As String

, ByVal  productId As String

, ByVal  MatchPrice As String

, ByVal  MatchQty As String

, ByVal  netWorkId As String

, ByVal  productKind As String

, ByVal  matchseq As String

, ByVal multipleName As String

, ByVal  tradedate As String

, ByVal ORDERKIND As String

 

)

輸入

回傳

investorAcno  帳戶

orderNo  委託書號

matchTime  成交時間

BS   買賣別

productId  商品代號

MatchPrice  成交價格

MatchQty 成交口數

netWorkId  網路流水序號

productKind  商品類別

matchseq 成交序號

multipleName組合方式

tradedate 交易日期

ORDERKIND 盤別 1 一般、2盤後

說明

當有成交回報時,會觸發matchreplyData event

注意

If Application.Ready = True Then

 Your code ……………………….

End if

Ex:

If Application.Ready = True Then

  Cells(15, 1) = objAPI.getPosition("XXXXXX", "TXFK9")

  count4 = count4 + 1

Sheets("Sheet5").Cells(count4, 1) = investorAcno

Sheets("Sheet5").Cells(count4, 2) = orderNo

Sheets("Sheet5").Cells(count4, 3) = matchTime

Sheets("Sheet5").Cells(count4, 4) = BS

Sheets("Sheet5").Cells(count4, 5) = ProductId

Sheets("Sheet5").Cells(count4, 6) = MatchPrice

Sheets("Sheet5").Cells(count4, 7) = matchQty

Sheets("Sheet5").Cells(count4, 8) = netWorkId

Sheets("Sheet5").Cells(count4, 9) = productKind

Sheets("Sheet5").Cells(count4, 10) = matchseq

Sheets("Sheet5").Cells(count4, 11) =multipleName

        

  End If

 

12.取得委託回報明細orderReplyData()

函式

orderReplyData

 (ByVal investorAcno As String

, ByVal orderNo As String

, ByVal orderTime As String

, ByVal bs As String

, ByVal  productId As String

, ByVal matchQty As String

, ByVal NoMatchQty As String

, ByVal DelQty As String

, ByVal orderStatus As String

, ByVal Statuscode As String

, ByVal netWorkId As String

, ByVal orderPrice As String

, ByVal orderQty As String

, ByVal OpenOffSetFlag As String

, ByVal OrderCondition As String

, ByVal dtrade As String

, ByVal mdate As String , ByVal multipleName As String

, ByVal  tradedate As String

, ByVal ORDERKIND As String

)

輸入

 

回傳

帳戶 investorAcno

委託書號 orderNo

委託時間 orderTime

買賣別 BS   

商品代號productId 

成交數量 matchQty

沒成交數量 NoMatchQty

刪除數量DelQty

委託狀態orderStatus

委託狀態CODE Statuscode

網路流水序號netWorkId 

委託價格 orderPrice 

委託數量orderQty

新平倉碼OpenOffSetFlag 

委託狀況OrderCondition 

當沖碼dtrade

回傳時間mdate

組合方式, multipleName

tradedate 交易日期

ORDERKIND 盤別 1 一般、2盤後

說明

當有委託回報時,會觸發orderReplyData event

注意

If Application.Ready = True Then

 Your code ……………………….

End if

Ex:

If Application.Ready = True Then

 

    Cells(15, 2) = objAPI.getWB("0000016", "TXFK9")

      Cells(15, 3) = objAPI.getWS("0000016", "TXFK9")

  count3 = count3 + 1

  Sheets("Sheet4").Cells(count3, 1) = orderNo

    Sheets("Sheet4").Cells(count3, 2) = orderTime

Sheets("Sheet4").Cells(count3, 3) = bs

Sheets("Sheet4").Cells(count3, 4) = productId 

    Sheets("Sheet4").Cells(count3, 5) = matchQty

    Sheets("Sheet4").Cells(count3, 6) = NoMatchQty

    Sheets("Sheet4").Cells(count3, 7) = DelQty

    Sheets("Sheet4").Cells(count3, 8) = orderStatus

    Sheets("Sheet4").Cells(count3, 9) = Statuscode

    Sheets("Sheet4").Cells(count3, 10) = netWorkId

    Sheets("Sheet4").Cells(count3, 11) = orderPrice

    Sheets("Sheet4").Cells(count3, 12) = orderQty

    Sheets("Sheet4").Cells(count3, 13) = OpenOffSetFlag

    Sheets("Sheet4").Cells(count3, 14) = OrderCondition

    Sheets("Sheet4").Cells(count3, 15) = dtrade

    Sheets("Sheet4").Cells(count3, 16) = mdate

Sheets("Sheet4").Cells(count3, 17) = multipleName

 

 

  End If

 

 

13.取得期貨商品檔FutureData()

函式

FutureData (

ByVal Class As String

, ByVal COMMODITYID As String

, ByVal desc As String

, ByVal month As String

, ByVal MaxPrice As String

, ByVal MinPrice As String

)

輸入

回傳

 

商品類別 Class

商品代號COMMODITYID

商品描述desc 

年月month  

漲停價MaxPrice

跌停價MinPrice

說明

當執行excuteINIDATA method 時,會觸發FutureData  event

注意

If Application.Ready = True Then

 Your code ……………………….

End if  

Ex:

   If Application.Ready = True Then

       count1 = count1 + 1

    Sheets("Sheet2").Cells(count1, 1) = Class

    Sheets("Sheet2").Cells(count1, 2) = COMMODITYID

    Sheets("Sheet2").Cells(count1, 3) = desc

    Sheets("Sheet2").Cells(count1, 4) = month

    Sheets("Sheet2").Cells(count1, 5) = MaxPrice

    Sheets("Sheet2").Cells(count1, 6) = MinPrice

    Sheets("Sheet2").Cells(count1, 7) = objAPI.getCntsize(Class)

 

   End If

 

14.取得選擇權商品檔OptionData()

函式

OptionData (

ByVal Class As String

, ByVal COMMODITYID As String

, ByVal desc As String

, ByVal month As String

, ByVal cp As String

, ByVal stikeprice As String

, ByVal MaxPrice As String

, ByVal MinPrice As String

)

 

輸入

 

回傳

商品類別 Class

商品代號COMMODITYID

商品描述desc 

年月month 

CP

履約價 strikeprice

漲停價MaxPrice

跌停價MinPrice

說明

當執行excuteINIDATA method 時,會觸發OptionData event

注意

If Application.Ready = True Then

 Your code ……………………….

End if 

Ex:

   If Application.Ready = True Then

     count2 = count2 + 1

    Sheets("Sheet3").Cells(count2, 1) = Class

    Sheets("Sheet3").Cells(count2, 2) = COMMODITYID

    Sheets("Sheet3").Cells(count2, 3) = desc

    Sheets("Sheet3").Cells(count2, 4) = month

    Sheets("Sheet3").Cells(count2, 5) = cp

    Sheets("Sheet3").Cells(count2, 6) = strikePrice

    Sheets("Sheet3").Cells(count2, 7) = MaxPrice

    Sheets("Sheet3").Cells(count2, 8) = MinPrice

    Sheets("Sheet3").Cells(count2, 9) = objAPI.getCntsize(Class)

   End If

15.行情五檔資料MarketInfoData()

函式

MarketInfoData (ByVal COMMODITYID As String

, ByVal BP1 As String

, ByVal BP2 As String

, ByVal BP3 As String

, ByVal BP4 As String

, ByVal BP5 As String

, ByVal BQ1 As String

, ByVal BQ2 As String

, ByVal BQ3 As String

, ByVal BQ4 As String

, ByVal BQ5 As String

, ByVal SP1 As String

, ByVal SP2 As String

, ByVal SP3 As String

, ByVal SP4 As String

, ByVal SP5 As String

, ByVal SQ1 As String

, ByVal SQ2 As String

, ByVal SQ3 As String

, ByVal SQ4 As String

, ByVal SQ5 As String

);

 

輸入

回傳

商品代號 COMMODITYID 

第一檔委買價格BP1

第二檔委買價格BP2

第三檔委買價格BP3

第四檔委買價格BP4

第五檔委買價格BP5

第一檔委買數量BQ1

第二檔委買數量BQ2

第三檔委買數量BQ3

第四檔委買數量BQ4

第五檔委買數量BQ5

第一檔委賣價格SP1

第二檔委賣價格SP2

第三檔委賣價格SP3

第四檔委賣價格SP4

第五檔委賣價格SP5

第一檔委買數量SQ1

第二檔委買數量SQ2

第三檔委買數量SQ3

第四檔委買數量SQ4

第五檔委買數量SQ5

說明

接收到行情五檔會觸發MarketInfoData event

注意

If Application.Ready = True Then

 Your code ……………………….

End if 

EX:

If Application.Ready = True Then

If COMMODITYID = "TXFJ9" Then

  

    Cells(15, 5) = SP1

    Cells(14, 5) = SP2

    Cells(13, 5) = SP3

    Cells(12, 5) = SP4

    Cells(11, 5) = SP5

    Cells(17, 5) = BP1

    Cells(18, 5) = BP2

    Cells(19, 5) = BP3

    Cells(20, 5) = BP4

    Cells(21, 5) = BP5

   

    Cells(15, 6) = SQ1

    Cells(14, 6) = SQ2

    Cells(13, 6) = SQ3

    Cells(12, 6) = SQ4

    Cells(11, 6) = SQ5

    Cells(17, 4) = BQ1

    Cells(18, 4) = BQ2

    Cells(19, 4) = BQ3

    Cells(20, 4) = BQ4

    Cells(21, 4) = BQ5

End If

   

End If

 

16.行情成交資料MarketInfoDataMatch()

函式

MarketInfoDataMatch (ByVal COMMODITYID As String

,ByVal  MatchTime      As String 

,ByVal  MatchPrice  As String 

,ByVal  MatchBuyCnt  As String 

,ByVal  MatchSellCnt  As String 

,ByVal  MatchQuantity  As String 

,ByVal  MatchTotalQty  As String  )

 

輸入

回傳

商品代號 COMMODITYID

成交時間 MatchTime

成交價格MatchPrice 

成交買量MatchBuyCnt

成交賣量MatchSellCnt

成交量MatchQuantity 

成交總量MatchTotalQty 

說明

接收到行情成交會觸發MarketInfoDataMatch event
注意

If Application.Ready = True Then

 Your code ……………………….

End if 

Ex:

If Application.Ready = True Then

    If COMMODITYID = "TXFJ9" Then

      

     Cells(16, 5) = MatchPrice

    

    End If

End If

 

17.取得登入狀態loginStatus()

函式

loginStatus (ByVal msg As String)

 

輸入

回傳

登入、登出狀態資訊msg

說明

當登入或登出時,會觸發loginStatus event

 

18.取得錯誤資訊 Error()

函式

Error (ByVal msg As String)

輸入

回傳

錯誤資訊 msg

說明

當有例外錯誤訊息發生時,會觸發Error Event

 

19.取得登入狀態旗標 loginStatusFlag

屬性

loginStatusFlag  As Boolean

輸入

回傳

當登入成功時 loginStatusFlag  =true

當登入失敗時 loginStatusFlag  =false

說明

取得登入狀態旗標

 

20.取得使用者帳戶UserOrderSet

屬性

UserOrderSet  As String ()

輸入

回傳

使用者帳戶 UserOrderSet  

說明

取得使用者帳戶

 

21.行情註冊商品regItem()

函式

regItem  (ByVal Item As String)

輸入

商品ID Item

回傳

說明

行情註冊

22.行情反註冊商品unregItem()

函式

regItem  (ByVal Item As String)

輸入

商品ID Item

回傳

說明

行情反註冊

23.執行委託回報歷史查詢DoOrderReplyData()

函式

DoOrderReplyData(ByVal investorAcno As String ByVal orderno_st As StringByVal orderno_ed As String)  

輸入

帳戶 investorAcno

委託書號起 orderno_st

委託書號迄orderno_ed

回傳

說明

執行委託回報歷史查詢

 

24.執行成交回報歷史查詢DoMatchReplyData()

函式

DoMatchReplyData (ByVal investorAcno As String ByVal orderno_st As StringByVal orderno_ed As String)  

輸入

帳戶 investorAcno

委託書號起 orderno_st

委託書號迄orderno_ed

回傳

說明

執行成交回報歷史查詢

 

25.取得委託回報歷史資料QueryHOrderReply()

函式

QueryHOrderReply (ByVal investorAcno As String

, ByVal orderNo As String

, ByVal orderTime As String

, ByVal matchQty As String

, ByVal NoMatchQty As String

, ByVal DelQty As String

, ByVal orderStatus As String

, ByVal Statuscode As String

, ByVal netWorkId As String

, ByVal orderPrice As String

, ByVal orderQty As String

, ByVal OpenOffSetFlag As String

, ByVal OrderCondition As String

, ByVal dtrade As String

, ByVal mdate As String

,ByVal multipleName As String

, ByVal  tradedate As String

, ByVal ORDERKIND As String)

輸入

 

回傳

帳戶 investorAcno

委託書號 orderNo

委託時間 orderTime

成交數量 matchQty

沒成交數量 NoMatchQty

刪除數量DelQty

委託狀態orderStatus

委託狀態CODE Statuscode

網路流水序號netWorkId 

委託價格 orderPrice 

委託數量orderQty

新平倉碼OpenOffSetFlag 

委託狀況OrderCondition 

當沖碼dtrade

回傳時間mdate

組合方式multipleNme

tradedate 交易日期

ORDERKIND 盤別 1 一般、2盤後

說明

當有委託回報時,會觸發QueryHOrderReply event

注意

If Application.Ready = True Then

 Your code ……………………….

End if

Ex:

If Application.Ready = True Then

        count5 = count5 + 1

 

    Sheets("歷史委託回報").Cells(count5, 1) = orderNo

    Sheets("歷史委託回報").Cells(count5, 2) = orderTime

    Sheets("歷史委託回報").Cells(count5, 3) = BS

    Sheets("歷史委託回報").Cells(count5, 4) = productId

    Sheets("歷史委託回報").Cells(count5, 5) = matchQty

    Sheets("歷史委託回報").Cells(count5, 6) = NoMatchQty

    Sheets("歷史委託回報").Cells(count5, 7) = DelQty

    Sheets("歷史委託回報").Cells(count5, 8) = orderStatus

    Sheets("歷史委託回報").Cells(count5, 9) = Statuscode

    Sheets("歷史委託回報").Cells(count5, 10) = netWorkId

    Sheets("歷史委託回報").Cells(count5, 11) = orderPrice

    Sheets("歷史委託回報").Cells(count5, 12) = orderQty

    Sheets("歷史委託回報").Cells(count5, 13) = OpenOffSetFlag

    Sheets("歷史委託回報").Cells(count5, 14) = OrderCondition

    Sheets("歷史委託回報").Cells(count5, 15) = dtrade

    Sheets("歷史委託回報").Cells(count5, 16) = mdate

Sheets("歷史委託回報").Cells(count5, 17) = multipleNme

 

 

  End If

 

26.取得成交回報歷史資料QueryHMatchReply()

函式

QueryHMatchReply (ByVal  investorAcno As String

, ByVal  orderNo As String

, ByVal  matchTime  As String

, ByVal  BS As String

, ByVal  productId As String

, ByVal  MatchPrice As String

, ByVal  MatchQty As String

, ByVal  netWorkId As String

, ByVal  productKind As String

, ByVal  matchseq As String

,ByVal multipleName As String

, ByVal  tradedate As String

, ByVal ORDERKIND As String

)

輸入

回傳

investorAcno  帳戶

orderNo  委託書號

matchTime  成交時間

BS   買賣別

productId  商品代號

MatchPrice  成交價格

MatchQty 成交口數

netWorkId  網路流水序號

productKind  商品類別

matchseq 成交序號

multipleNme組合方式

tradedate 交易日期

ORDERKIND 盤別 1 一般、2盤後

說明

當有成交回報時,會觸發QueryHMatchReplyevent

注意

If Application.Ready = True Then

 Your code ……………………….

End if

Ex:

If Application.Ready = True Then

           count6 = count6 + 1

        Sheets("歷史成交回報").Cells(count6, 1) = investorAcno

        Sheets("歷史成交回報").Cells(count6, 2) = orderNo

        Sheets("歷史成交回報").Cells(count5, 3) = MatchTime

        Sheets("歷史成交回報").Cells(count6, 4) = BS

        Sheets("歷史成交回報").Cells(count6, 5) = productId

        Sheets("歷史成交回報").Cells(count6, 6) = MatchPrice

        Sheets("歷史成交回報").Cells(count6, 7) = matchQty

        Sheets("歷史成交回報").Cells(count6, 8) = netWorkId

        Sheets("歷史成交回報").Cells(count6, 9) = productKind

        Sheets("歷史成交回報").Cells(count6, 10) = matchseq

Sheets("歷史成交回報").Cells(count6, 11) = multipleNme

                  

  End If

27.憑證路徑CertFileName

屬性

CertFileName

輸入

輸入憑證路徑

回傳

取得憑證路徑

說明

當登入成功時,如果是Internet使用者必須輸入憑證路徑

If objAPI Is Nothing Then

      Set objAPI = New DDSCTradeAPI

   

    End If

objAPI.login 88888, 88888, 203.66.1.44

objAPI.CertFileName = "c:\康和"

objAPI.CertPassword = "**********"

 

連線組別如下

internet203.66.1.44

專線:192.168.250.45

 

 

28.憑證密碼CertPassword

屬性

CertPassword

輸入

輸入憑證密碼

回傳

取得憑證密碼

說明

當登入成功時,如果是Internet使用者必須輸入憑證路徑

If objAPI Is Nothing Then

      Set objAPI = New DDSCTradeAPI

   

    End If

objAPI.login 88888, 88888, 203.66.1.44

objAPI.CertFileName = "c:\康和"

objAPI.CertPassword = "**********"

 

連線組別如下

internet203.66.1.44

專線:192.168.250.45

 

 

29.憑證測試testEkeySign()

函式

testEkeySign()

輸入

 

回傳

回傳錯誤訊息 ex 回傳0則簽章成功,其他則否

說明

當登入成功時,如果是Internet使用者必須輸入憑證路徑

If objAPI Is Nothing Then

      Set objAPI = New DDSCTradeAPI

   

    End If

Dim msg As String

   msg = objAPI.testEkeySign

 Cells(5, "B") = msg

 

 

30.行情連線MarketInfoConnection

屬性

MarketInfoConnection

輸入

 

回傳

True or  false

說明

當連線成功時回傳true 否則傳false

 

31.交易連線TradeConnection

屬性

TradeConnection

輸入

 

回傳

True or  false

說明

當連線成功時回傳true 否則傳false

 

 

32.交易回報連線ReplyConnection

屬性

ReplyConnection

輸入

 

回傳

當連線成功時回傳true 否則傳false

 

 

說明

當連線成功時回傳true 否則傳false

 

 

33.行情註冊連線RegisterConnection

屬性

RegisterConnection

輸入

 

回傳

當連線成功時回傳true 否則傳false

 

 

34.帳委託連線AccountRequestConnection

屬性

AccountRequestConnection

輸入

 

回傳

當連線成功時回傳true 否則傳false

 

35.帳務回報連線AccountReplyConnection

屬性

AccountReplyConnection

輸入

 

回傳

當連線成功時回傳true 否則傳false

 

36.即時更新帳務RefreshPosition()

函式

RefreshPosition()

輸入

 

回傳

說明

即時更新帳務

37.複式單委託送單 SpreadOrderSend ()

函式

Ordersend (

ByVal ACTNO As String

ByVal ProductId As String

ByVal BS As String

ByVal price As String

ByVal ML As String

ByVal ORDQTYAs String

ByVal effTypeAs String

ByVal OpenOffSetFlag As String

 

)

輸入

ACTNO 帳戶

ProductId 商品代號

BS 買賣別

Price 委託價格 

ML 市價/限價  M:市價、L:限價

ORDQTY 口數

effType 委託種類   exR(ROD)F(FOK)I(IOC)

OpenOffSetFlag 下單種類 ex:期貨-“”(空白):自動、2:當沖 、選擇權-“”(空白):自動

回傳

說明

複式單委託下單

Call Price Spreads:同時買賣到期日相同但履約價格不同之買權。

Put Price Spreads:同時買賣到期日相同但履約價格不同之賣權。

Call Time Spreads:同時買賣履約價格相同但到期日不同之買權。

Put Time Spreads:同時買賣履約價格相同但到期日不同之賣權。

Straddles:同時買進(或賣出)相同履約價格且到期日相同之買權與賣權。

Strangles:同時買進(或賣出)相同到期日但履約價格不同之買權與賣權。

Conversion /ReversalsConversion賣出買權並買進履約價格且到期日相同之賣權;Reversals買進買權並賣出履約價格且到期日相同之賣權

 

組合規則如下

組合式委託規則

第二支腳減第一支腳。

定義"/"":""-"之規則

"/"規則 S/B B/S 

":"規則 B Call : B Put  S Call : S Put

"-"規則Conversion S Call - B Put  Reversals B Call - S Put 買低賣高

組合式委託代號實例說明

 

交易策略

規則(重點說明)

例子

說明

重點提示

Call price spread:

 

履約價格高者寫於前,履約價格低者寫於後

TXO06500/06300C6

表示買20063月履約價格6300Call;賣20063月履約價格6500Call

S履約價大 

B履約價小

 

備註:作多

TXO06500/06300C6

表示賣20063月履約價格6300Call;買20063月履約價格6500Call

B履約價大

   S履約價小

 

備註:作空

Put price spread

履約價格低者寫於前,履約價格高者寫於後

TXO06300/06500O6

表示買20063月履約價格6500Put;賣20063月履約價格6300Put

S履約價小

   B履約價大

 

備註:作空

TXO06300/06500O6

表示賣20063月履約價格6500Put;買9993月履約價格6300Put

B履約價小

   S履約價大

 

備註:作多

Call time spread

契約年月近者寫於前,契約年月遠者寫於後

TXO06500C6/F6

表示買20063月履約價格6500Call;賣20066月履約價格6500Call

S近期契約年月

B遠期契約年月

TXO06500C6/F6

表示賣20063月履約價格6500Call;買20066月履約價格6500Call

B近期契約年月

S遠期契約年月

Put time spread

契約年月近者寫於前,契約年月遠者寫於後

TXO06300O6/R6

表示買20063月履約價格6300Put;賣20066月履約價格6300Put

 

S近期契約年月

B遠期契約年月

TXO06300O6/R6

表示賣20063月履約價格6300Put;買20066月履約價格6300Put

 

B近期契約年月

S遠期契約年月

Straddle

買權寫於前,賣權寫於後

TXO06300C6:O6

表示買20063月履約價格6300Call;買20063月履約價格6300Put

B 買權 B賣權

TXO06300C6:O6

表示賣20063月履約價格6300Call;賣20063月履約價格6300Put

S 買權 S 賣權

Strangle

 

買權寫於前,賣權寫於後

TXO06300C6:06500O6

表示買20063月履約價格6300Call;買20063月履約價格6500Put

B履約價買權  

 B履約價賣權

TXO06300C6:06500O6

表示賣20063月履約價格6300Call;賣20063月履約價格6500Put

S履約價買權 

  S履約價賣權

Conversion/Reversals

 

 

 

 

買權寫於前,賣權寫於後

Conversion

TXO06300C6-O6

 

表示買20063月履約價格6300Put;賣20063月履約價格6300Call

S買權    B賣權

備註:作空期貨

Reversals

TXO06300C6-O6

表示賣20063月履約價格6300Put;買20063月履約價格6300Call

B買權    S賣權

備註:作多期貨

 

 

 

 

38.務改價委託下單ChangePrice()

函式

ChangePrice(ByVal ACTNO As String

ByVal OrderNo As String

ByVal Price String

ByVal EffType  String

ByVal ML  String

)

輸入

ACTNO帳戶

OrderNo書號

Price價格

EffType 委託種類 exR(ROD)F(FOK)I(IOC)

ML  市價限價 exM/L

回傳

39.盤前虛擬行情五檔資料BMarketInfoData()

函式

BMarketInfoData (ByVal COMMODITYID As String

, ByVal BP1 As String

, ByVal BP2 As String

, ByVal BP3 As String

, ByVal BP4 As String

, ByVal BP5 As String

, ByVal BQ1 As String

, ByVal BQ2 As String

, ByVal BQ3 As String

, ByVal BQ4 As String

, ByVal BQ5 As String

, ByVal SP1 As String

, ByVal SP2 As String

, ByVal SP3 As String

, ByVal SP4 As String

, ByVal SP5 As String

, ByVal SQ1 As String

, ByVal SQ2 As String

, ByVal SQ3 As String

, ByVal SQ4 As String

, ByVal SQ5 As String

);

 

輸入

回傳

商品代號 COMMODITYID 

第一檔委買價格BP1

第二檔委買價格BP2

第三檔委買價格BP3

第四檔委買價格BP4

第五檔委買價格BP5

第一檔委買數量BQ1

第二檔委買數量BQ2

第三檔委買數量BQ3

第四檔委買數量BQ4

第五檔委買數量BQ5

第一檔委賣價格SP1

第二檔委賣價格SP2

第三檔委賣價格SP3

第四檔委賣價格SP4

第五檔委賣價格SP5

第一檔委買數量SQ1

第二檔委買數量SQ2

第三檔委買數量SQ3

第四檔委買數量SQ4

第五檔委買數量SQ5

說明

接收到行情五檔會觸發BMarketInfoData event

注意

If Application.Ready = True Then

 Your code ……………………….

End if 

EX:

If Application.Ready = True Then

If COMMODITYID = "TXFJ9" Then

  

    Cells(15, 5) = SP1

    Cells(14, 5) = SP2

    Cells(13, 5) = SP3

    Cells(12, 5) = SP4

    Cells(11, 5) = SP5

    Cells(17, 5) = BP1

    Cells(18, 5) = BP2

    Cells(19, 5) = BP3

    Cells(20, 5) = BP4

    Cells(21, 5) = BP5

   

    Cells(15, 6) = SQ1

    Cells(14, 6) = SQ2

    Cells(13, 6) = SQ3

    Cells(12, 6) = SQ4

    Cells(11, 6) = SQ5

    Cells(17, 4) = BQ1

    Cells(18, 4) = BQ2

    Cells(19, 4) = BQ3

    Cells(20, 4) = BQ4

    Cells(21, 4) = BQ5

End If

   

End If

40.行情成交資料BMarketInfoDataMatch()

函式

BMarketInfoDataMatch (ByVal COMMODITYID As String

,ByVal  MatchTime      As String  

,ByVal  MatchPrice  As String 

,ByVal  MatchBuyCnt  As String 

,ByVal  MatchSellCnt  As String 

,ByVal  MatchQuantity  As String 

,ByVal  MatchTotalQty  As String  )

 

輸入

回傳

商品代號 COMMODITYID

成交時間 MatchTime

成交價格MatchPrice 

成交買量MatchBuyCnt

成交賣量MatchSellCnt

成交量MatchQuantity 

成交總量MatchTotalQty 

說明

接收到行情成交會觸發BMarketInfoDataMatch event
注意

If Application.Ready = True Then

 Your code ……………………….

End if 

Ex:

If Application.Ready = True Then

    If COMMODITYID = "TXFJ9" Then

      

     Cells(16, 5) = MatchPrice

    

    End If

End If

 

 

四、使用說明

  1. 安裝元件: 執行setup 程式

API1.png

API2.png

API3.png

API4.png

API5.png

2.如何使用元件

2.1 Excel VBA

A. 宣告

宣告共用物件變數

   Public WithEvents objAPI As DDSCTradeAPI

   ‘若物件變數不存在

    If  objAPI  Is Nothing Then

    ‘創造物件

         Set objAPI = New DDSCTradeAPI

    End If

B. 設定行情、委託、成交回報

  VBA -> 工具->設定引用項目,選擇DDSCTrade,

API6.png

   在設計模式下, 選擇objAPIevent選擇所要產生的事件  

“Private Sub objAPI_MarketInfoData” , 當主動回報發生時,便會自動觸發此函數

API7.png

  1. 注意事項
  1. 在使用事件時,請用 If Application.Ready = True Then end if 做判斷
  2. EXCEL版本必須為excel 2003 sp3 以上
arrow
arrow

    小仙女 發表在 痞客邦 留言(0) 人氣()