Skip to content

Commit 75d3cf7

Browse files
committed
Initial commit
0 parents  commit 75d3cf7

File tree

477 files changed

+20938
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

477 files changed

+20938
-0
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Binary file not shown.
Binary file not shown.
176 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

.vs/TradingWebApp/config/applicationhost.config

Lines changed: 1016 additions & 0 deletions
Large diffs are not rendered by default.

.vs/TradingWebApp/v17/.futdcache.v2

308 Bytes
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"Version": 1,
3+
"WorkspaceRootPath": "C:\\Users\\Admin\\source\\repos\\TradingWebApp\\",
4+
"Documents": [
5+
{
6+
"AbsoluteMoniker": "D:0:0:{B3E91CE2-D353-4B86-8B8A-7929A78BD67C}|tradingwebapp.client\\tradingwebapp.client.esproj|c:\\users\\admin\\source\\repos\\tradingwebapp\\tradingwebapp.client\\src\\pagehistory.tsx||{0F2454B1-A556-402D-A7D0-1FDE7F99DEE0}",
7+
"RelativeMoniker": "D:0:0:{B3E91CE2-D353-4B86-8B8A-7929A78BD67C}|tradingwebapp.client\\tradingwebapp.client.esproj|solutionrelative:tradingwebapp.client\\src\\pagehistory.tsx||{0F2454B1-A556-402D-A7D0-1FDE7F99DEE0}"
8+
}
9+
],
10+
"DocumentGroupContainers": [
11+
{
12+
"Orientation": 0,
13+
"VerticalTabListWidth": 256,
14+
"DocumentGroups": [
15+
{
16+
"DockedWidth": 200,
17+
"SelectedChildIndex": 0,
18+
"Children": [
19+
{
20+
"$type": "Document",
21+
"DocumentIndex": 0,
22+
"Title": "PageHistory.tsx",
23+
"DocumentMoniker": "C:\\Users\\Admin\\source\\repos\\TradingWebApp\\tradingwebapp.client\\src\\PageHistory.tsx",
24+
"RelativeDocumentMoniker": "tradingwebapp.client\\src\\PageHistory.tsx",
25+
"ToolTip": "C:\\Users\\Admin\\source\\repos\\TradingWebApp\\tradingwebapp.client\\src\\PageHistory.tsx",
26+
"RelativeToolTip": "tradingwebapp.client\\src\\PageHistory.tsx",
27+
"ViewState": "AQIAADIAAAAAAAAAAAAQwDoAAAA3AAAA",
28+
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.003213|",
29+
"WhenOpened": "2024-03-06T00:35:26.351Z",
30+
"EditorCaption": ""
31+
}
32+
]
33+
}
34+
]
35+
}
36+
]
37+
}

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Trading Web Application README
2+
3+
Welcome to my Trading Web Application! Below is an overview of the application's architecture, technologies used, and instructions for setting up and deploying the application.
4+
5+
## Overview
6+
7+
My Trading Web Application is built using ASP.NET on the server-side with AzureSQL for database management. On the client-side, I have utilized Node React with TypeScript. The application allows users to perform stock trading activities and manage their transactions efficiently.
8+
9+
### APIs
10+
11+
I utilize third-party APIs for fetching live stock prices and other indicators for trading. Due to cost considerations, I have opted for the Yahoo Finance API, which provides live stock prices using stock symbols, and the Google API for retrieving stock names.
12+
13+
## Server
14+
15+
### Technologies Used
16+
- ASP.NET for developing APIs using MVC controllers
17+
- Entity Framework for CRUD operations and data management
18+
- AzureSQL for database storage
19+
20+
### Features
21+
- Utilizes MVC architecture for API development
22+
- Provides RESTful APIs for user management, stock trading, and transaction records
23+
- Easy data migration with Entity Framework for updating data schema
24+
25+
## Client
26+
27+
### Technologies Used
28+
- Node React with TypeScript for front-end development
29+
- React for state management and user interface development
30+
31+
### Features
32+
- Challenges with type checking due to TypeScript
33+
- Responsive user interface to handle user responses and errors effectively
34+
- Utilizes React for state management, including user input validation before sending data to the server
35+
- Implements cookie-based authentication to reduce the need for repeated sign-ins
36+
37+
# <span style="color:red">START APPLICATION</span>
38+
39+
### For Client
40+
41+
1. Install Node Modules: npm install
42+
2. If Using Visual Studio:
43+
- Simply click start or use `dotnet run`
44+
45+
### For Deployment
46+
47+
1. After installing node modules, build the app: yarn build
48+
2. Configure the startup file to point to the `dist` index HTML for deployment.
49+
50+
**Note**: Configuration files or startup instructions might be highlighted in red for better visibility.
51+
52+
---
53+
54+
Feel free to reach out if you have any questions or need further assistance!
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"swashbuckle.aspnetcore.cli": {
6+
"version": "6.4.0",
7+
"commands": [
8+
"swagger"
9+
]
10+
}
11+
}
12+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net;
5+
using System.Threading.Tasks;
6+
7+
namespace TradingWebApp.Server.Controllers
8+
{
9+
[Route("api/[controller]")]
10+
[ApiController]
11+
public class QuoteController : ControllerBase
12+
{
13+
// GetCompanyName method moved here
14+
private string GetCompanyName(string ticker)
15+
{
16+
string url = $"https://finance.google.com/finance?q={ticker}";
17+
WebClient client = new WebClient();
18+
string content = client.DownloadString(url);
19+
int startLocation = content.IndexOf("<title>") + "<title>".Length;
20+
int endLocation = content.IndexOf("</title>");
21+
string title = content.Substring(startLocation, endLocation - startLocation);
22+
string companyName = title.Split(':')[0];
23+
int positionRemove = companyName.IndexOf('(');
24+
companyName = companyName.Substring(0, positionRemove);
25+
return companyName.Trim();
26+
}
27+
28+
//api/Quote/Lookup
29+
[HttpPost("Lookup")]
30+
public async Task<IActionResult> LookupStock([FromBody] string symbol)
31+
{
32+
if (string.IsNullOrWhiteSpace(symbol))
33+
{
34+
return BadRequest("Symbol cannot be empty");
35+
}
36+
37+
Console.WriteLine($"Symbol: {symbol}");
38+
39+
symbol = symbol.ToUpper();
40+
DateTime end = DateTime.Now;
41+
DateTime start = end.AddDays(-5);
42+
43+
string url = $"https://query1.finance.yahoo.com/v7/finance/download/{Uri.EscapeDataString(symbol)}" +
44+
$"?period1={(Int32)(start.Subtract(new DateTime(1970, 1, 1))).TotalSeconds}" +
45+
$"&period2={(Int32)(end.Subtract(new DateTime(1970, 1, 1))).TotalSeconds}" +
46+
$"&interval=1d&events=history&includeAdjustedClose=true";
47+
48+
try
49+
{
50+
WebClient client = new WebClient();
51+
client.Headers["User-Agent"] = "C# WebClient";
52+
string response = client.DownloadString(url);
53+
string[] lines = response.Split('\n');
54+
Array.Reverse(lines);
55+
string[] headers = lines[0].Split(',');
56+
string[] data = lines[1].Split(',');
57+
double price = Math.Round(Double.Parse(data[4]), 2); // Getting current price instead of adjusted close
58+
string name = GetCompanyName(symbol);
59+
60+
var stockInfo = new Dictionary<string, dynamic>()
61+
{
62+
{"name", name},
63+
{"price", price},
64+
{"symbol", symbol}
65+
};
66+
67+
Console.WriteLine($"Stock Information: {stockInfo}");
68+
return Ok(stockInfo);
69+
}
70+
catch (WebException)
71+
{
72+
Console.WriteLine($"No information found for symbol: {symbol}");
73+
return NotFound($"No information found for symbol: {symbol}");
74+
}
75+
}
76+
}
77+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System.Linq;
3+
using TradingWebApp.Server.Data;
4+
using TradingWebApp.Server.Models;
5+
6+
namespace TradingWebApp.Server.Controllers
7+
{
8+
[Route("api/[controller]")]
9+
[ApiController]
10+
public class StockController : ControllerBase
11+
{
12+
private readonly AppDbContext _context;
13+
14+
public StockController(AppDbContext context)
15+
{
16+
_context = context;
17+
}
18+
19+
// GET: api/Stock/Read
20+
[HttpGet("Read")]
21+
public IActionResult Read(int userId)
22+
{
23+
// Find the user by userId
24+
var user = _context.Users.FirstOrDefault(u => u.Id == userId);
25+
if (user == null)
26+
{
27+
return NotFound("User not found.");
28+
}
29+
30+
// Retrieve stocks associated with the user
31+
var userStocks = _context.Stocks.Where(s => s.UserId == userId).ToList();
32+
33+
return Ok(userStocks);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)