Exemplo n.º 1
0
        /// <summary>Send a range of market data.</summary>
        private void SendHistoricMarketData(MarketSeries series, int i_oldest, int i_newest)
        {
            // Send historical data to Tradee
            var open_time = new List <long>(series.OpenTime.Count);
            var open      = new List <double>(series.Open.Count);
            var high      = new List <double>(series.High.Count);
            var low       = new List <double>(series.Low.Count);
            var close     = new List <double>(series.Close.Count);
            var median    = new List <double>(series.Median.Count);
            var volume    = new List <double>(series.TickVolume.Count);

            Debug.Assert(i_newest <= i_oldest);
            for (int i = i_oldest; i-- != i_newest;)
            {
                var t = series.OpenTime.Last(i).Ticks;
                var o = series.Open.Last(i);
                var h = series.High.Last(i);
                var l = series.Low.Last(i);
                var c = series.Close.Last(i);
                var m = series.Median.Last(i);
                var v = series.TickVolume.Last(i);

                open_time.Add(t);
                open.Add(o);
                high.Add(Math.Max(h, Math.Max(o, c)));
                low.Add(Math.Min(l, Math.Min(o, c)));
                close.Add(c);
                median.Add(m);
                volume.Add(v);
            }

            // Nothing available?
            if (close.Count == 0)
            {
                return;
            }

            // Create a candle batch
            var data = new PriceCandles(
                open_time.ToArray(),
                open.ToArray(),
                high.ToArray(),
                low.ToArray(),
                close.ToArray(),
                median.ToArray(),
                volume.ToArray());

            if (Model.Post(new InMsg.CandleData(SymbolCode, series.TimeFrame.ToTradeeTimeframe(), data)))
            {
                Debug.WriteLine("Historic data for {0},{1} sent".Fmt(series.SymbolCode, series.TimeFrame.ToTradeeTimeframe()));
            }
        }
Exemplo n.º 2
0
        /// <summary>Send fake historic data</summary>
        private void SendHistoricData()
        {
            const int Count = 20;

            foreach (var tf in TimeFrames)
            {
                var one     = Misc.TimeFrameToTicks(1.0, tf);
                var candles = new PriceCandles(
                    Enumerable.Range(0, Count).Select(i => m_now - (Count - i) * one).ToArray(),
                    Enumerable.Range(0, Count).Select(i => m_rng.NextDouble(0.5, 1.5)).ToArray(),
                    Enumerable.Range(0, Count).Select(i => m_rng.NextDouble(1.5, 2.0)).ToArray(),
                    Enumerable.Range(0, Count).Select(i => m_rng.NextDouble(0.0, 0.5)).ToArray(),
                    Enumerable.Range(0, Count).Select(i => m_rng.NextDouble(0.5, 1.5)).ToArray(),
                    Enumerable.Range(0, Count).Select(i => m_rng.NextDouble(0.5, 1.5)).ToArray(),
                    Enumerable.Range(0, Count).Select(i => (double)(int)m_rng.NextDouble(1, 100)).ToArray());

                Model.Post(new InMsg.CandleData(SymbolCode, tf, candles));
            }
        }
Exemplo n.º 3
0
        /// <summary>Add a batch of candles</summary>
        public void Add(ETimeFrame tf, PriceCandles candles)
        {
            // Insert the candles into the database
            using (var t = m_db.NewTransaction())
                using (var query = new Sqlite.Query(m_db, SqlExpr.InsertCandle(tf)))
                {
                    foreach (var candle in candles.AllCandles.Select(x => new Candle(x)))
                    {
                        query.Reset();
                        query.BindParms(1, SqlExpr.InsertCandleParams(candle));
                        query.Run();
                    }
                    t.Commit();
                }

            // Don't bother maintaining the cache, just invalidate it
            InvalidateCachedData();

            // Record the last time data was received
            LastUpdatedUTC = Model.UtcNow;

            // Notify data added/changed
            DataChanged.Raise(this, new DataEventArgs(this, tf, null, false));
        }