Example #1
0
        void processSecBidAskLine(string line, int date, SecProduct product)
        {
            int lineNumber = int.Parse(line.Substring(0, 8).Trim());

            int TIME = int.Parse(line.Substring(8, 9));
            int sec = (TIME / 1000);
            int millSec = TIME % 1000;

            char type = line[17];

            string[] arrVBar = line.Substring(19).Split(VBAR);

            ProductEvent pEvent = null;
            if (type == 'A' || type == 'B' || type == 'C')
            {
                //return;//hack for dayEndOnly
                pEvent = new BidAskEvent(product, type, date, sec, millSec, 0);
            }
            else if (type == 'D' || type == 'E')
                pEvent = new ProductEvent(product, date, sec, millSec);
            else
                return;

            if (!eventSecondList.ContainsKey(sec))
                eventSecondList.Add(sec, new EventInSecond());

            eventSecondList[sec].events.Add(pEvent);

            if (type == 'E')
            {
                pEvent.EnablesStatistics();
                char ch = arrVBar[1][0];
                float val = float.Parse(arrVBar[1].Substring(1));
                if (ch == 'C')
                    pEvent.DayClose = val;
                else
                {
                    pEvent.PrevClose = val;
                    pEvent.Suspended = (ch == 'S') ? 'Y' : 'N';
                }
                return;
            }

            if (arrVBar[0].Length > 0)
            {
                string[] arr = arrVBar[0].Split(COMMA);
                pEvent.EnablesStatistics();
                pEvent.Day2SecHighest = float.Parse(arr[0]);
                pEvent.Day2SecLowest = float.Parse(arr[1]);
                pEvent.Day2SecTradedShare = float.Parse(arr[2]);
                pEvent.Day2SecTradedVolume = float.Parse(arr[3]);
                pEvent.LastPrice = (arr[4] == "-") ? float.NaN : float.Parse(arr[4]);
            }

            if (arrVBar.Length == 1)
                return;

            BidAskEvent baEvent = pEvent as BidAskEvent;

            // handle first section
            {
                string[] arr1 = arrVBar[1].Split(COMMA);
                int queueDepth1 = (arr1.Length - 1) / 2;
                float price1 = float.Parse(arr1[0]);

                List<PriceQty> pList1 = new List<PriceQty>();
                float[] priceSpread = (type == BidAsk.ASK) ?
                         HKExPriceSpreadFunctions.getPriceLevel(price1, true, 10)
                        : HKExPriceSpreadFunctions.getPriceLevel(price1, false, 10);

                for (int i = 0; i < queueDepth1; i++)
                {
                    float price = priceSpread[i];
                    int qLen = int.Parse(arr1[i * 2 + 1]);
                    long LongQty = (int)(float.Parse(arr1[i * 2 + 2])*1000);
                    int qty = (LongQty > int.MaxValue) ? int.MaxValue - 1 :(int) (LongQty);

                    if (qLen > 0 || qty > 0)
                        pList1.Add(new PriceQty(price, qty, qLen));
                }
                if (type == 'A')
                    baEvent.asks = pList1.ToArray();
                else
                    baEvent.bids = pList1.ToArray();
            }
            // handle 2nd section
            if (type == BidAsk.BOTH)
            {
                string[] arr2 = arrVBar[2].Split(COMMA);
                int queueDepth2 = (arr2.Length - 1) / 2;
                float price2 = float.Parse(arr2[0]);
                List<PriceQty> pList2 = new List<PriceQty>();
                float[] priceSpread = HKExPriceSpreadFunctions.getPriceLevel(price2, true, 10);

                for (int i = 0; i < queueDepth2; i++)
                {
                    float price = priceSpread[i];
                    int qLen = int.Parse(arr2[i * 2 + 1]);
                    int qty = (int)(float.Parse(arr2[i * 2 + 2])*1000);
                    if (qLen > 0 || qty > 0)
                        pList2.Add(new PriceQty(price, qty, qLen));
                }
                baEvent.asks = pList2.ToArray();
            }
        }
Example #2
0
        public bool readProductInfoSecurities(string rootFolder, int date, string tempFolder = null)
        {
            // date 20110627
            string subFolder     = String.Format("{0:####-##}", date / 100);

            string rawBidAskPath = rootFolder + RawDataFolder_SecuritiesBidAsk + "\\" + subFolder + "\\";
            string rawBidAskFilename = rawBidAskPath + "ba_cm_" + date + ".zip";

            // if already have parsed Zip file, use it directly
            string parsedPath   = rootFolder + ParsedDataFolder_Securities + "\\" + subFolder + "\\";
            string parsedBAZipName = parsedPath + date + "_SecBA.zip";
            string parsedTRZipName = parsedPath + date + "_SecTR.zip";

            if (tempFolder != null && Directory.Exists(tempFolder) == false)
                Directory.CreateDirectory(tempFolder);

            if (File.Exists(parsedBAZipName) == false || File.Exists(parsedTRZipName) == false)
                if (parseProductSecurities(rootFolder, date, tempFolder) == false) // raw file don't exist also?
                    return false;

            // read info
            string[] lines = File.ReadAllLines(parsedPath + date + "_mast.txt");

            foreach (string line in lines)
            {
                string STKCODE = line.Substring(0, 5).Trim();
                string STK_ID = line.Substring(6, 9).Trim();
                int DATE = int.Parse(line.Substring(16, 8).Trim());
                string FULL_ID = line.Substring(25, 12).Trim();
                string FULL_NAME = line.Substring(40, 60).Trim();
                char STATUS = line[101];
                string MERGE_TO = line.Substring(106, 5).Trim();
                int TRAD_CURR = int.Parse(line.Substring(103, 2).Trim());
                int SE_TYPE = int.Parse(line.Substring(112, 4).Trim());

                bool isMB = line[117]=='M';

                char productType = ProductType.Share;
                if (SE_TYPE >= 301 && SE_TYPE <= 307)
                    productType = ProductType.Warrants;
                //else if (SE_TYPE == 308)
                    // productType = ProductType.BullBear;
                else if (SE_TYPE == 401)
                    productType = ProductType.Debt;
                else if (SE_TYPE == 501)
                    productType = ProductType.ETF;

                SecProduct product = new SecProduct(STKCODE, productType, STK_ID, FULL_ID,
                    FULL_NAME, MERGE_TO, STATUS, TRAD_CURR, isMB);

                ProductTable[STKCODE] = product;
            }

            return true;
        }