Skip to content

Commit ea3cf2a

Browse files
committed
feat: update available local data when a download is completed
1 parent 558538a commit ea3cf2a

File tree

3 files changed

+75
-59
lines changed

3 files changed

+75
-59
lines changed

.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* text=auto eol=lf
2+
3+
*.html text eol=lf
4+
*.ini text eol=lf
5+
*.js text eol=lf
6+
*.json text eol=lf
7+
*.md text eol=lf
8+
*.vue text eol=lf
9+
*.ts text eol=lf
10+
11+
*.ico binary
12+
*.png binary

stores/dataAvailabilityStore.ts

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
1-
export const useDataAvailabilityStore = defineStore('dataAvailability', () => {
2-
const manifest = ref<DataAvailabilityManifestItem[]>([]);
3-
const status = ref<LoadingStatus>('idle');
4-
const toast = useToast();
5-
6-
const isLoading = computed(() => status.value === 'loading');
7-
8-
async function fetchManifest() {
9-
if (manifest.value.length > 0) return;
10-
11-
status.value = 'loading';
12-
try {
13-
manifest.value = await $fetch<DataAvailabilityManifestItem[]>('/api/data-availability');
14-
status.value = 'success';
15-
} catch (e: any) {
16-
toast.add({
17-
title: 'Error Loading Market Data',
18-
description: e.data?.error || 'Could not connect to the API to get available market data.',
19-
color: 'error',
20-
icon: 'i-heroicons-exclamation-triangle',
21-
});
22-
console.error('Failed to fetch data availability manifest:', e);
23-
status.value = 'error';
24-
}
25-
}
26-
27-
const availableSymbols = computed(() => manifest.value.map(item => item.symbol).sort());
28-
29-
const getTimeframesForSymbol = (symbol: string | null): TimeframeData[] => {
30-
if (!symbol) return [];
31-
const symbolData = manifest.value.find(item => item.symbol === symbol);
32-
return symbolData?.timeframes ?? [];
33-
};
34-
35-
const getDateRangeFor = (symbol: string | null, timeframe: string | null): { min?: string, max?: string } => {
36-
if (!symbol || !timeframe) return {};
37-
38-
const symbolTimeframes = getTimeframesForSymbol(symbol);
39-
const timeframeData = symbolTimeframes.find(tf => tf.timeframe === timeframe);
40-
41-
if (!timeframeData) return {};
42-
43-
return {
44-
min: timeframeData.startDate.split('T')[0],
45-
max: timeframeData.endDate.split('T')[0],
46-
};
47-
};
48-
49-
50-
return {
51-
manifest,
52-
status,
53-
isLoading,
54-
fetchManifest,
55-
availableSymbols,
56-
getTimeframesForSymbol,
57-
getDateRangeFor,
58-
};
59-
});
1+
export const useDataAvailabilityStore = defineStore('dataAvailability', () => {
2+
const manifest = ref<DataAvailabilityManifestItem[]>([]);
3+
const status = ref<LoadingStatus>('idle');
4+
const toast = useToast();
5+
6+
const isLoading = computed(() => status.value === 'loading');
7+
8+
async function fetchManifest(force = false) {
9+
if (manifest.value.length > 0 && !force) return;
10+
11+
status.value = 'loading';
12+
try {
13+
manifest.value = await $fetch<DataAvailabilityManifestItem[]>('/api/data-availability');
14+
status.value = 'success';
15+
} catch (e: any) {
16+
toast.add({
17+
title: 'Error Loading Market Data',
18+
description: e.data?.error || 'Could not connect to the API to get available market data.',
19+
color: 'error',
20+
icon: 'i-heroicons-exclamation-triangle',
21+
});
22+
console.error('Failed to fetch data availability manifest:', e);
23+
status.value = 'error';
24+
}
25+
}
26+
27+
const availableSymbols = computed(() => manifest.value.map(item => item.symbol).sort());
28+
29+
const getTimeframesForSymbol = (symbol: string | null): TimeframeData[] => {
30+
if (!symbol) return [];
31+
const symbolData = manifest.value.find(item => item.symbol === symbol);
32+
return symbolData?.timeframes ?? [];
33+
};
34+
35+
const getDateRangeFor = (symbol: string | null, timeframe: string | null): { min?: string, max?: string } => {
36+
if (!symbol || !timeframe) return {};
37+
38+
const symbolTimeframes = getTimeframesForSymbol(symbol);
39+
const timeframeData = symbolTimeframes.find(tf => tf.timeframe === timeframe);
40+
41+
if (!timeframeData) return {};
42+
43+
return {
44+
min: timeframeData.startDate.split('T')[0],
45+
max: timeframeData.endDate.split('T')[0],
46+
};
47+
};
48+
49+
50+
return {
51+
manifest,
52+
status,
53+
isLoading,
54+
fetchManifest,
55+
availableSymbols,
56+
getTimeframesForSymbol,
57+
getDateRangeFor,
58+
};
59+
});

stores/dataDownloadStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const useDataDownloadStore = defineStore('dataDownload', () => {
22
const toast = useToast();
33
const { public: { apiUrl } } = useRuntimeConfig();
4+
const dataAvailabilityStore = useDataAvailabilityStore();
45

56
// --- State ---
67
const exchanges = ref<string[]>([]);
@@ -125,6 +126,7 @@ export const useDataDownloadStore = defineStore('dataDownload', () => {
125126
job.status = 'failed';
126127
job.message = e.data?.error || 'Failed to start download.';
127128
toast.add({ title: 'Download Error', description: job.message, color: 'error' });
129+
// Move to the next job even if this one fails to start
128130
downloadQueue.value.shift();
129131
processQueue();
130132
}
@@ -172,6 +174,7 @@ export const useDataDownloadStore = defineStore('dataDownload', () => {
172174
job.status = data.status;
173175
eventSource.close();
174176
downloadQueue.value.shift();
177+
dataAvailabilityStore.fetchManifest(true);
175178
processQueue();
176179
resolve();
177180
}
@@ -182,6 +185,7 @@ export const useDataDownloadStore = defineStore('dataDownload', () => {
182185
job.message = 'Connection to progress stream failed.';
183186
eventSource.close();
184187
downloadQueue.value.shift();
188+
dataAvailabilityStore.fetchManifest(true);
185189
processQueue();
186190
resolve();
187191
};

0 commit comments

Comments
 (0)