jaspervault_cli 1.0.15 → 1.0.16
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/bin/jv.js +2 -0
- package/dist/bin/jv.js.map +1 -1
- package/dist/src/commands/price.d.ts +2 -0
- package/dist/src/commands/price.js +28 -0
- package/dist/src/commands/price.js.map +1 -0
- package/dist/src/templates/skill-body.js +39 -1
- package/dist/src/templates/skill-body.js.map +1 -1
- package/package.json +1 -1
package/dist/bin/jv.js
CHANGED
|
@@ -13,6 +13,7 @@ import { registerVaultCommand } from '../src/commands/vault.js';
|
|
|
13
13
|
import { registerDepositCommand } from '../src/commands/deposit.js';
|
|
14
14
|
import { registerInitCommand } from '../src/commands/init.js';
|
|
15
15
|
import { registerConnectCommand } from '../src/commands/connect.js';
|
|
16
|
+
import { registerPriceCommand } from '../src/commands/price.js';
|
|
16
17
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
18
|
const { version } = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf-8'));
|
|
18
19
|
const program = new Command();
|
|
@@ -30,5 +31,6 @@ registerVaultCommand(program);
|
|
|
30
31
|
registerDepositCommand(program);
|
|
31
32
|
registerInitCommand(program);
|
|
32
33
|
registerConnectCommand(program);
|
|
34
|
+
registerPriceCommand(program);
|
|
33
35
|
program.parse();
|
|
34
36
|
//# sourceMappingURL=jv.js.map
|
package/dist/bin/jv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jv.js","sourceRoot":"","sources":["../../bin/jv.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,oBAAoB,E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E,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAC5B,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC,CACtC,CAAC;AAEzB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,IAAI,CAAC;KACV,WAAW,CAAC,6DAA6D,CAAC;KAC1E,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC9B,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAC3B,iBAAiB,CAAC,OAAO,CAAC,CAAC;AAC3B,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAC5B,yBAAyB,CAAC,OAAO,CAAC,CAAC;AACnC,qBAAqB,CAAC,OAAO,CAAC,CAAC;AAC/B,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC9B,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAChC,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC7B,sBAAsB,CAAC,OAAO,CAAC,CAAC;AAChC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAE9B,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { fetchCurrentPrice } from '../services/price-service.js';
|
|
3
|
+
import { printJson, exitWithError, EXIT_CODES } from '../utils/output.js';
|
|
4
|
+
export function registerPriceCommand(program) {
|
|
5
|
+
program
|
|
6
|
+
.command('price')
|
|
7
|
+
.description('Fetch current market price from Quote Center')
|
|
8
|
+
.requiredOption('--symbol <symbol>', 'Asset symbol (e.g. JBTC, CBBTC)')
|
|
9
|
+
.option('--network <name>', 'Network name', 'jaspervault')
|
|
10
|
+
.option('--pretty', 'Pretty-print JSON output')
|
|
11
|
+
.action(async (opts) => {
|
|
12
|
+
try {
|
|
13
|
+
const priceWei = await fetchCurrentPrice(opts.symbol, opts.network);
|
|
14
|
+
const price = ethers.formatUnits(priceWei, 18);
|
|
15
|
+
printJson({
|
|
16
|
+
symbol: opts.symbol.toUpperCase(),
|
|
17
|
+
price,
|
|
18
|
+
priceWei: priceWei.toString(),
|
|
19
|
+
source: 'quote_center',
|
|
20
|
+
timestamp: new Date().toISOString(),
|
|
21
|
+
}, opts.pretty);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
exitWithError(`Failed to fetch price: ${err.message}`, EXIT_CODES.HTTP_ERROR);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=price.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../src/commands/price.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,8CAA8C,CAAC;SAC3D,cAAc,CAAC,mBAAmB,EAAE,iCAAiC,CAAC;SACtE,MAAM,CAAC,kBAAkB,EAAE,cAAc,EAAE,aAAa,CAAC;SACzD,MAAM,CAAC,UAAU,EAAE,0BAA0B,CAAC;SAC9C,MAAM,CACL,KAAK,EAAE,IAA2D,EAAE,EAAE;QACpE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACpE,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAE/C,SAAS,CACP;gBACE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;gBACjC,KAAK;gBACL,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE;gBAC7B,MAAM,EAAE,cAAc;gBACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;aACpC,EACD,IAAI,CAAC,MAAM,CACZ,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,aAAa,CACX,0BAA2B,GAAa,CAAC,OAAO,EAAE,EAClD,UAAU,CAAC,UAAU,CACtB,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACN,CAAC"}
|
|
@@ -100,7 +100,7 @@ Do NOT ask the user to set \`PRIVATE_KEY\`. Do NOT suggest \`jv vault init\` unl
|
|
|
100
100
|
| "open a $3,000 notional position at 50x" | margin = 3000 / 50 = 60 | \`--margin 60\` |
|
|
101
101
|
| "long 0.1 BTC at 50x" | margin = (0.1 × current_price) / 50 | \`--margin <result>\` |
|
|
102
102
|
|
|
103
|
-
CRITICAL: When the user specifies an asset amount (e.g. "0.1 BTC"), you MUST first
|
|
103
|
+
CRITICAL: When the user specifies an asset amount (e.g. "0.1 BTC"), you MUST first run \`jv price --symbol JBTC --pretty\` to get the current price, then compute \`notional = size × price\`, then \`margin = notional / leverage\` before passing \`--margin\`.
|
|
104
104
|
|
|
105
105
|
**How to read \`jv orders list\` output:**
|
|
106
106
|
|
|
@@ -113,8 +113,46 @@ CRITICAL: When the user specifies an asset amount (e.g. "0.1 BTC"), you MUST fir
|
|
|
113
113
|
|
|
114
114
|
To calculate notional from output: \`notional = margin × leverage\` (or \`size × current_price\`)
|
|
115
115
|
|
|
116
|
+
**How to calculate unrealized PnL:**
|
|
117
|
+
|
|
118
|
+
When the user asks about profit/loss, portfolio value, or position health, you MUST fetch the current price first using \`jv price\`, then compute PnL from \`jv orders list\` output:
|
|
119
|
+
|
|
120
|
+
| Step | Formula |
|
|
121
|
+
|------|---------|
|
|
122
|
+
| 1. Get current price | \`jv price --symbol JBTC --pretty\` → read \`price\` field |
|
|
123
|
+
| 2. Get position data | \`jv orders list --pretty\` → read \`size\`, \`entryPriceUsd\`, \`margin\`, \`positionSide\` |
|
|
124
|
+
| 3. Compute PnL (LONG) | \`unrealizedPnL = size × (currentPrice − entryPrice)\` |
|
|
125
|
+
| 3. Compute PnL (SHORT) | \`unrealizedPnL = size × (entryPrice − currentPrice)\` |
|
|
126
|
+
| 4. PnL percentage | \`pnlPercent = unrealizedPnL / margin × 100%\` |
|
|
127
|
+
| 5. Effective leverage loss | \`leveragedPnlPercent = priceChangePercent × leverage\` |
|
|
128
|
+
|
|
129
|
+
Example: LONG 0.0428 JBTC, entry $70,000, current $71,000, margin 60 USDC
|
|
130
|
+
- PnL = 0.0428 × (71000 − 70000) = +$42.80
|
|
131
|
+
- PnL% = 42.80 / 60 = +71.3%
|
|
132
|
+
|
|
133
|
+
IMPORTANT: NEVER guess or estimate the current price from your training data. ALWAYS use \`jv price\` to get the real-time price from Quote Center before any PnL calculation or price-dependent operation.
|
|
134
|
+
|
|
116
135
|
## Intent Mapping
|
|
117
136
|
|
|
137
|
+
### Getting Market Price (MUST use before any price-dependent operation)
|
|
138
|
+
|
|
139
|
+
When the user asks about **current price**, **market quote**, **how much is BTC**, **profit/loss**, **PnL**, or before **opening a position with asset quantity**:
|
|
140
|
+
|
|
141
|
+
\`\`\`bash
|
|
142
|
+
# Get current JBTC price
|
|
143
|
+
jv price --symbol JBTC --pretty
|
|
144
|
+
|
|
145
|
+
# Get current CBBTC price
|
|
146
|
+
jv price --symbol CBBTC --pretty
|
|
147
|
+
\`\`\`
|
|
148
|
+
|
|
149
|
+
Output:
|
|
150
|
+
\`\`\`json
|
|
151
|
+
{"symbol":"JBTC","price":"87295.123456","priceWei":"87295123456000000000000","source":"quote_center","timestamp":"2026-03-05T10:30:00.000Z"}
|
|
152
|
+
\`\`\`
|
|
153
|
+
|
|
154
|
+
Use the \`price\` field (human-readable USD value) for display and calculations. This command does NOT require vault initialization — it can be run anytime.
|
|
155
|
+
|
|
118
156
|
### Creating Orders (Open New Position)
|
|
119
157
|
|
|
120
158
|
When the user wants to **open a position**, **place a market order**, or **place a limit order**:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill-body.js","sourceRoot":"","sources":["../../../src/templates/skill-body.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CACzC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,OAAO,CAAC,CACzC,CAAC;AAEzB,sEAAsE;AACtE,MAAM,CAAC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;wBAcE,WAAW;;CAElC,CAAC,IAAI,EAAE,CAAC;AAET,2EAA2E;AAC3E,MAAM,kBAAkB,GAAG
|
|
1
|
+
{"version":3,"file":"skill-body.js","sourceRoot":"","sources":["../../../src/templates/skill-body.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAA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