Ejemplo n.º 1
0
        public List <Candle> CreateCandlesSeries(string pair, Timeframe timeframe,
                                                 bool updateCandles, DateTime?minOpenTimeUtc = null, DateTime?maxCloseTimeUtc = null)
        {
            var candles = _candlesService.GetCandles(_broker, pair, timeframe, updateCandles, minOpenTimeUtc, maxCloseTimeUtc);

            if (candles != null && candles.Count > 0)
            {
                return(candles);
            }

            // Get first/second symbol from pair
            var firstSymbol  = string.Empty;
            var secondSymbol = string.Empty;
            var allSymbols   = _broker.GetSymbols();

            for (var l = 5;
                 l >= 3;
                 l--) // Go backwards because e.g. LUNABTC - for some reason there already is a LUNBTC in the symbols
            {
                if (allSymbols.Contains($"{pair.Substring(0, l)}BTC") ||
                    allSymbols.Contains($"{pair.Substring(0, l)}BNB") ||
                    allSymbols.Contains($"{pair.Substring(0, l)}USDT"))
                {
                    firstSymbol  = pair.Substring(0, l);
                    secondSymbol = pair.Substring(firstSymbol.Length, pair.Length - firstSymbol.Length);
                    break;
                }
            }

            if (string.IsNullOrEmpty(firstSymbol))
            {
                // Try reverse
                firstSymbol  = string.Empty;
                secondSymbol = string.Empty;
                for (var l = 5;
                     l >= 3;
                     l--) // Go backwards because e.g. LUNABTC - for some reason there already is a LUNBTC in the symbols
                {
                    if (allSymbols.Contains($"{pair.Substring(pair.Length - l, l)}BTC") ||
                        allSymbols.Contains($"{pair.Substring(pair.Length - l, l)}BNB") ||
                        allSymbols.Contains($"{pair.Substring(pair.Length - l, l)}USDT"))
                    {
                        firstSymbol  = pair.Substring(0, pair.Length - l);
                        secondSymbol = pair.Substring(firstSymbol.Length, pair.Length - firstSymbol.Length);
                        break;
                    }
                }
            }

            if (string.IsNullOrEmpty(firstSymbol))
            {
                throw new ApplicationException($"Unable to find market {pair}");
            }

            return(CreateCandlesSeries(firstSymbol, secondSymbol, timeframe, updateCandles, minOpenTimeUtc, maxCloseTimeUtc));
        }