use aggregated cex median in PriceFeeder
This commit is contained in:
parent
51932068d0
commit
e36d977e40
|
@ -2,7 +2,14 @@ import fs from "fs"
|
||||||
import { Wallet } from "solray"
|
import { Wallet } from "solray"
|
||||||
import { AggregatorDeployFile } from "./Deployer"
|
import { AggregatorDeployFile } from "./Deployer"
|
||||||
import { loadJSONFile } from "./json"
|
import { loadJSONFile } from "./json"
|
||||||
import { coinbase } from "./feeds"
|
import {
|
||||||
|
AggregatedFeed,
|
||||||
|
BitStamp,
|
||||||
|
CoinBase,
|
||||||
|
coinbase,
|
||||||
|
FTX,
|
||||||
|
PriceFeed,
|
||||||
|
} from "./feeds"
|
||||||
import { Submitter, SubmitterConfig } from "./Submitter"
|
import { Submitter, SubmitterConfig } from "./Submitter"
|
||||||
import { log } from "./log"
|
import { log } from "./log"
|
||||||
import { conn } from "./context"
|
import { conn } from "./context"
|
||||||
|
@ -10,12 +17,21 @@ import { conn } from "./context"
|
||||||
// Look at all the available aggregators and submit to those that the wallet can
|
// Look at all the available aggregators and submit to those that the wallet can
|
||||||
// act as an oracle.
|
// act as an oracle.
|
||||||
export class PriceFeeder {
|
export class PriceFeeder {
|
||||||
|
private feeds: PriceFeed[]
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private deployInfo: AggregatorDeployFile,
|
private deployInfo: AggregatorDeployFile,
|
||||||
private wallet: Wallet
|
private wallet: Wallet
|
||||||
) {}
|
) {
|
||||||
|
this.feeds = [new CoinBase(), new BitStamp(), new FTX()]
|
||||||
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
|
// connect to the price feeds
|
||||||
|
for (const feed of this.feeds) {
|
||||||
|
feed.connect()
|
||||||
|
}
|
||||||
|
|
||||||
// find aggregators that this wallet can act as oracle
|
// find aggregators that this wallet can act as oracle
|
||||||
this.startAccessibleAggregators()
|
this.startAccessibleAggregators()
|
||||||
}
|
}
|
||||||
|
@ -40,7 +56,10 @@ export class PriceFeeder {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const priceFeed = coinbase(name)
|
const feed = new AggregatedFeed(this.feeds, name)
|
||||||
|
const priceFeed = feed.medians()
|
||||||
|
// const priceFeed = coinbase(name)
|
||||||
|
|
||||||
const submitter = new Submitter(
|
const submitter = new Submitter(
|
||||||
this.deployInfo.programID,
|
this.deployInfo.programID,
|
||||||
aggregatorInfo.pubkey,
|
aggregatorInfo.pubkey,
|
||||||
|
|
|
@ -296,13 +296,16 @@ export class AggregatedFeed {
|
||||||
this.emitter.emit(UPDATE, this)
|
this.emitter.emit(UPDATE, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
async* medians() {
|
async *medians() {
|
||||||
for await (let _ of this.updates()) {
|
for await (let _ of this.updates()) {
|
||||||
yield this.median
|
const price = this.median
|
||||||
|
if (price) {
|
||||||
|
yield price
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async* updates() {
|
async *updates() {
|
||||||
for await (let _ of eventsIter<AggregatedFeed>(this.emitter, "UPDATE")) {
|
for await (let _ of eventsIter<AggregatedFeed>(this.emitter, "UPDATE")) {
|
||||||
yield this
|
yield this
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue