コード例 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="stockInfo"></param>
        public void AddStockInfo( StockInfo stockInfo )
        {
            StockInfo outStockInfo = null;
            if ( m_StockInfoByCode.TryGetValue( stockInfo.StockCode, out outStockInfo ) == true )
                return;

            m_StockInfoByCode.Add( stockInfo.StockCode, stockInfo );

            //
            m_StockInfoArray.Add( stockInfo );
        }
コード例 #2
0
        public static bool LoadGlobalSetting()
        {
            PlateInfo[] plateInfos = LoadConfigSetting( GlobalSetting.ConfigFilePath );
            if ( plateInfos == null )
                return false;

            if ( LoadingGlobalSetting != null )
                LoadingGlobalSetting( null, EventArgs.Empty );

            s_SecurityDictionary.Clear();
            s_PriceDictionary.Clear();
            GlobalStockManager.Clear();

            s_PlateInfos = plateInfos;

            for ( int iIndex = 0; iIndex < s_PlateInfos.Length; iIndex++ )
            {
                PlateInfo plateInfo = s_PlateInfos[iIndex];

                for ( int iIndex2 = 0; iIndex2 < plateInfo.VarietyInfos.Length; iIndex2++ )
                {
                    VarietyInfo varietyInfo = plateInfo.VarietyInfos[iIndex2];

                    StockManager stockManager = new StockManager();
                    stockManager.StockPlate = plateInfo.Name;
                    stockManager.StockVariety = varietyInfo.Name;

                    for ( int iIndex3 = 0; iIndex3 < varietyInfo.FileInfos.Length; iIndex3++ )
                    {
                        FileInfo FileInfo = varietyInfo.FileInfos[iIndex3];

                        StockInfo stockInfo = new StockInfo();
                        if ( StockInfo.LoadFileFormatForMetaStock( FileInfo.StockName, FileInfo.StockSymbol, FileInfo.FilePath, ref  stockInfo ) == true )
                            stockManager.AddStockInfo( stockInfo );
                    }

                    GlobalStockManager.AddStockManager( stockManager );
                }
            }

            s_IsLoadGlobalSetting = true;

            if ( LoadedGlobalSetting != null )
                LoadedGlobalSetting( null, EventArgs.Empty );

            return true;
        }
コード例 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonFile_Click( object sender, EventArgs e )
        {
            char[] codeArray = this.RichTextBoxCode.Text.ToCharArray();
            char[] nameArray = this.RichTextBoxName.Text.ToCharArray();

            for ( int iIndex = 0; iIndex < m_RandomFileCount; iIndex++ )
            {
                StockInfo stockInfo = new StockInfo();

                StringBuilder strCode = new StringBuilder();
                for ( int i = 0; i < 6; i++ )
                    strCode.Append( RandomEx.RandomArray( codeArray ) );

                StringBuilder strName = new StringBuilder();
                for ( int i = 0; i < 10; i++ )
                    strName.Append( RandomEx.RandomArray( nameArray ) );

                //stockInfo.StockCode = strCode.ToString();
                //stockInfo.StockName = strName.ToString();

                DateTime[] allTradingTime = this.GetAllTradingTime();

                for ( int iIndex2 = 0; iIndex2 < allTradingTime.Length; iIndex2++ )
                {
                    StockData stockData = new StockData();

                    stockData.TradingTime = allTradingTime[iIndex2];
                    stockData.OpenPrice = this.GetRandomOpenPrice();
                    stockData.ClosePrice = this.GetRandomClosePrice();
                    stockData.HighestPrice = this.GetRandomHighestPrice();
                    stockData.MinimumPrice = this.GetRandomMinimumPrice( (uint)stockData.HighestPrice );
                    stockData.TradingVolume = this.GetRandomDailyTurnover();
                    stockData.OpenInterest = this.GetRandomDailyAmount();

                    //stockInfo.AddStockData( stockData );
                }

                StockInfo.SaveFileFormatForDStock( this.TextBoxFolder.Text + "\\" + stockInfo.StockCode + ".DStock", stockInfo );
            }
        }
コード例 #4
0
        public static void SaveFileFormatForDStock( string strFile, StockInfo stockInfo )
        {
/*
            FileStream fileStream = File.Open( strFile, FileMode.CreateNew );

            byte[] fileSignNone = Encoding.ASCII.GetBytes( "123456" );
            fileStream.Write( fileSignNone, 0, fileSignNone.Length );

            fileStream.WriteByte( (byte)stockInfo.StockInfoVer );

            byte[] byteStockCode = ConvertByteArray.ToByteArray( stockInfo.StockCode );
            byte[] byteStockCodeSize = ConvertByteArray.ToByteArray( byteStockCode.Length );
            fileStream.Write( byteStockCodeSize, 0, byteStockCodeSize.Length );
            fileStream.Write( byteStockCode, 0, byteStockCode.Length );

            Debug.WriteLine( stockInfo.StockCode );

            byte[] byteStockName = ConvertByteArray.ToByteArray( stockInfo.StockName );
            byte[] byteStockNameSize = ConvertByteArray.ToByteArray( byteStockName.Length );
            fileStream.Write( byteStockNameSize, 0, byteStockNameSize.Length );
            fileStream.Write( byteStockName, 0, byteStockName.Length );

            Debug.WriteLine( stockInfo.StockName );

            uint uiStockDataCount = 0;
            long lStockDataCountPosition = fileStream.Position;
            byte[] byteStockDataCount = ConvertByteArray.ToByteArray( uiStockDataCount );
            fileStream.Write( byteStockDataCount, 0, byteStockDataCount.Length );

            foreach ( StockData stockData in stockInfo.ToArray() )
            {
                fileStream.WriteByte( (byte)stockData.StockDataVer );

                byte[] byteTradingTime = ConvertByteArray.ToByteArray( stockData.TradingTime.Ticks );
                fileStream.Write( byteTradingTime, 0, byteTradingTime.Length );

                byte[] byteOpenPrice = ConvertByteArray.ToByteArray( stockData.OpenPrice );
                fileStream.Write( byteOpenPrice, 0, byteOpenPrice.Length );

                byte[] byteClosePrice = ConvertByteArray.ToByteArray( stockData.ClosePrice );
                fileStream.Write( byteClosePrice, 0, byteClosePrice.Length );

                byte[] byteHighestPrice = ConvertByteArray.ToByteArray( stockData.HighestPrice );
                fileStream.Write( byteHighestPrice, 0, byteHighestPrice.Length );

                byte[] byteMinimumPrice = ConvertByteArray.ToByteArray( stockData.MinimumPrice );
                fileStream.Write( byteMinimumPrice, 0, byteMinimumPrice.Length );

                byte[] byteDailyTurnover = ConvertByteArray.ToByteArray( stockData.TradingVolume );
                fileStream.Write( byteDailyTurnover, 0, byteDailyTurnover.Length );

                byte[] byteDailyAmount = ConvertByteArray.ToByteArray( stockData.DailyAmount );
                fileStream.Write( byteDailyAmount, 0, byteDailyAmount.Length );

                uiStockDataCount++;
            }

            fileStream.Seek( lStockDataCountPosition, SeekOrigin.Begin );
            byteStockDataCount = ConvertByteArray.ToByteArray( uiStockDataCount );
            fileStream.Write( byteStockDataCount, 0, byteStockDataCount.Length );

            // 最后写入代表文件成功
            fileStream.Seek( 0, SeekOrigin.Begin );
            byte[] fileSign = Encoding.ASCII.GetBytes( "DStock" );
            fileStream.Write( fileSign, 0, fileSign.Length );

            fileStream.Flush();
            fileStream.Close();
*/
        }
コード例 #5
0
        public static bool LoadFileFormatForDStock( string strFile, ref StockInfo stockInfo )
        {
/*
            if ( File.Exists( strFile ) == false )
                return false;
            //else // 修改去掉只读
            //    File.SetAttributes( strFile, FileAttributes.Archive );

            FileStream fileStream  = File.Open( strFile, FileMode.Open );

            byte[] fileSign = new byte[6];
            fileStream.Read( fileSign, 0, fileSign.Length );
            if ( Encoding.ASCII.GetString( fileSign ) != "DStock" )
                return false;

            byte byStockInfoVer = (byte)fileStream.ReadByte();
            //stockInfo.StockInfoVer = (StockInfoVer)byStockInfoVer;

            byte[] byteStockCodeSize = new byte[4];
            fileStream.Read( byteStockCodeSize, 0, byteStockCodeSize.Length );
            byte[] byteStockCode = new byte[ConvertByteArray.ToInt( byteStockCodeSize )];
            fileStream.Read( byteStockCode, 0, byteStockCode.Length );
            stockInfo.StockCode = ConvertByteArray.ToString( byteStockCode );

            Debug.WriteLine( ConvertByteArray.ToString( byteStockCode ) );

            byte[] byteStockNameSize = new byte[4];
            fileStream.Read( byteStockNameSize, 0, byteStockNameSize.Length );
            byte[] byteStockName = new byte[ConvertByteArray.ToInt( byteStockNameSize )];
            fileStream.Read( byteStockName, 0, byteStockName.Length );
            stockInfo.StockName = ConvertByteArray.ToString( byteStockName );

            Debug.WriteLine( ConvertByteArray.ToString( byteStockName ) );

            byte[] byteStockDataCount = new byte[4];
            fileStream.Read( byteStockDataCount, 0, byteStockDataCount.Length );
            uint uiStockDataCount = ConvertByteArray.ToUInt( byteStockDataCount );

            for ( int iIndex = 0; iIndex < uiStockDataCount; iIndex++ )
            {
                StockData stockData = new StockData();

                byte byStockDataVer = (byte)fileStream.ReadByte();
                //stockData.StockDataVer = (StockDataVer)byStockDataVer;

                byte[] byteTradingTime = new byte[8];
                fileStream.Read( byteTradingTime, 0, byteTradingTime.Length );
                stockData.TradingTime = new DateTime( ConvertByteArray.ToLong( byteTradingTime ) );

                byte[] byteOpenPrice = new byte[4];
                fileStream.Read( byteOpenPrice, 0, byteOpenPrice.Length );
                stockData.OpenPrice = ConvertByteArray.ToUInt( byteOpenPrice );

                byte[] byteClosePrice = new byte[4];
                fileStream.Read( byteClosePrice, 0, byteClosePrice.Length );
                stockData.ClosePrice = ConvertByteArray.ToUInt( byteClosePrice );

                byte[] byteHighestPrice = new byte[4];
                fileStream.Read( byteHighestPrice, 0, byteHighestPrice.Length );
                stockData.HighestPrice = ConvertByteArray.ToUInt( byteHighestPrice );

                byte[] byteMinimumPrice = new byte[4];
                fileStream.Read( byteMinimumPrice, 0, byteMinimumPrice.Length );
                stockData.MinimumPrice = ConvertByteArray.ToUInt( byteMinimumPrice );

                byte[] byteDailyTurnover = new byte[8];
                fileStream.Read( byteDailyTurnover, 0, byteDailyTurnover.Length );
                stockData.TradingVolume = ConvertByteArray.ToULong( byteDailyTurnover );

                byte[] byteDailyAmount = new byte[8];
                fileStream.Read( byteDailyAmount, 0, byteDailyAmount.Length );
                stockData.OpenInterest = ConvertByteArray.ToULong( byteDailyAmount );

                stockInfo.AddStockData( stockData );
            }

            fileStream.Close();

            stockInfo.m_StockFilePath = strFile;
            stockInfo.m_IsLoadFile = true;
*/
            return true;
        }
コード例 #6
0
        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;
        }