public OhlcResolutionAdapter(OhlcResolutionAdapterContext context) { Ctx = context; context.EnsureDefaults(); if (context.RequiresApiDiscovery()) { context.ApplyApiProviders(); } context.EnsureProvider(); context.Network = context.Network ?? context.PrimaryApiProvider?.Network; SeriesId = OhlcUtilities.GetHash(context.Pair, context.TimeResolution, context.Network); if (StorageEnabled) { if (Ctx.MemoryStorageEnabled) { _storageAdapters.Add(0, new OhlcResolutionDataAdapterMemory(this)); } if (Ctx.DbStorageEnabled) { _storageAdapters.Add(1, new OhlcResolutionDataAdapterDb(this)); } } _apiAdapters.Add(0, new OhlcResolutionDataAdapterApi(this)); }
public ObjectId GetHash(Network network) { return(OhlcUtilities.GetHash(Pair, TimeResolution, network)); }
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); }