fixed proper decimal submissions in feeds
This commit is contained in:
parent
208759f577
commit
b1318349e6
|
@ -44,13 +44,13 @@ const priceFeedMapping = {
|
||||||
pairNames: ['ETH-USD', 'live_trades_ethusd', 'ETH/USD', 'ETHBUSD', 'ETH-USDC']
|
pairNames: ['ETH-USD', 'live_trades_ethusd', 'ETH/USD', 'ETHBUSD', 'ETH-USDC']
|
||||||
},
|
},
|
||||||
'sol:usd': {
|
'sol:usd': {
|
||||||
minValueChangeForNewRound: 4,
|
minValueChangeForNewRound: 400,
|
||||||
useFeeds: [2,3,4],
|
useFeeds: [2,3,4],
|
||||||
pairNames: ['SOL/USD', 'SOLBUSD', 'SOL-USDT']
|
pairNames: ['SOL/USD', 'SOLBUSD', 'SOL-USDT']
|
||||||
// uses USDT for OKEx
|
// uses USDT for OKEx
|
||||||
},
|
},
|
||||||
'srm:usd': {
|
'srm:usd': {
|
||||||
minValueChangeForNewRound: 1,
|
minValueChangeForNewRound: 50,
|
||||||
useFeeds: [2,3,4],
|
useFeeds: [2,3,4],
|
||||||
pairNames: ['SRM/USD', 'SRMBUSD', 'SRM-USDT']
|
pairNames: ['SRM/USD', 'SRMBUSD', 'SRM-USDT']
|
||||||
// uses USDT for OKEx
|
// uses USDT for OKEx
|
||||||
|
|
27
src/feeds.ts
27
src/feeds.ts
|
@ -25,7 +25,6 @@ export interface IPriceFeed {
|
||||||
|
|
||||||
export abstract class PriceFeed {
|
export abstract class PriceFeed {
|
||||||
public emitter = new EventEmitter()
|
public emitter = new EventEmitter()
|
||||||
|
|
||||||
protected conn!: ReconnectingWebSocket
|
protected conn!: ReconnectingWebSocket
|
||||||
protected connected!: Promise<void>
|
protected connected!: Promise<void>
|
||||||
|
|
||||||
|
@ -91,6 +90,10 @@ export abstract class PriceFeed {
|
||||||
this.emitter.emit(UPDATE, price)
|
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(data: any): IPrice | undefined
|
||||||
// abstract parseMessage(pair: string)
|
// abstract parseMessage(pair: string)
|
||||||
// abstract parseMessage(pair: string)
|
// abstract parseMessage(pair: string)
|
||||||
|
@ -131,8 +134,8 @@ export class CoinBase extends PriceFeed {
|
||||||
const price: IPrice = {
|
const price: IPrice = {
|
||||||
source: CoinBase.name,
|
source: CoinBase.name,
|
||||||
pair,
|
pair,
|
||||||
decimals: 2,
|
decimals: 0,
|
||||||
value: Math.floor(payload.price * 100),
|
value: payload.price,
|
||||||
}
|
}
|
||||||
|
|
||||||
return price
|
return price
|
||||||
|
@ -182,8 +185,8 @@ export class BitStamp extends PriceFeed {
|
||||||
const price: IPrice = {
|
const price: IPrice = {
|
||||||
source: BitStamp.name,
|
source: BitStamp.name,
|
||||||
pair,
|
pair,
|
||||||
decimals: 2,
|
decimals: 0,
|
||||||
value: Math.floor(payload.data.price * 100),
|
value: payload.data.price,
|
||||||
}
|
}
|
||||||
|
|
||||||
return price
|
return price
|
||||||
|
@ -231,8 +234,8 @@ export class FTX extends PriceFeed {
|
||||||
const price: IPrice = {
|
const price: IPrice = {
|
||||||
source: FTX.name,
|
source: FTX.name,
|
||||||
pair,
|
pair,
|
||||||
decimals: 2,
|
decimals: 0,
|
||||||
value: Math.floor(payload.data.last * 100),
|
value: payload.data.last,
|
||||||
}
|
}
|
||||||
|
|
||||||
return price
|
return price
|
||||||
|
@ -276,12 +279,11 @@ export class Binance extends PriceFeed {
|
||||||
|
|
||||||
const pair = payload.s;
|
const pair = payload.s;
|
||||||
|
|
||||||
|
|
||||||
const price: IPrice = {
|
const price: IPrice = {
|
||||||
source: Binance.name,
|
source: Binance.name,
|
||||||
pair,
|
pair,
|
||||||
decimals: 2,
|
decimals: 0,
|
||||||
value: Math.floor(payload.p * 100),
|
value: payload.p,
|
||||||
}
|
}
|
||||||
|
|
||||||
return price
|
return price
|
||||||
|
@ -341,8 +343,8 @@ export class OKEx extends PriceFeed {
|
||||||
const price: IPrice = {
|
const price: IPrice = {
|
||||||
source: OKEx.name,
|
source: OKEx.name,
|
||||||
pair,
|
pair,
|
||||||
decimals: 2,
|
decimals: 0,
|
||||||
value: Math.floor(payload.data[0].last * 100),
|
value: payload.data[0].last,
|
||||||
}
|
}
|
||||||
|
|
||||||
return price
|
return price
|
||||||
|
@ -388,6 +390,7 @@ export class AggregatedFeed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
price.timestamp = Date.now()
|
price.timestamp = Date.now()
|
||||||
|
price.value = Math.floor(Math.pow(10, decimals - price.decimals) * price.value)
|
||||||
price.decimals = decimals;
|
price.decimals = decimals;
|
||||||
this.prices[index] = price
|
this.prices[index] = price
|
||||||
this.onPriceUpdate(price)
|
this.onPriceUpdate(price)
|
||||||
|
|
Loading…
Reference in New Issue