예제 #1
0
        public void InsertBar_MultipleInsert()
        {
            string  sym = "FTI";
            int     d   = 20070926;
            BarList org = new BarListImpl(BarInterval.FiveMin, sym);

            Assert.IsTrue(org.isValid, "your original barlist is not valid 1");
            int orgcount = org.Count;

            Assert.AreEqual(0, orgcount);

            int h = 7;
            int m = 55;

            for (int i = 0; i < 10; i++)
            {
                int t      = h * 10000 + m * 100;
                Bar insert = new BarImpl(30, 30, 30, 30, 10000, d, t, sym, (int)BarInterval.FiveMin);
                Assert.IsTrue(insert.isValid, "your bar to insert is not valid 1");
                int insertpos = BarListImpl.GetBarIndexPreceeding(org, insert.Bardate, insert.Bartime);
                Assert.AreEqual(i - 1, insertpos, "insertion position");
                BarList inserted = BarListImpl.InsertBar(org, insert, insertpos);
                Assert.AreEqual(i + 1, inserted.Count, "element count after insertion");
                m += 5;
                if (m >= 60)
                {
                    h += m / 60;
                    m  = m % 60;
                }
                org = inserted;
            }
            Assert.AreEqual(orgcount + 10, org.Count, "total element count after insertion");
        }
예제 #2
0
        public void ReadAndOverwrite()
        {
            const string tf = @"SPX20070926.TIK";

            // read a barlist
            var bl = BarListImpl.FromTIK(tf);

            // get new bars
            var newbl = BarListImpl.DayFromGoogle("FTI");

            // append
            for (int i = 0; i < newbl.Count; i++)
            {
                foreach (var k in BarImpl.ToTick(newbl[i]))
                {
                    bl.newTick(k);
                }
            }



            // write the barlist
            Assert
            .IsTrue(BarListImpl.ChartSave(bl, Environment.CurrentDirectory, 20070926), "error saving new data");
        }
예제 #3
0
        public void InsertBar_HistoricalPlusNewBarsPresent()
        {
            string sym = "FTI";
            int    d   = 20070926;
            // historical bar filename
            string filename = sym + d + TikConst.DOT_EXT;
            // case 3 - middle insertion aka (some historical and some new bars already present)
            var org = BarListImpl.FromTIK(filename);

            Assert.IsTrue(org.isValid, "your original bar is not valid 3");
            var orgcount = org.Count;

            Assert.Greater(orgcount, 0);
            // create bar to insert
            var insert = new BarImpl(30, 30, 30, 30, 10000, d, 75500, sym, (int)BarInterval.FiveMin);

            Assert.IsTrue(insert.isValid, "your bar to insert is not valid 3");
            int insertpos = BarListImpl.GetBarIndexPreceeding(org, insert.Bardate);
            var inserted  = BarListImpl.InsertBar(org, insert, insertpos);

            Assert.AreEqual(inserted.Count, orgcount + 1);
            var actualinsert = inserted[insertpos];

            Assert.IsTrue(actualinsert.isValid);
            Assert.AreEqual(insert.Close, actualinsert.Close);
            Assert.AreEqual(insert.Open, actualinsert.Open);
            Assert.AreEqual(insert.High, actualinsert.High);
            Assert.AreEqual(insert.Low, actualinsert.Low);
            Assert.AreEqual(insert.Symbol, actualinsert.Symbol);
        }
예제 #4
0
        public void InsertBar_HistoricalBarsPresent()
        {
            string sym = "FTI";
            int    d   = 20070926;
            // historical bar filename
            string filename = sym + d + TikConst.DOT_EXT;

            // unit test case 2 existing bars with front insertion (aka historical bar insert)

            var org = BarListImpl.FromTIK(filename);

            Assert.IsTrue(org.isValid, "your original bar is not valid 2");
            var orgcount = org.Count;

            Assert.Greater(orgcount, 0);
            // create bar to insert
            var insert = new BarImpl(30, 30, 30, 30, 10000, d, 75500, sym, (int)BarInterval.FiveMin);

            Assert.IsTrue(insert.isValid, "your bar to insert is not valid 2");
            var inserted = BarListImpl.InsertBar(org, insert, 0);

            Assert.AreEqual(inserted.Count, orgcount + 1);
            var actualinsert = inserted[0];

            Assert.IsTrue(actualinsert.isValid);
            Assert.AreEqual(insert.Close, actualinsert.Close);
            Assert.AreEqual(insert.Open, actualinsert.Open);
            Assert.AreEqual(insert.High, actualinsert.High);
            Assert.AreEqual(insert.Low, actualinsert.Low);
            Assert.AreEqual(insert.Symbol, actualinsert.Symbol);
        }
예제 #5
0
        public void SpoolDailyBars()
        {
            BarList bl = dailyBarTracker["SPY", (int)BarInterval.Day];

            for (int x = 0; x < SPY_Daily.Length; x++)
            {
                Bar b = BarImpl.Deserialize(SPY_Daily[x]);

                bl.newPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);
            }

            Console.WriteLine("Count: " + bl.Count);
            Assert.AreEqual(SPY_Daily.Length, bl.Count);
            for (int x = 0; x < SPY_Daily.Length; x++)
            {
                Bar t = BarImpl.Deserialize(SPY_Daily[x]);
                Assert.AreEqual(bl[x].Bardate, t.Bardate);
                Assert.AreEqual(bl[x].Close, t.Close);
            }

            DisplayTrackerContent(dailyBarTracker["SPY"]);
        }
예제 #6
0
        public void IntraMixedTickAndBars()
        {
            BarList bl = intraBarTracker["SPY", (int)BarInterval.FiveMin];

            for (int x = 0; x < SPY_Intra.Length; x++)
            {
                Bar b = BarImpl.Deserialize(SPY_Intra[x]);

                bl.newPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.newPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);

                // interleave ticks with the bars to simulate datafeed asynchronous-ness
                int  baseTime = 144500;
                Tick k        = new TickImpl("SPY");
                k.ask   = 101;
                k.bid   = 100;
                k.date  = 20110208;
                k.trade = 100.5m;
                k.size  = 5000;
                k.time  = baseTime + x;
                intraBarTracker.newTick(k);
            }

            Console.WriteLine("Count: " + bl.Count);
            DisplayTrackerContent(intraBarTracker["SPY"]);
            Assert.AreEqual(SPY_Intra.Length, bl.Count);
            for (int x = 0; x < SPY_Intra.Length - 1; x++)
            {
                Bar t = BarImpl.Deserialize(SPY_Intra[x]);
                Assert.AreEqual(bl[x].Bardate, t.Bardate);
                Assert.AreEqual(bl[x].Close, t.Close);
            }
        }
예제 #7
0
        public void InsertBar_NoexistingBars()
        {
            string sym = "FTI";
            int    d   = 20070926;

            // historical bar filename
            string filename = sym + d + TikConst.DotExt;

            // test for the parameter's prescence
            Assert.NotEmpty(filename);

            // unit test case 1 no existing bars aka (empty or brand-new insertion)
            BarList org = new BarListImpl(BarInterval.FiveMin, sym);

            Assert.True(org.IsValid, "your original barlist is not valid 1");
            int orgcount = org.Count;

            Assert.Equal(0, orgcount);

            // make up a bar here  (eg at 755 in FTI there are no ticks so this should add a new bar in most scenarios)
            Bar insert = new BarImpl(30, 30, 30, 30, 10000, d, 75500000, sym, (int)BarInterval.FiveMin);

            Assert.True(insert.IsValid, "your bar to insert is not valid 1");
            BarList inserted = BarListImpl.InsertBar(org, insert, org.Count);

            Assert.Equal(inserted.Count, orgcount + 1);
            Bar actualinsert = inserted.RecentBar;

            Assert.True(actualinsert.IsValid);
            Assert.Equal(insert.Close, actualinsert.Close);
            Assert.Equal(insert.Open, actualinsert.Open);
            Assert.Equal(insert.High, actualinsert.High);
            Assert.Equal(insert.Low, actualinsert.Low);
            Assert.Equal(insert.Symbol, actualinsert.Symbol);
        }
예제 #8
0
        public void DailyMixedTickAndBars()
        {
            BarListImpl bl = (BarListImpl)_dailyBarTracker["SPY", (int)BarInterval.Day];

            for (int x = 0; x < _spyDaily.Length; x++)
            {
                BarImpl b = (BarImpl)BarImpl.Deserialize(_spyDaily[x]);
                bl.NewPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);

                // interleave ticks with the bars to simulate datafeed asynchronous-ness
                int      baseTime = 144500;
                TickImpl k        = new TickImpl("SPY");
                k.Ask   = 101;
                k.Bid   = 100;
                k.Date  = 20110208;
                k.Trade = 100.5m;
                k.Size  = 5000;
                k.Time  = baseTime + x;
                _dailyBarTracker.NewTick(k);
            }

            Console.WriteLine("Count: " + bl.Count);
            DisplayTrackerContent(_dailyBarTracker["SPY"]);
            Assert.Equal(_spyDaily.Length, bl.Count);
            for (int x = 0; x < _spyDaily.Length - 1; x++)
            {
                Bar t = BarImpl.Deserialize(_spyDaily[x]);
                Assert.Equal(bl[x].Bardate, t.Bardate);
                Assert.Equal(bl[x].Close, t.Close);
            }
        }
예제 #9
0
        public void TestBarMix()
        {
            // get some test symbols and intervals
            var syms     = new string[] { "IBM", "GOOG", "QQQ" };
            var ints     = new int[] { (int)BarInterval.Day, (int)BarInterval.FiveMin, (int)BarInterval.Hour };
            var barsback = new int[] { 100, 100, 20 };
            // make some random bars
            var bars = new List <Bar>();

            for (int i = 0; i < ints.Length; i++)
            {
                bars.AddRange(TestTradeLink_WM.GetRandomBars(syms, ints[i], barsback[i]));
            }
            // populate the tracker
            foreach (var bar in bars)
            {
                var msg = BarImpl.Serialize(bar);
#if DEBUG
                g.d(bar.Symbol + " sending: " + msg);
#endif
                _mt.GotMessage(MessageTypes.BARRESPONSE, 0, 0, 0, string.Empty, ref msg);
            }
            // verify everything was populated
            var blt = _mt.BLT;
            foreach (var sym in syms)
            {
                for (int i = 0; i < ints.Length; i++)
                {
                    var bint = ints[i];
                    var bb   = barsback[i];
                    var bl   = blt[sym, bint];
                    Assert.GreaterOrEqual(bl.IntervalCount((BarInterval)bint, bint), bb, sym + " missing bars on interval: " + bint);
                }
            }
        }
예제 #10
0
        public void SpoolIntraBars()
        {
            BarListImpl bl = (BarListImpl)_intraBarTracker["SPY", (int)BarInterval.FiveMin];

            for (int x = 0; x < _spyIntra.Length; x++)
            {
                Bar b = BarImpl.Deserialize(_spyIntra[x]);

                bl.NewPoint(b.Symbol, b.Open, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.High, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Low, b.Bartime, b.Bardate, 0);
                bl.NewPoint(b.Symbol, b.Close, b.Bartime, b.Bardate, (int)b.Volume);
            }

            Console.WriteLine("Count: " + bl.Count);

            Assert.Equal(_spyIntra.Length, bl.Count);
            for (int x = 0; x < _spyIntra.Length; x++)
            {
                Bar t = BarImpl.Deserialize(_spyIntra[x]);
                Assert.Equal(bl[x].Bardate, t.Bardate);
                Assert.Equal(bl[x].Close, t.Close);
            }

            DisplayTrackerContent(_intraBarTracker["SPY"]);
        }
예제 #11
0
        public void BarsBack()
        {
            DateTime present = DateTime.Parse("2010/1/3 15:00:00");
            DateTime past    = BarImpl.DateFromBarsBack(5, BarInterval.FiveMin, present);

            Assert.AreEqual(20100103, Util.ToTLDate(past));
            Assert.AreEqual(143500, Util.ToTLTime(past));
        }
예제 #12
0
    public static Bar parseline(string line, string sym)
    {
        string[] values = line.Split(',');

        Bar bar = new BarImpl(sym);

        DateTime date;

        if (DateTime.TryParse(line[DATE], out date))
        {
            bar.Date = date;
        }

        decimal priceOpen;

        if (decimal.TryParse(line[OPEN], out priceOpen))
        {
            bar.Open = priceOpen;
        }

        decimal priceHigh;

        if (decimal.TryParse(line[HIGH], out priceHigh))
        {
            bar.High = priceHigh;
        }

        decimal priceLow;

        if (decimal.TryParse(line[LOW], out priceLow))
        {
            bar.Low = priceLow;
        }

        decimal priceClose;

        if (decimal.TryParse(line[CLOSE], out priceClose))
        {
            bar.Close = priceClose;
        }

        int volume;

        if (decimal.TryParse(line[VOLUME], out volume))
        {
            bar.Volume = volume;
        }

        int openInterest;

        if (decimal.TryParse(line[OPENINTEREST], out volume))
        {
            bar.OpenInterest = openInterest;
        }

        return(bar);
    }
예제 #13
0
파일: TikUtil.cs 프로젝트: w1r2p1/Core-1
        /// <summary>
        /// create ticks from bars on default interval
        /// </summary>
        /// <param name="bl"></param>
        /// <returns></returns>
        public static Tick[] Barlist2Tick(BarList bl)
        {
            List <Tick> k = new List <Tick>(bl.Count * 4);

            foreach (Bar b in bl)
            {
                k.AddRange(BarImpl.ToTick(b));
            }
            return(k.ToArray());
        }
예제 #14
0
 public override void GotTick(Tick k)
 {
     // if we don't have bar data, request historical data
     if (_blt[k.symbol].Count == 0)
     {
         D(k.symbol + " no bars found, requesting...");
         sendmessage(MessageTypes.BARREQUEST, BarImpl.BuildBarRequest(k.symbol, BarInterval.Hour));
     }
     D(k.symbol + " bar count: " + _blt[k.symbol].Count);
     // update whatever data we have with ticks
     _blt.newTick(k);
 }
예제 #15
0
        Bar GetBar(List <string> r)
        {
            if (type != ConvertMapType.Bar)
            {
                return(new BarImpl());
            }

            Bar b = new BarImpl(get(gi(r, O)), get(gi(r, H)), get(gi(r, L)), get(gi(r, C)), getl(gi(r, V)),
                                getd(gi(r, DATE)), gett(gi(r, TIME)), gi(r, SYM), geti(gi(r, BI)));

            return(b);
        }
예제 #16
0
        void c_gotUnknownMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            if (type == MessageTypes.BARRESPONSE)
            {
                bar = BarImpl.Deserialize(response);
                if (bar.isValid)
                {
#if DEBUG
                    g.d("got bar: " + response);
#endif
                    barcount++;
                }
            }
        }
예제 #17
0
        long IQFeedHelper_newUnknownRequest(MessageTypes t, string msg)
        {
            switch (t)
            {
            case MessageTypes.DAYHIGH:
            {
                // get index for request
                int idx = _highs.getindex(msg);
                // ignore if no index
                if (idx == GenericTracker.UNKNOWN)
                {
                    return(0);
                }
                decimal v = _highs[idx];
                // ensure we have a high
                if (v == decimal.MinValue)
                {
                    return(0);
                }
                return(WMUtil.pack(v));
            }

            case MessageTypes.DAYLOW:
            {
                // get index for request
                int idx = _highs.getindex(msg);
                // ignore if no index
                if (idx == GenericTracker.UNKNOWN)
                {
                    return(0);
                }
                decimal v = _highs[idx];
                // ensure we have a high
                if (v == decimal.MaxValue)
                {
                    return(0);
                }
                return(WMUtil.pack(v));
            }

            case MessageTypes.BARREQUEST:
            {
                BarRequest br = BarImpl.ParseBarRequest(msg);
                RequestBars(br);
                return((long)MessageTypes.OK);
            }
            }
            return((long)MessageTypes.FEATURE_NOT_IMPLEMENTED);
        }
예제 #18
0
        public static Bar GetRandomBar(string sym, int intervaltype, int custinterval, int date, int time)
        {
            // send some bars back
            var b = new BarImpl();

            while (!b.isValid)
            {
                var p  = (decimal)r.NextDouble() * 100;
                var d  = (decimal)Math.Round(r.NextDouble(), 2);
                var v  = r.Next(1000, 100000);
                var dt = Util.ToDateTime(date, time);
                b = new BarImpl(p, p + d * 3, p - d * 5, p - d, v, Util.ToTLDate(dt), Util.ToTLTime(dt), sym, intervaltype, custinterval);
            }
            return(b);
        }
예제 #19
0
파일: TestBar.cs 프로젝트: w1r2p1/Core-1
        public void Construction()
        {
            BarImpl b = new BarImpl();

            Assert.True(!b.IsValid);
            Assert.True(!b.IsNew);
            b.NewTick(_ticklist[0]);
            Assert.True(b.IsValid);
            Assert.True(b.IsNew);
            b.NewTick(_ticklist[1]);
            Assert.True(b.IsValid);
            Assert.True(!b.IsNew);
            Assert.True(b.Volume == 200);
            b.NewTick(TickImpl.NewQuote(Sym, D, T, 10m, 11m, 1, 1, X, X));
            Assert.True(b.TradeCount == 2);
        }
예제 #20
0
        public void Construction()
        {
            BarImpl b = new BarImpl();

            Assert.That(!b.isValid);
            Assert.That(!b.isNew);
            b.newTick(ticklist[0]);
            Assert.That(b.isValid);
            Assert.That(b.isNew);
            b.newTick(ticklist[1]);
            Assert.That(b.isValid);
            Assert.That(!b.isNew);
            Assert.That(b.Volume == 200);
            b.newTick(TickImpl.NewQuote(sym, d, t, 10m, 11m, 1, 1, x, x));
            Assert.That(b.TradeCount == 2);
        }
예제 #21
0
        public void SerializeDeseralize()
        {
            Bar    b   = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533, "IBM", (int)BarInterval.FiveMin);
            string msg = BarImpl.Serialize(b);
            Bar    cb  = BarImpl.Deserialize(msg);

            Assert.AreEqual(b.Symbol, cb.Symbol);
            Assert.AreEqual(b.time, cb.time);
            Assert.AreEqual(b.Interval, cb.Interval);
            Assert.AreEqual(b.High, cb.High);
            Assert.AreEqual(b.Low, cb.Low);
            Assert.AreEqual(b.Open, cb.Open);
            Assert.AreEqual(b.Close, cb.Close);
            Assert.AreEqual(b.Volume, cb.Volume);
            Assert.AreEqual(b.Bardate, cb.Bardate);
        }
예제 #22
0
        public void BarTime()
        {
            Bar b = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533, "IBM", (int)BarInterval.FiveMin);

            Assert.AreEqual(93500, b.Bartime);
            Assert.AreEqual(93533, b.time);
            Console.WriteLine(b.Bartime + " " + b.time);

            b = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533, "IBM", (int)BarInterval.Hour);
            Assert.AreEqual(90000, b.Bartime);
            Assert.AreEqual(93533, b.time);
            Console.WriteLine(b.Bartime + " " + b.time);

            b = new BarImpl(1, 1, 1, 1, 1, 20100302, 95504, "IBM", (int)BarInterval.FiveMin);
            Assert.AreEqual(95500, b.Bartime);
            Assert.AreEqual(95504, b.time);
            Console.WriteLine(b.Bartime + " " + b.time);
        }
예제 #23
0
        void processhistory(int lHandle, BarRequest br)
        {
            int numbars = esig.get_GetNumBars(lHandle);

            if (numbars == 0)
            {
                verb("no bars available for reqhandle: " + lHandle);
                return;
            }
            numbars *= -1;
            for (int i = numbars; i <= 0; i++)
            {
                try
                {
                    BarData bd = esig.get_GetBar(lHandle, i);
                    if (VerboseDebugging)
                    {
                        verb(br.Symbol + " " + bd.dtTime.ToString() + " " + bd.dOpen + " " + bd.dHigh + " " + bd.dLow + " " + bd.dClose + " " + bd.dVolume);
                    }
                    Bar    b   = new BarImpl((decimal)bd.dOpen, (decimal)bd.dHigh, (decimal)bd.dLow, (decimal)bd.dClose, (long)bd.dVolume, Util.ToTLDate(bd.dtTime), Util.ToTLTime(bd.dtTime), br.Symbol, br.Interval);
                    string msg = BarImpl.Serialize(b);
                    if (!b.isValid && !AllowSendInvalidBars)
                    {
                        debug("Not sending invalid bar: " + b.ToString() + " raw: " + msg);
                        continue;
                    }
                    tl.TLSend(msg, MessageTypes.BARRESPONSE, br.Client);
                }
                catch (Exception ex)
                {
                    verb("error obtaining bar: " + i + " from: " + lHandle);
                    verb(ex.Message + ex.StackTrace);
                }
            }
            if (ReleaseBarHistoryAfteRequest)
            {
                try
                {
                    esig.ReleaseHistory(lHandle);
                    _barhandle2barrequest.Remove(lHandle);
                }
                catch { }
            }
        }
예제 #24
0
        Tick[] ConvertLine(List <string> line)
        {
            if (type == ConvertMapType.Bar)
            {
                var b = GetBar(line);
                if (ignoreinvalidtick && !b.isValid)
                {
                    return(new Tick[0]);
                }
                return(BarImpl.ToTick(b));
            }
            var k = GetTick(line);

            if (ignoreinvalidtick && !k.isValid)
            {
                return(new Tick[0]);
            }
            return(new Tick[] { k });
        }
예제 #25
0
 public override void GotTick(Tick k)
 {
     // if we don't have bar data, request historical data
     if (_blt[k.symbol].Count == 0)
     {
         if (barRequestedFlag == 0)
         {
             D(k.symbol + " no bars found, requesting...");
             sendmessage(MessageTypes.BARREQUEST, BarImpl.BuildBarRequest(k.symbol, BarInterval.Day, 20120105));
             barRequestedFlag += 1;
         }
         else
         {
             D("Waiting for Broker backfill");
         }
     }
     D(k.symbol + " bar count: " + _blt[k.symbol].Count);
     // update whatever data we have with ticks
     _blt.newTick(k);
 }
예제 #26
0
파일: TestBar.cs 프로젝트: w1r2p1/Core-1
        public void BarTime()
        {
            Bar b = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533000, "IBM", (int)BarInterval.FiveMin);

            Assert.Equal(93500000, b.Bartime);
            Assert.Equal(93533000, b.Time);
            Console.WriteLine(b.Bartime + " " + b.Time);

            b = new BarImpl(1, 1, 1, 1, 1, 20100302, 93533000, "IBM", (int)BarInterval.Hour);
            Assert.Equal(90000000, b.Bartime);
            Assert.Equal(93533000, b.Time);
            Console.WriteLine(b.Bartime + " " + b.Time);

            b = new BarImpl(1, 1, 1, 1, 1, 20100302, 95504000, "IBM", (int)BarInterval.FiveMin);
            Assert.Equal(95500000, b.Bartime);
            Assert.Equal(95504000, b.Time);
            Console.WriteLine(b.Bartime + " " + b.Time);

            //DateTime check
            Assert.Equal(int.Parse(b.BarDateTime.ToString("hhmmssfff")), 95500000);
        }
예제 #27
0
 long s_newUnknownRequest(MessageTypes t, string msg)
 {
     if (t == MessageTypes.BARREQUEST)
     {
         var br = BarRequest.Deserialize(msg);
         var MAXBARPERREQUEST = br.BarsBack;
         if (br.isValid)
         {
             for (int i = 0; i < MAXBARPERREQUEST; i++)
             {
                 var bar = GetRandomBar(br.symbol, br.Interval);
                 s.TLSend(BarImpl.Serialize(bar), MessageTypes.BARRESPONSE, c.Name);
             }
         }
     }
     if (t == MessageTypes.LOOPBACKSERVER)
     {
         return(SPECIAL);
     }
     return(0);
 }
예제 #28
0
        void client_gotUnknownMessage(MessageTypes type, long source, long dest, long msgid, string request, ref string response)
        {
            if (type == MessageTypes.BARRESPONSE)
            {
                lastbarraw = response;
                var b         = BarImpl.Deserialize(response);
                var label     = b.Symbol + b.Interval.ToString() + b.CustomInterval.ToString();
                var symintidx = symintcount.getindex(label);
                if (symintidx < 0)
                {
                    symintidx = symintcount.addindex(label, new List <Bar>());
                    g.d("got new symbol/interval: " + b.Symbol + " " + b.Interval + b.CustomInterval + " bar:" + b.ToString());
                }

                symintcount[symintidx].Add(b);
                if (!recvsyms.Contains(b.Symbol))
                {
                    recvsyms.Add(b.Symbol);
                }
                recvbarcount++;
            }
            else if (type == MessageTypes.BARRESPONSE_FINAL)
            {
                var br = BarRequest.Deserialize(response);
                reccomplete++;
                g.d("completed: " + br.symbol + " " + br.Interval + " " + br.ID);
            }
            else
            {
                g.d("got unknown message: " + type + request + response);
            }
            var ok = mt.GotMessage(type, source, dest, msgid, request, ref response);

            if (!ok)
            {
                g.d("error processing: " + type + " request: " + request + " response: " + response);
            }
            msgok &= ok;
        }
예제 #29
0
 long EsignalServer_newUnknownRequest(MessageTypes t, string msg)
 {
     switch (t)
     {
     case MessageTypes.BARREQUEST:
     {
         verb("got barrequest: " + msg);
         try
         {
             BarRequest br = BarImpl.ParseBarRequest(msg);
             _barrequests.Write(br);
         }
         catch (Exception ex)
         {
             debug("error parsing bar request: " + msg);
             debug(ex.Message + ex.StackTrace);
         }
         return(0);
     }
     }
     return((long)MessageTypes.FEATURE_NOT_IMPLEMENTED);
 }
예제 #30
0
파일: TestBar.cs 프로젝트: w1r2p1/Core-1
        public void BarIntervals()
        {
            BarImpl b       = new BarImpl(BarInterval.FiveMin);
            int     accepts = _ticklist.Count(k => b.NewTick(k));

            Assert.Equal(5, accepts);

            b       = new BarImpl(BarInterval.FifteenMin);
            accepts = _ticklist.Count(k => b.NewTick(k));
            Assert.Equal(9, accepts);

            b       = new BarImpl(BarInterval.Minute);
            accepts = 0;
            for (int i = 7; i < _ticklist.Length; i++)
            {
                if (b.NewTick(_ticklist[i]))
                {
                    accepts++;
                }
            }
            Assert.Equal(2, accepts);
        }