diff --git a/src/lib/components/DarkPool.svelte b/src/lib/components/DarkPool.svelte index 8bd18a27..0583ae15 100644 --- a/src/lib/components/DarkPool.svelte +++ b/src/lib/components/DarkPool.svelte @@ -1,13 +1,163 @@ - +
- +
- + @@ -109,9 +257,7 @@ {monthlyVolume} - + diff --git a/src/lib/components/DarkPoolLevel.svelte b/src/lib/components/DarkPoolLevel.svelte new file mode 100644 index 00000000..a2f0a3e6 --- /dev/null +++ b/src/lib/components/DarkPoolLevel.svelte @@ -0,0 +1,270 @@ + + +
+
+
+ + +
+ + {#if isLoaded} + {#if rawData?.length !== 0} + +
+ Over the past 12 months, GameStop Corp. has experienced an average + dark pool trading volume of 8.55M shares. Out of this total, an + average of 3.81M shares, constituting approximately 44.52%, were short + volume. +
+ +
+
+
+ {#each ["Volume", "Size", "Premium"] as item} + + {/each} +
+ + +
+
+ + + {/if} + {:else} +
+
+ +
+
+ {/if} +
+
+ + diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 149bb386..25771b91 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -70,6 +70,7 @@ const sectionMap = { insider: "/insider", options: "/options", + "dark-pool": "/dark-pool", dividends: "/dividends", statistics: "/statistics", metrics: "metrics", @@ -349,6 +350,7 @@ statistics: "statistics", financials: "financials", options: "options", + "dark-pool": "dark-pool", metrics: "metrics", insider: "insider", dividends: "dividends", @@ -938,6 +940,16 @@ > Options + changeSection("dark-pool")} + class="p-2 px-5 cursor-pointer {displaySection === + 'dark-pool' + ? 'text-white bg-secondary sm:hover:bg-opacity-[0.95] font-semibold' + : 'text-gray-400 sm:hover:text-white sm:hover:bg-secondary sm:hover:bg-opacity-[0.95]'}" + > + Dark Pool + changeSection("insider")} diff --git a/src/routes/stocks/[tickerID]/dark-pool/+layout.server.ts b/src/routes/stocks/[tickerID]/dark-pool/+layout.server.ts new file mode 100644 index 00000000..49c34a91 --- /dev/null +++ b/src/routes/stocks/[tickerID]/dark-pool/+layout.server.ts @@ -0,0 +1,28 @@ +export const load = async ({ locals, params }) => { + + const getSimilarStocks = async () => { + const { apiKey, apiURL } = locals; + const postData = { + ticker: params.tickerID, + }; + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/similar-stocks", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getSimilarStocks: await getSimilarStocks(), + }; +}; diff --git a/src/routes/stocks/[tickerID]/dark-pool/+layout.svelte b/src/routes/stocks/[tickerID]/dark-pool/+layout.svelte new file mode 100644 index 00000000..2a9784b9 --- /dev/null +++ b/src/routes/stocks/[tickerID]/dark-pool/+layout.svelte @@ -0,0 +1,61 @@ + + +
+ +
diff --git a/src/routes/stocks/[tickerID]/dark-pool/+page.server.ts b/src/routes/stocks/[tickerID]/dark-pool/+page.server.ts new file mode 100644 index 00000000..3398feca --- /dev/null +++ b/src/routes/stocks/[tickerID]/dark-pool/+page.server.ts @@ -0,0 +1,206 @@ +import { error, fail, redirect } from "@sveltejs/kit"; +import { validateData } from "$lib/utils"; +import { loginUserSchema, registerUserSchema } from "$lib/schemas"; + + +export const load = async ({ params, locals }) => { + const { apiURL, apiKey } = locals; + + const postData = { + ticker: params.tickerID, + }; + + const getStockDividend = async () => { + + + const response = await fetch(apiURL + "/stock-dividend", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + const getHistoricalDarkPool = async () => { + + + // make the POST request to the endpoint + const response = await fetch(apiURL + "/historical-dark-pool", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + + const output = await response.json(); + + return output; + }; + + // Make sure to return a promise + return { + getStockDividend: await getStockDividend(), + getHistoricalDarkPool: await getHistoricalDarkPool(), + + }; +}; + + + +export const actions = { + login: async ({ url, request, locals }) => { + + const path = url?.href?.replace("/oauth2","") + + const { formData, errors } = await validateData( + await request.formData(), + loginUserSchema, + ); + + if (errors) { + return fail(400, { + data: formData, + errors: errors.fieldErrors, + }); + } + + try { + await locals.pb + .collection("users") + .authWithPassword(formData.email, formData.password); + + /* + if (!locals.pb?.authStore?.model?.verified) { + locals.pb.authStore.clear(); + return { + notVerified: true, + }; + } + */ + } catch (err) { + console.log("Error: ", err); + error(err.status, err.message); + } + + redirect(302, path); + }, + + register: async ({ url, locals, request }) => { + const path = url?.href?.replace("/oauth2","") + + const { formData, errors } = await validateData( + await request.formData(), + registerUserSchema, + ); + + if (errors) { + return fail(400, { + data: formData, + errors: errors.fieldErrors, + }); + } + + try { + let newUser = await locals.pb.collection("users").create(formData); + /* +await locals.pb?.collection('users').update( + newUser?.id, { + 'freeTrial' : true, + 'tier': 'Pro', //Give new users a free trial for the Pro Subscription + }); +*/ + await locals.pb.collection("users")?.requestVerification(formData.email); + } catch (err) { + console.log("Error: ", err); + error(err.status, err.message); + } + + try { + await locals.pb + .collection("users") + .authWithPassword(formData.email, formData.password); + } catch (err) { + console.log("Error: ", err); + error(err.status, err.message); + } + + redirect(303, path); + }, + + oauth2: async ({ url, locals, request, cookies }) => { + + const path = url?.href?.replace("/oauth2","") + const authMethods = (await locals?.pb + ?.collection("users") + ?.listAuthMethods())?.oauth2; + + + const data = await request?.formData(); + const providerSelected = data?.get("provider"); + + if (!authMethods) { + return { + authProviderRedirect: "", + authProviderState: "", + }; + } + const redirectURL = `${url.origin}/oauth`; + + const targetItem = authMethods?.providers?.findIndex( + (item) => item?.name === providerSelected, + ); + //console.log("==================") + //console.log(authMethods.authProviders) + //console.log('target item is: ', targetItem) + + const provider = authMethods.providers[targetItem]; + const authProviderRedirect = `${provider.authUrl}${redirectURL}`; + const state = provider.state; + const verifier = provider.codeVerifier; + + + + cookies.set("state", state, { + httpOnly: true, + sameSite: "lax", + secure: true, + path: "/", + maxAge: 60 * 60, + }); + + cookies.set("verifier", verifier, { + httpOnly: true, + sameSite: "lax", + secure: true, + path: "/", + maxAge: 60 * 60, + }); + + cookies.set("provider", providerSelected, { + httpOnly: true, + sameSite: "lax", + secure: true, + path: "/", + maxAge: 60 * 60, + }); + + cookies.set("path", path, { + httpOnly: true, + sameSite: "lax", + secure: true, + path: "/", + maxAge: 60, + }); + + redirect(302, authProviderRedirect); + }, + +}; diff --git a/src/routes/stocks/[tickerID]/dark-pool/+page.svelte b/src/routes/stocks/[tickerID]/dark-pool/+page.svelte new file mode 100644 index 00000000..306b9fd5 --- /dev/null +++ b/src/routes/stocks/[tickerID]/dark-pool/+page.svelte @@ -0,0 +1,318 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Dividend History, Dates & Yield · + stocknear + + + + + + + + + + + + + + + + +
+
+
+
+
+

+ Dark Pool +

+
+ + + + {#if rawData?.history?.length !== 0} +
+

Dividends History

+
+ + {#if isLoaded} + {#if rawData?.history?.length !== 0 && optionsDividend} +
+ +
+ +
+
@@ -97,9 +247,7 @@ {formatDateRange(rawData?.slice(-1)?.at(0)?.date)}
Total Volume
Avg. Short % of Volume
+ + + + + + + + + + {#each rawData?.history as item} + + + + + + + {/each} + +
+ Ex-Divid. Date + + Cash Amount + + Record Date + + Pay Date +
+ {new Date(item?.date)?.toLocaleString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + daySuffix: "2-digit", + })} + + {item?.adjDividend?.toFixed(3)} + + {item?.recordDate?.length !== 0 + ? new Date(item?.recordDate)?.toLocaleString( + "en-US", + { + month: "short", + day: "numeric", + year: "numeric", + daySuffix: "2-digit", + }, + ) + : "n/a"} + + {item?.paymentDate?.length !== 0 + ? new Date(item?.paymentDate)?.toLocaleString( + "en-US", + { + month: "short", + day: "numeric", + year: "numeric", + daySuffix: "2-digit", + }, + ) + : "n/a"} +
+
+ + * Dividend amounts are adjusted for stock splits when + applicable. + + {:else} +

+ No history found +

+ {/if} + {:else} +
+
+ +
+
+ {/if} + {/if} +
+ + +
+ +