private void GetPriceRecord( MSFL.MSFLSecurityInfo msflSecurityInfo ) { IntPtr hSecurity = msflSecurityInfo.hSecurity; int iErr = MSFL.MSFL1_LockSecurity( hSecurity, MSFL.MSFL_LOCK_PREV_WRITE_LOCK ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return; ushort wPriceRecCount = 0; iErr = MSFL.MSFL1_GetDataRecordCount( hSecurity, ref wPriceRecCount ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return; if ( wPriceRecCount > 0 ) { iErr = MSFL.MSFL1_SeekBeginData( hSecurity ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return; MSFL.DateTime sDateTime = new MSFL.DateTime(); m_PriceRecordArray = new MSFL.MSFLPriceRecord[wPriceRecCount]; iErr = MSFL.MSFL2_ReadMultipleRecs( hSecurity, m_PriceRecordArray, ref sDateTime, ref wPriceRecCount, (int)MSFL.MSFL_FIND.MSFL_FIND_USE_CURRENT_POS ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return; // Unlock the security (we're done using it) iErr = MSFL.MSFL1_UnlockSecurity( hSecurity ); } }
public KLineViewFormSubForm( MSFL.MSFLSecurityInfo[] msflSecurityInfoArray ) { InitializeComponent(); for ( int iIndex = 0; iIndex < msflSecurityInfoArray.Length; iIndex++ ) { MSFL.MSFLSecurityInfo msflSecurityInfo = msflSecurityInfoArray[iIndex]; string securityInfo = msflSecurityInfo.szName + "[" + msflSecurityInfo.szSymbol + "]"; m_SecurityDictionary.Add( securityInfo, msflSecurityInfo ); this.checkedListBox.Items.Add( securityInfo ); } }
//[DllImport( "MSFL91.dll", CallingConvention = CallingConvention.StdCall )] //private static extern int MSFL2_ReadMultipleRecsByDates(); //[DllImport( "MSFL91.dll", CallingConvention = CallingConvention.StdCall )] //private static extern int MSFL2_RemoveDuplicateDataRecs(); //[DllImport( "MSFL91.dll", CallingConvention = CallingConvention.StdCall )] //private static extern int MSFL2_SortData(); //[DllImport( "MSFL91.dll", CallingConvention = CallingConvention.StdCall )] //private static extern int MSFL2_SortSecurities(); //[DllImport( "MSFL91.dll", CallingConvention = CallingConvention.StdCall )] //private static extern int MSFL2_WriteDataRec(); //[DllImport( "MSFL91.dll", CallingConvention = CallingConvention.StdCall )] //private static extern int MSFL2_WriteMultipleRecs(); /// <summary> /// /// </summary> /// <param name="iErr"></param> public static void DisplayMSFLError(int iErr) { // If there is an error or message if (iErr != (int)MSFL_ERR.MSFL_NO_ERR) { StringBuilder szErrMsg = new StringBuilder(MSFL.MSFL_MAX_ERR_MSG_LENGTH); // Get the error/message text from MSFL IntPtr ptrStrInfo = MSFL.MSFL1_GetErrorMessage(iErr, szErrMsg, (ushort)szErrMsg.Capacity); //String strInfo = Marshal.PtrToStringAuto( ptrStrInfo ); // If this is a information message, display the text in a message box if (iErr > (int)MSFL_ERR.MSFL_NO_ERR) { MessageBox.Show(szErrMsg.ToString(), "MSFL Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } // If there is an error, display the text in a message box else { MessageBox.Show(szErrMsg.ToString(), "MSFL Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static bool TryLoadMsflPriceInfo( string stockName, string stockSymbol, string strFilePath, out MSFL.MSFLPriceRecord[] msflPriceRecordArray ) { msflPriceRecordArray = new MSFL.MSFLPriceRecord[0]; string strStockCode = GetStockCode( stockName, stockSymbol ); if ( s_PriceDictionary.TryGetValue( strStockCode, out msflPriceRecordArray ) == true ) return true; if ( Directory.Exists( strFilePath ) == false ) return false; byte dirNumber = 0; int iErr = MSFL.MSFL1_OpenDirectory( strFilePath, ref dirNumber, MSFL.MSFL_DIR_FORCE_USER_IN ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; MSFL.MSFLDirectoryStatus msflDirectoryStatus = new MSFL.MSFLDirectoryStatus(); msflDirectoryStatus.dwTotalSize = (uint)Marshal.SizeOf( msflDirectoryStatus ); iErr = MSFL.MSFL1_GetDirectoryStatus( dirNumber, string.Empty, ref msflDirectoryStatus ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; if ( msflDirectoryStatus.bExists == false || msflDirectoryStatus.bOpen == false || msflDirectoryStatus.bMetaStockDir == false ) return false; MSFL.MSFLSecurityInfo msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf( msflSecurityInfo ); iErr = MSFL.MSFL1_GetFirstSecurityInfo( dirNumber, ref msflSecurityInfo ); while ( iErr == (int)MSFL.MSFL_ERR.MSFL_NO_ERR || iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) { if ( msflSecurityInfo.szName == stockName && msflSecurityInfo.szSymbol == stockSymbol ) { iErr = MSFL.MSFL1_LockSecurity( msflSecurityInfo.hSecurity, MSFL.MSFL_LOCK_PREV_WRITE_LOCK ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; ushort wPriceRecCount = 0; iErr = MSFL.MSFL1_GetDataRecordCount( msflSecurityInfo.hSecurity, ref wPriceRecCount ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; if ( wPriceRecCount > 0 ) { iErr = MSFL.MSFL1_SeekBeginData( msflSecurityInfo.hSecurity ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; MSFL.DateTime sDateTime = new MSFL.DateTime(); msflPriceRecordArray = new MSFL.MSFLPriceRecord[wPriceRecCount]; iErr = MSFL.MSFL2_ReadMultipleRecs( msflSecurityInfo.hSecurity, msflPriceRecordArray, ref sDateTime, ref wPriceRecCount, (int)MSFL.MSFL_FIND.MSFL_FIND_USE_CURRENT_POS ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) break; // Unlock the security (we're done using it) iErr = MSFL.MSFL1_UnlockSecurity( msflSecurityInfo.hSecurity ); iErr = MSFL.MSFL1_CloseDirectory( dirNumber ); s_PriceDictionary.Add( strStockCode, msflPriceRecordArray ); return true; } break; } if ( iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) break; iErr = MSFL.MSFL1_GetNextSecurityInfo( msflSecurityInfo.hSecurity, ref msflSecurityInfo ); } MSFL.MSFL1_CloseDirectory( dirNumber ); return false; }
public static bool TryLoadMsflSecurityInfo( string strFilePath, out MSFL.MSFLSecurityInfo[] msflSecurityInfoArray ) { msflSecurityInfoArray = new MSFL.MSFLSecurityInfo[0]; if ( s_SecurityDictionary.TryGetValue( strFilePath, out msflSecurityInfoArray ) == true ) return true; if ( Directory.Exists( strFilePath ) == false ) return false; byte dirNumber = 0; int iErr = MSFL.MSFL1_OpenDirectory( strFilePath, ref dirNumber, MSFL.MSFL_DIR_FORCE_USER_IN ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; MSFL.MSFLDirectoryStatus msflDirectoryStatus = new MSFL.MSFLDirectoryStatus(); msflDirectoryStatus.dwTotalSize = (uint)Marshal.SizeOf( msflDirectoryStatus ); iErr = MSFL.MSFL1_GetDirectoryStatus( dirNumber, string.Empty, ref msflDirectoryStatus ); if ( iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR ) return false; if ( msflDirectoryStatus.bExists == false || msflDirectoryStatus.bOpen == false || msflDirectoryStatus.bMetaStockDir == false ) return false; List<MSFL.MSFLSecurityInfo> msflSecurityInfoList = new List<MSFL.MSFLSecurityInfo>(); MSFL.MSFLSecurityInfo msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf( msflSecurityInfo ); iErr = MSFL.MSFL1_GetFirstSecurityInfo( dirNumber, ref msflSecurityInfo ); while ( iErr == (int)MSFL.MSFL_ERR.MSFL_NO_ERR || iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) { msflSecurityInfoList.Add( msflSecurityInfo ); if ( iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR ) break; msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf( msflSecurityInfo ); iErr = MSFL.MSFL1_GetNextSecurityInfo( msflSecurityInfo.hSecurity, ref msflSecurityInfo ); } MSFL.MSFL1_CloseDirectory( dirNumber ); msflSecurityInfoArray = msflSecurityInfoList.ToArray(); s_SecurityDictionary.Add( strFilePath, msflSecurityInfoArray ); return true; }
public static bool LoadFileFormatForMetaStock(string stockName, string stockSymbol, string strFilePath, ref StockInfo stockInfo) { MSFL.MSFLSecurityInfo[] msflSecurityInfoArray = null; if (GlobalSetting.TryLoadMsflSecurityInfo(strFilePath, out msflSecurityInfoArray) == false) { return(false); } int iErr = (int)MSFL.MSFL_ERR.MSFL_NO_ERR; StringBuilder dateString = new StringBuilder(MSFL.MSFL_MAX_NAME_LENGTH + 1); for (int iIndex = 0; iIndex < msflSecurityInfoArray.Length; iIndex++) { MSFL.MSFLSecurityInfo msflSecurityInfo = msflSecurityInfoArray[iIndex]; if (msflSecurityInfo.szName == stockName && msflSecurityInfo.szSymbol == stockSymbol) { stockInfo.m_StockCode = GlobalSetting.GetStockCode(msflSecurityInfo.szName, msflSecurityInfo.szSymbol); stockInfo.m_StockName = msflSecurityInfo.szName; stockInfo.m_StockSymbol = msflSecurityInfo.szSymbol; stockInfo.m_Periodicity = msflSecurityInfo.cPeriodicity; iErr = MSFL.MSFL1_FormatDate(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lFirstDate); stockInfo.m_FirstDate = DateTime.Parse(dateString.ToString()); iErr = MSFL.MSFL1_FormatDate(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lLastDate); stockInfo.m_LastDate = DateTime.Parse(dateString.ToString()); iErr = MSFL.MSFL1_FormatTime(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lFirstTime, true); string strFirstTime = dateString.ToString(); strFirstTime = strFirstTime.Substring(0, strFirstTime.Length - 1); stockInfo.m_FirstTime = DateTime.Parse(strFirstTime); iErr = MSFL.MSFL1_FormatTime(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lLastTime, true); string strLastTime = dateString.ToString(); strLastTime = strLastTime.Substring(0, strLastTime.Length - 1); stockInfo.m_LastTime = DateTime.Parse(strLastTime); iErr = MSFL.MSFL1_FormatTime(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lStartTime, false); stockInfo.m_StartTime = DateTime.Parse(dateString.ToString()); iErr = MSFL.MSFL1_FormatTime(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lEndTime, false); stockInfo.m_EndTime = DateTime.Parse(dateString.ToString()); iErr = MSFL.MSFL1_FormatDate(dateString, (ushort)dateString.Capacity, msflSecurityInfo.lCollectionDate); stockInfo.m_CollectionDate = DateTime.Parse(dateString.ToString()); MSFL.MSFLPriceRecord[] msflPriceInfoArray = null; if (GlobalSetting.TryLoadMsflPriceInfo(stockName, stockSymbol, strFilePath, out msflPriceInfoArray) == false) { return(true); } // numbers for summing price info float fOpenSum = 0.0f, fHighSum = 0.0f, fLowSum = 0.0f, fCloseSum = 0.0f, fVolumeSum = 0.0f, fOpenIntSum = 0.0f; StringBuilder szBuf = new StringBuilder(MSFL.MSFL_MAX_NAME_LENGTH + 1); for (int iIndex2 = 0; iIndex2 < msflPriceInfoArray.Length; iIndex2++) { MSFL.MSFLPriceRecord msflPriceRecord = msflPriceInfoArray[iIndex2]; StockData stockData = new StockData(); if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_DATE) == MSFL.MSFL_DATA_DATE) { iErr = MSFL.MSFL1_FormatDate(szBuf, (ushort)szBuf.Capacity, msflPriceRecord.lDate); stockData.TradingDate = DateTime.Parse(szBuf.ToString()); } if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_TIME) == MSFL.MSFL_DATA_TIME) { iErr = MSFL.MSFL1_FormatTime(szBuf, (ushort)szBuf.Capacity, msflPriceRecord.lTime, true); string strTradingTime = szBuf.ToString(); strTradingTime = strLastTime.Substring(0, strTradingTime.Length - 1); stockData.TradingTime = DateTime.Parse(strTradingTime); } stockData.TradingDateTime = stockData.TradingDate + stockData.TradingTime.TimeOfDay; //Debug.WriteLine( stockData.TradingDateTime.ToString() ); if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_OPEN) == MSFL.MSFL_DATA_OPEN) { fOpenSum += msflPriceRecord.fOpen; stockData.OpenPrice = msflPriceRecord.fOpen; } if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_HIGH) == MSFL.MSFL_DATA_HIGH) { fHighSum += msflPriceRecord.fHigh; stockData.HighestPrice = msflPriceRecord.fHigh; } if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_LOW) == MSFL.MSFL_DATA_LOW) { fLowSum += msflPriceRecord.fLow; stockData.MinimumPrice = msflPriceRecord.fLow; } if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_CLOSE) == MSFL.MSFL_DATA_CLOSE) { fCloseSum += msflPriceRecord.fClose; stockData.ClosePrice = msflPriceRecord.fClose; } if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_VOLUME) == MSFL.MSFL_DATA_VOLUME) { fVolumeSum += msflPriceRecord.fVolume; stockData.TradingVolume = msflPriceRecord.fVolume; } if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_OPENINT) == MSFL.MSFL_DATA_OPENINT) { fOpenIntSum += msflPriceRecord.fOpenInt; stockData.OpenInterest = msflPriceRecord.fOpenInt; } stockInfo.AddStockData(stockData); } return(true); } } return(false); }
public static bool TryLoadMsflPriceInfo(string stockName, string stockSymbol, string strFilePath, out MSFL.MSFLPriceRecord[] msflPriceRecordArray) { msflPriceRecordArray = new MSFL.MSFLPriceRecord[0]; string strStockCode = GetStockCode(stockName, stockSymbol); if (s_PriceDictionary.TryGetValue(strStockCode, out msflPriceRecordArray) == true) { return(true); } if (Directory.Exists(strFilePath) == false) { return(false); } byte dirNumber = 0; int iErr = MSFL.MSFL1_OpenDirectory(strFilePath, ref dirNumber, MSFL.MSFL_DIR_FORCE_USER_IN); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { return(false); } MSFL.MSFLDirectoryStatus msflDirectoryStatus = new MSFL.MSFLDirectoryStatus(); msflDirectoryStatus.dwTotalSize = (uint)Marshal.SizeOf(msflDirectoryStatus); iErr = MSFL.MSFL1_GetDirectoryStatus(dirNumber, string.Empty, ref msflDirectoryStatus); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { return(false); } if (msflDirectoryStatus.bExists == false || msflDirectoryStatus.bOpen == false || msflDirectoryStatus.bMetaStockDir == false) { return(false); } MSFL.MSFLSecurityInfo msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf(msflSecurityInfo); iErr = MSFL.MSFL1_GetFirstSecurityInfo(dirNumber, ref msflSecurityInfo); while (iErr == (int)MSFL.MSFL_ERR.MSFL_NO_ERR || iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR) { if (msflSecurityInfo.szName == stockName && msflSecurityInfo.szSymbol == stockSymbol) { iErr = MSFL.MSFL1_LockSecurity(msflSecurityInfo.hSecurity, MSFL.MSFL_LOCK_PREV_WRITE_LOCK); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { break; } ushort wPriceRecCount = 0; iErr = MSFL.MSFL1_GetDataRecordCount(msflSecurityInfo.hSecurity, ref wPriceRecCount); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { break; } if (wPriceRecCount > 0) { iErr = MSFL.MSFL1_SeekBeginData(msflSecurityInfo.hSecurity); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { break; } MSFL.DateTime sDateTime = new MSFL.DateTime(); msflPriceRecordArray = new MSFL.MSFLPriceRecord[wPriceRecCount]; iErr = MSFL.MSFL2_ReadMultipleRecs(msflSecurityInfo.hSecurity, msflPriceRecordArray, ref sDateTime, ref wPriceRecCount, (int)MSFL.MSFL_FIND.MSFL_FIND_USE_CURRENT_POS); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { break; } // Unlock the security (we're done using it) iErr = MSFL.MSFL1_UnlockSecurity(msflSecurityInfo.hSecurity); iErr = MSFL.MSFL1_CloseDirectory(dirNumber); s_PriceDictionary.Add(strStockCode, msflPriceRecordArray); return(true); } break; } if (iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR) { break; } iErr = MSFL.MSFL1_GetNextSecurityInfo(msflSecurityInfo.hSecurity, ref msflSecurityInfo); } MSFL.MSFL1_CloseDirectory(dirNumber); return(false); }
public static bool TryLoadMsflSecurityInfo(string strFilePath, out MSFL.MSFLSecurityInfo[] msflSecurityInfoArray) { msflSecurityInfoArray = new MSFL.MSFLSecurityInfo[0]; if (s_SecurityDictionary.TryGetValue(strFilePath, out msflSecurityInfoArray) == true) { return(true); } if (Directory.Exists(strFilePath) == false) { return(false); } byte dirNumber = 0; int iErr = MSFL.MSFL1_OpenDirectory(strFilePath, ref dirNumber, MSFL.MSFL_DIR_FORCE_USER_IN); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { return(false); } MSFL.MSFLDirectoryStatus msflDirectoryStatus = new MSFL.MSFLDirectoryStatus(); msflDirectoryStatus.dwTotalSize = (uint)Marshal.SizeOf(msflDirectoryStatus); iErr = MSFL.MSFL1_GetDirectoryStatus(dirNumber, string.Empty, ref msflDirectoryStatus); if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR) { return(false); } if (msflDirectoryStatus.bExists == false || msflDirectoryStatus.bOpen == false || msflDirectoryStatus.bMetaStockDir == false) { return(false); } List <MSFL.MSFLSecurityInfo> msflSecurityInfoList = new List <MSFL.MSFLSecurityInfo>(); MSFL.MSFLSecurityInfo msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf(msflSecurityInfo); iErr = MSFL.MSFL1_GetFirstSecurityInfo(dirNumber, ref msflSecurityInfo); while (iErr == (int)MSFL.MSFL_ERR.MSFL_NO_ERR || iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR) { msflSecurityInfoList.Add(msflSecurityInfo); if (iErr == (int)MSFL.MSFL_Messages.MSFL_MSG_LAST_SECURITY_IN_DIR) { break; } msflSecurityInfo = new MSFL.MSFLSecurityInfo(); msflSecurityInfo.dwTotalSize = (uint)Marshal.SizeOf(msflSecurityInfo); iErr = MSFL.MSFL1_GetNextSecurityInfo(msflSecurityInfo.hSecurity, ref msflSecurityInfo); } MSFL.MSFL1_CloseDirectory(dirNumber); msflSecurityInfoArray = msflSecurityInfoList.ToArray(); s_SecurityDictionary.Add(strFilePath, msflSecurityInfoArray); return(true); }
public KLineViewFormDocument( MSFL.MSFLSecurityInfo msflSecurityInfo ) { GetPriceRecord( msflSecurityInfo ); InitializeComponent(); }