@okx_ai/okx-trade-cli 1.3.2-beta.7 → 1.3.3-beta.1
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/LICENSE +21 -0
- package/dist/index.js +2021 -532
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/scripts/postinstall-download.js +152 -0
- package/scripts/postinstall.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okx_ai/okx-trade-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3-beta.1",
|
|
4
4
|
"description": "OKX CLI - Command line tool for OKX exchange",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,14 +16,6 @@
|
|
|
16
16
|
"publishConfig": {
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsup && node -e \"const fs=require('fs');fs.mkdirSync('scripts',{recursive:true});fs.copyFileSync('../../scripts/postinstall-notice.js','scripts/postinstall.js')\"",
|
|
21
|
-
"typecheck": "tsc --noEmit",
|
|
22
|
-
"clean": "rm -rf dist scripts",
|
|
23
|
-
"postinstall": "node scripts/postinstall.js || exit 0",
|
|
24
|
-
"test:unit": "node --import tsx/esm --test test/*.test.ts",
|
|
25
|
-
"test:coverage": "c8 --reporter=lcov --reporter=text --src=src node --import tsx/esm --test test/*.test.ts"
|
|
26
|
-
},
|
|
27
19
|
"engines": {
|
|
28
20
|
"node": ">=18"
|
|
29
21
|
},
|
|
@@ -43,5 +35,13 @@
|
|
|
43
35
|
"tsup": "^8.5.1",
|
|
44
36
|
"tsx": "^4.19.3",
|
|
45
37
|
"typescript": "^5.9.3"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup && node -e \"const fs=require('fs');fs.mkdirSync('scripts',{recursive:true});fs.copyFileSync('../../scripts/postinstall-notice.js','scripts/postinstall.js')\"",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"clean": "rm -rf dist scripts",
|
|
43
|
+
"postinstall": "node scripts/postinstall.js || exit 0",
|
|
44
|
+
"test:unit": "node --import tsx/esm --test test/*.test.ts",
|
|
45
|
+
"test:coverage": "c8 --reporter=lcov --reporter=text --src=src node --import tsx/esm --test test/*.test.ts"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* postinstall-download.js
|
|
4
|
+
*
|
|
5
|
+
* Downloads the platform-specific okx-doh-resolver binary from OKX CDN
|
|
6
|
+
* to ~/.okx/bin/. Two-layer CDN fallback:
|
|
7
|
+
* 1. static.okx.com (HTTPS, overseas)
|
|
8
|
+
* 2. pcdoh.qcxex.com (HTTP, domestic)
|
|
9
|
+
*
|
|
10
|
+
* This script MUST NOT block npm install — all errors are silently swallowed.
|
|
11
|
+
* If the binary cannot be downloaded the SDK falls back to direct connection.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createWriteStream, mkdirSync, chmodSync, existsSync, unlinkSync } from 'node:fs';
|
|
15
|
+
import { homedir, platform, arch } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { get as httpsGet } from 'node:https';
|
|
18
|
+
import { get as httpGet } from 'node:http';
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Config
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
const CDN_SOURCES = [
|
|
25
|
+
{ host: 'static.okx.com', protocol: 'https' },
|
|
26
|
+
{ host: 'pcdoh.qcxex.com', protocol: 'http' },
|
|
27
|
+
];
|
|
28
|
+
const CDN_PATH_PREFIX = '/upgradeapp/doh/prepub';
|
|
29
|
+
const DOWNLOAD_TIMEOUT_MS = 30_000;
|
|
30
|
+
const BIN_DIR = join(homedir(), '.okx', 'bin');
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Platform detection
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
function getPlatformDir() {
|
|
37
|
+
const p = platform();
|
|
38
|
+
const a = arch();
|
|
39
|
+
|
|
40
|
+
const map = {
|
|
41
|
+
'darwin-arm64': 'darwin-arm64',
|
|
42
|
+
'darwin-x64': 'darwin-x64',
|
|
43
|
+
'linux-x64': 'linux-x64',
|
|
44
|
+
'win32-x64': 'win32-x64',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const key = `${p}-${a}`;
|
|
48
|
+
return map[key] ?? null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getBinaryName() {
|
|
52
|
+
return platform() === 'win32' ? 'okx-doh-resolver.exe' : 'okx-doh-resolver';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
// Download helper (follows up to 5 redirects)
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
function download(url, destPath, timeoutMs) {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
let redirects = 0;
|
|
62
|
+
const maxRedirects = 5;
|
|
63
|
+
const getter = url.startsWith('https') ? httpsGet : httpGet;
|
|
64
|
+
|
|
65
|
+
function doRequest(requestUrl) {
|
|
66
|
+
const reqFn = requestUrl.startsWith('https') ? httpsGet : getter;
|
|
67
|
+
const req = reqFn(requestUrl, { timeout: timeoutMs }, (res) => {
|
|
68
|
+
// Follow redirects
|
|
69
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
70
|
+
redirects++;
|
|
71
|
+
if (redirects > maxRedirects) {
|
|
72
|
+
reject(new Error(`Too many redirects (${maxRedirects})`));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
doRequest(res.headers.location);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (res.statusCode !== 200) {
|
|
80
|
+
reject(new Error(`HTTP ${res.statusCode}`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const file = createWriteStream(destPath);
|
|
85
|
+
res.pipe(file);
|
|
86
|
+
file.on('finish', () => file.close(resolve));
|
|
87
|
+
file.on('error', (err) => {
|
|
88
|
+
try { unlinkSync(destPath); } catch { /* ignore */ }
|
|
89
|
+
reject(err);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
req.on('error', reject);
|
|
94
|
+
req.on('timeout', () => {
|
|
95
|
+
req.destroy();
|
|
96
|
+
reject(new Error('Download timed out'));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
doRequest(url);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Main
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
async function main() {
|
|
109
|
+
// Skip if OKX_DOH_BINARY_PATH is set (user manages their own binary)
|
|
110
|
+
if (process.env.OKX_DOH_BINARY_PATH) return;
|
|
111
|
+
|
|
112
|
+
const platformDir = getPlatformDir();
|
|
113
|
+
if (!platformDir) {
|
|
114
|
+
// Unsupported platform — silently skip
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const binaryName = getBinaryName();
|
|
119
|
+
const destPath = join(BIN_DIR, binaryName);
|
|
120
|
+
|
|
121
|
+
// Skip if binary already exists
|
|
122
|
+
if (existsSync(destPath)) return;
|
|
123
|
+
|
|
124
|
+
// Ensure target directory exists
|
|
125
|
+
mkdirSync(BIN_DIR, { recursive: true });
|
|
126
|
+
|
|
127
|
+
const urlPath = `${CDN_PATH_PREFIX}/${platformDir}/${binaryName}`;
|
|
128
|
+
|
|
129
|
+
for (const { host, protocol } of CDN_SOURCES) {
|
|
130
|
+
const url = `${protocol}://${host}${urlPath}`;
|
|
131
|
+
try {
|
|
132
|
+
await download(url, destPath, DOWNLOAD_TIMEOUT_MS);
|
|
133
|
+
// Make executable on Unix
|
|
134
|
+
if (platform() !== 'win32') {
|
|
135
|
+
chmodSync(destPath, 0o755);
|
|
136
|
+
}
|
|
137
|
+
process.stderr.write(` ✓ DoH resolver downloaded from ${host}\n`);
|
|
138
|
+
return;
|
|
139
|
+
} catch {
|
|
140
|
+
// Remove partial download
|
|
141
|
+
try { unlinkSync(destPath); } catch { /* ignore */ }
|
|
142
|
+
// Try next CDN source
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// All CDN hosts failed — silently degrade
|
|
147
|
+
process.stderr.write(' ⓘ DoH resolver not available (download failed), using direct connection.\n');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
main().catch(() => {
|
|
151
|
+
// Never block npm install
|
|
152
|
+
});
|
package/scripts/postinstall.js
CHANGED
|
@@ -43,7 +43,7 @@ function getPlatformDir() {
|
|
|
43
43
|
const map = {
|
|
44
44
|
'darwin-arm64': 'darwin-arm64',
|
|
45
45
|
'darwin-x64': 'darwin-x64',
|
|
46
|
-
'linux-arm64': 'linux-
|
|
46
|
+
'linux-arm64': 'linux-arm64',
|
|
47
47
|
'linux-x64': 'linux-x64',
|
|
48
48
|
'win32-arm64': 'win32-x64', // fallback: x64 binary via WoW64 emulation
|
|
49
49
|
'win32-x64': 'win32-x64',
|