openbroker 1.0.33

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/cli.ts ADDED
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+ // Open Broker CLI - Hyperliquid trading toolkit
3
+
4
+ import { spawn } from 'child_process';
5
+ import { fileURLToPath } from 'url';
6
+ import path from 'path';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const scriptsDir = path.resolve(__dirname, '../scripts');
11
+
12
+ const commands: Record<string, { script: string; description: string }> = {
13
+ // Setup
14
+ 'setup': { script: 'setup/onboard.ts', description: 'Interactive setup wizard' },
15
+ 'onboard': { script: 'setup/onboard.ts', description: 'Interactive setup wizard' },
16
+ 'approve-builder': { script: 'setup/approve-builder.ts', description: 'Approve builder fee' },
17
+
18
+ // Info
19
+ 'account': { script: 'info/account.ts', description: 'View account balance and equity' },
20
+ 'positions': { script: 'info/positions.ts', description: 'View open positions' },
21
+ 'funding': { script: 'info/funding.ts', description: 'View funding rates' },
22
+ 'markets': { script: 'info/markets.ts', description: 'View market data' },
23
+ 'all-markets': { script: 'info/all-markets.ts', description: 'View all markets (perps, HIP-3, spot)' },
24
+ 'search': { script: 'info/search-markets.ts', description: 'Search for assets across providers' },
25
+ 'spot': { script: 'info/spot.ts', description: 'View spot markets and balances' },
26
+
27
+ // Operations
28
+ 'buy': { script: 'operations/market-order.ts', description: 'Market buy order' },
29
+ 'sell': { script: 'operations/market-order.ts', description: 'Market sell order' },
30
+ 'market': { script: 'operations/market-order.ts', description: 'Market order' },
31
+ 'limit': { script: 'operations/limit-order.ts', description: 'Limit order' },
32
+ 'trigger': { script: 'operations/trigger-order.ts', description: 'Trigger order (TP/SL)' },
33
+ 'tpsl': { script: 'operations/set-tpsl.ts', description: 'Set TP/SL on position' },
34
+ 'cancel': { script: 'operations/cancel.ts', description: 'Cancel orders' },
35
+ 'twap': { script: 'operations/twap.ts', description: 'TWAP execution' },
36
+ 'scale': { script: 'operations/scale.ts', description: 'Scale in/out orders' },
37
+ 'bracket': { script: 'operations/bracket.ts', description: 'Bracket order (entry + TP + SL)' },
38
+ 'chase': { script: 'operations/chase.ts', description: 'Chase order with ALO' },
39
+
40
+ // Strategies
41
+ 'funding-arb': { script: 'strategies/funding-arb.ts', description: 'Funding arbitrage strategy' },
42
+ 'grid': { script: 'strategies/grid.ts', description: 'Grid trading strategy' },
43
+ 'dca': { script: 'strategies/dca.ts', description: 'DCA strategy' },
44
+ 'mm-spread': { script: 'strategies/mm-spread.ts', description: 'Market making (spread)' },
45
+ 'mm-maker': { script: 'strategies/mm-maker.ts', description: 'Market making (ALO)' },
46
+ };
47
+
48
+ function printHelp() {
49
+ console.log(`
50
+ Open Broker - Hyperliquid Trading CLI
51
+
52
+ Usage: openbroker <command> [options]
53
+
54
+ Setup Commands:
55
+ setup, onboard Interactive setup wizard (generate wallet, configure)
56
+ approve-builder Approve builder fee (one-time)
57
+
58
+ Info Commands:
59
+ account View account balance, equity, and margin
60
+ positions View open positions with PnL
61
+ funding View funding rates (sorted by annualized rate)
62
+ markets View market data for main perps
63
+ all-markets View all markets (perps, HIP-3, spot)
64
+ search Search for assets across all providers
65
+ spot View spot markets and balances
66
+
67
+ Trading Commands:
68
+ buy Market buy order
69
+ sell Market sell order
70
+ market Market order (specify --side)
71
+ limit Limit order
72
+ trigger Trigger order (stop loss / take profit)
73
+ tpsl Set TP/SL on existing position
74
+ cancel Cancel orders
75
+
76
+ Advanced Execution:
77
+ twap Time-weighted average price execution
78
+ scale Scale in/out with multiple orders
79
+ bracket Entry with TP and SL
80
+ chase Chase price with ALO orders
81
+
82
+ Strategies:
83
+ funding-arb Funding rate arbitrage
84
+ grid Grid trading
85
+ dca Dollar cost averaging
86
+ mm-spread Market making (spread-based)
87
+ mm-maker Market making (ALO orders)
88
+
89
+ Options:
90
+ --help, -h Show help for a command
91
+ --dry Preview without executing
92
+ --verbose Show debug output
93
+
94
+ Examples:
95
+ openbroker setup # First-time setup
96
+ openbroker account # View account info
97
+ openbroker buy --coin ETH --size 0.1 # Market buy 0.1 ETH
98
+ openbroker limit --coin BTC --side buy --size 0.01 --price 60000
99
+ openbroker search --query GOLD # Find GOLD across providers
100
+ openbroker tpsl --coin HYPE --tp 40 --sl 30 # Set TP/SL on position
101
+
102
+ Documentation: https://github.com/aurracloud/open-broker
103
+ `);
104
+ }
105
+
106
+ function runScript(scriptPath: string, args: string[]) {
107
+ const fullPath = path.join(scriptsDir, scriptPath);
108
+
109
+ // Use tsx to run TypeScript directly
110
+ const child = spawn('npx', ['tsx', fullPath, ...args], {
111
+ stdio: 'inherit',
112
+ cwd: path.resolve(__dirname, '..'),
113
+ env: { ...process.env },
114
+ });
115
+
116
+ child.on('error', (err) => {
117
+ if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
118
+ console.error('Error: npx/tsx not found. Please ensure Node.js is installed.');
119
+ } else {
120
+ console.error('Error:', err.message);
121
+ }
122
+ process.exit(1);
123
+ });
124
+
125
+ child.on('exit', (code) => {
126
+ process.exit(code ?? 0);
127
+ });
128
+ }
129
+
130
+ function main() {
131
+ const args = process.argv.slice(2);
132
+
133
+ if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
134
+ printHelp();
135
+ process.exit(0);
136
+ }
137
+
138
+ const command = args[0].toLowerCase();
139
+ const commandArgs = args.slice(1);
140
+
141
+ // Handle buy/sell shortcuts
142
+ if (command === 'buy') {
143
+ runScript(commands['market'].script, ['--side', 'buy', ...commandArgs]);
144
+ return;
145
+ }
146
+ if (command === 'sell') {
147
+ runScript(commands['market'].script, ['--side', 'sell', ...commandArgs]);
148
+ return;
149
+ }
150
+
151
+ // Handle version
152
+ if (command === '--version' || command === '-v') {
153
+ import('../package.json', { with: { type: 'json' } }).then((pkg) => {
154
+ console.log(`openbroker v${pkg.default.version}`);
155
+ process.exit(0);
156
+ });
157
+ return;
158
+ }
159
+
160
+ const cmd = commands[command];
161
+ if (!cmd) {
162
+ console.error(`Unknown command: ${command}`);
163
+ console.log('Run "openbroker --help" for usage information.');
164
+ process.exit(1);
165
+ }
166
+
167
+ runScript(cmd.script, commandArgs);
168
+ }
169
+
170
+ main();
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+
3
+ // This wrapper uses tsx to run the TypeScript CLI
4
+ import { spawn } from 'child_process';
5
+ import { fileURLToPath } from 'url';
6
+ import path from 'path';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const cliPath = path.join(__dirname, 'cli.ts');
11
+
12
+ // Run the TypeScript CLI with tsx
13
+ const child = spawn(
14
+ process.execPath,
15
+ ['--import', 'tsx', cliPath, ...process.argv.slice(2)],
16
+ {
17
+ stdio: 'inherit',
18
+ cwd: process.cwd(),
19
+ }
20
+ );
21
+
22
+ child.on('exit', (code) => {
23
+ process.exit(code ?? 0);
24
+ });
@@ -0,0 +1,48 @@
1
+ # Open Broker - Environment Variables
2
+ # Copy this file to .env in the project root and fill in your values:
3
+ # cp config/example.env .env
4
+
5
+ # Required: Your wallet private key (64 hex chars with 0x prefix)
6
+ # WARNING: Keep this secret! Never commit .env to git
7
+ HYPERLIQUID_PRIVATE_KEY=0x...
8
+
9
+ # Optional: Network (mainnet or testnet)
10
+ # Default: mainnet
11
+ HYPERLIQUID_NETWORK=mainnet
12
+
13
+ # =============================================================================
14
+ # API Wallet Setup (Optional)
15
+ # =============================================================================
16
+ # To use an API wallet (recommended for automated trading):
17
+ # 1. Generate a new wallet for signing (the "API wallet")
18
+ # 2. Approve it as an agent on your main account via Hyperliquid UI
19
+ # 3. Set HYPERLIQUID_PRIVATE_KEY to the API wallet's key
20
+ # 4. Set HYPERLIQUID_ACCOUNT_ADDRESS to your main account address
21
+ #
22
+ # IMPORTANT: Builder fee approval must be done with the MAIN wallet first!
23
+ # After approval, you can switch to using the API wallet for trading.
24
+ #
25
+ # HYPERLIQUID_ACCOUNT_ADDRESS=0x...
26
+
27
+ # =============================================================================
28
+ # Builder Fee Configuration
29
+ # =============================================================================
30
+ # Open Broker uses builder codes to fund development.
31
+ # Default builder: 0xbb67021fA3e62ab4DA985bb5a55c5c1884381068
32
+ #
33
+ # Custom builder address (optional):
34
+ # BUILDER_ADDRESS=0x...
35
+ #
36
+ # Builder fee in tenths of basis points (10 = 1 bps = 0.01%)
37
+ # Default: 10
38
+ # BUILDER_FEE=10
39
+
40
+ # =============================================================================
41
+ # Trading Configuration
42
+ # =============================================================================
43
+ # Default slippage for market orders in basis points
44
+ # Default: 50 (0.5%)
45
+ # SLIPPAGE_BPS=50
46
+
47
+ # Enable verbose/debug logging
48
+ # VERBOSE=1
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "openbroker",
3
+ "version": "1.0.33",
4
+ "description": "Hyperliquid trading CLI - execute orders, manage positions, and run trading strategies",
5
+ "type": "module",
6
+ "bin": {
7
+ "openbroker": "./bin/openbroker.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "scripts/",
12
+ "config/example.env",
13
+ "README.md",
14
+ "CHANGELOG.md",
15
+ "SKILL.md"
16
+ ],
17
+ "scripts": {
18
+ "onboard": "tsx scripts/setup/onboard.ts",
19
+ "setup": "tsx scripts/setup/onboard.ts",
20
+ "approve-builder": "tsx scripts/setup/approve-builder.ts",
21
+ "account": "tsx scripts/info/account.ts",
22
+ "positions": "tsx scripts/info/positions.ts",
23
+ "funding": "tsx scripts/info/funding.ts",
24
+ "markets": "tsx scripts/info/markets.ts",
25
+ "all-markets": "tsx scripts/info/all-markets.ts",
26
+ "search-markets": "tsx scripts/info/search-markets.ts",
27
+ "spot": "tsx scripts/info/spot.ts",
28
+ "market-order": "tsx scripts/operations/market-order.ts",
29
+ "limit-order": "tsx scripts/operations/limit-order.ts",
30
+ "trigger-order": "tsx scripts/operations/trigger-order.ts",
31
+ "set-tpsl": "tsx scripts/operations/set-tpsl.ts",
32
+ "cancel": "tsx scripts/operations/cancel.ts",
33
+ "twap": "tsx scripts/operations/twap.ts",
34
+ "scale": "tsx scripts/operations/scale.ts",
35
+ "bracket": "tsx scripts/operations/bracket.ts",
36
+ "chase": "tsx scripts/operations/chase.ts",
37
+ "funding-arb": "tsx scripts/strategies/funding-arb.ts",
38
+ "grid": "tsx scripts/strategies/grid.ts",
39
+ "dca": "tsx scripts/strategies/dca.ts",
40
+ "mm-spread": "tsx scripts/strategies/mm-spread.ts",
41
+ "mm-maker": "tsx scripts/strategies/mm-maker.ts",
42
+ "prepublishOnly": "npm run test:cli",
43
+ "test:cli": "node --import tsx bin/cli.ts --help"
44
+ },
45
+ "dependencies": {
46
+ "@nktkas/hyperliquid": "^0.30.3",
47
+ "dotenv": "^17.2.3",
48
+ "tsx": "^4.19.0",
49
+ "viem": "^2.21.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^22.0.0",
53
+ "typescript": "^5.6.0"
54
+ },
55
+ "engines": {
56
+ "node": ">=22.0.0"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/aurracloud/openbroker.git"
61
+ },
62
+ "homepage": "https://github.com/aurracloud/openbroker#readme",
63
+ "bugs": {
64
+ "url": "https://github.com/aurracloud/openbroker/issues"
65
+ },
66
+ "author": "aurracloud",
67
+ "keywords": [
68
+ "hyperliquid",
69
+ "trading",
70
+ "cli",
71
+ "defi",
72
+ "perpetuals",
73
+ "crypto",
74
+ "dex",
75
+ "agent-skills",
76
+ "ai-agents"
77
+ ],
78
+ "license": "MIT"
79
+ }