Example #1
0
        /// <summary>
        /// the method in which the processing queue _candleSeriesNeadToStart is running
        /// метод, в котором работает поток обрабатывающий очередь _candleSeriesNeadToStart
        /// </summary>
        private async void CandleStarter()
        {
            try
            {
                while (true)
                {
                    await Task.Delay(50);

                    if (_isDisposed == true)
                    {
                        return;
                    }

                    if (MainWindow.ProccesIsWorked == false)
                    {
                        return;
                    }

                    if (_candleSeriesNeadToStart.Count != 0)
                    {
                        CandleSeries series = _candleSeriesNeadToStart.Dequeue();

                        if (series == null || series.IsStarted)
                        {
                            continue;
                        }

                        ServerType serverType = _server.ServerType;

                        if (serverType == ServerType.Tester)
                        {
                            series.IsStarted = true;
                        }

                        else if (serverType == ServerType.Plaza ||
                                 serverType == ServerType.QuikDde ||
                                 serverType == ServerType.AstsBridge ||
                                 serverType == ServerType.NinjaTrader ||
                                 serverType == ServerType.Lmax)
                        {
                            series.CandlesAll = null;
                            // further, we try to load candles with ticks
                            // далее, пытаемся пробуем прогрузить свечи при помощи тиков
                            List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);

                            series.PreLoad(allTrades);
                            // if there is a preloading of candles on the server and something is downloaded
                            // если на сервере есть предзагрузка свечек и что-то скачалось
                            series.UpdateAllCandles();

                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.SmartCom)
                        {
                            SmartComServer smart = (SmartComServer)_server;

                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);

                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = smart.GetSmartComCandleHistory(series.Security.Name,
                                                                                       series.TimeFrameSpan, 170);
                                if (candles != null)
                                {
                                    candles.Reverse();
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Tinkoff)
                        {
                            TinkoffServer smart = (TinkoffServer)_server;

                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1 ||
                                series.TimeFrame == TimeFrame.Hour2 ||
                                series.TimeFrame == TimeFrame.Hour4 ||
                                series.TimeFrame == TimeFrame.Min20 ||
                                series.TimeFrame == TimeFrame.Min45)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);

                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = smart.GetCandleHistory(series.Security.NameId,
                                                                               series.TimeFrame);

                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Tester ||
                                 serverType == ServerType.Optimizer ||
                                 serverType == ServerType.Oanda ||
                                 serverType == ServerType.BitStamp
                                 )
                        {
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.QuikLua)
                        {
                            QuikLuaServer luaServ = (QuikLuaServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = luaServ.GetQuikLuaTickHistory(series.Security);
                                if (allTrades != null && allTrades.Count != 0)
                                {
                                    series.PreLoad(allTrades);
                                }
                            }
                            else
                            {
                                List <Candle> candles = luaServ.GetQuikLuaCandleHistory(series.Security,
                                                                                        series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    //candles.Reverse();
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.BitMex)
                        {
                            BitMexServer bitMex = (BitMexServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = bitMex.GetBitMexCandleHistory(series.Security.Name,
                                                                                      series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Kraken)
                        {
                            KrakenServer kraken = (KrakenServer)_server;

                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = kraken.GetCandleHistory(series.Security.Name,
                                                                                series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Binance)
                        {
                            BinanceServer binance = (BinanceServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = binance.GetCandleHistory(series.Security.Name,
                                                                                 series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.InteractivBrokers)
                        {
                            InteractiveBrokersServer server = (InteractiveBrokersServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = server.GetCandleHistory(series.Security.Name,
                                                                                series.TimeFrame);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.BinanceFutures)
                        {
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                BinanceServerFutures binance = (BinanceServerFutures)_server;
                                List <Candle>        candles = binance.GetCandleHistory(series.Security.Name,
                                                                                        series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.BitMax)
                        {
                            BitMaxProServer bitMax = (BitMaxProServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = bitMax.GetCandleHistory(series.Security.Name,
                                                                                series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Bitfinex)
                        {
                            BitfinexServer bitfinex = (BitfinexServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = bitfinex.GetCandleHistory(series.Security.Name,
                                                                                  series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Transaq)
                        {
                            TransaqServer transaq = (TransaqServer)_server;

                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);

                                series.PreLoad(allTrades);
                                series.UpdateAllCandles();
                                series.IsStarted = true;
                            }
                            else
                            {
                                transaq.GetCandleHistory(series);
                            }
                        }
                        else if (serverType == ServerType.Livecoin ||
                                 serverType == ServerType.Exmo)
                        {
                            List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);

                            series.PreLoad(allTrades);
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Zb)
                        {
                            ZbServer zbServer = (ZbServer)_server;

                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = zbServer.GetCandleHistory(series.Security.Name, series.TimeFrameSpan);

                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.GateIo)
                        {
                            GateIoServer gateIoServer = (GateIoServer)_server;

                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = gateIoServer.GetCandleHistory(series.Security.Name, series.TimeFrameSpan);

                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.GateIoFutures)
                        {
                            GateIoFuturesServer gateIoFutures = (GateIoFuturesServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = gateIoFutures.GetCandleHistory(series.Security.Name,
                                                                                       series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.Hitbtc)
                        {
                            HitbtcServer hitbtc = (HitbtcServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = hitbtc.GetCandleHistory(series.Security.Name,
                                                                                series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.HuobiSpot)
                        {
                            HuobiSpotServer huobiSpot = (HuobiSpotServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = huobiSpot.GetCandleHistory(series.Security.Name,
                                                                                   series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.HuobiFutures)
                        {
                            HuobiFuturesServer huobi = (HuobiFuturesServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = huobi.GetCandleHistory(series.Security.Name,
                                                                               series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.HuobiFuturesSwap)
                        {
                            HuobiFuturesSwapServer huobi = (HuobiFuturesSwapServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = huobi.GetCandleHistory(series.Security.Name,
                                                                               series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                        else if (serverType == ServerType.FTX)
                        {
                            FTXServer ftxServer = (FTXServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = ftxServer.GetCandleHistory(series.Security.Name,
                                                                                   series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }

                        else if (serverType == ServerType.Bybit)
                        {
                            BybitServer bybit = (BybitServer)_server;
                            if (series.CandleCreateMethodType != CandleCreateMethodType.Simple ||
                                series.TimeFrameSpan.TotalMinutes < 1)
                            {
                                List <Trade> allTrades = _server.GetAllTradesToSecurity(series.Security);
                                series.PreLoad(allTrades);
                            }
                            else
                            {
                                List <Candle> candles = bybit.GetCandleHistory(series.Security.Name,
                                                                               series.TimeFrameSpan);
                                if (candles != null)
                                {
                                    series.CandlesAll = candles;
                                }
                            }
                            series.UpdateAllCandles();
                            series.IsStarted = true;
                        }
                    }
                }
            }
            catch (Exception error)
            {
                SendLogMessage(error.ToString(), LogMessageType.Error);
            }
        }
Example #2
0
        /// <summary>
        /// create server
        /// создать сервер
        /// </summary>
        /// <param name="type"> server type / тип сервера </param>
        /// <param name="neadLoadTicks"> shows whether upload ticks from storage. this is need for bots with QUIK or Plaza2 servers / нужно ли подгружать тики из хранилища. Актуально в режиме робота для серверов Квик, Плаза 2 </param>
        public static void CreateServer(ServerType type, bool neadLoadTicks)
        {
            try
            {
                if (_servers == null)
                {
                    _servers = new List <IServer>();
                }

                if (_servers.Find(server => server.ServerType == type) != null)
                {
                    return;
                }

                IServer newServer = null;
                if (type == ServerType.FTX)
                {
                    newServer = new FTXServer();
                }
                if (type == ServerType.HuobiFuturesSwap)
                {
                    newServer = new HuobiFuturesSwapServer();
                }
                if (type == ServerType.HuobiFutures)
                {
                    newServer = new HuobiFuturesServer();
                }
                if (type == ServerType.HuobiSpot)
                {
                    newServer = new HuobiSpotServer();
                }
                if (type == ServerType.MfdWeb)
                {
                    newServer = new MfdServer();
                }
                if (type == ServerType.MoexDataServer)
                {
                    newServer = new MoexDataServer();
                }
                if (type == ServerType.Tinkoff)
                {
                    newServer = new TinkoffServer();
                }
                if (type == ServerType.Hitbtc)
                {
                    newServer = new HitbtcServer();
                }
                if (type == ServerType.GateIo)
                {
                    newServer = new GateIoServer();
                }
                if (type == ServerType.GateIoFutures)
                {
                    newServer = new GateIoFuturesServer();
                }
                if (type == ServerType.Zb)
                {
                    newServer = new ZbServer();
                }
                if (type == ServerType.Exmo)
                {
                    newServer = new ExmoServer();
                }
                if (type == ServerType.Livecoin)
                {
                    newServer = new LivecoinServer();
                }
                if (type == ServerType.BitMax)
                {
                    newServer = new BitMaxServer();
                }
                if (type == ServerType.Transaq)
                {
                    newServer = new TransaqServer();
                }
                if (type == ServerType.Lmax)
                {
                    newServer = new LmaxServer();
                }
                if (type == ServerType.Bitfinex)
                {
                    newServer = new BitfinexServer();
                }
                if (type == ServerType.Binance)
                {
                    newServer = new BinanceServer();
                }
                if (type == ServerType.BinanceFutures)
                {
                    newServer = new BinanceServerFutures();
                }
                if (type == ServerType.NinjaTrader)
                {
                    newServer = new NinjaTraderServer();
                }
                if (type == ServerType.BitStamp)
                {
                    newServer = new BitStampServer();
                }
                if (type == ServerType.Kraken)
                {
                    newServer = new KrakenServer(neadLoadTicks);
                }
                if (type == ServerType.Oanda)
                {
                    newServer = new OandaServer();
                }
                if (type == ServerType.BitMex)
                {
                    newServer = new BitMexServer();
                }
                if (type == ServerType.QuikLua)
                {
                    newServer = new QuikLuaServer();
                }
                if (type == ServerType.QuikDde)
                {
                    newServer = new QuikServer();
                }
                if (type == ServerType.InteractivBrokers)
                {
                    newServer = new InteractivBrokersServer();
                }
                else if (type == ServerType.SmartCom)
                {
                    newServer = new SmartComServer();
                }
                else if (type == ServerType.Plaza)
                {
                    newServer = new PlazaServer();
                }
                else if (type == ServerType.AstsBridge)
                {
                    newServer = new AstsBridgeServer(neadLoadTicks);
                }
                else if (type == ServerType.Tester)
                {
                    newServer = new TesterServer();
                }
                else if (type == ServerType.Finam)
                {
                    newServer = new FinamServer();
                }

                if (newServer == null)
                {
                    return;
                }

                _servers.Add(newServer);

                if (ServerCreateEvent != null)
                {
                    ServerCreateEvent(newServer);
                }

                SendNewLogMessage(OsLocalization.Market.Message3 + _servers[_servers.Count - 1].ServerType, LogMessageType.System);
            }
            catch (Exception error)
            {
                SendNewLogMessage(error.ToString(), LogMessageType.Error);
            }
        }