Esempio n. 1
0
 /// <summary>
 /// Quote Dispatcher
 /// </summary>
 /// <param name="e"></param>
 private void QuoteDispatcher(MyEventArgs <Tick> e)
 {
     // 1. strategies
     _feedstrategyquoteservice.FeedStrategies(e.Value);
     // 2. tick archive
     _tickarchiveservice.newTick(e.Value);
     // 3. Views
     _quoteviewupdateservice.UpdateViews(e.Value);
 }
Esempio n. 2
0
        public void CreateRead()
        {
            readdata.Clear();
            readdata2.Clear();
            FILE = TikWriter.SafeFilename(SYM, PATH, DATE);
            TestTikWriterReader.removefile(FILE);
            {
                Tick[] data = RandomTicks.GenerateSymbol(SYM, MAXTICKS);

                TickArchiver ta = new TickArchiver(Environment.CurrentDirectory);
                for (int i = 0; i < data.Length; i++)
                {
                    data[i].date = DATE;
                    data[i].time = Util.DT2FT(DateTime.Now);
                    ta.newTick(data[i]);
                }
                ta.Stop();

                // read file back in from file
                TikReader tr = new TikReader(FILE);
                tr.gotTick += new TickDelegate(tr_gotTick);
                while (tr.NextTick())
                {
                    ;
                }

                // verify length
                Assert.AreEqual(data.Length, readdata.Count);
                // verify content
                bool equal = true;
                for (int i = 0; i < MAXTICKS; i++)
                {
                    equal &= data[i].trade == readdata[i].trade;
                }
                tr.Close();

                readdata.Clear();
                Assert.IsTrue(equal, "ticks did not matched archive.");
                TestTikWriterReader.removefile(FILE);
            }
        }
Esempio n. 3
0
        void tl_gotTick(Tick t)
        {
            // see if we are tracking this symbol
            int[] idxs = new int[0];
            if (!_symidx.TryGetValue(t.symbol, out idxs))
            {
                return;
            }

            // see if we should save this tick
            if (_ao.archivetickbox.Checked)
            {
                _ta.newTick(t);
            }

            // send tick to any valid requesting responses
            foreach (int idx in idxs)
            {
                if (_reslist[idx].isValid)
                {
                    _reslist[idx].GotTick(t);
                }
            }
        }
Esempio n. 4
0
        public void Multiday()
        {
            readdata.Clear();
            readdata2.Clear();
            int           d  = 20100223;
            int           t  = 235900;
            int           t1 = 0;
            const decimal p  = 50;
            int           s  = 100;

            string FILE1 = TikWriter.SafeFilename(SYM, PATH, d);

            TestTikWriterReader.removefile(FILE1);
            string FILE2 = TikWriter.SafeFilename(SYM, PATH, d + 1);

            TestTikWriterReader.removefile(FILE2);


            Tick[] data = new Tick[]
            {
                TickImpl.NewTrade(SYM, d, t++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t++, p, s, string.Empty),
                // day two
                TickImpl.NewTrade(SYM, ++d, t1++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t1++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t1++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t1++, p, s, string.Empty),
                TickImpl.NewTrade(SYM, d, t1++, p, s, string.Empty),
            };


            TickArchiver ta = new TickArchiver(Environment.CurrentDirectory);

            for (int i = 0; i < data.Length; i++)
            {
                ta.newTick(data[i]);
            }
            ta.Stop();

            // read file back in from files
            if (System.IO.File.Exists(FILE1))
            {
                TikReader tr = new TikReader(FILE1);
                tr.gotTick += new TickDelegate(tr_gotTick);
                while (tr.NextTick())
                {
                    ;
                }
                tr.Close();
            }

            if (System.IO.File.Exists(FILE2))
            {
                TikReader tr2 = new TikReader(FILE2);
                tr2.gotTick += new TickDelegate(tr2_gotTick);
                while (tr2.NextTick())
                {
                    ;
                }
                tr2.Close();
            }

            // verify length
            Assert.AreEqual(5, readdata2.Count);
            Assert.AreEqual(5, readdata.Count);

            TestTikWriterReader.removefile(FILE1);
            TestTikWriterReader.removefile(FILE2);
        }
        // GotTick is called everytime a new quote or trade occurs
        public override void GotTick(TradeLink.API.Tick tick)
        {
            // store tick
            tick_archiver.newTick(tick);
            return; // for now only track/store ticks here...

            // ignore quotes
            if (!tick.isTrade)
            {
                return;
            }

            // ensure we track this symbol, all the other trackers will be indexed inside track_symbols_NewTxt()
            track_symbols.addindex(tick.symbol, false);

            // track tick
            track_ticks.newTick(tick);

            // another "track tick" :)
            //
            // For now we track tick in 2 different trackers:
            // TickTracker
            // and
            // BarListTracker (connected with MessageTracker)
            //
            // todo: Read more on topic of TickTracker vs BarListTracker. And eventually get rid of one of them.
            //      TickTracker - seems have more functionality, but
            //      BarListTracker - can build bars with any interval (we can mix diff. bar size in one strategy easily using this!)
            //
            track_barlists.newTick(tick); // dimon: give any ticks (trades) to this symbol and tracker will create barlists automatically

            // if we don't have enough bars, wait for more ticks
            //if (!track_barlists[tick.symbol].Has(BarsBack)) return;

            // get current position
            Position pos = track_positions[tick.symbol];

            // if we're flat and haven't seen this symbol yet, then...
            if (pos.isFlat && !track_symbols[tick.symbol])
            {
                // strart tracking it (other trackers will be updated accordingly, see track_symbols_NewTxt()
                track_symbols[tick.symbol] = true;

                D(tick.symbol + ": entering long");
                O(new MarketOrder(tick.symbol, EntrySize));
            }
            else if (!pos.isFlat && !track_exitsignals[tick.symbol])
            {
                // get most recent tick data
                Tick k = track_ticks[tick.symbol];
                // estimate our exit price
                decimal exitprice = UseQuotes
                    ? (k.hasAsk && pos.isLong ? k.ask
                    : (k.hasBid && pos.isShort ? k.bid : 0))
                    : (k.isTrade ? k.trade : 0);
                // assuming we could estimate an exit, see if our exit would hit our target
                if ((exitprice != 0) && (Calc.OpenPT(exitprice, pos) > ProfitTarget))
                {
                    track_exitsignals[tick.symbol] = true;
                    D("hit profit target");
                    O(new MarketOrderFlat(pos));
                }
            }
            // --------------------------------------------
            //
            // this is a grey box that manages exits, so wait until we have a position
            //if (!pt[tick.symbol].isFlat) return;
            //
            //// calculate the MA from closing bars
            //decimal MA = Calc.Avg(Calc.Closes(track_barlists[tick.symbol], BarsBack));

            //// if we're short, a cross is when market moves above MA
            //// if we're long, cross is when market goes below MA
            //bool cross = pt[tick.symbol].isShort ? (tick.trade > MA) : (tick.trade < MA);

            //// if we have a cross, then flat us for the requested size
            //if (cross)
            //    sendorder(new MarketOrderFlat(pt[tick.symbol], exitpercent));

            //// notify gauntlet and kadina about our moving average and cross
            //sendindicators(new string[] { MA.ToString(), cross.ToString() });
            // --------------------------------------------
        }
Esempio n. 6
0
 void tl_gotTick(Tick t)
 {
     _ta.newTick(t);
     _tlt.newTick(t);
 }