openbook-cli 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 OpenBook CLI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # OpenBook CLI
2
+
3
+ A comprehensive command-line interface for interacting with OpenBook and Serum DEX markets on Solana.
4
+
5
+ ## 🚀 Features
6
+
7
+ - **Auto-detection**: Automatically detects OpenBook vs Serum markets
8
+ - **Real-time data**: Fetches live order book data from the blockchain
9
+ - **Market management**: Add and list known markets
10
+ - **Universal support**: Works with any market address (known or unknown)
11
+ - **Separate storage**: Maintains separate files for OpenBook and Serum markets
12
+
13
+ ## 📦 Installation
14
+
15
+ ```bash
16
+ npm install -g openbook-cli
17
+ ```
18
+
19
+ Or install locally:
20
+
21
+ ```bash
22
+ npm install openbook-cli
23
+ ```
24
+
25
+ ## 🎯 Quick Start
26
+
27
+ ```bash
28
+ # Fetch market data (auto-detects OpenBook/Serum)
29
+ openbook-cli Gc4tfUHRNnpVwvASfQD3q26G8GNmLYuz4KzB4QNkNuiQ
30
+
31
+ # Add market to known markets
32
+ openbook-cli 8nqjw5UVN65GyfdqiXnfJNbDVBgbk8RpFFd7uACXenbx --add
33
+
34
+ # List OpenBook markets
35
+ openbook-cli --list
36
+
37
+ # List Serum markets
38
+ openbook-cli --list --serum
39
+ ```
40
+
41
+ ## 📋 Commands
42
+
43
+ ### Fetch Market Data
44
+ ```bash
45
+ openbook-cli <market_address>
46
+ ```
47
+ Fetches real-time market information and order book data.
48
+
49
+ ### Add Market to Known Markets
50
+ ```bash
51
+ openbook-cli <market_address> --add
52
+ ```
53
+ Adds a market to the persistent storage for future quick access.
54
+
55
+ ### List Known Markets
56
+ ```bash
57
+ # List OpenBook markets
58
+ openbook-cli --list
59
+
60
+ # List Serum markets
61
+ openbook-cli --list --serum
62
+ ```
63
+
64
+ ## 🔍 Auto-Detection
65
+
66
+ The CLI automatically detects whether a market belongs to OpenBook or Serum by checking the market account owner:
67
+
68
+ - **OpenBook**: `srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX`
69
+ - **Serum**: `9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin`
70
+
71
+ ## 📊 Data Storage
72
+
73
+ The CLI maintains separate files for different market types:
74
+
75
+ - `known_openbook_markets.json` - OpenBook markets and token symbols
76
+ - `known_serum_markets.json` - Serum markets and token symbols
77
+
78
+ ## 🎨 Token Symbol Resolution
79
+
80
+ ### Known Tokens
81
+ Automatically recognizes common tokens:
82
+ - **SOL**: `So11111111111111111111111111111111111111112`
83
+ - **USDC**: `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`
84
+ - **ATLAS**: `HjFijcGWKgfDwGpFX2rqFwEU9jtEgFuRQAJe1ERXFsA3`
85
+
86
+ ### Unknown Tokens
87
+ For unknown tokens, the system:
88
+ 1. Attempts to fetch Metaplex metadata
89
+ 2. Falls back to first 8 characters of the mint address
90
+ 3. Displays as: `First8Chars` (e.g., `BV1soTdX`)
91
+
92
+ ## 📈 Order Book Data
93
+
94
+ The CLI fetches live order book data directly from the blockchain:
95
+ - **Bids**: Buy orders sorted by price (highest first)
96
+ - **Asks**: Sell orders sorted by price (lowest first)
97
+ - **Depth**: Configurable depth (default: 15 levels)
98
+
99
+ ### Market Statistics
100
+ - **Total Bids/Asks**: Number of orders on each side
101
+ - **Best Bid/Ask**: Highest bid and lowest ask prices
102
+ - **Spread**: Difference between best ask and best bid
103
+ - **Spread %**: Spread as a percentage of best bid
104
+
105
+ ## 🛠️ Development
106
+
107
+ ### Prerequisites
108
+ - Node.js >= 16.0.0
109
+ - TypeScript
110
+
111
+ ### Setup
112
+ ```bash
113
+ git clone https://github.com/yourusername/openbook-cli.git
114
+ cd openbook-cli
115
+ npm install
116
+ ```
117
+
118
+ ### Build
119
+ ```bash
120
+ npm run build
121
+ ```
122
+
123
+ ### Development
124
+ ```bash
125
+ npm run dev
126
+ ```
127
+
128
+ ## 📝 Examples
129
+
130
+ ### Basic Market Fetch
131
+ ```bash
132
+ # Fetch any market (auto-detects type)
133
+ openbook-cli Gc4tfUHRNnpVwvASfQD3q26G8GNmLYuz4KzB4QNkNuiQ
134
+ ```
135
+
136
+ ### Add New Markets
137
+ ```bash
138
+ # Add OpenBook market
139
+ openbook-cli EgnTFXgaQ8CzVSQJyTD2sT3Yx8esLgKf5e6YGvQfm2U7 --add
140
+
141
+ # Add Serum market
142
+ openbook-cli 8nqjw5UVN65GyfdqiXnfJNbDVBgbk8RpFFd7uACXenbx --add
143
+ ```
144
+
145
+ ### List Markets
146
+ ```bash
147
+ # List OpenBook markets
148
+ openbook-cli --list
149
+
150
+ # List Serum markets
151
+ openbook-cli --list --serum
152
+ ```
153
+
154
+ ## 🔧 Configuration
155
+
156
+ The CLI uses the following configuration:
157
+
158
+ - **RPC Endpoint**: Default Solana RPC
159
+ - **Market Files**: Stored in the current directory
160
+ - **Token Symbols**: Cached for faster access
161
+
162
+ ## 🚨 Error Handling
163
+
164
+ ### Common Issues
165
+ 1. **Market not found**: Invalid market address
166
+ 2. **Network issues**: Connection problems to Solana RPC
167
+ 3. **Token metadata unavailable**: Missing Metaplex data
168
+ 4. **Program ownership mismatch**: Market belongs to different program
169
+
170
+ ### Error Messages
171
+ - `❌ Market account not found` - Invalid market address
172
+ - `❌ Market verification failed` - Program ownership issue
173
+ - `No Metaplex metadata found` - Token symbol resolution failed
174
+
175
+ ## 📊 Performance
176
+
177
+ ### Response Times
178
+ - **Known markets**: ~2-3 seconds
179
+ - **Unknown markets**: ~3-5 seconds (includes metadata fetch)
180
+ - **Order book data**: ~1-2 seconds
181
+
182
+ ### Network Usage
183
+ - Each market fetch requires multiple RPC calls
184
+ - Order book data is fetched in real-time
185
+ - Token metadata is cached after first fetch
186
+
187
+ ## 🔒 Security
188
+
189
+ ### Data Sources
190
+ - All data comes directly from Solana blockchain
191
+ - No third-party API dependencies
192
+ - Real-time verification of market ownership
193
+
194
+ ### Market Validation
195
+ - Verifies market account exists
196
+ - Checks program ownership
197
+ - Validates token mint addresses
198
+
199
+ ## 📄 License
200
+
201
+ MIT License - see [LICENSE](LICENSE) file for details.
202
+
203
+ ## 🤝 Contributing
204
+
205
+ 1. Fork the repository
206
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
207
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
208
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
209
+ 5. Open a Pull Request
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const index_1 = require("./index");
5
+ // Run the CLI
6
+ (0, index_1.main)().catch((error) => {
7
+ console.error('❌ CLI Error:', error);
8
+ process.exit(1);
9
+ });
10
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AAEA,mCAA+B;AAE/B,cAAc;AACd,IAAA,YAAI,GAAE,CAAC,KAAK,CAAC,CAAC,KAAU,EAAE,EAAE;IACxB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Market } from "@project-serum/serum";
2
+ interface OrderBookLevel {
3
+ price: number;
4
+ size: number;
5
+ side: 'bid' | 'ask';
6
+ }
7
+ interface MarketInfo {
8
+ address: string;
9
+ baseMint: string;
10
+ quoteMint: string;
11
+ baseSymbol: string;
12
+ quoteSymbol: string;
13
+ minOrderSize: number;
14
+ priceTick: number;
15
+ eventQueueLength: number;
16
+ requestQueueLength: number;
17
+ bidsLength: number;
18
+ asksLength: number;
19
+ }
20
+ declare function getMarketInfo(marketAddress: string, useSerum?: boolean): Promise<MarketInfo>;
21
+ declare function loadOpenBookMarket(marketAddress: string, useSerum?: boolean): Promise<Market>;
22
+ declare function getRealOrderBook(marketAddress: string, depth?: number, useSerum?: boolean): Promise<{
23
+ bids: OrderBookLevel[];
24
+ asks: OrderBookLevel[];
25
+ }>;
26
+ declare function getOrderBook(marketAddress: string, depth?: number): Promise<{
27
+ bids: OrderBookLevel[];
28
+ asks: OrderBookLevel[];
29
+ }>;
30
+ declare function getMarketStats(marketAddress: string, useSerum?: boolean): Promise<{
31
+ totalBids: number;
32
+ totalAsks: number;
33
+ bestBid: number | null;
34
+ bestAsk: number | null;
35
+ spread: number | null;
36
+ spreadPercentage: number | null;
37
+ }>;
38
+ declare function displayOrderBook(marketAddress: string, depth?: number, useSerum?: boolean): Promise<void>;
39
+ declare function displayMarketInfo(marketAddress: string, useSerum?: boolean): Promise<void>;
40
+ declare function listKnownMarkets(useSerum?: boolean): void;
41
+ declare function main(): Promise<void>;
42
+ export { getMarketInfo, getOrderBook, getMarketStats, displayOrderBook, displayMarketInfo, listKnownMarkets, loadOpenBookMarket, getRealOrderBook };
43
+ export { main };
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAY9C,UAAU,cAAc;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;CACvB;AAED,UAAU,UAAU;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACtB;AA+ED,iBAAe,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAiDlG;AA8BD,iBAAe,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBnG;AAED,iBAAe,gBAAgB,CAAC,aAA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