@gera2ld/lib-cex 0.0.1 → 0.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/dist/index.js +314 -338
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,351 +1,327 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { delay as
|
|
3
|
-
import { createHmac as
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return s;
|
|
1
|
+
import e from "node:process";
|
|
2
|
+
import { delay as t } from "es-toolkit";
|
|
3
|
+
import { createHmac as n } from "node:crypto";
|
|
4
|
+
new Uint8Array([13, 10]), e.env.CGI_DIR;
|
|
5
|
+
function r(t) {
|
|
6
|
+
let n = e.env[t];
|
|
7
|
+
if (!n) throw Error(`Missing environment variable: ${t}`);
|
|
8
|
+
return n;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region ../../node_modules/.pnpm/@gera2ld+common@file+packages+common/node_modules/@gera2ld/common/dist/index.js
|
|
12
|
+
var i = "=", a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
13
|
+
function o(e, t, n) {
|
|
14
|
+
let r = "", a = 0;
|
|
15
|
+
for (; a < e.length;) {
|
|
16
|
+
let o = e[a++], s = e[a++], c = e[a++];
|
|
17
|
+
if (r += t[o >> 2], r += t[(o & 3) << 4 | (s || 0) >> 4], s == null ? n && (r += i) : r += t[(s & 15) << 2 | (c || 0) >> 6], c == null) {
|
|
18
|
+
n && (r += i);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
r += t[c & 63];
|
|
22
|
+
}
|
|
23
|
+
return r;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
25
|
+
function s(e) {
|
|
26
|
+
return o(e, a, !0);
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
28
|
+
function c(e) {
|
|
29
|
+
return new TextEncoder().encode(e);
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
new Uint8Array([13, 10]);
|
|
32
|
+
var l = {
|
|
33
|
+
maximumFractionDigits: 4,
|
|
34
|
+
exponentialThresholdLarge: 1e6,
|
|
35
|
+
exponentialThresholdSmall: 1e-6,
|
|
36
|
+
minimumSignificantDigits: 2,
|
|
37
|
+
maximumSignificantDigits: 8,
|
|
38
|
+
quantizationStep: 0,
|
|
39
|
+
keepTrailingZeros: !1
|
|
38
40
|
};
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
let r = new Intl.NumberFormat("en-US", o).format(t);
|
|
61
|
-
return !e.keepTrailingZeros && r.includes(".") && (r = r.replace(/\.?0+$/, "")), r;
|
|
41
|
+
function u(e, t) {
|
|
42
|
+
if (e == null || e === "") return "";
|
|
43
|
+
let n = +e;
|
|
44
|
+
if (Number.isNaN(n)) return "";
|
|
45
|
+
let r = {
|
|
46
|
+
...l,
|
|
47
|
+
...t
|
|
48
|
+
};
|
|
49
|
+
r.quantizationStep > 0 && (n = Math.round(n / r.quantizationStep) * r.quantizationStep);
|
|
50
|
+
let i = Math.abs(n), a = r.maximumSignificantDigits;
|
|
51
|
+
if (n !== 0 && (i >= r.exponentialThresholdLarge || i < r.exponentialThresholdSmall)) {
|
|
52
|
+
let e;
|
|
53
|
+
return r.keepTrailingZeros ? e = n.toExponential(Math.max(0, a - 1)) : (e = n.toPrecision(a), e = (+e).toExponential()), e;
|
|
54
|
+
}
|
|
55
|
+
let o = {
|
|
56
|
+
useGrouping: !1,
|
|
57
|
+
notation: "standard"
|
|
58
|
+
};
|
|
59
|
+
t?.maximumFractionDigits === void 0 ? (o.minimumSignificantDigits = r.minimumSignificantDigits, o.maximumSignificantDigits = a) : o.maximumFractionDigits = r.maximumFractionDigits;
|
|
60
|
+
let s = new Intl.NumberFormat("en-US", o).format(n);
|
|
61
|
+
return !r.keepTrailingZeros && s.includes(".") && (s = s.replace(/\.?0+$/, "")), s;
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
var d = [
|
|
64
|
+
["ms", 1],
|
|
65
|
+
["s", 1e3],
|
|
66
|
+
["m", 60],
|
|
67
|
+
["h", 60],
|
|
68
|
+
["d", 24],
|
|
69
|
+
["mo", 30],
|
|
70
|
+
["y", 365 / 30]
|
|
71
71
|
];
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
function f(e, t) {
|
|
73
|
+
let n = Math.sign(e);
|
|
74
|
+
e = Math.abs(e);
|
|
75
|
+
let r = "ms";
|
|
76
|
+
for (let [n, i] of t?.intervalLevels || d) {
|
|
77
|
+
if (e < i) break;
|
|
78
|
+
e /= i, r = n;
|
|
79
|
+
}
|
|
80
|
+
return `${n < 0 ? "-" : ""}${u(e, t) || ""}${r}`;
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/requesters/util.ts
|
|
84
|
+
var p = {};
|
|
85
|
+
function m(e) {
|
|
86
|
+
return new URLSearchParams(Object.entries(e || {}).filter(([, e]) => e != null).map(([e, t]) => [e, `${t}`]));
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
function h(e) {
|
|
89
|
+
let t = Date.now();
|
|
90
|
+
return () => {
|
|
91
|
+
let n = Date.now() - t;
|
|
92
|
+
console.log(`${e}: ${f(n)}`);
|
|
93
|
+
};
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const { id: e, method: i, params: a, nonce: o } = t, r = w(a), c = i + e + n + r + o;
|
|
176
|
-
return g("sha256", s).update(c).digest("hex");
|
|
177
|
-
}
|
|
178
|
-
class E {
|
|
179
|
-
constructor(s, t) {
|
|
180
|
-
this.apiKey = s, this.apiSecret = t;
|
|
181
|
-
}
|
|
182
|
-
static defaultOpts = {
|
|
183
|
-
auth: !0,
|
|
184
|
-
checkResponse: !0,
|
|
185
|
-
method: "GET"
|
|
186
|
-
};
|
|
187
|
-
static create(s) {
|
|
188
|
-
let t = ["CRYPTO_CDC_API_KEY", "CRYPTO_CDC_API_SECRET"];
|
|
189
|
-
s && (t = t.map((a) => `${a}_${s}`));
|
|
190
|
-
const e = d(t[0]), i = d(t[1]);
|
|
191
|
-
return new E(e, i);
|
|
192
|
-
}
|
|
193
|
-
requestId = 0;
|
|
194
|
-
async request(s, t) {
|
|
195
|
-
const e = {
|
|
196
|
-
...E.defaultOpts,
|
|
197
|
-
...t
|
|
198
|
-
}, { auth: i, params: a } = e;
|
|
199
|
-
let { method: o } = e;
|
|
200
|
-
const r = {
|
|
201
|
-
method: s,
|
|
202
|
-
params: e.body
|
|
203
|
-
};
|
|
204
|
-
if (i) {
|
|
205
|
-
const { requestId: f } = this;
|
|
206
|
-
this.requestId += 1;
|
|
207
|
-
const h = Date.now();
|
|
208
|
-
Object.assign(r, {
|
|
209
|
-
id: f,
|
|
210
|
-
nonce: h,
|
|
211
|
-
api_key: this.apiKey
|
|
212
|
-
}), r.sig = M(this.apiKey, this.apiSecret, r);
|
|
213
|
-
}
|
|
214
|
-
const c = r.params || r.sig ? JSON.stringify(r) : null;
|
|
215
|
-
o === "GET" && c && (o = "POST");
|
|
216
|
-
const p = a ? "?" + new URLSearchParams(
|
|
217
|
-
Object.entries(a).map(([f, h]) => [f, `${h}`])
|
|
218
|
-
).toString() : "", u = `https://api.crypto.com/v2/${s}${p}`, l = await fetch(u, {
|
|
219
|
-
...T.options,
|
|
220
|
-
method: o,
|
|
221
|
-
headers: {
|
|
222
|
-
"Content-Type": "application/json"
|
|
223
|
-
},
|
|
224
|
-
body: c
|
|
225
|
-
}), m = await l.json();
|
|
226
|
-
if (!e.ignoreError && (!l.ok || m.code))
|
|
227
|
-
throw { status: l.status, data: m };
|
|
228
|
-
return m;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
class O {
|
|
232
|
-
constructor(s, t) {
|
|
233
|
-
this.apiKey = s, this.apiSecret = t;
|
|
234
|
-
}
|
|
235
|
-
static defaultOpts = {
|
|
236
|
-
auth: !0,
|
|
237
|
-
checkResponse: !0
|
|
238
|
-
};
|
|
239
|
-
static create(s) {
|
|
240
|
-
let t = ["CRYPTO_GEMINI_API_KEY", "CRYPTO_GEMINI_API_SECRET"];
|
|
241
|
-
s && (t = t.map((a) => `${a}_${s}`));
|
|
242
|
-
const e = d(t[0]), i = d(t[1]);
|
|
243
|
-
return new O(e, i);
|
|
244
|
-
}
|
|
245
|
-
requestToken = {
|
|
246
|
-
public: Promise.resolve(),
|
|
247
|
-
private: Promise.resolve()
|
|
248
|
-
};
|
|
249
|
-
async doRequest(s, t) {
|
|
250
|
-
const { auth: e, params: i, body: a } = t;
|
|
251
|
-
let o = "";
|
|
252
|
-
const r = {
|
|
253
|
-
...T.options
|
|
254
|
-
};
|
|
255
|
-
if (i && (o = new URLSearchParams(
|
|
256
|
-
Object.entries(i).map(([f, h]) => [f, `${h}`])
|
|
257
|
-
).toString(), o && (o = `?${o}`)), e) {
|
|
258
|
-
const m = {
|
|
259
|
-
request: s,
|
|
260
|
-
nonce: Date.now() / 1e3,
|
|
261
|
-
...a
|
|
262
|
-
}, f = R(x(JSON.stringify(m))), h = g("sha384", this.apiSecret).update(f).digest("hex");
|
|
263
|
-
Object.assign(r, {
|
|
264
|
-
method: "POST",
|
|
265
|
-
headers: {
|
|
266
|
-
"content-type": "text/plain",
|
|
267
|
-
"X-GEMINI-APIKEY": this.apiKey,
|
|
268
|
-
"X-GEMINI-PAYLOAD": f,
|
|
269
|
-
"X-GEMINI-SIGNATURE": h
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
const c = `https://api.gemini.com${s}`, p = k(c), u = await fetch(c + o, r), l = await u.json();
|
|
274
|
-
if (p(), !u.ok) throw { status: u.status, data: l };
|
|
275
|
-
return l;
|
|
276
|
-
}
|
|
277
|
-
request(s, t) {
|
|
278
|
-
const e = {
|
|
279
|
-
...O.defaultOpts,
|
|
280
|
-
...t
|
|
281
|
-
}, i = e.auth ? "private" : "public", a = this.requestToken[i], o = a.then(() => this.doRequest(s, e));
|
|
282
|
-
return this.requestToken[i] = Promise.allSettled([
|
|
283
|
-
o,
|
|
284
|
-
a.then(() => A(e.auth ? 200 : 1e3))
|
|
285
|
-
]).then(() => {
|
|
286
|
-
}), o;
|
|
287
|
-
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/requesters/binance.ts
|
|
97
|
+
var g = class e {
|
|
98
|
+
static defaultOpts = {
|
|
99
|
+
auth: !0,
|
|
100
|
+
checkResponse: !0,
|
|
101
|
+
method: "GET"
|
|
102
|
+
};
|
|
103
|
+
static create(t = "spot") {
|
|
104
|
+
let n = ["CRYPTO_BINANCE_API_KEY", "CRYPTO_BINANCE_API_SECRET"];
|
|
105
|
+
return new e(r(n[0]), r(n[1]), t);
|
|
106
|
+
}
|
|
107
|
+
requestToken = Promise.resolve();
|
|
108
|
+
constructor(e, t, n = "spot") {
|
|
109
|
+
this.apiKey = e, this.apiSecret = t, this.marketType = n;
|
|
110
|
+
}
|
|
111
|
+
async _request(t, r) {
|
|
112
|
+
let i = {
|
|
113
|
+
...e.defaultOpts,
|
|
114
|
+
...r
|
|
115
|
+
}, { auth: a, params: o, body: s } = i, { method: c } = i, l;
|
|
116
|
+
c === "GET" && s && (c = "POST", l = {
|
|
117
|
+
...l,
|
|
118
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
119
|
+
});
|
|
120
|
+
let u = o ? new URLSearchParams(o).toString() : "", d = s ? new URLSearchParams(s).toString() : null;
|
|
121
|
+
if (a) {
|
|
122
|
+
let e = `×tamp=${Date.now()}`;
|
|
123
|
+
d ? d += e : u += e;
|
|
124
|
+
let t = `&signature=${n("sha256", this.apiSecret).update(u + (d || "")).digest("hex")}`;
|
|
125
|
+
d ? d += t : u += t, l = {
|
|
126
|
+
...l,
|
|
127
|
+
"X-MBX-APIKEY": this.apiKey
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
u &&= `?${u}`;
|
|
131
|
+
let f = {
|
|
132
|
+
spot: "api",
|
|
133
|
+
"future-u": "fapi",
|
|
134
|
+
"future-c": "dapi"
|
|
135
|
+
}[this.marketType], m = `https://${f}.binance.com/${f}${t}`, g = h(m), _ = await fetch(m + u, {
|
|
136
|
+
...p.options,
|
|
137
|
+
method: c,
|
|
138
|
+
headers: l,
|
|
139
|
+
body: d
|
|
140
|
+
}), v = await _.json();
|
|
141
|
+
if (g(), !_.ok) throw {
|
|
142
|
+
status: _.status,
|
|
143
|
+
data: v
|
|
144
|
+
};
|
|
145
|
+
return v;
|
|
146
|
+
}
|
|
147
|
+
async _requestWithRetry(e, t) {
|
|
148
|
+
let n = /* @__PURE__ */ Error("Unknown error");
|
|
149
|
+
for (let r = 0; r < 3; r += 1) {
|
|
150
|
+
r > 0 && console.error(`Invalid timestamp, retry ${r}...`);
|
|
151
|
+
try {
|
|
152
|
+
return await this._request(e, t);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
if (n = e, n?.status === 400 && n.data?.code === -1021) continue;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
throw n;
|
|
159
|
+
}
|
|
160
|
+
request(e, n) {
|
|
161
|
+
let r = this.requestToken.then(() => this._requestWithRetry(e, n));
|
|
162
|
+
return this.requestToken = r.catch(() => {}).then(() => t(50)), r;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/requesters/crypto-com.ts
|
|
167
|
+
function _(e) {
|
|
168
|
+
if (e == null) return "";
|
|
169
|
+
if (Array.isArray(e)) return e.map(_).join("");
|
|
170
|
+
if (typeof e == "object") {
|
|
171
|
+
let t = e;
|
|
172
|
+
return Object.keys(t).sort().map((e) => t[e] == null ? "" : e + _(t[e])).join("");
|
|
173
|
+
}
|
|
174
|
+
return `${e}`;
|
|
288
175
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}
|
|
293
|
-
static defaultOpts = {
|
|
294
|
-
auth: !0,
|
|
295
|
-
method: "GET",
|
|
296
|
-
checkResponse: !0
|
|
297
|
-
};
|
|
298
|
-
static create(s) {
|
|
299
|
-
let t = [
|
|
300
|
-
"CRYPTO_OKX_API_KEY",
|
|
301
|
-
"CRYPTO_OKX_API_SECRET",
|
|
302
|
-
"CRYPTO_OKX_API_PASS"
|
|
303
|
-
];
|
|
304
|
-
s && (t = t.map((o) => `${o}_${s}`));
|
|
305
|
-
const e = d(t[0]), i = d(t[1]), a = d(t[2]);
|
|
306
|
-
return new I(e, i, a);
|
|
307
|
-
}
|
|
308
|
-
async request(s, t) {
|
|
309
|
-
const e = {
|
|
310
|
-
...I.defaultOpts,
|
|
311
|
-
...t
|
|
312
|
-
}, { auth: i, params: a, checkResponse: o } = e;
|
|
313
|
-
let { method: r } = e;
|
|
314
|
-
const c = (/* @__PURE__ */ new Date()).toISOString(), p = e.body == null ? null : JSON.stringify(e.body);
|
|
315
|
-
r === "GET" && p && (r = "POST");
|
|
316
|
-
let u = G(a).toString();
|
|
317
|
-
u && (u = `?${u}`);
|
|
318
|
-
const l = {
|
|
319
|
-
"Content-Type": "application/json"
|
|
320
|
-
};
|
|
321
|
-
if (i) {
|
|
322
|
-
const y = [c, r, s, u, p].filter(Boolean).join(""), C = R(
|
|
323
|
-
g("sha256", this.apiSecret).update(y).digest()
|
|
324
|
-
);
|
|
325
|
-
Object.assign(l, {
|
|
326
|
-
"OK-ACCESS-KEY": this.apiKey,
|
|
327
|
-
"OK-ACCESS-TIMESTAMP": c,
|
|
328
|
-
"OK-ACCESS-PASSPHRASE": this.apiPass,
|
|
329
|
-
"OK-ACCESS-SIGN": C
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
const m = `https://www.okx.com${s}`, f = k(m), h = await fetch(m + u, {
|
|
333
|
-
...T.options,
|
|
334
|
-
method: r,
|
|
335
|
-
headers: l,
|
|
336
|
-
body: p
|
|
337
|
-
}), S = await h.json();
|
|
338
|
-
if (f(), !h.ok || o && S.code !== "0")
|
|
339
|
-
throw { status: h.status, data: S };
|
|
340
|
-
return S.data;
|
|
341
|
-
}
|
|
176
|
+
function v(e, t, r) {
|
|
177
|
+
let { id: i, method: a, params: o, nonce: s } = r, c = _(o), l = a + i + e + c + s;
|
|
178
|
+
return n("sha256", t).update(l).digest("hex");
|
|
342
179
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
180
|
+
var y = class e {
|
|
181
|
+
static defaultOpts = {
|
|
182
|
+
auth: !0,
|
|
183
|
+
checkResponse: !0,
|
|
184
|
+
method: "GET"
|
|
185
|
+
};
|
|
186
|
+
static create(t) {
|
|
187
|
+
let n = ["CRYPTO_CDC_API_KEY", "CRYPTO_CDC_API_SECRET"];
|
|
188
|
+
return t && (n = n.map((e) => `${e}_${t}`)), new e(r(n[0]), r(n[1]));
|
|
189
|
+
}
|
|
190
|
+
requestId = 0;
|
|
191
|
+
constructor(e, t) {
|
|
192
|
+
this.apiKey = e, this.apiSecret = t;
|
|
193
|
+
}
|
|
194
|
+
async request(t, n) {
|
|
195
|
+
let r = {
|
|
196
|
+
...e.defaultOpts,
|
|
197
|
+
...n
|
|
198
|
+
}, { auth: i, params: a } = r, { method: o } = r, s = {
|
|
199
|
+
method: t,
|
|
200
|
+
params: r.body
|
|
201
|
+
};
|
|
202
|
+
if (i) {
|
|
203
|
+
let { requestId: e } = this;
|
|
204
|
+
this.requestId += 1, Object.assign(s, {
|
|
205
|
+
id: e,
|
|
206
|
+
nonce: Date.now(),
|
|
207
|
+
api_key: this.apiKey
|
|
208
|
+
}), s.sig = v(this.apiKey, this.apiSecret, s);
|
|
209
|
+
}
|
|
210
|
+
let c = s.params || s.sig ? JSON.stringify(s) : null;
|
|
211
|
+
o === "GET" && c && (o = "POST");
|
|
212
|
+
let l = `https://api.crypto.com/v2/${t}${a ? "?" + new URLSearchParams(Object.entries(a).map(([e, t]) => [e, `${t}`])).toString() : ""}`, u = await fetch(l, {
|
|
213
|
+
...p.options,
|
|
214
|
+
method: o,
|
|
215
|
+
headers: { "Content-Type": "application/json" },
|
|
216
|
+
body: c
|
|
217
|
+
}), d = await u.json();
|
|
218
|
+
if (!r.ignoreError && (!u.ok || d.code)) throw {
|
|
219
|
+
status: u.status,
|
|
220
|
+
data: d
|
|
221
|
+
};
|
|
222
|
+
return d;
|
|
223
|
+
}
|
|
224
|
+
}, b = class e {
|
|
225
|
+
static defaultOpts = {
|
|
226
|
+
auth: !0,
|
|
227
|
+
checkResponse: !0
|
|
228
|
+
};
|
|
229
|
+
static create(t) {
|
|
230
|
+
let n = ["CRYPTO_GEMINI_API_KEY", "CRYPTO_GEMINI_API_SECRET"];
|
|
231
|
+
return t && (n = n.map((e) => `${e}_${t}`)), new e(r(n[0]), r(n[1]));
|
|
232
|
+
}
|
|
233
|
+
requestToken = {
|
|
234
|
+
public: Promise.resolve(),
|
|
235
|
+
private: Promise.resolve()
|
|
236
|
+
};
|
|
237
|
+
constructor(e, t) {
|
|
238
|
+
this.apiKey = e, this.apiSecret = t;
|
|
239
|
+
}
|
|
240
|
+
async doRequest(e, t) {
|
|
241
|
+
let { auth: r, params: i, body: a } = t, o = "", l = { ...p.options };
|
|
242
|
+
if (i && (o = new URLSearchParams(Object.entries(i).map(([e, t]) => [e, `${t}`])).toString(), o &&= `?${o}`), r) {
|
|
243
|
+
let t = {
|
|
244
|
+
request: e,
|
|
245
|
+
nonce: Date.now() / 1e3,
|
|
246
|
+
...a
|
|
247
|
+
}, r = s(c(JSON.stringify(t))), i = n("sha384", this.apiSecret).update(r).digest("hex");
|
|
248
|
+
Object.assign(l, {
|
|
249
|
+
method: "POST",
|
|
250
|
+
headers: {
|
|
251
|
+
"content-type": "text/plain",
|
|
252
|
+
"X-GEMINI-APIKEY": this.apiKey,
|
|
253
|
+
"X-GEMINI-PAYLOAD": r,
|
|
254
|
+
"X-GEMINI-SIGNATURE": i
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
let u = `https://api.gemini.com${e}`, d = h(u), f = await fetch(u + o, l), m = await f.json();
|
|
259
|
+
if (d(), !f.ok) throw {
|
|
260
|
+
status: f.status,
|
|
261
|
+
data: m
|
|
262
|
+
};
|
|
263
|
+
return m;
|
|
264
|
+
}
|
|
265
|
+
request(n, r) {
|
|
266
|
+
let i = {
|
|
267
|
+
...e.defaultOpts,
|
|
268
|
+
...r
|
|
269
|
+
}, a = i.auth ? "private" : "public", o = this.requestToken[a], s = o.then(() => this.doRequest(n, i));
|
|
270
|
+
return this.requestToken[a] = Promise.allSettled([s, o.then(() => t(i.auth ? 200 : 1e3))]).then(() => {}), s;
|
|
271
|
+
}
|
|
272
|
+
}, x = class e {
|
|
273
|
+
static defaultOpts = {
|
|
274
|
+
auth: !0,
|
|
275
|
+
method: "GET",
|
|
276
|
+
checkResponse: !0
|
|
277
|
+
};
|
|
278
|
+
static create(t) {
|
|
279
|
+
let n = [
|
|
280
|
+
"CRYPTO_OKX_API_KEY",
|
|
281
|
+
"CRYPTO_OKX_API_SECRET",
|
|
282
|
+
"CRYPTO_OKX_API_PASS"
|
|
283
|
+
];
|
|
284
|
+
return t && (n = n.map((e) => `${e}_${t}`)), new e(r(n[0]), r(n[1]), r(n[2]));
|
|
285
|
+
}
|
|
286
|
+
constructor(e, t, n) {
|
|
287
|
+
this.apiKey = e, this.apiSecret = t, this.apiPass = n;
|
|
288
|
+
}
|
|
289
|
+
async request(t, r) {
|
|
290
|
+
let i = {
|
|
291
|
+
...e.defaultOpts,
|
|
292
|
+
...r
|
|
293
|
+
}, { auth: a, params: o, checkResponse: c } = i, { method: l } = i, u = (/* @__PURE__ */ new Date()).toISOString(), d = i.body == null ? null : JSON.stringify(i.body);
|
|
294
|
+
l === "GET" && d && (l = "POST");
|
|
295
|
+
let f = m(o).toString();
|
|
296
|
+
f &&= `?${f}`;
|
|
297
|
+
let g = { "Content-Type": "application/json" };
|
|
298
|
+
if (a) {
|
|
299
|
+
let e = [
|
|
300
|
+
u,
|
|
301
|
+
l,
|
|
302
|
+
t,
|
|
303
|
+
f,
|
|
304
|
+
d
|
|
305
|
+
].filter(Boolean).join(""), r = s(n("sha256", this.apiSecret).update(e).digest());
|
|
306
|
+
Object.assign(g, {
|
|
307
|
+
"OK-ACCESS-KEY": this.apiKey,
|
|
308
|
+
"OK-ACCESS-TIMESTAMP": u,
|
|
309
|
+
"OK-ACCESS-PASSPHRASE": this.apiPass,
|
|
310
|
+
"OK-ACCESS-SIGN": r
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
let _ = `https://www.okx.com${t}`, v = h(_), y = await fetch(_ + f, {
|
|
314
|
+
...p.options,
|
|
315
|
+
method: l,
|
|
316
|
+
headers: g,
|
|
317
|
+
body: d
|
|
318
|
+
}), b = await y.json();
|
|
319
|
+
if (v(), !y.ok || c && b.code !== "0") throw {
|
|
320
|
+
status: y.status,
|
|
321
|
+
data: b
|
|
322
|
+
};
|
|
323
|
+
return b.data;
|
|
324
|
+
}
|
|
351
325
|
};
|
|
326
|
+
//#endregion
|
|
327
|
+
export { g as BinanceRequester, y as CDCRequester, p as FetchConfig, b as GeminiRequester, x as OKXRequester, m as buildSearchParams, h as timeit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gera2ld/lib-cex",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"registry": "https://registry.npmjs.org/"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@gera2ld/common": "^0.0.
|
|
20
|
-
"@gera2ld/common-node": "^0.0.
|
|
21
|
-
"@gera2ld/lib-trading": "^0.0.
|
|
19
|
+
"@gera2ld/common": "^0.0.3",
|
|
20
|
+
"@gera2ld/common-node": "^0.0.3",
|
|
21
|
+
"@gera2ld/lib-trading": "^0.0.3"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"es-toolkit": "^1.
|
|
24
|
+
"es-toolkit": "^1.45.1"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"clean": "del-cli dist tsconfig.tsbuildinfo",
|