private OhlcData Convert(TimeRange range)
        {
            Ctx.Status("Converting @" + Ctx.PrimaryApiProvider.Title + " " + Ctx.CurrencyConversionApiProvider.Title + " [1]");

            var pc = new OhlcContext(new AssetPair(Ctx.Pair.Asset1, Ctx.AssetIntermediary), Ctx.TimeResolution, range, L);
            var r1 = ApiCoordinator.GetOhlc(Ctx.PrimaryApiProvider, pc);

            if (r1.IsNull)
            {
                return(null);
            }

            var d1 = r1.Response.OhlcData;

            Ctx.Status("Converting @" + Ctx.PrimaryApiProvider.Title + " " + Ctx.CurrencyConversionApiProvider.Title + " [2]");

            var pc2 = new OhlcContext(new AssetPair(Ctx.AssetIntermediary, Ctx.Pair.Asset2), Ctx.TimeResolution, range, L);

            var r2 = ApiCoordinator.GetOhlc(Ctx.CurrencyConversionApiProvider, pc2);

            if (r2.IsNull)
            {
                return(null);
            }

            var d2 = r2.Response.OhlcData;

            if (d1.IsEmpty() || d2.IsEmpty())
            {
                return(null);
            }

            if (d1.Count != d2.Count)
            {
                return(null);
            }

            var ohcldata = new OhlcData(_adapter.TimeResolution)
            {
                ConvertedFrom = Ctx.AssetIntermediary,
                Network       = Ctx.PrimaryApiProvider.Network
            };

            var seriesid = OhlcUtilities.GetHash(Ctx.Pair, range.TimeResolution, ohcldata.Network);

            foreach (var i in d1)
            {
                var i2 = d2.FirstOrDefault(x => x.DateTimeUtc == i.DateTimeUtc);
                if (i2 == null)
                {
                    return(null);
                }

                ohcldata.Add(new OhlcEntry(seriesid, i.DateTimeUtc, Ctx.PrimaryApiProvider, Ctx.CurrencyConversionApiProvider, Ctx.AssetIntermediary)
                {
                    Open            = i.Open * i2.Open,
                    Close           = i.Close * i2.Close,
                    High            = i.High * i2.High,
                    Low             = i.Low * i2.Low,
                    VolumeTo        = 0,
                    VolumeFrom      = i2.VolumeFrom,
                    WeightedAverage = 0
                });
            }

            return(ohcldata);
        }
Ejemplo n.º 2
0
 public static Task <ApiResponse <OhlcDataResponse> > GetOhlcAsync(IOhlcProvider provider, OhlcContext context)
 {
     return(ApiHelpers.WrapExceptionAsync(() => provider.GetOhlcAsync(context), nameof(GetOhlc), provider, context));
 }
Ejemplo n.º 3
0
 public static ApiResponse <OhlcDataResponse> GetOhlc(IOhlcProvider provider, OhlcContext context)
 {
     return(AsyncContext.Run(() => GetOhlcAsync(provider, context)));
 }