File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 88 ratesV2 ,
99 rateV2 ,
1010 sendCoinrankAssetV2 ,
11+ sendCoinrankListV2 ,
1112 sendCoinranksV2
1213} from './legacyRouter'
1314import { heartbeatV3 , ratesV3 } from './router'
@@ -23,6 +24,7 @@ function server(): void {
2324 '/v2/exchangeRates' : pickMethod ( { POST : ratesV2 } ) ,
2425 '/v2/coinrank' : pickMethod ( { GET : sendCoinranksV2 } ) ,
2526 '/v2/coinrankAsset/([^/]+)' : pickMethod ( { GET : sendCoinrankAssetV2 } ) ,
27+ '/v2/coinrankList' : pickMethod ( { GET : sendCoinrankListV2 } ) ,
2628 '/v3/rates' : pickMethod ( { POST : ratesV3 } )
2729 } )
2830
Original file line number Diff line number Diff line change 88 type CoinrankAssetReq ,
99 type CoinrankReq
1010} from '../types'
11+ import { hgetallAsync } from '../utils/dbUtils'
1112import { ratesV3 , v2CurrencyCodeMapSyncDoc } from './router'
1213import { asGetRatesParams } from './types'
1314import { convertV2 , convertV3ToV2 } from './v2converter'
@@ -214,3 +215,22 @@ export const sendCoinrankAssetV2 = async (
214215 }
215216 }
216217}
218+
219+ export const sendCoinrankListV2 = async (
220+ request : ExpressRequest
221+ ) : Promise < HttpResponse > => {
222+ try {
223+ const data = await hgetallAsync ( 'coingeckoassets' )
224+ return {
225+ status : 200 ,
226+ headers : { 'content-type' : 'application/json' } ,
227+ body : JSON . stringify ( { data } )
228+ }
229+ } catch ( e : unknown ) {
230+ return {
231+ status : 500 ,
232+ headers : { 'content-type' : 'application/json' } ,
233+ body : JSON . stringify ( { error : `Internal server error ${ String ( e ) } ` } )
234+ }
235+ }
236+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ import { asCouchDoc, syncedDocument } from 'edge-server-tools'
33
44import { coinrankEngine } from '../../../coinrankEngine'
55import { config } from '../../../config'
6+ import { coingeckoAssetsInternal } from '../../../providers/coingecko'
7+ import type { AssetMap } from '../../../rates'
8+ import { hsetAsync } from '../../../utils/dbUtils'
69import { dateOnly , snooze } from '../../../utils/utils'
710import { TOKEN_TYPES_KEY } from '../../constants'
811import {
@@ -289,6 +292,17 @@ const getHistoricalRates = async (
289292 return out
290293}
291294
295+ const coingeckoAssetsEngine : RateEngine = async ( ) => {
296+ const assets = await coingeckoAssetsInternal ( 3000 )
297+ const assetMap : AssetMap = { }
298+ for ( const asset of assets ) {
299+ const currencyCode = asset . symbol . toUpperCase ( )
300+ const { id } = asset
301+ assetMap [ currencyCode ] ??= id
302+ }
303+ await hsetAsync ( 'coingeckoassets' , assetMap )
304+ }
305+
292306export const coingecko : RateProvider = {
293307 providerId : 'coingecko' ,
294308 type : 'api' ,
@@ -362,6 +376,10 @@ export const coingecko: RateProvider = {
362376 engine : async ( ) => {
363377 await coinrankEngine ( true )
364378 }
379+ } ,
380+ {
381+ frequency : 'day' ,
382+ engine : coingeckoAssetsEngine
365383 }
366384 ]
367385}
You can’t perform that action at this time.
0 commit comments