Skip to content

Commit

Permalink
bomb commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bush1D3v committed Nov 9, 2024
1 parent b9ae02f commit afe1682
Show file tree
Hide file tree
Showing 25 changed files with 488 additions and 285 deletions.
51 changes: 31 additions & 20 deletions api/src/proxy/BrapiDev.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import type {Request, Response} from "express";
import {get} from "../helpers/HttpClient.ts";
import type { Request, Response } from "express";
import { get } from "../helpers/HttpClient.ts";
import dotenv from "dotenv";
import type {Stock} from "../types/BrapiDev/Stock.ts";
import type { Stock } from "../types/BrapiDev/Stock.ts";
import type { SortBy } from "../types/BrapiDev/SortBy.ts";
import type { SortOrder } from "../types/BrapiDev/SortOrder.ts";
dotenv.config();

const BASE_API_URL = process.env.BRAPI_HOST as string;
const API_KEY = process.env.BRAPI_KEY as string;

const defaultHeaders = {
"Accept-Encoding": "deflate, gzip",
"referrer-policy": "origin-when-cross-origin",
"X-Api-Key": API_KEY,
"Accept-Encoding": "deflate, gzip",
"referrer-policy": "origin-when-cross-origin",
"X-Api-Key": API_KEY,
};

interface QueryParams {
limit?: number;
page?: number;
limit?: number;
page?: number;
sortBy?: SortBy;
sortOrder?: SortOrder;
}

interface ResponseListStocks {
stocks: Stock[];
stocks: Stock[];
}

/**
Expand All @@ -31,19 +35,26 @@ interface ResponseListStocks {
* @throws {Error} If the request to the external API fails
*/
export async function listStocks(req: Request, res: Response): Promise<void> {
const {limit = 12, page = 1}: QueryParams = req.query;
const url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}`;
const { limit = 12, page = 1, sortBy, sortOrder }: QueryParams = req.query;

try {
const response = await get(url, defaultHeaders);
let url: string;

if (!response.ok) throw new Error(await response.json());
if (sortBy && sortOrder) {
url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}&sortBy=${sortBy}&sortOrder=${sortOrder}`;
} else {
url = `${BASE_API_URL}/api/quote/list?limit=${limit}&page=${page}`;
}

const jsonData: ResponseListStocks = await response.json();
try {
const response = await get(url, defaultHeaders);

res.status(200).json(jsonData.stocks);
} catch (error) {
console.error(error);
res.status(500).json({error: error});
}
if (!response.ok) throw new Error(await response.json());

const jsonData: ResponseListStocks = await response.json();

res.status(200).json(jsonData.stocks);
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
}
74 changes: 41 additions & 33 deletions api/src/proxy/CoinMarketCap.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import type {Request, Response} from "express";
import {get} from "../helpers/HttpClient.ts";
import type { Request, Response } from "express";
import { get } from "../helpers/HttpClient.ts";
import dotenv from "dotenv";
import type {CryptoCurrency} from "../types/CoinMarketCap/CryptoCurrency.ts";
import type { CryptoCurrency } from "../types/CoinMarketCap/CryptoCurrency.ts";
import type { Sort } from "../types/CoinMarketCap/Sort.ts";
dotenv.config();

const BASE_API_URL = process.env.COINMARKETCAP_HOST as string;
const API_KEY = process.env.COINMARKETCAP_KEY as string;

const defaultHeaders = {
"Accept-Encoding": "deflate, gzip",
"referrer-policy": "origin-when-cross-origin",
"X-CMC_PRO_API_KEY": API_KEY,
"Accept-Encoding": "deflate, gzip",
"referrer-policy": "origin-when-cross-origin",
"X-CMC_PRO_API_KEY": API_KEY,
};

interface ListingsLatestQueryParams {
limit?: number;
start?: number;
limit?: number;
start?: number;
sort?: Sort;
}

interface ResponseListingLatestData {
data: CryptoCurrency[];
data: CryptoCurrency[];
}

/**
Expand All @@ -31,29 +33,35 @@ interface ResponseListingLatestData {
* @throws {Error} If the request to the external API fails
*/
export async function listingsLatest(req: Request, res: Response): Promise<void> {
const {limit = 12, start = 1}: ListingsLatestQueryParams = req.query;
const url = `${BASE_API_URL}/v1/cryptocurrency/listings/latest?limit=${limit}&start=${start}`;
const { limit = 12, start = 1, sort }: ListingsLatestQueryParams = req.query;

try {
const response = await get(url, defaultHeaders);
let url: string;
if (sort) {
url = `${BASE_API_URL}/v1/cryptocurrency/listings/latest?limit=${limit}&start=${start}&sort=${sort}`;
} else {
url = `${BASE_API_URL}/v1/cryptocurrency/listings/latest?limit=${limit}&start=${start}`;
}

if (!response.ok) throw new Error(await response.json());
try {
const response = await get(url, defaultHeaders);

const data: ResponseListingLatestData = await response.json();
if (!response.ok) throw new Error(await response.json());

res.json(data.data);
} catch (error) {
console.error(error);
res.status(500).json({error: error});
}
const data: ResponseListingLatestData = await response.json();

res.json(data.data);
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
}

interface DetailQueryParams {
slug?: string;
slug?: string;
}

interface ResponseDetailData {
data: CryptoCurrency;
data: CryptoCurrency;
}

/**
Expand All @@ -65,19 +73,19 @@ interface ResponseDetailData {
* @throws {Error} If the request to the external API fails
*/
export async function detail(req: Request, res: Response): Promise<void> {
const {slug}: DetailQueryParams = req.query;
const url = `${BASE_API_URL}/v2/cryptocurrency/info?slug=${slug}`;
const { slug }: DetailQueryParams = req.query;
const url = `${BASE_API_URL}/v2/cryptocurrency/info?slug=${slug}`;

try {
const response = await get(url, defaultHeaders);
try {
const response = await get(url, defaultHeaders);

if (!response.ok) throw new Error(await response.json());
if (!response.ok) throw new Error(await response.json());

const data: ResponseDetailData = await response.json();
const data: ResponseDetailData = await response.json();

res.json(data.data).status(200);
} catch (error) {
console.error(error);
res.status(500).json({error: error});
}
res.json(data.data).status(200);
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
}
66 changes: 51 additions & 15 deletions api/src/proxy/Finnhub.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import type {Request, Response} from "express";
import {get} from "../helpers/HttpClient.ts";
import type { Request, Response } from "express";
import { get } from "../helpers/HttpClient.ts";
import dotenv from "dotenv";
import type {New} from "../types/Finnhub/New.ts";
import type { New } from "../types/Finnhub/New.ts";
dotenv.config();

const BASE_API_URL = process.env.FINNHUB_HOST as string;
const API_KEY = process.env.FINNHUB_KEY as string;

const defaultHeaders = {
"X-Finnhub-Token": API_KEY,
"X-Finnhub-Token": API_KEY,
};

interface ListingsMarketNewsQueryParams {
category?: string;
}

/**
* @description Handles the request to get the list of market news.
*
Expand All @@ -20,19 +24,51 @@ const defaultHeaders = {
* @throws {Error} If the request to the external API fails
*/
export async function listMarketNews(req: Request, res: Response): Promise<void> {
const {category} = req.query;
const url = `${BASE_API_URL}/api/v1/news?category=${category}`;
const { category }: ListingsMarketNewsQueryParams = req.query;
const url = `${BASE_API_URL}/api/v1/news?category=${category}`;

try {
const response = await get(url, defaultHeaders);

if (!response.ok) throw new Error(await response.json());

const jsonData: New[] = await response.json();

res.json(jsonData);
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
}

interface ListingsCompanyNewsQueryParams {
symbol?: string;
from?: string;
to?: string;
}

/**
* @description Handles the request to get the list of company news.
*
* @param {Request} req - The request object
* @param {Response} res - The response object
* @returns {void}
* @throws {Error} If the request to the external API fails
*/
export async function listCompanyNews(req: Request, res: Response): Promise<void> {
const { symbol, from, to }: ListingsCompanyNewsQueryParams = req.query;
const url = `${BASE_API_URL}/api/v1/company-news?symbol=${symbol}&from=${from}&to=${to}`;

try {
const response = await get(url, defaultHeaders);
try {
const response = await get(url, defaultHeaders);

if (!response.ok) throw new Error(await response.json());
if (!response.ok) throw new Error(await response.json());

const jsonData: New[] = await response.json();
const jsonData: New[] = await response.json();

res.json(jsonData);
} catch (error) {
console.error(error);
res.status(500).json({error: error});
}
res.json(jsonData);
} catch (error) {
console.error(error);
res.status(500).json({ error: error });
}
}
3 changes: 2 additions & 1 deletion api/src/routes/Finnhub.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import express from "express";
import {listMarketNews} from "../proxy/Finnhub.ts";
import { listCompanyNews, listMarketNews } from "../proxy/Finnhub.ts";

const finnhubRoutes = express();

finnhubRoutes.get("/api/v1/news", listMarketNews);
finnhubRoutes.get("/api/v1/company-news", listCompanyNews);

export default finnhubRoutes;
1 change: 1 addition & 0 deletions api/src/types/BrapiDev/SortBy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SortBy = "name" | "close" | "change" | "change_abs" | "volume" | "market_cap_basic";
1 change: 1 addition & 0 deletions api/src/types/BrapiDev/SortOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type SortOrder = "asc" | "desc";
1 change: 1 addition & 0 deletions api/src/types/CoinMarketCap/Sort.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Sort = "name" | "symbol" | "date_added" | "market_cap" | "market_cap_strict" | "price" | "circulating_supply" | "total_supply" | "max_supply" | "num_market_pairs" | "volume_24h" | "percent_change_1h" | "percent_change_24h" | "percent_change_7d" | "market_cap_by_total_supply_strict" | "volume_7d" | " volume_30d"
58 changes: 28 additions & 30 deletions app/components/CurrencyQuotes/Dialog.vue
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
<script setup lang="ts">
import {Button} from "@/components/ui/button";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
DialogClose,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
DialogClose,
} from "@/components/ui/dialog";
import {useCurrencyQuotesStore} from "@/stores/useCurrencyQuotesStore";
import {ref, watch} from "vue";
import {Cross2Icon} from "@radix-icons/vue";
import {CurrencyQuotesDto} from "@/components/Dto/CurrencyQuotesDto";
import {t} from "i18next";
import { useCurrencyQuotesStore } from "@/stores/useCurrencyQuotesStore";
import { ref, watch } from "vue";
import { Cross2Icon } from "@radix-icons/vue";
import { CurrencyQuotesDto } from "@/components/Dto/CurrencyQuotesDto";
import { t } from "i18next";
import numberFormatter from "@/utils/numberFormatter";
const currencyQuotesStore = useCurrencyQuotesStore();
const props = defineProps<{result: number | undefined; open: boolean}>();
const emit = defineEmits(["update:open"]);
const props = defineProps<{ result: number | undefined; open: boolean }>();
const emit = defineEmits([ "update:open" ]);
const isOpen = ref(props.open);
watch(
() => props.open,
(newVal) => {
isOpen.value = newVal;
},
() => props.open,
(newVal) => {
isOpen.value = newVal;
},
);
watch(isOpen, (newVal) => {
emit("update:open", newVal);
emit("update:open", newVal);
});
watch(
() => currencyQuotesStore.leftCode,
(value) => {
console.log(CurrencyQuotesDto[currencyQuotesStore.leftCode]);
currencyQuotesStore.leftCode = value;
},
() => currencyQuotesStore.leftCode,
(value) => {
currencyQuotesStore.leftCode = value;
},
);
watch(
() => currencyQuotesStore.rightCode,
(value) => {
console.log(CurrencyQuotesDto[currencyQuotesStore.rightCode]);
currencyQuotesStore.rightCode = value;
},
() => currencyQuotesStore.rightCode,
(value) => {
currencyQuotesStore.rightCode = value;
},
);
</script>

Expand Down
Loading

0 comments on commit afe1682

Please sign in to comment.