kalshi-cli 1.1.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/bin/kalshi +31 -0
- package/package.json +16 -0
- package/postinstall.js +66 -0
package/bin/kalshi
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const CLI_DIR = path.join(os.homedir(), '.local', 'share', 'kalshi-cli');
|
|
8
|
+
const VENV_PYTHON = path.join(CLI_DIR, '.venv', 'bin', 'python');
|
|
9
|
+
const CLI_PYTHON = path.join(CLI_DIR, 'cli.py');
|
|
10
|
+
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
|
|
13
|
+
// Find Python executable
|
|
14
|
+
function getPython() {
|
|
15
|
+
// Try venv first
|
|
16
|
+
if (require('fs').existsSync(VENV_PYTHON)) {
|
|
17
|
+
return VENV_PYTHON;
|
|
18
|
+
}
|
|
19
|
+
// Fallback to system python3
|
|
20
|
+
return 'python3';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const python = getPython();
|
|
24
|
+
const child = spawn(python, [CLI_PYTHON, ...args], {
|
|
25
|
+
stdio: 'inherit',
|
|
26
|
+
cwd: process.cwd()
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
child.on('exit', (code) => {
|
|
30
|
+
process.exit(code);
|
|
31
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kalshi-cli",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Interactive CLI for trading prediction markets on Kalshi",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"kalshi": "./bin/kalshi"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"postinstall": "node postinstall.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": ["kalshi", "prediction-markets", "trading"],
|
|
13
|
+
"author": "Jonathan Thomas",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {}
|
|
16
|
+
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
const CLI_DIR = path.join(os.homedir(), '.local', 'share', 'kalshi-cli');
|
|
9
|
+
const VENV_DIR = path.join(CLI_DIR, '.venv');
|
|
10
|
+
const REPO_URL = 'https://github.com/JThomasDevs/kalshi-cli.git';
|
|
11
|
+
|
|
12
|
+
console.log('🎰 Setting up kalshi-cli...');
|
|
13
|
+
|
|
14
|
+
// Clone or update repo
|
|
15
|
+
function setupRepo() {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
if (fs.existsSync(path.join(CLI_DIR, '.git'))) {
|
|
18
|
+
console.log('📦 Updating kalshi-cli...');
|
|
19
|
+
const git = spawn('git', ['pull'], { cwd: CLI_DIR, stdio: 'inherit' });
|
|
20
|
+
git.on('close', resolve);
|
|
21
|
+
} else {
|
|
22
|
+
console.log('📦 Cloning kalshi-cli...');
|
|
23
|
+
fs.mkdirSync(CLI_DIR, { recursive: true });
|
|
24
|
+
const git = spawn('git', ['clone', REPO_URL, CLI_DIR], { stdio: 'inherit' });
|
|
25
|
+
git.on('close', resolve);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Create venv and install deps
|
|
31
|
+
function setupVenv() {
|
|
32
|
+
return new Promise((resolve) => {
|
|
33
|
+
if (fs.existsSync(VENV_DIR)) {
|
|
34
|
+
console.log('✅ Virtual environment exists');
|
|
35
|
+
resolve();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log('📦 Creating virtual environment...');
|
|
40
|
+
const venv = spawn('python3', ['-m', 'venv', VENV_DIR], { stdio: 'inherit' });
|
|
41
|
+
venv.on('close', (code) => {
|
|
42
|
+
if (code !== 0) {
|
|
43
|
+
console.error('❌ Failed to create venv');
|
|
44
|
+
process.exit(code);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.log('📦 Installing Python dependencies...');
|
|
48
|
+
const pip = spawn(path.join(VENV_DIR, 'bin', 'pip'), ['install', '-r', path.join(CLI_DIR, 'requirements.txt')], {
|
|
49
|
+
stdio: 'inherit'
|
|
50
|
+
});
|
|
51
|
+
pip.on('close', resolve);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function main() {
|
|
57
|
+
await setupRepo();
|
|
58
|
+
await setupVenv();
|
|
59
|
+
console.log('✅ kalshi-cli is ready!');
|
|
60
|
+
console.log(' Run: kalshi --help');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
main().catch(err => {
|
|
64
|
+
console.error('❌ Setup failed:', err.message);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
});
|