fixed proper decimal submissions in feeds

This commit is contained in:
dd 2021-06-05 12:11:13 -04:00
parent 208759f577
commit b1318349e6
2 changed files with 33 additions and 30 deletions

View File

@ -44,13 +44,13 @@ const priceFeedMapping = {
pairNames: ['ETH-USD', 'live_trades_ethusd', 'ETH/USD', 'ETHBUSD', 'ETH-USDC']
},
'sol:usd': {
minValueChangeForNewRound: 4,
minValueChangeForNewRound: 400,
useFeeds: [2,3,4],
pairNames: ['SOL/USD', 'SOLBUSD', 'SOL-USDT']
// uses USDT for OKEx
},
'srm:usd': {
minValueChangeForNewRound: 1,
minValueChangeForNewRound: 50,
useFeeds: [2,3,4],
pairNames: ['SRM/USD', 'SRMBUSD', 'SRM-USDT']
// uses USDT for OKEx

View File

@ -25,7 +25,6 @@ export interface IPriceFeed {
export abstract class PriceFeed {
public emitter = new EventEmitter()
protected conn!: ReconnectingWebSocket
protected connected!: Promise<void>
@ -91,6 +90,10 @@ export abstract class PriceFeed {
this.emitter.emit(UPDATE, price)
}
/**
* Every implementation must return IPrice with the correct amount of decimal transformation done on the incoming price
* @param data
*/
abstract parseMessage(data: any): IPrice | undefined
// abstract parseMessage(pair: string)
// abstract parseMessage(pair: string)
@ -131,8 +134,8 @@ export class CoinBase extends PriceFeed {
const price: IPrice = {
source: CoinBase.name,
pair,
decimals: 2,
value: Math.floor(payload.price * 100),
decimals: 0,
value: payload.price,
}
return price
@ -182,8 +185,8 @@ export class BitStamp extends PriceFeed {
const price: IPrice = {
source: BitStamp.name,
pair,
decimals: 2,
value: Math.floor(payload.data.price * 100),
decimals: 0,
value: payload.data.price,
}
return price
@ -231,8 +234,8 @@ export class FTX extends PriceFeed {
const price: IPrice = {
source: FTX.name,
pair,
decimals: 2,
value: Math.floor(payload.data.last * 100),
decimals: 0,
value: payload.data.last,
}
return price
@ -276,12 +279,11 @@ export class Binance extends PriceFeed {
const pair = payload.s;
const price: IPrice = {
source: Binance.name,
pair,
decimals: 2,
value: Math.floor(payload.p * 100),
decimals: 0,
value: payload.p,
}
return price
@ -341,8 +343,8 @@ export class OKEx extends PriceFeed {
const price: IPrice = {
source: OKEx.name,
pair,
decimals: 2,
value: Math.floor(payload.data[0].last * 100),
decimals: 0,
value: payload.data[0].last,
}
return price
@ -388,6 +390,7 @@ export class AggregatedFeed {
return
}
price.timestamp = Date.now()
price.value = Math.floor(Math.pow(10, decimals - price.decimals) * price.value)
price.decimals = decimals;
this.prices[index] = price
this.onPriceUpdate(price)