@gaberoo/kalshitools 1.0.1 → 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/README.md +11 -11
- 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/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,7 +163,7 @@ $ npm install -g @gaberoo/kalshitools
|
|
|
163
163
|
$ kalshitools COMMAND
|
|
164
164
|
running command...
|
|
165
165
|
$ kalshitools (--version)
|
|
166
|
-
@gaberoo/kalshitools/1.0.
|
|
166
|
+
@gaberoo/kalshitools/1.0.2 darwin-arm64 node-v22.20.0
|
|
167
167
|
$ kalshitools --help [COMMAND]
|
|
168
168
|
USAGE
|
|
169
169
|
$ kalshitools COMMAND
|
|
@@ -218,7 +218,7 @@ EXAMPLES
|
|
|
218
218
|
$ kalshitools config init --env production
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
_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)_
|
|
222
222
|
|
|
223
223
|
## `kalshitools config show`
|
|
224
224
|
|
|
@@ -240,7 +240,7 @@ EXAMPLES
|
|
|
240
240
|
$ kalshitools config show --json
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
-
_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)_
|
|
244
244
|
|
|
245
245
|
## `kalshitools help [COMMAND]`
|
|
246
246
|
|
|
@@ -287,7 +287,7 @@ EXAMPLES
|
|
|
287
287
|
$ kalshitools markets list --json
|
|
288
288
|
```
|
|
289
289
|
|
|
290
|
-
_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)_
|
|
291
291
|
|
|
292
292
|
## `kalshitools markets show TICKER`
|
|
293
293
|
|
|
@@ -312,7 +312,7 @@ EXAMPLES
|
|
|
312
312
|
$ kalshitools markets show TICKER --json
|
|
313
313
|
```
|
|
314
314
|
|
|
315
|
-
_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)_
|
|
316
316
|
|
|
317
317
|
## `kalshitools orders cancel ORDERID`
|
|
318
318
|
|
|
@@ -340,7 +340,7 @@ EXAMPLES
|
|
|
340
340
|
$ kalshitools orders cancel ORDER_ID --json
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
-
_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)_
|
|
344
344
|
|
|
345
345
|
## `kalshitools orders create`
|
|
346
346
|
|
|
@@ -378,7 +378,7 @@ EXAMPLES
|
|
|
378
378
|
$ kalshitools orders create --ticker TICKER --action buy --side yes --quantity 100 --dry-run
|
|
379
379
|
```
|
|
380
380
|
|
|
381
|
-
_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)_
|
|
382
382
|
|
|
383
383
|
## `kalshitools orders list`
|
|
384
384
|
|
|
@@ -409,7 +409,7 @@ EXAMPLES
|
|
|
409
409
|
$ kalshitools orders list --json
|
|
410
410
|
```
|
|
411
411
|
|
|
412
|
-
_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)_
|
|
413
413
|
|
|
414
414
|
## `kalshitools plugins`
|
|
415
415
|
|
|
@@ -721,7 +721,7 @@ EXAMPLES
|
|
|
721
721
|
$ kalshitools portfolio balance --json
|
|
722
722
|
```
|
|
723
723
|
|
|
724
|
-
_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)_
|
|
725
725
|
|
|
726
726
|
## `kalshitools portfolio fills`
|
|
727
727
|
|
|
@@ -749,7 +749,7 @@ EXAMPLES
|
|
|
749
749
|
$ kalshitools portfolio fills --json
|
|
750
750
|
```
|
|
751
751
|
|
|
752
|
-
_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)_
|
|
753
753
|
|
|
754
754
|
## `kalshitools portfolio positions`
|
|
755
755
|
|
|
@@ -771,5 +771,5 @@ EXAMPLES
|
|
|
771
771
|
$ kalshitools portfolio positions --json
|
|
772
772
|
```
|
|
773
773
|
|
|
774
|
-
_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)_
|
|
775
775
|
<!-- commandsstop -->
|
|
@@ -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
|
package/oclif.manifest.json
CHANGED