|
樓主 |
發表於 12-2-12 18:30
|
顯示全部樓層
/*
以下是群益API 在C# 當中開發所需要的重要參考資料
有了它您就可以自己開發使用群益API的版本
不在受到 DLL 引用困擾了
*/
Thread TickReceive;
// 0.初始使用者相關資訊
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_Initialize([MarshalAs(UnmanagedType.LPStr)] String lpszLoginID, [MarshalAs(UnmanagedType.LPStr)] String lpszPassword);
// 1.0.向報價函式庫註冊接收連線狀態的 Call back 函式位址
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate void FOnNotifyConnection(Int32 nKind, Int32 nCode);
static FOnNotifyConnection Delegate_AttachConnection = new FOnNotifyConnection(CBFunc_AttachConnection);
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_AttachConnectionCallBack(FOnNotifyConnection Delegate_AttachConnection);
// 1.1.當有索取的個股報價異動時,將透過此註冊的函式通知應用程式處理
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate void FOnNotifyQuote(Int16 sMarketNo, Int16 sStockidx);
static FOnNotifyQuote Delegate_AttachQuote = new FOnNotifyQuote(CBFunc_AttachQuote);
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_AttachQuoteCallBack(FOnNotifyQuote Delegate_AttachQuote);
// 1.2.當有索取的個股成交明細有所異動,即透過向此註冊的 Call back 函式進行處理
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate void FOnNotifyTicks(Int16 sMarketNo, Int16 sStockidx, Int32 nPtr);
static FOnNotifyTicks Delegate_AttachTicks = new FOnNotifyTicks(CBFunc_AttachTicks);
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_AttachTicksCallBack(FOnNotifyTicks Delegate_AttachTicks);
// 2.建立與報價伺服器的連線
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_EnterMonitor();
// 3.根據股票代號取得報價資訊
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
extern static int SKQuoteLib_GetStockByNo(String lpszStockNo, ref TStock pStock);
// 4.要求傳送成交明細以及五檔
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
extern static int SKQuoteLib_RequestStocks(ref Int16 psPageNo, String pStockNo);
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
extern static int SKQuoteLib_RequestTicks(ref Int16 psPageNo, String pStockNo);
// 5.取得成交明細資訊
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_GetTick(Int16 sMarketNo, Int16 sStockidx, Int32 nPtr, ref TTick pTick);
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_GetStockByIndex(Int16 sMarketNo, Int16 sStockidx, ref TStock pStock);
// END.中斷與報價伺服器的連線
[DllImport("SKQuoteLib.dll", CallingConvention = CallingConvention.StdCall)]
extern static int SKQuoteLib_LeaveMonitor();
static string[] tick = new string[256];
static int [] qttl = new int [50];
static bool APIConnectStatus = false;
static bool KeepTickInfo = false;
static bool LastAPIStatus = true;
static bool APIRequestStatus = false;
static int dataPtr = 0;
static int ProcPtr = 0;
static int SK_SUBJECT_CONNECTION_CONNECTED = 100;
// static int SK_SUBJECT_CONNECTION_DISCONNECT = 101;
[StructLayout(LayoutKind.Sequential)]
// [struct] TStock
public struct TStock
{
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; // 跌停價
}
// [struct] TTick
[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; // 成交量
}
/*
* [In,Out] ref Variable
*/
// PageNo
static short PageNo = -1;
// TStock
public static TStock Stock = new TStock();
// Tick
public static TTick Tick = new TTick(); |
|