From c2efd858805d5268945b58e17b401035f402c87a Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 21 Jun 2024 19:51:31 +0200 Subject: [PATCH] adding market maker activity --- src/lib/components/DarkPool.svelte | 2 +- src/lib/components/MarketMaker.svelte | 350 ++++++++++++++++++++++ src/lib/components/RetailVolume.svelte | 4 +- src/lib/store.ts | 1 + src/routes/stocks/[tickerID]/+page.svelte | 12 +- src/routes/terms-of-use/+page.svelte | 2 +- 6 files changed, 365 insertions(+), 6 deletions(-) create mode 100644 src/lib/components/MarketMaker.svelte diff --git a/src/lib/components/DarkPool.svelte b/src/lib/components/DarkPool.svelte index 8b182094..04a9092c 100644 --- a/src/lib/components/DarkPool.svelte +++ b/src/lib/components/DarkPool.svelte @@ -185,7 +185,7 @@ $: {
+ import { marketMakerComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; + import InfoModal from '$lib/components/InfoModal.svelte'; + import { Chart } from 'svelte-echarts' + import { abbreviateNumber } from "$lib/utils"; + + import Lazy from 'svelte-lazy'; + export let data; + + let isLoaded = false; + const usRegion = ['cle1','iad1','pdx1','sfo1']; + + let apiURL; + + userRegion.subscribe(value => { + + if (usRegion.includes(value)) { + apiURL = import.meta.env.VITE_USEAST_API_URL; + } else { + apiURL = import.meta.env.VITE_EU_API_URL; + } + }); + + const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + + let rawData = {}; + let historyData = []; + let topMarketMakers = []; + let optionsData; + let avgVolume; + let avgShortVolume; + +function normalizer(value) { + if (Math?.abs(value) >= 1e18) { + return { unit: 'Q', denominator: 1e18 }; + } else if (Math?.abs(value) >= 1e12) { + return { unit: 'T', denominator: 1e12 }; + } else if (Math?.abs(value) >= 1e9) { + return { unit: 'B', denominator: 1e9 }; + } else if (Math?.abs(value) >= 1e6) { + return { unit: 'M', denominator: 1e6 }; + } else if (Math?.abs(value) >= 1e5) { + return { unit: 'K', denominator: 1e5 }; + } else { + return { unit: '', denominator: 1 }; + } +} + + +function getPlotOptions() { + let dates = []; + let tradeCountList = []; + let shareQuantityList = []; + let notionalSumList = []; + // Iterate over the data and extract required information + historyData?.forEach(item => { + + dates?.push(item?.date); + tradeCountList?.push(item?.totalWeeklyTradeCount); + shareQuantityList?.push(item?.totalWeeklyShareQuantity) + notionalSumList?.push(item?.totalNotionalSum) + }); + + console.log(tradeCountList) + const {unit, denominator } = normalizer(Math.max(...notionalSumList) ?? 0) + + const option = { + silent: true, + animation: $screenWidth < 640 ? false: true, + grid: { + left: '2%', + right: '2%', + bottom: '2%', + top: '5%', + containLabel: true + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: dates, + + }, + yAxis: [ + { + type: 'value', + splitLine: { + show: false, // Disable x-axis grid lines + }, + axisLabel: { + color: '#6E7079', // Change label color to white + formatter: function (value, index) { + // Display every second tick + if (index % 2 === 0) { + value = Math.max(value, 0); + return (value / denominator)?.toFixed(1) + unit; // Format value in millions + } else { + return ''; // Hide this tick + } + } + }, + }, + { + type: 'value', + splitLine: { + show: false, // Disable x-axis grid lines + }, + name: 'Sentiment', + position: 'right', + axisLabel: { + formatter: function (value, index) { + if (index % 2 === 0) { + return value.toFixed(2); // Format the sentiment value + } else { + return ''; // Hide this tick + } + } + } + } + ], + series: [ + { + data: notionalSumList, + type: 'line', + itemStyle: { + color: '#fff' // Change bar color to white + }, + showSymbol: false + }, + { + data: tradeCountList, + type: 'bar', + yAxisIndex: 1, + itemStyle: { + color: '#9DED1E' // Change bar color to white + }, + showSymbol: false + }, + { + + data: shareQuantityList, + type: 'bar', + yAxisIndex: 1, + itemStyle: { + color: '#536FC5' // Change bar color to white + }, + showSymbol: false + }, + ] + }; + + +return option; +} + +const getMarketMaker = async (ticker) => { + // Get cached data for the specific tickerID + const cachedData = getCache(ticker, 'getMarketMaker'); + if (cachedData) { + rawData = cachedData; + } else { + + const postData = {'ticker': ticker}; + // make the POST request to the endpoint + const response = await fetch(apiURL + '/market-maker', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(postData) + }); + + rawData = await response.json(); + // Cache the data for this specific tickerID with a specific name 'getMarketMaker' + setCache(ticker, rawData, 'getMarketMaker'); + } + + if(Object?.keys(rawData)?.length !== 0) { + $marketMakerComponent = true; + } else { + $marketMakerComponent = false; + } +}; + + +$: { + if($assetType === 'stock' ? $stockTicker :$etfTicker && typeof window !== 'undefined') { + isLoaded=false; + const ticker = $assetType === 'stock' ? $stockTicker :$etfTicker + const asyncFunctions = [ + getMarketMaker(ticker) + ]; + Promise.all(asyncFunctions) + .then((results) => { + topMarketMakers = rawData?.topMarketMakers ?? []; + historyData = rawData?.history; + optionsData = getPlotOptions() + }) + .catch((error) => { + console.error('An error occurred:', error); + }); + isLoaded = true; + + } +} + + + + + + +
+
+ +
+ + +
+ + {#if data?.user?.tier === 'Pro'} + {#if isLoaded} + + {#if historyData?.length !== 0} + +
+
+ Over the past 12 months, {$displayCompanyName} has experienced an average dark pool trading volume of + 12 shares. + Out of this total, an average of 12 shares, + constituting approximately 12%, were short volume. +
+
+ +
+ + + +
+ +
+
+ +
+ +
+
+ + + + Total Volume + +
+
+ + + + Short Volume + +
+ +
+ + + +

+ Latest Information +

+ + + + {/if} + + {:else} +
+
+ +
+
+ {/if} + + {:else} +
+ + Unlock content with Pro Subscription +
+ {/if} + +
+
+ + + + + \ No newline at end of file diff --git a/src/lib/components/RetailVolume.svelte b/src/lib/components/RetailVolume.svelte index fcca9d26..b3dad3a9 100644 --- a/src/lib/components/RetailVolume.svelte +++ b/src/lib/components/RetailVolume.svelte @@ -219,10 +219,10 @@ $: {
diff --git a/src/lib/store.ts b/src/lib/store.ts index 3bbb86ea..bafe94d9 100644 --- a/src/lib/store.ts +++ b/src/lib/store.ts @@ -70,6 +70,7 @@ export const enterpriseComponent = writable((false)); export const varComponent = writable((false)); export const sentimentComponent = writable((false)); export const analystEstimateComponent = writable((false)); +export const marketMakerComponent = writable((false)); export const strategyId = writable( ("")); diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index bae26686..dcfdaba3 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -3,7 +3,7 @@ import {AreaSeries, Chart, PriceLine, CandlestickSeries} from 'svelte-lightweight-charts'; import { TrackingModeExitMode } from 'lightweight-charts'; - import {getCache, setCache, analystEstimateComponent, sentimentComponent, screenWidth, displayCompanyName, numberOfUnreadNotification, globalForm, varComponent, shareStatisticsComponent, enterpriseComponent, darkPoolComponent, retailVolumeComponent, shareholderComponent, trendAnalysisComponent, revenueSegmentationComponent, priceAnalysisComponent, fundamentalAnalysisComponent, userRegion, isCrosshairMoveActive, realtimePrice, priceIncrease, currentPortfolioPrice, currentPrice, stockTicker, isOpen, isBeforeMarketOpen, isWeekend} from '$lib/store'; + import {getCache, setCache, marketMakerComponent, analystEstimateComponent, sentimentComponent, screenWidth, displayCompanyName, numberOfUnreadNotification, globalForm, varComponent, shareStatisticsComponent, enterpriseComponent, darkPoolComponent, retailVolumeComponent, shareholderComponent, trendAnalysisComponent, revenueSegmentationComponent, priceAnalysisComponent, fundamentalAnalysisComponent, userRegion, isCrosshairMoveActive, realtimePrice, priceIncrease, currentPortfolioPrice, currentPrice, stockTicker, isOpen, isBeforeMarketOpen, isWeekend} from '$lib/store'; import { onDestroy, onMount } from 'svelte'; import BullBearSay from '$lib/components/BullBearSay.svelte'; import CommunitySentiment from '$lib/components/CommunitySentiment.svelte'; @@ -1328,7 +1328,15 @@ function changeChartType() { - + +
+ {#await import('$lib/components/MarketMaker.svelte') then {default: Comp}} + + {/await} +
+
+ +
{#await import('$lib/components/DarkPool.svelte') then {default: Comp}} diff --git a/src/routes/terms-of-use/+page.svelte b/src/routes/terms-of-use/+page.svelte index 0a205103..ce1962de 100644 --- a/src/routes/terms-of-use/+page.svelte +++ b/src/routes/terms-of-use/+page.svelte @@ -87,7 +87,7 @@
-

Last updated: 22.06.2023

+

Last updated: 21.06.2024

Please carefully read the terms and conditions before using this website.