Add Historial CalendarPrices Chart
parent
0856c9f3d4
commit
f3698ec8bd
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,52 @@
|
|||||||
|
import { Chart as ChartJS, Tooltip, Legend, LineElement, CategoryScale, LinearScale, PointElement } from "chart.js";
|
||||||
|
import { Line } from 'react-chartjs-2';
|
||||||
|
import { atom as $, useAtomValue } from 'jotai';
|
||||||
|
import { loadable } from 'jotai/utils';
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { baseUrl, $selectedUnderlying, $selectedStrike, $selectedFrontExpiration, $selectedBackExpiration } from "./App";
|
||||||
|
|
||||||
|
ChartJS.register(LineElement, Tooltip, Legend, CategoryScale, LinearScale, PointElement);
|
||||||
|
|
||||||
|
export type CalendarPrice = {
|
||||||
|
quote_date: string,
|
||||||
|
price: number
|
||||||
|
};
|
||||||
|
|
||||||
|
const $prices = loadable<Promise<Array<CalendarPrice>>>($(async (get)=>{
|
||||||
|
const selectedUnderlying = get($selectedUnderlying);
|
||||||
|
const selectedStrike = get($selectedStrike);
|
||||||
|
const selectedFrontExpiration = get($selectedFrontExpiration);
|
||||||
|
const selectedBackExpiration = get($selectedBackExpiration);
|
||||||
|
if(selectedUnderlying!=='' && selectedStrike!=='' && selectedFrontExpiration!=='' && selectedBackExpiration!==''){
|
||||||
|
return await fetch(`${baseUrl}/option_quotes/${selectedUnderlying}/${selectedStrike}/${selectedFrontExpiration}/${selectedBackExpiration}`).then(x=>x.json()).catch(()=>[]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
export function CalendarPricesChart(){
|
||||||
|
const prices = useAtomValue($prices);
|
||||||
|
|
||||||
|
useEffect(()=>{ console.log(prices); },[prices])
|
||||||
|
if(prices.state === 'hasData'){
|
||||||
|
return (<div>
|
||||||
|
<Line
|
||||||
|
datasetIdKey='id'
|
||||||
|
data={{
|
||||||
|
labels: prices.data.map((x)=>x.quote_date.substring(0,10)),
|
||||||
|
datasets: [
|
||||||
|
{//@ts-ignore
|
||||||
|
id: 1,
|
||||||
|
label: '',
|
||||||
|
data: prices.data.map((x)=>x.price),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (<></>);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"jsx": "react-jsx"
|
"jsx": "react-jsx",
|
||||||
|
"lib": ["DOM", "DOM.Iterable", "ES2017"]
|
||||||
},
|
},
|
||||||
}
|
}
|
Loading…
Reference in New Issue