diff --git a/sandbox/aggregated-feeds.ts b/sandbox/aggregated-feeds.ts index fb8e752..df54846 100644 --- a/sandbox/aggregated-feeds.ts +++ b/sandbox/aggregated-feeds.ts @@ -11,7 +11,7 @@ async function main() { // const aggfeed2 = new AggregatedFeed(feeds, "eth:usd") for (let pair of ["btc:usd", "eth:usd"]) { - const aggfeed = new AggregatedFeed(feeds, pair) + const aggfeed = new AggregatedFeed(feeds, [], 2, pair) setImmediate(async () => { for await (let _ of aggfeed.updates()) { diff --git a/src/PriceFeeder.ts b/src/PriceFeeder.ts index cbfdb28..b47df74 100644 --- a/src/PriceFeeder.ts +++ b/src/PriceFeeder.ts @@ -99,7 +99,7 @@ export class PriceFeeder { } const useFeeds = (priceFeedMapping[name]) ? priceFeedMapping[name].useFeeds.map(x => this.feeds[x]) : this.feeds; - const feed = new AggregatedFeed(useFeeds, priceFeedMapping[name].pairNames, name) + const feed = new AggregatedFeed(useFeeds, priceFeedMapping[name].pairNames, aggregatorInfo.config.decimals, name) const priceFeed = feed.medians() const minValueChangeForNewRound = priceFeedMapping[name].minValueChangeForNewRound || 100 diff --git a/src/feeds.ts b/src/feeds.ts index efa125d..d79cf03 100644 --- a/src/feeds.ts +++ b/src/feeds.ts @@ -366,13 +366,14 @@ export class AggregatedFeed { public prices: IPrice[] = [] // assume that the feeds are already connected - constructor(public feeds: PriceFeed[], public pairMappings: string[], public pair: string) { + constructor(public feeds: PriceFeed[], public pairMappings: string[], public decimals: number, public pair: string) { this.subscribe() } private subscribe() { const pair = this.pair const pairMappings = this.pairMappings; + const decimals = this.decimals; let j = 0 @@ -387,6 +388,7 @@ export class AggregatedFeed { return } price.timestamp = Date.now() + price.decimals = decimals; this.prices[index] = price this.onPriceUpdate(price) }) @@ -492,7 +494,7 @@ export function coinbase(pair: string): IPriceFeed { export function file(pair: string, filepath: string): IPriceFeed { const emitter = new EventEmitter() - + try { fs.accessSync(filepath); } catch { @@ -517,4 +519,4 @@ export function file(pair: string, filepath: string): IPriceFeed { }); return eventsIter(emitter, UPDATE) -} \ No newline at end of file +}