() => {
const [events, setEvents] = React.useState([])
const feed = React.useMemo(() => new Feed(), [])
React.useEffect(() => {
feed.connect('wss://demo.dxfeed.com/webservice/cometd')
return () => feed.disconnect()
}, [])
const subscriptionRef = React.useRef()
const subscribe = () => {
subscriptionRef.current && subscriptionRef.current.unsubscribe()
setEvents([])
subscriptionRef.current = feed.subscribeTimeSeriesSnapshot(
'AAPL{=d}',
'Candle',
1690374317924,
(snapshot) => {
setEvents(snapshot)
}
)
}
return (
<>
<Button variant="outlined" onClick={subscribe}>
Subscribe
</Button>
<DataViewer events={events} />
</>
)
}