@gaberoo/kalshitools 1.0.0 → 1.0.2
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/.env.example +12 -0
- package/.env.local.example +22 -0
- package/README.md +127 -18
- package/SETUP_DEMO_API.md +251 -0
- package/dist/commands/portfolio/balance.js +11 -6
- package/dist/lib/kalshi/client.js +20 -7
- package/dist/lib/kalshi/types.d.ts +1 -1
- package/docs/DEVELOPMENT.md +547 -0
- package/oclif.manifest.json +1 -1
- package/package.json +6 -2
package/.env.example
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Kalshi API Configuration
|
|
2
|
+
# Override config file settings with environment variables
|
|
3
|
+
|
|
4
|
+
# Environment: demo or production
|
|
5
|
+
KALSHI_ENV=demo
|
|
6
|
+
|
|
7
|
+
# API Credentials
|
|
8
|
+
KALSHI_API_KEY_ID=your-email@example.com
|
|
9
|
+
KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
|
|
10
|
+
|
|
11
|
+
# Logging
|
|
12
|
+
LOG_LEVEL=info
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Local Development API Credentials
|
|
2
|
+
# Copy this file to .env or .env.local and fill in your credentials
|
|
3
|
+
# NEVER commit this file with real credentials!
|
|
4
|
+
|
|
5
|
+
# Environment: demo (safe for testing) or production (real money!)
|
|
6
|
+
KALSHI_ENV=demo
|
|
7
|
+
|
|
8
|
+
# API Key ID (your email address from Kalshi)
|
|
9
|
+
KALSHI_API_KEY_ID=your-email@example.com
|
|
10
|
+
|
|
11
|
+
# Path to your private key file
|
|
12
|
+
# Can be absolute path or relative to home directory (~/)
|
|
13
|
+
KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
|
|
14
|
+
|
|
15
|
+
# Optional: Logging level (debug, info, warn, error)
|
|
16
|
+
LOG_LEVEL=info
|
|
17
|
+
|
|
18
|
+
# Note: Environment variables override ~/.config/kalshitools/config.json
|
|
19
|
+
# This is useful for:
|
|
20
|
+
# - Testing with different credentials
|
|
21
|
+
# - CI/CD environments
|
|
22
|
+
# - Switching between demo and production quickly
|
package/README.md
CHANGED
|
@@ -17,15 +17,95 @@ A powerful CLI tool for interacting with the Kalshi prediction markets API. Buil
|
|
|
17
17
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
20
|
+
### 1. Install
|
|
21
|
+
|
|
20
22
|
```bash
|
|
21
|
-
|
|
23
|
+
npm install -g @gaberoo/kalshitools
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Get Demo API Credentials
|
|
27
|
+
|
|
28
|
+
Visit the [Kalshi Demo Portal](https://demo-api.kalshi.co) to generate API credentials:
|
|
29
|
+
- **API Key ID**: Your registered email address
|
|
30
|
+
- **Private Key**: Download the `.pem` file
|
|
31
|
+
|
|
32
|
+
### 3. Configure Credentials
|
|
33
|
+
|
|
34
|
+
**Option A: Interactive Setup (Recommended)**
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Run the configuration wizard
|
|
22
38
|
kalshitools config init
|
|
23
39
|
|
|
24
|
-
#
|
|
40
|
+
# Follow the prompts:
|
|
41
|
+
# - Environment: demo (default)
|
|
42
|
+
# - API Key ID: your-email@example.com
|
|
43
|
+
# - Private Key Path: ~/.kalshitools/demo-private-key.pem (default)
|
|
44
|
+
|
|
45
|
+
# Place your private key file
|
|
46
|
+
mkdir -p ~/.kalshitools
|
|
47
|
+
cp ~/Downloads/private-key.pem ~/.kalshitools/demo-private-key.pem
|
|
48
|
+
chmod 600 ~/.kalshitools/demo-private-key.pem # Secure permissions
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Option B: Environment Variables (Quick Testing)**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Copy the example file
|
|
55
|
+
cp .env.example .env
|
|
56
|
+
|
|
57
|
+
# Edit .env with your credentials
|
|
58
|
+
nano .env
|
|
59
|
+
|
|
60
|
+
# Source the environment
|
|
61
|
+
source .env
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. Verify Setup
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Check configuration
|
|
25
68
|
kalshitools config show
|
|
26
69
|
|
|
27
|
-
#
|
|
28
|
-
kalshitools
|
|
70
|
+
# Test API connection
|
|
71
|
+
kalshitools portfolio balance
|
|
72
|
+
|
|
73
|
+
# List active markets
|
|
74
|
+
kalshitools markets list --status active --limit 5
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 5. Start Trading
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# View available markets
|
|
81
|
+
kalshitools markets list --status active
|
|
82
|
+
|
|
83
|
+
# Get market details
|
|
84
|
+
kalshitools markets show TICKER-SYMBOL
|
|
85
|
+
|
|
86
|
+
# View your portfolio
|
|
87
|
+
kalshitools portfolio balance
|
|
88
|
+
kalshitools portfolio positions
|
|
89
|
+
|
|
90
|
+
# Place an order (with confirmation)
|
|
91
|
+
kalshitools orders create \
|
|
92
|
+
--ticker MARKET-TICKER \
|
|
93
|
+
--action buy \
|
|
94
|
+
--side yes \
|
|
95
|
+
--quantity 10 \
|
|
96
|
+
--type market
|
|
97
|
+
|
|
98
|
+
# Use --dry-run to simulate without placing order
|
|
99
|
+
kalshitools orders create \
|
|
100
|
+
--ticker MARKET-TICKER \
|
|
101
|
+
--action buy \
|
|
102
|
+
--side yes \
|
|
103
|
+
--quantity 10 \
|
|
104
|
+
--type market \
|
|
105
|
+
--dry-run
|
|
106
|
+
|
|
107
|
+
# View order history
|
|
108
|
+
kalshitools orders list
|
|
29
109
|
```
|
|
30
110
|
|
|
31
111
|
## Configuration
|
|
@@ -39,11 +119,40 @@ export KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
|
|
|
39
119
|
export LOG_LEVEL=info
|
|
40
120
|
```
|
|
41
121
|
|
|
122
|
+
### Security Notes
|
|
123
|
+
|
|
124
|
+
- Private keys are **never** committed to the repository
|
|
125
|
+
- All `.pem`, `.key`, and `.env` files are in `.gitignore`
|
|
126
|
+
- Demo environment is the default (safe for testing)
|
|
127
|
+
- Always use `--dry-run` first to verify order parameters
|
|
128
|
+
- Store private keys with restricted permissions: `chmod 600`
|
|
129
|
+
|
|
130
|
+
### Configuration Precedence
|
|
131
|
+
|
|
132
|
+
1. Environment variables (highest priority)
|
|
133
|
+
2. `~/.config/kalshitools/config.json`
|
|
134
|
+
3. Default values (demo environment)
|
|
135
|
+
|
|
42
136
|
<!-- toc -->
|
|
43
137
|
* [kalshitools](#kalshitools)
|
|
44
|
-
* [
|
|
45
|
-
* [
|
|
46
|
-
* [
|
|
138
|
+
* [Run the configuration wizard](#run-the-configuration-wizard)
|
|
139
|
+
* [Follow the prompts:](#follow-the-prompts)
|
|
140
|
+
* [- Environment: demo (default)](#--environment-demo-default)
|
|
141
|
+
* [- API Key ID: your-email@example.com](#--api-key-id-your-emailexamplecom)
|
|
142
|
+
* [- Private Key Path: ~/.kalshitools/demo-private-key.pem (default)](#--private-key-path-kalshitoolsdemo-private-keypem-default)
|
|
143
|
+
* [Place your private key file](#place-your-private-key-file)
|
|
144
|
+
* [Copy the example file](#copy-the-example-file)
|
|
145
|
+
* [Edit .env with your credentials](#edit-env-with-your-credentials)
|
|
146
|
+
* [Source the environment](#source-the-environment)
|
|
147
|
+
* [Check configuration](#check-configuration)
|
|
148
|
+
* [Test API connection](#test-api-connection)
|
|
149
|
+
* [List active markets](#list-active-markets)
|
|
150
|
+
* [View available markets](#view-available-markets)
|
|
151
|
+
* [Get market details](#get-market-details)
|
|
152
|
+
* [View your portfolio](#view-your-portfolio)
|
|
153
|
+
* [Place an order (with confirmation)](#place-an-order-with-confirmation)
|
|
154
|
+
* [Use --dry-run to simulate without placing order](#use---dry-run-to-simulate-without-placing-order)
|
|
155
|
+
* [View order history](#view-order-history)
|
|
47
156
|
* [Usage](#usage)
|
|
48
157
|
* [Commands](#commands)
|
|
49
158
|
<!-- tocstop -->
|
|
@@ -54,7 +163,7 @@ $ npm install -g @gaberoo/kalshitools
|
|
|
54
163
|
$ kalshitools COMMAND
|
|
55
164
|
running command...
|
|
56
165
|
$ kalshitools (--version)
|
|
57
|
-
@gaberoo/kalshitools/1.0.
|
|
166
|
+
@gaberoo/kalshitools/1.0.2 darwin-arm64 node-v22.20.0
|
|
58
167
|
$ kalshitools --help [COMMAND]
|
|
59
168
|
USAGE
|
|
60
169
|
$ kalshitools COMMAND
|
|
@@ -109,7 +218,7 @@ EXAMPLES
|
|
|
109
218
|
$ kalshitools config init --env production
|
|
110
219
|
```
|
|
111
220
|
|
|
112
|
-
_See code: [src/commands/config/init.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
221
|
+
_See code: [src/commands/config/init.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/config/init.ts)_
|
|
113
222
|
|
|
114
223
|
## `kalshitools config show`
|
|
115
224
|
|
|
@@ -131,7 +240,7 @@ EXAMPLES
|
|
|
131
240
|
$ kalshitools config show --json
|
|
132
241
|
```
|
|
133
242
|
|
|
134
|
-
_See code: [src/commands/config/show.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
243
|
+
_See code: [src/commands/config/show.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/config/show.ts)_
|
|
135
244
|
|
|
136
245
|
## `kalshitools help [COMMAND]`
|
|
137
246
|
|
|
@@ -178,7 +287,7 @@ EXAMPLES
|
|
|
178
287
|
$ kalshitools markets list --json
|
|
179
288
|
```
|
|
180
289
|
|
|
181
|
-
_See code: [src/commands/markets/list.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
290
|
+
_See code: [src/commands/markets/list.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/markets/list.ts)_
|
|
182
291
|
|
|
183
292
|
## `kalshitools markets show TICKER`
|
|
184
293
|
|
|
@@ -203,7 +312,7 @@ EXAMPLES
|
|
|
203
312
|
$ kalshitools markets show TICKER --json
|
|
204
313
|
```
|
|
205
314
|
|
|
206
|
-
_See code: [src/commands/markets/show.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
315
|
+
_See code: [src/commands/markets/show.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/markets/show.ts)_
|
|
207
316
|
|
|
208
317
|
## `kalshitools orders cancel ORDERID`
|
|
209
318
|
|
|
@@ -231,7 +340,7 @@ EXAMPLES
|
|
|
231
340
|
$ kalshitools orders cancel ORDER_ID --json
|
|
232
341
|
```
|
|
233
342
|
|
|
234
|
-
_See code: [src/commands/orders/cancel.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
343
|
+
_See code: [src/commands/orders/cancel.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/orders/cancel.ts)_
|
|
235
344
|
|
|
236
345
|
## `kalshitools orders create`
|
|
237
346
|
|
|
@@ -269,7 +378,7 @@ EXAMPLES
|
|
|
269
378
|
$ kalshitools orders create --ticker TICKER --action buy --side yes --quantity 100 --dry-run
|
|
270
379
|
```
|
|
271
380
|
|
|
272
|
-
_See code: [src/commands/orders/create.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
381
|
+
_See code: [src/commands/orders/create.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/orders/create.ts)_
|
|
273
382
|
|
|
274
383
|
## `kalshitools orders list`
|
|
275
384
|
|
|
@@ -300,7 +409,7 @@ EXAMPLES
|
|
|
300
409
|
$ kalshitools orders list --json
|
|
301
410
|
```
|
|
302
411
|
|
|
303
|
-
_See code: [src/commands/orders/list.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
412
|
+
_See code: [src/commands/orders/list.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/orders/list.ts)_
|
|
304
413
|
|
|
305
414
|
## `kalshitools plugins`
|
|
306
415
|
|
|
@@ -612,7 +721,7 @@ EXAMPLES
|
|
|
612
721
|
$ kalshitools portfolio balance --json
|
|
613
722
|
```
|
|
614
723
|
|
|
615
|
-
_See code: [src/commands/portfolio/balance.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
724
|
+
_See code: [src/commands/portfolio/balance.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/portfolio/balance.ts)_
|
|
616
725
|
|
|
617
726
|
## `kalshitools portfolio fills`
|
|
618
727
|
|
|
@@ -640,7 +749,7 @@ EXAMPLES
|
|
|
640
749
|
$ kalshitools portfolio fills --json
|
|
641
750
|
```
|
|
642
751
|
|
|
643
|
-
_See code: [src/commands/portfolio/fills.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
752
|
+
_See code: [src/commands/portfolio/fills.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/portfolio/fills.ts)_
|
|
644
753
|
|
|
645
754
|
## `kalshitools portfolio positions`
|
|
646
755
|
|
|
@@ -662,5 +771,5 @@ EXAMPLES
|
|
|
662
771
|
$ kalshitools portfolio positions --json
|
|
663
772
|
```
|
|
664
773
|
|
|
665
|
-
_See code: [src/commands/portfolio/positions.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.
|
|
774
|
+
_See code: [src/commands/portfolio/positions.ts](https://github.com/kalshitools/kalshitools/blob/v1.0.2/src/commands/portfolio/positions.ts)_
|
|
666
775
|
<!-- commandsstop -->
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# Quick Setup: Demo API Credentials
|
|
2
|
+
|
|
3
|
+
Follow these steps to set up your demo API credentials for local testing.
|
|
4
|
+
|
|
5
|
+
## ✅ Step-by-Step Checklist
|
|
6
|
+
|
|
7
|
+
### Step 1: Get Your Demo API Credentials
|
|
8
|
+
|
|
9
|
+
1. Visit **[Kalshi Demo Portal](https://demo-api.kalshi.co)**
|
|
10
|
+
2. Sign up or log in to your demo account
|
|
11
|
+
3. Navigate to **API Settings** or **Developer Settings**
|
|
12
|
+
4. Click **Generate API Key** or **Create New API Key**
|
|
13
|
+
5. You'll receive:
|
|
14
|
+
- **API Key ID** (your email address)
|
|
15
|
+
- **Private Key** (download the `.pem` file)
|
|
16
|
+
6. Download and save the private key file
|
|
17
|
+
|
|
18
|
+
### Step 2: Choose Your Configuration Method
|
|
19
|
+
|
|
20
|
+
**Option A: Interactive Setup (Recommended)**
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Run the configuration wizard
|
|
24
|
+
kalshitools config init
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Follow the prompts:
|
|
28
|
+
- **Environment**: `demo` (press Enter for default)
|
|
29
|
+
- **API Key ID**: Enter your email address from Kalshi
|
|
30
|
+
- **Private Key Path**: `~/.kalshitools/demo-private-key.pem` (press Enter for default)
|
|
31
|
+
|
|
32
|
+
**Option B: Environment Variables**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Copy the example file
|
|
36
|
+
cp .env.example .env
|
|
37
|
+
|
|
38
|
+
# Edit the file with your credentials
|
|
39
|
+
nano .env
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Update these values in `.env`:
|
|
43
|
+
```bash
|
|
44
|
+
KALSHI_ENV=demo
|
|
45
|
+
KALSHI_API_KEY_ID=your-email@example.com
|
|
46
|
+
KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Step 3: Place Your Private Key File
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# Create the directory
|
|
53
|
+
mkdir -p ~/.kalshitools
|
|
54
|
+
|
|
55
|
+
# Copy your downloaded private key
|
|
56
|
+
cp ~/Downloads/demo-private-key.pem ~/.kalshitools/demo-private-key.pem
|
|
57
|
+
|
|
58
|
+
# Set secure permissions (important!)
|
|
59
|
+
chmod 600 ~/.kalshitools/demo-private-key.pem
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Verify the file is in place:**
|
|
63
|
+
```bash
|
|
64
|
+
ls -la ~/.kalshitools/demo-private-key.pem
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Expected output:
|
|
68
|
+
```
|
|
69
|
+
-rw------- 1 you staff 1679 Feb 17 10:00 /Users/you/.kalshitools/demo-private-key.pem
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Step 4: Verify Configuration
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Check configuration
|
|
76
|
+
kalshitools config show
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Expected output:
|
|
80
|
+
```
|
|
81
|
+
Kalshi API Configuration
|
|
82
|
+
Environment: DEMO
|
|
83
|
+
API Key ID: yo****@ex******.com
|
|
84
|
+
Private Key Path: /Users/you/.kalshitools/demo-private-key.pem
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Step 5: Test API Connection
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Test authentication and connectivity
|
|
91
|
+
kalshitools portfolio balance
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Expected output:
|
|
95
|
+
```
|
|
96
|
+
Account Balance
|
|
97
|
+
Available: $10,000.00
|
|
98
|
+
Total: $10,000.00
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Step 6: Try Some Commands
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# List active markets
|
|
105
|
+
kalshitools markets list --status active --limit 5
|
|
106
|
+
|
|
107
|
+
# Get specific market details
|
|
108
|
+
kalshitools markets show TICKER-SYMBOL
|
|
109
|
+
|
|
110
|
+
# View your positions
|
|
111
|
+
kalshitools portfolio positions
|
|
112
|
+
|
|
113
|
+
# Simulate an order (doesn't actually place it)
|
|
114
|
+
kalshitools orders create \
|
|
115
|
+
--ticker MARKET-TICKER \
|
|
116
|
+
--action buy \
|
|
117
|
+
--side yes \
|
|
118
|
+
--quantity 1 \
|
|
119
|
+
--type market \
|
|
120
|
+
--dry-run
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 🔒 Security Checklist
|
|
124
|
+
|
|
125
|
+
Before you start, verify these security measures are in place:
|
|
126
|
+
|
|
127
|
+
- [x] `.gitignore` protects `.env` files ✓
|
|
128
|
+
- [x] `.gitignore` protects `.pem` files ✓
|
|
129
|
+
- [x] `.gitignore` protects `config.json` ✓
|
|
130
|
+
- [ ] Private key has restricted permissions (`chmod 600`)
|
|
131
|
+
- [ ] You're using the **demo** environment (not production)
|
|
132
|
+
- [ ] You've verified credentials are not in any committed files
|
|
133
|
+
|
|
134
|
+
**Check git status:**
|
|
135
|
+
```bash
|
|
136
|
+
git status
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
You should **NOT** see any of these files:
|
|
140
|
+
- `.env`
|
|
141
|
+
- `.env.local`
|
|
142
|
+
- `*.pem`
|
|
143
|
+
- `config.json`
|
|
144
|
+
- `.kalshitools/`
|
|
145
|
+
|
|
146
|
+
## 🆘 Troubleshooting
|
|
147
|
+
|
|
148
|
+
### Problem: "Private key not found"
|
|
149
|
+
|
|
150
|
+
**Solution:**
|
|
151
|
+
```bash
|
|
152
|
+
# Check the file exists
|
|
153
|
+
ls -la ~/.kalshitools/demo-private-key.pem
|
|
154
|
+
|
|
155
|
+
# Verify the path in config
|
|
156
|
+
kalshitools config show
|
|
157
|
+
|
|
158
|
+
# Re-run config init if needed
|
|
159
|
+
kalshitools config init
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Problem: "Authentication failed"
|
|
163
|
+
|
|
164
|
+
**Solution:**
|
|
165
|
+
1. Verify your API Key ID is correct (check for typos)
|
|
166
|
+
2. Ensure you downloaded the correct private key file
|
|
167
|
+
3. Check the file isn't corrupted:
|
|
168
|
+
```bash
|
|
169
|
+
head -1 ~/.kalshitools/demo-private-key.pem
|
|
170
|
+
# Should show: -----BEGIN PRIVATE KEY-----
|
|
171
|
+
```
|
|
172
|
+
4. Try regenerating credentials in the Kalshi Demo Portal
|
|
173
|
+
|
|
174
|
+
### Problem: "Permission denied"
|
|
175
|
+
|
|
176
|
+
**Solution:**
|
|
177
|
+
```bash
|
|
178
|
+
# Fix file permissions
|
|
179
|
+
chmod 600 ~/.kalshitools/demo-private-key.pem
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Problem: "Environment variables not working"
|
|
183
|
+
|
|
184
|
+
**Solution:**
|
|
185
|
+
```bash
|
|
186
|
+
# If using .env file, source it first
|
|
187
|
+
source .env
|
|
188
|
+
|
|
189
|
+
# Or export manually
|
|
190
|
+
export KALSHI_ENV=demo
|
|
191
|
+
export KALSHI_API_KEY_ID=your-email@example.com
|
|
192
|
+
export KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
|
|
193
|
+
|
|
194
|
+
# Then run commands
|
|
195
|
+
kalshitools portfolio balance
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 📚 Next Steps
|
|
199
|
+
|
|
200
|
+
Once you've verified everything works:
|
|
201
|
+
|
|
202
|
+
1. **Explore the API**: Try different commands to familiarize yourself with the tool
|
|
203
|
+
2. **Read the docs**: Check `docs/DEVELOPMENT.md` for detailed guides
|
|
204
|
+
3. **Test safely**: Always use `--dry-run` when testing order placement
|
|
205
|
+
4. **Get JSON output**: Add `--json` flag for programmatic use
|
|
206
|
+
|
|
207
|
+
## 🔗 Useful Resources
|
|
208
|
+
|
|
209
|
+
- **Kalshi Demo Portal**: https://demo-api.kalshi.co
|
|
210
|
+
- **Kalshi API Documentation**: https://docs.kalshi.com
|
|
211
|
+
- **Development Guide**: [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md)
|
|
212
|
+
- **Main README**: [README.md](README.md)
|
|
213
|
+
|
|
214
|
+
## 💡 Quick Tips
|
|
215
|
+
|
|
216
|
+
1. **Always use demo environment for testing**
|
|
217
|
+
```bash
|
|
218
|
+
echo $KALSHI_ENV # Should be "demo"
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
2. **Use --dry-run first**
|
|
222
|
+
```bash
|
|
223
|
+
kalshitools orders create ... --dry-run
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
3. **Get JSON for debugging**
|
|
227
|
+
```bash
|
|
228
|
+
kalshitools markets list --json | jq
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
4. **Check config anytime**
|
|
232
|
+
```bash
|
|
233
|
+
kalshitools config show
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## ✅ Verification Checklist
|
|
237
|
+
|
|
238
|
+
Before you start trading:
|
|
239
|
+
|
|
240
|
+
- [ ] Demo API credentials obtained from Kalshi
|
|
241
|
+
- [ ] Configuration completed (config init or .env)
|
|
242
|
+
- [ ] Private key file placed in `~/.kalshitools/`
|
|
243
|
+
- [ ] File permissions set to 600
|
|
244
|
+
- [ ] `kalshitools config show` displays your email (redacted)
|
|
245
|
+
- [ ] `kalshitools portfolio balance` returns successfully
|
|
246
|
+
- [ ] You understand the difference between demo and production
|
|
247
|
+
- [ ] You've tested with `--dry-run` flag
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
**Ready to go!** You're all set up for local testing with the demo API. 🚀
|
|
@@ -15,18 +15,23 @@ export default class PortfolioBalance extends BaseCommand {
|
|
|
15
15
|
const client = createClientFromConfig();
|
|
16
16
|
// Fetch balance
|
|
17
17
|
const balance = await client.getBalance();
|
|
18
|
+
// Convert cents to dollars
|
|
19
|
+
const balanceDollars = balance.balance / 100;
|
|
20
|
+
const portfolioValueDollars = balance.portfolio_value / 100;
|
|
18
21
|
if (this.formatter.isJSONMode()) {
|
|
19
|
-
|
|
22
|
+
// Return in dollars for readability
|
|
23
|
+
this.formatter.success({
|
|
24
|
+
balance: balanceDollars,
|
|
25
|
+
portfolio_value: portfolioValueDollars,
|
|
26
|
+
});
|
|
20
27
|
}
|
|
21
28
|
else {
|
|
22
29
|
this.log(chalk.cyan.bold('Account Balance'));
|
|
23
30
|
this.log();
|
|
24
|
-
this.log(`${chalk.cyan('
|
|
25
|
-
this.log(`${chalk.cyan('
|
|
26
|
-
this.log();
|
|
27
|
-
this.log(chalk.gray(`Total: $${(balance.balance + balance.payout).toFixed(2)}`));
|
|
31
|
+
this.log(`${chalk.cyan('Available:')} ${chalk.green('$' + balanceDollars.toFixed(2))}`);
|
|
32
|
+
this.log(`${chalk.cyan('Portfolio Value:')} ${chalk.yellow('$' + portfolioValueDollars.toFixed(2))}`);
|
|
28
33
|
}
|
|
29
|
-
logger.info({ balance:
|
|
34
|
+
logger.info({ balance: balanceDollars, portfolio_value: portfolioValueDollars }, 'Balance fetched successfully');
|
|
30
35
|
}
|
|
31
36
|
catch (error) {
|
|
32
37
|
// Error will be handled by BaseCommand.catch()
|
|
@@ -42,13 +42,18 @@ export class KalshiClient {
|
|
|
42
42
|
// Add request interceptor for authentication
|
|
43
43
|
this.axios.interceptors.request.use((config) => {
|
|
44
44
|
const method = (config.method || 'GET').toUpperCase();
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// CRITICAL: Include baseURL pathname in signature
|
|
46
|
+
// Kalshi expects signature over full path: /trade-api/v2/portfolio/balance
|
|
47
|
+
// Not just the relative path: /portfolio/balance
|
|
48
|
+
const baseUrlPath = new URL(baseUrl).pathname;
|
|
49
|
+
const relativePath = config.url || '/';
|
|
50
|
+
const fullPath = baseUrlPath + relativePath;
|
|
51
|
+
const authHeaders = this.auth.generateAuthHeaders(method, fullPath);
|
|
47
52
|
// Set auth headers
|
|
48
53
|
for (const [key, value] of Object.entries(authHeaders)) {
|
|
49
54
|
config.headers.set(key, value);
|
|
50
55
|
}
|
|
51
|
-
logger.debug({ method, path }, 'Making API request');
|
|
56
|
+
logger.debug({ method, path: fullPath }, 'Making API request');
|
|
52
57
|
return config;
|
|
53
58
|
});
|
|
54
59
|
// Add response interceptor for error handling
|
|
@@ -94,7 +99,9 @@ export class KalshiClient {
|
|
|
94
99
|
details: response.data.error.details,
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
|
-
|
|
102
|
+
// Kalshi API doesn't always wrap in a data envelope
|
|
103
|
+
// Return response.data.data if it exists, otherwise response.data
|
|
104
|
+
return (response.data.data ?? response.data);
|
|
98
105
|
});
|
|
99
106
|
}
|
|
100
107
|
/**
|
|
@@ -109,7 +116,9 @@ export class KalshiClient {
|
|
|
109
116
|
details: response.data.error.details,
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
|
-
|
|
119
|
+
// Kalshi API doesn't always wrap in a data envelope
|
|
120
|
+
// Return response.data.data if it exists, otherwise response.data
|
|
121
|
+
return (response.data.data ?? response.data);
|
|
113
122
|
});
|
|
114
123
|
}
|
|
115
124
|
/**
|
|
@@ -124,7 +133,9 @@ export class KalshiClient {
|
|
|
124
133
|
details: response.data.error.details,
|
|
125
134
|
});
|
|
126
135
|
}
|
|
127
|
-
|
|
136
|
+
// Kalshi API doesn't always wrap in a data envelope
|
|
137
|
+
// Return response.data.data if it exists, otherwise response.data
|
|
138
|
+
return (response.data.data ?? response.data);
|
|
128
139
|
});
|
|
129
140
|
}
|
|
130
141
|
/**
|
|
@@ -139,7 +150,9 @@ export class KalshiClient {
|
|
|
139
150
|
*/
|
|
140
151
|
async getPositions(params) {
|
|
141
152
|
logger.info({ params }, 'Fetching portfolio positions');
|
|
142
|
-
|
|
153
|
+
const response = await this.get('/portfolio/positions', { params });
|
|
154
|
+
// Kalshi returns { market_positions: [...] }, not just the array
|
|
155
|
+
return response.market_positions || [];
|
|
143
156
|
}
|
|
144
157
|
/**
|
|
145
158
|
* Get markets
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
# Development Guide
|
|
2
|
+
|
|
3
|
+
This guide covers setting up kalshitools for local development and testing.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Initial Setup](#initial-setup)
|
|
8
|
+
- [API Credentials Setup](#api-credentials-setup)
|
|
9
|
+
- [Configuration Methods](#configuration-methods)
|
|
10
|
+
- [Testing](#testing)
|
|
11
|
+
- [Troubleshooting](#troubleshooting)
|
|
12
|
+
- [Best Practices](#best-practices)
|
|
13
|
+
|
|
14
|
+
## Initial Setup
|
|
15
|
+
|
|
16
|
+
### 1. Clone and Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
git clone https://github.com/yourusername/kalshitools.git
|
|
20
|
+
cd kalshitools
|
|
21
|
+
npm install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Build the Project
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm run build
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 3. Link for Local Development
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm link
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Now you can use `kalshitools` command anywhere on your system.
|
|
37
|
+
|
|
38
|
+
## API Credentials Setup
|
|
39
|
+
|
|
40
|
+
### Obtain Demo API Credentials
|
|
41
|
+
|
|
42
|
+
1. Visit [Kalshi Demo Portal](https://demo-api.kalshi.co)
|
|
43
|
+
2. Sign up or log in to your demo account
|
|
44
|
+
3. Navigate to API settings
|
|
45
|
+
4. Generate a new API key pair:
|
|
46
|
+
- **API Key ID**: Your registered email address
|
|
47
|
+
- **Private Key**: Download the `.pem` file
|
|
48
|
+
|
|
49
|
+
### Store Credentials Securely
|
|
50
|
+
|
|
51
|
+
**IMPORTANT**: Never commit real credentials to the repository!
|
|
52
|
+
|
|
53
|
+
The `.gitignore` file protects:
|
|
54
|
+
- `*.pem`, `*.key`, `*-private-key*` (private keys)
|
|
55
|
+
- `.env`, `.env.local`, `.env.*.local` (environment files)
|
|
56
|
+
- `config.json`, `.kalshitools/` (config directory)
|
|
57
|
+
|
|
58
|
+
## Configuration Methods
|
|
59
|
+
|
|
60
|
+
### Method 1: Interactive Configuration (Recommended for Development)
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# Run the configuration wizard
|
|
64
|
+
kalshitools config init
|
|
65
|
+
|
|
66
|
+
# Follow the prompts
|
|
67
|
+
Environment: demo
|
|
68
|
+
API Key ID: your-email@example.com
|
|
69
|
+
Private Key Path: ~/.kalshitools/demo-private-key.pem
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
This creates `~/.config/kalshitools/config.json` with your settings.
|
|
73
|
+
|
|
74
|
+
**Place your private key:**
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
mkdir -p ~/.kalshitools
|
|
78
|
+
cp ~/Downloads/demo-private-key.pem ~/.kalshitools/demo-private-key.pem
|
|
79
|
+
chmod 600 ~/.kalshitools/demo-private-key.pem
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Verify configuration:**
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
kalshitools config show
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Expected output:
|
|
89
|
+
```
|
|
90
|
+
Kalshi API Configuration
|
|
91
|
+
Environment: DEMO
|
|
92
|
+
API Key ID: yo****@ex******.com
|
|
93
|
+
Private Key Path: /Users/you/.kalshitools/demo-private-key.pem
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Method 2: Environment Variables (Quick Testing)
|
|
97
|
+
|
|
98
|
+
Create a `.env` file in the project root:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
cp .env.example .env
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Edit `.env` with your credentials:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
KALSHI_ENV=demo
|
|
108
|
+
KALSHI_API_KEY_ID=your-email@example.com
|
|
109
|
+
KALSHI_PRIVATE_KEY_PATH=/absolute/path/to/demo-private-key.pem
|
|
110
|
+
LOG_LEVEL=debug
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Use environment variables:**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Source the file
|
|
117
|
+
source .env
|
|
118
|
+
|
|
119
|
+
# Or export manually
|
|
120
|
+
export KALSHI_ENV=demo
|
|
121
|
+
export KALSHI_API_KEY_ID=your-email@example.com
|
|
122
|
+
export KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Method 3: Multiple Credential Sets
|
|
126
|
+
|
|
127
|
+
For testing with multiple accounts:
|
|
128
|
+
|
|
129
|
+
**Create separate env files:**
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# Demo account 1
|
|
133
|
+
cat > .env.demo1 <<EOF
|
|
134
|
+
KALSHI_ENV=demo
|
|
135
|
+
KALSHI_API_KEY_ID=demo1@example.com
|
|
136
|
+
KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo1-private-key.pem
|
|
137
|
+
EOF
|
|
138
|
+
|
|
139
|
+
# Demo account 2
|
|
140
|
+
cat > .env.demo2 <<EOF
|
|
141
|
+
KALSHI_ENV=demo
|
|
142
|
+
KALSHI_API_KEY_ID=demo2@example.com
|
|
143
|
+
KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo2-private-key.pem
|
|
144
|
+
EOF
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Switch between accounts:**
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Use demo1
|
|
151
|
+
source .env.demo1
|
|
152
|
+
kalshitools portfolio balance
|
|
153
|
+
|
|
154
|
+
# Use demo2
|
|
155
|
+
source .env.demo2
|
|
156
|
+
kalshitools portfolio balance
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Configuration Precedence
|
|
160
|
+
|
|
161
|
+
Environment variables **override** config file values:
|
|
162
|
+
|
|
163
|
+
1. **Environment Variables** (highest priority)
|
|
164
|
+
- `KALSHI_ENV`
|
|
165
|
+
- `KALSHI_API_KEY_ID`
|
|
166
|
+
- `KALSHI_PRIVATE_KEY_PATH`
|
|
167
|
+
|
|
168
|
+
2. **Config File** (`~/.config/kalshitools/config.json`)
|
|
169
|
+
- Set via `kalshitools config init`
|
|
170
|
+
|
|
171
|
+
3. **Default Values** (lowest priority)
|
|
172
|
+
- Environment: `demo`
|
|
173
|
+
|
|
174
|
+
## Testing
|
|
175
|
+
|
|
176
|
+
### Test API Connection
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Check configuration
|
|
180
|
+
kalshitools config show
|
|
181
|
+
|
|
182
|
+
# Test authentication and basic API call
|
|
183
|
+
kalshitools portfolio balance
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Expected output:
|
|
187
|
+
```
|
|
188
|
+
Account Balance
|
|
189
|
+
Available: $10,000.00
|
|
190
|
+
Total: $10,000.00
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Test Market Data
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
# List active markets
|
|
197
|
+
kalshitools markets list --status active --limit 5
|
|
198
|
+
|
|
199
|
+
# Get specific market details
|
|
200
|
+
kalshitools markets show TICKER-SYMBOL
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Test Orders (Dry Run)
|
|
204
|
+
|
|
205
|
+
**Always use `--dry-run` first:**
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
kalshitools orders create \
|
|
209
|
+
--ticker MARKET-TICKER \
|
|
210
|
+
--action buy \
|
|
211
|
+
--side yes \
|
|
212
|
+
--quantity 10 \
|
|
213
|
+
--type market \
|
|
214
|
+
--dry-run
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
This validates the order without actually placing it.
|
|
218
|
+
|
|
219
|
+
### Test JSON Output
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# JSON format for programmatic use
|
|
223
|
+
kalshitools portfolio balance --json
|
|
224
|
+
kalshitools markets list --json
|
|
225
|
+
kalshitools orders list --json
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Run Unit Tests
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Run all tests
|
|
232
|
+
npm test
|
|
233
|
+
|
|
234
|
+
# Run with coverage
|
|
235
|
+
npm run test:coverage
|
|
236
|
+
|
|
237
|
+
# Run specific test file
|
|
238
|
+
npm test -- tests/commands/config/init.test.ts
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Troubleshooting
|
|
242
|
+
|
|
243
|
+
### Issue: "Private key not found"
|
|
244
|
+
|
|
245
|
+
**Symptoms:**
|
|
246
|
+
```
|
|
247
|
+
Error: ENOENT: no such file or directory, open '/path/to/private-key.pem'
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Solutions:**
|
|
251
|
+
|
|
252
|
+
1. **Check the path in configuration:**
|
|
253
|
+
```bash
|
|
254
|
+
kalshitools config show
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
2. **Verify file exists:**
|
|
258
|
+
```bash
|
|
259
|
+
ls -la ~/.kalshitools/demo-private-key.pem
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
3. **Re-configure with correct path:**
|
|
263
|
+
```bash
|
|
264
|
+
kalshitools config init --privateKeyPath /correct/path/to/key.pem
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
4. **Check tilde expansion:**
|
|
268
|
+
```bash
|
|
269
|
+
# If using ~/ in path, ensure it's expanded
|
|
270
|
+
export KALSHI_PRIVATE_KEY_PATH="$HOME/.kalshitools/demo-private-key.pem"
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Issue: "Authentication failed"
|
|
274
|
+
|
|
275
|
+
**Symptoms:**
|
|
276
|
+
```
|
|
277
|
+
Error: Authentication failed: Invalid credentials
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Solutions:**
|
|
281
|
+
|
|
282
|
+
1. **Verify Key ID is correct:**
|
|
283
|
+
- Should be your email address from Kalshi
|
|
284
|
+
- Check for typos
|
|
285
|
+
|
|
286
|
+
2. **Verify private key is not corrupted:**
|
|
287
|
+
```bash
|
|
288
|
+
# Check file is readable and starts with "-----BEGIN PRIVATE KEY-----"
|
|
289
|
+
head -1 ~/.kalshitools/demo-private-key.pem
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
3. **Regenerate credentials:**
|
|
293
|
+
- Go to Kalshi Demo Portal
|
|
294
|
+
- Delete old API key
|
|
295
|
+
- Generate new key pair
|
|
296
|
+
- Update configuration
|
|
297
|
+
|
|
298
|
+
4. **Check environment mismatch:**
|
|
299
|
+
```bash
|
|
300
|
+
# Ensure you're using demo credentials with demo environment
|
|
301
|
+
kalshitools config show
|
|
302
|
+
# Environment should be "DEMO"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Issue: "Permission denied reading private key"
|
|
306
|
+
|
|
307
|
+
**Symptoms:**
|
|
308
|
+
```
|
|
309
|
+
Error: EACCES: permission denied, open '/path/to/private-key.pem'
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
**Solution:**
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# Set proper permissions (read/write for owner only)
|
|
316
|
+
chmod 600 ~/.kalshitools/demo-private-key.pem
|
|
317
|
+
|
|
318
|
+
# Verify
|
|
319
|
+
ls -la ~/.kalshitools/demo-private-key.pem
|
|
320
|
+
# Should show: -rw-------
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Issue: "Command not found: kalshitools"
|
|
324
|
+
|
|
325
|
+
**Solutions:**
|
|
326
|
+
|
|
327
|
+
1. **Re-link after rebuild:**
|
|
328
|
+
```bash
|
|
329
|
+
npm run build
|
|
330
|
+
npm link
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
2. **Check npm global bin path:**
|
|
334
|
+
```bash
|
|
335
|
+
npm bin -g
|
|
336
|
+
# Ensure this directory is in your PATH
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
3. **Use local dev version:**
|
|
340
|
+
```bash
|
|
341
|
+
./bin/dev.js config show
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Issue: "Environment variables not being used"
|
|
345
|
+
|
|
346
|
+
**Symptoms:**
|
|
347
|
+
- Set `KALSHI_API_KEY_ID` but config shows different value
|
|
348
|
+
|
|
349
|
+
**Solutions:**
|
|
350
|
+
|
|
351
|
+
1. **Verify environment variables are set:**
|
|
352
|
+
```bash
|
|
353
|
+
echo $KALSHI_API_KEY_ID
|
|
354
|
+
echo $KALSHI_PRIVATE_KEY_PATH
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
2. **Source the .env file:**
|
|
358
|
+
```bash
|
|
359
|
+
source .env
|
|
360
|
+
# NOT: sh .env or bash .env
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
3. **Export manually:**
|
|
364
|
+
```bash
|
|
365
|
+
export KALSHI_ENV=demo
|
|
366
|
+
export KALSHI_API_KEY_ID=your@email.com
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
4. **Check shell session:**
|
|
370
|
+
- Environment variables only persist in the current shell
|
|
371
|
+
- Open a new terminal? You need to source .env again
|
|
372
|
+
|
|
373
|
+
### Issue: "Invalid ticker symbol"
|
|
374
|
+
|
|
375
|
+
**Symptoms:**
|
|
376
|
+
```
|
|
377
|
+
Error: Market not found: TICKER-SYMBOL
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
**Solutions:**
|
|
381
|
+
|
|
382
|
+
1. **List available markets first:**
|
|
383
|
+
```bash
|
|
384
|
+
kalshitools markets list --status active
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
2. **Use exact ticker from market list:**
|
|
388
|
+
- Tickers are case-sensitive
|
|
389
|
+
- Copy-paste from `markets list` output
|
|
390
|
+
|
|
391
|
+
3. **Check market status:**
|
|
392
|
+
```bash
|
|
393
|
+
# Market might be closed or settled
|
|
394
|
+
kalshitools markets show TICKER-SYMBOL
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## Best Practices
|
|
398
|
+
|
|
399
|
+
### Development Workflow
|
|
400
|
+
|
|
401
|
+
1. **Always use demo environment for testing:**
|
|
402
|
+
```bash
|
|
403
|
+
export KALSHI_ENV=demo
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
2. **Use `--dry-run` for order testing:**
|
|
407
|
+
```bash
|
|
408
|
+
kalshitools orders create ... --dry-run
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
3. **Use `--json` for debugging:**
|
|
412
|
+
```bash
|
|
413
|
+
kalshitools markets list --json | jq
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
4. **Set debug logging when developing:**
|
|
417
|
+
```bash
|
|
418
|
+
export LOG_LEVEL=debug
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### Security Best Practices
|
|
422
|
+
|
|
423
|
+
1. **Never commit credentials:**
|
|
424
|
+
- Always check `.gitignore` before pushing
|
|
425
|
+
- Use `git status` to verify no credential files
|
|
426
|
+
|
|
427
|
+
2. **Use restrictive file permissions:**
|
|
428
|
+
```bash
|
|
429
|
+
chmod 600 ~/.kalshitools/*.pem
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
3. **Separate demo and production:**
|
|
433
|
+
- Use different key pairs
|
|
434
|
+
- Store production keys outside the repo
|
|
435
|
+
- Double-check `KALSHI_ENV` before trading
|
|
436
|
+
|
|
437
|
+
4. **Rotate keys regularly:**
|
|
438
|
+
- Regenerate API keys periodically
|
|
439
|
+
- Delete old keys from Kalshi portal
|
|
440
|
+
|
|
441
|
+
### Testing Best Practices
|
|
442
|
+
|
|
443
|
+
1. **Test configuration first:**
|
|
444
|
+
```bash
|
|
445
|
+
kalshitools config show
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
2. **Verify connectivity:**
|
|
449
|
+
```bash
|
|
450
|
+
kalshitools portfolio balance
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
3. **Use small quantities for testing:**
|
|
454
|
+
```bash
|
|
455
|
+
--quantity 1 # Not --quantity 1000
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
4. **Always check order details:**
|
|
459
|
+
```bash
|
|
460
|
+
# Review the order summary before confirming
|
|
461
|
+
# Use --yes to skip confirmation (be careful!)
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
### Code Development
|
|
465
|
+
|
|
466
|
+
1. **Run tests before committing:**
|
|
467
|
+
```bash
|
|
468
|
+
npm test
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
2. **Build and test locally:**
|
|
472
|
+
```bash
|
|
473
|
+
npm run build
|
|
474
|
+
./bin/dev.js config show
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
3. **Use TypeScript types:**
|
|
478
|
+
- Leverage the typed API client
|
|
479
|
+
- Check `src/lib/types.ts` for available types
|
|
480
|
+
|
|
481
|
+
4. **Follow existing patterns:**
|
|
482
|
+
- Look at existing commands for structure
|
|
483
|
+
- Use oclif conventions
|
|
484
|
+
- Add tests for new features
|
|
485
|
+
|
|
486
|
+
## Quick Reference
|
|
487
|
+
|
|
488
|
+
### Essential Commands
|
|
489
|
+
|
|
490
|
+
```bash
|
|
491
|
+
# Configuration
|
|
492
|
+
kalshitools config init # Interactive setup
|
|
493
|
+
kalshitools config show # View config (redacted)
|
|
494
|
+
kalshitools config show --json # JSON output
|
|
495
|
+
|
|
496
|
+
# Portfolio
|
|
497
|
+
kalshitools portfolio balance # Account balance
|
|
498
|
+
kalshitools portfolio positions # Current positions
|
|
499
|
+
kalshitools portfolio fills # Trade history
|
|
500
|
+
|
|
501
|
+
# Markets
|
|
502
|
+
kalshitools markets list # All markets
|
|
503
|
+
kalshitools markets list --status active # Active only
|
|
504
|
+
kalshitools markets show TICKER # Market details
|
|
505
|
+
|
|
506
|
+
# Orders
|
|
507
|
+
kalshitools orders list # Your orders
|
|
508
|
+
kalshitools orders create ... # Place order
|
|
509
|
+
kalshitools orders create ... --dry-run # Simulate order
|
|
510
|
+
kalshitools orders cancel ORDER_ID # Cancel order
|
|
511
|
+
|
|
512
|
+
# Help
|
|
513
|
+
kalshitools --help # Main help
|
|
514
|
+
kalshitools COMMAND --help # Command help
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
### Environment Variables
|
|
518
|
+
|
|
519
|
+
```bash
|
|
520
|
+
KALSHI_ENV=demo # demo or production
|
|
521
|
+
KALSHI_API_KEY_ID=your@email.com # Your email
|
|
522
|
+
KALSHI_PRIVATE_KEY_PATH=/path/to/key.pem # Private key path
|
|
523
|
+
LOG_LEVEL=debug # Logging level
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### File Locations
|
|
527
|
+
|
|
528
|
+
```
|
|
529
|
+
~/.config/kalshitools/config.json # Main config file
|
|
530
|
+
~/.kalshitools/demo-private-key.pem # Default key location
|
|
531
|
+
.env # Local env vars (gitignored)
|
|
532
|
+
.env.example # Template (committed)
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
## Getting Help
|
|
536
|
+
|
|
537
|
+
- **Issues**: https://github.com/yourusername/kalshitools/issues
|
|
538
|
+
- **Kalshi API Docs**: https://docs.kalshi.com
|
|
539
|
+
- **Demo Portal**: https://demo-api.kalshi.co
|
|
540
|
+
|
|
541
|
+
## Contributing
|
|
542
|
+
|
|
543
|
+
See [CONTRIBUTING.md](../CONTRIBUTING.md) for guidelines on:
|
|
544
|
+
- Code style
|
|
545
|
+
- Pull request process
|
|
546
|
+
- Testing requirements
|
|
547
|
+
- Documentation standards
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaberoo/kalshitools",
|
|
3
3
|
"description": "CLI for interacting with Kalshi prediction markets API",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -45,7 +45,11 @@
|
|
|
45
45
|
"files": [
|
|
46
46
|
"./bin",
|
|
47
47
|
"./dist",
|
|
48
|
-
"./oclif.manifest.json"
|
|
48
|
+
"./oclif.manifest.json",
|
|
49
|
+
"./docs",
|
|
50
|
+
"./SETUP_DEMO_API.md",
|
|
51
|
+
"./.env.local.example",
|
|
52
|
+
"./.env.example"
|
|
49
53
|
],
|
|
50
54
|
"homepage": "https://github.com/kalshitools/kalshitools",
|
|
51
55
|
"keywords": [
|