Skip to content

Commit

Permalink
trading view component
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgsolomon committed Nov 22, 2024
1 parent ef34c39 commit 75c8980
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions generate/src/tradingview-widget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// TradingViewWidget.jsx
import React, { useEffect, useRef, memo } from 'react';

export type Timeframe = '1D' | '1M' | '6M' | '1Y' | '5Y';

function TradingViewWidget({ timeframe }: { timeframe: Timeframe }) {
const container = useRef<HTMLDivElement>(null);

useEffect(() => {
const script = document.createElement('script');
script.src =
'https://s3.tradingview.com/external-embedding/embed-widget-symbol-overview.js';
script.type = 'text/javascript';
script.async = true;
script.innerHTML = `
{
"symbols": [
[
"RAYDIUM:FWOGSOL_AB1EU2.USD|${timeframe}"
]
],
"chartOnly": false,
"width": "100%",
"height": "100%",
"locale": "en",
"colorTheme": "dark",
"autosize": true,
"showVolume": true,
"showMA": false,
"hideDateRanges": false,
"hideMarketStatus": true,
"hideSymbolLogo": false,
"scalePosition": "right",
"scaleMode": "Normal",
"fontFamily": "-apple-system, BlinkMacSystemFont, Trebuchet MS, Roboto, Ubuntu, sans-serif",
"fontSize": "20",
"noTimeScale": false,
"valuesTracking": "1",
"changeMode": "price-and-percent",
"chartType": "candlesticks",
"headerFontSize": "large",
"lineType": 0,
"dateRanges": [
"1d|15",
"1m|240",
"6m|1D",
"12m|1D",
"60m|1W",
"all|1M"
],
"timeHoursFormat": "12-hours",
"upColor": "#22ab94",
"downColor": "#f7525f",
"borderUpColor": "#22ab94",
"borderDownColor": "#f7525f",
"wickUpColor": "#22ab94",
"wickDownColor": "#f7525f"
}`;
container.current?.appendChild(script);

// Cleanup previous script when timeframe changes
return () => {
if (container.current) {
container.current.innerHTML = '';
}
};
}, [timeframe]);

return (
<div className="tradingview-widget-container" ref={container}>
<div className="tradingview-widget-container__widget"></div>
<div className="tradingview-widget-copyright">
<a
href="https://www.tradingview.com/"
rel="noopener nofollow"
target="_blank"
>
<span className="blue-text">Track all markets on TradingView</span>
</a>
</div>
</div>
);
}

export default memo(TradingViewWidget);

0 comments on commit 75c8980

Please sign in to comment.