Closed FrictionlessMike closed 3 years ago
With this change:
1 diff --git a/i7531.v b/i7531.1.v
2 index 3da898ffa..5cda819b3 100644
3 --- a/i7531.v
4 +++ b/i7531.1.v
5 @@ -1,5 +1,5 @@
6 import os
7 -import x.websocket
8 +import net.websocket
9 import json
10 import strconv
11
12 @@ -41,7 +41,7 @@ fn start_client() ? {
13 message_decoded := json.decode(Trade, message) or { eprintln('json trade decode failed') return }
14 price := strconv.atof64(message_decoded.price)
15 mut f := os.create('/tmp/btc') or { panic(err) }
16 - f.writeln("${price:5.2f}\n")
17 + f.writeln("${price:5.2f}\n") ?
18 f.flush()
19 f.close()
20 }
Your script seems to work now.
$ v run i7531.v
2021-09-23 07:11:58 [INFO ] connecting to host wss://stream.binance.com:9443/ws/btcusdt@trade
2021-09-23 07:11:59 [INFO ] successfully connected to host wss://stream.binance.com:9443/ws/btcusdt@trade
open!
2021-09-23 07:11:59 [INFO ] Starting client listener, server(false)...
If it matters, I get the same behavior having done
rm -rf ~/.vmodules /tmp/v*
.tldr: calling json.decode fails to compile with the error
undefined reference to
json__decode_main__Trade'` when decoding a string from a websocket. It can decode a string literal copied from the output of the websocket. It can, for some reason, also decode strings from the websocket if it has first decoded a string literal.The offending code is modified from the websocket example that comes with vlib. Here are the interesting bits, with the full code further down:
dumbtrade
is never used or referenced anywhere in the code, but if it's never defined, compilation fails with this error:along with hundreds of warnings:
Here's the full script.