├── logo.png ├── .DS_Store ├── src ├── index.ts ├── cache.ts ├── types │ ├── crypto_types.ts │ ├── forex_types.ts │ └── stocks_types.ts ├── stocks.ts ├── forex.ts └── crypto.ts ├── tsconfig.json ├── package.json ├── LICENSE ├── .gitignore └── README.md /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayankTamakuwala/WealthSyncPro/HEAD/logo.png -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MayankTamakuwala/WealthSyncPro/HEAD/.DS_Store -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | // src/index.ts 2 | import * as stocks from "./stocks"; 3 | import * as crypto from "./crypto"; 4 | import * as forex from "./forex"; 5 | 6 | export { stocks, crypto, forex }; 7 | -------------------------------------------------------------------------------- /src/cache.ts: -------------------------------------------------------------------------------- 1 | // src/cache.ts 2 | import NodeCache from "node-cache"; 3 | 4 | const cache = new NodeCache({ stdTTL: 60 * 3 }); // Cache for 3 minutes 5 | 6 | const getCachedData = (key: string): T | undefined => cache.get(key); 7 | const setCachedData = (key: string, value: T): boolean => 8 | cache.set(key, value); 9 | 10 | export { getCachedData, setCachedData }; 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2018", 4 | "module": "commonjs", 5 | "strict": true, 6 | "esModuleInterop": true, 7 | "skipLibCheck": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "outDir": "./dist", 10 | "rootDir": "./src" 11 | }, 12 | "include": [ 13 | "src/**/*" 14 | ], 15 | "exclude": [ 16 | "node_modules" 17 | ] 18 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wealthsync-pro", 3 | "version": "1.1.2", 4 | "description": "An NPM package that aggregates financial data from various APIs", 5 | "main": "dist/index.js", 6 | "types": "dist/index.d.ts", 7 | "scripts": { 8 | "build": "tsc", 9 | "prepare": "npm run build", 10 | "start": "node dist/index.js" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC, MIT", 15 | "dependencies": { 16 | "node-cache": "^5.1.2" 17 | }, 18 | "devDependencies": { 19 | "@types/node": "^14.14.31", 20 | "@types/node-cache": "^4.2.5", 21 | "typescript": "^4.2.3" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Mayank Tamakuwala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/types/crypto_types.ts: -------------------------------------------------------------------------------- 1 | export type Coin = { 2 | uuid: string; 3 | iconUrl: string; 4 | name: string; 5 | symbol: string; 6 | price: string; 7 | } 8 | 9 | export type CryptoData = { 10 | status: string; 11 | data: { 12 | coin: { 13 | uuid: string; 14 | symbol: string; 15 | name: string; 16 | description: string; 17 | color: string; 18 | iconUrl: string; 19 | websiteUrl: string; 20 | links: Array<{ 21 | name: string; 22 | url: string; 23 | type: string; 24 | }>; 25 | supply: { 26 | confirmed: boolean; 27 | supplyAt: number; 28 | max: null; 29 | total: string; 30 | circulating: string; 31 | }; 32 | numberOfMarkets: number; 33 | numberOfExchanges: number; 34 | "24hVolume": string; 35 | marketCap: string; 36 | fullyDilutedMarketCap: string; 37 | price: string; 38 | btcPrice: string; 39 | priceAt: number; 40 | change: string; 41 | rank: number; 42 | sparkline: Array; 43 | allTimeHigh: { 44 | price: string; 45 | timestamp: number; 46 | }; 47 | coinrankingUrl: string; 48 | tier: number; 49 | lowVolume: boolean; 50 | listedAt: number; 51 | hasContent: boolean; 52 | notices: null; 53 | contractAddresses: Array; 54 | tags: Array; 55 | }; 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /src/types/forex_types.ts: -------------------------------------------------------------------------------- 1 | export type ExchangeRate = { 2 | from: string; 3 | to: string; 4 | rate: number; 5 | trend: "down" | "up"; 6 | rateChange: number; 7 | percentageChange: number; 8 | } 9 | 10 | export const CURRENCIES = ["ADA","AED","AFN","ALL","AMD","ANG","AOA","ARS","ATS","AUD","AWG","AZM","AZN","BAM","BBD","BCH","BDT","BEF","BGN","BHD","BIF","BMD","BND","BOB","BRL","BSD","BTC","BTN","BWP","BYN","BYR","BZD","CAD","CDF","CHF","CLF","CLP","CNH","CNY","COP","CRC","CUC","CUP","CVE","CYP","CZK","DEM","DJF","DKK","DOGE","DOP","DOT","DZD","EEK","EGP","ERN","ESP","ETB","ETH","EUR","FIM","FJD","FKP","FRF","GBP","GEL","GGP","GHC","GHS","GIP","GMD","GNF","GRD","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","IEP","ILS","IMP","INR","IQD","IRR","ISK","ITL","JEP","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LINK","LKR","LRD","LSL","LTC","LTL","LUF","LUNA","LVL","LYD","MAD","MDL","MGA","MGF","MKD","MMK","MNT","MOP","MRO","MRU","MTL","MUR","MVR","MWK","MXN","MXV","MYR","MZM","MZN","NAD","NGN","NIO","NLG","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKR","PLN","PTE","PYG","QAR","ROL","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDD","SDG","SEK","SGD","SHP","SIT","SKK","SLE","SLL","SOS","SPL","SRD","SRG","STD","STN","SVC","SYP","SZL","THB","TJS","TMM","TMT","TND","TOP","TRL","TRY","TTD","TVD","TWD","TZS","UAH","UGX","UNI","USD","UYU","UZS","VAL","VEB","VED","VEF","VES","VND","VUV","WST","XAF","XAG","XAU","XBT","XCD","XDR","XLM","XOF","XPD","XPF","XPT","XRP","YER","ZAR","ZMK","ZMW","ZWD","ZWG","ZWL",]; 11 | -------------------------------------------------------------------------------- /src/stocks.ts: -------------------------------------------------------------------------------- 1 | // src/stocks.ts 2 | import { getCachedData, setCachedData } from "./cache"; 3 | import { StockData } from "./types/stocks_types"; 4 | 5 | const headers: HeadersInit = { 6 | Accept: "*/*", 7 | "Accept-Encoding": "gzip, deflate, br", 8 | "Accept-Language": "en-US,en;q=0.9", 9 | Connection: "keep-alive", 10 | Cookie: 11 | "axids=gam=y-USdS87RE2uJGi.N0VuHGUcS4JNHLDKcY~A&dv360=eS1kd0RyVkYxRTJ1SGFaR3FtN25wY0Jld0JuZ3VNMVNSRn5B&ydsp=y-1muHCMZE2uIKr54BV8upK_dslERPGchO~A&tbla=y-esjZMn1E2uLPpDNzgr_K5KLrJQBSNjce~A; tbla_id=16799d63-e9f4-46a8-8524-f84477af5f14-tuctd9ee196; PRF=t%3DTSLA; cmp=t=1722113045&j=0&u=1YNN; gpp=DBAA; gpp_sid=-1; A1=d=AQABBBNcpWYCEA7oK21_A0kuIZlVbDBF6ooFEgEBAQGtpmavZtwx0iMA_eMAAA&S=AQAAAtl8oGAwMwMDtRLyDalqASw; A1S=d=AQABBBNcpWYCEA7oK21_A0kuIZlVbDBF6ooFEgEBAQGtpmavZtwx0iMA_eMAAA&S=AQAAAtl8oGAwMwMDtRLyDalqASw; A3=d=AQABBBNcpWYCEA7oK21_A0kuIZlVbDBF6ooFEgEBAQGtpmavZtwx0iMA_eMAAA&S=AQAAAtl8oGAwMwMDtRLyDalqASw", 12 | Host: "query1.finance.yahoo.com", 13 | Origin: "https://finance.yahoo.com", 14 | "Sec-Fetch-Dest": "empty", 15 | "Sec-Fetch-Mode": "cors", 16 | "Sec-Fetch-Site": "same-site", 17 | "User-Agent": 18 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15", 19 | }; 20 | 21 | /** 22 | * Retrieves stock data for a given symbol from Yahoo Finance API. 23 | * If cached data is available, it returns the cached data instead of making a new request. 24 | * 25 | * @param symbol The stock symbol to retrieve data for. 26 | * @returns A promise that resolves to the stock data. 27 | */ 28 | const getStockData = async (symbol: string): Promise => { 29 | const cachedData = getCachedData(symbol); 30 | if (cachedData) return cachedData; 31 | 32 | const url = `https://query1.finance.yahoo.com/v8/finance/chart/${symbol}?interval=1m&includePrePost=true&events=div%7Csplit%7Cearn&lang=en-US®ion=US`; 33 | try { 34 | const response = await fetch(url, { 35 | headers: { 36 | ...headers, 37 | Referer: `https://finance.yahoo.com/quote/${symbol}/`, 38 | }, 39 | }); 40 | const data = await response.json(); 41 | 42 | setCachedData(symbol, data); 43 | return data; 44 | } catch (error) { 45 | if (error instanceof Error) { 46 | throw new Error(error.message); 47 | } else { 48 | throw new Error(String(error)); 49 | } 50 | } 51 | }; 52 | 53 | export { getStockData }; 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | -------------------------------------------------------------------------------- /src/types/stocks_types.ts: -------------------------------------------------------------------------------- 1 | export type StockData = { 2 | chart: { 3 | result: [ 4 | { 5 | meta: { 6 | currency: string; 7 | symbol: string; 8 | exchangeName: string; 9 | fullExchangeName: string; 10 | instrumentType: string; 11 | firstTradeDate: number; 12 | regularMarketTime: number; 13 | hasPrePostMarketData: boolean; 14 | gmtoffset: number; 15 | timezone: string; 16 | exchangeTimezoneName: string; 17 | regularMarketPrice: number; 18 | fiftyTwoWeekHigh: number; 19 | fiftyTwoWeekLow: number; 20 | regularMarketDayHigh: number; 21 | regularMarketDayLow: number; 22 | regularMarketVolume: number; 23 | chartPreviousClose: number; 24 | previousClose: number; 25 | scale: number; 26 | priceHint: number; 27 | currentTradingPeriod: { 28 | pre: { 29 | timezone: string; 30 | start: number; 31 | end: number; 32 | gmtoffset: number; 33 | }; 34 | regular: { 35 | timezone: string; 36 | start: number; 37 | end: number; 38 | gmtoffset: number; 39 | }; 40 | post: { 41 | timezone: string; 42 | start: number; 43 | end: number; 44 | gmtoffset: number; 45 | }; 46 | }; 47 | tradingPeriods: { 48 | pre: [ 49 | [ 50 | { 51 | timezone: string; 52 | start: number; 53 | end: number; 54 | gmtoffset: number; 55 | } 56 | ] 57 | ]; 58 | post: [ 59 | [ 60 | { 61 | timezone: string; 62 | start: number; 63 | end: number; 64 | gmtoffset: number; 65 | } 66 | ] 67 | ]; 68 | regular: [ 69 | [ 70 | { 71 | timezone: string; 72 | start: number; 73 | end: number; 74 | gmtoffset: number; 75 | } 76 | ] 77 | ]; 78 | }; 79 | dataGranularity: string; 80 | range: string; 81 | validRanges: Array; 82 | }; 83 | timestamp: Array; 84 | indicators: { 85 | quote: [ 86 | { 87 | close: Array; 88 | volume: Array; 89 | low: Array; 90 | high: Array; 91 | open: Array; 92 | } 93 | ]; 94 | }; 95 | } 96 | ]; 97 | error: null; 98 | }; 99 | }; 100 | -------------------------------------------------------------------------------- /src/forex.ts: -------------------------------------------------------------------------------- 1 | // src/forex.ts 2 | import { getCachedData, setCachedData } from "./cache"; 3 | import { ExchangeRate, CURRENCIES } from "./types/forex_types"; 4 | 5 | const headers: HeadersInit = { 6 | "User-Agent": 7 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0", 8 | Accept: "*/*", 9 | "Accept-Language": "en-US,en;q=0.5", 10 | "Accept-Encoding": "gzip, deflate, br, zstd", 11 | Referer: "https://www.xe.com/currencycharts/", 12 | authorization: "Basic bG9kZXN0YXI6cHVnc25heA==", 13 | Connection: "keep-alive", 14 | Cookie: 15 | "homepage-test=oldCore; amp_470887=fGWDWp-CKGMxAEjPWSmRyw...1i3qps6mo.1i3qps6mt.1.1.2; _ga_KRKJ3PLCP1=GS1.1.1722107698.1.0.1722107717.41.0.0; _ga=GA1.2.1217575113.1722107698; _gid=GA1.2.251026674.1722107698; _dc_gtm_UA-183969431-1=1; IR_gbd=xe.com; IR_12610=1722107698129%7C0%7C1722107698129%7C%7C; _uetsid=83d3b3604c4c11ef8667a9ae9647c7c3; _uetvid=83d39f704c4c11efbca13ba42c15e507; _fbp=fb.1.1722107698494.3491396618848408; _y2=1%3AeyJjIjp7IjI0NzE0NSI6MjQ4MTIzNzEzfX0%3D%3ALTEzMDM1OTEwMDg%3D%3A2; _yi=1%3AeyJsaSI6eyJjIjowLCJjb2wiOjMxMjIwODM5MTksImNwZyI6MjQ3MTQ0LCJjcGkiOjk2Nzg0NjAxNDkwLCJzYyI6MSwidHMiOjE3MjIxMDc3MTMxODB9LCJzZSI6eyJjIjoxLCJlYyI6MTUsImxhIjoxNzIyMTA3NzE2MjM1LCJwIjoxLCJzYyI6MTd9LCJ1Ijp7ImlkIjoiYWVkZDlhOGYtNTEyZi00Njc2LTkzMWQtNzVkYjYzNmUxOTlhIiwiZmwiOiIwIn19%3ALTE0MzE4NDYxMTI%3D%3A2", 16 | "Sec-Fetch-Dest": "empty", 17 | "Sec-Fetch-Mode": "cors", 18 | "Sec-Fetch-Site": "same-origin", 19 | }; 20 | 21 | /** 22 | * Retrieves the exchange rate for a given currency pair from XE.com API. 23 | * If cached data is available, it returns the cached data instead of making a new request. 24 | * 25 | * @param from_currency The currency to convert from. 26 | * @param to_currency The currency to convert to. 27 | * @returns A promise that resolves to the exchange rate object. 28 | */ 29 | const getExchangeRates = async ( 30 | from_currency: string, 31 | to_currency: string 32 | ): Promise => { 33 | 34 | if (CURRENCIES.indexOf(from_currency) == -1) { 35 | throw Error(`404 Not Found: 'from_currency' is not available. These are the currencies you can choose from\n\n${CURRENCIES.toString()}`); 36 | } else if (CURRENCIES.indexOf(to_currency) == -1) { 37 | throw Error(`404 Not Found: 'to_currency' is not available. These are the currencies you can choose from\n\n${CURRENCIES.toString()}`); 38 | } 39 | 40 | const pair = `exchange_${from_currency}_${to_currency}`; 41 | const cachedData = getCachedData(pair); 42 | if (cachedData) return cachedData; 43 | 44 | const url = `https://www.xe.com/api/protected/live-currency-rates?currencyPairs=${from_currency}/${to_currency}`; 45 | 46 | try { 47 | const response = await fetch(url, { 48 | headers: headers, 49 | }); 50 | const data = (await response.json())[0]; 51 | 52 | setCachedData(pair, data); 53 | return data; 54 | } catch (error) { 55 | if (error instanceof Error) { 56 | throw new Error(error.message); 57 | } else { 58 | throw new Error(String(error)); 59 | } 60 | } 61 | }; 62 | 63 | export { getExchangeRates }; 64 | -------------------------------------------------------------------------------- /src/crypto.ts: -------------------------------------------------------------------------------- 1 | // src/crypto.ts 2 | import { getCachedData, setCachedData } from "./cache"; 3 | import { Coin, CryptoData } from "./types/crypto_types"; 4 | 5 | const BASE_URL = "https://coinranking.com/api/v2"; 6 | 7 | const headers: HeadersInit = { 8 | Referer: "https://coinranking.com/", 9 | Accept: "application/json, text/plain, */*", 10 | "Accept-Encoding": "gzip, deflate, br", 11 | "Accept-Language": "en-US,en;q=0.9", 12 | Connection: "keep-alive", 13 | Host: "coinranking.com", 14 | "Sec-Fetch-Dest": "empty", 15 | "Sec-Fetch-Mode": "cors", 16 | "Sec-Fetch-Site": "same-origin", 17 | "User-Agent": 18 | "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15", 19 | }; 20 | 21 | /** 22 | * Searches for coins by symbol and returns a list of matching coins. 23 | * If cached data is available, it returns the cached data instead of making a new request. 24 | * 25 | * @param symbol The symbol of the coin to search for. 26 | * @returns A promise that resolves to a list of matching coins. 27 | */ 28 | const searchCoins = async (symbol: string): Promise => { 29 | const cacheKey = `search_suggestions_${symbol}`; 30 | const cachedData = getCachedData(cacheKey); 31 | if (cachedData) return cachedData; 32 | 33 | const url = `${BASE_URL}/search-suggestions?query=${symbol}&referenceCurrencyUuid=yhjMzLPhuIDl`; 34 | 35 | try { 36 | const response = await fetch(url, { 37 | method: "GET", 38 | headers: headers, 39 | }); 40 | const data = (await response.json()).data.coins; 41 | 42 | setCachedData(cacheKey, data); 43 | return data; 44 | } catch (error) { 45 | if (error instanceof Error) { 46 | throw new Error(error.message); 47 | } else { 48 | throw new Error(String(error)); 49 | } 50 | } 51 | }; 52 | 53 | /** 54 | * Retrieves the real-time data for a specific coin by ID. 55 | * If cached data is available, it returns the cached data instead of making a new request. 56 | * 57 | * @param coinId The ID of the coin to retrieve data for. 58 | * @returns A promise that resolves to the coin data. 59 | */ 60 | const getCoinData = async (coinId: string): Promise => { 61 | const cacheKey = `crypto_${coinId}`; 62 | const cachedData = getCachedData(cacheKey); 63 | if (cachedData) return cachedData; 64 | 65 | const url = `${BASE_URL}/coin/${coinId}?referenceCurrencyUuid=yhjMzLPhuIDl&timePeriod=24h`; 66 | 67 | try { 68 | const response = await fetch(url, { 69 | method: "GET", 70 | headers: headers, 71 | }); 72 | const data = await response.json(); 73 | 74 | setCachedData(cacheKey, data); 75 | return data; 76 | } catch (error) { 77 | if (error instanceof Error) { 78 | throw new Error(error.message); 79 | } else { 80 | throw new Error(String(error)); 81 | } 82 | } 83 | }; 84 | 85 | /** 86 | * Retrieves the real-time data for the top 100 crypto coins based on their market value. 87 | * If cached data is available, it returns the cached data instead of making a new request. 88 | * 89 | * @returns A promise that resolves to the data for the top 100 crypto coins. 90 | */ 91 | const getTop100CryptoCoinsData = async (): Promise => { 92 | const cacheKey = "crypto_top_100"; 93 | const cachedData = getCachedData(cacheKey); 94 | if (cachedData) return cachedData; 95 | 96 | const url = `${BASE_URL}/coins?offset=0&orderBy=marketCap&limit=100&orderDirection=desc&timePeriod=24h&tiers%5B%5D=1&tiers%5B%5D=2`; 97 | 98 | try { 99 | const response = await fetch(url, { 100 | method: "GET", 101 | headers: headers, 102 | }); 103 | const data = await response.json(); 104 | 105 | setCachedData(cacheKey, data); 106 | return data; 107 | } catch (error) { 108 | if (error instanceof Error) { 109 | throw new Error(error.message); 110 | } else { 111 | throw new Error(String(error)); 112 | } 113 | } 114 | }; 115 | 116 | export { getCoinData, getTop100CryptoCoinsData, searchCoins }; 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |

WealthSync Pro

4 | License: MIT 5 |
6 | 7 | # WealthSync Pro 8 | 9 | Welcome to WealthSync Pro, an npm package designed for seamless finance aggregation. Say goodbye to the challenges of managing API keys, wading through extensive documentation, and dealing with endless subscriptions. WealthSync Pro provides unlimited, streamlined, and hassle-free access to real-time financial data without the need for API keys. 10 | 11 | ## Features 12 | 13 | ### Cryptocurrency Data 14 | 15 | - Real-time Data: Access real-time information on the top 100 cryptocurrencies based on market value. 16 | - Detailed Information: Retrieve detailed data for specific cryptocurrencies via symbol input, including the latest data needed for accurate real-time graphics. 17 | - Source: Reverse-engineered from the Coinrank API. 18 | 19 | ### Foreign Exchange Data 20 | 21 | - Real-time Conversion Rates: Get real-time conversion rates between selected countries. 22 | - Source: Reverse-engineered from the XE API. 23 | 24 | ### Stock Exchange Data 25 | 26 | - Real-time Stock Information: Retrieve real-time information about stocks using stock acronyms. Get data such as the highest and lowest bids, closing market price, and the latest data needed for accurate real-time graphics. 27 | - Source: Reverse-engineered from the Yahoo Finance API. 28 | 29 | ## Upcoming Features 30 | 31 | ### Enhanced Cryptocurrency and Stock Functions 32 | 33 | - Provide more comprehensive information for each cryptocurrency and stock, such as the current allotted amount of a specific stock or cryptocurrency. 34 | 35 | ### Improved Foreign Exchange Features 36 | 37 | - Allow users to specify amounts for conversions beyond specific country exchanges. 38 | 39 | ### Financial Calculators and Advising 40 | 41 | - Add tools for personal finance management and AI advising to further enrich the package. 42 | 43 | ## Installation 44 | 45 | Install WealthSync Pro using npm: 46 | 47 | ``` 48 | npm install wealthsync-pro 49 | ``` 50 | 51 | ## Usage 52 | 53 | Here’s how to use WealthSync Pro to access different types of financial data: 54 | 55 | ### Import 56 | 57 | ``` 58 | const { crypto, forex, stocks } = require('wealthsync-pro'); 59 | ``` 60 | 61 | ### Cryptocurrency Data 62 | 63 | ``` 64 | // Get real-time data on top 100 cryptocurrencies 65 | const top100 = async() => { 66 | await crypto.getTop100CryptoCoinsData() 67 | .then(data => console.log(data)) 68 | .catch(err => console.error(err)); 69 | } 70 | 71 | // Get detailed information for a specific cryptocurrency 72 | const info = async() => { 73 | await crypto.searchCoins('BTC') 74 | .then(coins => { 75 | const coinId = coins[0].uuid; 76 | return crypto.getCoinData(coinId); 77 | }) 78 | .then(data => console.log(data)) 79 | .catch(err => console.error(err)); 80 | } 81 | ``` 82 | 83 | ### Foreign Exchange Data 84 | 85 | ``` 86 | // Get real-time conversion rates between selected countries 87 | const rates = async() => { 88 | forex.getExchangeRates('USD', 'EUR') 89 | .then(data => console.log(data)) 90 | .catch(err => console.error(err)); 91 | } 92 | ``` 93 | 94 | ### Stock Exchange Data 95 | 96 | ``` 97 | // Get real-time information about a specific stock 98 | const stockdata = async() => { 99 | stocks.getStockData('AAPL') 100 | .then(data => console.log(data)) 101 | .catch(err => console.error(err)); 102 | } 103 | ``` 104 | 105 | ## Disclaimer 106 | 107 | This package reverse engineers proprietary finance APIs. Use it at your own risk. The authors are not responsible for any misuse or legal issues that may arise from using this package. 108 | 109 | Thank you for using WealthSync Pro! We hope you find it as exciting and useful as we do. 110 | --------------------------------------------------------------------------------