google-finance-quote 2.0.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -22
- package/index.d.ts +0 -15
- package/index.js +1 -35
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# google-finance-quote
|
|
2
|
+
|
|
2
3
|
Node Google Finance API wrapper for free.
|
|
3
4
|
No API key is required!
|
|
4
5
|
> Note: This results may vary by up to 20 minutes.
|
|
6
|
+
> Note: `3.0.0 <= x` doesn't support proxies.
|
|
7
|
+
|
|
5
8
|
## Usage
|
|
9
|
+
|
|
6
10
|
### Get Started
|
|
11
|
+
|
|
7
12
|
```js
|
|
8
13
|
const { Finance, symbols, currencyCodesSymbols, cryptoCurrencyCodesSymbols } = require("google-finance-quote");
|
|
9
14
|
|
|
@@ -12,15 +17,6 @@ console.log(currencyCodesSymbols); // Returns available currency codes symbols.
|
|
|
12
17
|
console.log(cryptoCurrencyCodesSymbols); // Returns available crypto currency codes symbols.
|
|
13
18
|
|
|
14
19
|
const finance = new Finance(); // You can use this: new Finance({ from 'USD', to: 'JPY' });
|
|
15
|
-
// You can use http(s) proxies.
|
|
16
|
-
/*
|
|
17
|
-
const proxy = {
|
|
18
|
-
host: 'example.com',
|
|
19
|
-
port: 2000,
|
|
20
|
-
protocol: 'http'
|
|
21
|
-
}
|
|
22
|
-
const finance = new Finance({ proxy });
|
|
23
|
-
*/
|
|
24
20
|
|
|
25
21
|
finance
|
|
26
22
|
.setFrom('USD');
|
|
@@ -30,21 +26,18 @@ finance
|
|
|
30
26
|
console.log(await finance.quote()); // { success: true, rate: 150.94225699999998 }
|
|
31
27
|
})();
|
|
32
28
|
```
|
|
33
|
-
### Class
|
|
34
|
-
<strong>Finance({ from?:string, to?:string, proxy?:object })</strong>
|
|
35
29
|
|
|
36
|
-
###
|
|
37
|
-
- <strong>.setFrom(from: string)</strong>
|
|
38
|
-
Set the parameter of from.
|
|
30
|
+
### Class
|
|
39
31
|
|
|
40
|
-
-
|
|
41
|
-
Set the parameter of to.
|
|
32
|
+
- **Finance({ from?: string, to?: string })**
|
|
42
33
|
|
|
43
|
-
-
|
|
44
|
-
|
|
34
|
+
- **.setFrom(from: string)**
|
|
35
|
+
Set the parameter of from.
|
|
36
|
+
- **.setTo(to: string)**
|
|
37
|
+
Set the parameter of to.
|
|
38
|
+
- **.getParam(): object**
|
|
39
|
+
Returns the current param.
|
|
40
|
+
- **.quote(amount?: number): Promise<{ success: boolean, rate: number }>**
|
|
41
|
+
Returns the converted amount based on the exchange rate.
|
|
45
42
|
|
|
46
|
-
- <strong>.quote(amount?: number): Promise<{ success: boolean, rate: number }></strong>
|
|
47
|
-
Returns the converted amount based on the exchange rate.
|
|
48
43
|
> Note: If the current rate cannot be obtained due to rate limits or network errors, success: false is returned.
|
|
49
|
-
## Get Support
|
|
50
|
-
<a href="https://discord.gg/yKW8wWKCnS"><img src="https://discordapp.com/api/guilds/1005287561582878800/widget.png?style=banner4" alt="Discord Banner"/></a>
|
package/index.d.ts
CHANGED
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
declare module 'google-finance-quote' {
|
|
2
|
-
/**
|
|
3
|
-
* @interface Proxy
|
|
4
|
-
* @description Interface for proxy parameters.
|
|
5
|
-
* @property {string} host - Proxy host name.
|
|
6
|
-
* @property {number | undefined} - Proxy port number.
|
|
7
|
-
* @property {'http' | 'https'} protocol - Proxy protocol type.
|
|
8
|
-
*/
|
|
9
|
-
interface Proxy {
|
|
10
|
-
host: string;
|
|
11
|
-
port?: number,
|
|
12
|
-
protocol: 'http' | 'https';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
2
|
/**
|
|
16
3
|
* @interface FinanceParams
|
|
17
4
|
* @description Interface for Finance class constructor parameters.
|
|
18
5
|
* @property {string} from - The original currency symbol.
|
|
19
6
|
* @property {string} to - The desired currency symbol.
|
|
20
|
-
* @property {Proxy | undefined} proxy - Proxy options.
|
|
21
7
|
*/
|
|
22
8
|
interface FinanceParams {
|
|
23
9
|
from: string;
|
|
24
10
|
to: string;
|
|
25
|
-
proxy?: Proxy;
|
|
26
11
|
}
|
|
27
12
|
|
|
28
13
|
/**
|
package/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const symbols = require('./lib/symbols');
|
|
|
9
9
|
* @param {Object} p - The param includes p.from and p.to.
|
|
10
10
|
* @param {string} p.from - The original currency symbol.
|
|
11
11
|
* @param {string} p.to - The desired currency symbol.
|
|
12
|
-
* @param {object | undefined} p.proxy - Proxy options.
|
|
13
12
|
*/
|
|
14
13
|
class Finance {
|
|
15
14
|
constructor(p) {
|
|
@@ -30,21 +29,6 @@ class Finance {
|
|
|
30
29
|
to: null
|
|
31
30
|
};
|
|
32
31
|
} else throw new Error('Invalid parameters.');
|
|
33
|
-
|
|
34
|
-
this.proxy = {};
|
|
35
|
-
if (typeof p?.proxy === 'object') {
|
|
36
|
-
if (
|
|
37
|
-
typeof p.proxy?.host === 'string' &&
|
|
38
|
-
(
|
|
39
|
-
p.proxy.protocol === 'http' ||
|
|
40
|
-
p.proxy.protocol === 'https'
|
|
41
|
-
)
|
|
42
|
-
) {
|
|
43
|
-
this.proxy.host = p.proxy.host;
|
|
44
|
-
if (typeof p.proxy?.port === 'number') this.proxy.port = p.proxy.port;
|
|
45
|
-
this.proxy.protocol = p.proxy.protocol;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
32
|
}
|
|
49
33
|
|
|
50
34
|
/**
|
|
@@ -96,25 +80,7 @@ class Finance {
|
|
|
96
80
|
|
|
97
81
|
const url = `${API_URL}${from}-${to}`;
|
|
98
82
|
|
|
99
|
-
|
|
100
|
-
if (this.proxy) {
|
|
101
|
-
const axiosConfig = {};
|
|
102
|
-
if (this.proxy.protocol === 'http') {
|
|
103
|
-
axiosConfig.proxy = {
|
|
104
|
-
host: this.proxy.host,
|
|
105
|
-
}
|
|
106
|
-
if (this.proxy.port) axiosConfig.proxy.port = this.proxy.port;
|
|
107
|
-
} else if (this.proxy.protocol === 'https') {
|
|
108
|
-
const proxyUrl = `http://${this.proxy.host}${this.proxy.port ? `:${this.proxy.port}` : ''}`;
|
|
109
|
-
const agent = new HttpsProxyAgent(proxyUrl);
|
|
110
|
-
axiosConfig.httpsAgent = agent;
|
|
111
|
-
axiosConfig.proxy = false;
|
|
112
|
-
}
|
|
113
|
-
response = await axios.get(url, axiosConfig);
|
|
114
|
-
} else {
|
|
115
|
-
response = await axios.get(url);
|
|
116
|
-
}
|
|
117
|
-
|
|
83
|
+
const response = await axios.get(url);
|
|
118
84
|
const html = response.data;
|
|
119
85
|
const startIndex =
|
|
120
86
|
html.indexOf(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-finance-quote",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Node Google Finance API wrapper for free. No API key is required!",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"codes",
|
|
25
25
|
"data",
|
|
26
26
|
"lib",
|
|
27
|
-
"free"
|
|
28
|
-
"proxy"
|
|
27
|
+
"free"
|
|
29
28
|
],
|
|
30
29
|
"author": "otoneko.",
|
|
31
30
|
"license": "ISC",
|
|
@@ -34,8 +33,7 @@
|
|
|
34
33
|
},
|
|
35
34
|
"homepage": "https://github.com/otoneko1102/google-finance-quote#readme",
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"axios": "^1.7.9"
|
|
38
|
-
"https-proxy-agent": "^7.0.6"
|
|
36
|
+
"axios": "^1.7.9"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
39
|
"@types/node": "^22.13.2"
|