mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 23:29:58 -07:00
general: snapshot
This commit is contained in:
40
app/src/scripts/datasets/base.ts
Normal file
40
app/src/scripts/datasets/base.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { createResourceDataset } from "./resource";
|
||||
|
||||
export { averages } from "./consts/averages";
|
||||
|
||||
export function createScaleDatasets<Scale extends ResourceScale>({
|
||||
scale,
|
||||
setActiveResources,
|
||||
groupedKeysToURLPath,
|
||||
}: {
|
||||
scale: Scale;
|
||||
setActiveResources: Setter<Set<ResourceDataset<any, any>>>;
|
||||
groupedKeysToURLPath: GroupedKeysToURLPath[Scale];
|
||||
}) {
|
||||
type Key = keyof typeof groupedKeysToURLPath;
|
||||
type ResourceData = ReturnType<typeof createResourceDataset<Scale>>;
|
||||
|
||||
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
|
||||
|
||||
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
|
||||
|
||||
for (const key in groupedKeysToURLPath) {
|
||||
if ((key as Key) !== "ohlc") {
|
||||
datasets[key as unknown as Exclude<Key, "ohlc">] = createResourceDataset({
|
||||
scale,
|
||||
path: groupedKeysToURLPath[key as Key] as any,
|
||||
setActiveResources,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const price = createResourceDataset<Scale, OHLC>({
|
||||
scale,
|
||||
path: `/${scale}-to-ohlc`,
|
||||
setActiveResources,
|
||||
});
|
||||
|
||||
Object.assign(datasets, { price });
|
||||
|
||||
return datasets;
|
||||
}
|
||||
@@ -14,33 +14,27 @@ export function createDateDatasets({
|
||||
|
||||
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
|
||||
|
||||
for (const _key in groupedKeysToURLPath) {
|
||||
const key = _key as Key;
|
||||
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
|
||||
|
||||
if (key !== "ohlc") {
|
||||
const path = groupedKeysToURLPath[key];
|
||||
|
||||
(groupedKeysToURLPath as any as ResourceDatasets)[key] =
|
||||
createResourceDataset<"date">({
|
||||
scale: "date",
|
||||
path,
|
||||
setActiveResources,
|
||||
});
|
||||
for (const key in groupedKeysToURLPath) {
|
||||
if ((key as Key) !== "ohlc") {
|
||||
datasets[key as Exclude<Key, "ohlc">] = createResourceDataset<"date">({
|
||||
scale: "date",
|
||||
path: groupedKeysToURLPath[key as Key],
|
||||
setActiveResources,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const resourceDatasets = groupedKeysToURLPath as any as ResourceDatasets;
|
||||
|
||||
const price = createResourceDataset<"date", OHLC>({
|
||||
scale: "date",
|
||||
path: "/date-to-ohlc",
|
||||
setActiveResources,
|
||||
});
|
||||
|
||||
const datasets = {
|
||||
price,
|
||||
...resourceDatasets,
|
||||
};
|
||||
Object.assign(datasets, { price });
|
||||
|
||||
return datasets;
|
||||
return datasets as ResourceDatasets & {
|
||||
price: ResourceDataset<"date", OHLC>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,31 +12,27 @@ export function createHeightDatasets({
|
||||
|
||||
type ResourceDatasets = Record<Exclude<Key, "ohlc">, ResourceData>;
|
||||
|
||||
for (const _key in groupedKeysToURLPath) {
|
||||
const key = _key as Key;
|
||||
const datasets = groupedKeysToURLPath as any as ResourceDatasets;
|
||||
|
||||
if (key !== "ohlc") {
|
||||
const path = groupedKeysToURLPath[key];
|
||||
|
||||
(groupedKeysToURLPath as any as ResourceDatasets)[key] =
|
||||
createResourceDataset<"height">({
|
||||
scale: "height",
|
||||
path,
|
||||
setActiveResources,
|
||||
});
|
||||
for (const key in groupedKeysToURLPath) {
|
||||
if ((key as Key) !== "ohlc") {
|
||||
datasets[key as Exclude<Key, "ohlc">] = createResourceDataset<"height">({
|
||||
scale: "height",
|
||||
path: groupedKeysToURLPath[key as Key],
|
||||
setActiveResources,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const resourceDatasets = groupedKeysToURLPath as any as ResourceDatasets;
|
||||
|
||||
const price = createResourceDataset<"height", OHLC>({
|
||||
scale: "height",
|
||||
path: "/height-to-ohlc",
|
||||
setActiveResources,
|
||||
});
|
||||
|
||||
return {
|
||||
...resourceDatasets,
|
||||
price,
|
||||
Object.assign(datasets, { price });
|
||||
|
||||
return datasets as ResourceDatasets & {
|
||||
price: ResourceDataset<"height", OHLC>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,13 +21,6 @@ export function createResourceDataset<
|
||||
path: string;
|
||||
setActiveResources: Setter<Set<ResourceDataset<any, any>>>;
|
||||
}) {
|
||||
const baseURL = `${
|
||||
// location.hostname === "localhost"
|
||||
// ? "http://localhost:3110"
|
||||
// : "https://api.satonomics.xyz"
|
||||
"https://api.satonomics.xyz"
|
||||
}${path}`;
|
||||
|
||||
type Dataset = Scale extends "date"
|
||||
? FetchedDateDataset<Type>
|
||||
: FetchedHeightDataset<Type>;
|
||||
@@ -36,6 +29,13 @@ export function createResourceDataset<
|
||||
Type extends number ? SingleValueData : CandlestickData
|
||||
>;
|
||||
|
||||
const baseURL = `${
|
||||
// location.hostname === "localhost"
|
||||
// ? "http://localhost:3110"
|
||||
// : "https://api.satonomics.xyz"
|
||||
"https://api.satonomics.xyz"
|
||||
}${path}`;
|
||||
|
||||
const fetchedJSONs = new Array(
|
||||
(new Date().getFullYear() - new Date("2009-01-01").getFullYear() + 2) *
|
||||
(scale === "date" ? 1 : 6),
|
||||
@@ -51,12 +51,12 @@ export function createResourceDataset<
|
||||
vec: createMemo(() => {
|
||||
const map = json()?.dataset.map || null;
|
||||
|
||||
const chunkId = json()?.chunk.id!;
|
||||
|
||||
if (!map) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const chunkId = json()?.chunk.id!;
|
||||
|
||||
if (Array.isArray(map)) {
|
||||
return map.map(
|
||||
(value, index) =>
|
||||
|
||||
@@ -40,6 +40,9 @@ export function createChart(scale: ResourceScale) {
|
||||
shiftVisibleRangeOnNewBar: false,
|
||||
allowShiftVisibleRangeOnWhitespaceReplacement: false,
|
||||
},
|
||||
handleScale: {
|
||||
axisDoubleClickReset: false,
|
||||
},
|
||||
crosshair: {
|
||||
mode: CrosshairMode.Normal,
|
||||
horzLine: {
|
||||
|
||||
@@ -34,9 +34,9 @@ export const applyPriceSeries = <
|
||||
const id = options?.id || "price";
|
||||
const title = options?.title || "Price";
|
||||
|
||||
const dataset = createMemo(() => _dataset || datasets[preset.scale].price);
|
||||
const dataset = _dataset || datasets[preset.scale].price;
|
||||
|
||||
const url = "url" in dataset() ? (dataset() as any).url : undefined;
|
||||
const url = "url" in dataset ? (dataset as any).url : undefined;
|
||||
|
||||
const priceScaleOptions: DeepPartial<PriceScaleOptions> = {
|
||||
...(options?.halved
|
||||
@@ -51,7 +51,6 @@ export const applyPriceSeries = <
|
||||
? {}
|
||||
: {
|
||||
mode: 1,
|
||||
// mode: PriceScaleMode.Logarithmic,
|
||||
}),
|
||||
...options?.priceScaleOptions,
|
||||
};
|
||||
@@ -139,9 +138,12 @@ export const applyPriceSeries = <
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
const d = dataset();
|
||||
lineSeries.setData(d.values());
|
||||
ohlcSeries.setData(d.values());
|
||||
const values = dataset.values();
|
||||
|
||||
if (values) {
|
||||
lineSeries.setData(values);
|
||||
ohlcSeries.setData(values);
|
||||
}
|
||||
});
|
||||
|
||||
createEffect(() => {
|
||||
|
||||
5
app/src/scripts/utils/tick.ts
Normal file
5
app/src/scripts/utils/tick.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function tick() {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user