private static async Task EnqueueData(string delta)
        {
            HistDataResponse histData = await BtrexREST.GetMarketHistoryV2(delta, "fiveMin");

            if (histData.success != true)
            {
                Console.WriteLine("    !!!!ERR GET-HISTORY>>> " + histData.message);
                return;
            }
            //downloaded++;

            DataQueue.Enqueue(histData);
        }
Ejemplo n.º 2
0
        public async Task <bool> Resolve5mCandles(bool retryOnFail = true)
        {
            DateTime NextCandleTime     = LastStoredCandle.AddMinutes(5);
            DateTime NextCandleCurrTime = LastStoredCandle.AddMinutes(10);

            if (CandlesResolved)
            {
                Trace.WriteLine(string.Format("\r[{1}] CANDLES RESOLVED - LastCandleStart: {0}", LastStoredCandle, MarketDelta));
                return(true);
            }

            while (!CandlesResolved)
            {
                HistDataResponse response = await BtrexREST.GetMarketHistoryV2(MarketDelta, "oneMin");

                if (!response.success)
                {
                    Trace.WriteLine("    !!!!ERR GET-1m-CANDLES: [{0}]", MarketDelta);
                    return(false);
                }

                DateTime last1mCandleCurrTime = response.result.Last().T.AddMinutes(1);
                DateTime firstFillTime        = RecentFills.First().TimeStamp;

                if (last1mCandleCurrTime >= firstFillTime)
                {
                    //Build latest 5m candle with 1m data and RecentFills:
                    List <HistDataLine> Candles1m = new List <HistDataLine>();
                    foreach (HistDataLine line in response.result)
                    {
                        if (line.T >= LastStoredCandle.AddMinutes(5))
                        {
                            Candles1m.Add(line);
                        }
                    }

                    //Grab O:H:L:V (noC) from 1mCandles
                    //simulate 2 mdFills (H&L:V) and add to beginning of RecentFills
                    Decimal O = Candles1m.First().O,
                            H = Candles1m.Max(x => x.H),
                            L = Candles1m.Min(x => x.L),
                            V = Candles1m.Sum(x => x.V),
                            C = Candles1m.Last().C;

                    List <mdFill> RevisedFills = new List <mdFill>();
                    RevisedFills.Add(new mdFill(LastStoredCandle.AddMinutes(5), O, (V / 4M), "BUY"));
                    RevisedFills.Add(new mdFill(LastStoredCandle.AddSeconds(300.5), H, (V / 4M), "SELL"));
                    RevisedFills.Add(new mdFill(LastStoredCandle.AddSeconds(300.5), L, (V / 4M), "BUY"));
                    RevisedFills.Add(new mdFill(LastStoredCandle.AddSeconds(301), C, (V / 4M), "SELL"));

                    if (last1mCandleCurrTime >= NextCandleCurrTime)
                    {
                        RecentFills = new List <mdFill>(RevisedFills);
                    }
                    else
                    {
                        foreach (mdFill fill in RecentFills)
                        {
                            if (fill.TimeStamp >= last1mCandleCurrTime && last1mCandleCurrTime < NextCandleCurrTime)
                            {
                                RevisedFills.Add(fill);
                            }
                        }

                        RecentFills = new List <mdFill>(RevisedFills);
                    }



                    BuildCandleFromRecentFills(NextCandleTime);

                    CandlesResolved = true;
                    Trace.WriteLine(string.Format("\r[{1}] CANDLES RESOLVED - LastCandleStart: {0}", LastStoredCandle, MarketDelta));
                }
                else
                {
                    //Trace.WriteLine("    !!!!ERR RESOLVE_CANDLES>>Current: {0} < LastFill: {1} :: [{2}]", last1mCandleCurrTime, firstFillTime, MarketDelta);
                    if (!retryOnFail)
                    {
                        return(false);
                    }

                    for (int s = 15; s > 0; s--)
                    {
                        Trace.Write(string.Format("\r    Resolving [{0}] TradeHist->Candles time gap. Retry in {1} seconds...", MarketDelta, s));
                        Thread.Sleep(1000);
                    }
                    Trace.Write("\r                                                                                  \r");
                }
            }

            return(true);
        }