mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-26 09:44:45 -07:00
kibo: part 1
This commit is contained in:
@@ -1518,7 +1518,6 @@
|
||||
"
|
||||
>希望</small
|
||||
>
|
||||
希望.お金
|
||||
</a>
|
||||
<small style="display: block">
|
||||
<strong>Bitcoin</strong> is
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
* @import { DeepPartial, ChartOptions, IChartApi, IHorzScaleBehavior, WhitespaceData, SingleValueData, ISeriesApi, Time, LogicalRange, SeriesType, BaselineStyleOptions, SeriesOptionsCommon, createChart as CreateClassicChart, createChartEx as CreateCustomChart } from "./v4.2.2/types"
|
||||
*/
|
||||
|
||||
const ids = {
|
||||
from: "from",
|
||||
to: "to",
|
||||
chartRange: "chart-range",
|
||||
/**
|
||||
* @param {TimeScale} scale
|
||||
*/
|
||||
visibleTimeRange(scale) {
|
||||
return `${ids.chartRange}-${scale}`;
|
||||
},
|
||||
};
|
||||
|
||||
export default import("./v4.2.2/script.js").then((lightweightCharts) => {
|
||||
const ids = {
|
||||
from: "from",
|
||||
to: "to",
|
||||
chartRange: "chart-range",
|
||||
/**
|
||||
* @param {TimeScale} scale
|
||||
*/
|
||||
visibleTimeRange(scale) {
|
||||
return `${ids.chartRange}-${scale}`;
|
||||
},
|
||||
};
|
||||
|
||||
const createClassicChart = /** @type {CreateClassicChart} */ (
|
||||
lightweightCharts.createChart
|
||||
);
|
||||
@@ -357,6 +357,7 @@ export default import("./v4.2.2/script.js").then((lightweightCharts) => {
|
||||
* @param {TimeScale} param0.scale
|
||||
* @param {"static" | "moveable"} param0.kind
|
||||
* @param {Utilities} param0.utils
|
||||
* @param {Constants} param0.consts
|
||||
* @param {Owner | null} [param0.owner]
|
||||
* @param {CreatePaneParameters[]} [param0.config]
|
||||
*/
|
||||
@@ -368,6 +369,7 @@ export default import("./v4.2.2/script.js").then((lightweightCharts) => {
|
||||
kind,
|
||||
scale,
|
||||
config,
|
||||
consts,
|
||||
utils,
|
||||
owner: _owner,
|
||||
}) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
* @param {Datasets} args.datasets
|
||||
* @param {Constants} args.consts
|
||||
* @param {WebSockets} args.webSockets
|
||||
* @param {Elements} args.elements
|
||||
*/
|
||||
@@ -19,6 +20,7 @@ export function init({
|
||||
selected,
|
||||
signals,
|
||||
utils,
|
||||
consts,
|
||||
webSockets,
|
||||
}) {
|
||||
console.log("init chart state");
|
||||
@@ -43,6 +45,7 @@ export function init({
|
||||
id: "chart",
|
||||
scale: scale(),
|
||||
kind: "moveable",
|
||||
consts,
|
||||
utils,
|
||||
});
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Colors} args.colors
|
||||
* @param {Consts} args.consts
|
||||
* @param {Constants} args.consts
|
||||
* @param {LightweightCharts} args.lightweightCharts
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {Colors} args.colors
|
||||
* @param {Consts} args.consts
|
||||
* @param {Constants} args.consts
|
||||
* @param {Signals} args.signals
|
||||
* @param {Utilities} args.utils
|
||||
* @param {Options} args.options
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
* @import {AnySpecificSeriesBlueprint, SplitSeriesBlueprint} from '../packages/lightweight-charts/types';
|
||||
*/
|
||||
|
||||
const DATE_TO_PREFIX = "date-to-";
|
||||
const HEIGHT_TO_PREFIX = "height-to-";
|
||||
|
||||
function initGroups() {
|
||||
const xTermHolders = /** @type {const} */ ([
|
||||
{
|
||||
@@ -5204,8 +5201,8 @@ export function initOptions({
|
||||
if (!blueprint) return undefined;
|
||||
|
||||
const id = blueprint.datasetPath
|
||||
.replace(DATE_TO_PREFIX, "")
|
||||
.replace(HEIGHT_TO_PREFIX, "");
|
||||
.replace("date-to-", "")
|
||||
.replace("height-to-", "");
|
||||
|
||||
return /** @type {LastPath} */ (id);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* @param {Utilities} args.utils
|
||||
* @param {Datasets} args.datasets
|
||||
* @param {Elements} args.elements
|
||||
* @param {Constants} args.consts
|
||||
* @param {Signal<LastValues>} args.lastValues
|
||||
*/
|
||||
export function init({
|
||||
@@ -22,6 +23,7 @@ export function init({
|
||||
lightweightCharts,
|
||||
signals,
|
||||
utils,
|
||||
consts,
|
||||
lastValues,
|
||||
}) {
|
||||
const simulationElement = elements.simulation;
|
||||
@@ -31,6 +33,120 @@ export function init({
|
||||
const resultsElement = window.document.createElement("div");
|
||||
simulationElement.append(resultsElement);
|
||||
|
||||
function computeFrequencies() {
|
||||
const weekDays = [
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
"Sunday",
|
||||
];
|
||||
const maxDays = 28;
|
||||
|
||||
/** @param {number} day */
|
||||
function getOrdinalDay(day) {
|
||||
const rest = (day % 30) % 20;
|
||||
|
||||
return `${day}${
|
||||
rest === 1 ? "st" : rest === 2 ? "nd" : rest === 3 ? "rd" : "th"
|
||||
}`;
|
||||
}
|
||||
|
||||
/** @satisfies {([Frequency, Frequencies, Frequencies, Frequencies])} */
|
||||
const list = [
|
||||
{
|
||||
name: "Every day",
|
||||
value: "every-day",
|
||||
/** @param {Date} _ */
|
||||
isTriggerDay(_) {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Once a week",
|
||||
list: weekDays.map((day, index) => ({
|
||||
name: day,
|
||||
value: day.toLowerCase(),
|
||||
/** @param {Date} date */
|
||||
isTriggerDay(date) {
|
||||
let day = date.getUTCDay() - 1;
|
||||
if (day === -1) {
|
||||
day = 6;
|
||||
}
|
||||
return day === index;
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: "Every two weeks",
|
||||
list: [...Array(Math.round(maxDays / 2)).keys()].map((day) => {
|
||||
const day1 = day + 1;
|
||||
const day2 = day + 15;
|
||||
|
||||
return {
|
||||
value: `${day1}+${day2}`,
|
||||
name: `The ${getOrdinalDay(day1)} and the ${getOrdinalDay(day2)}`,
|
||||
/** @param {Date} date */
|
||||
isTriggerDay(date) {
|
||||
const d = date.getUTCDate();
|
||||
return d === day1 || d === day2;
|
||||
},
|
||||
};
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "Once a month",
|
||||
list: [...Array(maxDays).keys()].map((day) => {
|
||||
day++;
|
||||
|
||||
return {
|
||||
name: `The ${getOrdinalDay(day)}`,
|
||||
value: String(day),
|
||||
/** @param {Date} date */
|
||||
isTriggerDay(date) {
|
||||
const d = date.getUTCDate();
|
||||
return d === day;
|
||||
},
|
||||
};
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
/** @type {Record<string, Frequency>} */
|
||||
const idToFrequency = {};
|
||||
|
||||
list.forEach((anyFreq, index) => {
|
||||
if ("list" in anyFreq) {
|
||||
anyFreq.list?.forEach((freq) => {
|
||||
idToFrequency[freq.value] = freq;
|
||||
});
|
||||
} else {
|
||||
idToFrequency[anyFreq.value] = anyFreq;
|
||||
}
|
||||
});
|
||||
|
||||
const serde = {
|
||||
/**
|
||||
* @param {Frequency} v
|
||||
*/
|
||||
serialize(v) {
|
||||
return v.value;
|
||||
},
|
||||
/**
|
||||
* @param {string} v
|
||||
*/
|
||||
deserialize(v) {
|
||||
const freq = idToFrequency[v];
|
||||
if (!freq) throw "Freq not found";
|
||||
return freq;
|
||||
},
|
||||
};
|
||||
|
||||
return { list, serde };
|
||||
}
|
||||
|
||||
const frequencies = computeFrequencies();
|
||||
|
||||
const keyPrefix = "save-in-bitcoin";
|
||||
@@ -437,6 +553,7 @@ export function init({
|
||||
kind: "static",
|
||||
scale: "date",
|
||||
utils,
|
||||
consts,
|
||||
config: [
|
||||
{
|
||||
unit: "US Dollars",
|
||||
@@ -478,6 +595,7 @@ export function init({
|
||||
scale: "date",
|
||||
kind: "static",
|
||||
utils,
|
||||
consts,
|
||||
config: [
|
||||
{
|
||||
unit: "US Dollars",
|
||||
@@ -501,6 +619,7 @@ export function init({
|
||||
scale: "date",
|
||||
kind: "static",
|
||||
utils,
|
||||
consts,
|
||||
config: [
|
||||
{
|
||||
unit: "US Dollars",
|
||||
@@ -530,6 +649,7 @@ export function init({
|
||||
scale: "date",
|
||||
kind: "static",
|
||||
utils,
|
||||
consts,
|
||||
config: [
|
||||
{
|
||||
unit: "US Dollars",
|
||||
@@ -563,6 +683,7 @@ export function init({
|
||||
scale: "date",
|
||||
utils,
|
||||
owner,
|
||||
consts,
|
||||
config: [
|
||||
{
|
||||
unit: "Percentage",
|
||||
@@ -879,117 +1000,3 @@ export function init({
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** @param {number} day */
|
||||
function getOrdinalDay(day) {
|
||||
const rest = (day % 30) % 20;
|
||||
|
||||
return `${day}${
|
||||
rest === 1 ? "st" : rest === 2 ? "nd" : rest === 3 ? "rd" : "th"
|
||||
}`;
|
||||
}
|
||||
|
||||
function computeFrequencies() {
|
||||
const weekDays = [
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
"Sunday",
|
||||
];
|
||||
const maxDays = 28;
|
||||
|
||||
/** @satisfies {([Frequency, Frequencies, Frequencies, Frequencies])} */
|
||||
const list = [
|
||||
{
|
||||
name: "Every day",
|
||||
value: "every-day",
|
||||
/** @param {Date} _ */
|
||||
isTriggerDay(_) {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Once a week",
|
||||
list: weekDays.map((day, index) => ({
|
||||
name: day,
|
||||
value: day.toLowerCase(),
|
||||
/** @param {Date} date */
|
||||
isTriggerDay(date) {
|
||||
let day = date.getUTCDay() - 1;
|
||||
if (day === -1) {
|
||||
day = 6;
|
||||
}
|
||||
return day === index;
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
name: "Every two weeks",
|
||||
list: [...Array(Math.round(maxDays / 2)).keys()].map((day) => {
|
||||
const day1 = day + 1;
|
||||
const day2 = day + 15;
|
||||
|
||||
return {
|
||||
value: `${day1}+${day2}`,
|
||||
name: `The ${getOrdinalDay(day1)} and the ${getOrdinalDay(day2)}`,
|
||||
/** @param {Date} date */
|
||||
isTriggerDay(date) {
|
||||
const d = date.getUTCDate();
|
||||
return d === day1 || d === day2;
|
||||
},
|
||||
};
|
||||
}),
|
||||
},
|
||||
{
|
||||
name: "Once a month",
|
||||
list: [...Array(maxDays).keys()].map((day) => {
|
||||
day++;
|
||||
|
||||
return {
|
||||
name: `The ${getOrdinalDay(day)}`,
|
||||
value: String(day),
|
||||
/** @param {Date} date */
|
||||
isTriggerDay(date) {
|
||||
const d = date.getUTCDate();
|
||||
return d === day;
|
||||
},
|
||||
};
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
/** @type {Record<string, Frequency>} */
|
||||
const idToFrequency = {};
|
||||
|
||||
list.forEach((anyFreq, index) => {
|
||||
if ("list" in anyFreq) {
|
||||
anyFreq.list?.forEach((freq) => {
|
||||
idToFrequency[freq.value] = freq;
|
||||
});
|
||||
} else {
|
||||
idToFrequency[anyFreq.value] = anyFreq;
|
||||
}
|
||||
});
|
||||
|
||||
const serde = {
|
||||
/**
|
||||
* @param {Frequency} v
|
||||
*/
|
||||
serialize(v) {
|
||||
return v.value;
|
||||
},
|
||||
/**
|
||||
* @param {string} v
|
||||
*/
|
||||
deserialize(v) {
|
||||
const freq = idToFrequency[v];
|
||||
if (!freq) throw "Freq not found";
|
||||
return freq;
|
||||
},
|
||||
};
|
||||
|
||||
return { list, serde };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user