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.
- package/LICENSE.md +21 -0
- package/README.md +273 -0
- package/dist/api/accounts.d.ts +12 -0
- package/dist/api/accounts.js +5 -0
- package/dist/api/accounts.js.map +1 -0
- package/dist/api/history.d.ts +31 -0
- package/dist/api/history.js +29 -0
- package/dist/api/history.js.map +1 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.js +9 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/instruments.d.ts +22 -0
- package/dist/api/instruments.js +46 -0
- package/dist/api/instruments.js.map +1 -0
- package/dist/api/market-data.d.ts +48 -0
- package/dist/api/market-data.js +20 -0
- package/dist/api/market-data.js.map +1 -0
- package/dist/api/option-details.d.ts +17 -0
- package/dist/api/option-details.js +9 -0
- package/dist/api/option-details.js.map +1 -0
- package/dist/api/orders.d.ts +125 -0
- package/dist/api/orders.js +43 -0
- package/dist/api/orders.js.map +1 -0
- package/dist/api/portfolio.d.ts +81 -0
- package/dist/api/portfolio.js +19 -0
- package/dist/api/portfolio.js.map +1 -0
- package/dist/api/types.d.ts +12 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/authentication/keychain.d.ts +5 -0
- package/dist/authentication/keychain.js +17 -0
- package/dist/authentication/keychain.js.map +1 -0
- package/dist/authentication/token.d.ts +9 -0
- package/dist/authentication/token.js +35 -0
- package/dist/authentication/token.js.map +1 -0
- package/dist/commands/accounts.d.ts +3 -0
- package/dist/commands/accounts.js +42 -0
- package/dist/commands/accounts.js.map +1 -0
- package/dist/commands/authenticate.d.ts +3 -0
- package/dist/commands/authenticate.js +103 -0
- package/dist/commands/authenticate.js.map +1 -0
- package/dist/commands/completion.d.ts +3 -0
- package/dist/commands/completion.js +234 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.js +67 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/history.d.ts +3 -0
- package/dist/commands/history.js +91 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/instrument.d.ts +3 -0
- package/dist/commands/instrument.js +85 -0
- package/dist/commands/instrument.js.map +1 -0
- package/dist/commands/instruments.d.ts +3 -0
- package/dist/commands/instruments.js +118 -0
- package/dist/commands/instruments.js.map +1 -0
- package/dist/commands/option-greeks.d.ts +3 -0
- package/dist/commands/option-greeks.js +66 -0
- package/dist/commands/option-greeks.js.map +1 -0
- package/dist/commands/options-chain.d.ts +3 -0
- package/dist/commands/options-chain.js +110 -0
- package/dist/commands/options-chain.js.map +1 -0
- package/dist/commands/options-expirations.d.ts +3 -0
- package/dist/commands/options-expirations.js +54 -0
- package/dist/commands/options-expirations.js.map +1 -0
- package/dist/commands/order-cancel.d.ts +3 -0
- package/dist/commands/order-cancel.js +37 -0
- package/dist/commands/order-cancel.js.map +1 -0
- package/dist/commands/order-place.d.ts +3 -0
- package/dist/commands/order-place.js +104 -0
- package/dist/commands/order-place.js.map +1 -0
- package/dist/commands/order-preflight.d.ts +3 -0
- package/dist/commands/order-preflight.js +138 -0
- package/dist/commands/order-preflight.js.map +1 -0
- package/dist/commands/order.d.ts +3 -0
- package/dist/commands/order.js +108 -0
- package/dist/commands/order.js.map +1 -0
- package/dist/commands/portfolio.d.ts +3 -0
- package/dist/commands/portfolio.js +107 -0
- package/dist/commands/portfolio.js.map +1 -0
- package/dist/commands/quotes.d.ts +3 -0
- package/dist/commands/quotes.js +86 -0
- package/dist/commands/quotes.js.map +1 -0
- package/dist/helpers/api.d.ts +3 -0
- package/dist/helpers/api.js +5 -0
- package/dist/helpers/api.js.map +1 -0
- package/dist/helpers/config.d.ts +5 -0
- package/dist/helpers/config.js +40 -0
- package/dist/helpers/config.js.map +1 -0
- package/dist/helpers/fetch.d.ts +24 -0
- package/dist/helpers/fetch.js +202 -0
- package/dist/helpers/fetch.js.map +1 -0
- package/dist/helpers/output.d.ts +5 -0
- package/dist/helpers/output.js +13 -0
- package/dist/helpers/output.js.map +1 -0
- package/dist/helpers/validation.d.ts +2 -0
- package/dist/helpers/validation.js +14 -0
- package/dist/helpers/validation.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
const BASH_COMPLETION_SCRIPT = `
|
|
3
|
+
###-begin-public-cli-completions-###
|
|
4
|
+
#
|
|
5
|
+
# public-cli bash completion
|
|
6
|
+
#
|
|
7
|
+
# Installation:
|
|
8
|
+
# public-cli completion bash >> ~/.bashrc
|
|
9
|
+
# # or
|
|
10
|
+
# public-cli completion bash > /usr/local/etc/bash_completion.d/public-cli
|
|
11
|
+
#
|
|
12
|
+
|
|
13
|
+
_public_cli_completions() {
|
|
14
|
+
local cur prev commands global_opts
|
|
15
|
+
|
|
16
|
+
COMPREPLY=()
|
|
17
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
18
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
19
|
+
|
|
20
|
+
commands="auth config accounts portfolio history instruments instrument quotes options-expirations options-chain order-preflight order-place order order-cancel option-greeks completion help"
|
|
21
|
+
global_opts="--no-retry --version --help"
|
|
22
|
+
|
|
23
|
+
# Auth subcommands
|
|
24
|
+
auth_commands="login logout status"
|
|
25
|
+
|
|
26
|
+
# Config subcommands
|
|
27
|
+
config_commands="set-endpoint get-endpoint reset-endpoint"
|
|
28
|
+
|
|
29
|
+
case "\${COMP_WORDS[1]}" in
|
|
30
|
+
auth)
|
|
31
|
+
if [[ \${COMP_CWORD} -eq 2 ]]; then
|
|
32
|
+
COMPREPLY=( \$(compgen -W "\${auth_commands}" -- "\${cur}") )
|
|
33
|
+
return 0
|
|
34
|
+
fi
|
|
35
|
+
case "\${COMP_WORDS[2]}" in
|
|
36
|
+
login)
|
|
37
|
+
COMPREPLY=( \$(compgen -W "-k --key" -- "\${cur}") )
|
|
38
|
+
return 0
|
|
39
|
+
;;
|
|
40
|
+
esac
|
|
41
|
+
;;
|
|
42
|
+
config)
|
|
43
|
+
if [[ \${COMP_CWORD} -eq 2 ]]; then
|
|
44
|
+
COMPREPLY=( \$(compgen -W "\${config_commands}" -- "\${cur}") )
|
|
45
|
+
return 0
|
|
46
|
+
fi
|
|
47
|
+
;;
|
|
48
|
+
portfolio|history|quotes|options-expirations|options-chain|order-preflight|order-place|order|order-cancel|option-greeks)
|
|
49
|
+
# These commands need accountId as first arg
|
|
50
|
+
return 0
|
|
51
|
+
;;
|
|
52
|
+
instruments)
|
|
53
|
+
COMPREPLY=( \$(compgen -W "-t --type --trading --fractional --options --spreads" -- "\${cur}") )
|
|
54
|
+
return 0
|
|
55
|
+
;;
|
|
56
|
+
instrument)
|
|
57
|
+
COMPREPLY=( \$(compgen -W "-t --type" -- "\${cur}") )
|
|
58
|
+
return 0
|
|
59
|
+
;;
|
|
60
|
+
completion)
|
|
61
|
+
if [[ \${COMP_CWORD} -eq 2 ]]; then
|
|
62
|
+
COMPREPLY=( \$(compgen -W "bash zsh fish" -- "\${cur}") )
|
|
63
|
+
return 0
|
|
64
|
+
fi
|
|
65
|
+
;;
|
|
66
|
+
help)
|
|
67
|
+
if [[ \${COMP_CWORD} -eq 2 ]]; then
|
|
68
|
+
COMPREPLY=( \$(compgen -W "\${commands}" -- "\${cur}") )
|
|
69
|
+
return 0
|
|
70
|
+
fi
|
|
71
|
+
;;
|
|
72
|
+
esac
|
|
73
|
+
|
|
74
|
+
if [[ \${COMP_CWORD} -eq 1 ]]; then
|
|
75
|
+
COMPREPLY=( \$(compgen -W "\${commands} \${global_opts}" -- "\${cur}") )
|
|
76
|
+
return 0
|
|
77
|
+
fi
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
complete -F _public_cli_completions public-cli
|
|
81
|
+
complete -F _public_cli_completions public-com-cli
|
|
82
|
+
###-end-public-cli-completions-###
|
|
83
|
+
`.trim();
|
|
84
|
+
const ZSH_COMPLETION_SCRIPT = `
|
|
85
|
+
#compdef public-cli public-com-cli
|
|
86
|
+
|
|
87
|
+
###-begin-public-cli-completions-###
|
|
88
|
+
#
|
|
89
|
+
# public-cli zsh completion
|
|
90
|
+
#
|
|
91
|
+
# Installation:
|
|
92
|
+
# public-cli completion zsh > ~/.zsh/completions/_public-cli
|
|
93
|
+
# # Then add to ~/.zshrc: fpath=(~/.zsh/completions $fpath)
|
|
94
|
+
#
|
|
95
|
+
|
|
96
|
+
_public-cli() {
|
|
97
|
+
local -a commands
|
|
98
|
+
commands=(
|
|
99
|
+
'auth:Manage authentication with Public.com API'
|
|
100
|
+
'config:Manage CLI configuration'
|
|
101
|
+
'accounts:List your trading accounts'
|
|
102
|
+
'portfolio:View portfolio for an account'
|
|
103
|
+
'history:View transaction history for an account'
|
|
104
|
+
'instruments:List available trading instruments'
|
|
105
|
+
'instrument:Get details for a specific instrument'
|
|
106
|
+
'quotes:Get quotes for one or more instruments'
|
|
107
|
+
'options-expirations:Get available option expiration dates'
|
|
108
|
+
'options-chain:Get option chain for an instrument'
|
|
109
|
+
'order-preflight:Preview estimated costs for an order'
|
|
110
|
+
'order-place:Place a new order'
|
|
111
|
+
'order:Get order details'
|
|
112
|
+
'order-cancel:Cancel an open order'
|
|
113
|
+
'option-greeks:Get option Greeks'
|
|
114
|
+
'completion:Generate shell completion script'
|
|
115
|
+
'help:Display help for command'
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
_arguments -C \\
|
|
119
|
+
'--no-retry[Disable automatic retries]' \\
|
|
120
|
+
'--version[Output version number]' \\
|
|
121
|
+
'--help[Display help]' \\
|
|
122
|
+
'1: :->command' \\
|
|
123
|
+
'*::arg:->args'
|
|
124
|
+
|
|
125
|
+
case "$state" in
|
|
126
|
+
command)
|
|
127
|
+
_describe -t commands 'command' commands
|
|
128
|
+
;;
|
|
129
|
+
args)
|
|
130
|
+
case "\${words[1]}" in
|
|
131
|
+
auth)
|
|
132
|
+
local -a auth_commands
|
|
133
|
+
auth_commands=(
|
|
134
|
+
'login:Store your API key'
|
|
135
|
+
'logout:Remove stored credentials'
|
|
136
|
+
'status:Check authentication status'
|
|
137
|
+
)
|
|
138
|
+
_describe -t auth_commands 'auth command' auth_commands
|
|
139
|
+
;;
|
|
140
|
+
config)
|
|
141
|
+
local -a config_commands
|
|
142
|
+
config_commands=(
|
|
143
|
+
'set-endpoint:Set the API endpoint URL'
|
|
144
|
+
'get-endpoint:Show the current API endpoint'
|
|
145
|
+
'reset-endpoint:Reset to default endpoint'
|
|
146
|
+
)
|
|
147
|
+
_describe -t config_commands 'config command' config_commands
|
|
148
|
+
;;
|
|
149
|
+
completion)
|
|
150
|
+
_values 'shell' bash zsh fish
|
|
151
|
+
;;
|
|
152
|
+
esac
|
|
153
|
+
;;
|
|
154
|
+
esac
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_public-cli "$@"
|
|
158
|
+
###-end-public-cli-completions-###
|
|
159
|
+
`.trim();
|
|
160
|
+
const FISH_COMPLETION_SCRIPT = `
|
|
161
|
+
###-begin-public-cli-completions-###
|
|
162
|
+
#
|
|
163
|
+
# public-cli fish completion
|
|
164
|
+
#
|
|
165
|
+
# Installation:
|
|
166
|
+
# public-cli completion fish > ~/.config/fish/completions/public-cli.fish
|
|
167
|
+
#
|
|
168
|
+
|
|
169
|
+
# Disable file completion by default
|
|
170
|
+
complete -c public-cli -f
|
|
171
|
+
complete -c public-com-cli -f
|
|
172
|
+
|
|
173
|
+
# Global options
|
|
174
|
+
complete -c public-cli -l no-retry -d 'Disable automatic retries'
|
|
175
|
+
complete -c public-cli -l version -s V -d 'Output version number'
|
|
176
|
+
complete -c public-cli -l help -s h -d 'Display help'
|
|
177
|
+
|
|
178
|
+
# Commands
|
|
179
|
+
complete -c public-cli -n __fish_use_subcommand -a auth -d 'Manage authentication'
|
|
180
|
+
complete -c public-cli -n __fish_use_subcommand -a config -d 'Manage CLI configuration'
|
|
181
|
+
complete -c public-cli -n __fish_use_subcommand -a accounts -d 'List trading accounts'
|
|
182
|
+
complete -c public-cli -n __fish_use_subcommand -a portfolio -d 'View portfolio'
|
|
183
|
+
complete -c public-cli -n __fish_use_subcommand -a history -d 'View transaction history'
|
|
184
|
+
complete -c public-cli -n __fish_use_subcommand -a instruments -d 'List instruments'
|
|
185
|
+
complete -c public-cli -n __fish_use_subcommand -a instrument -d 'Get instrument details'
|
|
186
|
+
complete -c public-cli -n __fish_use_subcommand -a quotes -d 'Get quotes'
|
|
187
|
+
complete -c public-cli -n __fish_use_subcommand -a options-expirations -d 'Get option expirations'
|
|
188
|
+
complete -c public-cli -n __fish_use_subcommand -a options-chain -d 'Get option chain'
|
|
189
|
+
complete -c public-cli -n __fish_use_subcommand -a order-preflight -d 'Preview order costs'
|
|
190
|
+
complete -c public-cli -n __fish_use_subcommand -a order-place -d 'Place an order'
|
|
191
|
+
complete -c public-cli -n __fish_use_subcommand -a order -d 'Get order details'
|
|
192
|
+
complete -c public-cli -n __fish_use_subcommand -a order-cancel -d 'Cancel an order'
|
|
193
|
+
complete -c public-cli -n __fish_use_subcommand -a option-greeks -d 'Get option Greeks'
|
|
194
|
+
complete -c public-cli -n __fish_use_subcommand -a completion -d 'Generate completion script'
|
|
195
|
+
complete -c public-cli -n __fish_use_subcommand -a help -d 'Display help'
|
|
196
|
+
|
|
197
|
+
# Auth subcommands
|
|
198
|
+
complete -c public-cli -n '__fish_seen_subcommand_from auth' -a login -d 'Store API key'
|
|
199
|
+
complete -c public-cli -n '__fish_seen_subcommand_from auth' -a logout -d 'Remove credentials'
|
|
200
|
+
complete -c public-cli -n '__fish_seen_subcommand_from auth' -a status -d 'Check auth status'
|
|
201
|
+
|
|
202
|
+
# Config subcommands
|
|
203
|
+
complete -c public-cli -n '__fish_seen_subcommand_from config' -a set-endpoint -d 'Set API endpoint'
|
|
204
|
+
complete -c public-cli -n '__fish_seen_subcommand_from config' -a get-endpoint -d 'Show endpoint'
|
|
205
|
+
complete -c public-cli -n '__fish_seen_subcommand_from config' -a reset-endpoint -d 'Reset endpoint'
|
|
206
|
+
|
|
207
|
+
# Completion subcommands
|
|
208
|
+
complete -c public-cli -n '__fish_seen_subcommand_from completion' -a 'bash zsh fish' -d 'Shell type'
|
|
209
|
+
###-end-public-cli-completions-###
|
|
210
|
+
`.trim();
|
|
211
|
+
export function createCompletionCommand() {
|
|
212
|
+
const completion = new Command('completion')
|
|
213
|
+
.description('Generate shell completion script')
|
|
214
|
+
.argument('<shell>', 'Shell type (bash, zsh, fish)')
|
|
215
|
+
.action((shell) => {
|
|
216
|
+
switch (shell.toLowerCase()) {
|
|
217
|
+
case 'bash':
|
|
218
|
+
console.log(BASH_COMPLETION_SCRIPT);
|
|
219
|
+
break;
|
|
220
|
+
case 'zsh':
|
|
221
|
+
console.log(ZSH_COMPLETION_SCRIPT);
|
|
222
|
+
break;
|
|
223
|
+
case 'fish':
|
|
224
|
+
console.log(FISH_COMPLETION_SCRIPT);
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
console.error(`Unknown shell: ${shell}`);
|
|
228
|
+
console.error('Supported shells: bash, zsh, fish');
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
return completion;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=completion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../../src/commands/completion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiF9B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2E7B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkD9B,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,UAAU,uBAAuB;IACrC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,YAAY,CAAC;SACzC,WAAW,CAAC,kCAAkC,CAAC;SAC/C,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;SACnD,MAAM,CAAC,CAAC,KAAa,EAAE,EAAE;QACxB,QAAQ,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YAC5B,KAAK,MAAM;gBACT,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;gBACpC,MAAM;YACR,KAAK,KAAK;gBACR,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;gBACnC,MAAM;YACR,KAAK,MAAM;gBACT,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;gBACpC,MAAM;YACR;gBACE,OAAO,CAAC,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC;gBACzC,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;gBACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getEndpoint, setEndpoint, resetEndpoint, getDefaultEndpoint, } from '../helpers/config.js';
|
|
3
|
+
import { success, error, info } from '../helpers/output.js';
|
|
4
|
+
function isValidUrl(urlString) {
|
|
5
|
+
try {
|
|
6
|
+
const url = new URL(urlString);
|
|
7
|
+
return url.protocol === 'https:' || url.protocol === 'http:';
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function createConfigCommand() {
|
|
14
|
+
const config = new Command('config').description('Manage CLI configuration');
|
|
15
|
+
config
|
|
16
|
+
.command('set-endpoint')
|
|
17
|
+
.description('Set the API endpoint URL')
|
|
18
|
+
.argument('<url>', 'The API endpoint URL')
|
|
19
|
+
.action(async (url) => {
|
|
20
|
+
try {
|
|
21
|
+
const trimmedUrl = url.trim();
|
|
22
|
+
if (!isValidUrl(trimmedUrl)) {
|
|
23
|
+
error('Invalid URL. Please provide a valid HTTP or HTTPS URL.');
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
const normalizedUrl = trimmedUrl.endsWith('/')
|
|
27
|
+
? trimmedUrl
|
|
28
|
+
: `${trimmedUrl}/`;
|
|
29
|
+
await setEndpoint(normalizedUrl);
|
|
30
|
+
success(`API endpoint set to: ${normalizedUrl}`);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
error(`Failed to set endpoint: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
config
|
|
38
|
+
.command('get-endpoint')
|
|
39
|
+
.description('Show the current API endpoint URL')
|
|
40
|
+
.action(async () => {
|
|
41
|
+
try {
|
|
42
|
+
const endpoint = await getEndpoint();
|
|
43
|
+
const defaultEndpoint = getDefaultEndpoint();
|
|
44
|
+
const isDefault = endpoint === defaultEndpoint;
|
|
45
|
+
info(`API endpoint: ${endpoint}${isDefault ? ' (default)' : ''}`);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
error(`Failed to get endpoint: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
config
|
|
53
|
+
.command('reset-endpoint')
|
|
54
|
+
.description('Reset the API endpoint to default')
|
|
55
|
+
.action(async () => {
|
|
56
|
+
try {
|
|
57
|
+
await resetEndpoint();
|
|
58
|
+
success(`API endpoint reset to default: ${getDefaultEndpoint()}`);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
error(`Failed to reset endpoint: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return config;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,WAAW,EACX,WAAW,EACX,aAAa,EACb,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5D,SAAS,UAAU,CAAC,SAAiB;IACnC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,0BAA0B,CAAC,CAAC;IAE7E,MAAM;SACH,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,0BAA0B,CAAC;SACvC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;SACzC,MAAM,CAAC,KAAK,EAAE,GAAW,EAAE,EAAE;QAC5B,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;YAE9B,IAAI,CAAC,UAA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EL,MAAM;SACH,OAAO,CAAC,gBAAgB,CAAC;SACzB,WAAW,CAAC,mCAAmC,CAAC;SAChD,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI,CAAC;YACH,MAAM,aAAa,EAAE,CAAC;YACtB,OAAO,CAAC,kCAAkC,kBAAkB,EAAE,EAAE,CAAC,CAAC;QACpE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,CACH,6BAA6B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACpF,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getHistory, ApiError, AuthenticationError, RateLimitError, NotFoundError, } from '../helpers/api.js';
|
|
3
|
+
import { error, info } from '../helpers/output.js';
|
|
4
|
+
function formatCurrency(value) {
|
|
5
|
+
const num = parseFloat(value);
|
|
6
|
+
if (isNaN(num))
|
|
7
|
+
return value;
|
|
8
|
+
return new Intl.NumberFormat('en-US', {
|
|
9
|
+
style: 'currency',
|
|
10
|
+
currency: 'USD',
|
|
11
|
+
}).format(num);
|
|
12
|
+
}
|
|
13
|
+
function formatDate(timestamp) {
|
|
14
|
+
return new Date(timestamp).toLocaleString();
|
|
15
|
+
}
|
|
16
|
+
function formatTransaction(tx) {
|
|
17
|
+
const amount = formatCurrency(tx.netAmount);
|
|
18
|
+
console.log(`\n ${formatDate(tx.timestamp)}`);
|
|
19
|
+
console.log(` ${tx.type}${tx.subType ? ` / ${tx.subType}` : ''}`);
|
|
20
|
+
console.log(` ${tx.description}`);
|
|
21
|
+
if (tx.symbol) {
|
|
22
|
+
console.log(` Symbol: ${tx.symbol} (${tx.securityType || 'N/A'})`);
|
|
23
|
+
}
|
|
24
|
+
if (tx.quantity && tx.side) {
|
|
25
|
+
console.log(` ${tx.side} ${tx.quantity} shares`);
|
|
26
|
+
}
|
|
27
|
+
console.log(` Amount: ${amount} (${tx.direction})`);
|
|
28
|
+
if (tx.fees && parseFloat(tx.fees) !== 0) {
|
|
29
|
+
console.log(` Fees: ${formatCurrency(tx.fees)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function validateDateFormat(value) {
|
|
33
|
+
const date = new Date(value);
|
|
34
|
+
if (isNaN(date.getTime())) {
|
|
35
|
+
throw new Error(`Invalid date format: ${value}. Use ISO 8601 format (e.g., 2025-01-15T09:00:00Z)`);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
export function createHistoryCommand() {
|
|
40
|
+
const history = new Command('history')
|
|
41
|
+
.description('View transaction history for an account')
|
|
42
|
+
.argument('<accountId>', 'The account ID')
|
|
43
|
+
.option('-s, --start <datetime>', 'Start timestamp (ISO 8601 format)', validateDateFormat)
|
|
44
|
+
.option('-e, --end <datetime>', 'End timestamp (ISO 8601 format)', validateDateFormat)
|
|
45
|
+
.option('-n, --limit <number>', 'Maximum number of records', (v) => parseInt(v, 10))
|
|
46
|
+
.option('--next-token <token>', 'Pagination token for next page')
|
|
47
|
+
.action(async (accountId, options) => {
|
|
48
|
+
try {
|
|
49
|
+
const response = await getHistory(accountId, {
|
|
50
|
+
start: options.start,
|
|
51
|
+
end: options.end,
|
|
52
|
+
pageSize: options.limit,
|
|
53
|
+
nextToken: options.nextToken,
|
|
54
|
+
});
|
|
55
|
+
console.log(`\nTransaction History for Account: ${accountId}`);
|
|
56
|
+
console.log(`Period: ${formatDate(response.start)} - ${formatDate(response.end)}`);
|
|
57
|
+
if (response.transactions.length === 0) {
|
|
58
|
+
info('\nNo transactions found for this period.');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
console.log(`\nShowing ${response.transactions.length} transaction${response.transactions.length > 1 ? 's' : ''}:`);
|
|
62
|
+
for (const tx of response.transactions) {
|
|
63
|
+
formatTransaction(tx);
|
|
64
|
+
}
|
|
65
|
+
if (response.nextToken) {
|
|
66
|
+
console.log(`\n More results available. Use --next-token "${response.nextToken}" to see next page.`);
|
|
67
|
+
}
|
|
68
|
+
console.log();
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err instanceof NotFoundError) {
|
|
72
|
+
error(err.message);
|
|
73
|
+
}
|
|
74
|
+
else if (err instanceof AuthenticationError) {
|
|
75
|
+
error(err.message);
|
|
76
|
+
}
|
|
77
|
+
else if (err instanceof RateLimitError) {
|
|
78
|
+
error('Too many requests. Please try again later.');
|
|
79
|
+
}
|
|
80
|
+
else if (err instanceof ApiError) {
|
|
81
|
+
error(`Failed to fetch history: ${err.message}`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
error(`Failed to fetch history: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
85
|
+
}
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return history;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/commands/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEnD,SAAS,cAAc,CAAC,KAAa;IACnC,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QACpC,KAAK,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AAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CACF,CAAC;IAEJ,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getInstrument, ApiError, AuthenticationError, RateLimitError, NotFoundError, } from '../helpers/api.js';
|
|
3
|
+
import { error, success } from '../helpers/output.js';
|
|
4
|
+
const VALID_SECURITY_TYPES = [
|
|
5
|
+
'EQUITY',
|
|
6
|
+
'ETF',
|
|
7
|
+
'ADR',
|
|
8
|
+
'CRYPTO',
|
|
9
|
+
'OPTION',
|
|
10
|
+
'MULTI_LEG_INSTRUMENT',
|
|
11
|
+
'ALT',
|
|
12
|
+
'TREASURY',
|
|
13
|
+
'BOND',
|
|
14
|
+
'INDEX',
|
|
15
|
+
];
|
|
16
|
+
function parseSecurityType(value) {
|
|
17
|
+
const type = value.trim().toUpperCase();
|
|
18
|
+
if (!VALID_SECURITY_TYPES.includes(type)) {
|
|
19
|
+
throw new Error(`Invalid security type: ${type}. Valid types: ${VALID_SECURITY_TYPES.join(', ')}`);
|
|
20
|
+
}
|
|
21
|
+
return type;
|
|
22
|
+
}
|
|
23
|
+
function formatTradingStatus(status) {
|
|
24
|
+
switch (status) {
|
|
25
|
+
case 'BUY_AND_SELL':
|
|
26
|
+
return 'Buy & Sell';
|
|
27
|
+
case 'BUY_ONLY':
|
|
28
|
+
return 'Buy Only';
|
|
29
|
+
case 'SELL_ONLY':
|
|
30
|
+
return 'Sell Only';
|
|
31
|
+
case 'LIQUIDATION_ONLY':
|
|
32
|
+
return 'Liquidation Only';
|
|
33
|
+
case 'DISABLED':
|
|
34
|
+
return 'Disabled';
|
|
35
|
+
case 'NONE':
|
|
36
|
+
return 'None';
|
|
37
|
+
default:
|
|
38
|
+
return status;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function createInstrumentCommand() {
|
|
42
|
+
const instrument = new Command('instrument')
|
|
43
|
+
.description('Get details for a specific instrument')
|
|
44
|
+
.argument('<symbol>', 'The trading symbol (e.g., AAPL, BTC)')
|
|
45
|
+
.option('-t, --type <type>', `Security type (${VALID_SECURITY_TYPES.join(', ')})`, parseSecurityType, 'EQUITY')
|
|
46
|
+
.action(async (symbol, options) => {
|
|
47
|
+
try {
|
|
48
|
+
const data = await getInstrument(symbol.toUpperCase(), options.type);
|
|
49
|
+
success(`\nInstrument: ${data.instrument.symbol}\n`);
|
|
50
|
+
console.log(` Type: ${data.instrument.type}`);
|
|
51
|
+
console.log(` Trading: ${formatTradingStatus(data.trading)}`);
|
|
52
|
+
console.log(` Fractional: ${formatTradingStatus(data.fractionalTrading)}`);
|
|
53
|
+
console.log(` Options: ${formatTradingStatus(data.optionTrading)}`);
|
|
54
|
+
console.log(` Option Spreads: ${formatTradingStatus(data.optionSpreadTrading)}`);
|
|
55
|
+
if (data.instrumentDetails) {
|
|
56
|
+
console.log('\n Details:');
|
|
57
|
+
const details = data.instrumentDetails;
|
|
58
|
+
for (const [key, value] of Object.entries(details)) {
|
|
59
|
+
console.log(` ${key}: ${JSON.stringify(value)}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
console.log();
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err instanceof NotFoundError) {
|
|
66
|
+
error(err.message);
|
|
67
|
+
}
|
|
68
|
+
else if (err instanceof AuthenticationError) {
|
|
69
|
+
error(err.message);
|
|
70
|
+
}
|
|
71
|
+
else if (err instanceof RateLimitError) {
|
|
72
|
+
error('Too many requests. Please try again later.');
|
|
73
|
+
}
|
|
74
|
+
else if (err instanceof ApiError) {
|
|
75
|
+
error(`Failed to fetch instrument: ${err.message}`);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
error(`Failed to fetch instrument: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
79
|
+
}
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return instrument;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=instrument.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrument.js","sourceRoot":"","sources":["../../src/commands/instrument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,aAAa,EACb,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,aAAa,GAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,oBAAoB,GAAmB;IAC3C,QAAQ;IACR,KAAK;IACL,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,sBAAsB;IACtB,KAAK;IACL,UAAU;IACV,MAAM;IACN,OAAO;CACR,CAAC;AAEF,SAAS,iBAAiB,CAAC,KAAa;IACtC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACxC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAoB,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CACb,0BAA0B,IAAI,kBAAkB,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClF,CAAC;IACJ,CAAC;IACD,OAAO,IAAoB,CAAC;AAC9B,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc;IACzC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,cAAc;YACjB,OAAO,YAAY,CAAC;QACtB,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB,KAAK,WAAW;YACd,OAAO,WAAW,CAAC;QACrB,KAAK,kBAAkB;YACrB,OAAO,kBAAkB,CAAC;QAC5B,KAAK,UAAU;YACb,OAAO,UAAU,CAAC;QACpB,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC;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AC,EAAE,CAAC;oBACnD,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;YAED,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,aAAa,EAAE,CAAC;gBACjC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrB,CAAC;iBAAM,IAAI,GAAG,YAAY,mBAAmB,EAAE,CAAC;gBAC9C,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrB,CAAC;iBAAM,IAAI,GAAG,YAAY,cAAc,EAAE,CAAC;gBACzC,KAAK,CAAC,4CAA4C,CAAC,CAAC;YACtD,CAAC;iBAAM,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;gBACnC,KAAK,CAAC,+BAA+B,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACN,KAAK,CACH,+BAA+B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACtF,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { getInstruments, ApiError, AuthenticationError, RateLimitError, } from '../helpers/api.js';
|
|
3
|
+
import { error, success } from '../helpers/output.js';
|
|
4
|
+
const VALID_SECURITY_TYPES = [
|
|
5
|
+
'EQUITY',
|
|
6
|
+
'ETF',
|
|
7
|
+
'ADR',
|
|
8
|
+
'CRYPTO',
|
|
9
|
+
'OPTION',
|
|
10
|
+
'MULTI_LEG_INSTRUMENT',
|
|
11
|
+
'ALT',
|
|
12
|
+
'TREASURY',
|
|
13
|
+
'BOND',
|
|
14
|
+
'INDEX',
|
|
15
|
+
];
|
|
16
|
+
const VALID_TRADING_STATUSES = [
|
|
17
|
+
'BUY_AND_SELL',
|
|
18
|
+
'BUY_ONLY',
|
|
19
|
+
'SELL_ONLY',
|
|
20
|
+
'LIQUIDATION_ONLY',
|
|
21
|
+
'DISABLED',
|
|
22
|
+
'NONE',
|
|
23
|
+
];
|
|
24
|
+
function parseSecurityTypes(value) {
|
|
25
|
+
const types = value.split(',').map((t) => t.trim().toUpperCase());
|
|
26
|
+
for (const type of types) {
|
|
27
|
+
if (!VALID_SECURITY_TYPES.includes(type)) {
|
|
28
|
+
throw new Error(`Invalid security type: ${type}. Valid types: ${VALID_SECURITY_TYPES.join(', ')}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return types;
|
|
32
|
+
}
|
|
33
|
+
function parseTradingStatuses(value) {
|
|
34
|
+
const statuses = value.split(',').map((s) => s.trim().toUpperCase());
|
|
35
|
+
for (const status of statuses) {
|
|
36
|
+
if (!VALID_TRADING_STATUSES.includes(status)) {
|
|
37
|
+
throw new Error(`Invalid trading status: ${status}. Valid statuses: ${VALID_TRADING_STATUSES.join(', ')}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return statuses;
|
|
41
|
+
}
|
|
42
|
+
function formatTradingStatus(status) {
|
|
43
|
+
switch (status) {
|
|
44
|
+
case 'BUY_AND_SELL':
|
|
45
|
+
return 'Buy & Sell';
|
|
46
|
+
case 'BUY_ONLY':
|
|
47
|
+
return 'Buy Only';
|
|
48
|
+
case 'SELL_ONLY':
|
|
49
|
+
return 'Sell Only';
|
|
50
|
+
case 'LIQUIDATION_ONLY':
|
|
51
|
+
return 'Liquidation';
|
|
52
|
+
case 'DISABLED':
|
|
53
|
+
return 'Disabled';
|
|
54
|
+
case 'NONE':
|
|
55
|
+
return 'None';
|
|
56
|
+
default:
|
|
57
|
+
return status;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function createInstrumentsCommand() {
|
|
61
|
+
const instruments = new Command('instruments')
|
|
62
|
+
.description('List available trading instruments')
|
|
63
|
+
.option('-t, --type <types>', `Filter by security type (comma-separated: ${VALID_SECURITY_TYPES.join(', ')})`, parseSecurityTypes)
|
|
64
|
+
.option('--trading <statuses>', `Filter by trading status (comma-separated: ${VALID_TRADING_STATUSES.join(', ')})`, parseTradingStatuses)
|
|
65
|
+
.option('--fractional <statuses>', 'Filter by fractional trading status', parseTradingStatuses)
|
|
66
|
+
.option('--options <statuses>', 'Filter by option trading status', parseTradingStatuses)
|
|
67
|
+
.option('--spreads <statuses>', 'Filter by option spread trading status', parseTradingStatuses)
|
|
68
|
+
.action(async (options) => {
|
|
69
|
+
try {
|
|
70
|
+
const response = await getInstruments({
|
|
71
|
+
typeFilter: options.type,
|
|
72
|
+
tradingFilter: options.trading,
|
|
73
|
+
fractionalTradingFilter: options.fractional,
|
|
74
|
+
optionTradingFilter: options.options,
|
|
75
|
+
optionSpreadTradingFilter: options.spreads,
|
|
76
|
+
});
|
|
77
|
+
if (response.instruments.length === 0) {
|
|
78
|
+
console.log('\nNo instruments found matching the criteria.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
success(`\nFound ${response.instruments.length} instrument${response.instruments.length > 1 ? 's' : ''}:\n`);
|
|
82
|
+
console.log(' Symbol'.padEnd(12) +
|
|
83
|
+
'Type'.padEnd(10) +
|
|
84
|
+
'Trading'.padEnd(14) +
|
|
85
|
+
'Fractional'.padEnd(14) +
|
|
86
|
+
'Options'.padEnd(14) +
|
|
87
|
+
'Spreads');
|
|
88
|
+
console.log(' ' + '-'.repeat(70));
|
|
89
|
+
for (const entry of response.instruments) {
|
|
90
|
+
const symbol = entry.instrument.symbol.padEnd(10);
|
|
91
|
+
const type = entry.instrument.type.padEnd(8);
|
|
92
|
+
const trading = formatTradingStatus(entry.trading).padEnd(12);
|
|
93
|
+
const fractional = formatTradingStatus(entry.fractionalTrading).padEnd(12);
|
|
94
|
+
const optionTrading = formatTradingStatus(entry.optionTrading).padEnd(12);
|
|
95
|
+
const spreads = formatTradingStatus(entry.optionSpreadTrading);
|
|
96
|
+
console.log(` ${symbol} ${type} ${trading} ${fractional} ${optionTrading} ${spreads}`);
|
|
97
|
+
}
|
|
98
|
+
console.log();
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (err instanceof AuthenticationError) {
|
|
102
|
+
error(err.message);
|
|
103
|
+
}
|
|
104
|
+
else if (err instanceof RateLimitError) {
|
|
105
|
+
error('Too many requests. Please try again later.');
|
|
106
|
+
}
|
|
107
|
+
else if (err instanceof ApiError) {
|
|
108
|
+
error(`Failed to fetch instruments: ${err.message}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
error(`Failed to fetch instruments: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
112
|
+
}
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return instruments;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=instruments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instruments.js","sourceRoot":"","sources":["../../src/commands/instruments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,cAAc,GAGf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,oBAAoB,GAAmB;IAC3C,QAAQ;IACR,KAAK;IACL,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,sBAAsB;IACtB,KAAK;IACL,UAAU;IACV,MAAM;IACN,OAAO;CACR,CAAC;AAEF,MAAM,sBAAsB,GAAoB;IAC9C,cAAc;IACd,UAAU;IACV,WAAW;IAC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