COCO研究院

 找回密碼
 註冊
搜索
查看: 8603|回復: 12

[API] 群益報價 API + VB2008 求救

[複製鏈接]
發表於 12-7-16 07:57 | 顯示全部樓層 |閱讀模式
各位前輩好,想請問關於群益報價 API + VB2008 的問題....

小弟申請群益報價 API, 範例中的 excel 抓報價可正常使用。

現在想用群益報價 API + VB2008 抓報價,可是卻總是卡在 OnConnectionBack (ByVal Kind As Long, ByVal Code As Long)這裡,程式總是傳回好大一個數字,

?code
376613828076503040

因為 code <>0 結果就顯示『報價中斷』的訊息。

還請有經驗的前輩指導一下,謝謝。

還有,請問到底群益報價 API 中的 config.ini 要放在哪個目錄裡啊?



=================================
    Declare Function SKQuoteLib_Initialize Lib "SKQuoteLib.dll" (ByVal strID As String, ByVal strPass As String) As Integer
    Declare Function SKQuoteLib_EnterMonitor Lib "SKQuoteLib.dll" () As Integer
    Declare Function SKQuoteLib_AttachConnectionCallBack Lib "SKQuoteLib.dll" (ByVal Func As ConnectionCallBack) As Integer
    Declare Function SKQuoteLib_AttachQuoteCallBack Lib "SKQuoteLib.dll" (ByVal Func As QuoteCallBack) As Integer
    Declare Function SKQuoteLib_AttachTicksCallBack Lib "SKQuoteLib.dll" (ByVal Func As TicksCallBack) As Integer
    Declare Function SKQuoteLib_AttachBest5CallBack Lib "SKQuoteLib.dll" (ByVal Func As Best5CallBack) As Integer
    Declare Function SKQuoteLib_RequestStocks Lib "SKQuoteLib.dll" (ByRef Page As Integer, ByVal Stocks As String) As Integer
    Declare Function SKQuoteLib_RequestTicks Lib "SKQuoteLib.dll" (ByRef Page As Integer, ByVal Stock As String) As Integer
    Declare Function SKQuoteLib_GetStockByNo Lib "SKQuoteLib.dll" (ByVal strStockNo As String, ByRef Stock As TSTOCK) As Integer
    Declare Function SKQuoteLib_GetStockByIndex Lib "SKQuoteLib.dll" (ByVal Market As Integer, ByVal Index As Integer, ByRef Stock As TSTOCK) As Integer
    Declare Function SKQuoteLib_GetTick Lib "SKQuoteLib.dll" (ByVal Market As Integer, ByVal Index As Integer, ByVal Ptr As Integer, ByRef Tick As TTick) As Integer
    Declare Function SKQuoteLib_GetBest5 Lib "SKQuoteLib.dll" (ByVal Market As Integer, ByVal Index As Integer, ByRef Best5 As TBest5) As Integer

    Public Delegate Sub ConnectionCallBack(ByVal Kind As Long, ByVal Code As Long)
    Public Delegate Sub QuoteCallBack(ByVal Market As Integer, ByVal Index As Integer)
    Public Delegate Sub TicksCallBack(ByVal Market As Integer, ByVal Index As Integer)
    Public Delegate Sub Best5CallBack(ByVal Market As Integer, ByVal Index As Integer)
.
.(這裡是定義結構的部份)
.

    Public Function Login(ByVal AcNo As String, ByVal Pwd As String) As Integer

        Dim Status As Long
        Status = Status + SKQuoteLib_Initialize(AcNo, Pwd)
        Status = Status + SKQuoteLib_AttachConnectionCallBack(AddressOf OnConnectionBack)
        Status = Status + SKQuoteLib_AttachQuoteCallBack(AddressOf OnQuoteCallBack)
        'Status = Status + SKQuoteLib_AttachTicksCallBack(AddressOf OnTicks)
        'Status = Status + SKQuoteLib_AttachBest5CallBack(AddressOf OnBest5)

        If Status = 0 Then
            Status = SKQuoteLib_EnterMonitor()
            Login = 0
        Else
            Login = -1
        End If

    End Function

    Sub OnConnectionBack(ByVal Kind As Long, ByVal Code As Long)
        If Code = 0 Then
            MsgBox("報價伺服器登入成功!!")
        Else
            MsgBox("報價中斷!!")
            'UserForm1.Show()
        End If
    End Sub
=====================================
發表於 12-7-16 09:40 | 顯示全部樓層
integer   , long 型別轉換不對吧, 或你沒define 變數是integer or long

評分

參與人數 1金錢 +2 收起 理由
indypan + 2 謝謝您的指導,感恩

查看全部評分

發表於 12-7-16 11:08 | 顯示全部樓層
本帖最後由 sangi 於 12-7-16 11:11 編輯

少了 DLLIMPORT...... 請參照下面範例匯入
-----------------------

  ' DLL Import:
    '* 0. SKQuoteLib_Initialize  // 0.初始使用者相關資訊
    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_Initialize(<MarshalAs(UnmanagedType.LPStr)> ByVal lpszLoginID As String, <MarshalAs(UnmanagedType.LPStr)> ByVal lpszPassword As String) As Integer
    End Function

    '* 1.0 SKQuoteLib_AttachConnectionCallBack  // 1.0.向報價函式庫註冊接收連線狀態的 Call back 函式位址
    <UnmanagedFunctionPointer(CallingConvention.StdCall)> _
    Public Delegate Sub FOnNotifyConnection(ByVal nKind As Int32, ByVal nCode As Int32)
    Shared Delegate_AttachConnection As New FOnNotifyConnection(AddressOf CBFunc_AttachConnection)

    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_AttachConnectionCallBack(ByVal Delegate_AttachConnection As FOnNotifyConnection) As Integer
    End Function

    '* 1.1 SKQuoteLib_AttachQuoteCallBack  // 1.1.當有索取的個股報價異動時,將透過此註冊的函式通知應用程式處理
    <UnmanagedFunctionPointer(CallingConvention.StdCall)> _
    Public Delegate Sub FOnNotifyQuote(ByVal sMarketNo As Int16, ByVal sStockidx As Int16)
    Public Shared Delegate_AttachQuote As New FOnNotifyQuote(AddressOf CBFunc_AttachQuote)

    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_AttachQuoteCallBack(ByVal Delegate_AttachQuote As FOnNotifyQuote) As Integer
    End Function

    '* 1.3 SKQuoteLib_AttachBest5CallBack  // 1.3.當有索取的個股五檔價格有所異動,即透過向此註冊的Call back 函式進行處理
    <UnmanagedFunctionPointer(CallingConvention.StdCall)> _
    Public Delegate Sub FOnNotifyBest5(ByVal sMarketNo As Int16, ByVal sStockidx As Int16)
    Shared Delegate_AttachBest5 As New FOnNotifyBest5(AddressOf CBFunc_AttachBest5)

    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_AttachBest5CallBack(ByVal Delegate_AttachBest5 As FOnNotifyBest5) As Integer
    End Function

    '* 2. SKQuoteLib_EnterMonitor  // 2.建立與報價伺服器的連線
    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_EnterMonitor() As Integer
    End Function

    '* END. SKQuoteLib_LeaveMonitor  // END.中斷與報價伺服器的連線
    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_LeaveMonitor() As Integer
    End Function

    '* 3. SKQuoteLib_GetStockByNo  // 3.根據股票代號取得報價資訊
    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
    Public Shared Function SKQuoteLib_RequestStocks(ByRef psPageNo As Int16, ByVal pStockNo As [String]) As Integer
    End Function

    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
    Public Shared Function SKQuoteLib_GetStockByNo(ByVal lpszStockNo As [String], ByRef pStock As TStock) As Integer
    End Function


另外,config.ini 和 SKQuoteLib.dll 直接從VS的方案總管中加入,並在屬性中將[複製到輸出目錄]改成[永遠複製]

評分

參與人數 1金錢 +2 收起 理由
indypan + 2 太強了!

查看全部評分

 樓主| 發表於 12-7-16 17:11 | 顯示全部樓層
sangi 發表於 12-7-16 11:08
少了 DLLIMPORT...... 請參照下面範例匯入
-----------------------

感謝!! 感謝!!

程式功力不好,謝謝您的指導。下班後修改。

謝謝
 樓主| 發表於 12-7-20 15:56 | 顯示全部樓層
sangi 大你好,

我按照您的建議修改,現在可以正常登入,也收得到報價,但是,每次收報價大概幾分鐘後,報價就停掉了,只能重啟程式。我只收大台和小台,收報價的程式碼如下:

請問還有哪裡有錯誤嗎?

謝謝

======================

////在 frmTrade 中的開始收報價按鈕

    Private Sub btnSKQ_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSKQ.Click
        Dim ComIds As String = ""
        Dim Status As Long
        ComIds = "TX00,MTX00"
        Status = SKQuoteLib_RequestStocks(-1, ComIds)
    End Sub

////////// 在 module 中的 callback 函數


    Sub CBFunc_AttachQuote(ByVal Market As Integer, ByVal Index As Integer)
        On Error Resume Next

        Dim Status As Long
        Dim Stock As New TSTOCK
        Dim ComId As String
        Dim Dot As Integer

        Status = SKQuoteLib_GetStockByIndex(Market, Index, Stock)

        ComId = Replace(Stock.aStockNo, Chr(160), "")
        Dot = 10 ^ Stock.Decimal_
        If ComId = "TX00" Then
            frmTrade.lblTxOpen.Text = Stock.Open / Dot
            frmTrade.lblTxNow.Text = Stock.Close / Dot
            frmTrade.lblTxVol.Text = Stock.TQty
        End If

        If ComId = "MTX00" Then
            frmTrade.lblMtxOpen.Text = Stock.Open / Dot
            frmTrade.lblMtxNow.Text = Stock.Close / Dot
            frmTrade.lblMtxVol.Text = Stock.TQty
        End If

    End Sub
===================================
發表於 12-8-1 19:02 | 顯示全部樓層
不說明!自已看,直接複制成class就可以直接使用

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace StockAPI
{
    [StructLayout(LayoutKind.Sequential)]
    public struct STOCK
    {
        public Int16 m_sStockidx; // 系統自行定義的股票代碼
        public Int16 m_sDecimal; // 報價小數位數
        public Int16 m_sTypeNo; // 類股分類
        public byte m_cMarketNo; // 市場代號0x00上市;0x01上櫃;0x02期貨;0x03選擇權;0x04興櫃
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string m_caStockNo; // 股票代號
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
        public string m_caName; // 股票名稱
        public Int32 m_nOpen; // 開盤價
        public Int32 m_nHigh; // 最高價
        public Int32 m_nLow; // 最低價
        public Int32 m_nClose; // 成交價
        public Int32 m_nTickQty; // 單量
        public Int32 m_nRef; // 昨收、參考價
        public Int32 m_nBid; // 買價
        public Int32 m_nBc; // 買量
        public Int32 m_nAsk; // 賣價
        public Int32 m_nAc; // 賣量
        public Int32 m_nTBc; // 買盤量
        public Int32 m_nTAc; // 賣盤量
        public Int32 m_nFutureOI; // 期貨未平倉 OI
        public Int32 m_nTQty; // 總量
        public Int32 m_nYQty; // 昨量
        public Int32 m_nUp; // 漲停價
        public Int32 m_nDown; // 跌停價
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct TTick
    {
        public Int32 m_nPtr; // 資料所在的位置(Key)
        public Int32 m_nTime; // 時間
        public Int32 m_nBid; // 買價
        public Int32 m_nAsk; // 賣價
        public Int32 m_nClose; // 成交價
        public Int32 m_nQty; // 成交量
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct DataItem
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 13)]
        public string caKeyNo;                        // 委託序號
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
        public string caMarketType;       // TS:證券 TA:盤後 TL:零股 TF:期貨 TO:選擇權
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
        public string cType;                // N:委託 C:取消 U:改量 D:成交 Q:報價
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
        public string cOrderErr;             // Y:失敗 T:逾時 N:正常
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
        public string caBroker;           // TS,TA,TL: 分公司代號 unit no , TF,TO: IB 代號 broker id
        [MarshalAs(UnmanagedType.AnsiBStr, SizeConst = 7)]
        public string caCustNo;                        // 交易帳號
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
        public string caBuySell;          // 證[0] B/S 買/賣,[1,2] 00 現股,01 代資,02 代券,03 融資,04 融券,20 零股,40 拍賣現股  
        // 期[0] B/S 買/賣,[1] Y 當沖,         [2] I/R/F  IOC / ROD / FOK
        // 權[0] B/S 買/賣,[1] N/O 新倉 / 平倉,[2] I/R/F  IOC / ROD / FOK
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
        public string caExchangeID;       // 交易所
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string caComId;          // 前13碼商品代號 一個空白 後六碼商品年月
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 13)]
        public string caStrikePrice;       // 履約價 七位整數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]
        public string caOrderNo;                        //  委託書號
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 13)]
        public String caPrice;           // 證券兩位小數, 期貨三位小數,  
        // 期貨委託:9999999999999為市價,
        // 海外期貨,八位整數五位小數
        // 其餘為根據 Type 種類,「委託」為委託價;「成交」為成交價
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]
        public string caNumerator;        // 海外期貨回報用,分子,3位整數,2位小數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string caDenominator;      // 海外期貨回報用,分母 4位整數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 13)]
        public string caPrice1;                   // 八位整數五位小數 委託:觸發價  成交:0000000000000
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]
        public string caNumerator1;       // 海外期貨回報用,分子 三位整數二位小數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string caDenominator1;     // 海外期貨回報用,分母 四位整數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 13)]
        public string caPrice2;                   // 八位整數五位小數 委託:0000000000000  成交:0000000000000
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]
        public string caNumerator2;       // 海外期貨回報用,分子 三位整數二位小數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string caDenominator2;     // 海外期貨回報用,分母 四位整數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string caQty;              // TS TA張數/ TL股數/ TF TO 口數
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string caBeforeQty;                // 參考欄位,異動變更前量       
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string caAfterQty;                        // 參考欄位,異動變更後量
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string caDate;                                // 交易日期
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
        public string caTime;                                // 交易時間
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        public string caOkSeq;           // 成交序號
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
        public string caSubID;                         // 子帳帳號
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)]
        public string caSaleNo;                        // 營業員編號       
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
        public string cAgent;                                // 委託介面
    };

    public class SKStockAPI
    {
        #region 事件宣告
        public delegate void ErrorMessage(string msg);
        /// <summary>
        /// 錯誤回報事件
        /// </summary>
        public event ErrorMessage OnErrorMessage;

        public delegate void OnReplayConnectedEvent(string MSG, int Code);
        /// <summary>
        /// 連線交易回報伺服器事件
        /// </summary>
        public static event OnReplayConnectedEvent OnReplayConnected;

        public delegate void OnReplayDisconnectEvent(string MSG, int Code);
        /// <summary>
        /// 交易回報伺服器斷線事件
        /// </summary>
        public static event OnReplayConnectedEvent OnReplayDisconnect;

        public delegate void OnReplayDataEvent(ref DataItem Item);
        /// <summary>
        /// 交易回報資料接收事件
        /// </summary>
        public static event OnReplayDataEvent OnReplayDataReceive;

        public delegate void OnOrderAccountEvent(string Data);
        /// <summary>
        /// 回傳帳戶資料事件,由執行GetUserAccount()後回傳
        /// </summary>
        public static event OnOrderAccountEvent OnOrderAccount;

        public delegate void OnOrderOpenInterestEvent(string Data);
        /// <summary>
        /// 回傳未平倉內容事件,由執行 GetOpenInterest()後回傳
        /// </summary>
        public static event OnOrderOpenInterestEvent OnOrderOpenInterest;

        public delegate void OnRealBalanceReportEvent(string Data);
        /// <summary>
        /// 回傳證劵庫存內容事件,由執行GetRealBalanceReport()後回傳
        /// </summary>
        public static event OnRealBalanceReportEvent OnRealBalanceReport;

        public delegate void OnQuoteAttachConnectionEvent(int Kind, int Code);
        /// <summary>
        /// 連線報價伺服器事件
        /// </summary>
        public static event OnQuoteAttachConnectionEvent OnQuoteAttachConnection;

        public delegate void OnQuoteAttachQuoteEvent(int MarketNo, int StockIex);
        /// <summary>
        /// 當所選取的商品報價有變動時的事件
        /// </summary>
        public static event OnQuoteAttachQuoteEvent OnQuoteAttachQuote;

        public delegate void OnQuoteAttachTicksEvent(int MarketNo, int Stockidx, int Ptr);
        /// <summary>
        /// 當所選取的商品交易資料有變動時的事件
        /// </summary>
        public static event OnQuoteAttachTicksEvent OnQuoteAttachTicks;

        public delegate void OnQuoteAttachBest5Event(int MarketNo, int Stockidx);
        /// <summary>
        /// 當所選取的五檔商品報價有變動時資料
        /// </summary>
        public static event OnQuoteAttachBest5Event OnQuoteAttachBest5;

        public delegate void OnQuoteAttachStrikePricesEvent(string BProduct, string BName, string BCall, string BPut, int StrikePrice, int YearMonth);
        /// <summary>
        /// 當選擇權商品交易資料有變動時事件
        /// </summary>
        public static event OnQuoteAttachStrikePricesEvent OnQuoteAttachStrikePrices;

        public delegate void OnQuoteAttachKLineDataEvent(string caStockNo, string caData);
        /// <summary>
        /// 當所選取的商品回傳K線技術資料時的事件
        /// </summary>
        public static event OnQuoteAttachKLineDataEvent OnQuoteAttachKLineData;
      

        public delegate void OnQuoteAttachMarketTotEvent(char cMarketNo, int sPrt, long lTime, long lTotv, long lTots, long lTotc);
        /// <summary>
        /// 回傳大盤成交張筆資料事件
        /// </summary>
        public static event OnQuoteAttachMarketTotEvent OnQuoteAttachMarketTot;

        public delegate void OnQuoteAttachMarketBuySellEvent(char cMarketNo, int sPrt, long lTime, long lBc, long lSc, long lBs, long lSs);
        /// <summary>
        /// 回傳大盤買賣張筆數事件
        /// </summary>
        public static event OnQuoteAttachMarketBuySellEvent OnQuoteAttachMarketBuySell;

        public delegate void OnQuoteAttachMarketHighLowEvent(char cMarketNo, int sPrt, long lTime, short sUp, short sDown, short sHigh, short sLow, short sNoChange);
        /// <summary>
        /// 回傳大盤上漲下跌家數資料事件
        /// </summary>
        public static event OnQuoteAttachMarketHighLowEvent OnQuoteAttachMarketHighLow;
        #endregion

        #region  APIs  呼叫
        const string OrderDll = "SKOrderLib.dll";
        const string QuoteDll = "SKQuoteLib.dll";
        const string ReplyDll = "SKReplyLib.dll";

        #region 下單API
        //CallBack 指標
        delegate void OrderAccountCallback(string Data);
        delegate void OrderOpenInterestCallBack(string Data);
        delegate void OrderOnRealBalanceReportCallBack(string Data);
        //API
        [DllImport(OrderDll, EntryPoint = "SKOrderLib_Initialize")]
        private static extern int SKOrderLib_Initialize(string UserName, string PassWord);

        [DllImport(OrderDll, EntryPoint = "SKOrderLib_ReadCertByID")]
        private static extern int SKOrderLib_ReadCertByID(string UserID);

        [DllImport(OrderDll, EntryPoint = "SendStockOrder")]
        private static extern int SendStockOrder(string Account, string StockNo, int nPeriod, int nFlag, int nBuySell, string Price, int nQty,string Msg, ref int nBufferSize);

        [DllImport(OrderDll, EntryPoint = "SendStockOrderAsync")]
        private static extern int SendStockOrderAsync(string Account, string StockNo, int nPeriod, int nFlag, int nBuySell, string Price, int nQty);

        [DllImport(OrderDll, EntryPoint = "SendFutureOrder")]
        private static extern int SendFutureOrder(string Account, string StockNo, int nTradeType, int nDayTrade, int nBuySell, string Price, int nQty, string Msg, int nBufferSize);

        [DllImport(OrderDll, EntryPoint = "SendFutureOrderAsync")]
        private static extern int SendFutureOrderAsync(string Account, string StockNo, int nTradeType, int nDayTrade, int nBuySell, string Price, int nQty, string Msg, int nBufferSize);

        [DllImport(OrderDll, EntryPoint = "SendOptionOrder")]
        private static extern int SendOptionOrder(string Account, string StockNo, int nTradeType, int nNewClose, int nBuySell, string Price, int nQty, string Msg, int nBufferSize);

        [DllImport(OrderDll, EntryPoint = "SendOptionOrderAsync")]
        private static extern int SendOptionOrderAsync(string Account, string StockNo, int nTradeType, int nNewClose, int nBuySell, string Price, int nQty, string Msg, int nBufferSize);

        [DllImport(OrderDll, EntryPoint = "CancelOrderBySeqNo")]
        private static extern int CancelOrderBySeqNo(string Account, string SegNo);

        [DllImport(OrderDll, EntryPoint = "CancelOrderByStockNo")]
        private static extern int CancelOrderByStockNo(string Account , string StockNo);

        [DllImport(OrderDll, EntryPoint = "DecreaseOrderBySeqNo")]
        private static extern int DecreaseOrderBySeqNo(string SeqNo, int DecreaseQty);

        [DllImport(OrderDll, EntryPoint = "GetUserAccount")]
        private static extern int GetUserAccount();

        [DllImport(OrderDll, EntryPoint = "GetOpenInterest")]
        private static extern int GetOpenInterest(string Account);

        [DllImport(OrderDll, EntryPoint = "GetRealBalanceReport")]
        private static extern int GetRealBalanceReport(string Account);

        [DllImport(OrderDll, EntryPoint = "RegisterOnAccountCallBack")]
        private static extern int RegisterOnAccountCallBack(OrderAccountCallback cb);
        [DllImport(OrderDll, EntryPoint = "RegisterOnOpenInterestCallBack")]
        private static extern int RegisterOnOpenInterestCallBack(OrderOpenInterestCallBack cb);
        [DllImport(OrderDll, CallingConvention = CallingConvention.StdCall, EntryPoint = "RegisterOnRealBalanceReportCallBack")]
        private static extern int RegisterOnRealBalanceReportCallBack(OrderOnRealBalanceReportCallBack cb);

        OrderAccountCallback OrderAccountDel = new OrderAccountCallback(OrderAccount);
        OrderOpenInterestCallBack OrderOpenInterestDel = new OrderOpenInterestCallBack(OrderOpenInterest);
        OrderOnRealBalanceReportCallBack OrderRealBalanceReportDel = new OrderOnRealBalanceReportCallBack(OrderRealBalanceReport);
        #endregion

        #region 回報API
        // CallBack 指標
        delegate void ReplayConnectCallBack(string MSG, int Code);
        delegate void ReplayDisconnectCallBack(string MSG, int Code);
        delegate void ReplayDataCallBack(ref DataItem Item);
        //API 呼叫
        [DllImport(ReplyDll, EntryPoint = "SKReplyLib_Initialize")]
        private static extern int SKReplyLib_Initialize(string UserName, string PassWord);

        [DllImport(ReplyDll, EntryPoint = "SKReplyLib_Connect")]
        private static extern int SKReplyLib_Connect();

        [DllImport(ReplyDll, EntryPoint = "SKReplyLib_Connect")]
        private static extern int SKReplyLib_ConnectByID(string Account);

        [DllImport(ReplyDll, EntryPoint = "SKReplyLib_Close")]
        private static extern int SKReplyLib_Close();

        [DllImport(ReplyDll, EntryPoint = "SKReplyLib_IsConnected")]
        private static extern int SKReplyLib_IsConnected();

        [DllImport(ReplyDll, EntryPoint = "RegisterOnConnectCallBack")]
        private static extern int RegisterOnConnectCallBack(ReplayConnectCallBack cb);

        [DllImport(ReplyDll, CallingConvention = CallingConvention.StdCall, EntryPoint = "RegisterOnDataCallBack")]
        private static extern int RegisterOnDataCallBack(ReplayDataCallBack cb);

        [DllImport(ReplyDll, EntryPoint = "RegisterOnDisconnectCallBack")]
        private static extern int RegisterOnDisconnectCallBack(ReplayDisconnectCallBack cb);

        static ReplayConnectCallBack ReplayConnectDel = new ReplayConnectCallBack(ReplayConnect);
        static ReplayDisconnectCallBack ReplayDisconnectDel = new ReplayDisconnectCallBack(ReplayDisconnect);
        static ReplayDataCallBack ReplayDataDel = new ReplayDataCallBack(ReplayData);

        #endregion

        #region 報價API
        //Call Back 指標
        delegate void QuoteAttachConnectionCallBack(int Kind, int Code);
        delegate void QuoteAttachQuoteCallBack(int MarketNo, int StockIex);
        delegate void QuoteAttachTicksCallBack(int MarketNo, int Stockidx, int Ptr);
        delegate void QuoteAttachBest5CallBack(int MarketNo, int Stockidx);
        delegate void QuoteAttachStrikePricesCallBack([Out, MarshalAs(UnmanagedType.LPTStr)] string BProduct, [Out, MarshalAs(UnmanagedType.LPTStr)] string BName, [Out, MarshalAs(UnmanagedType.LPTStr)] string BCall, [Out, MarshalAs(UnmanagedType.LPTStr)]string BPut, int StrikePrice, int YearMonth);
        delegate void QuoteAttachKLineDataCallBack(string caStockNo, string caData);
        delegate void QuoteAttachMarketTotCallBack(char cMarketNo, int sPrt, long lTime, long lTotv, long lTots, long lTotc);
        delegate void QuoteAttachMarketBuySellCallBack(char cMarketNo, int sPrt, long lTime, long lBc, long lSc, long lBs, long lSs);
        delegate void QuoteAttachMarketHighLowCallBack(char cMarketNo, int sPrt, long lTime, short sUp, short sDown, short sHigh, short sLow, short sNoChange);
        //API
        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_Initialize")]
        private static extern int SKQuoteLib_Initialize(string UserName, string PassWord);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_EnterMonitor")]
        private static extern int SKQuoteLib_EnterMonitor();

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_LeaveMonitor")]
        private static extern int SKQuoteLib_LeaveMonitor();

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_RequestStocks")]
        private static extern int SKQuoteLib_RequestStocks(ref int PageNo, string StockNos);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_RequestTicks")]
        private static extern int SKQuoteLib_RequestTicks(ref int PageNo, string StockNos);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetStockByIndex")]
        private static extern int SKQuoteLib_GetStockByIndex(int MarketNo, int Index, ref STOCK pStock);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetStockByNo")]
        private static extern int SKQuoteLib_GetStockByNo(string StockNo, ref STOCK pStock);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetTick")]
        private static extern int SKQuoteLib_GetTick(int MarketNo, int StockIndex, int nPtr,ref TTick pTick);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetBest5")]
        private static extern int SKQuoteLib_GetBest5(int MarketNo, int StockIndex,ref BEST5 pBest5);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetStrikePrices")]
        private static extern int SKQuoteLib_GetStrikePrices();

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetKLine")]
        private static extern int SKQuoteLib_GetKLine(string StockNo, int KLineType);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetMarketTot")]
        private static extern int SKQuoteLib_GetMarketTot(int Index, char MarketNo, ref int nPtr, ref long lTime, ref long lTotv, ref long lTotc);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetMarketBuySell")]
        private static extern int SKQuoteLib_GetMarketBuySell(int Index, string MarketNo, ref int nPtr, ref long lTime, ref long lBc, ref long lSc, ref long lBs, ref long lSs);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_GetMarketHighLow")]
        private static extern int SKQuoteLib_GetMarketHighLow(int Index, string MarketNo, ref int nPtr, ref long lTime, ref short sUp, ref short sDown, ref short sHigh, ref short sLow, ref short sNoChange);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachConnectionCallBack")]
        private static extern int SKQuoteLib_AttachConnectionCallBack(QuoteAttachConnectionCallBack cb);

        [DllImport(QuoteDll, CallingConvention = CallingConvention.StdCall, EntryPoint = "SKQuoteLib_AttachQuoteCallBack")]
        private static extern int SKQuoteLib_AttachQuoteCallBack(QuoteAttachQuoteCallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachTicksCallBack")]
        private static extern int SKQuoteLib_AttachTicksCallBack(QuoteAttachTicksCallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachBest5CallBack")]
        private static extern int SKQuoteLib_AttachBest5CallBack(QuoteAttachBest5CallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachStrikePricesCallBack")]
        private static extern int SKQuoteLib_AttachStrikePricesCallBack(QuoteAttachStrikePricesCallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachKLineDataCallBack")]
        private static extern int SKQuoteLib_AttachKLineDataCallBack(QuoteAttachKLineDataCallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachMarketTotCallBack")]
        private static extern int SKQuoteLib_AttachMarketTotCallBack(QuoteAttachMarketTotCallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachMarketBuySellCallBack")]
        private static extern int SKQuoteLib_AttachMarketBuySellCallBack(QuoteAttachMarketBuySellCallBack cb);

        [DllImport(QuoteDll, EntryPoint = "SKQuoteLib_AttachMarketHighLowCallBack")]
        private static extern int SKQuoteLib_AttachMarketHighLowCallBack(QuoteAttachMarketHighLowCallBack cb);

        QuoteAttachConnectionCallBack QuoteAttachConnectionDel = new QuoteAttachConnectionCallBack(QuoteAttachConnection);
        QuoteAttachQuoteCallBack QuoteAttachQuoteDel = new QuoteAttachQuoteCallBack(QuoteAttachQuote);
        QuoteAttachTicksCallBack QuoteAttachTicksDel = new QuoteAttachTicksCallBack(QuoteAttachTicks);
        QuoteAttachBest5CallBack QuoteAttachBest5Del = new QuoteAttachBest5CallBack(QuoteAttachBest5);
        QuoteAttachStrikePricesCallBack QuoteAttachStrikePricesDel = new QuoteAttachStrikePricesCallBack(QuoteAttachStrikePrices);
        QuoteAttachKLineDataCallBack QuoteAttachKLineDataDel = new QuoteAttachKLineDataCallBack(QuoteAttachKLineData);
        QuoteAttachMarketTotCallBack QuoteAttachMarketTotDel = new QuoteAttachMarketTotCallBack(QuoteAttachMarketTot);
        QuoteAttachMarketBuySellCallBack QuoteAttachMarketBuySellDel = new QuoteAttachMarketBuySellCallBack(QuoteAttachMarketBuySell);
        QuoteAttachMarketHighLowCallBack QuoteAttachMarketHighLowDel = new QuoteAttachMarketHighLowCallBack(QuoteAttachMarketHighLow);
        #endregion


        #endregion

        private string UserName; //帳號
        private string PassWord; //密碼

        /// <summary>
        /// 建構式
        /// </summary>
        /// <param name="UserName">帳號名稱(身份證字號)</param>
        /// <param name="PassWord">帳號密碼</param>
        public SKStockAPI(string UserName, String PassWord)
        {
            this.UserName = UserName;
            this.PassWord = PassWord;
        }
        /// <summary>
        /// 解構式
        /// </summary>
        ~SKStockAPI()
        {
        }

        #region 公用
        /// <summary>
        /// 初始化Stock API
        /// </summary>
        public void Init()
        {
            try
            {
                //初始化API
                int OrderMSG = SKOrderLib_Initialize(UserName, PassWord);
                if (OrderMSG != (int)MessageType.SK_SUCCESS)
                {
                    OnErrorMessage("下單API初始化錯誤 CODE=" + OrderMSG.ToString());
                    return;
                }

                int ReplayMSG = SKReplyLib_Initialize(UserName, PassWord);
                if (ReplayMSG != (int)MessageType.SK_SUCCESS)
                {
                    OnErrorMessage("回報API初始化錯誤 CODE=" + ReplayMSG.ToString());
                    return;
                }

                int QuoteMSG = SKQuoteLib_Initialize(UserName, PassWord);
                if (QuoteMSG != (int)MessageType.SK_SUCCESS)
                {
                    OnErrorMessage("報價API初始化錯誤 CODE=" + QuoteMSG.ToString());
                    return;
                }

                int ReadCertMSG = SKOrderLib_ReadCertByID(UserName);
                if (ReadCertMSG != (int)MessageType.SK_SUCCESS)
                {
                    OnErrorMessage("讀取交易憑證錯誤 CODE =" + ReadCertMSG.ToString());
                }

                //註冊Replay CallBack
                RegisterOnConnectCallBack(ReplayConnectDel);
                RegisterOnDisconnectCallBack(ReplayDisconnectDel);
                RegisterOnDataCallBack(ReplayDataDel);
                //註冊Order CallBack
                RegisterOnAccountCallBack(OrderAccountDel);
                RegisterOnOpenInterestCallBack(OrderOpenInterestDel);
                RegisterOnRealBalanceReportCallBack(OrderRealBalanceReportDel);
                //註冊Quote CallBack
                SKQuoteLib_AttachConnectionCallBack(QuoteAttachConnectionDel);
                SKQuoteLib_AttachQuoteCallBack(QuoteAttachQuoteDel);
                SKQuoteLib_AttachTicksCallBack(QuoteAttachTicksDel);
                SKQuoteLib_AttachBest5CallBack(QuoteAttachBest5Del);
                SKQuoteLib_AttachStrikePricesCallBack(QuoteAttachStrikePricesDel);
                SKQuoteLib_AttachKLineDataCallBack(QuoteAttachKLineDataDel);
                //SKQuoteLib_AttachMarketTotCallBack(QuoteAttachMarketTotDel);
                //SKQuoteLib_AttachMarketBuySellCallBack(QuoteAttachMarketBuySellDel);
                //SKQuoteLib_AttachMarketHighLowCallBack(QuoteAttachMarketHighLowDel);

            }
            catch (Exception ex)
            {
                OnErrorMessage("初始化錯誤!" + ex.Message);
            }
        }


        #region PUBLIC Quote API Function
        /// <summary>
        /// 連線報價伺服器
        /// </summary>
        /// <returns></returns>
        public int QuoteEnterMonitor()
        {
            return SKQuoteLib_EnterMonitor();
        }
        /// <summary>
        /// 離線報價伺服器
        /// </summary>
        /// <returns></returns>
        public int QuoteLeaveMonitor()
        {
            return SKQuoteLib_LeaveMonitor();
        }

        /// <summary>
        /// 要求傳送報價
        /// </summary>
        /// <param name="PageNo">頁碼</param>
        /// <param name="StockNos">股票代碼</param>
        /// <returns></returns>
        public int RequestStocks(ref int PageNo, string StockNos)
        {
            return SKQuoteLib_RequestStocks(ref PageNo, StockNos);
        }
        /// <summary>
        /// 要求傳送成交明細資料
        /// </summary>
        /// <param name="PageNo">頁碼</param>
        /// <param name="StockNo">股票代碼</param>
        /// <returns></returns>
        public int RequestTicks(ref int PageNo, string StockNo)
        {
            return SKQuoteLib_RequestTicks(ref PageNo, StockNo);
        }

        /// <summary>
        /// 依股票編號取得股票報價資料
        /// </summary>
        /// <param name="StockNo">股票編號</param>
        /// <param name="pSTock">SSTOCK 物件</param>
        /// <returns></returns>
        public int GetStockByNo(string StockNo, ref STOCK pSTock)
        {
            return SKQuoteLib_GetStockByNo(StockNo, ref pSTock);
        }
        /// <summary>
        /// 依索引取得股票報價資料
        /// </summary>
        /// <param name="MarketNo">市場編號</param>
        /// <param name="Index">索引</param>
        /// <param name="pStock">Stock 物件</param>
        /// <returns></returns>
        public int GetStockByIndex(int MarketNo, int Index, ref STOCK pStock)
        {
            return SKQuoteLib_GetStockByIndex(MarketNo, Index, ref pStock);
        }

        /// <summary>
        /// 取得成交明細資料
        /// </summary>
        /// <param name="MarketNo">市場編號</param>
        /// <param name="Index">索引</param>
        /// <param name="nPtr">指標</param>
        /// <param name="pTick">TTICK物件</param>
        /// <returns></returns>
        public int GetTick(int MarketNo, int Index, int nPtr,ref TTick pTick)
        {
            return SKQuoteLib_GetTick(MarketNo, Index, nPtr, ref pTick);
        }
        /// <summary>
        /// 取得五檔名細
        /// </summary>
        /// <param name="MarketNo">市場編號</param>
        /// <param name="StockIndex">商品索引編號</param>
        /// <param name="pBase5">BASE5 物件</param>
        /// <returns></returns>
        public int QuoteGetBest5(int MarketNo,int StockIndex,ref BEST5 pBase5)
        {
            return SKQuoteLib_GetBest5(MarketNo, StockIndex, ref pBase5);
        }
        /// <summary>
        /// 取得選擇權報價
        /// </summary>
        /// <returns></returns>
        public int QuoteGetStrikePrices()
        {
            return SKQuoteLib_GetStrikePrices();
        }
        /// <summary>
        /// 取得商品k線資訊
        /// </summary>
        /// <param name="StockNo">商品編號</param>
        /// <param name="KLineType">0 = 1分鐘線        1 = 5分鐘線。2 = 30分鐘線。3 =日線288天。4 =完整日線。5 =週線。        6 =月線。</param>
        /// <returns></returns>
        public int QuoteGetKLine(string StockNo,int KLineType)
        {
            return SKQuoteLib_GetKLine(StockNo,KLineType);
        }

        #endregion


        #region Public Order API Function
        /// <summary>
        /// 送出證劵委託單
        /// </summary>
        /// <param name="Account">證券帳號,分公司四碼+帳號7碼</param>
        /// <param name="StockNo">委託股票代號</param>
        /// <param name="nPeriod">0:盤中 1:盤後 2:零股</param>
        /// <param name="nFlag">0:現股 1:融資 2:融券</param>
        /// <param name="nByeSell">0:買進 1:賣出</param>
        /// <param name="Price">委託價格,「M」表示參考價(昨收價)</param>
        /// <param name="nQty">整股交易為張數,如果是零股則為股數</param>
        /// <param name="Msg">回覆訊息,如果回傳值為 0表示委託成功,訊息內容則為13碼的委託序號</param>
        /// <param name="nBufferSize"> Buffer 寬度,如果傳入的 Buffer 寬度不足,則訊息內容將會被截斷以符合 Buffer 的大小,回傳會回覆真正填入 Buffer 的訊息長度</param>
        /// <returns></returns>
        public int SendStockOrders(string Account,string StockNo,int nPeriod,int nFlag,int nBuySell,string Price,int nQty,string Msg,ref int nBufferSize)
        {
            return SendStockOrder(Account, StockNo, nPeriod, nFlag, nBuySell, Price, nQty, Msg, ref nBufferSize);
        }
        /// <summary>
        /// 送出證劵非同步委託單
        /// </summary>
        /// <param name="Account">證券帳號,分公司四碼+帳號7碼</param>
        /// <param name="StockNo">委託股票代號</param>
        /// <param name="nPeriod">0:盤中 1:盤後 2:零股</param>
        /// <param name="nFlag">0:現股 1:融資 2:融券</param>
        /// <param name="nByeSell">0:買進 1:賣出</param>
        /// <param name="Price">委託價格,「M」表示參考價(昨收價)</param>
        /// <param name="nQty">整股交易為張數,如果是零股則為股數</param>
        /// <param name="Msg">回覆訊息,如果回傳值為 0表示委託成功,訊息內容則為13碼的委託序號</param>
        /// <param name="nBufferSize"> Buffer 寬度,如果傳入的 Buffer 寬度不足,則訊息內容將會被截斷以符合 Buffer 的大小,回傳會回覆真正填入 Buffer 的訊息長度</param>
        /// <returns></returns>
        public int SendStockOrdersAsync(string Account, string StockNo, int nPeriod, int nFlag, int nBuySell, string Price, int nQty)
        {
            return SendStockOrderAsync(Account, StockNo, nPeriod, nFlag, nBuySell, Price, nQty);
        }
        /// <summary>
        /// 傳送期貨委託單
        /// </summary>
        /// <param name="Account">期貨帳號,IB+帳號</param>
        /// <param name="StockNo">委託期貨代號</param>
        /// <param name="nTradeType">0:ROD 1:IOC 2:FOK</param>
        /// <param name="nDayTrade">當沖0:否 1:是,可當沖商品請參考交易所規定。</param>
        /// <param name="nBuySell">買賣別,0:買進 1:賣出</param>
        /// <param name="Price">委託價格,「M」表示市價</param>
        /// <param name="nQty">交易口數</param>
        /// <param name="Msg">回覆訊息,如果回傳值為 0表示委託成功,訊息內容則為13碼的委託序號</param>
        /// <param name="nBufferSize"> Buffer 寬度,如果傳入的 Buffer 寬度不足,則訊息內容將會被截斷以符合 Buffer 的大小,回傳會回覆真正填入 Buffer 的訊息長度</param>
        /// <returns></returns>
        public int SendFutureOrders(string Account, string StockNo, int nTradeType, int nDayTrade, int nBuySell, string Price, int nQty, string Msg, int nBufferSize)
        {
            return SendFutureOrder(Account, StockNo, nTradeType, nDayTrade, nBuySell, Price, nQty, Msg, nBufferSize);
        }

        /// <summary>
        /// 取得帳戶資料
        /// </summary>
        /// <returns></returns>
        public int OrderGetUserAccount()
        {
            return GetUserAccount();
        }
        /// <summary>
        /// 取得證劵即時庫存資料
        /// </summary>
        /// <param name="Account">分公司+帳號</param>
        /// <returns></returns>
        public int OrderGetRealBalanceReport(string Account)
        {
            return GetRealBalanceReport(Account);
        }

        public int GetOpenInterestReport(string Account)
        {
            return GetOpenInterest(Account);
        }

        /// <summary>
        /// 取消下單
        /// </summary>
        /// <param name="StockNo">股票代號</param>
        /// <returns></returns>
        public int CancelOrder(string Account , string StockNo)
        {
            return CancelOrderByStockNo(Account, StockNo);
        }
        #endregion

        #region Public Replay API Function
        /// <summary>
        /// 連接回報伺服器
        /// </summary>
        /// <returns></returns>
        public int ReplyConnect()
        {
            return SKReplyLib_Connect();
        }
        /// <summary>
        /// 依帳戶名稱連線回報伺服器
        /// </summary>
        /// <param name="Account"></param>
        /// <returns></returns>
        public int ReplyConnectByID(string Account)
        {
            return SKReplyLib_ConnectByID(Account);
        }
        /// <summary>
        /// 關閉回報伺服器
        /// </summary>
        /// <returns></returns>
        public int ReplyClose()
        {
            return SKReplyLib_Close();
        }
        /// <summary>
        /// 取得回報伺服器是否連線,回傳值0尚未連線,回傳值1已連線
        /// </summary>
        /// <returns></returns>
        public int ReplyIsConnected()
        {
            return SKReplyLib_IsConnected();
        }
        #endregion

        #endregion


        #region 內部回呼

        private static void ReplayConnect(string MSG, int Code)
        {
            if (OnReplayConnected != null) OnReplayConnected(MSG,Code);
        }

        private static void ReplayDisconnect(string MSG, int Code)
        {
            if (OnReplayDisconnect != null) OnReplayDisconnect(MSG,Code);
        }

        private static void ReplayData(ref DataItem Item)
        {
            if (OnReplayDataReceive != null) OnReplayDataReceive(ref Item);
        }

        private static void OrderAccount(string Data)
        {
            if (OnOrderAccount != null) OnOrderAccount(Data);
        }

        private static void OrderOpenInterest(string Data)
        {
            if (OnOrderOpenInterest != null) OnOrderOpenInterest(Data);
        }

        private static void OrderRealBalanceReport(string Data)
        {
            if (OnRealBalanceReport != null) OnRealBalanceReport(Data);
        }

        private static void QuoteAttachConnection(int Kind, int Code)
        {
            if (OnQuoteAttachConnection != null) OnQuoteAttachConnection(Kind, Code);
        }

        private static void QuoteAttachQuote(int MarketNo, int StockIex)
        {
            if (OnQuoteAttachQuote != null) OnQuoteAttachQuote(MarketNo, StockIex);
        }

        private static void QuoteAttachTicks(int MarketNo, int Stockidx, int Ptr)
        {
            if (OnQuoteAttachTicks != null) OnQuoteAttachTicks(MarketNo, Stockidx, Ptr);
        }

        private static void QuoteAttachBest5(int MarketNo, int Stockidx)
        {
            if (OnQuoteAttachBest5 != null) OnQuoteAttachBest5(MarketNo, Stockidx);
        }

        private static void QuoteAttachStrikePrices(string BProduct, string BName, string BCall, string BPut, int StrikePrice, int YearMonth)
        {
            if (OnQuoteAttachStrikePrices != null) OnQuoteAttachStrikePrices(BProduct, BName, BCall, BPut, StrikePrice, YearMonth);
        }

        private static void QuoteAttachKLineData(string caStockNo, string caData)
        {
            if (OnQuoteAttachKLineData != null) OnQuoteAttachKLineData(caStockNo, caData);
        }

        private static void QuoteAttachMarketTot(char cMarketNo, int sPrt, long lTime, long lTotv, long lTots, long lTotc)
        {
            if (OnQuoteAttachMarketTot != null) OnQuoteAttachMarketTot(cMarketNo, sPrt, lTime, lTotv, lTots, lTotc);
        }

        private static void QuoteAttachMarketBuySell(char cMarketNo, int sPrt, long lTime, long lBc, long lSc, long lBs, long lSs)
        {
            if (OnQuoteAttachMarketBuySell != null) OnQuoteAttachMarketBuySell(cMarketNo, sPrt, lTime, lBc, lSc, lBs, lSs);
        }

        private static void QuoteAttachMarketHighLow(char cMarketNo, int sPrt, long lTime, short sUp, short sDown, short sHigh, short sLow, short sNoChange)
        {
            if (OnQuoteAttachMarketHighLow != null) OnQuoteAttachMarketHighLow(cMarketNo, sPrt, lTime, sUp, sDown, sHigh, sLow, sNoChange);
        }
        #endregion

    }
}

評分

參與人數 1金錢 +2 收起 理由
enochyu + 2 按一個讚!

查看全部評分

發表於 12-8-15 13:11 | 顯示全部樓層
indypan 發表於 12-7-20 15:56
sangi 大你好,

我按照您的建議修改,現在可以正常登入,也收得到報價,但是,每次收報價大概幾分鐘後,報 ...

每隔一陣子要去  request server time 才不會被防火牆斷線....

  <UnmanagedFunctionPointer(CallingConvention.StdCall)> _
    Public Delegate Sub FOnNotifyServerTime(ByVal tHour As Int16, ByVal tMinute As Int16, ByVal tSecond As Int16, ByVal tTotal As Int16)
    Shared Delegate_ServerTime As New FOnNotifyServerTime(AddressOf CBFunc_ServerTime)

    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_AttchServerTimeCallBack(ByVal Delegate_ServerTime As FOnNotifyServerTime) As Integer
    End Function

    <DllImport("SKQuoteLib.dll", CallingConvention:=CallingConvention.StdCall)> _
    Public Shared Function SKQuoteLib_RequestServerTime() As Integer
    End Function

----------------------
然後

    Public Shared Sub CBFunc_ServerTime()
    '留空
    End Sub


    '定時要求系統時間以防止斷線
    Private Sub HeartBeat() Handles HeartbeatTimer.Elapsed
        Try
            SKQuoteLib_RequestServerTime()
      
        Catch ex As Exception
        End Try
    End Sub

-----------------------------------------------

對了,要報價時 用 Timer 去 call SKQuoteLib_RequestStocks 儘量不要用 AttachTicks

然後  ...
Public Shared Sub CBFunc_AttachQuote(sMarketNo As Short, sStockidx As Short)
..
    SKQuoteLib_GetStockByNo(. , .)
..
End Sub







 樓主| 發表於 12-8-16 08:18 | 顯示全部樓層
謝謝指導, 自從之前無故斷線之後, 因本身能力不足, 沒有在繼續修改下去, 後來只用 excel 收報價, 再研究看看 sangi 網兄的程式碼, 把它加上去.

感謝再感謝
發表於 12-12-3 09:39 | 顯示全部樓層
alex_sender 發表於 12-8-1 19:02
不說明!自已看,直接複制成class就可以直接使用

using System;

感謝Alex大大
上禮拜策略王出問題後
就在想要自己寫了
可以看到範例真是比較方便一點

發表於 13-3-13 12:50 | 顯示全部樓層
請問大大妳的群益API可以接收報價嗎??
我的可以登入旦無法接收報價,可以請教大大是甚麼原因嗎??
發表於 13-3-13 12:51 | 顯示全部樓層
sangi 發表於 12-7-16 11:08
少了 DLLIMPORT...... 請參照下面範例匯入
-----------------------

請問大大妳的群益API可以接收報價嗎??
我的可以登入旦無法接收報價,可以請教大大是甚麼原因嗎??
發表於 13-3-13 12:52 | 顯示全部樓層
alex_sender 發表於 12-8-1 19:02
不說明!自已看,直接複制成class就可以直接使用

using System;

請問大大妳的群益API可以接收報價嗎??
我的可以登入旦無法接收報價,可以請教大大是甚麼原因嗎??
發表於 13-3-14 17:01 | 顯示全部樓層
獨孤求勝 發表於 13-3-13 12:52
請問大大妳的群益API可以接收報價嗎??
我的可以登入旦無法接收報價,可以請教大大是甚麼原因嗎??
...



同一個問題應該不用回三次吧?
如果可以登入但沒報價, 要確定一下 symbol 對不對~
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-12-22 21:38

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 |