public-com-cli 0.1.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.
Files changed (102) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +273 -0
  3. package/dist/api/accounts.d.ts +12 -0
  4. package/dist/api/accounts.js +5 -0
  5. package/dist/api/accounts.js.map +1 -0
  6. package/dist/api/history.d.ts +31 -0
  7. package/dist/api/history.js +29 -0
  8. package/dist/api/history.js.map +1 -0
  9. package/dist/api/index.d.ts +9 -0
  10. package/dist/api/index.js +9 -0
  11. package/dist/api/index.js.map +1 -0
  12. package/dist/api/instruments.d.ts +22 -0
  13. package/dist/api/instruments.js +46 -0
  14. package/dist/api/instruments.js.map +1 -0
  15. package/dist/api/market-data.d.ts +48 -0
  16. package/dist/api/market-data.js +20 -0
  17. package/dist/api/market-data.js.map +1 -0
  18. package/dist/api/option-details.d.ts +17 -0
  19. package/dist/api/option-details.js +9 -0
  20. package/dist/api/option-details.js.map +1 -0
  21. package/dist/api/orders.d.ts +125 -0
  22. package/dist/api/orders.js +43 -0
  23. package/dist/api/orders.js.map +1 -0
  24. package/dist/api/portfolio.d.ts +81 -0
  25. package/dist/api/portfolio.js +19 -0
  26. package/dist/api/portfolio.js.map +1 -0
  27. package/dist/api/types.d.ts +12 -0
  28. package/dist/api/types.js +2 -0
  29. package/dist/api/types.js.map +1 -0
  30. package/dist/authentication/keychain.d.ts +5 -0
  31. package/dist/authentication/keychain.js +17 -0
  32. package/dist/authentication/keychain.js.map +1 -0
  33. package/dist/authentication/token.d.ts +9 -0
  34. package/dist/authentication/token.js +35 -0
  35. package/dist/authentication/token.js.map +1 -0
  36. package/dist/commands/accounts.d.ts +3 -0
  37. package/dist/commands/accounts.js +42 -0
  38. package/dist/commands/accounts.js.map +1 -0
  39. package/dist/commands/authenticate.d.ts +3 -0
  40. package/dist/commands/authenticate.js +103 -0
  41. package/dist/commands/authenticate.js.map +1 -0
  42. package/dist/commands/completion.d.ts +3 -0
  43. package/dist/commands/completion.js +234 -0
  44. package/dist/commands/completion.js.map +1 -0
  45. package/dist/commands/config.d.ts +3 -0
  46. package/dist/commands/config.js +67 -0
  47. package/dist/commands/config.js.map +1 -0
  48. package/dist/commands/history.d.ts +3 -0
  49. package/dist/commands/history.js +91 -0
  50. package/dist/commands/history.js.map +1 -0
  51. package/dist/commands/instrument.d.ts +3 -0
  52. package/dist/commands/instrument.js +85 -0
  53. package/dist/commands/instrument.js.map +1 -0
  54. package/dist/commands/instruments.d.ts +3 -0
  55. package/dist/commands/instruments.js +118 -0
  56. package/dist/commands/instruments.js.map +1 -0
  57. package/dist/commands/option-greeks.d.ts +3 -0
  58. package/dist/commands/option-greeks.js +66 -0
  59. package/dist/commands/option-greeks.js.map +1 -0
  60. package/dist/commands/options-chain.d.ts +3 -0
  61. package/dist/commands/options-chain.js +110 -0
  62. package/dist/commands/options-chain.js.map +1 -0
  63. package/dist/commands/options-expirations.d.ts +3 -0
  64. package/dist/commands/options-expirations.js +54 -0
  65. package/dist/commands/options-expirations.js.map +1 -0
  66. package/dist/commands/order-cancel.d.ts +3 -0
  67. package/dist/commands/order-cancel.js +37 -0
  68. package/dist/commands/order-cancel.js.map +1 -0
  69. package/dist/commands/order-place.d.ts +3 -0
  70. package/dist/commands/order-place.js +104 -0
  71. package/dist/commands/order-place.js.map +1 -0
  72. package/dist/commands/order-preflight.d.ts +3 -0
  73. package/dist/commands/order-preflight.js +138 -0
  74. package/dist/commands/order-preflight.js.map +1 -0
  75. package/dist/commands/order.d.ts +3 -0
  76. package/dist/commands/order.js +108 -0
  77. package/dist/commands/order.js.map +1 -0
  78. package/dist/commands/portfolio.d.ts +3 -0
  79. package/dist/commands/portfolio.js +107 -0
  80. package/dist/commands/portfolio.js.map +1 -0
  81. package/dist/commands/quotes.d.ts +3 -0
  82. package/dist/commands/quotes.js +86 -0
  83. package/dist/commands/quotes.js.map +1 -0
  84. package/dist/helpers/api.d.ts +3 -0
  85. package/dist/helpers/api.js +5 -0
  86. package/dist/helpers/api.js.map +1 -0
  87. package/dist/helpers/config.d.ts +5 -0
  88. package/dist/helpers/config.js +40 -0
  89. package/dist/helpers/config.js.map +1 -0
  90. package/dist/helpers/fetch.d.ts +24 -0
  91. package/dist/helpers/fetch.js +202 -0
  92. package/dist/helpers/fetch.js.map +1 -0
  93. package/dist/helpers/output.d.ts +5 -0
  94. package/dist/helpers/output.js +13 -0
  95. package/dist/helpers/output.js.map +1 -0
  96. package/dist/helpers/validation.d.ts +2 -0
  97. package/dist/helpers/validation.js +14 -0
  98. package/dist/helpers/validation.js.map +1 -0
  99. package/dist/index.d.ts +3 -0
  100. package/dist/index.js +49 -0
  101. package/dist/index.js.map +1 -0
  102. package/package.json +78 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2024
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,273 @@
1
+ # Public.com CLI
2
+
3
+ A command-line interface for interacting with the Public.com API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g public-com-cli
9
+ ```
10
+
11
+ After installation, the CLI is available as both `public-cli` and `public-com-cli`:
12
+
13
+ ```bash
14
+ public-cli --help
15
+ # or
16
+ public-com-cli --help
17
+ ```
18
+
19
+ ### Install from Source
20
+
21
+ ```bash
22
+ git clone https://github.com/inlineblock/public-com-cli.git
23
+ cd public-com-cli
24
+ npm install
25
+ npm run build
26
+ npm link
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```bash
32
+ # Authenticate with your API key
33
+ public-cli auth login -k <your-api-key>
34
+
35
+ # List your accounts
36
+ public-cli accounts
37
+
38
+ # View portfolio
39
+ public-cli portfolio <accountId>
40
+
41
+ # Get a quote
42
+ public-cli quotes <accountId> AAPL TSLA
43
+ ```
44
+
45
+ ## Commands
46
+
47
+ ### Authentication
48
+
49
+ ```bash
50
+ # Store your API key (validates against the API)
51
+ public-cli auth login -k <your-api-key>
52
+
53
+ # Check authentication status and view account info
54
+ public-cli auth status
55
+
56
+ # Remove stored credentials
57
+ public-cli auth logout
58
+ ```
59
+
60
+ ### Configuration
61
+
62
+ ```bash
63
+ # Set custom API endpoint
64
+ public-cli config set-endpoint https://custom-api.example.com/
65
+
66
+ # View current endpoint
67
+ public-cli config get-endpoint
68
+
69
+ # Reset to default endpoint
70
+ public-cli config reset-endpoint
71
+ ```
72
+
73
+ ### Accounts
74
+
75
+ ```bash
76
+ # List all trading accounts
77
+ public-cli accounts
78
+ ```
79
+
80
+ ### Portfolio
81
+
82
+ ```bash
83
+ # View portfolio (positions, orders, buying power)
84
+ public-cli portfolio <accountId>
85
+ ```
86
+
87
+ ### Transaction History
88
+
89
+ ```bash
90
+ # View transaction history
91
+ public-cli history <accountId>
92
+
93
+ # With date range
94
+ public-cli history <accountId> --start 2025-01-01T00:00:00Z --end 2025-01-31T23:59:59Z
95
+
96
+ # Limit results
97
+ public-cli history <accountId> --limit 10
98
+
99
+ # Pagination
100
+ public-cli history <accountId> --next-token <token>
101
+ ```
102
+
103
+ ### Instruments
104
+
105
+ ```bash
106
+ # List all available instruments
107
+ public-cli instruments
108
+
109
+ # Filter by type
110
+ public-cli instruments -t EQUITY,ETF
111
+
112
+ # Filter by trading status
113
+ public-cli instruments --trading BUY_AND_SELL
114
+
115
+ # Get details for a specific instrument
116
+ public-cli instrument AAPL
117
+ public-cli instrument BTC -t CRYPTO
118
+ ```
119
+
120
+ ### Market Data
121
+
122
+ ```bash
123
+ # Get quotes for one or more symbols
124
+ public-cli quotes <accountId> AAPL TSLA GOOGL
125
+ public-cli quotes <accountId> BTC ETH -t CRYPTO
126
+
127
+ # Get option expiration dates
128
+ public-cli options-expirations <accountId> AAPL
129
+ public-cli options-expirations <accountId> SPX -t UNDERLYING_SECURITY_FOR_INDEX_OPTION
130
+
131
+ # Get option chain for an expiration date
132
+ public-cli options-chain <accountId> AAPL 2025-02-21
133
+
134
+ # Get option Greeks
135
+ public-cli option-greeks <accountId> AAPL250221C00185000
136
+ ```
137
+
138
+ ### Order Management
139
+
140
+ ```bash
141
+ # Preview order costs (preflight)
142
+ public-cli order-preflight <accountId> AAPL -s BUY -T MARKET -q 10
143
+ public-cli order-preflight <accountId> AAPL -s BUY -T LIMIT -q 10 -l 180.00
144
+
145
+ # Place an order
146
+ public-cli order-place <accountId> AAPL -s BUY -T MARKET -q 10
147
+ public-cli order-place <accountId> AAPL -s BUY -T LIMIT -q 10 -l 180.00 --tif DAY
148
+
149
+ # Get order details
150
+ public-cli order <accountId> <orderId>
151
+
152
+ # Cancel an order
153
+ public-cli order-cancel <accountId> <orderId>
154
+ ```
155
+
156
+ #### Order Options
157
+
158
+ | Option | Description |
159
+ | ------------------ | -------------------------------------------------------------- |
160
+ | `-s, --side` | Order side: `BUY` or `SELL` (required) |
161
+ | `-T, --order-type` | Order type: `MARKET`, `LIMIT`, `STOP`, `STOP_LIMIT` (required) |
162
+ | `-q, --quantity` | Number of shares/contracts |
163
+ | `-a, --amount` | Dollar amount (alternative to quantity) |
164
+ | `-l, --limit` | Limit price (required for LIMIT/STOP_LIMIT) |
165
+ | `--stop` | Stop price (required for STOP/STOP_LIMIT) |
166
+ | `-t, --type` | Security type (default: EQUITY) |
167
+ | `--tif` | Time in force: `DAY` or `GTD` (default: DAY) |
168
+ | `--session` | Market session: `CORE` or `EXTENDED` (default: CORE) |
169
+ | `--open-close` | For options: `OPEN` or `CLOSE` |
170
+
171
+ ## Global Options
172
+
173
+ | Option | Description |
174
+ | --------------- | ------------------------------------------ |
175
+ | `--no-retry` | Disable automatic retries on server errors |
176
+ | `-V, --version` | Output version number |
177
+ | `-h, --help` | Display help |
178
+
179
+ ## Error Handling
180
+
181
+ The CLI includes automatic retry logic for server errors:
182
+
183
+ - **5XX errors**: Exponential backoff retry (up to 3 attempts over ~30 seconds)
184
+ - **429 (Rate Limited)**: Respects `Retry-After` header
185
+ - **401 (Unauthorized)**: Automatically refreshes access token and retries
186
+
187
+ Use `--no-retry` to disable automatic retries.
188
+
189
+ ## Shell Completion
190
+
191
+ Enable tab completion for commands and options:
192
+
193
+ ### Bash
194
+
195
+ ```bash
196
+ # Add to ~/.bashrc
197
+ public-cli completion bash >> ~/.bashrc
198
+ source ~/.bashrc
199
+ ```
200
+
201
+ ### Zsh
202
+
203
+ ```bash
204
+ # Create completions directory and add completion
205
+ mkdir -p ~/.zsh/completions
206
+ public-cli completion zsh > ~/.zsh/completions/_public-cli
207
+
208
+ # Add to ~/.zshrc (if not already there)
209
+ echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
210
+ echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
211
+ source ~/.zshrc
212
+ ```
213
+
214
+ ### Fish
215
+
216
+ ```bash
217
+ public-cli completion fish > ~/.config/fish/completions/public-cli.fish
218
+ ```
219
+
220
+ ## Development
221
+
222
+ ### Prerequisites
223
+
224
+ - Node.js 18.0.0 or higher
225
+ - npm
226
+
227
+ ### Setup
228
+
229
+ ```bash
230
+ npm install
231
+ ```
232
+
233
+ ### Commands
234
+
235
+ | Command | Description |
236
+ | ------------------------------ | -------------------------------------------- |
237
+ | `npm run build` | Compile TypeScript to JavaScript |
238
+ | `npm run build:binary` | Build standalone binaries for all platforms |
239
+ | `npm run build:binary:current` | Build standalone binary for current platform |
240
+ | `npm run dev` | Run the CLI in development mode |
241
+ | `npm run format` | Format code with Prettier |
242
+ | `npm run format:check` | Check code formatting |
243
+ | `npm run typecheck` | Run TypeScript type checking |
244
+
245
+ ### Building Standalone Binaries
246
+
247
+ Create a single executable that includes Node.js runtime:
248
+
249
+ ```bash
250
+ # Build for current platform only
251
+ npm run build:binary:current
252
+ ./dist/public-com-cli --help
253
+
254
+ # Build for all platforms (macOS, Linux, Windows)
255
+ npm run build:binary
256
+ ls dist/bin/
257
+ ```
258
+
259
+ The binaries are output to:
260
+
261
+ - `dist/public-com-cli` (current platform)
262
+ - `dist/bin/` (all platforms: macOS ARM64/x64, Linux x64, Windows x64)
263
+
264
+ ## Security
265
+
266
+ - API keys are stored in your system's secure keychain, not in plain text files
267
+ - Access tokens are cached in the keychain with expiration tracking
268
+ - The CLI uses [keytar](https://github.com/atom/keytar) for secure credential storage
269
+ - Never share your API key or commit it to version control
270
+
271
+ ## License
272
+
273
+ MIT License - see [LICENSE.md](LICENSE.md) for details.
@@ -0,0 +1,12 @@
1
+ export interface Account {
2
+ accountId: string;
3
+ accountType: string;
4
+ optionsLevel: string;
5
+ brokerageAccountType: string;
6
+ tradePermissions: string;
7
+ }
8
+ export interface AccountsResponse {
9
+ accounts: Account[];
10
+ }
11
+ export declare function getAccounts(): Promise<AccountsResponse>;
12
+ //# sourceMappingURL=accounts.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { authenticatedFetch } from '../helpers/fetch.js';
2
+ export async function getAccounts() {
3
+ return authenticatedFetch('userapigateway/trading/account');
4
+ }
5
+ //# sourceMappingURL=accounts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.js","sourceRoot":"","sources":["../../src/api/accounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAczD,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,OAAO,kBAAkB,CAAmB,gCAAgC,CAAC,CAAC;AAChF,CAAC"}
@@ -0,0 +1,31 @@
1
+ export interface Transaction {
2
+ timestamp: string;
3
+ id: string;
4
+ type: string;
5
+ subType: string;
6
+ accountNumber: string;
7
+ symbol?: string;
8
+ securityType?: string;
9
+ side?: string;
10
+ description: string;
11
+ netAmount: string;
12
+ principalAmount?: string;
13
+ quantity?: string;
14
+ direction: string;
15
+ fees?: string;
16
+ }
17
+ export interface HistoryResponse {
18
+ transactions: Transaction[];
19
+ nextToken?: string;
20
+ start: string;
21
+ end: string;
22
+ pageSize: number;
23
+ }
24
+ export interface HistoryOptions {
25
+ start?: string;
26
+ end?: string;
27
+ pageSize?: number;
28
+ nextToken?: string;
29
+ }
30
+ export declare function getHistory(accountId: string, options?: HistoryOptions): Promise<HistoryResponse>;
31
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1,29 @@
1
+ import { authenticatedFetch, ApiError } from '../helpers/fetch.js';
2
+ import { NotFoundError } from './portfolio.js';
3
+ export async function getHistory(accountId, options = {}) {
4
+ const params = new URLSearchParams();
5
+ if (options.start) {
6
+ params.set('start', options.start);
7
+ }
8
+ if (options.end) {
9
+ params.set('end', options.end);
10
+ }
11
+ if (options.pageSize) {
12
+ params.set('pageSize', options.pageSize.toString());
13
+ }
14
+ if (options.nextToken) {
15
+ params.set('nextToken', options.nextToken);
16
+ }
17
+ const queryString = params.toString();
18
+ const path = `userapigateway/trading/${encodeURIComponent(accountId)}/history${queryString ? `?${queryString}` : ''}`;
19
+ try {
20
+ return await authenticatedFetch(path);
21
+ }
22
+ catch (err) {
23
+ if (err instanceof ApiError && err.statusCode === 404) {
24
+ throw new NotFoundError(`Account '${accountId}' not found`);
25
+ }
26
+ thro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I,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YACtD,MAAM,IAAI,aAAa,CAAC,YAAY,SAAS,aAAa,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ export * from './types.js';
2
+ export * from './accounts.js';
3
+ export * from './portfolio.js';
4
+ export * from './history.js';
5
+ export * from './instruments.js';
6
+ export * from './market-data.js';
7
+ export * from './orders.js';
8
+ export * from './option-details.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ export * from './types.js';
2
+ export * from './accounts.js';
3
+ export * from './portfolio.js';
4
+ export * from './history.js';
5
+ export * from './instruments.js';
6
+ export * from './market-data.js';
7
+ export * from './orders.js';
8
+ export * from './option-details.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { SecurityType, TradingStatus, InstrumentInfo } from './types.js';
2
+ export interface InstrumentEntry {
3
+ instrument: InstrumentInfo;
4
+ trading: TradingStatus;
5
+ fractionalTrading: TradingStatus;
6
+ optionTrading: TradingStatus;
7
+ optionSpreadTrading: TradingStatus;
8
+ instrumentDetails: unknown;
9
+ }
10
+ export interface InstrumentsResponse {
11
+ instruments: InstrumentEntry[];
12
+ }
13
+ export interface InstrumentsOptions {
14
+ typeFilter?: SecurityType[];
15
+ tradingFilter?: TradingStatus[];
16
+ fractionalTradingFilter?: TradingStatus[];
17
+ optionTradingFilter?: TradingStatus[];
18
+ optionSpreadTradingFilter?: TradingStatus[];
19
+ }
20
+ export declare function getInstruments(options?: InstrumentsOptions): Promise<InstrumentsResponse>;
21
+ export declare function getInstrument(symbol: string, type: SecurityType): Promise<InstrumentEntry>;
22
+ //# sourceMappingURL=instruments.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { authenticatedFetch, ApiError } from '../helpers/fetch.js';
2
+ import { NotFoundError } from './portfolio.js';
3
+ export async function getInstruments(options = {}) {
4
+ const params = new URLSearchParams();
5
+ if (options.typeFilter?.length) {
6
+ for (const type of options.typeFilter) {
7
+ params.append('typeFilter', type);
8
+ }
9
+ }
10
+ if (options.tradingFilter?.length) {
11
+ for (const status of options.tradingFilter) {
12
+ params.append('tradingFilter', status);
13
+ }
14
+ }
15
+ if (options.fractionalTradingFilter?.length) {
16
+ for (const status of options.fractionalTradingFilter) {
17
+ params.append('fractionalTradingFilter', status);
18
+ }
19
+ }
20
+ if (options.optionTradingFilter?.length) {
21
+ for (const status of options.optionTradingFilter) {
22
+ params.append('optionTradingFilter', status);
23
+ }
24
+ }
25
+ if (options.optionSpreadTradingFilter?.length) {
26
+ for (const status of options.optionSpreadTradingFilter) {
27
+ params.append('optionSpreadTradingFilter', status);
28
+ }
29
+ }
30
+ const queryString = params.toString();
31
+ const path = `userapigateway/trading/instruments${queryString ? `?${queryString}` : ''}`;
32
+ return authenticatedFetch(path);
33
+ }
34
+ export async function getInstrument(symbol, type) {
35
+ const path = `userapigateway/trading/instruments/${encodeURIComponent(symbol)}/${encodeURIComponent(type)}`;
36
+ try {
37
+ return await authenticatedFetch(path);
38
+ }
39
+ catch (err) {
40
+ if (err instanceof ApiError && err.statusCode === 404) {
41
+ throw new NotFoundError(`Instrument '${symbol}' (${type}) not found`);
42
+ }
43
+ throw err;
44
+ }
45
+ }
46
+ //# sourceMappingURL=instruments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instruments.js","sourceRoot":"","sources":["../../src/api/instruments.ts"],"names":[],"mappings":"AAAA,O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MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,qCAAqC,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAEzF,OAAO,kBAAkB,CAAsB,IAAI,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,IAAkB;IAElB,MAAM,IAAI,GAAG,sCAAsC,kBAAkB,CAAC,MAAM,CAAC,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;IAE5G,IAAI,CAAC;QACH,OAAO,MAAM,kBAAkB,CAAkB,IAAI,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,QAAQ,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;YACtD,MAAM,IAAI,aAAa,CAAC,eAAe,MAAM,MAAM,IAAI,aAAa,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ import { InstrumentInfo } from './types.js';
2
+ export type QuoteSecurityType = 'EQUITY' | 'OPTION' | 'CRYPTO' | 'INDEX';
3
+ export interface QuoteInstrument {
4
+ symbol: string;
5
+ type: QuoteSecurityType;
6
+ }
7
+ export interface Quote {
8
+ instrument: InstrumentInfo;
9
+ outcome: 'SUCCESS' | 'FAILURE';
10
+ last?: string;
11
+ lastTimestamp?: string;
12
+ bid?: string;
13
+ bidSize?: number;
14
+ ask?: string;
15
+ askSize?: number;
16
+ volume?: number;
17
+ openInterest?: number;
18
+ }
19
+ export interface QuotesResponse {
20
+ quotes: Quote[];
21
+ }
22
+ export declare function getQuotes(accountId: string, instruments: QuoteInstrument[]): Promise<QuotesResponse>;
23
+ export type OptionUnderlyingType = 'EQUITY' | 'UNDERLYING_SECURITY_FOR_INDEX_OPTION';
24
+ export interface OptionUnderlyingInstrument {
25
+ symbol: string;
26
+ type: OptionUnderlyingType;
27
+ }
28
+ export interface OptionExpirationsResponse {
29
+ baseSymbol: string;
30
+ expirations: string[];
31
+ }
32
+ export declare function getOptionExpirations(accountId: string, instrument: OptionUnderlyingInstrument): Promise<OptionExpirationsResponse>;
33
+ export interface OptionQuote {
34
+ instrument: InstrumentInfo;
35
+ outcome: 'SUCCESS' | 'FAILURE';
36
+ last?: string;
37
+ bid?: string;
38
+ ask?: string;
39
+ volume?: number;
40
+ openInterest?: number;
41
+ }
42
+ export interface OptionChainResponse {
43
+ baseSymbol: string;
44
+ calls: OptionQuote[];
45
+ puts: OptionQuote[];
46
+ }
47
+ export declare function getOptionChain(accountId: string, instrument: OptionUnderlyingInstrument, expirationDate: string): Promise<OptionChainResponse>;
48
+ //# sourceMappingURL=market-data.d.ts.map
@@ -0,0 +1,20 @@
1
+ import { authenticatedFetch } from '../helpers/fetch.js';
2
+ export async function getQuotes(accountId, instruments) {
3
+ return authenticatedFetch(`userapigateway/marketdata/${encodeURIComponent(accountId)}/quotes`, {
4
+ method: 'POST',
5
+ body: { instruments },
6
+ });
7
+ }
8
+ export async function getOptionExpirations(accountId, instrument) {
9
+ return authenticatedFetch(`userapigateway/marketdata/${encodeURIComponent(accountId)}/option-expirations`, {
10
+ method: 'POST',
11
+ body: { instrument },
12
+ });
13
+ }
14
+ export async function getOptionChain(accountId, instrument, expirationDate) {
15
+ return authenticatedFetch(`userapigateway/marketdata/${encodeURIComponent(accountId)}/option-chain`, {
16
+ method: 'POST',
17
+ body: { instrument, expirationDate },
18
+ });
19
+ }
20
+ //# sourceMappingURL=market-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"market-data.js","sourceRoot":"","sources":["../../src/api/market-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AA2BzD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,SAAiB,EACjB,WAA8B;IAE9B,OAAO,kBAAkB,CACvB,6BAA6B,kBAAkB,CAAC,SAAS,CAAC,SAAS,EACnE;QACE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,EAAE,WAAW,EAAE;KACtB,CACF,CAAC;AACJ,CAAC;AAgBD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,SAAiB,EACjB,UAAsC;IAEtC,OAAO,kBAAkB,CACvB,6BAA6B,kBAAkB,CAAC,SAAS,CAAC,qBAAqB,EAC/E;QACE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,EAAE,UAAU,EAAE;KACrB,CACF,CAAC;AACJ,CAAC;AAkBD,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,SAAiB,EACjB,UAAsC,EACtC,cAAsB;IAEtB,OAAO,kBAAkB,CACvB,6BAA6B,kBAAkB,CAAC,SAAS,CAAC,eAAe,EACzE;QACE,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE;KACrC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ export interface Greeks {
2
+ delta?: string;
3
+ gamma?: string;
4
+ theta?: string;
5
+ vega?: string;
6
+ rho?: string;
7
+ impliedVolatility?: string;
8
+ }
9
+ export interface OptionGreek {
10
+ symbol: string;
11
+ greeks: Greeks;
12
+ }
13
+ export interface OptionGreeksResponse {
14
+ greeks: OptionGreek[];
15
+ }
16
+ export declare function getOptionGreeks(accountId: string, osiSymbols: string[]): Promise<OptionGreeksResponse>;
17
+ //# sourceMappingURL=option-details.d.ts.map
@@ -0,0 +1,9 @@
1
+ import { authenticatedFetch } from '../helpers/fetch.js';
2
+ export async function getOptionGreeks(accountId, osiSymbols) {
3
+ const params = new URLSearchParams();
4
+ for (const symbol of osiSymbols) {
5
+ params.append('osiSymbols', symbol);
6
+ }
7
+ return authenticatedFetch(`userapigateway/option-details/${encodeURIComponent(accountId)}/greeks?${params.toString()}`);
8
+ }
9
+ //# sourceMappingURL=option-details.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option-details.js","sourceRoot":"","sources":["../../src/api/option-details.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAoBzD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,UAAoB;IAEpB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,kBAAkB,CACvB,iCAAiC,kBAAkB,CAAC,SAAS,CAAC,WAAW,MAAM,CAAC,QAAQ,EAAE,EAAE,CAC7F,CAAC;AACJ,CAAC"}