added Binance feed
This commit is contained in:
parent
8b805a4961
commit
27959f873f
|
@ -25,6 +25,32 @@
|
|||
"blockworks",
|
||||
"bonafida"
|
||||
]
|
||||
},
|
||||
"sol:usd": {
|
||||
"decimals": 2,
|
||||
"minSubmissions": 1,
|
||||
"maxSubmissions": 3,
|
||||
"restartDelay": 0,
|
||||
"rewardAmount": 10000,
|
||||
"rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1",
|
||||
"oracles": [
|
||||
"solink",
|
||||
"blockworks",
|
||||
"bonafida"
|
||||
]
|
||||
},
|
||||
"srm:usd": {
|
||||
"decimals": 2,
|
||||
"minSubmissions": 1,
|
||||
"maxSubmissions": 3,
|
||||
"restartDelay": 0,
|
||||
"rewardAmount": 10000,
|
||||
"rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1",
|
||||
"oracles": [
|
||||
"solink",
|
||||
"blockworks",
|
||||
"bonafida"
|
||||
]
|
||||
}
|
||||
},
|
||||
"oracles": {
|
||||
|
@ -38,4 +64,4 @@
|
|||
"owner": "5tTHnk3YjZuPUKUKAXR9PoAPhbLRCyy7AthLLZUTKpUX"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,28 @@
|
|||
"oracles": [
|
||||
"tester"
|
||||
]
|
||||
},
|
||||
"sol:usd": {
|
||||
"decimals": 2,
|
||||
"minSubmissions": 1,
|
||||
"maxSubmissions": 3,
|
||||
"restartDelay": 0,
|
||||
"rewardAmount": 10000,
|
||||
"rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1",
|
||||
"oracles": [
|
||||
"tester"
|
||||
]
|
||||
},
|
||||
"srm:usd": {
|
||||
"decimals": 2,
|
||||
"minSubmissions": 1,
|
||||
"maxSubmissions": 3,
|
||||
"restartDelay": 0,
|
||||
"rewardAmount": 10000,
|
||||
"rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1",
|
||||
"oracles": [
|
||||
"tester"
|
||||
]
|
||||
}
|
||||
},
|
||||
"oracles": {
|
||||
|
@ -28,4 +50,4 @@
|
|||
"owner": "9QYPHz91uGZMSueGBhtxmy17L4ynJoWXdTE7mU21kizc"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,28 @@
|
|||
"oracles": [
|
||||
"tester"
|
||||
]
|
||||
},
|
||||
"sol:usd": {
|
||||
"decimals": 2,
|
||||
"minSubmissions": 1,
|
||||
"maxSubmissions": 3,
|
||||
"restartDelay": 0,
|
||||
"rewardAmount": 10000,
|
||||
"rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1",
|
||||
"oracles": [
|
||||
"tester"
|
||||
]
|
||||
},
|
||||
"srm:usd": {
|
||||
"decimals": 2,
|
||||
"minSubmissions": 1,
|
||||
"maxSubmissions": 3,
|
||||
"restartDelay": 0,
|
||||
"rewardAmount": 10000,
|
||||
"rewardTokenAccount": "3oLHHTaRqNsuTMjsTtkVy8bock6Bx8gCmDxku4TurVj1",
|
||||
"oracles": [
|
||||
"tester"
|
||||
]
|
||||
}
|
||||
},
|
||||
"oracles": {
|
||||
|
@ -28,4 +50,4 @@
|
|||
"owner": "FosLwbttPgkEDv36VJLU3wwXcBSSoUGkh7dyZPsXNtT4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
CoinBase,
|
||||
coinbase,
|
||||
FTX,
|
||||
Binance,
|
||||
PriceFeed,
|
||||
} from "./feeds"
|
||||
import { Submitter, SubmitterConfig } from "./Submitter"
|
||||
|
@ -23,7 +24,7 @@ export class PriceFeeder {
|
|||
private deployInfo: AggregatorDeployFile,
|
||||
private wallet: Wallet
|
||||
) {
|
||||
this.feeds = [new CoinBase(), new BitStamp(), new FTX()]
|
||||
this.feeds = [new CoinBase(), new BitStamp(), new FTX(), new Binance()]
|
||||
}
|
||||
|
||||
async start() {
|
||||
|
@ -64,6 +65,10 @@ export class PriceFeeder {
|
|||
minValueChangeForNewRound = 5000
|
||||
} else if (name === "eth:usd") {
|
||||
minValueChangeForNewRound = 150
|
||||
} else if (name === "sol:usd") {
|
||||
minValueChangeForNewRound = 10
|
||||
} else if (name === "srm:usd") {
|
||||
minValueChangeForNewRound = 10
|
||||
}
|
||||
|
||||
const submitter = new Submitter(
|
||||
|
|
56
src/feeds.ts
56
src/feeds.ts
|
@ -126,7 +126,7 @@ export class BitStamp extends PriceFeed {
|
|||
|
||||
const channel = (payload.channel as string).replace("live_trades_", "")
|
||||
|
||||
// assume that the symbols for the pair are 3 letters
|
||||
// assume that the base symbol for the pair is 3 letters
|
||||
const pair = channel.slice(0, 3) + ":" + channel.slice(3)
|
||||
|
||||
const price: IPrice = {
|
||||
|
@ -261,6 +261,60 @@ export class CoinBase extends PriceFeed {
|
|||
}
|
||||
}
|
||||
|
||||
export class Binance extends PriceFeed {
|
||||
protected log = log.child({ class: Binance.name })
|
||||
protected baseurl = "wss://stream.binance.com/ws"
|
||||
|
||||
parseMessage(data) {
|
||||
const payload = JSON.parse(data)
|
||||
|
||||
// {
|
||||
// "e": "trade", // Event type
|
||||
// "E": 123456789, // Event time
|
||||
// "s": "BNBBTC", // Symbol
|
||||
// "t": 12345, // Trade ID
|
||||
// "p": "0.001", // Price
|
||||
// "q": "100", // Quantity
|
||||
// "b": 88, // Buyer order ID
|
||||
// "a": 50, // Seller order ID
|
||||
// "T": 123456785, // Trade time
|
||||
// "m": true, // Is the buyer the market maker?
|
||||
// "M": true // Ignore
|
||||
// }
|
||||
|
||||
if (payload.e != "trade") {
|
||||
return
|
||||
}
|
||||
|
||||
// assume that the base symbol for the pair is 3 letters
|
||||
const pair = (payload.s.slice(0, 3) + ":" + payload.s.slice(3)).toLowerCase()
|
||||
|
||||
const price: IPrice = {
|
||||
source: Binance.name,
|
||||
pair,
|
||||
decimals: 2,
|
||||
value: Math.floor(payload.p * 100),
|
||||
}
|
||||
|
||||
return price
|
||||
}
|
||||
|
||||
async handleSubscribe(pair: string) {
|
||||
// "btc:usd" => "btcusdt"
|
||||
const [baseCurrency, quoteCurrency] = pair.split(':')
|
||||
const targetPair = `${baseCurrency}${(quoteCurrency.toLowerCase() === 'usd' ? 'usdt' : quoteCurrency)}@trade`.toLowerCase()
|
||||
this.conn.send(
|
||||
JSON.stringify({
|
||||
method: "SUBSCRIBE",
|
||||
params: [
|
||||
targetPair,
|
||||
],
|
||||
id: 1
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export class AggregatedFeed {
|
||||
public emitter = new EventEmitter()
|
||||
public prices: IPrice[] = []
|
||||
|
|
Loading…
Reference in New Issue