@@ -195,9 +195,14 @@ export async function syncPastDaysNewerPrices (): Promise<void> {
195195
196196 console . log ( `[PRICES] Found ${ missingXECDays . length } missing XEC days and ${ missingBCHDays . length } missing BCH days. Fetching from API...` )
197197
198+ const failedDays : string [ ] = [ ]
199+
198200 const allXECPrices = missingXECDays . length > 0 ? await getAllPricesByNetworkTicker ( NETWORK_TICKERS . ecash , false ) : null
199201 const allBCHPrices = missingBCHDays . length > 0 ? await getAllPricesByNetworkTicker ( NETWORK_TICKERS . bitcoincash , false ) : null
200202
203+ const xecBulkDays = new Set ( allXECPrices ?. map ( p => p . day ) ?? [ ] )
204+ const bchBulkDays = new Set ( allBCHPrices ?. map ( p => p . day ) ?? [ ] )
205+
201206 if ( allXECPrices !== null ) {
202207 const missingDaySet = new Set ( missingXECDays . map ( d => d . formatted ) )
203208 await Promise . all (
@@ -216,7 +221,38 @@ export async function syncPastDaysNewerPrices (): Promise<void> {
216221 )
217222 }
218223
219- console . log ( '[PRICES] All missing prices have been synced.' )
224+ const xecStillMissing = missingXECDays . filter ( d => ! xecBulkDays . has ( d . formatted ) )
225+ const bchStillMissing = missingBCHDays . filter ( d => ! bchBulkDays . has ( d . formatted ) )
226+
227+ for ( const day of xecStillMissing ) {
228+ const price = await withRetries (
229+ async ( ) => await getPriceForDayAndNetworkTicker ( moment . utc ( day . formatted ) , NETWORK_TICKERS . ecash ) ,
230+ { throwOnFailure : false , context : { day : day . formatted , network : 'XEC' } }
231+ )
232+ if ( price !== null ) {
233+ await upsertPricesForNetworkId ( price , XEC_NETWORK_ID , day . timestamp )
234+ } else {
235+ failedDays . push ( `XEC ${ day . formatted } ` )
236+ }
237+ }
238+
239+ for ( const day of bchStillMissing ) {
240+ const price = await withRetries (
241+ async ( ) => await getPriceForDayAndNetworkTicker ( moment . utc ( day . formatted ) , NETWORK_TICKERS . bitcoincash ) ,
242+ { throwOnFailure : false , context : { day : day . formatted , network : 'BCH' } }
243+ )
244+ if ( price !== null ) {
245+ await upsertPricesForNetworkId ( price , BCH_NETWORK_ID , day . timestamp )
246+ } else {
247+ failedDays . push ( `BCH ${ day . formatted } ` )
248+ }
249+ }
250+
251+ if ( failedDays . length > 0 ) {
252+ console . warn ( `[PRICES] Could not fetch prices for: ${ failedDays . join ( ', ' ) } ` )
253+ } else {
254+ console . log ( '[PRICES] All missing prices have been synced.' )
255+ }
220256}
221257
222258export async function syncCurrentPrices ( ) : Promise < void > {
0 commit comments