-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add uniswap3base exchange driver
- Loading branch information
1 parent
494d840
commit 6670882
Showing
3 changed files
with
1,743 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const Driver = require('../models/driver'); | ||
const request = require('../lib/request'); | ||
const Ticker = require('../models/ticker'); | ||
const { parseToFloat } = require('../lib/utils'); | ||
|
||
/** | ||
* @memberof Driver | ||
* @augments Driver | ||
*/ | ||
class Uniswap3base extends Driver { | ||
/** | ||
* @augments Driver.fetchTickers | ||
* @returns {Promise.Array<Ticker>} Returns a promise of an array with tickers. | ||
*/ | ||
async fetchTickers() { | ||
const { data } = await request('https://api.geckoterminal.com/api/v2/networks/base/dexes/uniswap-v3-base/pools?page=1&sort=h24_volume_usd_desc'); | ||
|
||
return Object.keys(data).map((market) => { | ||
const ticker = data[market]; | ||
const base = ticker.relationships.base_token.data.id.split('base_')[1]; | ||
const quote = ticker.relationships.quote_token.data.id.split('base_')[1]; | ||
|
||
const usdVolume = ticker.attributes.volume_usd.h24; | ||
const usdBasePrice = ticker.attributes.base_token_price_usd; | ||
const usdQuotePrice = ticker.attributes.base_token_price_usd; | ||
const baseVolume = usdVolume * usdBasePrice; | ||
const quoteVolume = usdVolume * usdQuotePrice; | ||
|
||
return new Ticker({ | ||
base, | ||
quote, | ||
close: parseToFloat(ticker.attributes.base_token_price_native_currency), | ||
baseVolume: parseToFloat(baseVolume), | ||
quoteVolume: parseToFloat(quoteVolume), | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Uniswap3base; |
Oops, something went wrong.