Decimal issue fix
This commit is contained in:
parent
552444f773
commit
4f859f291b
|
@ -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()) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue