diff --git a/src/routes/stocks/[tickerID]/insider/+page.server.ts b/src/routes/stocks/[tickerID]/insider/+page.server.ts
index e09eb86b..21f15870 100644
--- a/src/routes/stocks/[tickerID]/insider/+page.server.ts
+++ b/src/routes/stocks/[tickerID]/insider/+page.server.ts
@@ -40,13 +40,19 @@ export const load = async ({ locals, params }) => {
let output = await response.json();
- output = output?.map((item) => ({
- ...item,
- transactionType:
+ output = output?.reduce((acc, item) => {
+ const newTransactionType =
typeof transactionTypeMap[item?.transactionType] === "function"
? transactionTypeMap[item?.transactionType](item)
- : transactionTypeMap[item?.transactionType] || "n/a",
- }));
+ : transactionTypeMap[item?.transactionType];
+
+ // Only include items with 'Bought' or 'Sold'
+ if (newTransactionType === "Bought" || newTransactionType === "Sold") {
+ acc.push({ ...item, transactionType: newTransactionType });
+ }
+
+ return acc;
+ }, []);
return output;
};
@@ -71,42 +77,9 @@ export const load = async ({ locals, params }) => {
return output;
};
- async function historicalPrice() {
- const postData = {
- ticker: params.tickerID,
- timePeriod: "max",
- };
-
- const response = await fetch(apiURL + "/historical-price", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- "X-API-KEY": apiKey,
- },
- body: JSON.stringify(postData),
- });
-
- const output = (await response?.json()) ?? [];
-
- //Adding this would create a bug hence I cant use the historicalPrice endpoint such as in +page.svelte but rather need to call
- // it again without modification.
- /*
- output= (data) => map(({ time, open, high, low, close }) => ({
- time: Date.parse(time),
- open,
- high,
- low,
- close
- }));
- */
-
- return output;
- }
-
// Make sure to return a promise
return {
getInsiderTrading: await getInsiderTrading(),
getInsiderTradingStatistics: await getInsiderTradingStatistics(),
- getHistoricalPrice: await historicalPrice(),
};
};
diff --git a/src/routes/stocks/[tickerID]/insider/+page.svelte b/src/routes/stocks/[tickerID]/insider/+page.svelte
index c3426352..67f6ff22 100644
--- a/src/routes/stocks/[tickerID]/insider/+page.svelte
+++ b/src/routes/stocks/[tickerID]/insider/+page.svelte
@@ -1,19 +1,10 @@
@@ -333,6 +127,7 @@ onMount(async() => {
{#if insiderTradingList?.length !== 0}
+
{/if}
@@ -366,6 +162,7 @@ onMount(async() => {
{#if insiderTradingList?.length !== 0}
+
+
{#if Object?.keys(statistics)?.length !== 0 }
-
+
Q{statistics?.quarter} {statistics?.year} Insider Statistics
@@ -521,10 +320,10 @@ onMount(async() => {
|
- Person
+ Name
|
- Transaction Date
+ Date
|
Shares
@@ -532,7 +331,7 @@ onMount(async() => {
|
Price
|
- Type |
+ Value |
@@ -542,10 +341,10 @@ onMount(async() => {
{formatString(item?.reportingName)?.replace('/de/','')}
- {extractOfficeInfo(item?.typeOfOwner)}
+ {extractOfficeInfo(item?.typeOfOwner)}
|
-
+
{new Date(item?.transactionDate)?.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', daySuffix: '2-digit' })}
|
@@ -557,17 +356,17 @@ onMount(async() => {
${item?.price?.toFixed(2)}
- {#if item?.transactionType === 'Bought'}
- Bought
- {:else if item?.transactionType === 'Grant'}
- Grant
- {:else if item?.transactionType === 'Sold'}
- Sold
- {:else if item?.transactionType === 'Exercise'}
- Exercise
- {:else if item?.transactionType === 'n/a'}
+
+
+ {#if transactionStyles[item?.transactionType]}
+ {abbreviateNumber(item?.securitiesTransacted * item?.price, true)}
+
+ {transactionStyles[item?.transactionType].text}
+
+ {:else}
n/a
{/if}
+
|
{/each}
@@ -583,10 +382,6 @@ onMount(async() => {
{/if}
- {#if data?.user?.tier === 'Pro'}
-
- {/if}
-
diff --git a/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts b/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts
deleted file mode 100644
index 76f8e95c..00000000
--- a/src/routes/stocks/[tickerID]/insider/workers/insiderWorker.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-function findLatestDateInPast(data) {
- if (!data || !Array?.isArray(data) || data?.length === 0) {
- return null;
- }
-
- let latestDate = new Date(data?.at(0)?.transactionDate);
-
- for (let i = 1; i < data?.length; i++) {
- const currentDate = new Date(data[i]?.transactionDate);
- const currentTransactionDate = currentDate.getDate();
- const currentTransactionDay = currentDate.getDay(); // Sunday is 0, Monday is 1, ..., Saturday is 6
-
- // If the current date is a weekday, reduce it by one month
- if (currentTransactionDay !== 0 && currentTransactionDay !== 6) {
- currentDate.setMonth(currentDate.getMonth() - 1);
- }
-
- if (currentDate < latestDate) {
- latestDate = currentDate;
- }
- }
-
- return latestDate?.toISOString()?.split("T")?.at(0); // Format to yyyy-mm-dd
-}
-
-function getBarChart(data, dates) {
- let soldList = Array(dates?.length)?.fill(0);
- let boughtList = Array(dates?.length)?.fill(0);
- let grantList = Array(dates?.length)?.fill(0);
- let exerciseList = Array(dates?.length)?.fill(0);
-
- // Group transactions by date and transaction type
- const groupedTransactions = {};
- data?.forEach((item) => {
- const { transactionDate, securitiesTransacted, transactionType } = item;
- const key = `${transactionDate}_${transactionType}`;
-
- if (!groupedTransactions[key]) {
- groupedTransactions[key] = 0;
- }
-
- // Update transaction type specific lists
- if (transactionType === "Sold") {
- soldList[dates?.indexOf(transactionDate)] -= securitiesTransacted;
- } else if (transactionType === "Bought") {
- boughtList[dates?.indexOf(transactionDate)] += securitiesTransacted;
- } else if (transactionType === "Grant") {
- grantList[dates?.indexOf(transactionDate)] += securitiesTransacted;
- } else if (transactionType === "Exercise") {
- exerciseList[dates?.indexOf(transactionDate)] += securitiesTransacted;
- }
- });
-
- return {
- sold: soldList,
- bought: boughtList,
- grant: grantList,
- exercise: exerciseList,
- };
-}
-
-onmessage = async (event: MessageEvent) => {
- const data = event.data?.message;
- const rawData = data?.sort(
- (a, b) => new Date(b?.transactionDate) - new Date(a?.transactionDate)
- );
- const latestDate = findLatestDateInPast(rawData);
-
- let historicalPrice = event.data?.historicalPrice?.filter(
- (item) => new Date(item?.time) >= new Date(latestDate)
- );
-
- const dataPoints = historicalPrice?.map(({ close }) => close);
- const dates = historicalPrice?.map(({ time }) => time);
- const barChartData = getBarChart(rawData, dates);
-
- let finalData = { rawData, dataPoints, dates, barChartData };
- postMessage({ message: "success", finalData });
-};
-
-export {};