yhtx 1.0.1 → 1.0.3
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/index.js +23 -21
- package/index2.js +113 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,7 +2,14 @@ const crypto = require("crypto");
|
|
|
2
2
|
const axios = require("axios");
|
|
3
3
|
|
|
4
4
|
function getSign(queryString, secret, method, path) {
|
|
5
|
-
let signString = [
|
|
5
|
+
let signString = [
|
|
6
|
+
method,
|
|
7
|
+
path.includes("linear-swap-api") ? "api.hbdm.com" : "api.huobi.pro",
|
|
8
|
+
path,
|
|
9
|
+
queryString || undefined,
|
|
10
|
+
]
|
|
11
|
+
.filter(Boolean)
|
|
12
|
+
.join("\n");
|
|
6
13
|
return crypto.createHmac("sha256", secret).update(signString).digest("base64");
|
|
7
14
|
}
|
|
8
15
|
|
|
@@ -11,7 +18,9 @@ async function call(path, { apiKey, secret, data, method, recvWindow } = {}) {
|
|
|
11
18
|
secret ||= "";
|
|
12
19
|
method ||= "GET";
|
|
13
20
|
recvWindow ??= 30000;
|
|
14
|
-
const origin = "
|
|
21
|
+
const origin = path.includes("linear-swap-api")
|
|
22
|
+
? "https://api.hbdm.com" //UM //for debig:https:api.btcgateway.pro, aws:https://api.hbdm.vn
|
|
23
|
+
: "https://api.huobi.pro"; //spot //https:api-aws.huobi.pro
|
|
15
24
|
data ||= {};
|
|
16
25
|
|
|
17
26
|
let timestamp = Date.now();
|
|
@@ -19,49 +28,42 @@ async function call(path, { apiKey, secret, data, method, recvWindow } = {}) {
|
|
|
19
28
|
let sign;
|
|
20
29
|
|
|
21
30
|
timestamp = new Date(timestamp).toISOString().slice(0, 19);
|
|
22
|
-
|
|
31
|
+
let preBody = {
|
|
23
32
|
AccessKeyId: apiKey,
|
|
24
|
-
SignatureMethod: "HmacSHA256",
|
|
33
|
+
SignatureMethod: "HmacSHA256", //Ed25519
|
|
25
34
|
SignatureVersion: 2,
|
|
26
35
|
Timestamp: timestamp,
|
|
36
|
+
};
|
|
37
|
+
body = {
|
|
38
|
+
...preBody,
|
|
27
39
|
...data,
|
|
28
40
|
};
|
|
41
|
+
|
|
29
42
|
let pars = [];
|
|
30
|
-
for (let k in
|
|
43
|
+
for (let k in method == "GET" ? body : preBody)
|
|
44
|
+
pars.push(k + "=" + encodeURIComponent(body[k]));
|
|
31
45
|
let queryString = pars.sort().join("&");
|
|
32
46
|
|
|
33
|
-
if (
|
|
47
|
+
if (method === "POST") {
|
|
34
48
|
url = origin + path + "?" + queryString;
|
|
35
49
|
sign = getSign(queryString, secret, method, path);
|
|
36
50
|
url += `&Signature=${sign}`;
|
|
37
|
-
body.Signature = sign;
|
|
38
51
|
} /*GET*/ else {
|
|
39
52
|
url = origin + path + "?" + queryString;
|
|
40
53
|
sign = getSign(queryString, secret, method, path);
|
|
41
54
|
url += `&Signature=${sign}`;
|
|
42
|
-
body.Signature = sign;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
var headers = {
|
|
46
|
-
// "Content-Type": "application/json",
|
|
47
|
-
// "User-Agent":
|
|
48
|
-
// "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
if (method === "POST") {
|
|
52
|
-
headers["Content-Type"] = "application/json; charset=utf-8";
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
let headers = { "Content-Type": "application/json" };
|
|
58
|
+
let config = {
|
|
56
59
|
method,
|
|
57
60
|
url,
|
|
58
61
|
headers,
|
|
59
|
-
...
|
|
62
|
+
...(method == "POST" && { data }), //must be "data" //if GET, don't send
|
|
60
63
|
};
|
|
61
64
|
|
|
62
65
|
let r = await axios(config)
|
|
63
66
|
.then((r) => {
|
|
64
|
-
// log(r);
|
|
65
67
|
if (r.data?.code != 200 /*success*/) console.log(r.data);
|
|
66
68
|
let rs = r.data.data;
|
|
67
69
|
return rs;
|
package/index2.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const crypto = require("crypto");
|
|
2
|
+
const axios = require("axios");
|
|
3
|
+
|
|
4
|
+
function getSign(queryString, secret, method, path) {
|
|
5
|
+
let signString = [
|
|
6
|
+
method,
|
|
7
|
+
path.includes("linear-swap-api") ? "api.hbdm.com" : "api.huobi.pro",
|
|
8
|
+
path,
|
|
9
|
+
queryString,
|
|
10
|
+
].join("\n");
|
|
11
|
+
return crypto.createHmac("sha256", secret).update(signString).digest("base64");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function call(path, { apiKey, secret, data, method, recvWindow } = {}) {
|
|
15
|
+
apiKey ||= "";
|
|
16
|
+
secret ||= "";
|
|
17
|
+
method ||= "GET";
|
|
18
|
+
recvWindow ??= 30000;
|
|
19
|
+
const origin = path.includes("linear-swap-api")
|
|
20
|
+
? "https://api.hbdm.com" //UM //for debig:https:api.btcgateway.pro, aws:https://api.hbdm.vn
|
|
21
|
+
: "https://api.huobi.pro"; //spot //https:api-aws.huobi.pro
|
|
22
|
+
data ||= {};
|
|
23
|
+
|
|
24
|
+
let timestamp = Date.now();
|
|
25
|
+
let url;
|
|
26
|
+
let sign;
|
|
27
|
+
|
|
28
|
+
timestamp = new Date(timestamp).toISOString().slice(0, 19);
|
|
29
|
+
let preBody = {
|
|
30
|
+
AccessKeyId: apiKey,
|
|
31
|
+
SignatureMethod: "HmacSHA256", //Ed25519
|
|
32
|
+
SignatureVersion: 2,
|
|
33
|
+
Timestamp: timestamp,
|
|
34
|
+
};
|
|
35
|
+
body = {
|
|
36
|
+
...preBody,
|
|
37
|
+
...data,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let pars = [];
|
|
41
|
+
for (let k in body) pars.push(k + "=" + encodeURIComponent(body[k]));
|
|
42
|
+
let queryString = pars.sort().join("&");
|
|
43
|
+
|
|
44
|
+
if (/*payload not yet supported*/ method === "POST") {
|
|
45
|
+
url = origin + path + "?" + queryString;
|
|
46
|
+
sign = getSign(queryString, secret, method, path);
|
|
47
|
+
url += `&Signature=${sign}`;
|
|
48
|
+
body.Signature = sign;
|
|
49
|
+
} /*GET*/ else {
|
|
50
|
+
url = origin + path + "?" + queryString;
|
|
51
|
+
sign = getSign(queryString, secret, method, path);
|
|
52
|
+
url += `&Signature=${sign}`;
|
|
53
|
+
body.Signature = sign;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var headers = {
|
|
57
|
+
// "Content-Type": "application/json",
|
|
58
|
+
// "User-Agent":
|
|
59
|
+
// "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36",
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (method === "POST") {
|
|
63
|
+
headers["Content-Type"] = "application/json; charset=utf-8";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var config = {
|
|
67
|
+
method,
|
|
68
|
+
url,
|
|
69
|
+
headers,
|
|
70
|
+
...body,
|
|
71
|
+
data,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
let r = await axios(config)
|
|
75
|
+
.then((r) => {
|
|
76
|
+
// log(r);
|
|
77
|
+
if (r.data?.code != 200 /*success*/) console.log(r.data);
|
|
78
|
+
let rs = r.data.data;
|
|
79
|
+
return rs;
|
|
80
|
+
})
|
|
81
|
+
.catch(function (e) {
|
|
82
|
+
console.log(e.response.data);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class api {
|
|
89
|
+
constructor(apiKey = "", secret = "") {
|
|
90
|
+
this.apiKey = apiKey;
|
|
91
|
+
this.secret = secret;
|
|
92
|
+
}
|
|
93
|
+
async get(path, pr = {}) {
|
|
94
|
+
let data = {
|
|
95
|
+
apiKey: this.apiKey,
|
|
96
|
+
secret: this.secret,
|
|
97
|
+
data: pr,
|
|
98
|
+
};
|
|
99
|
+
return call(path, data);
|
|
100
|
+
}
|
|
101
|
+
async post(path, pr = {}) {
|
|
102
|
+
let data = {
|
|
103
|
+
apiKey: this.apiKey,
|
|
104
|
+
secret: this.secret,
|
|
105
|
+
method: "POST",
|
|
106
|
+
data: pr,
|
|
107
|
+
};
|
|
108
|
+
return call(path, data);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = api;
|
|
113
|
+
module.exports.call = call;
|