(exchangeNames: string, symbol: string, args: any, cliOptions: any)
| 8 | const defaultDepth = 15; |
| 9 | |
| 10 | async function plotOrderBook (exchangeNames: string, symbol: string, args: any, cliOptions: any) { |
| 11 | spinner.start (); |
| 12 | const exchangeIds = exchangeNames.split (','); |
| 13 | |
| 14 | const exchangePromises = exchangeIds.map ((id) => loadSettingsAndCreateExchange (id, cliOptions)); |
| 15 | |
| 16 | const exchanges = await Promise.all (exchangePromises); |
| 17 | |
| 18 | const depth = args[0] ?? defaultDepth; |
| 19 | const boxWidth = 35; |
| 20 | const boxHeight = depth * 2 + 7; |
| 21 | |
| 22 | const screen = blessed.screen ({ |
| 23 | 'smartCSR': true, |
| 24 | 'title': `Order Book - ${symbol}`, |
| 25 | }); |
| 26 | |
| 27 | // append screens |
| 28 | const boxes = []; |
| 29 | for (let i = 0; i < exchanges.length; i++) { |
| 30 | const box = blessed.box ({ |
| 31 | 'top': 'center', |
| 32 | 'left': boxWidth * i + 2, |
| 33 | 'width': boxWidth, |
| 34 | 'height': boxHeight, |
| 35 | 'tags': true, |
| 36 | 'border': { |
| 37 | 'type': 'line', |
| 38 | }, |
| 39 | 'style': { |
| 40 | 'fg': 'white', |
| 41 | 'bg': 'black', |
| 42 | 'border': { 'fg': 'magenta' }, |
| 43 | }, |
| 44 | }); |
| 45 | boxes.push (box); |
| 46 | screen.append (box); |
| 47 | } |
| 48 | screen.key ([ 'escape', 'q', 'C-c' ], () => { |
| 49 | process.exit (0); |
| 50 | }); |
| 51 | |
| 52 | process.on ('SIGINT', () => { |
| 53 | screen.destroy (); // cleanup blessed screen |
| 54 | spinner.clear (); |
| 55 | process.exit (0); |
| 56 | }); |
| 57 | // screen.render (); |
| 58 | const renderPromises = []; |
| 59 | for (let i = 0; i < exchanges.length; i++) { |
| 60 | renderPromises.push (renderOrderBook (screen, exchanges[i], symbol, boxes[i], exchanges[i].id, depth)); |
| 61 | } |
| 62 | await Promise.all (renderPromises); |
| 63 | } |
| 64 | |
| 65 | function center (str, width) { |
| 66 | const len = str.length; |
no test coverage detected
searching dependent graphs…