从钱龙数据中读取股票权息信息导入到数据库

本文介绍了一种从钱龙软件中读取股票权息数据的方法。通过解析特定目录下的文件,可以获取到股票的分红派息等信息,并进一步存入数据库进行管理和分析。
前面写了如果读股票代码和日线数据,下面是如何读股票的权息信息。

钱龙中权息数据存储在QLDATA\history\shase\weight和QLDATA\history\sznse\weight目录下,每个文件对应一只股票。

与前文一样,只贴核心代码:

None.gif        private static void ReadStockWeights(string strPath, string p_strMarket)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
string[] parts = strPath.Split('\\');
InBlock.gif            
string strStockCode = null;
InBlock.gif            
for (int i = parts.Length - 1; i >= 0;i-- )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string strTemp = parts[i];
InBlock.gif                
if (strTemp.ToUpper().EndsWith(".WGT"))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strStockCode 
= strTemp.Substring(0, strTemp.Length - 4) ;
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            Debug.Assert(strStockCode 
!= null);
InBlock.gif            Console.WriteLine(
"Read stock weight from file '" + strPath + "'");
InBlock.gif            FileStream stream 
= new FileStream(strPath, FileMode.Open, FileAccess.Read);
InBlock.gif            BinaryReader b_reader 
= new BinaryReader(stream);
InBlock.gif            List
<StockWeightInfo> weightInfos = new List<StockWeightInfo>();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
while (stream.CanRead && stream.Position < stream.Length)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
int[] oneRow = new int[9];
InBlock.gif                    
forint i=0;i<9;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        oneRow[i] 
= b_reader.ReadInt32();
ExpandedSubBlockEnd.gif                    }
//for
InBlock.gif
                    if (oneRow[8!= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
throw new Exception("Last entry is not empty");
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
//read date
InBlock.gif
                    int nYear = oneRow[0>> 20;
InBlock.gif                    
int nMon = (int)(((uint)(oneRow[0<< 12))>> 28);
InBlock.gif                    
int nDay = (oneRow[0& 0xffff)>> 11;
InBlock.gif
InBlock.gif                    DateTime wgtDate;
InBlock.gif                    
if (nYear == 0 && nMon == 0 && nDay == 0)
InBlock.gif                        wgtDate 
= DateTime.MinValue;
InBlock.gif                    
else
InBlock.gif                            wgtDate 
= new DateTime(nYear, nMon, nDay);
InBlock.gif                    StockWeightInfo wgtInfo 
= new StockWeightInfo();
InBlock.gif                    wgtInfo.m_date 
= wgtDate;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    wgtInfo.m_stockCountAsGift 
= oneRow[1];/**////10000.0f;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    wgtInfo.m_stockCountForSell = oneRow[2];/**////10000.0f;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    wgtInfo.m_priceForSell = oneRow[3];/**////1000.0f;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    wgtInfo.m_bonus = oneRow[4];/**////1000.0f;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    wgtInfo.m_stockCountOfIncreasement = oneRow[5];/**////10000.0f;
InBlock.gif                    wgtInfo.m_stockOwnership = (ulong)oneRow[6];
InBlock.gif                    wgtInfo.m_freeStockCount 
= (ulong)oneRow[7];
InBlock.gif                    
if (!weightInfos.Contains(wgtInfo))
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        weightInfos.Add(wgtInfo);
InBlock.gif                        
//Console.WriteLine();
InBlock.gif                        
//Console.Write(wgtInfo.ToString());
ExpandedSubBlockEnd.gif
                    }

ExpandedSubBlockEnd.gif                }
//while
InBlock.gif
                weightInfos.Sort();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (EndOfStreamException)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"Unexpected end of stream");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                Console.WriteLine(ex.Message);
InBlock.gif                
throw;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                stream.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            SqlCommand cmd 
= new SqlCommand("", m_conn);
InBlock.gif            cmd.Transaction 
= m_tran;
InBlock.gif            cmd.CommandText 
= "INSERT INTO [StockWeightInfos] ([StockCode] ,[Market] ,[Date] ,[StockCountAsGift] ,[StockCountForSell] ,[PriceForSell] ,[Bonus] ,[StockCountOfIncreasement] ,[StockOwnership] ,[FreeStockCount]) " + 
InBlock.gif                               
"VALUES (@StockCode, @Market ,@Date ,@StockCountAsGift ,@StockCountForSell ,@PriceForSell ,@Bonus ,@StockCountOfIncreasement ,@StockOwnership ,@FreeStockCount)";
InBlock.gif            cmd.Parameters.Add(
"@StockCode", SqlDbType.NVarChar, 50);
InBlock.gif            cmd.Parameters.Add(
"@Market", SqlDbType.NVarChar, 50);
InBlock.gif            cmd.Parameters.Add(
"@Date", SqlDbType.DateTime);
InBlock.gif            cmd.Parameters.Add(
"@StockCountAsGift", SqlDbType.Real);
InBlock.gif            cmd.Parameters.Add(
"@StockCountForSell", SqlDbType.Real);
InBlock.gif            cmd.Parameters.Add(
"@PriceForSell", SqlDbType.Real);
InBlock.gif            cmd.Parameters.Add(
"@Bonus", SqlDbType.Real);
InBlock.gif            cmd.Parameters.Add(
"@StockCountOfIncreasement", SqlDbType.Real);
InBlock.gif            cmd.Parameters.Add(
"@StockOwnership", SqlDbType.BigInt);
InBlock.gif            cmd.Parameters.Add(
"@FreeStockCount", SqlDbType.BigInt);
InBlock.gif            
foreach(StockWeightInfo info in weightInfos)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                cmd.Parameters[
"@StockCode"].Value = strStockCode;
InBlock.gif                cmd.Parameters[
"@Market"].Value = p_strMarket;
InBlock.gif                cmd.Parameters[
"@Bonus"].Value = info.m_bonus / 1000.0;
InBlock.gif                
if (info.m_date != DateTime.MinValue)
InBlock.gif                    cmd.Parameters[
"@Date"].Value = info.m_date;
InBlock.gif                
else
InBlock.gif                    cmd.Parameters[
"@Date"].Value = DBNull.Value;
InBlock.gif                cmd.Parameters[
"@FreeStockCount"].Value = info.m_freeStockCount;
InBlock.gif                cmd.Parameters[
"@PriceForSell"].Value = info.m_priceForSell/1000.0;
InBlock.gif                cmd.Parameters[
"@StockCountAsGift"].Value = info.m_stockCountAsGift/10000.0;
InBlock.gif                cmd.Parameters[
"@StockCountForSell"].Value = info.m_stockCountForSell/10000.0;
InBlock.gif                cmd.Parameters[
"@StockCountOfIncreasement"].Value = info.m_stockCountOfIncreasement/10000.0;
InBlock.gif                cmd.Parameters[
"@StockOwnership"].Value = info.m_stockOwnership;
InBlock.gif                
int nCnt=cmd.ExecuteNonQuery();
InBlock.gif                Debug.Assert(nCnt 
== 1);
ExpandedSubBlockEnd.gif            }
//foreach
ExpandedBlockEnd.gif
        }
//ReadStockWeights
None.gif

转载于:https://www.cnblogs.com/sliencer/archive/2007/03/26/688643.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值