Skip to content

Commit 7427c56

Browse files
authored
Merge pull request #3306 from pyth-network/bduran/fix-runahead-bug
fix(insights hub): fixed run ahead bug by emitting data points in time-based order, regardless of their source
2 parents e1b61f1 + fac8803 commit 7427c56

File tree

12 files changed

+136
-290
lines changed

12 files changed

+136
-290
lines changed

apps/insights/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@
8787
"stylelint-config-standard-scss": "catalog:",
8888
"vercel": "catalog:"
8989
}
90-
}
90+
}
0 Bytes
Binary file not shown.

apps/insights/src/app/api/pyth/get-pyth-feeds-demo-data/[datasource]/[symbol]/route.ts renamed to apps/insights/src/app/api/pyth/get-pyth-feeds-demo-data/[symbol]/route.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NextRequest, NextResponse } from "next/server";
22

3-
import { fetchHistoricalDataForPythFeedsDemo } from "../../../../../../pyth-feed-demo-data/fetch-historical-data-from-db";
4-
import { GetPythFeedsDemoDataRequestSchema } from "../../../../../../schemas/pyth/pyth-pro-demo-schema";
3+
import { fetchHistoricalDataForPythFeedsDemo } from "../../../../../pyth-feed-demo-data/fetch-historical-data-from-db";
4+
import { GetPythFeedsDemoDataRequestSchema } from "../../../../../schemas/pyth/pyth-pro-demo-schema";
55

66
export const GET = async (
77
req: NextRequest,
@@ -11,28 +11,34 @@ export const GET = async (
1111
const {
1212
nextUrl: { searchParams },
1313
} = req;
14+
15+
const searchParamsToUse = {
16+
...Object.fromEntries(searchParams),
17+
datasources: searchParams.getAll("datasources[]"),
18+
};
19+
1420
const paramsAndQueryValidation = GetPythFeedsDemoDataRequestSchema.safeParse({
1521
params,
16-
searchParams: Object.fromEntries(searchParams),
22+
searchParams: searchParamsToUse,
1723
});
1824

1925
if (paramsAndQueryValidation.error) {
2026
return NextResponse.json(
2127
{
22-
error: paramsAndQueryValidation.error.message,
28+
error: paramsAndQueryValidation.error.format(),
2329
},
2430
{ status: 400 },
2531
);
2632
}
2733

2834
const {
29-
params: { datasource: datasourceToUse, symbol: symbolToUse },
30-
searchParams: { startAt },
35+
params: { symbol: symbolToUse },
36+
searchParams: { datasources, startAt },
3137
} = paramsAndQueryValidation.data;
3238

3339
try {
3440
const { data, hasNext } = await fetchHistoricalDataForPythFeedsDemo({
35-
datasource: datasourceToUse,
41+
datasources,
3642
startAt: startAt.toISOString(),
3743
symbol: symbolToUse,
3844
});

apps/insights/src/components/PythProDemoCards/price-card.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
datasourceRequiresApiToken,
1919
getColorForDataSource,
2020
isAllowedSymbol,
21+
isReplaySymbol,
2122
} from "../../util/pyth-pro-demo";
2223

2324
type PriceCardProps = {
@@ -102,7 +103,9 @@ export function PythProDemoCard({
102103
{socketStatus && (
103104
<div className={classes.socketStatus}>
104105
{/* the token is either missing or it's a bad token */}
105-
{requiresToken && (!apiToken || socketStatus === "closed") ? (
106+
{!isReplaySymbol(selectedSource) &&
107+
requiresToken &&
108+
(!apiToken || socketStatus === "closed") ? (
106109
<>
107110
Please enter a good API token
108111
<br />

apps/insights/src/components/PythProDemoPriceChart/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ export function PythProDemoPriceChartImpl({
188188
// data will track the price.
189189
// for market data, we just want to display the ask and bid
190190
const isPriceMetric = metricType === "price";
191-
const isNasdaq = dataSource === "nasdaq";
191+
const isNbbo = dataSource === "nbbo";
192192
const isPyth = dataSource === "pyth" || dataSource === "pyth_pro";
193-
if ((isNasdaq && isPriceMetric) || (isPyth && !isPriceMetric))
194-
continue;
193+
if ((isNbbo && isPriceMetric) || (isPyth && !isPriceMetric)) continue;
195194

196195
const latest = metrics[dataSource]?.latest;
197196
const symbolMetrics = latest?.[selectedSource];

apps/insights/src/context/pyth-pro-demo/pyth-pro-websockets-context.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export function WebSocketsProvider({ children }: PropsWithChildren) {
7272
// "Fake" websocket-like contract for easier integration
7373
const { status: replay_status } = useHttpDataStream({
7474
dataSources: [
75+
ALL_DATA_SOURCES.Values.nbbo,
7576
ALL_DATA_SOURCES.Values.pyth_pro,
76-
ALL_DATA_SOURCES.Values.nasdaq,
7777
],
7878
enabled: isGoodSymbol && isReplaySymbol(selectedSource),
7979
symbol: selectedSource,
@@ -87,10 +87,9 @@ export function WebSocketsProvider({ children }: PropsWithChildren) {
8787
bybit,
8888
coinbase,
8989
okx,
90-
nasdaq: replay_status,
90+
nbbo: replay_status,
9191
pyth,
9292
pyth_pro: isReplaySymbol(selectedSource) ? replay_status : pyth_pro,
93-
yahoo: "connected",
9493
},
9594
}),
9695
[

0 commit comments

Comments
 (0)