Ejemplo n.º 1
0
        public Dictionary <string, Trade> GetLastTrades(List <string> symbols, bool useCached = true)
        {
            List <GMSDK.Tick> gskTicks = new List <GMSDK.Tick>();

            if (useCached)
            {
                foreach (string symbol in symbols.ToArray())
                {
                    GMSDK.Tick gskTick;
                    if (this.tickCache.TryGetValue(symbol, out gskTick))
                    {
                        gskTicks.Add(gskTick);
                        symbols.Remove(symbol);
                    }
                }
            }
            if (symbols.Count > 0)
            {
                gskTicks.AddRange(this.GetLastTicks(symbols));
            }
            Dictionary <string, Trade> tradeDict = new Dictionary <string, Trade>();

            foreach (GMSDK.Tick gskTick in gskTicks)
            {
                string symbol = gskTick.exchange + "." + gskTick.sec_id;
                tradeDict.Add(symbol, GSKToGM.ConvertTrade(gskTick));
            }
            return(tradeDict);
        }
Ejemplo n.º 2
0
        public List <Trade> GetTrades(string symbol, string beginTimeString, string endTimeString)
        {
            List <GMSDK.Tick> gskTicks;

            lock (this._md)
            {
                gskTicks = this._md.GetTicks(symbol, beginTimeString, endTimeString);
            }
            List <Trade> trades = new List <Trade>();

            foreach (GMSDK.Tick gskTick in gskTicks)
            {
                trades.Add(GSKToGM.ConvertTrade(gskTick));
            }
            return(trades);
        }
Ejemplo n.º 3
0
        public List <Trade> GetLastNTrades(string symbol, string lastTimeString, int n)
        {
            List <GMSDK.Tick> gskTicks;

            lock (this._md)
            {
                gskTicks = this._md.GetLastNTicks(symbol, n, lastTimeString);
            }
            gskTicks.Reverse();
            List <Trade> trades = new List <Trade>();

            foreach (GMSDK.Tick gskTick in gskTicks)
            {
                trades.Add(GSKToGM.ConvertTrade(gskTick));
            }
            return(trades);
        }
Ejemplo n.º 4
0
        private void setNewTick(GMSDK.Tick tick, bool isPush = false)
        {
            string symbol = tick.exchange + "." + tick.sec_id;

            if (isPush)
            {
                this.symbolsOfPush.Add(symbol);
            }

            if (!subscribedSymbols.Contains(symbol))
            {
                return;
            }
            Instrument curInstrument = InstrumentManager.Instruments[symbol];

            if (curInstrument == null)
            {
                this.EmitError(2, "Symbol " + symbol + " was not found in InstrumentManager.");
                return;
            }
            GMSDK.Tick prevTick = null;
            if (!this.tickCache.TryGetValue(symbol, out prevTick))
            {
                this.EmitNewTrade(GSKToGM.ConvertTrade(tick), curInstrument);
                this.EmitNewQuote(GSKToGM.ConvertQuote(tick), curInstrument);
            }
            else
            {
                if (tick.utc_time > prevTick.utc_time)
                {
                    if (tick.last_volume > 0 || tick.last_price != prevTick.last_price)
                    {
                        this.EmitNewTrade(GSKToGM.ConvertTrade(tick), curInstrument);
                    }
                    this.EmitNewQuote(GSKToGM.ConvertQuote(tick), curInstrument);
                }
            }
            this.tickCache[symbol] = tick;
        }