I have this script:
#!/bin/bash
# Connect to the Binance stream using the "-c" flag
wscat -c wss://stream.binance.com:9443/ws/btcusdt@ticker | while read stream; do
# Extract the current price from the stream using jq
price=$(echo "$stream" | jq -r '.c')
#Exit the loop when the price is found
if [[ -n $price ]]; then
break
fi
done
If I try to exit the loop when the price is found, it returns a pipe error. This is the error code:
events.js:291
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:156:25)
at writeGeneric (internal/stream_base_commons.js:147:3)
at Socket._writeGeneric (net.js:788:11)
at Socket._write (net.js:800:8)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at Socket.Writable.write (_stream_writable.js:318:11)
at Console.print (/usr/lib/node_modules/wscat/bin/wscat:74:19)
at WebSocket.<anonymous> (/usr/lib/node_modules/wscat/bin/wscat:358:17)
at WebSocket.emit (events.js:314:20)
Emitted 'error' event on Socket instance at:
at errorOrDestroy (internal/streams/destroy.js:108:12)
at onwriteError (_stream_writable.js:418:5)
at onwrite (_stream_writable.js:445:5)
at internal/streams/destroy.js:50:7
at Socket.dummyDestroy [as _destroy] (internal/bootstrap/switches/is_main_thread.js:97:3)
at Socket.destroy (internal/streams/destroy.js:38:8)
at afterWriteDispatched (internal/stream_base_commons.js:156:17)
at writeGeneric (internal/stream_base_commons.js:147:3)
at Socket._writeGeneric (net.js:788:11)
at Socket._write (net.js:800:8) {
errno: 'EPIPE',
code: 'EPIPE',
syscall: 'write'
}
(standard_in) 1: syntax error
Il valore di bnbbtc () è minore o uguale a 0.1
./strambinance.sh: line 19: syntax error near unexpected token `done'
./strambinance.sh: line 19: `done'
Can anyone help me understand what’s causing this error and how to fix it?