Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions src/components/Accountsummary.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,79 @@
import React from "react";
// import { Link } from "react-router-dom";
import React, { useState, useEffect } from "react";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import { ref as databaseRef, get, child, onValue } from "firebase/database";
import { database } from "../firebase";
import { off } from "firebase/database";

const Accountsummary = () => {
const data = { amountInvested: 1000, cash: 500, portoflioValue: 50000 };
const [accountData, setAccountData] = useState({
amountInvested: 0,
cash: 0,
portfolioValue: 0,
});

useEffect(() => {
// Fetch account data from Firebase
const accountDataRef = databaseRef(database, "accountData");

const fetchData = async () => {
try {
const snapshot = await get(child(accountDataRef, "latest"));
if (snapshot.exists()) {
setAccountData(snapshot.val());
} else {
console.log("No data available");
}
} catch (error) {
console.error("Error getting account data:", error);
}
};

fetchData();

// Listen for changes and update the state accordingly
const onDataChange = (snapshot) => {
if (snapshot.exists()) {
setAccountData(snapshot.val());
} else {
console.log("No data available");
}
};

const dataRef = child(accountDataRef, "latest");
onValue(dataRef, onDataChange);

return () => {
// Cleanup the event listener when the component unmounts
off(dataRef, onDataChange);
};
}, []); // Empty dependency array ensures this effect runs once when the component mounts

return (
<Container className="mt-4">
<Row className="gx-1">
<Col>
<div className="d-flex align-items-center p-3 bg-primary text-white">
<span className="me-2 fw-bold">Amount Invested:</span>
<span>{data.amountInvested}</span>
<span>{accountData.amountInvested}</span>
</div>
</Col>
<Col>
<div className="d-flex align-items-center p-3 bg-success text-white">
<span className="me-2 fw-bold">Cash:</span>
<span>{data.cash}</span>
<span>{accountData.cash}</span>
</div>
</Col>
<Col>
<div className="d-flex align-items-center p-3 bg-danger text-white">
<span className="me-2 fw-bold">Portfolio Value:</span>
<span>{data.portoflioValue}</span>
<span>{accountData.portfolioValue}</span>
</div>
</Col>
</Row>
</Container>
);
};

export default Accountsummary;
export default Accountsummary;
225 changes: 0 additions & 225 deletions src/components/LineGraph.js
Original file line number Diff line number Diff line change
@@ -1,228 +1,3 @@
// import React, { useEffect, useState } from "react";
// import ReactApexChart from "react-apexcharts";
// import axios from "axios";

// const LineGraph = ({ companyname }) => {
// const [series1] = useState([
// {
// name: "Sales",
// data: [-10, 3, 10, 9, 29, 79, 22, 9, 12, 7, 19, 55, 13, 49, 17, 2, 89, 5],
// },
// ]);
// const [series2] = useState([
// {
// name: "Sales",
// data: [
// 34, 43, 50, 69, 79, 85, 82, 70, 82, 71, 39, 5, 43, 66, 37, 32, 47, 55,
// ],
// },
// ]);
// const [series4] = useState([
// {
// name: "Sales",
// data: [
// -10, 13, 17, 19, 29, 49, 22, 9, 12, 27, 19, 55, 43, 49, 17, 12, 80, 51,
// ],
// },
// ]);
// const [series3] = useState([
// {
// name: "Sales",
// data: [
// 43, 34, 16, 79, 39, 29, 32, 19, 42, 37, 59, 53, 13, 39, 17, 2, 7, 5,
// ],
// },
// ]);
// const [series5] = useState([
// {
// name: "Sales",
// data: [
// -10, 3, 10, 19, 29, 79, 22, 9, 12, 70, 19, 55, 13, 49, 17, 12, 59, 15,
// ],
// },
// ]);
// const [options] = useState({
// chart: {
// height: 350,
// type: "line",
// },
// forecastDataPoints: {
// count: 7,
// },
// stroke: {
// width: 5,
// curve: "smooth",
// },
// xaxis: {
// type: "datetime",
// categories: [
// "1/11/2000",
// "2/11/2000",
// "3/11/2000",
// "4/11/2000",
// "5/11/2000",
// "6/11/2000",
// "7/11/2000",
// "8/11/2000",
// "9/11/2000",
// "10/11/2000",
// "11/11/2000",
// "12/11/2000",
// "1/11/2001",
// "2/11/2001",
// "3/11/2001",
// "4/11/2001",
// "5/11/2001",
// "6/11/2001",
// ],
// tickAmount: 10,
// labels: {
// formatter: function (value, timestamp, opts) {
// return opts.dateFormatter(new Date(timestamp), "dd MMM");
// },
// },
// },
// title: {
// text: "Forecast",
// align: "left",
// style: {
// fontSize: "16px",
// color: "#666",
// },
// },
// fill: {
// type: "gradient",
// gradient: {
// shade: "dark",
// gradientToColors: ["#FDD835"],
// shadeIntensity: 1,
// type: "horizontal",
// opacityFrom: 1,
// opacityTo: 1,
// stops: [0, 100, 100, 100],
// },
// },
// yaxis: {
// min: -10,
// max: 90,
// },
// });

// // const [companyname, setCompanyName] = useState("apple");
// const getyahoodata = async () => {
// const optionss = {
// method: "GET",
// url: "https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-summary",
// params: {
// symbol: "AMRN",
// region: "US",
// },
// headers: {
// "X-RapidAPI-Key": "d6da08cc1fmsh2ffc0e825183be8p1c8245jsn3ba9199a4d47",
// "X-RapidAPI-Host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
// },
// };

// try {
// const response = await axios.request(optionss);
// console.log(response.data.earnings.financialsChart.yearly);
// } catch (error) {
// console.error(error);
// }
// };
// useEffect(() => {
// getyahoodata()
// }, [])

// return (
// <div id="chart">
// <ReactApexChart
// options={options}
// series={(() => {
// switch (companyname) {
// case "apple":
// return series1;
// case "stanchart":
// return series2;
// case "sumsung":
// return series3;
// case "vivo":
// return series4;
// case "realme":
// return series5;
// default:
// return [];
// }
// })()}
// type="line"
// height={350}
// />
// </div>
// );
// };

// export default LineGraph;
// import React, { useEffect, useState } from "react";
// import ReactApexChart from "react-apexcharts";
// import axios from "axios";

// const LineGraph = () => {
// const [options] = useState({
// // your existing options
// });

// const [series, setSeries] = useState([]);

// const getAlphaVantageData = async () => {
// const symbol = "TSLA"; // Replace with the desired stock symbol
// const apiKey = "S23I1KOF539FHN0W"; // Replace with your Alpha Vantage API key

// const url = `https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY_ADJUSTED&symbol=${symbol}&apikey=${apiKey}`;

// try {
// const response = await axios.get(url);
// console.log(response?.data);

// const monthlyData = response?.data?.["Monthly Adjusted Time Series"];

// // Extract relevant data for the graph
// const extractedData = Object.entries(monthlyData)
// .slice(0, 6) // Get only the last six months
// .map(([date, item]) => ({
// x: new Date(date).toLocaleDateString("en-US", { month: "long" }), // Format month name
// y: parseFloat(item["5. adjusted close"]), // Adjusted close price as a floating-point number
// }));

// setSeries([
// {
// name: "Adjusted Close Price",
// data: extractedData,
// },
// ]);
// } catch (error) {
// console.error(error);
// }
// };

// useEffect(() => {
// getAlphaVantageData();
// }, []);

// return (
// <div id="chart">
// <ReactApexChart
// options={options}
// series={series}
// type="line"
// height={350}
// />
// </div>
// );
// };

// export default LineGraph;

//
import React, { useEffect, useState } from "react";
import ReactApexChart from "react-apexcharts";
import axios from "axios";
Expand Down
2 changes: 2 additions & 0 deletions src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const Navbar = ({ toggleDarkMode, darkMode }) => {
</Link>
<Link className="nav-link text-white" to="/settings">
Settings
</Link> <Link className="nav-link text-white" to="/addaccountdata">
Investment
</Link>
</Nav>
{pathname.includes("/dash") && (
Expand Down
24 changes: 2 additions & 22 deletions src/components/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,19 @@ import React, { useEffect, useState } from "react";
import axios from "axios";

const News = () => {
// const [NewsArticles, setNewsArticles] = useState([]);
const [polygonNews, setNews] = useState([]);
// async function GetNewsArticles() {
// const response = await fetch(
// "https://newsapi.org/v2/everything?q=finance&from=2024-01-12&sortBy=publishedAt&apiKey=bf56f1217d1e4d048c67722c005ee4be"
// );
// const data = await response.json();
// setNewsArticles(data.articles);
// }

async function getnews() {
// const options = {
// method: "GET",
// url: "https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/get-popular-watchlists",
// headers: {
// "X-RapidAPI-Key": "d6da08cc1fmsh2ffc0e825183be8p1c8245jsn3ba9199a4d47",
// "X-RapidAPI-Host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
// },
// };

try {
const response = await axios.get(`https://www.alphavantage.co/query?function=NEWS_SENTIMENT&tickers=tsla&apikey=HYYWPKPI7YSU0TXJ`
const response = await axios.get(
`https://www.alphavantage.co/query?function=NEWS_SENTIMENT&tickers=tsla&apikey=HYYWPKPI7YSU0TXJ`
);
// console.log(response.data.finance.result[0]);
setNews(response?.data?.feed);
// console.log(response?.data?.feed);
// console.log(response.data.finance.result[0].portfolios);
} catch (error) {
console.error(error);
}
}
useEffect(() => {
// GetNewsArticles();
getnews();
}, []);

Expand Down
Loading