Skip to content

Commit 79037e2

Browse files
committed
Refresh persisted chart history
1 parent 18f7cc2 commit 79037e2

4 files changed

Lines changed: 69 additions & 4 deletions

File tree

src/sources/gloomberb-cloud/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { afterEach, describe, expect, test } from "bun:test";
22
import { createGloomberbCloudCapabilities, GloomberbCloudProvider } from "./index";
3+
import { getRangeStartDate, toHistoryRequest } from "./normalizers";
34
import type { NewsCapability } from "../../capabilities";
45
import { apiClient, type AuthUser, type CloudNewsPayload } from "../../api-client";
56

@@ -25,6 +26,17 @@ const originalGetCloudNews = apiClient.getCloudNews.bind(apiClient);
2526
const originalGetCloudNewsStory = apiClient.getCloudNewsStory.bind(apiClient);
2627
const originalSubscribeQuotes = apiClient.subscribeQuotes.bind(apiClient);
2728

29+
test("requests fifty years of cloud history for the ALL range", () => {
30+
const endDate = new Date("2026-07-30T20:00:00.000Z");
31+
32+
expect(getRangeStartDate("ALL", endDate).toISOString()).toBe("1976-07-30T20:00:00.000Z");
33+
expect(toHistoryRequest("ALL")).toEqual({
34+
interval: "1month",
35+
outputsize: 600,
36+
rangeKey: "ALL",
37+
});
38+
});
39+
2840
function makeCloudNewsPayload(overrides: Partial<CloudNewsPayload> = {}): CloudNewsPayload {
2941
return {
3042
id: "story-1",

src/sources/gloomberb-cloud/normalizers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export function getRangeStartDate(
326326
startDate.setFullYear(startDate.getFullYear() - 5);
327327
break;
328328
case "ALL":
329-
startDate.setFullYear(startDate.getFullYear() - 20);
329+
startDate.setFullYear(startDate.getFullYear() - 50);
330330
break;
331331
}
332332
return startDate;
@@ -353,7 +353,7 @@ export function toHistoryRequest(range: TimeRange): {
353353
case "5Y":
354354
return { interval: "1week", outputsize: 261, rangeKey: range };
355355
case "ALL":
356-
return { interval: "1month", outputsize: 240, rangeKey: range };
356+
return { interval: "1month", outputsize: 600, rangeKey: range };
357357
default:
358358
return { interval: "1day", outputsize: 366, rangeKey: range };
359359
}

src/sources/provider-router/history.test.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,59 @@ describe("AssetDataRouter chart history", () => {
135135
persistence.close();
136136
});
137137

138+
test("ignores the previous chart history cache generation", async () => {
139+
const dbPath = createTempDbPath("previous-chart-cache-generation");
140+
const persistence = new AppPersistence(dbPath);
141+
const latestDate = new Date(Date.now() - 60_000);
142+
const previousDate = new Date(latestDate.getTime() - 5 * 60_000);
143+
144+
persistence.resources.set(
145+
{
146+
namespace: "market",
147+
kind: "price-history",
148+
entityKey: "META",
149+
variantKey: "exchange=NASDAQ;range=1M;resolution=5m;version=2",
150+
sourceKey: "provider:gloomberb-cloud",
151+
},
152+
[
153+
{ date: previousDate, close: 620 },
154+
{ date: latestDate, close: 680 },
155+
],
156+
{
157+
cachePolicy: { staleMs: 60_000, expireMs: 60_000 },
158+
},
159+
);
160+
161+
let providerCalls = 0;
162+
const router = new AssetDataRouter({
163+
...fallbackProvider,
164+
id: "gloomberb-cloud",
165+
name: "Gloomberb Cloud",
166+
async getPriceHistoryForResolution() {
167+
providerCalls += 1;
168+
return [
169+
{ date: previousDate, close: 620 },
170+
{ date: latestDate, close: 560 },
171+
];
172+
},
173+
}, [], persistence.resources);
174+
175+
const history = await router.getPriceHistoryForResolution("META", "NASDAQ", "1M", "5m");
176+
177+
expect(providerCalls).toBe(1);
178+
expect(history.map((point) => point.close)).toEqual([620, 560]);
179+
180+
const cachedRows = persistence.database.connection
181+
.query("SELECT variant_key FROM resource_cache WHERE namespace = ? AND kind = ? AND entity_key = ? ORDER BY variant_key")
182+
.all("market", "price-history", "META") as Array<{ variant_key: string }>;
183+
expect(cachedRows.map((row) => row.variant_key)).toEqual([
184+
"exchange=NASDAQ;range=1M;resolution=5m;version=2",
185+
"exchange=NASDAQ;range=1M;resolution=5m;version=3",
186+
]);
187+
188+
persistence.close();
189+
});
190+
138191
test("ignores legacy unversioned sub-unit chart history caches", async () => {
139192
const dbPath = createTempDbPath("subunit-chart-cache");
140193
const persistence = new AppPersistence(dbPath);
@@ -180,7 +233,7 @@ describe("AssetDataRouter chart history", () => {
180233
.all("market", "price-history", "FTC") as Array<{ variant_key: string }>;
181234
expect(cachedRows.map((row) => row.variant_key)).toEqual([
182235
"exchange=LSE;range=ALL;resolution=1wk",
183-
"exchange=LSE;range=ALL;resolution=1wk;version=2;unit=GBP",
236+
"exchange=LSE;range=ALL;resolution=1wk;version=3;unit=GBP",
184237
]);
185238

186239
persistence.close();

src/sources/provider-router/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type PriceHistoryCachePolicyKey = Extract<
2929
ProviderRouterCachePolicyKey,
3030
"priceHistoryIntraday" | "priceHistoryDaily"
3131
>;
32-
const PRICE_HISTORY_CACHE_VERSION = 2;
32+
const PRICE_HISTORY_CACHE_VERSION = 3;
3333

3434
interface HistoryRequestDescriptor {
3535
identity: RouterRequestIdentity;

0 commit comments

Comments
 (0)