*
()
| 252 | * |
| 253 | */ |
| 254 | async function run () { |
| 255 | checkCache (); |
| 256 | |
| 257 | const iMode = cliOptions.i; |
| 258 | |
| 259 | while (true) { // main loop, used for the interactive mode |
| 260 | if (!methodName) { |
| 261 | process.exit (0); |
| 262 | } |
| 263 | |
| 264 | const exchange = await loadSettingsAndCreateExchange (exchangeId, cliOptions); |
| 265 | |
| 266 | if (exchange[methodName] === undefined) { |
| 267 | log.red (exchange.id + '.' + methodName + ': no such property'); |
| 268 | process.exit (0); |
| 269 | } |
| 270 | |
| 271 | if (typeof exchange[methodName] !== 'function') { |
| 272 | printHumanReadable (exchange, exchange[methodName], cliOptions, cliOptions.table); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | let i = 0; |
| 277 | const isWsMethod = methodName.startsWith ('watch'); |
| 278 | try { |
| 279 | while (true) { // inner loop used for watchX calls and --poll |
| 280 | await executeCCXTCommand (exchange, params, methodName, cliOptions, i); |
| 281 | i++; |
| 282 | |
| 283 | if (!isWsMethod && !cliOptions.poll) { |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | } catch (e) { |
| 288 | if (e instanceof ExchangeError) { |
| 289 | log.red (e.constructor.name, e.message); |
| 290 | } else if (e instanceof NetworkError) { |
| 291 | log.yellow (e.constructor.name, e.message); |
| 292 | } |
| 293 | log.dim ('---------------------------------------------------'); |
| 294 | // rethrow for call-stack // other errors |
| 295 | throw e; |
| 296 | } |
| 297 | |
| 298 | if (!iMode) { |
| 299 | exchange.close (); |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | inputArgs = await askForArgv ('[command]: '); |
| 304 | |
| 305 | // reparse args using the user input |
| 306 | program.parse (inputArgs); |
| 307 | |
| 308 | cliOptions = program.opts () as CLIOptions; |
| 309 | |
| 310 | [ exchangeId, methodName, ...params ] = program.args; |
| 311 | } |
no test coverage detected