@@ -49,7 +49,12 @@ type DownloadOptions struct {
4949// DownloadPublicationMarketData downloads and decodes publication market data for the current and next day if needed.
5050// fetchNextDay indicates whether to also download data for the next day (e.g. when it is past 13:30).
5151// cache is an optional XMLDocumentCache; when non-nil, cached entries are returned instead of fetching from the network.
52- func DownloadPublicationMarketData (ctx context.Context , securityToken string , urlFormat string , location * time.Location , fetchNextDay bool , cache * XMLDocumentCache ) (* PublicationMarketData , error ) {
52+ //
53+ // The second return value reports whether the returned document already covers the next day.
54+ // It is false when fetchNextDay is true but ENTSO-E has not published tomorrow's prices yet,
55+ // which lets callers shorten their cache lifetime and retry soon instead of caching a
56+ // partial (today-only) document for the rest of the day.
57+ func DownloadPublicationMarketData (ctx context.Context , securityToken string , urlFormat string , location * time.Location , fetchNextDay bool , cache * XMLDocumentCache ) (* PublicationMarketData , bool , error ) {
5358
5459 now := time .Now ().In (location )
5560 client := NewAPIClient ()
@@ -74,7 +79,7 @@ func DownloadPublicationMarketData(ctx context.Context, securityToken string, ur
7479 var rawXML []byte
7580 marketDocument , rawXML , err = downloadWithTimeout (ctx , url , opts )
7681 if err != nil {
77- return nil , err
82+ return nil , false , err
7883 }
7984 if cache != nil {
8085 cache .StoreDocumentWithRaw (todayKey , marketDocument , rawXML , CacheSourceDownload )
@@ -106,7 +111,7 @@ func DownloadPublicationMarketData(ctx context.Context, securityToken string, ur
106111 fmt .Printf ("No market data published yet for %s: %v\n " , tomorrowKey , err )
107112 marketDocumentNextDay = nil
108113 } else {
109- return nil , err
114+ return nil , false , err
110115 }
111116 } else if cache != nil {
112117 cache .StoreDocumentWithRaw (tomorrowKey , marketDocumentNextDay , rawXMLNextDay , CacheSourceDownload )
@@ -118,7 +123,10 @@ func DownloadPublicationMarketData(ctx context.Context, securityToken string, ur
118123 marketDocument = mergePublicationMarketData (marketDocument , marketDocumentNextDay )
119124 }
120125
121- return marketDocument , nil
126+ // The result is complete unless the caller asked for the next day and it is still missing.
127+ nextDayIncluded := ! fetchNextDay || marketDocumentNextDay != nil
128+
129+ return marketDocument , nextDayIncluded , nil
122130}
123131
124132// requestTimeout bounds a single ENTSO-E API call. The Transparency Platform can be
0 commit comments