Пример #1
0
        public static Tick parseline(string line, string sym)
        {
            int decimalplaces = 5;

            string[] r = line.Split(',');            

            var t = new TickImpl(sym);

            if(sym.Contains("JPY"))  
                decimalplaces = 3;
            
            DateTime dt;
            if (DateTime.TryParseExact(r[DATETIME], "yyyyMMdd HH:mm:ss.fff", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
            {
                t.date = Util.ToTLDate(dt.Date);
                t.time = Util.ToTLTime(dt);
            }

            decimal b, a;
            if (decimal.TryParse(r[BID], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out b))
                t.bid = b;
            if (decimal.TryParse(r[ASK], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out a))
                t.ask = a;
            
            //simulate bid/offer midpoint trade-tick
            decimal px = Math.Round((a + b) / 2, decimalplaces); 
            t.trade = px;

            //there is no size information in the data
            //assume bid/offer size of 500K basecurrency units
            //simulated midpoint trade of 1 BCU, for compatibility only
            t.bs = 500000; t.os = 500000; t.size = 1;  

            return t;
        }
Пример #2
0
        public void fromApp(QuickFix.Message message, SessionID sessionID)
        {
            // receiving messages
            Symbol sym = new Symbol();
            message.getField(sym);
            Tick k = new TickImpl(sym.getValue());
			
			{
            // bid
            BidPx bp = new BidPx();
            BidSize bs = new BidSize();
            k.bid = (decimal)bp.getValue();
            k.bs = (int)message.getField(bs).getValue();
			}
			
			{
            // ask
            OfferPx op = new OfferPx();
            OfferSize os = new OfferSize();
            k.ask = (decimal)op.getValue();
            k.os = (int)message.getField(os).getValue();
			}
			
			{
            // last
            Price price = new Price();
            message.getField(price);
            k.trade = (decimal)price.getValue();
			}
			
            tl.newTick(k);
            //ClOrdID clOrdID = new ClOrdID();
            //message.getField(clOrdID);
        }
Пример #3
0
 void rs_LevelOneStreaming_TickWithArgs(DateTime time, AmeritradeBrokerAPI.ATradeArgument args)
 {
     if (args.FunctionType != AmeritradeBrokerAPI.RequestState.AsyncType.LevelOneStreaming) return;
     Tick t = new TickImpl();
     /*  don't understand the time format provided here
     int date = 0;
     int ttime = 0;
     if (int.TryParse(args.oLevelOneData[0].quotedate, out date))
         t.date = date;
     if (int.TryParse(args.oLevelOneData[0].quotetime, out ttime))
         t.time = ttime;
      */
     t.date = Util.ToTLDate(DateTime.Now);
     t.time = Util.DT2FT(DateTime.Now);
     t.symbol = args.oLevelOneData[0].stock;
     t.bid = Convert.ToDecimal(args.oLevelOneData[0].bid);
     t.ask = Convert.ToDecimal(args.oLevelOneData[0].ask);
     t.ex = args.oLevelOneData[0].exchange;
     t.trade = Convert.ToDecimal(args.oLevelOneData[0].last);
     t.size = Convert.ToInt32(args.oLevelOneData[0].lastsize) * 100;
     t.bs = Convert.ToInt32(args.oLevelOneData[0].bid_size);
     t.os = Convert.ToInt32(args.oLevelOneData[0].ask_size);
     tl.newTick(t);
     
 }
Пример #4
0
        // here is where a line is converted
        public static Tick parseline(string line, string sym, int date)
        {
            // split line
            string[] r = line.Split(',');
            // create tick for this symbol
            Tick k = new TickImpl(sym);
            k.date = date;
            char type = 'z';

            long mtime = 0;
            if(long.TryParse(r[TIME], out mtime))
            {
                int hr = (int) mtime / 3600000;
                int min = (int) (mtime % 3600000) / 60000;
                int sec = (int) (mtime % 60000) / 1000;
                int ftime = Util.TL2FT(hr, min, sec);
                k.time = ftime;
            }
            int size = 0;
            if (int.TryParse(r[SHARES], out size))
                k.size = size;
            decimal price = 0.0M;
            if(decimal.TryParse(r[PRICE], out price))
                k.trade = price / 10000;

            return k;
        }
Пример #5
0
 // here is where a line is converted
 public static Tick parseline(string line, int defaultsize, int decimalplaces )
 {
     // split line
     string[] r = line.Split(',');
     // create tick for this symbol
     Tick k = new TickImpl(r[SYM]);
     // setup temp vars
     int iv = 0;
     decimal dv = 0;
     // parse date
     if (int.TryParse(r[DATE], out iv))
         k.date = iv;
     // parse time
     if (int.TryParse(r[TIME], out iv))
         k.time = iv * 100;
     // parse close as trade price
     if (decimal.TryParse(r[TRADE], out dv))
     {
         decimal divisor = (decimal)(  Math.Pow( 10, decimalplaces ) );
         // k.trade = (decimal)dv / 100;
         k.trade = (decimal) dv / divisor;
         k.size = defaultsize;
     }
     // return tick
     return k;
 }
Пример #6
0
    // here is where a line is converted
    public static Tick parseline(string line, string sym)
    {
        // split line
        string[] r = line.Split(',');
        // create tick for this symbol
        Tick k = new TickImpl(sym);
        // setup temp vars
        int iv = 0;
        decimal dv = 0;
        DateTime date;
        // parse date
        if (DateTime.TryParse(r[DATE], out date))
            k.date = Util.ToTLDate(date);
        // parse time
        if (int.TryParse(r[TIME], out iv))
            k.time = iv * 100;
        // parse close as trade price
        if (decimal.TryParse(r[CLOSE], out dv))
            k.trade = dv;
        // parse volume (up and down); up = trade volume at prior ask; down = trade volume at prior bid
        int volumeAtAsk = 0, volumeAtBid = 0;
        if (int.TryParse(r[UP], out volumeAtAsk) && int.TryParse(r[DOWN], out volumeAtBid))
            k.size = volumeAtAsk + volumeAtBid;

        // return tick
        return k;
    }
Пример #7
0
 // here is where a line is converted
 public static Tick parseline(string line, string sym, int defaultsize)
 {
     // split line
     string[] r = line.Split(',');
     // create tick for this symbol
     Tick k = new TickImpl(sym);
     // setup temp vars
     int iv = 0;
     decimal dv = 0;
     DateTime date;
     // parse date
     if (DateTime.TryParse(r[DATE], out date))
         k.date = Util.ToTLDate(date);
     // parse time
     if (int.TryParse(r[TIME], out iv))
         k.time = iv * 100;
     // parse close as trade price
     if (decimal.TryParse(r[CLOSE], out dv))
     {
         k.trade = dv;
         k.size = defaultsize;
     }
     // return tick
     return k;
 }
Пример #8
0
        public void Hours()
        {

            System.IO.StreamReader sr = new System.IO.StreamReader("TestWAG.txt");
            sr.ReadLine();
            sr.ReadLine();

            BarListImpl bl = new BarListImpl(BarInterval.Hour, "WAG");
            Tick k = new TickImpl();
            int tickcount = 0;
            while (!sr.EndOfStream) 
            {
                k = eSigTick.FromStream(bl.Symbol, sr);
                if (tickcount == 0)
                {
                    Assert.IsTrue(k.isValid);
                    Assert.AreEqual(20070926041502, k.datetime);
                    Assert.AreEqual(20070926, k.date);
                    Assert.AreEqual(041502, k.time);
                    Assert.AreEqual(43.81m, k.bid);
                    Assert.AreEqual(51.2m, k.ask);
                    Assert.AreEqual(1, k.bs);
                    Assert.AreEqual(1, k.os);
                    Assert.IsTrue(k.be.Contains("PSE"));
                    Assert.IsTrue(k.oe.Contains("PSE"));
                }
                tickcount++;
                bl.newTick(k);
            }
            // hour is what we asked for
            Assert.AreEqual(BarInterval.Hour,bl.DefaultInterval);
            // there are 4 trades on hour intervals, 6/7/8/9
            Assert.AreEqual(4,bl.Count);

        }
Пример #9
0
 // here is where a line is converted
 public static Tick parseline(string line, string sym)
 {
     // split line
     string[] r = line.Split(',');
     // create tick for this symbol
     Tick k = new TickImpl(sym);
     // setup temp vars
     int iv = 0;
     decimal dv = 0;
     DateTime date;
     // parse date
     if (DateTime.TryParse(r[DATE], out date))
         k.date = Util.ToTLDate(date);
     // parse time - remove colons to give format HHMMSS
     if (int.TryParse(r[TIME].Replace(":", ""), out iv))
         k.time = iv;
     // trade price
     if (decimal.TryParse(r[PRICE], out dv))
         k.trade = dv;
     // size of trade
     if (int.TryParse(r[VOLUME], out iv))
         k.size = iv;
     // return tick
     return k;
 }
Пример #10
0
        // here is where a line is converted
        public static Tick[] parseline(string line, string sym)
        {
            // split line
            line=line.Remove(8, 1);
            line=line.Insert(8, ";");
            string[] r = line.Split(';');
            // create tick for this symbol
            Tick[] result = new Tick[4];
            Tick high = new TickImpl(sym);
            Tick low = new TickImpl(sym);
            Tick open = new TickImpl(sym);
            Tick close = new TickImpl(sym);
            long dt = 0;
            int tt;
            if (long.TryParse(r[DATE], out dt))
            {
                open.date = (int)(dt);
                high.date = (int)(dt);
                low.date = (int)(dt);
                close.date = (int)(dt);
            }
            //r[TIME]=r[TIME].Substring(0, 4);
            if (int.TryParse(r[TIME], out tt))
            {
                if (tt < 040000) tt += 120000;
                open.time = tt;
                close.time = tt;
                high.time = tt;
                low.time = tt;

                open.datetime = dt * 1000000 + tt;
                high.datetime = dt * 1000000 + tt;
                low.datetime = dt * 1000000 + tt;
                close.datetime = dt * 1000000 + tt;
            }

            int size = 0;
            if (int.TryParse(r[VOL], out size))
            {
                high.size = Math.Max(1, size / 4);
                low.size = Math.Max(1, size / 4);
                open.size = Math.Max(1, size / 4);
                close.size = Math.Max(1, size/4);
            }
            decimal price = 0.0M;
            if (decimal.TryParse(r[HIGH], out price))
                high.trade = price;
            if (decimal.TryParse(r[OPEN], out price))
                open.trade = price;
            if (decimal.TryParse(r[LOW], out price))
                low.trade = price;
            if (decimal.TryParse(r[CLOSE], out price))
                close.trade = price;
            result[0] = open;
            result[1] = high;
            result[2] = low;
            result[3] = close;
            return result;
        }
Пример #11
0
        // here is where a line is converted
        public static Tick parseline(string line, string sym, int date)
        {
            // split line
            string[] r = line.Split(',');
            // create tick for this symbol
            Tick k = new TickImpl(sym);
            k.date = date;
            int orderid = 0;

            char type = 'z';
            char.TryParse(r[TYPE], out type);
            long mtime = 0;
            if (long.TryParse(r[TIME], out mtime))
            {
                int hr = (int) mtime / 3600000;
                int min = (int) (mtime % 3600000) / 60000;
                int sec = (int) (mtime % 60000) / 1000;
                int ftime = Util.TL2FT(hr, min, sec);
                k.time = ftime;
            }
            int size = 0;
            int.TryParse(r[SHARES], out size);
                
            decimal price = 0.0M;
            decimal.TryParse(r[PRICE], out price);
            switch(type)
            { 
                case 'B':
                    k.bid = price / 10000;
                    k.BidSize = size;
                    break;
                case 'S':
                    k.ask = price / 10000;
                    k.AskSize = size;
                    break;
                case 'F':
                case 'T':
                case 'E':
                    k.trade = price / 10000;
                    k.size = size;
                    break;
                case 'D':
                case 'X':
                    k.trade = price / 10000;
                    k.size = size;
                    break;
                default:
                    k.trade = price / 10000;
                    k.size = size;
                    break;

            }

            return k;
        }
Пример #12
0
        public static TickImpl NewTrade(string sym, int date, int time, decimal trade, int size, string ex)
        {
            TickImpl t = new TickImpl(sym);

            t.date  = date;
            t.time  = time;
            t.trade = trade;
            t.size  = size;
            t.ex    = ex.Trim();
            t.bid   = 0;
            return(t);
        }
Пример #13
0
        // here is where a line is converted
        public static Tick[] parseline(string line, string sym)
        {
            // split line
            string[] r = line.Split(',');
            sym = r[SYMBOL];
            // create tick for this symbol
            Tick[] result = new Tick[4];
            Tick high = new TickImpl(sym);
            Tick low = new TickImpl(sym);
            Tick open = new TickImpl(sym);
            Tick close = new TickImpl(sym);
            long dt=0;

            if (long.TryParse(r[DATETIME], out dt))
            {
                open.datetime = dt;
                high.datetime = dt;
                low.datetime = dt;
                close.datetime = dt;
                open.date = (int)(dt/10000);
                high.date = (int)(dt/10000);
                low.date = (int)(dt/10000);
                close.date = (int)(dt/10000);
                open.time = ((int)open.datetime - open.date * 10000)*100;
                close.time = ((int)close.datetime - close.date * 10000)*100;
                high.time = ((int)high.datetime - high.date * 10000)*100;
                low.time = ((int)low.datetime - low.date * 10000)*100;
            }
            int size = 0;
            if (int.TryParse(r[VOL], out size))
            {
                high.size = Math.Max(1, size / 4);
                low.size = Math.Max(1, size / 4);
                open.size = Math.Max(1, size / 4);
                close.size = Math.Max(1, size / 4);
            }
            decimal price = 0.0M;
            if (decimal.TryParse(r[HIGH], out price))
                high.trade = price;
            if (decimal.TryParse(r[OPEN], out price))
                open.trade = price;
            if (decimal.TryParse(r[LOW], out price))
                low.trade = price;
            if (decimal.TryParse(r[CLOSE], out price))
                close.trade = price;
            result[0] = open;
            result[1] = high;
            result[2] = low;
            result[3] = close;
            return result;
        }
Пример #14
0
        public static TickImpl GetQuoteTick(string strLine)
        {
            var values = strLine.Split(',');

            if (values.Length < 14)
            {
                return(new TickImpl());
            }
            string   strSym = values[2];
            TickImpl q      = new TickImpl(strSym);

            //Date
            string strDate = values[0];

            q.date = Convert.ToInt32(strDate);
            //Time
            string strTime = values[1];

            strTime = Regex.Replace(strTime, @":", "").Substring(0, 6);
            q.time  = Convert.ToInt32(strTime);
            //DateTime
            string strDateTime = strDate + strTime;

            q.datetime = Convert.ToInt64(strDateTime);
            //Bid / Ask
            string strScale = values[6];
            string strBid   = values[9];
            string strAsk   = values[12];

            int numDecPlace = Convert.ToInt32(Math.Log10(Convert.ToDouble(1 / Const.IPRECV)));
            int appendZeros = numDecPlace - Convert.ToInt32(strScale);

            strBid = appendZeros > 0 ? strBid + new string('0', appendZeros) : strBid.Substring(0, strBid.Length + appendZeros);
            strAsk = appendZeros > 0 ? strAsk + new string('0', appendZeros) : strAsk.Substring(0, strAsk.Length + appendZeros);
            q._bid = (ulong)Convert.ToInt64(strBid);
            q._ask = (ulong)Convert.ToInt64(strAsk);

            // BidSize / AskSize
            string strBidSize = values[10];
            string strAskSize = values[13];

            q.bs = Convert.ToInt32(strBidSize);
            q.os = Convert.ToInt32(strAskSize);

            // Exchange
            q.be = values[8];
            q.oe = values[11];

            return(q);
        }
Пример #15
0
        public static Tick Deserialize(string msg)
        {
            string [] r = msg.Split(',');
            Tick      t = new TickImpl();
            decimal   d = 0;
            int       i = 0;

            t.symbol = r[(int)TickField.symbol];
            if (decimal.TryParse(r[(int)TickField.trade], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
            {
                t.trade = d;
            }
            if (decimal.TryParse(r[(int)TickField.bid], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
            {
                t.bid = d;
            }
            if (decimal.TryParse(r[(int)TickField.ask], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
            {
                t.ask = d;
            }
            if (int.TryParse(r[(int)TickField.tsize], out i))
            {
                t.size = i;
            }
            if (int.TryParse(r[(int)TickField.asksize], out i))
            {
                t.os = i;
            }
            if (int.TryParse(r[(int)TickField.bidsize], out i))
            {
                t.bs = i;
            }
            if (int.TryParse(r[(int)TickField.time], out i))
            {
                t.time = i;
            }
            if (int.TryParse(r[(int)TickField.date], out i))
            {
                t.date = i;
            }
            if (int.TryParse(r[(int)TickField.tdepth], out i))
            {
                t.depth = i;
            }
            t.ex       = r[(int)TickField.tex];
            t.be       = r[(int)TickField.bidex];
            t.oe       = r[(int)TickField.askex];
            t.datetime = t.date * 1000000 + t.time;
            return(t);
        }
Пример #16
0
        // here is where a line is converted
        public static Tick parseline(string line, int defaultsize, int decimalplaces)
        {
            // split line
            string[] r;
            if (line.Contains(","))
                r = line.Split(','); // optional CQG format
            else
                r = line.Split(' '); // standard CQG format

            // create tick for this symbol
            string symbol = r[SYM];

            Tick k = new TickImpl(symbol);
            // setup temp vars
            int iv = 0;
            decimal dv = 0;
            // parse date
            if (int.TryParse(r[DATE], out iv))
                k.date = iv;
            // parse time
            if (int.TryParse(r[TIME], out iv))
                k.time = iv * 100;

            // parse price
            if (decimal.TryParse(r[PRICE], out dv))
            {
                decimal divisor = (decimal)(Math.Pow(10, decimalplaces));
                dv = (decimal)dv / divisor;
                string type = r[TYPE];
                if (type == "T") // trade
                {
                    k.trade = dv;
                    k.size = defaultsize;
                }
                else if (type == "B") // bid
                {
                    k.bid = dv;
                    k.bs = defaultsize;
                }
                else if (type == "A") // ask
                {
                    k.ask = dv;
                    k.os = defaultsize;
                }
            }
            // return tick
            return k;
        }
Пример #17
0
        /// <summary>
        /// Loads a tick straight from an EPF file in the form of a StreamReader
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="sr">The sr.</param>
        /// <returns></returns>
        public static Tick FromStream(string symbol,StreamReader sr)
        {
            TickImpl t = new TickImpl();
            string line = "";
            try
            {
                line = sr.ReadLine();
            }
            catch (Exception) { return t; }
            if (line == null) return t; // blank line
            string[] r = line.Split(',');
            if (r.Length < 6) return t;
            decimal td = 0;
            int ti = 0;

            if (r[(int)Q.TYPE] == TRADE)
            {
                if (decimal.TryParse(r[(int)T.PRICE], out td))
                    t.trade = td;
                if (int.TryParse(r[(int)T.SIZE], out ti))
                    t.size = ti;
                t.ex = r[(int)T.EXCH];
            }
            else
            {
                if (r.Length < 9) return t;
                if (decimal.TryParse(r[(int)Q.BID], out td))
                    t.bid = td;
                if (decimal.TryParse(r[(int)Q.ASK], out td))
                    t.ask = td;
                if (int.TryParse(r[(int)Q.BIDSIZE], out ti))
                    t.bs = ti;
                if (int.TryParse(r[(int)Q.ASKSIZE], out ti))
                    t.os = ti;
                t.be = r[(int)Q.BIDEX];
                t.oe = r[(int)Q.ASKEX];
            }
            t.symbol = symbol;
            if (int.TryParse(r[(int)Q.TIME], out ti))
            {
                t.time = ti;
            }
            if (int.TryParse(r[(int)Q.DATE], out ti))
                t.date = ti + 20000000;
            t.datetime = ((long)t.date * 1000000) + (long)t.time;
            return t;
        }
Пример #18
0
        public static TickImpl NewQuote(string sym, int date, int time, decimal bid, decimal ask, int bidsize, int asksize, string be, string oe, int depth)
        {
            TickImpl q = new TickImpl(sym);

            q.date    = date;
            q.time    = time;
            q.bid     = bid;
            q.ask     = ask;
            q.be      = be.Trim();
            q.oe      = oe.Trim();
            q.AskSize = asksize;
            q.BidSize = bidsize;
            q.trade   = 0;
            q.size    = 0;
            q.depth   = depth;
            return(q);
        }
Пример #19
0
        /// <summary>
        /// convert a bar into an array of ticks
        /// </summary>
        /// <param name="bar"></param>
        /// <returns></returns>
        public static Tick[] ToTick(Bar bar)
        {
            if (!bar.isValid)
            {
                return(new Tick[0]);
            }
            List <Tick> list = new List <Tick>();

            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime, bar.Open,
                                       (int)((double)bar.Volume / 4), string.Empty));
            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime,
                                       bar.High, (int)((double)bar.Volume / 4), string.Empty));
            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime, bar.Low,
                                       (int)((double)bar.Volume / 4), string.Empty));
            list.Add(TickImpl.NewTrade(bar.Symbol, bar.Bardate, bar.Bartime,
                                       bar.Close, (int)((double)bar.Volume / 4), string.Empty));
            return(list.ToArray());
        }
Пример #20
0
        public void Basics()
        {
            const string sym = "TST";
            const int d = 20080509;
            const int t = 93500;
            const string x = "NYSE";
            TickImpl[] ticklist = new TickImpl[] { 
                TickImpl.NewTrade(sym,d,t,10,100,x),
                TickImpl.NewTrade(sym,d,t+100,10,100,x),
                TickImpl.NewTrade(sym,d,t+200,10,100,x),
                TickImpl.NewTrade(sym,d,t+300,10,100,x),
                TickImpl.NewTrade(sym,d,t+400,15,100,x), // blade up
                TickImpl.NewTrade(sym,d,t+500,16,100,x), // new bar (blades reset)
                TickImpl.NewTrade(sym,d,t+600,16,100,x),
                TickImpl.NewTrade(sym,d,t+700,10,100,x), // blade down
                TickImpl.NewTrade(sym,d,t+700,10,100,x), // still a blade down (same bar)
                TickImpl.NewTrade(sym,d,t+800,15,100,x), 
                TickImpl.NewTrade(sym,d,t+1500,15,800,x), // volume spike
                TickImpl.NewTrade(sym,d,t+2000,15,100,x), 
                TickImpl.NewTrade(sym,d,t+2500,15,100,x), 
            };

            BarListImpl bl = new BarListImpl(BarInterval.FiveMin,sym);
            Blade b = new Blade();
            Assert.That(b.BladePercentage != 0);
            b = new Blade(.2m); // 20 percent move is a blade
            int up=0,down=0,newbar=0,bigvol=0;

            foreach (TickImpl k in ticklist)
            {
                bl.newTick(k);
                b.newBar(bl);
                if (bl.NewBar) newbar++;
                if (b.isBladeUP) up++;
                if (b.isBladeDOWN) down++;
                if (b.isBigVolume) bigvol++;
            }

            Assert.AreEqual(1, up);
            Assert.AreEqual(2,down);
            Assert.AreEqual(5, newbar);
            Assert.AreEqual(1,bigvol);

        }
Пример #21
0
        public static TickImpl GetTradeTick(string strLine)
        {
            var values = strLine.Split(',');

            if (values.Length < 11)
            {
                return(new TickImpl());
            }
            string   strSym = values[2];
            TickImpl q      = new TickImpl(strSym);

            //Date
            string strDate = values[0];

            q.date = Convert.ToInt32(strDate);
            //Time
            string strTime = values[1];

            strTime = Regex.Replace(strTime, @":", "").Substring(0, 6);
            q.time  = Convert.ToInt32(strTime);
            //DateTime
            string strDateTime = strDate + strTime;

            q.datetime = Convert.ToInt64(strDateTime);
            //TradePrice
            string strScale      = values[6];
            string strTradePrice = values[9];

            int numDecPlace = Convert.ToInt32(Math.Log10(Convert.ToDouble(1 / Const.IPRECV)));
            int appendZeros = numDecPlace - Convert.ToInt32(strScale);

            strTradePrice = appendZeros > 0 ? strTradePrice + new string('0', appendZeros) : strTradePrice.Substring(0, strTradePrice.Length + appendZeros);
            q._trade      = (ulong)Convert.ToInt64(strTradePrice);

            // TradeSize
            string strTradeSize = values[10];

            q.size = Convert.ToInt32(strTradeSize);

            // Exchange
            q.ex = values[8];

            return(q);
        }
Пример #22
0
 /// <summary>
 /// get a tick in tick format
 /// </summary>
 /// <param name="sym"></param>
 /// <returns></returns>
 public Tick this[int idx]
 {
     get
     {
         Tick k = new TickImpl(last.getlabel(idx));
         k.date  = date[idx];
         k.time  = time[idx];
         k.trade = last[idx];
         k.size  = ts[idx];
         k.ex    = ex[idx];
         k.bid   = bid[idx];
         k.bs    = bs[idx];
         k.be    = be[idx];
         k.ask   = ask[idx];
         k.os    = os[idx];
         k.oe    = oe[idx];
         return(k);
     }
 }
Пример #23
0
 public static TickImpl Copy(Tick c)
 {
     TickImpl k = new TickImpl();
     if (c.symbol != "") k.symbol = c.symbol;
     k.time = c.time;
     k.date = c.date;
     k.datetime = c.datetime;
     k.size = c.size;
     k.depth = c.depth;
     k.trade = c.trade;
     k.bid = c.bid;
     k.ask = c.ask;
     k.bs = c.bs;
     k.os = c.os;
     k.be = c.be;
     k.oe = c.oe;
     k.ex = c.ex;
     return k;
 }
Пример #24
0
        public static Tick parseline(string line)
        {
            string[] r = line.Split(',');
            TickImpl k = new TickImpl(r[SYM]);

            DateTime dt = DateTime.Parse(r[DATE] + ' ' + r[TIME]);
            k.time = Util.DT2FT(dt);
            k.date = dt.Year * 10000 + dt.Month * 100 + dt.Day;

            if(r[TYPE] == "Trade"){
                k.trade = Convert.ToDecimal(r[PRICE]);
                k.size = Convert.ToInt32(r[VOLUME]);
            } else {
                k.bid = Convert.ToDecimal(r[BID]);
                k.bs = Convert.ToInt32(r[BIDSIZE]);
                k.ask = Convert.ToDecimal(r[ASK]);
                k.os = Convert.ToInt32(r[ASKSIZE]);
            }
            return k;
        }
Пример #25
0
        public void QuoteOnlyTest()
        {
            TickImpl[] timesales = new TickImpl[] {
                TickImpl.NewBid("TST",100m,100),
                TickImpl.NewAsk("TST",100.1m,200),
            };

            Blade b = new Blade();
            BarListImpl bl = new BarListImpl(BarInterval.FiveMin,"TST");

            foreach (TickImpl k in timesales)
            {
                bl.newTick(k);
                b.newBar(bl);
            }

            // average volume should be zero bc
            // with only quotes we should have no bars to process
            Assert.That(b.AvgVol(bl) == 0, b.AvgVol(bl).ToString());
            Assert.That(!bl.Has(1), bl.ToString());
        }
Пример #26
0
        public static Tick Deserialize(string msg)
        {
            string [] r = msg.Split(',');
            Tick      t = new TickImpl();

            t.Sec      = SecurityImpl.Parse(r[(int)TickField.symbol]);
            t.symbol   = t.Sec.Symbol;
            t.trade    = Convert.ToDecimal(r[(int)TickField.trade]);
            t.size     = Convert.ToInt32(r[(int)TickField.tsize]);
            t.bid      = Convert.ToDecimal(r[(int)TickField.bid]);
            t.ask      = Convert.ToDecimal(r[(int)TickField.ask]);
            t.os       = Convert.ToInt32(r[(int)TickField.asksize]);
            t.bs       = Convert.ToInt32(r[(int)TickField.bidsize]);
            t.ex       = r[(int)TickField.tex];
            t.be       = r[(int)TickField.bidex];
            t.oe       = r[(int)TickField.askex];
            t.time     = Convert.ToInt32(r[(int)TickField.time]);
            t.date     = Convert.ToInt32(r[(int)TickField.date]);
            t.datetime = t.date * 1000000 + t.time;
            t.depth    = Convert.ToInt32(r[(int)TickField.tdepth]);
            return(t);
        }
Пример #27
0
        public void Basics()
        {
            TickImpl t = new TickImpl();
            Assert.That(!t.isValid);
            t.symbol = "IBM";
            t.size = 100;
            t.trade = 1;
            Assert.That(t.isValid);
            Assert.That(t.isTrade);
            Assert.That(!t.isQuote);

            t = new TickImpl("TST");
            t.TradeSize = 100;
            Assert.That(t.TradeSize == t.ts * 100, t.TradeSize.ToString());

            t = new TickImpl("TST");
            t.BidSize = 200;
            Assert.That(t.BidSize == t.bs * 100, t.BidSize.ToString());

            t = new TickImpl("TST");
            t.AskSize = 300;
            Assert.That(t.AskSize == t.os*100, t.AskSize.ToString());
        }
Пример #28
0
        public static TickImpl Copy(Tick c)
        {
            TickImpl k = new TickImpl();

            if (c.symbol != "")
            {
                k.symbol = c.symbol;
            }
            k.time     = c.time;
            k.date     = c.date;
            k.datetime = c.datetime;
            k.size     = c.size;
            k.depth    = c.depth;
            k.trade    = c.trade;
            k.bid      = c.bid;
            k.ask      = c.ask;
            k.bs       = c.bs;
            k.os       = c.os;
            k.be       = c.be;
            k.oe       = c.oe;
            k.ex       = c.ex;
            return(k);
        }
Пример #29
0
 // here is where a line is converted
 public static Tick parseline(string line, string SYMBOL)
 {
     // split line
     string[] r = line.Split(',');
     // create tick for this symbol
     Tick k = new TickImpl(SYMBOL);
     // setup temp vars
     int iv = 0;
     decimal dv = 0;
     // parse date
     if (int.TryParse(r[DATE], out iv))
         k.date = iv + 20000000;
     // parse time
     if (int.TryParse(r[TIME], out iv))
         k.time = iv;
     // parse close as trade price
     if (decimal.TryParse(r[TRADE], out dv))
     {
         k.trade = dv;
         k.size = geti(r[SIZE]);
         k.ex = r[EXCH];
     }
     if (decimal.TryParse(r[BID], out dv))
     {
         k.bid = dv;
         k.bs = geti(r[BIDSIZE]);
         k.be = r[BIDEX];
     }
     if (decimal.TryParse(r[ASK], out dv))
     {
         k.ask = dv;
         k.os = geti(r[ASKSIZE]);
         k.oe = r[ASKEX];
     }
     // return tick
     return k;
 }
Пример #30
0
 /// <summary>
 /// get a tick in tick format
 /// </summary>
 /// <param name="sym"></param>
 /// <returns></returns>
 public Tick this[string sym]
 {
     get
     {
         int idx = last.getindex(sym);
         if (idx < 0)
         {
             return(new TickImpl());
         }
         Tick k = new TickImpl(last.getlabel(idx));
         k.date  = date[idx];
         k.time  = time[idx];
         k.trade = last[idx];
         k.size  = ts[idx];
         k.ex    = ex[idx];
         k.bid   = bid[idx];
         k.bs    = bs[idx];
         k.be    = be[idx];
         k.ask   = ask[idx];
         k.os    = os[idx];
         k.oe    = oe[idx];
         return(k);
     }
 }
Пример #31
0
        void handle(MessageTypes type, string msg)
        {
            long result = 0;

            switch (type)
            {
            case MessageTypes.TICKNOTIFY:
                Tick t;
                try
                {
                    _lastheartbeat = DateTime.Now.Ticks;
                    t = TickImpl.Deserialize(msg);
                }
                catch (Exception ex)
                {
                    _tickerrors++;
                    debug("Error processing tick: " + msg);
                    debug("TickErrors: " + _tickerrors);
                    debug("Error: " + ex.Message + ex.StackTrace);
                    break;
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;

            case MessageTypes.ORDERCANCELRESPONSE:
            {
                long id = 0;
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotOrderCancel != null)
                {
                    if (long.TryParse(msg, out id))
                    {
                        gotOrderCancel(id);
                    }
                    else if (SendDebugEvent != null)
                    {
                        SendDebugEvent("Count not parse order cancel: " + msg);
                    }
                }
            }
            break;

            case MessageTypes.EXECUTENOTIFY:
                _lastheartbeat = DateTime.Now.Ticks;
                // date,time,symbol,side,size,price,comment
                Trade tr = TradeImpl.Deserialize(msg);
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                _lastheartbeat = DateTime.Now.Ticks;
                Order o = OrderImpl.Deserialize(msg);
                if (gotOrder != null)
                {
                    gotOrder(o);
                }
                break;

            case MessageTypes.HEARTBEATRESPONSE:
            {
                _lastheartbeat = DateTime.Now.Ticks;
                v("got heartbeat response at: " + _lastheartbeat);
                _recvheartbeat = !_recvheartbeat;
            }
            break;

            case MessageTypes.POSITIONRESPONSE:
                try
                {
                    _lastheartbeat = DateTime.Now.Ticks;
                    Position pos = PositionImpl.Deserialize(msg);
                    if (gotPosition != null)
                    {
                        gotPosition(pos);
                    }
                }
                catch (Exception ex)
                {
                    if (SendDebugEvent != null)
                    {
                        SendDebugEvent(msg + " " + ex.Message + ex.StackTrace);
                    }
                }
                break;

            case MessageTypes.ACCOUNTRESPONSE:
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case MessageTypes.FEATURERESPONSE:
                _lastheartbeat = DateTime.Now.Ticks;
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                _rfl.Clear();
                foreach (string s in p)
                {
                    try
                    {
                        MessageTypes mt = (MessageTypes)Convert.ToInt32(s);
                        f.Add(mt);
                        _rfl.Add(mt);
                    }
                    catch (Exception) { }
                }
                if (gotFeatures != null)
                {
                    gotFeatures(f.ToArray());
                }
                break;

            case MessageTypes.SERVERDOWN:
                if (gotServerDown != null)
                {
                    gotServerDown(msg);
                }
                break;

            case MessageTypes.SERVERUP:
                if (gotServerUp != null)
                {
                    gotServerUp(msg);
                }
                break;

            default:
                _lastheartbeat = DateTime.Now.Ticks;
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(type, 0, 0, 0, string.Empty, ref msg);
                }
                break;
            }
            result = 0;
        }
Пример #32
0
 public static Tick Deserialize(string msg)
 {
     string [] r = msg.Split(',');
     Tick t = new TickImpl();
     decimal d = 0;
     int i = 0;
     t.symbol = r[(int)TickField.symbol];
     if (decimal.TryParse(r[(int)TickField.trade], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
         t.trade = d;
     if (decimal.TryParse(r[(int)TickField.bid],  System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture,out d))
         t.bid = d;
     if (decimal.TryParse(r[(int)TickField.ask], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
         t.ask = d;
     if (int.TryParse(r[(int)TickField.tsize], out i))
         t.size = i;
     if (int.TryParse(r[(int)TickField.asksize], out i))
         t.os= i;
     if (int.TryParse(r[(int)TickField.bidsize], out i))
         t.bs = i;
     if (int.TryParse(r[(int)TickField.time], out i))
         t.time = i;
     if (int.TryParse(r[(int)TickField.date], out i))
         t.date = i;
     if (int.TryParse(r[(int)TickField.tdepth], out i))
         t.depth = i;
     t.ex = r[(int)TickField.tex];
     t.be = r[(int)TickField.bidex];
     t.oe = r[(int)TickField.askex];
     t.datetime = t.date * 1000000 + t.time;
     return t;
 }
Пример #33
0
 public static TickImpl NewQuote(string sym, int date, int time, int sec, decimal bid, decimal ask, int bidsize, int asksize, string be, string oe, int depth)
 {
     TickImpl q = new TickImpl(sym);
     q.date = date;
     q.time = time;
     q.bid = bid;
     q.ask = ask;
     q.be = be.Trim();
     q.oe = oe.Trim();
     q.AskSize = asksize;
     q.BidSize = bidsize;
     q.trade = 0;
     q.size = 0;
     q.depth = depth;
     return q;
 }
Пример #34
0
        /// <summary>
        /// Loads a tick straight from an EPF file in the form of a StreamReader
        /// </summary>
        /// <param name="symbol">The symbol.</param>
        /// <param name="sr">The sr.</param>
        /// <returns></returns>
        public static Tick FromStream(string symbol, StreamReader sr)
        {
            TickImpl t    = new TickImpl();
            string   line = "";

            try
            {
                line = sr.ReadLine();
            }
            catch (Exception) { return(t); }
            string[] r = line.Split(',');
            if (r.Length < 6)
            {
                return(t);
            }
            decimal td = 0;
            int     ti = 0;

            if (r[(int)Q.TYPE] == TRADE)
            {
                if (decimal.TryParse(r[(int)T.PRICE], out td))
                {
                    t.trade = td;
                }
                if (int.TryParse(r[(int)T.SIZE], out ti))
                {
                    t.size = ti;
                }
                t.ex = r[(int)T.EXCH];
            }
            else
            {
                if (r.Length < 9)
                {
                    return(t);
                }
                if (decimal.TryParse(r[(int)Q.BID], out td))
                {
                    t.bid = td;
                }
                if (decimal.TryParse(r[(int)Q.ASK], out td))
                {
                    t.ask = td;
                }
                if (int.TryParse(r[(int)Q.BIDSIZE], out ti))
                {
                    t.bs = ti;
                }
                if (int.TryParse(r[(int)Q.ASKSIZE], out ti))
                {
                    t.os = ti;
                }
                t.be = r[(int)Q.BIDEX];
                t.oe = r[(int)Q.ASKEX];
            }
            t.symbol = symbol;
            if (int.TryParse(r[(int)Q.TIME], out ti))
            {
                t.time = ti;
            }
            if (int.TryParse(r[(int)Q.DATE], out ti))
            {
                t.date = ti + 20000000;
            }
            t.datetime = ((long)t.date * 1000000) + (long)t.time;
            return(t);
        }
Пример #35
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            long             result = 0;
            TradeLinkMessage tlm    = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)         // if it's not a WM_COPYDATA message
            {
                base.WndProc(ref m); // let form process it
                return;              // we're done
            }

            string msg = tlm.body;

            switch (tlm.type)
            {
            case MessageTypes.TICKNOTIFY:
                Tick t;
                try
                {
                    t = TickImpl.Deserialize(msg);
                }
                catch (Exception ex)
                {
                    _tickerrors++;
                    debug("Error processing tick: " + msg);
                    debug("TickErrors: " + _tickerrors);
                    debug("Error: " + ex.Message + ex.StackTrace);
                    break;
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;

            case MessageTypes.ORDERCANCELRESPONSE:
            {
                long id = 0;
                if (gotOrderCancel != null)
                {
                    if (long.TryParse(msg, out id))
                    {
                        gotOrderCancel(id);
                    }
                    else if (SendDebugEvent != null)
                    {
                        SendDebugEvent("Count not parse order cancel: " + msg);
                    }
                }
            }
            break;

            case MessageTypes.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                try
                {
                    Trade tr = TradeImpl.Deserialize(msg);
                    if (gotFill != null)
                    {
                        gotFill(tr);
                    }
                }
                catch (Exception ex)
                {
                    debug("error deserializing fill: " + msg);
                    debug("error: " + ex.Message + ex.StackTrace);
                    debug("broker: " + BrokerName);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                try
                {
                    Order o = OrderImpl.Deserialize(msg);
                    if (gotOrder != null)
                    {
                        gotOrder(o);
                    }
                }
                catch (Exception ex)
                {
                    debug("error deserializing order: " + msg);
                    debug("error: " + ex.Message + ex.StackTrace);
                    debug("broker: " + BrokerName);
                }
                break;

            case MessageTypes.POSITIONRESPONSE:
                try
                {
                    Position pos = PositionImpl.Deserialize(msg);
                    if (gotPosition != null)
                    {
                        gotPosition(pos);
                    }
                }
                catch (Exception ex)
                {
                    if (SendDebugEvent != null)
                    {
                        SendDebugEvent(msg + " " + ex.Message + ex.StackTrace);
                    }
                }
                break;

            case MessageTypes.ACCOUNTRESPONSE:
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case MessageTypes.FEATURERESPONSE:
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((MessageTypes)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotFeatures != null)
                {
                    gotFeatures(f.ToArray());
                }
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(tlm.type, 0, 0, 0, string.Empty, ref tlm.body);
                }
                break;

            case MessageTypes.SERVERDOWN:
                if (gotServerDown != null)
                {
                    gotServerDown(msg);
                }
                break;

            case MessageTypes.SERVERUP:
                if (gotServerUp != null)
                {
                    gotServerUp(msg);
                }
                break;

            default:
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(tlm.type, 0, 0, 0, string.Empty, ref tlm.body);
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Пример #36
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            long             result = 0;
            TradeLinkMessage tlm    = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)         // if it's not a WM_COPYDATA message
            {
                base.WndProc(ref m); // let form process it
                return;              // we're done
            }

            string msg = tlm.body;

            string[] r = msg.Split(',');
            switch (tlm.type)
            {
            case MessageTypes.ORDERCANCELRESPONSE:
                if (gotOrderCancel != null)
                {
                    gotOrderCancel(Convert.ToUInt32(msg));
                }
                break;

            case MessageTypes.TICKNOTIFY:
                Tick t = TickImpl.Deserialize(msg);
                if (t.isTrade)
                {
                    try
                    {
                        if (t.trade > chighs[t.symbol])
                        {
                            chighs[t.symbol] = t.trade;
                        }
                        if (t.trade < clows[t.symbol])
                        {
                            clows[t.symbol] = t.trade;
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        chighs.Add(t.symbol, 0);
                        clows.Add(t.symbol, decimal.MaxValue);
                    }
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                Trade tr = TradeImpl.Deserialize(msg);
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                Order o = OrderImpl.Deserialize(msg);
                if (gotOrder != null)
                {
                    gotOrder(o);
                }
                break;

            case MessageTypes.POSITIONRESPONSE:
                Position pos = PositionImpl.Deserialize(msg);
                if (gotPosition != null)
                {
                    gotPosition(pos);
                }
                break;

            case MessageTypes.ACCOUNTRESPONSE:
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case MessageTypes.FEATURERESPONSE:
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((MessageTypes)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotSupportedFeatures != null)
                {
                    gotSupportedFeatures(f.ToArray());
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Пример #37
0
        /// <summary>
        /// this constructor creates a new tick by combining two ticks
        /// this is to handle tick updates that only provide bid/ask changes.
        /// </summary>
        /// <param name="a">old tick</param>
        /// <param name="b">new tick or update</param>
        public static Tick Copy(TickImpl a, TickImpl b)
        {
            TickImpl k = new TickImpl();
            if (b.symbol != a.symbol) return k; // don't combine different symbols
            if (b.time < a.time) return k; // don't process old updates
            k.time = b.time;
            k.date = b.date;
            k.datetime = b.datetime;
            k.symbol = b.symbol;
            k.depth = b.depth;

            if (b.isTrade)
            {
                k.trade = b.trade;
                k.size = b.size;
                k.ex = b.ex;
                //
                k.bid = a.bid;
                k.ask = a.ask;
                k.os = a.os;
                k.bs = a.bs;
                k.be = a.be;
                k.oe = a.oe;
            }
            else if (b.hasAsk && b.hasBid)
            {
                k.bid = b.bid;
                k.ask = b.ask;
                k.bs = b.bs;
                k.os = b.os;
                k.be = b.be;
                k.oe = b.oe;
                //
                k.trade = a.trade;
                k.size = a.size;
                k.ex = a.ex;
            }
            else if (b.hasAsk)
            {
                k.ask = b.ask;
                k.os = b.os;
                k.oe = b.oe;
                //
                k.bid = a.bid;
                k.bs = a.bs;
                k.be = a.be;
                k.trade = a.trade;
                k.size = a.size;
                k.ex = a.ex;
            }
            else if (b.hasBid)
            {
                k.bid = b.bid;
                k.bs = b.bs;
                k.be = b.be;
                //
                k.ask = a.ask;
                k.os = a.os;
                k.oe = a.oe;
                k.trade = a.trade;
                k.size = a.size;
                k.ex = a.ex;
            }
            return k;
        }
Пример #38
0
 void MBTQUOTELib.IMbtQuotesNotify.OnTSData(ref TSRECORD pRec)
 {
     TickImpl k = new TickImpl();
     k.symbol = pRec.bstrSymbol;
     enumTickType tt = (enumTickType)pRec.lType;
     switch (tt)
     {
         case enumTickType.ttAskTick:
             k.ask = (decimal)pRec.dPrice;
             k.oe = pRec.bstrExchange;
             k.os = pRec.lSize;
             break;
         case enumTickType.ttBidTick:
             k.bid = (decimal)pRec.dPrice;
             k.be = pRec.bstrExchange;
             k.bs= pRec.lSize;
             break;
         case enumTickType.ttTradeTick:
             k.trade = (decimal)pRec.dPrice;
             k.ex = pRec.bstrExchange;
             k.size= pRec.lSize;
             break;
     }
     tl.newTick(k);
 }
Пример #39
0
 public static Tick Deserialize(string msg)
 {
     string [] r = msg.Split(',');
     Tick t = new TickImpl();
     t.Sec = SecurityImpl.Parse(r[(int)TickField.symbol]);
     t.symbol = t.Sec.Symbol;
     t.trade = Convert.ToDecimal(r[(int)TickField.trade]);
     t.size = Convert.ToInt32(r[(int)TickField.tsize]);
     t.bid = Convert.ToDecimal(r[(int)TickField.bid]);
     t.ask = Convert.ToDecimal(r[(int)TickField.ask]);
     t.os = Convert.ToInt32(r[(int)TickField.asksize]);
     t.bs = Convert.ToInt32(r[(int)TickField.bidsize]);
     t.ex = r[(int)TickField.tex];
     t.be = r[(int)TickField.bidex];
     t.oe = r[(int)TickField.askex];
     t.time = Convert.ToInt32(r[(int)TickField.time]);
     t.date = Convert.ToInt32(r[(int)TickField.date]);
     t.datetime = t.date * 1000000 + t.time;
     t.depth = Convert.ToInt32(r[(int)TickField.tdepth]);
     return t;
 }
Пример #40
0
 Tick OrderToTick(Order o)
 {
     Tick t = new TickImpl(o.symbol);
     if (!o.isLimit) return t;
     t.time = o.time;
     t.date = o.date;
     if (o.side)
     {
         t.bid = o.price;
         t.BidSize = o.UnsignedSize;
         t.be = o.Exchange;
     }
     else
     {
         t.ask = o.price;
         t.AskSize = o.UnsignedSize;
         t.oe = o.Exchange;
     }
     return t;
 }
Пример #41
0
 public static TickImpl NewTrade(string sym, int date, int time, decimal trade, int size, string ex)
 {
     TickImpl t = new TickImpl(sym);
     t.date = date;
     t.time = time;
     t.trade = trade;
     t.size = size;
     t.ex = ex.Trim();
     t.bid = 0;
     return t;
 }
Пример #42
0
        bool convert(Converter con, string filename,int tradesize,string sym)
        {
            int bads = 0;
            int thistotal = _ticksprocessed;
            bool g = true;
            // get output filename
            string convertname = string.Empty;
            // setup writing to output
            TikWriter outfile = null;
            // setup input file
            StreamReader infile = null;
            int _date = 0;
            int cqgdecimalplaces = 2;

            try
            {
                // open input file
                switch (con)
                {
                    case Converter.TradeStation:
                        infile = new StreamReader(filename);
                        // read in and ignore header of input file
                        infile.ReadLine();
                        break;
                    case Converter.eSignal_EPF:
                        infile = new StreamReader(filename);
                        // ignore header
                        SecurityImpl esec = eSigTick.InitEpf(infile);
                        _sym = esec.Symbol;
                        break;
                    case Converter.CQG:
                        infile = new StreamReader(filename);
                        cqgdecimalplaces = (int) this._cqgdecimalplacesinput.Value;
                        // no header
                        break;
                    case Converter.TradingPhysicsTnS:
                    case Converter.TradingPhysicsTV:
                        string file = System.IO.Path.GetFileName(filename);
                        string[] date_sym = file.Split('_');
                        string[] sym_ext = date_sym[1].Split('.');
                        string datestr = date_sym[0];
                        int.TryParse(datestr, out _date);
                        _sym = sym_ext[0];
                        infile = new StreamReader(filename);
                        infile.ReadLine();//discard header line
                        break;
                    case Converter.QCollector_eSignal:
                        infile = new StreamReader(filename);
                        // no header in file
                        break;
                    case Converter.MultiCharts:
                        // The symbol for data being imported is obtained from the filename
                        // Selected files for import must be named SYMBOL.ext - eg AAPL.txt, GOOG.txt
                        _sym = System.IO.Path.GetFileNameWithoutExtension(filename);
                        infile = new StreamReader(filename);
                        infile.ReadLine(); // ignore first line header of input file
                        break;
                 }

            }
            catch (Exception ex) { debug("error reading input header:" + ex.Message); g = false; }
            // setup previous tick and current tick
            Tick pk = new TickImpl();
            Tick k = null;
            do
            {
                try
                {
                    // get next tick from the file

                    switch (con)
                    {
                        case Converter.CQG:
                            k = CQG.parseline(infile.ReadLine(), tradesize, cqgdecimalplaces );
                            break;
                        case Converter.eSignal_EPF:
                            k = eSigTick.FromStream(_sym, infile);
                            break;
                        case Converter.TradeStation:
                            k = TradeStation.parseline(infile.ReadLine(), sym, tradesize);
                            break;
                        case Converter.TradingPhysicsTnS:
                            k = TradingPhysicsTnS.parseline(infile.ReadLine(), _sym, _date);
                            break;
                        case Converter.TradingPhysicsTV:
                            k = TradingPhysicsTV.parseline(infile.ReadLine(), _sym, _date);
                            break;
                        case Converter.QCollector_eSignal:
                            k = QCollector.parseline(infile.ReadLine(), sym);
                            break;
                        case Converter.MultiCharts:
                            k = MultiCharts.parseline(infile.ReadLine(), _sym);
                            break;
                    }
                }
                catch (Exception ex) { bads++;  continue; }
                if (k == null)
                {
                    debug("Invalid converter: " + con.ToString());
                    return false;
                }
                // bad tick
                if (k.date == 0) { bads++; continue; }
                // if dates don't match, we need to write new output file
                if (k.date != pk.date)
                {
                    try
                    {
                    // if the outfile was open previously, close it
                    if (outfile != null)
                        outfile.Close();
                        // get path from input
                        string path = Path.GetDirectoryName(filename) + "\\";
                        // setup new file
                        outfile = new TikWriter(path,k.symbol, k.date);
                        // report progress
                        progress((double)_ticksprocessed / _approxtotal);
                    }
                    catch (Exception ex) { debug(ex.Message); g = false; }
                }
                try
                {
                    // write the tick
                    outfile.newTick(k);
                    // save this tick as previous tick
                    pk = k;
                    // count the tick as processed
                    _ticksprocessed++;
                }
                catch (Exception ex) { debug("error writing output tick: " + ex.Message); g = false; }

            }
            // keep going until input file is exhausted
            while (!infile.EndOfStream);
            // close output file
            if (outfile == null)
            {
                debug("Tick file was never opened, likely that input file in wrong format.");

            }
            else
            {
                debug("Saved: " + outfile.Filepath);
                outfile.Close();
            }
            // close input file
            infile.Close();
            // get percentage of good ticks
            double goodratio = (_ticksprocessed - thistotal - bads) / (_ticksprocessed - (double)thistotal);
            if (goodratio < GOODRATIO)
            {
                debug("Less than " + GOODRATIO.ToString("P0") + " good ticks");
                g = false;
            }
            // return status
            return g;
        }
Пример #43
0
        /*
        private void ExecuteNotifyHandler(object sender, OrderArgs e)
        {


            itemOrder iorder = e.ItemOrder;

           

            
            Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "", iorder.mc_date, iorder.mc_date, iorder.morderid);
            Trade trade = new TradeImpl();
            trade.symbol = iorder.msecsym;
            trade.side = iorder.IsBuyOrder();
            trade.xprice = Convert.ToDecimal(iorder.mprice);
            trade.xsize = iorder.mqty;
            DateTime mdate = ComFucs.GetDate(iorder.mm_date);

            trade.xdate = mdate.Day+ mdate.Month*100+mdate.Year*10000;
            trade.xtime = mdate.Second + mdate.Minute*100+ mdate.Hour*10000 ;
            tl.newFill(trade);
        }

       

        private void OrderHandler(object sender, OrderArgs e)
        {
            

                itemOrder iorder = e.ItemOrder;
                // if (!ls.Contains(iorder.morigtkn)) return;
                DateTime mdate = ComFucs.GetDate(iorder.mm_date);
                Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "",
                            mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000, mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000, iorder.morderid);

                tl.newOrder(o);
            


        }


        private void OrderModifyHandler(object sender, OrderArgs e)
        {
            
                if ((e.ItemOrder.mstatus | 0x0004) != 0)
                {
                  //  tl.newCancel(e.ItemOrder.morderid);
                }
                if ((e.ItemOrder.mstatus | 0x0002) != 0)
                {
                    itemOrder iorder = e.ItemOrder;
                    Order o = new OrderImpl(iorder.msecsym, iorder.IsBuyOrder(), iorder.mqty, Convert.ToDecimal(iorder.mprice), Convert.ToDecimal(iorder.mstopprice), "", iorder.mc_date, iorder.mc_date, iorder.morderid);
                    Trade trade = new TradeImpl();
                    trade.symbol = iorder.msecsym;
                    trade.side = iorder.IsBuyOrder();
                    trade.xprice = Convert.ToDecimal(iorder.mprice);
                    trade.xsize = iorder.mqty;
                    DateTime mdate = ComFucs.GetDate(iorder.mm_date);
                    trade.xdate = mdate.Day + mdate.Month * 100 + mdate.Year * 10000;
                    trade.xtime = mdate.Second + mdate.Minute * 100 + mdate.Hour * 10000;
                    tl.newFill(trade);
                }
            


        }
         * */


        private void Lv1Handler(object sender, Lv1Args e)
        {
           
            DateTime DT = new DateTime(1970, 1, 1);
            
            Tick t = new TickImpl();
            t.date = Util.ToTLDate(DateTime.Now);
            t.time = Util.DT2FT(DateTime.Now);
            t.symbol = e.TheIssuIfo.secsym;
            t.bid = Convert.ToDecimal(e.TheIssuIfo.l1_BidPrice);
            t.ask = Convert.ToDecimal(e.TheIssuIfo.l1_AskPrice);
            t.ex = e.TheIssuIfo.PrimExch.ToString();
            t.trade = Convert.ToDecimal(e.TheIssuIfo.l1_lastPrice);
            t.size = e.TheIssuIfo.l1_volume;
            t.bs = e.TheIssuIfo.l1_BidSize;
            t.os = e.TheIssuIfo.l1_AskSize;
            t.ex = e.TheIssuIfo.PrimExch.ToString();
           
            tl.newTick(t);

        }
Пример #44
0
        /// <summary>
        /// this constructor creates a new tick by combining two ticks
        /// this is to handle tick updates that only provide bid/ask changes.
        /// </summary>
        /// <param name="a">old tick</param>
        /// <param name="b">new tick or update</param>
        public static Tick Copy(TickImpl a, TickImpl b)
        {
            TickImpl k = new TickImpl();

            if (b.symbol != a.symbol)
            {
                return(k);                      // don't combine different symbols
            }
            if (b.time < a.time)
            {
                return(k);                 // don't process old updates
            }
            k.time     = b.time;
            k.date     = b.date;
            k.datetime = b.datetime;
            k.symbol   = b.symbol;
            k.depth    = b.depth;
            k.symidx   = b.symidx;
            if (b.isTrade)
            {
                k.trade = b.trade;
                k.size  = b.size;
                k.ex    = b.ex;
                //
                k.bid = a.bid;
                k.ask = a.ask;
                k.os  = a.os;
                k.bs  = a.bs;
                k.be  = a.be;
                k.oe  = a.oe;
            }
            if (b.hasAsk && b.hasBid)
            {
                k.bid = b.bid;
                k.ask = b.ask;
                k.bs  = b.bs;
                k.os  = b.os;
                k.be  = b.be;
                k.oe  = b.oe;
                //
                k.trade = a.trade;
                k.size  = a.size;
                k.ex    = a.ex;
            }
            else if (b.hasAsk)
            {
                k.ask = b.ask;
                k.os  = b.os;
                k.oe  = b.oe;
                //
                k.bid   = a.bid;
                k.bs    = a.bs;
                k.be    = a.be;
                k.trade = a.trade;
                k.size  = a.size;
                k.ex    = a.ex;
            }
            else if (b.hasBid)
            {
                k.bid = b.bid;
                k.bs  = b.bs;
                k.be  = b.be;
                //
                k.ask   = a.ask;
                k.os    = a.os;
                k.oe    = a.oe;
                k.trade = a.trade;
                k.size  = a.size;
                k.ex    = a.ex;
            }
            return(k);
        }
Пример #45
0
        void InsideMktEvent_GBEvent(object pISrc, string bstrSymbol, string bstrHint, object pIEventData)
        {
            GBInsideMkt insideMkt = new GBInsideMktClass();
            insideMkt = (GBInsideMkt)pIEventData;

          

            Tick k = new TickImpl(bstrSymbol);
            k.bid = (decimal)insideMkt.BidPrice;
            k.ask = (decimal)insideMkt.AskPrice;
            k.bs = insideMkt.BidVolume / 100;
            k.os = insideMkt.AskVolume / 100;
            k.date = Util.ToTLDate(DateTime.Now);
            k.time = Util.ToTLTime(DateTime.Now); 
           
            tl.newTick(k);
            

        }
Пример #46
0
        /// <summary>
        /// write a tick to file
        /// </summary>
        /// <param name="k"></param>
        public void newTick(TickImpl k)
        {
            // make sure we have a header
            if (!_hasheader)
            {
                init(k.symbol, k.date, _path);
            }
            // get types
            bool t  = k.isTrade;
            bool fq = k.isFullQuote;
            bool b  = k.hasBid;
            bool a  = k.hasAsk;
            bool i  = k.isIndex;

            // next we write tick type and the data
            if (!fq && b) // bid only
            {
                Write(TikConst.TickBid);
                Write(k.date);
                Write(k.time);
                Write(k._bid);
                Write(k.bs);
                Write(k.be);
                Write(k.depth);
            }
            else if (!fq && a) // ask only
            {
                Write(TikConst.TickAsk);
                Write(k.date);
                Write(k.time);
                Write(k._ask);
                Write(k.os);
                Write(k.oe);
                Write(k.depth);
            }
            else if ((t && !fq) || i) // trade or index
            {
                Write(TikConst.TickTrade);
                Write(k.date);
                Write(k.time);
                Write(k._trade);
                Write(k.size);
                Write(k.ex);
            }
            else if (t && fq) // full quote
            {
                Write(TikConst.TickFull);
                Write(k.date);
                Write(k.time);
                Write(k._trade);
                Write(k.size);
                Write(k.ex);
                Write(k._bid);
                Write(k.bs);
                Write(k.be);
                Write(k._ask);
                Write(k.os);
                Write(k.oe);
                Write(k.depth);
            }
            else if (!t && fq) // quote only
            {
                Write(TikConst.TickQuote);
                Write(k.date);
                Write(k.time);
                Write(k._bid);
                Write(k.bs);
                Write(k.be);
                Write(k._ask);
                Write(k.os);
                Write(k.oe);
                Write(k.depth);
            }
            // end tick
            Write(TikConst.EndTick);
            // write to disk
            Flush();
            // count it
            Count++;
        }